]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
super-intel: move scsi_get_serial from sg_io
authorKinga Stefaniuk <kinga.stefaniuk@intel.com>
Fri, 4 Oct 2024 08:23:57 +0000 (10:23 +0200)
committerMariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
Tue, 8 Oct 2024 10:24:59 +0000 (12:24 +0200)
scsi_get_serial() function is used only by super-intel.c. Move function
to this file and remove sg_io.c file.

Signed-off-by: Kinga Stefaniuk <kinga.stefaniuk@intel.com>
Makefile
sg_io.c [deleted file]
super-intel.c

index 32f579dea2371173bcc6dc0e64a06117b4e4edc3..24367b0fbd9823744f026e33ecc6e4c3098ffa3d 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -190,7 +190,7 @@ OBJS = mdadm.o config.o policy.o mdstat.o  ReadMe.o uuid.o util.o maps.o lib.o u
        Incremental.o Dump.o \
        mdopen.o super0.o super1.o super-ddf.o super-intel.o bitmap.o \
        super-mbr.o super-gpt.o \
-       restripe.o sysfs.o sha1.o mapfile.o crc32.o sg_io.o msg.o xmalloc.o \
+       restripe.o sysfs.o sha1.o mapfile.o crc32.o msg.o xmalloc.o \
        platform-intel.o probe_roms.o crc32c.o drive_encryption.o
 
 CHECK_OBJS = restripe.o uuid.o sysfs.o maps.o lib.o xmalloc.o dlink.o
@@ -201,7 +201,7 @@ INCL = mdadm.h part.h bitmap.h
 
 MON_OBJS = mdmon.o monitor.o managemon.o uuid.o util.o maps.o mdstat.o sysfs.o config.o mapfile.o mdopen.o\
        policy.o lib.o udev.o \
-       Kill.o sg_io.o dlink.o ReadMe.o super-intel.o \
+       Kill.o dlink.o ReadMe.o super-intel.o \
        super-mbr.o super-gpt.o \
        super-ddf.o sha1.o crc32.o msg.o bitmap.o xmalloc.o \
        platform-intel.o probe_roms.o crc32c.o drive_encryption.o
diff --git a/sg_io.c b/sg_io.c
deleted file mode 100644 (file)
index 7889a95..0000000
--- a/sg_io.c
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * 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 rsp_buf[255];
-       unsigned char inq_cmd[] = {INQUIRY, 1, 0x80, 0, sizeof(rsp_buf), 0};
-       unsigned char sense[32];
-       struct sg_io_hdr io_hdr;
-       int rv;
-       unsigned int rsp_len;
-
-       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 = rsp_buf;
-       io_hdr.dxfer_len = sizeof(rsp_buf);
-       io_hdr.dxfer_direction = SG_DXFER_FROM_DEV;
-       io_hdr.sbp = sense;
-       io_hdr.mx_sb_len = sizeof(sense);
-       io_hdr.timeout = 5000;
-
-       rv = ioctl(fd, SG_IO, &io_hdr);
-
-       if (rv)
-               return rv;
-
-       if ((io_hdr.info & SG_INFO_OK_MASK) != SG_INFO_OK)
-               return -1;
-
-       rsp_len = rsp_buf[3];
-
-       if (!rsp_len || buf_len < rsp_len)
-               return -1;
-
-       memcpy(buf, &rsp_buf[4], rsp_len);
-
-       return 0;
-}
index 7c5119c530a49ba0a6bd07a0ea98f6e9aca0acaf..3b856ad0e756a9d6ea8cecd0daebb1ef432bdec7 100644 (file)
 #include "mdadm.h"
 #include "mdmon.h"
 #include "dlink.h"
+#include "drive_encryption.h"
 #include "sha1.h"
 #include "platform-intel.h"
 #include "xmalloc.h"
 
-#include <values.h>
-#include <scsi/sg.h>
 #include <ctype.h>
 #include <dirent.h>
-#include "drive_encryption.h"
+#include <scsi/scsi.h>
+#include <scsi/sg.h>
+#include <string.h>
+#include <sys/ioctl.h>
+#include <values.h>
 
 /* MPB == Metadata Parameter Block */
 #define MPB_SIGNATURE "Intel Raid ISM Cfg Sig. "
@@ -4131,7 +4134,43 @@ static int nvme_get_serial(int fd, void *buf, size_t buf_len)
        return devpath_to_char(path, "serial", buf, buf_len, 0);
 }
 
-extern int scsi_get_serial(int fd, void *buf, size_t buf_len);
+mdadm_status_t scsi_get_serial(int fd, void *buf, size_t buf_len)
+{
+       struct sg_io_hdr io_hdr = {0};
+       unsigned char rsp_buf[255];
+       unsigned char inq_cmd[] = {INQUIRY, 1, 0x80, 0, sizeof(rsp_buf), 0};
+       unsigned char sense[32];
+       unsigned int rsp_len;
+       int rv;
+
+       io_hdr.interface_id = 'S';
+       io_hdr.cmdp = inq_cmd;
+       io_hdr.cmd_len = sizeof(inq_cmd);
+       io_hdr.dxferp = rsp_buf;
+       io_hdr.dxfer_len = sizeof(rsp_buf);
+       io_hdr.dxfer_direction = SG_DXFER_FROM_DEV;
+       io_hdr.sbp = sense;
+       io_hdr.mx_sb_len = sizeof(sense);
+       io_hdr.timeout = 5000;
+
+       rv = ioctl(fd, SG_IO, &io_hdr);
+
+       if (rv)
+               return MDADM_STATUS_ERROR;
+
+       if ((io_hdr.info & SG_INFO_OK_MASK) != SG_INFO_OK)
+               return MDADM_STATUS_ERROR;
+
+       rsp_len = rsp_buf[3];
+
+       if (!rsp_len || buf_len < rsp_len)
+               return MDADM_STATUS_ERROR;
+
+       memcpy(buf, &rsp_buf[4], rsp_len);
+
+       return MDADM_STATUS_SUCCESS;
+}
+
 
 static int imsm_read_serial(int fd, char *devname,
                            __u8 *serial, size_t serial_buf_len)