From e7e5dbca1dd12bbf0246f6ea3a323c395479867a Mon Sep 17 00:00:00 2001 From: Brandon King Date: Thu, 4 Jun 2009 22:55:37 +0000 Subject: [PATCH] A simple command to request the hard drive serial number from a device. * Used py_sg (easy_install py_sg) --- htsworkflow/util/hdquery.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 htsworkflow/util/hdquery.py diff --git a/htsworkflow/util/hdquery.py b/htsworkflow/util/hdquery.py new file mode 100644 index 0000000..ff16387 --- /dev/null +++ b/htsworkflow/util/hdquery.py @@ -0,0 +1,25 @@ +import os + +#try: +import py_sg +#except: +# print 'ERROR: Please install py_sg (easy_install py_sg)' + + +def get_hd_serial_num(device): + """ + device = '/dev/sdX' + + returns hard drive serial number for a device; requires read permissions. + """ + fd = os.open(device, os.O_RDONLY) + + # fd: device object + # \x12: INQUIRY CMD; \x01: EVPD bit set to 1; \x80: Unit Serial Number page + # See http://en.wikipedia.org/wiki/SCSI_Inquiry_Command for helpful chart + # ##: # byte buffer for returned data + data = py_sg.read(fd, "\x12\x01\x80", 32) + + # Remove extra \x00's, and split remaining data into two chunks, + # the 2nd of which is the serial number + return data.strip('\x00').split()[1] -- 2.30.2