Date: Tue, 15 May 2007 18:10:27 +0200 From: Viktor Vasilev <viktor.vasilev@stud.tu-darmstadt.de> To: freebsd-hackers@freebsd.org, Mohsen Pahlevanzadeh <mohsen@pahlevanzadeh.org> Subject: Re: ioctl Message-ID: <200705151810.29508.viktor.vasilev@stud.tu-darmstadt.de> In-Reply-To: <86ejljsffa.fsf@dwp.des.no> References: <e420c1bd0705130659h89f09b4wb47b4e476063e66e@mail.gmail.com> <4648625A.9060606@pahlevanzadeh.org> <86ejljsffa.fsf@dwp.des.no>
next in thread | previous in thread | raw e-mail | index | archive | help
On Monday 14 May 2007 15:28 Dag-Erling Smørgrav wrote:
> Mohsen Pahlevanzadeh <mohsen@pahlevanzadeh.org> writes:
> > 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200705151810.29508.viktor.vasilev>
