Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Serial number and Model number of HDD using C

Posted on 2008-06-19
11
Medium Priority
?
2,090 Views
Last Modified: 2008-07-10
How do i get the serial number of the HDDs connected to a system using c/c++. I need a code compatable with DJGPP compiler.
I was trying to get the serial number using int 13 with ah=25, but it got stuck up after calling interrupt.

Thanks
Ned
0
Comment
Question by:nedfine
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 2
11 Comments
 
LVL 45

Accepted Solution

by:
sunnycoder earned 750 total points
ID: 21820730
0
 
LVL 8

Author Comment

by:nedfine
ID: 21821027
Thanks for ur quick reply.

But I want a code that is supported by DJGPP compiler.
I am executing this code in DOS mode.
We were using interrupt programming to get disk information. I was trying to do with int 13 .
Can you please help me to do this?

Thanks
Ned
0
 
LVL 12

Expert Comment

by:trinitrotoluene
ID: 21821554
go to the libraries documentation on the DJGPP compiler page. Check the following if youve not seen it before...

http://www.delorie.com/djgpp/doc/libc-2.02/

and check out the "bios" functions

go to biosdisk
the following function should help you

int biosdisk(int cmd, int drive, int head, int track,
           int sector, int nsects, void *buffer);

You need to include bios.h
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 12

Expert Comment

by:trinitrotoluene
ID: 21821565
doesn't look like you need to use Assembly Language.....try with a simple C program and use the function I've pointed out above
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 21823877
May be I am missing something but I could not see a command for getting disk info.
0
 
LVL 8

Author Comment

by:nedfine
ID: 21828632
Actually I want to get the physical serial number of HDD. I would like to know whether it is possible using bios disk function.  
I am using a formatted HDD for testing , so the boot sector doesnt contain any data.
I dont know much about HDD structure etc, but i think the physical serial number of hdd is not stored in a particular sector of HDD (Please correct me if i am wrong.)
I know that we can get logical serial number of a drive by reading the boot sector of the drive.
but i would like to get the physical serial number of HDD using biosdisk . Please help!

Thanks
Ned
0
 
LVL 12

Expert Comment

by:trinitrotoluene
ID: 21830247
ok...

check the following functions at the same link I mentioned in my previous post. These functions can be found under the io section

_get_dev_info
ioctl (DOS)

I feel you should be able to achieve your objective using the ioctl(DOS) function. Since the HD is a block device you need to supply the device number. This too can be obtained using a library fn. I think it is getdisk(). Will leave it to you to check it out...
0
 
LVL 12

Expert Comment

by:trinitrotoluene
ID: 21854883
did you try out what I suggested?
0
 
LVL 8

Author Comment

by:nedfine
ID: 21855594
I have tried . I used the getdisk() function to get the handle. I am booting from the usb drive. So its saying that current drive is A: and after calling _get_dev_info() it is returning -1.
 
I need to get unique serial number of the HDD.  With biosdisk I tried it giving the sector data.but i think the serial number is not stored in a particular sector .
For IDE hard disks I am able to get the manufacturers serial number and model number of HDD by using controller base address and by sending 0xEC command to the port.

But I need the serial number of SATA HDDs also. and I am executing my code in  DOS mode. Iam using DJGPP to compile my code.
 
is there a solution to this with int13?
The function ah=25 hangs after calling int 13. Is there any prerequisites for executing int 13 with Function ah=25?

Can you give me some alternate ways to get the Physical serial number of an HDD?

Thanks
Ned
0
 
LVL 12

Assisted Solution

by:trinitrotoluene
trinitrotoluene earned 750 total points
ID: 21857600
i think you've not tried out the ioctl. That is the standard way to read from io devices. Reproducing below the relevant sections....all you need to do now is to supply a correct logical device number, you can do this by trial and error....start from 0 and keep incrementing....


--------------------------------------------------------------------------------------------------------


ioctl (DOS)
 
The DOSish version of ioctl performs an interrupt 0x21, function 0x44. It takes care of supplying transfer buffers in low address regions, if they are needed. For an exhaustive description of the various commands and subcommands, see Ralf Brown's interrupt list.
 
It is highly recommended to use only the DOS_* functions listed in `sys/ioctl.h'.
Syntax
 
#include <sys/ioctl.h>
 
int ioctl(int fd, int cmd, ... );
 
Description
 
The parameter fd must refer to a file descriptor for character device functions, or the number of a block device (usually current=0, A:=1, ...).
 
The following constants can be used for the cmd parameter:
 
DOS_GETDEVDATA
    Get device information. Returns the device information word from DX. The call to ioctl should look like this:
 
     int ret_val = ioctl (fd, DOS_GETDEVDATA);

Open in new window

0
 
LVL 8

Author Comment

by:nedfine
ID: 21884702
Hi,

It is not working for me. I am getting -1 and 0 only as output.
And I read in some article that , ioctl is using int21 with ax=440dh.
If so, even it works well ,it will give volume serial number only.
If its not the case, then I failed to do as required.
Please help.

Thanks
Ned
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question