Skip site navigation (1)Skip section navigation (2)
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=C3=B8rgrav 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=20
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 !=3D 3) {
		errx(1, "usage: %s <channel> <device>", argv[0]);
	}
=09
	channel =3D atoi(argv[1]);
	device =3D atoi(argv[2]);
=09
	if ((fd =3D open("/dev/ata", O_RDONLY)) =3D=3D -1) {
		err(1, "error opening /dev/ata");
	}

	bzero(&iocmd, sizeof(struct ata_cmd));
	iocmd.channel =3D channel;
	iocmd.device =3D channel;
	iocmd.cmd =3D ATAGPARM;
=09
	if (ioctl(fd, IOCATA, &iocmd) =3D=3D -1) {
		err(1, "error executing ioctl");
	}

	if (iocmd.u.param.type[device]) {
		ap =3D iocmd.u.param.params[device];
	} else {
		errx(1, "no information for device %d channel %d",
			device, channel);
	}=09
=09
	printf("Model:    ");
	for(i =3D 0; i < 40 && ap.model[i] !=3D '\0'; i++)
		printf("%c", ap.model[i]);
	putchar('\n');

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

	printf("Serial:   ");
	for(i =3D 0; i < 20 && ap.serial[i] !=3D '\0'; i++)
		printf("%c", ap.serial[i]);
	putchar('\n');
=09
	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>