mirror of
https://gitee.com/openharmony/third_party_f2fs-tools
synced 2024-11-23 10:10:00 +00:00
libf2fs: show disk information
This adds to show disk information. Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
This commit is contained in:
parent
d2446560e2
commit
c6834e9cc4
@ -19,10 +19,14 @@
|
||||
#include <sys/stat.h>
|
||||
#include <sys/mount.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <scsi/sg.h>
|
||||
#include <linux/hdreg.h>
|
||||
|
||||
#include <f2fs_fs.h>
|
||||
|
||||
/* SCSI command for standard inquiry*/
|
||||
#define MODELINQUIRY 0x12,0x00,0x00,0x00,0x4A,0x00
|
||||
|
||||
/*
|
||||
* UTF conversion codes are Copied from exfat tools.
|
||||
*/
|
||||
@ -582,6 +586,9 @@ int f2fs_get_device_info(struct f2fs_configuration *c)
|
||||
#endif
|
||||
struct stat stat_buf;
|
||||
struct hd_geometry geom;
|
||||
sg_io_hdr_t io_hdr;
|
||||
unsigned char reply_buffer[96];
|
||||
unsigned char model_inq[6] = {MODELINQUIRY};
|
||||
u_int64_t wanted_total_sectors = c->total_sectors;
|
||||
|
||||
fd = open(c->device_name, O_RDWR);
|
||||
@ -630,6 +637,25 @@ int f2fs_get_device_info(struct f2fs_configuration *c)
|
||||
c->start_sector = 0;
|
||||
else
|
||||
c->start_sector = geom.start;
|
||||
|
||||
/* Send INQUIRY command */
|
||||
memset(&io_hdr, 0, sizeof(sg_io_hdr_t));
|
||||
io_hdr.interface_id = 'S';
|
||||
io_hdr.dxfer_direction = SG_DXFER_FROM_DEV;
|
||||
io_hdr.dxfer_len = sizeof(reply_buffer);
|
||||
io_hdr.dxferp = reply_buffer;
|
||||
io_hdr.cmd_len = sizeof(model_inq);
|
||||
io_hdr.cmdp = model_inq;
|
||||
io_hdr.timeout = 1000;
|
||||
|
||||
if (!ioctl(fd,SG_IO,&io_hdr)) {
|
||||
int i = 16;
|
||||
|
||||
MSG(0, "Info: Disk Model: ");
|
||||
while (reply_buffer[i] != '`')
|
||||
printf("%c", reply_buffer[i++]);
|
||||
printf("\n");
|
||||
}
|
||||
} else {
|
||||
MSG(0, "\tError: Volume type is not supported!!!\n");
|
||||
return -1;
|
||||
@ -638,7 +664,6 @@ int f2fs_get_device_info(struct f2fs_configuration *c)
|
||||
MSG(0, "Info: total device sectors = %"PRIu64" (in %u bytes)\n",
|
||||
c->total_sectors, c->sector_size);
|
||||
c->total_sectors = wanted_total_sectors;
|
||||
|
||||
}
|
||||
if (c->total_sectors * c->sector_size >
|
||||
(u_int64_t)F2FS_MAX_SEGMENT * 2 * 1024 * 1024) {
|
||||
|
Loading…
Reference in New Issue
Block a user