]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib/sysfs: add function to detect partitioned devices
authorKarel Zak <kzak@redhat.com>
Tue, 16 Oct 2018 13:52:13 +0000 (15:52 +0200)
committerKarel Zak <kzak@redhat.com>
Fri, 7 Dec 2018 11:32:57 +0000 (12:32 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
include/sysfs.h
lib/sysfs.c

index 74f69fb9cb80c1f65085abca4be02f93b4c9807f..edda8ca991a5a415786787ebd94ad6639c0512ca 100644 (file)
@@ -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,
index 626451bddb3efa62492ef9c29013d545afa7b020..6916c2584d47165c5ca622cd57acc85ad42fa2b2 100644 (file)
@@ -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