- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Retrieving disk serial number programmatically
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-27-2002 03:01 AM
11-27-2002 03:01 AM
I am trying to retrieve the disk serial number programmatically.
I saw a post
http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0xc4bf0bce6f33d6118fff0090279cd0f9,00.html
that gives a way (run cstm tool and parse the output).
Can we retrieve the serial number by calling some API in C
or a kernel call?
How does cstm find the serial number? (I tried running tusc,
but couldn't extract much info). Is it doing ioctl? If yes,
then what IOCTL code can be used to get the serial number?
Any help will be appreciated.
With regards,
Nikhil
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-27-2002 05:21 AM
11-27-2002 05:21 AM
SolutionI put the following together, it gives you most of the serial number - I haven't had time to work out the rest, but should get you going:
#include
#include
#include
#include
#include
#include
int main(int argc,char *argv[])
{
struct inquiry inquiry;
char *dev;
int fd;
if (argc != 2)
{
fprintf(stderr, "Usage: %s
exit(1);
}
if (argc == 2)
dev=argv[1];
/* open the device */
if ((fd=open(dev,O_RDONLY))<0)
{
perror("open failed");
exit(errno);
}
if ((ioctl(fd,SIOC_INQUIRY,&inquiry))<0)
{
perror("ioctl(SIOC_INQUIRY) failed");
exit(errno);
}
printf("\nVendor ID = %s\n",inquiry.vendor_id);
printf("Product ID=%s\n",inquiry.product_id);
printf("Vendor Spec=%s\n",inquiry.vendor_spec);
printf("Rev Number=%s\n",inquiry.rev_num);
exit(0) ;
}
Rgds, Robin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-27-2002 06:10 AM
11-27-2002 06:10 AM
Re: Retrieving disk serial number programmatically
The inquiry string will not give the S/N of the device... see my reply to your post in the Storage forum.
Vince
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-27-2002 06:19 AM
11-27-2002 06:19 AM
Re: Retrieving disk serial number programmatically
I'm suprised because Robin's answer as well as mine (Nikhil posted several questions) are both giving the same SN as cstm. In fact the structure member name I use is even called 'serial' ... But Robin's solution gives more detailed information.
Regards.
#include
#include
#include
#include
#include
#include
#include
#include
#define SIOC_SERIAL _IOR('S', 254, struct scsi_serial)
main (argc, argv)
int argc;
char *argv[];
{
int Fd, Inq;
struct scsi_serial Serial;
if ( (Fd = open (argv[1], O_RDONLY)) < 0 )
{
perror ("open");
exit (1);
}
if ( (Inq = ioctl (Fd, SIOC_SERIAL, &Serial)) != 0 )
{
perror ("ioctl SIOC_SERIAL");
}
else
{
printf ("Serial number for '%s' is '%s'\n", argv[1], Serial.serial);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-27-2002 06:22 AM
11-27-2002 06:22 AM
Re: Retrieving disk serial number programmatically
Mine only shows the 1st 8 chars. Yours is correct.
Rgds, Robin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2002 03:00 AM
11-28-2002 03:00 AM
Re: Retrieving disk serial number programmatically
I am able to get the SCSI disk serial number using ioctl.
With regards,
Nikhil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2002 04:13 AM
11-28-2002 04:13 AM
Re: Retrieving disk serial number programmatically
whats the compile options for your program ? I cant get it to compile, tried everything.
Cheers,
Stefan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2002 04:32 AM
11-28-2002 04:32 AM
Re: Retrieving disk serial number programmatically
I'm quite surprised because my compile options are strictly defaults ... since I only use 'make prog'. I wrote it on a 11.11 system. Give me you error messages if you want.
Regards.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2002 05:34 AM
11-28-2002 05:34 AM
Re: Retrieving disk serial number programmatically
Im trying it on 11.0;
> cc -o s serialnumber.c
cc: "serialnumber.c", line 16: error 1574: Unknown size for "Serial".
cc: "serialnumber.c", line 24: error 1594: The sizeof operator cannot be applied to types with unknown size.
cc: "serialnumber.c", line 30: error 1530: Undefined struct or union.
My 11i system is unavailable so cant try it there. Robins program compiles fine on 11.0 without any options. I would love to be able to compile yours on 11.0 also.
Thanks,
Stefan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2002 06:42 AM
11-28-2002 06:42 AM
Re: Retrieving disk serial number programmatically
I can't believe it ... Even on my 11.11 it gives the same messages. Yesterday I spent all my time looking for Harry's new hat and grep'ing in include files to find related structures. But I can see that Nikhil had the same problem. I can't find out what have changed between last source working version and my post, but I'm sure I didn't use any compile option. Anyway, declaring the structure in the source is not clean but works ... It-s defined in /usr/include/sys/scsi_ctl.h but seems to be active only if you have also _KERNEL defined. But with this flag, you get in big other troubles when compiling. I'am sorry !
#include
#include
#include
#include
struct scsi_serial
{
ubit8 device_type;
ubit8 page_code;
ubit8 reserved;
ubit8 page_length;
ubit8 serial[252];
};
#define SIOC_SERIAL _IOR('S', 254, struct scsi_serial)
main (argc, argv)
int argc;
char *argv[];
{
int Fd, Inq;
struct scsi_serial Serial;
if ( (Fd = open (argv[1], O_RDONLY)) < 0 )
{
perror ("open");
exit (1);
}
if ( (Inq = ioctl (Fd, SIOC_SERIAL, &Serial)) != 0 )
{
perror ("ioctl SIOC_SERIAL");
}
else
{
printf ("Serial number for '%s' is '%s'\n", argv[1], Serial.serial);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2002 11:25 PM
11-28-2002 11:25 PM
Re: Retrieving disk serial number programmatically
> Anyway, declaring the structure in the source is not clean but works
This is exactly what I did. I used g++3.2 as well as aCC 3.31.
Thanks,
Nikhil