summaryrefslogtreecommitdiffstats
path: root/shlibs/blkid/src
diff options
context:
space:
mode:
authorKarel Zak2010-10-15 01:32:13 +0200
committerKarel Zak2010-10-15 01:32:13 +0200
commitc76e710bc70bb89971c44e971e62793f34953d71 (patch)
tree4940d0d6d613485f60e78794b0cab4bcf65c3777 /shlibs/blkid/src
parentpartx: integrate support for mac and sun partitions, based on kpartx. (diff)
downloadkernel-qcow2-util-linux-c76e710bc70bb89971c44e971e62793f34953d71.tar.gz
kernel-qcow2-util-linux-c76e710bc70bb89971c44e971e62793f34953d71.tar.xz
kernel-qcow2-util-linux-c76e710bc70bb89971c44e971e62793f34953d71.zip
libblkid: consolidate magic strings detection code
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'shlibs/blkid/src')
-rw-r--r--shlibs/blkid/src/blkidP.h3
-rw-r--r--shlibs/blkid/src/partitions/partitions.c25
-rw-r--r--shlibs/blkid/src/probe.c39
-rw-r--r--shlibs/blkid/src/superblocks/superblocks.c28
4 files changed, 46 insertions, 49 deletions
diff --git a/shlibs/blkid/src/blkidP.h b/shlibs/blkid/src/blkidP.h
index 41eba9102..6ac8910cc 100644
--- a/shlibs/blkid/src/blkidP.h
+++ b/shlibs/blkid/src/blkidP.h
@@ -386,6 +386,9 @@ extern int blkid_probe_get_dimension(blkid_probe pr,
extern int blkid_probe_set_dimension(blkid_probe pr,
blkid_loff_t off, blkid_loff_t size);
+extern int blkid_probe_get_idmag(blkid_probe pr, const struct blkid_idinfo *id,
+ blkid_loff_t *offset, const struct blkid_idmag **res);
+
/* returns superblok according to 'struct blkid_idmag' */
#define blkid_probe_get_sb(_pr, _mag, type) \
((type *) blkid_probe_get_buffer((_pr),\
diff --git a/shlibs/blkid/src/partitions/partitions.c b/shlibs/blkid/src/partitions/partitions.c
index d6abc203d..5b34d037e 100644
--- a/shlibs/blkid/src/partitions/partitions.c
+++ b/shlibs/blkid/src/partitions/partitions.c
@@ -515,35 +515,12 @@ int blkid_is_nested_dimension(blkid_partition par,
static int idinfo_probe(blkid_probe pr, const struct blkid_idinfo *id)
{
const struct blkid_idmag *mag;
- int hasmag = 0;
int rc = 1; /* = nothing detected */
if (pr->size <= 0 || (id->minsz && id->minsz > pr->size))
goto nothing; /* the device is too small */
- mag = id->magics ? &id->magics[0] : NULL;
-
- /* try to detect by magic string */
- while(mag && mag->magic) {
- int idx;
- unsigned char *buf;
-
- idx = mag->kboff + (mag->sboff >> 10);
- buf = blkid_probe_get_buffer(pr, idx << 10, 1024);
-
- if (buf && !memcmp(mag->magic,
- buf + (mag->sboff & 0x3ff), mag->len)) {
- DBG(DEBUG_LOWPROBE, printf(
- "%s: magic sboff=%u, kboff=%ld\n",
- id->name, mag->sboff, mag->kboff));
- hasmag = 1;
- break;
- }
- mag++;
- }
-
- if (hasmag == 0 && id->magics && id->magics[0].magic)
- /* magic string(s) defined, but not found */
+ if (blkid_probe_get_idmag(pr, id, NULL, &mag))
goto nothing;
/* final check by probing function */
diff --git a/shlibs/blkid/src/probe.c b/shlibs/blkid/src/probe.c
index 9353ecd2e..a748f2e24 100644
--- a/shlibs/blkid/src/probe.c
+++ b/shlibs/blkid/src/probe.c
@@ -714,6 +714,45 @@ int blkid_probe_set_dimension(blkid_probe pr,
return 0;
}
+int blkid_probe_get_idmag(blkid_probe pr, const struct blkid_idinfo *id,
+ blkid_loff_t *offset, const struct blkid_idmag **res)
+{
+ const struct blkid_idmag *mag = NULL;
+ blkid_loff_t off = 0;
+
+ if (id)
+ mag = id->magics ? &id->magics[0] : NULL;
+ if (res)
+ *res = NULL;
+
+ /* try to detect by magic string */
+ while(mag && mag->magic) {
+ unsigned char *buf;
+
+ 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)) {
+ DBG(DEBUG_LOWPROBE, printf(
+ "\tmagic sboff=%u, kboff=%ld\n",
+ mag->sboff, mag->kboff));
+ if (offset)
+ *offset = off + (mag->sboff & 0x3ff);
+ if (res)
+ *res = mag;
+ return 0;
+ }
+ mag++;
+ }
+
+ if (id->magics && id->magics[0].magic)
+ /* magic string(s) defined, but not found */
+ return 1;
+
+ return 0;
+}
+
static inline void blkid_probe_start(blkid_probe pr)
{
if (pr) {
diff --git a/shlibs/blkid/src/superblocks/superblocks.c b/shlibs/blkid/src/superblocks/superblocks.c
index 95c10d6eb..268b2d9b7 100644
--- a/shlibs/blkid/src/superblocks/superblocks.c
+++ b/shlibs/blkid/src/superblocks/superblocks.c
@@ -322,11 +322,9 @@ 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;
+ const struct blkid_idmag *mag = NULL;
blkid_loff_t off = 0;
- int hasmag = 0;
-
chn->idx = i;
if (chn->fltr && blkid_bmp_get_item(chn->fltr, i))
@@ -351,27 +349,7 @@ static int superblocks_probe(blkid_probe pr, struct blkid_chain *chn)
DBG(DEBUG_LOWPROBE, printf("[%d] %s:\n", i, id->name));
- /* try to detect by magic string */
- while(mag && mag->magic) {
- unsigned char *buf;
-
- 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)) {
- DBG(DEBUG_LOWPROBE, printf(
- "\tmagic sboff=%u, kboff=%ld\n",
- mag->sboff, mag->kboff));
- hasmag = 1;
- off += mag->sboff & 0x3ff;
- break;
- }
- mag++;
- }
-
- if (hasmag == 0 && id->magics && id->magics[0].magic)
- /* magic string(s) defined, but not found */
+ if (blkid_probe_get_idmag(pr, id, &off, &mag))
continue;
/* final check by probing function */
@@ -391,7 +369,7 @@ static int superblocks_probe(blkid_probe pr, struct blkid_chain *chn)
blkid_probe_set_usage(pr, id->usage);
- if (hasmag)
+ if (mag)
blkid_probe_set_magic(pr, off, mag->len,
(unsigned char *) mag->magic);