]> err.no Git - util-linux/commitdiff
libblkid: add blkid_probe_get_{size,sectorsize,devno}
authorKarel Zak <kzak@redhat.com>
Tue, 15 Sep 2009 20:50:11 +0000 (22:50 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 16 Sep 2009 08:57:23 +0000 (10:57 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
shlibs/blkid/src/blkid.h
shlibs/blkid/src/probe.c

index 40ada4dc9645c40aff1a559c2f0ace6158d33f90..a1cfe90cc74e5cde7e9fe9179294ef8025df94b0 100644 (file)
@@ -128,6 +128,11 @@ extern void blkid_reset_probe(blkid_probe pr);
 
 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 blkid_loff_t blkid_probe_get_size(blkid_probe pr);
+extern unsigned int blkid_probe_get_sectorsize(blkid_probe pr);
+
 /*
  * superblocks probing
  */
index a68881db2cc8c613e9853ccfd82d7ae345c1c722..a3d08114e304cc93a7c2e7d9c20d65bb246e6c46 100644 (file)
@@ -744,6 +744,65 @@ int blkid_probe_vsprintf_value(blkid_probe pr, const char *name,
        return 0;
 }
 
+/**
+ * blkid_probe_get_devno:
+ * @pr: probe
+ *
+ * Returns: block device number, or 0 for regilar files.
+ */
+dev_t blkid_probe_get_devno(blkid_probe pr)
+{
+       if (!pr->devno) {
+               struct stat sb;
+
+               if (fstat(pr->fd, &sb) == 0 && S_ISBLK(sb.st_mode))
+                       pr->devno = sb.st_rdev;
+       }
+       return pr->devno;
+}
+
+/**
+ * blkid_probe_get_size:
+ * @pr: probe
+ *
+ * Returns: block device (or file) size in bytes or -1 in case of error.
+ */
+blkid_loff_t blkid_probe_get_size(blkid_probe pr)
+{
+       return pr ? pr->size : -1;
+}
+
+/**
+ * blkid_probe_get_sectorsize:
+ * @pr: probe
+ *
+ * Returns: block device hardware sector size (BLKSSZGET ioctl, default 512).
+ */
+unsigned int blkid_probe_get_sectorsize(blkid_probe pr)
+{
+       if (!pr)
+               return DEFAULT_SECTOR_SIZE;  /*... and good luck! */
+       if (pr->blkssz)
+               return pr->blkssz;
+       if (!pr->mode) {
+               struct stat st;
+
+               if (fstat(pr->fd, &st))
+                       goto fallback;
+               pr->mode = st.st_mode;
+       }
+       if (S_ISBLK(pr->mode)) {
+           if (blkdev_get_sector_size(pr->fd, (int *) &pr->blkssz))
+               goto fallback;
+
+           return pr->blkssz;
+       }
+
+fallback:
+       pr->blkssz = DEFAULT_SECTOR_SIZE;
+       return pr->blkssz;
+}
+
 /**
  * blkid_probe_numof_values:
  * @pr: probe