Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 13 May 2007 17:30:25 +0200
From:      Viktor Vasilev <viktor.vasilev@stud.tu-darmstadt.de>
To:        freebsd-hackers@freebsd.org
Subject:   Re: ioctl
Message-ID:  <200705131730.27958.viktor.vasilev@stud.tu-darmstadt.de>
In-Reply-To: <200705131657.39028.viktor.vasilev@stud.tu-darmstadt.de>
References:  <e420c1bd0705130659h89f09b4wb47b4e476063e66e@mail.gmail.com> <200705131657.39028.viktor.vasilev@stud.tu-darmstadt.de>

next in thread | previous in thread | raw e-mail | index | archive | help
--Boundary-00=_T8yRGJ+P/Dq1H7W
Content-Type: text/plain;
  charset="iso-8859-15"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

On Sunday 13 May 2007 16:57 Viktor Vasilev wrote:
> On Sunday 13 May 2007 15:59 Mohsen Pahlevanzadeh wrote:
> > 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.

i'll inline the source since it didn't came through..

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

int main() {
        struct ata_params ap;
        int fd, i;

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

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

        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

--Boundary-00=_T8yRGJ+P/Dq1H7W--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200705131730.27958.viktor.vasilev>