From: Karel Zak Date: Tue, 16 Oct 2018 13:52:13 +0000 (+0200) Subject: lib/sysfs: add function to detect partitioned devices X-Git-Tag: v2.34-rc1~219 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=93c687d895752582bd95ef52a53684b346f2cc70;p=thirdparty%2Futil-linux.git lib/sysfs: add function to detect partitioned devices Signed-off-by: Karel Zak --- diff --git a/include/sysfs.h b/include/sysfs.h index 74f69fb9cb..edda8ca991 100644 --- a/include/sysfs.h +++ b/include/sysfs.h @@ -97,6 +97,7 @@ dev_t sysfs_devname_to_devno(const char *name); dev_t __sysfs_devname_to_devno(const char *prefix, const char *name, const char *parent); char *sysfs_devno_to_devpath(dev_t devno, char *buf, size_t bufsiz); char *sysfs_devno_to_devname(dev_t devno, char *buf, size_t bufsiz); +int sysfs_devno_count_partitions(dev_t devno); int sysfs_blkdev_scsi_get_hctl(struct path_cxt *pc, int *h, int *c, int *t, int *l); char *sysfs_blkdev_scsi_host_strdup_attribute(struct path_cxt *pc, diff --git a/lib/sysfs.c b/lib/sysfs.c index 626451bddb..6916c2584d 100644 --- a/lib/sysfs.c +++ b/lib/sysfs.c @@ -999,6 +999,20 @@ char *sysfs_devno_to_devname(dev_t devno, char *buf, size_t bufsiz) return res; } +int sysfs_devno_count_partitions(dev_t devno) +{ + struct path_cxt *pc = ul_new_sysfs_path(devno, NULL, NULL); + int n = 0; + + if (pc) { + char buf[PATH_MAX + 1]; + char *name = sysfs_blkdev_get_name(pc, buf, sizeof(buf)); + + n = sysfs_blkdev_count_partitions(pc, name); + ul_unref_path(pc); + } + return n; +} #ifdef TEST_PROGRAM_SYSFS