Discussion:
ioctl
(too old to reply)
Mohsen Pahlevanzadeh
2007-05-13 13:59:48 UTC
Permalink
Dear all,
I need to a code piece that it gets serial number of hdd.
Please help me....
Viktor Vasilev
2007-05-13 14:57:37 UTC
Permalink
Viktor Vasilev
2007-05-13 15:30:25 UTC
Permalink
Bernd Walter
2007-05-13 15:11:53 UTC
Permalink
Post by Mohsen Pahlevanzadeh
Dear all,
I need to a code piece that it gets serial number of hdd.
Please help me....
"atacontrol cap" shows you the serial number.
--
B.Walter http://www.bwct.de http://www.fizon.de
***@bwct.de ***@bwct.de ***@fizon.de
Mohsen Pahlevanzadeh
2007-05-13 16:17:21 UTC
Permalink
Dear all,
When i compile it,gcc tell me that IOCATAGPARM isn't declare.
May i patch for kernel?
Yours,Mohsen
Post by Mohsen Pahlevanzadeh
Dear all,
I need to a code piece that it gets serial number of hdd.
Please help me....
For an ATA disk you can use the IOCATAGPARM ioctl to get the information.
See the attached C source for example. Be sure to have a look
at /usr/src/sys/sys/ata.h for other relevant fields and sizes.
Cheers,
Vik
_______________________________________________
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
Viktor Vasilev
2007-05-13 16:51:27 UTC
Permalink
Post by Mohsen Pahlevanzadeh
Post by Mohsen Pahlevanzadeh
Dear all,
I need to a code piece that it gets serial number of hdd.
Please help me....
For an ATA disk you can use the IOCATAGPARM ioctl to get the
information. See the attached C source for example. Be sure to have a
look
at /usr/src/sys/sys/ata.h for other relevant fields and sizes.
Dear all,
When i compile it,gcc tell me that IOCATAGPARM isn't declare.
May i patch for kernel?
Yours,Mohsen
Maybe you just didn't install the src distribution. Please look at the
handbook:


http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/kernelconfig-building.html

the note that says "If there is not a /usr/src/sys directory on your
system...".


Cheers,
Vik
Dag-Erling Smørgrav
2007-05-13 18:46:38 UTC
Permalink
Post by Viktor Vasilev
Post by Mohsen Pahlevanzadeh
When i compile it,gcc tell me that IOCATAGPARM isn't declare.
May i patch for kernel?
Maybe you just didn't install the src distribution.
He doesn't need to. Your code should build cleanly on a stock install
of FreeBSD 6.0 or newer.

DES
--
Dag-Erling Smørgrav - ***@des.no
Dag-Erling Smørgrav
2007-05-14 13:28:09 UTC
Permalink
[The] code should build cleanly on a stock install of FreeBSD 6.0 or
newer.
Our FreeBSD is 4.11 because we can't use another version.
In that case, we can't help you.

DES
--
Dag-Erling Smørgrav - ***@des.no
Viktor Vasilev
2007-05-15 16:10:27 UTC
Permalink
Post by Dag-Erling Smørgrav
Our FreeBSD is 4.11 because we can't use another version.
In that case, we can't help you.
Maybe he still has a chance. The following works on FreeBSD 4.9 for ATA
devices. I could only test it with an ATA CDROM, but here's the output:

Model: CD-224E
Revision: 1.9A
Serial:


#include <stdio.h>
#include <strings.h>
#include <stdlib.h>
#include <fcntl.h>
#include <err.h>
#include <sys/types.h>
#include <sys/ata.h>

int main(int argc, char **argv) {
struct ata_cmd iocmd;
struct ata_params ap;
int channel, device, fd, i;

if(argc != 3) {
errx(1, "usage: %s <channel> <device>", argv[0]);
}

channel = atoi(argv[1]);
device = atoi(argv[2]);

if ((fd = open("/dev/ata", O_RDONLY)) == -1) {
err(1, "error opening /dev/ata");
}

bzero(&iocmd, sizeof(struct ata_cmd));
iocmd.channel = channel;
iocmd.device = channel;
iocmd.cmd = ATAGPARM;

if (ioctl(fd, IOCATA, &iocmd) == -1) {
err(1, "error executing ioctl");
}

if (iocmd.u.param.type[device]) {
ap = iocmd.u.param.params[device];
} else {
errx(1, "no information for device %d channel %d",
device, channel);
}

printf("Model: ");
for(i = 0; i < 40 && ap.model[i] != '\0'; i++)
printf("%c", ap.model[i]);
putchar('\n');

printf("Revision: ");
for(i = 0; i < 8 && ap.revision[i] != '\0'; i++)
printf("%c", ap.revision[i]);
putchar('\n');

printf("Serial: ");
for(i = 0; i < 20 && ap.serial[i] != '\0'; i++)
printf("%c", ap.serial[i]);
putchar('\n');

return 0;
}


Cheers,
Vik

Loading...