mirror of
https://github.com/koverstreet/bcachefs-tools.git
synced 2025-02-02 00:00:03 +03:00
cmd_show_super: Also print device model
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
parent
6e50a9b4fc
commit
9f4ed5ce05
@ -384,6 +384,15 @@ int cmd_show_super(int argc, char *argv[])
|
||||
if (f)
|
||||
__bch2_sb_field_to_text(&buf, sb.sb, f);
|
||||
} else {
|
||||
printbuf_tabstop_push(&buf, 44);
|
||||
|
||||
char *model = fd_to_dev_model(sb.bdev->bd_fd);
|
||||
prt_str(&buf, "Device:");
|
||||
prt_tab(&buf);
|
||||
prt_str(&buf, model);
|
||||
prt_newline(&buf);
|
||||
free(model);
|
||||
|
||||
bch2_sb_to_text(&buf, sb.sb, print_layout, fields);
|
||||
}
|
||||
printf("%s", buf.buf);
|
||||
|
@ -579,6 +579,49 @@ int dev_mounted(char *dev)
|
||||
return 2;
|
||||
}
|
||||
|
||||
static char *dev_to_sysfs_path(dev_t dev)
|
||||
{
|
||||
return mprintf("/sys/dev/block/%u:%u", major(dev), minor(dev));
|
||||
}
|
||||
|
||||
char *fd_to_dev_model(int fd)
|
||||
{
|
||||
struct stat stat = xfstat(fd);
|
||||
|
||||
if (S_ISBLK(stat.st_mode)) {
|
||||
char *sysfs_path = dev_to_sysfs_path(stat.st_rdev);
|
||||
|
||||
char *model_path = mprintf("%s/device/model", sysfs_path);
|
||||
if (!access(model_path, R_OK))
|
||||
goto got_model;
|
||||
free(model_path);
|
||||
|
||||
/* partition? try parent */
|
||||
|
||||
char buf[1024];
|
||||
if (readlink(sysfs_path, buf, sizeof(buf)) < 0)
|
||||
die("readlink error on %s: %m", sysfs_path);
|
||||
|
||||
free(sysfs_path);
|
||||
sysfs_path = strdup(buf);
|
||||
|
||||
*strrchr(sysfs_path, '/') = 0;
|
||||
model_path = mprintf("%s/device/model", sysfs_path);
|
||||
if (!access(model_path, R_OK))
|
||||
goto got_model;
|
||||
|
||||
return strdup("(unknown device)");
|
||||
char *model;
|
||||
got_model:
|
||||
model = read_file_str(AT_FDCWD, model_path);
|
||||
free(model_path);
|
||||
free(sysfs_path);
|
||||
return model;
|
||||
} else {
|
||||
return strdup("(reg file)");
|
||||
}
|
||||
}
|
||||
|
||||
static int kstrtoull_symbolic(const char *s, unsigned int base, unsigned long long *res)
|
||||
{
|
||||
if (!strcmp(s, "U64_MAX")) {
|
||||
|
@ -180,6 +180,7 @@ char *dev_to_name(dev_t);
|
||||
char *dev_to_path(dev_t);
|
||||
struct mntent *dev_to_mount(char *);
|
||||
int dev_mounted(char *);
|
||||
char *fd_to_dev_model(int);
|
||||
|
||||
#define args_shift(_nr) \
|
||||
do { \
|
||||
|
Loading…
Reference in New Issue
Block a user