From: Karel Zak Date: Tue, 29 Sep 2009 13:59:34 +0000 (+0200) Subject: libblkid: add support for SBMAGIC and SBMAGIC_OFFSET X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=92838067f3c3ac92cd1754341f72e0857d1f822c;p=util-linux libblkid: add support for SBMAGIC and SBMAGIC_OFFSET Signed-off-by: Karel Zak --- diff --git a/shlibs/blkid/src/blkid.h b/shlibs/blkid/src/blkid.h index 057e3130..9ab99c2f 100644 --- a/shlibs/blkid/src/blkid.h +++ b/shlibs/blkid/src/blkid.h @@ -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) diff --git a/shlibs/blkid/src/blkidP.h b/shlibs/blkid/src/blkidP.h index d09529ef..86b2b096 100644 --- a/shlibs/blkid/src/blkidP.h +++ b/shlibs/blkid/src/blkidP.h @@ -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 */ }; /* diff --git a/shlibs/blkid/src/superblocks/superblocks.c b/shlibs/blkid/src/superblocks/superblocks.c index 46d9494a..f3287368 100644 --- a/shlibs/blkid/src/superblocks/superblocks.c +++ b/shlibs/blkid/src/superblocks/superblocks.c @@ -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));