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),\
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 */
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) {
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))
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 */
blkid_probe_set_usage(pr, id->usage);
- if (hasmag)
+ if (mag)
blkid_probe_set_magic(pr, off, mag->len,
(unsigned char *) mag->magic);