Solved

Serial number and Model number of HDD using C

Posted on 2008-06-19
11
2,066 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
  • 5
  • 4
  • 2
11 Comments
 
LVL 45

Accepted Solution

by:
sunnycoder earned 250 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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 250 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

910 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now