From owner-freebsd-hackers@FreeBSD.ORG Sun May 13 15:30:37 2007 Return-Path: X-Original-To: freebsd-hackers@freebsd.org Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id B34A816A402 for ; Sun, 13 May 2007 15:30:37 +0000 (UTC) (envelope-from viktor.vasilev@stud.tu-darmstadt.de) Received: from lnx130.hrz.tu-darmstadt.de (lnx130.hrz.tu-darmstadt.de [130.83.174.24]) by mx1.freebsd.org (Postfix) with ESMTP id 4A8E813C43E for ; Sun, 13 May 2007 15:30:36 +0000 (UTC) (envelope-from viktor.vasilev@stud.tu-darmstadt.de) Received: from mailserver3.hrz.tu-darmstadt.de (lnx117.hrz.tu-darmstadt.de [130.83.174.26]) by lnx130.hrz.tu-darmstadt.de (8.13.4/8.12.10) with ESMTP id l4DFUamN007991 for ; Sun, 13 May 2007 17:30:36 +0200 Received: from [217.224.75.196] (helo=local.lan.fli4l) by mailserver3.hrz.tu-darmstadt.de with esmtpsa (TLS-1.0:DHE_RSA_AES_256_CBC_SHA:32) (Exim 4.50) id 1HnG1q-0007wB-TI for freebsd-hackers@freebsd.org; Sun, 13 May 2007 17:30:36 +0200 From: Viktor Vasilev To: freebsd-hackers@freebsd.org Date: Sun, 13 May 2007 17:30:25 +0200 User-Agent: KMail/1.9.4 References: <200705131657.39028.viktor.vasilev@stud.tu-darmstadt.de> In-Reply-To: <200705131657.39028.viktor.vasilev@stud.tu-darmstadt.de> MIME-Version: 1.0 Content-Type: Multipart/Mixed; boundary="Boundary-00=_T8yRGJ+P/Dq1H7W" Message-Id: <200705131730.27958.viktor.vasilev@stud.tu-darmstadt.de> X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Subject: Re: ioctl X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 13 May 2007 15:30:37 -0000 --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 #include #include #include #include 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--