]>
git.ipfire.org Git - thirdparty/mdadm.git/blob - sg_io.c
2 * Copyright (C) 2007-2008 Intel Corporation
4 * Retrieve drive serial numbers for scsi disks
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.
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
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.
20 #include <scsi/scsi.h>
22 #include <sys/ioctl.h>
24 int scsi_get_serial(int fd
, void *buf
, size_t buf_len
)
26 unsigned char inq_cmd
[] = {INQUIRY
, 1, 0x80, 0, buf_len
, 0};
27 unsigned char sense
[32];
28 struct sg_io_hdr io_hdr
;
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
);
35 io_hdr
.dxfer_len
= buf_len
;
36 io_hdr
.dxfer_direction
= SG_DXFER_FROM_DEV
;
38 io_hdr
.mx_sb_len
= sizeof(sense
);
39 io_hdr
.timeout
= 5000;
41 return ioctl(fd
, SG_IO
, &io_hdr
);