diff options
author | Michael Tokarev <mjt@tls.msk.ru> | 2014-12-20 08:48:44 +0000 |
---|---|---|
committer | Michael Tokarev <mjt@tls.msk.ru> | 2014-12-20 08:48:44 +0000 |
commit | 489bea7ee8e1dbecfa517b8415568044ab57c73a (patch) | |
tree | 44d4878d4c7da3f4908ea9a765ef9b8f9c141756 /sg_io.c |
mdadm (3.3.2-5) unstable; urgency=medium
* use-tempnode-not-devnode.patch: change udev rules file to use
$tempnode which works both on wheezy and jessie udev, instead
of $devnode which only works in jessie. At this stage it is
better to make rules file compatible with old version instead
of adding versioned dependency. Should be removed for jessie+1.
(Closes: #770883)
* fix Closes: list in previous entry (Closes: #771852)
# imported from the archive
Diffstat (limited to 'sg_io.c')
-rw-r--r-- | sg_io.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/sg_io.c b/sg_io.c new file mode 100644 index 00000000..50ad180d --- /dev/null +++ b/sg_io.c @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2007-2008 Intel Corporation + * + * Retrieve drive serial numbers for scsi disks + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. + */ +#include <string.h> +#include <scsi/scsi.h> +#include <scsi/sg.h> +#include <sys/ioctl.h> + +int scsi_get_serial(int fd, void *buf, size_t buf_len) +{ + unsigned char inq_cmd[] = {INQUIRY, 1, 0x80, 0, buf_len, 0}; + unsigned char sense[32]; + struct sg_io_hdr io_hdr; + + memset(&io_hdr, 0, sizeof(io_hdr)); + io_hdr.interface_id = 'S'; + io_hdr.cmdp = inq_cmd; + io_hdr.cmd_len = sizeof(inq_cmd); + io_hdr.dxferp = buf; + io_hdr.dxfer_len = buf_len; + io_hdr.dxfer_direction = SG_DXFER_FROM_DEV; + io_hdr.sbp = sense; + io_hdr.mx_sb_len = sizeof(sense); + io_hdr.timeout = 5000; + + return ioctl(fd, SG_IO, &io_hdr); +} |