Whamcloud - gitweb
libblkid: Strengthen the JFS probe routine
authorTheodore Ts'o <tytso@mit.edu>
Sun, 24 Aug 2008 02:27:22 +0000 (22:27 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Sun, 24 Aug 2008 21:29:33 +0000 (17:29 -0400)
Check to make sure a JFS filesystem is really correct by checking the
relationship between the following fields in the JFS superblock:
s_bsize, s_l2bsize, s_pbsize, s_l2pbsize, and s_l2bfactor.  Thanks to
Lesh Bogdanow for this suggestion.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
lib/blkid/probe.c
lib/blkid/probe.h

index 225116a..92052e1 100644 (file)
@@ -780,6 +780,16 @@ static int probe_jfs(struct blkid_probe *probe,
 
        js = (struct jfs_super_block *)buf;
 
+       if (blkid_le32(js->js_bsize) != (1 << blkid_le16(js->js_l2bsize)))
+               return 1;
+
+       if (blkid_le32(js->js_pbsize) != (1 << blkid_le16(js->js_l2pbsize)))
+               return 1;
+
+       if ((blkid_le16(js->js_l2bsize) - blkid_le16(js->js_l2pbsize)) !=
+           blkid_le16(js->js_l2bfactor))
+               return 1;
+
        if (strlen((char *) js->js_label))
                label = (char *) js->js_label;
        blkid_set_tag(probe->dev, "LABEL", label, sizeof(js->js_label));
index ac3a083..993156d 100644 (file)
@@ -181,10 +181,13 @@ struct jfs_super_block {
        unsigned char   js_magic[4];
        __u32           js_version;
        __u64           js_size;
-       __u32           js_bsize;
-       __u32           js_dummy1;
-       __u32           js_pbsize;
-       __u32           js_dummy2[27];
+       __u32           js_bsize;       /* 4: aggregate block size in bytes */
+       __u16           js_l2bsize;     /* 2: log2 of s_bsize */
+       __u16           js_l2bfactor;   /* 2: log2(s_bsize/hardware block size) */
+       __u32           js_pbsize;      /* 4: hardware/LVM block size in bytes */
+       __u16           js_l2pbsize;    /* 2: log2 of s_pbsize */
+       __u16           js_pad;         /* 2: padding necessary for alignment */
+       __u32           js_dummy2[26];
        unsigned char   js_uuid[16];
        unsigned char   js_label[16];
        unsigned char   js_loguuid[16];