From: Karel Zak Date: Mon, 19 Apr 2010 08:51:37 +0000 (+0200) Subject: libblkid: export functions to get whole-disk devno X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=601fb1c11e8b93c3b0e7488a73b4e97df12c676d;p=util-linux libblkid: export functions to get whole-disk devno Signed-off-by: Karel Zak --- diff --git a/shlibs/blkid/src/blkid.h.in b/shlibs/blkid/src/blkid.h.in index 07001a3a..fc744b13 100644 --- a/shlibs/blkid/src/blkid.h.in +++ b/shlibs/blkid/src/blkid.h.in @@ -197,6 +197,9 @@ extern int blkid_probe_set_device(blkid_probe pr, int fd, blkid_loff_t off, blkid_loff_t size); extern dev_t blkid_probe_get_devno(blkid_probe pr); +extern dev_t blkid_probe_get_wholedisk_devno(blkid_probe pr); +extern int blkid_probe_is_wholedisk(blkid_probe pr); + extern blkid_loff_t blkid_probe_get_size(blkid_probe pr); extern blkid_loff_t blkid_probe_get_offset(blkid_probe pr); extern unsigned int blkid_probe_get_sectorsize(blkid_probe pr); diff --git a/shlibs/blkid/src/blkid.sym b/shlibs/blkid/src/blkid.sym index a80e8739..e6a1e36e 100644 --- a/shlibs/blkid/src/blkid.sym +++ b/shlibs/blkid/src/blkid.sym @@ -125,4 +125,6 @@ global: blkid_probe_all_removable; blkid_probe_get_fd; blkid_probe_get_offset; + blkid_probe_get_wholedisk_devno; + blkid_probe_is_wholedisk; } BLKID_2.17; diff --git a/shlibs/blkid/src/blkidP.h b/shlibs/blkid/src/blkidP.h index b15c7f9b..c37f7306 100644 --- a/shlibs/blkid/src/blkidP.h +++ b/shlibs/blkid/src/blkidP.h @@ -191,6 +191,7 @@ struct blkid_struct_probe blkid_loff_t size; /* end of data on the device */ dev_t devno; /* device number (st.st_rdev) */ + dev_t disk_devno; /* devno of the whole-disk or 0 */ unsigned int blkssz; /* sector size (BLKSSZGET ioctl) */ mode_t mode; /* struct stat.sb_mode */ diff --git a/shlibs/blkid/src/partitions/partitions.c b/shlibs/blkid/src/partitions/partitions.c index ad0c2f8c..293ee86a 100644 --- a/shlibs/blkid/src/partitions/partitions.c +++ b/shlibs/blkid/src/partitions/partitions.c @@ -694,7 +694,8 @@ static int blkid_partitions_probe_partition(blkid_probe pr) if (!devno) goto nothing; - if (blkid_devno_to_wholedisk(devno, NULL, 0, &disk_devno)) + disk_devno = blkid_probe_get_wholedisk_devno(pr); + if (!disk_devno) goto nothing; if (devno == disk_devno) diff --git a/shlibs/blkid/src/probe.c b/shlibs/blkid/src/probe.c index 3c6e6948..6d58d5ae 100644 --- a/shlibs/blkid/src/probe.c +++ b/shlibs/blkid/src/probe.c @@ -993,6 +993,48 @@ dev_t blkid_probe_get_devno(blkid_probe pr) return pr->devno; } +/** + * blkid_probe_get_wholedisk_devno: + * @pr: probe + * + * Returns: device number of the wholedisk, or 0 for regilar files. + */ +dev_t blkid_probe_get_wholedisk_devno(blkid_probe pr) +{ + if (!pr->disk_devno) { + dev_t devno, disk_devno = 0; + + devno = blkid_probe_get_devno(pr); + if (!devno) + return 0; + + if (blkid_devno_to_wholedisk(devno, NULL, 0, &disk_devno) == 0) + pr->disk_devno = disk_devno; + } + return pr->disk_devno; +} + +/** + * blkid_probe_is_wholedisk: + * @pr: probe + * + * Returns: 1 if the device is whole-disk or 0. + */ +int blkid_probe_is_wholedisk(blkid_probe pr) +{ + dev_t devno, disk_devno; + + devno = blkid_probe_get_devno(pr); + if (!devno) + return 0; + + disk_devno = blkid_probe_get_wholedisk_devno(pr); + if (!disk_devno) + return 0; + + return devno == disk_devno; +} + /** * blkid_probe_get_size: * @pr: probe