]>
Commit | Line | Data |
---|---|---|
cdddbdbc | 1 | /* |
a54d5262 | 2 | * Copyright (C) 2007-2008 Intel Corporation |
cdddbdbc DW |
3 | * |
4 | * Retrieve drive serial numbers for scsi disks | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or modify it | |
7 | * under the terms and conditions of the GNU General Public License, | |
8 | * version 2, as published by the Free Software Foundation. | |
9 | * | |
10 | * This program is distributed in the hope it will be useful, but WITHOUT | |
11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
13 | * more details. | |
14 | * | |
15 | * You should have received a copy of the GNU General Public License along with | |
16 | * this program; if not, write to the Free Software Foundation, Inc., | |
17 | * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. | |
18 | */ | |
19 | #include <string.h> | |
20 | #include <scsi/scsi.h> | |
21 | #include <scsi/sg.h> | |
22 | #include <sys/ioctl.h> | |
23 | ||
24 | int scsi_get_serial(int fd, void *buf, size_t buf_len) | |
25 | { | |
26 | unsigned char inq_cmd[] = {INQUIRY, 1, 0x80, 0, buf_len, 0}; | |
27 | unsigned char sense[32]; | |
28 | struct sg_io_hdr io_hdr; | |
29 | ||
30 | memset(&io_hdr, 0, sizeof(io_hdr)); | |
31 | io_hdr.interface_id = 'S'; | |
32 | io_hdr.cmdp = inq_cmd; | |
33 | io_hdr.cmd_len = sizeof(inq_cmd); | |
34 | io_hdr.dxferp = buf; | |
35 | io_hdr.dxfer_len = buf_len; | |
36 | io_hdr.dxfer_direction = SG_DXFER_FROM_DEV; | |
37 | io_hdr.sbp = sense; | |
38 | io_hdr.mx_sb_len = sizeof(sense); | |
39 | io_hdr.timeout = 5000; | |
40 | ||
41 | return ioctl(fd, SG_IO, &io_hdr); | |
42 | } |