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:
Nikita Ofitserov 2025-09-28 03:12:22 +03:00
parent 608ccdd381
commit a4f2c56ed4

View File

@ -632,27 +632,20 @@ char *fd_to_dev_model(int fd)
/* 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);
model_path = mprintf("%s/../device/model", sysfs_path);
if (!access(model_path, R_OK))
goto got_model;
free(model_path);
return strdup("(unknown device)");
char *model;
free(sysfs_path);
return strdup("(unknown model)");
got_model:
model = read_file_str(AT_FDCWD, model_path);
char* model = read_file_str(AT_FDCWD, model_path);
free(model_path);
free(sysfs_path);
return model;
} else {
return strdup("(reg file)");
return strdup("(image file)");
}
}