From: Thomas Weißschuh Date: Wed, 11 Jan 2023 18:13:50 +0000 (+0000) Subject: lib/sysfs: add function blkdev_is_removable X-Git-Tag: v2.39-rc1~121 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=216d8b054f7b4ccc80afbba4b7e4f96ccda11379;p=thirdparty%2Futil-linux.git lib/sysfs: add function blkdev_is_removable This exactly represents the kernels notion of a "removable" blockdevice. That is, the device itself is persistent but can contain some sort of medium that can be changed at runtime. Specifically it is *not* hotpluggable. --- diff --git a/include/sysfs.h b/include/sysfs.h index ad6b609f2a..8d77f75798 100644 --- a/include/sysfs.h +++ b/include/sysfs.h @@ -87,6 +87,7 @@ char *sysfs_blkdev_get_devchain(struct path_cxt *pc, char *buf, size_t bufsz); int sysfs_blkdev_next_subsystem(struct path_cxt *pc __attribute__((unused)), char *devchain, char **subsys); int sysfs_blkdev_is_hotpluggable(struct path_cxt *pc); +int sysfs_blkdev_is_removable(struct path_cxt *pc); int sysfs_blkdev_get_wholedisk( struct path_cxt *pc, char *diskname, size_t len, diff --git a/lib/sysfs.c b/lib/sysfs.c index 92a7e290b0..f325359560 100644 --- a/lib/sysfs.c +++ b/lib/sysfs.c @@ -465,7 +465,7 @@ int sysfs_blkdev_is_hotpluggable(struct path_cxt *pc) int rc = 0; - /* check /sys/dev/block/:/removable attribute */ + /* check /sys/devices/.../removable attribute */ if (ul_path_read_s32(pc, &rc, "removable") == 0 && rc == 1) return 1; @@ -483,6 +483,17 @@ int sysfs_blkdev_is_hotpluggable(struct path_cxt *pc) return rc; } +int sysfs_blkdev_is_removable(struct path_cxt *pc) +{ + int rc = 0; + + /* check /sys/dev/block/:/removable attribute */ + if (ul_path_read_s32(pc, &rc, "removable") == 0) + return rc; + + return 0; +} + static int get_dm_wholedisk(struct path_cxt *pc, char *diskname, size_t len, dev_t *diskdevno) { @@ -1182,6 +1193,7 @@ int main(int argc, char *argv[]) } printf(" HOTPLUG: %s\n", sysfs_blkdev_is_hotpluggable(pc) ? "yes" : "no"); + printf(" REMOVABLE: %s\n", sysfs_blkdev_is_removable(pc) ? "yes" : "no"); printf(" SLAVES: %d\n", ul_path_count_dirents(pc, "slaves")); if (!is_part) {