2 * ata_id - reads product/serial number from ATA drives
4 * Copyright (C) 2005 Kay Sievers <kay.sievers@vrfy.org>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 #include <sys/ioctl.h>
32 #include <sys/types.h>
34 #include <linux/types.h>
35 #include <linux/hdreg.h>
37 #include "../../logging.h"
38 #include "../../udev_utils.h"
41 void log_message(int priority, const char *format, ...)
44 static int udev_log = -1;
49 value = getenv("UDEV_LOG");
51 udev_log = log_priority(value);
56 if (priority > udev_log)
59 va_start(args, format);
60 vsyslog(priority, format, args);
65 static void set_str(char *to, const unsigned char *from, int count)
70 len = strnlen(from, count);
71 while (isspace(from[len-1]))
75 while (isspace(from[i]) && (i < len))
92 int main(int argc, char *argv[])
98 const char *node = NULL;
104 for (i = 1 ; i < argc; i++) {
107 if (strcmp(arg, "--export") == 0) {
113 err("no node specified");
118 fd = open(node, O_RDONLY);
120 if (errno == ENOMEDIUM)
121 fd = open(node, O_RDONLY|O_NONBLOCK);
123 err("unable to open '%s'", node);
128 if (ioctl(fd, HDIO_GET_IDENTITY, &id)) {
129 err("HDIO_GET_IDENTITY failed for '%s'", node);
134 set_str(model, id.model, 40);
135 set_str(serial, id.serial_no, 20);
136 set_str(revision, id.fw_rev, 8);
139 printf("ID_MODEL=%s\n", model);
140 printf("ID_SERIAL=%s\n", serial);
141 printf("ID_REVISION=%s\n", revision);
143 printf("%s_%s\n", model, serial);