Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Serial number and Model number of HDD using C

Posted on 2008-06-19
11
Medium Priority
?
2,094 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 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
Suggested Courses

971 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