• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2098
  • Last Modified:

Serial number and Model number of HDD using C

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
nedfine
Asked:
nedfine
  • 5
  • 4
  • 2
2 Solutions
 
sunnycoderCommented:
0
 
nedfineAuthor Commented:
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
 
trinitrotolueneDirector - Software EngineeringCommented:
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
Independent Software Vendors: 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!

 
trinitrotolueneDirector - Software EngineeringCommented:
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
 
sunnycoderCommented:
May be I am missing something but I could not see a command for getting disk info.
0
 
nedfineAuthor Commented:
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
 
trinitrotolueneDirector - Software EngineeringCommented:
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
 
trinitrotolueneDirector - Software EngineeringCommented:
did you try out what I suggested?
0
 
nedfineAuthor Commented:
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
 
trinitrotolueneDirector - Software EngineeringCommented:
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
 
nedfineAuthor Commented:
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

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

  • 5
  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now