]> err.no Git - util-linux/commitdiff
libblkid: add support for SBMAGIC and SBMAGIC_OFFSET
authorKarel Zak <kzak@redhat.com>
Tue, 29 Sep 2009 13:59:34 +0000 (15:59 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 29 Sep 2009 13:59:34 +0000 (15:59 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
shlibs/blkid/src/blkid.h
shlibs/blkid/src/blkidP.h
shlibs/blkid/src/superblocks/superblocks.c

index 057e31303d1d816b69820082fc6a395b8387ed57..9ab99c2ff385bb030d9f4d1ea61b44b0b8672f95 100644 (file)
@@ -209,6 +209,7 @@ extern int blkid_probe_enable_superblocks(blkid_probe pr, int enable);
 #define BLKID_SUBLKS_SECTYPE   (1 << 6) /* define compatible fs type (second type) */
 #define BLKID_SUBLKS_USAGE     (1 << 7) /* define USAGE result value */
 #define BLKID_SUBLKS_VERSION   (1 << 8) /* read FS type from superblock */
+#define BLKID_SUBLKS_MAGIC     (1 << 9) /* define SBMAGIC and SBMAGIC_OFFSET */
 
 #define BLKID_SUBLKS_DEFAULT   (BLKID_SUBLKS_LABEL | BLKID_SUBLKS_UUID | \
                                 BLKID_SUBLKS_TYPE | BLKID_SUBLKS_SECTYPE)
index d09529ef62d271ef1bf826a136526fbbd53912cb..86b2b096106bc11a6df9d8ca9fd10975099f04de 100644 (file)
@@ -134,7 +134,7 @@ struct blkid_chaindrv {
  */
 #define BLKID_PROBVAL_BUFSIZ   64
 
-#define BLKID_NVALS_SUBLKS     10
+#define BLKID_NVALS_SUBLKS     12
 #define BLKID_NVALS_TOPLGY     3
 #define BLKID_NVALS_PARTS      1
 
@@ -160,10 +160,10 @@ struct blkid_prval
 struct blkid_idmag
 {
        const char      *magic;         /* magic string */
-       unsigned        len;            /* length of magic */
+       unsigned int    len;            /* length of magic */
 
        long            kboff;          /* kilobyte offset of superblock */
-       unsigned        sboff;          /* byte offset within superblock */
+       unsigned int    sboff;          /* byte offset within superblock */
 };
 
 /*
index 46d9494abfb972af8380c4d5471e76c1a449c904..f32873682aaabb68b8968b9dcffaa474db1b4c70 100644 (file)
@@ -60,9 +60,9 @@
  *
  * @MOUNT: cluster mount name (?) -- ocfs only
  *
- * @SBMAGIC: super block magic string [not-implemented yet]
+ * @SBMAGIC: super block magic string
  *
- * @SBOFFSET: offset of superblock [not-implemented yet]
+ * @SBMAGIC_OFFSET: offset of SBMAGIC
  *
  * @FSSIZE: size of filessystem [not-implemented yet]
  */
@@ -310,6 +310,8 @@ static int superblocks_probe(blkid_probe pr, struct blkid_chain *chn)
        for ( ; i < ARRAY_SIZE(idinfos); i++) {
                const struct blkid_idinfo *id;
                const struct blkid_idmag *mag;
+               blkid_loff_t off = 0;
+
                int hasmag = 0;
 
                chn->idx = i;
@@ -322,11 +324,10 @@ static int superblocks_probe(blkid_probe pr, struct blkid_chain *chn)
 
                /* try to detect by magic string */
                while(mag && mag->magic) {
-                       blkid_loff_t off;
                        unsigned char *buf;
 
-                       off = mag->kboff + ((blkid_loff_t) mag->sboff >> 10);
-                       buf = blkid_probe_get_buffer(pr, off << 10, 1024);
+                       off = (mag->kboff + (mag->sboff >> 10)) << 10;
+                       buf = blkid_probe_get_buffer(pr, off, 1024);
 
                        if (buf && !memcmp(mag->magic,
                                        buf + (mag->sboff & 0x3ff), mag->len)) {
@@ -334,6 +335,7 @@ static int superblocks_probe(blkid_probe pr, struct blkid_chain *chn)
                                        "%s: magic sboff=%u, kboff=%ld\n",
                                        id->name, mag->sboff, mag->kboff));
                                hasmag = 1;
+                               off += mag->sboff & 0x3ff;
                                break;
                        }
                        mag++;
@@ -356,9 +358,17 @@ static int superblocks_probe(blkid_probe pr, struct blkid_chain *chn)
                        blkid_probe_set_value(pr, "TYPE",
                                (unsigned char *) id->name,
                                strlen(id->name) + 1);
+
                if (chn->flags & BLKID_SUBLKS_USAGE)
                        blkid_probe_set_usage(pr, id->usage);
 
+               if (hasmag && (chn->flags & BLKID_SUBLKS_MAGIC)) {
+                       blkid_probe_set_value(pr, "SBMAGIC",
+                               (unsigned char *) mag->magic, mag->len);
+                       blkid_probe_sprintf_value(pr, "SBMAGIC_OFFSET",
+                               "%llu", off);
+               }
+
                DBG(DEBUG_LOWPROBE,
                        printf("<-- leaving probing loop (type=%s) [SUBLKS idx=%d]\n",
                        id->name, chn->idx));