mirror of
https://github.com/koverstreet/bcachefs-tools.git
synced 2025-12-10 00:00:24 +03:00
cmd_show_super: Fix device model printing
Make device partition handling independent of the current directory and simplify code. Use better model placeholders: "(image file)" and "(unknown model)". Signed-off-by: Nikita Ofitserov <himikof@gmail.com>
This commit is contained in:
parent
608ccdd381
commit
a4f2c56ed4
@ -632,27 +632,20 @@ char *fd_to_dev_model(int fd)
|
|||||||
|
|
||||||
/* partition? try parent */
|
/* partition? try parent */
|
||||||
|
|
||||||
char buf[1024];
|
model_path = mprintf("%s/../device/model", sysfs_path);
|
||||||
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))
|
if (!access(model_path, R_OK))
|
||||||
goto got_model;
|
goto got_model;
|
||||||
|
free(model_path);
|
||||||
|
|
||||||
return strdup("(unknown device)");
|
free(sysfs_path);
|
||||||
char *model;
|
return strdup("(unknown model)");
|
||||||
got_model:
|
got_model:
|
||||||
model = read_file_str(AT_FDCWD, model_path);
|
char* model = read_file_str(AT_FDCWD, model_path);
|
||||||
free(model_path);
|
free(model_path);
|
||||||
free(sysfs_path);
|
free(sysfs_path);
|
||||||
return model;
|
return model;
|
||||||
} else {
|
} else {
|
||||||
return strdup("(reg file)");
|
return strdup("(image file)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user