libf2fs: read "disk model" from SCSI ioctl the same way kernel does
authorAdam Borowski <kilobyte@angband.pl>
Thu, 24 May 2018 21:17:01 +0000 (23:17 +0200)
committerJaegeuk Kim <jaegeuk@kernel.org>
Tue, 28 Aug 2018 06:49:26 +0000 (23:49 -0700)
Ref: drivers/scsi/scsi_scan.c scsi_add_lun()

Ie, fixed-width 16 bytes, assumed to be filled with spaces -- NOT
null-terminated; comments suggest that in some cases this field can be
truncated and filled with nulls but printf is fine with that.

The old code did read up to 64 characters, which produced garbage for
at least some USB-attached card readers.  It also special-cased '`'
character which the kernel does not.

Signed-off-by: Adam Borowski <kilobyte@angband.pl>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
lib/libf2fs.c

index 102e579..b25fbf2 100644 (file)
@@ -867,13 +867,8 @@ int get_device_info(int i)
                io_hdr.timeout = 1000;
 
                if (!ioctl(fd, SG_IO, &io_hdr)) {
-                       int i = 16;
-
-                       MSG(0, "Info: [%s] Disk Model: ",
-                                       dev->path);
-                       while (reply_buffer[i] != '`' && i < 80)
-                               printf("%c", reply_buffer[i++]);
-                       printf("\n");
+                       MSG(0, "Info: [%s] Disk Model: %.16s\n",
+                                       dev->path, reply_buffer+16);
                }
 #endif
        } else {