diff options
author | Karel Zak | 2010-10-15 01:32:13 +0200 |
---|---|---|
committer | Karel Zak | 2010-10-15 01:32:13 +0200 |
commit | c76e710bc70bb89971c44e971e62793f34953d71 (patch) | |
tree | 4940d0d6d613485f60e78794b0cab4bcf65c3777 /shlibs/blkid/src/probe.c | |
parent | partx: integrate support for mac and sun partitions, based on kpartx. (diff) | |
download | kernel-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/probe.c')
-rw-r--r-- | shlibs/blkid/src/probe.c | 39 |
1 files changed, 39 insertions, 0 deletions
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) { |