Solved

Serial number and Model number of HDD using C

Posted on 2008-06-19
11
2,063 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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
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…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

705 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

18 Experts available now in Live!

Get 1:1 Help Now