libblkid: export info about PT magic strings

Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
Karel Zak 2011-11-13 21:25:12 +01:00
parent 3c83b3b22f
commit 44765fdd84
5 changed files with 80 additions and 43 deletions

View File

@ -26,6 +26,7 @@
/* Signature - “EFI PART” */ /* Signature - “EFI PART” */
#define GPT_HEADER_SIGNATURE 0x5452415020494645ULL #define GPT_HEADER_SIGNATURE 0x5452415020494645ULL
#define GPT_HEADER_SIGNATURE_STR "EFI PART"
/* basic types */ /* basic types */
typedef uint16_t efi_char16_t; typedef uint16_t efi_char16_t;
@ -326,6 +327,10 @@ static int probe_gpt_pt(blkid_probe pr,
if (!tab) if (!tab)
goto err; goto err;
blkid_probe_set_magic(pr, lba << 9,
sizeof(GPT_HEADER_SIGNATURE_STR) - 1,
(unsigned char *) GPT_HEADER_SIGNATURE_STR);
ssf = blkid_probe_get_sectorsize(pr) / 512; ssf = blkid_probe_get_sectorsize(pr) / 512;
fu = le64_to_cpu(h->first_usable_lba); fu = le64_to_cpu(h->first_usable_lba);

View File

@ -530,15 +530,17 @@ int blkid_is_nested_dimension(blkid_partition par,
return 1; return 1;
} }
static int idinfo_probe(blkid_probe pr, const struct blkid_idinfo *id) static int idinfo_probe(blkid_probe pr, const struct blkid_idinfo *id,
struct blkid_chain *chn)
{ {
const struct blkid_idmag *mag; const struct blkid_idmag *mag;
blkid_loff_t off;
int rc = 1; /* = nothing detected */ int rc = 1; /* = nothing detected */
if (pr->size <= 0 || (id->minsz && id->minsz > pr->size)) if (pr->size <= 0 || (id->minsz && id->minsz > pr->size))
goto nothing; /* the device is too small */ goto nothing; /* the device is too small */
if (blkid_probe_get_idmag(pr, id, NULL, &mag)) if (blkid_probe_get_idmag(pr, id, &off, &mag))
goto nothing; goto nothing;
/* final check by probing function */ /* final check by probing function */
@ -549,9 +551,15 @@ static int idinfo_probe(blkid_probe pr, const struct blkid_idinfo *id)
if (rc == -1) { if (rc == -1) {
/* reset after error */ /* reset after error */
reset_partlist(blkid_probe_get_partlist(pr)); reset_partlist(blkid_probe_get_partlist(pr));
if (chn && !chn->binary)
blkid_probe_chain_reset_vals(pr, chn);
DBG(DEBUG_LOWPROBE, printf( DBG(DEBUG_LOWPROBE, printf(
"%s probefunc failed\n", id->name)); "%s probefunc failed\n", id->name));
} }
if (rc == 0 && mag && chn && !chn->binary)
blkid_probe_set_magic(pr, off, mag->len,
(unsigned char *) mag->magic);
DBG(DEBUG_LOWPROBE, printf( DBG(DEBUG_LOWPROBE, printf(
"%s: <--- (rc = %d)\n", id->name, rc)); "%s: <--- (rc = %d)\n", id->name, rc));
} }
@ -594,7 +602,7 @@ static int partitions_probe(blkid_probe pr, struct blkid_chain *chn)
continue; continue;
/* apply checks from idinfo */ /* apply checks from idinfo */
if (idinfo_probe(pr, idinfos[i]) != 0) if (idinfo_probe(pr, idinfos[i], chn) != 0)
continue; continue;
name = idinfos[i]->name; name = idinfos[i]->name;
@ -678,7 +686,7 @@ int blkid_partitions_do_subprobe(blkid_probe pr, blkid_partition parent,
blkid_probe_set_partlist(prc, ls); blkid_probe_set_partlist(prc, ls);
rc = idinfo_probe(prc, id); rc = idinfo_probe(prc, id, blkid_probe_get_chain(pr));
blkid_probe_set_partlist(prc, NULL); blkid_probe_set_partlist(prc, NULL);
blkid_partlist_set_parent(ls, NULL); blkid_partlist_set_parent(ls, NULL);

View File

@ -15,7 +15,9 @@
#include "partitions.h" #include "partitions.h"
#define ULTRIX_MAXPARTITIONS 8 #define ULTRIX_MAXPARTITIONS 8
#define ULTRIX_MAGIC 0x032957 #define ULTRIX_MAGIC 0x032957
#define ULTRIX_MAGIC_STR "\x02\x29\x57"
/* sector with partition table */ /* sector with partition table */
#define ULTRIX_SECTOR ((16384 - sizeof(struct ultrix_disklabel)) >> 9) #define ULTRIX_SECTOR ((16384 - sizeof(struct ultrix_disklabel)) >> 9)
@ -62,6 +64,10 @@ static int probe_ultrix_pt(blkid_probe pr,
if (!tab) if (!tab)
goto err; goto err;
blkid_probe_set_magic(pr, (ULTRIX_SECTOR << 9) + ULTRIX_OFFSET,
sizeof(ULTRIX_MAGIC_STR) - 1,
(unsigned char *) ULTRIX_MAGIC_STR);
for (i = 0; i < ULTRIX_MAXPARTITIONS; i++) { for (i = 0; i < ULTRIX_MAXPARTITIONS; i++) {
if (!l->pt_part[i].pi_nblocks) if (!l->pt_part[i].pi_nblocks)
blkid_partlist_increment_partno(ls); blkid_partlist_increment_partno(ls);

View File

@ -947,11 +947,11 @@ int blkid_do_probe(blkid_probe pr)
*/ */
int blkid_do_wipe(blkid_probe pr, int dryrun) int blkid_do_wipe(blkid_probe pr, int dryrun)
{ {
const char *off; const char *off = NULL;
size_t len = 0; size_t len = 0;
loff_t offset, l; loff_t offset, l;
char buf[BUFSIZ]; char buf[BUFSIZ];
int fd; int fd, rc;
struct blkid_chain *chn; struct blkid_chain *chn;
if (!pr) if (!pr)
@ -961,9 +961,22 @@ int blkid_do_wipe(blkid_probe pr, int dryrun)
if (!chn) if (!chn)
return -1; return -1;
if (blkid_probe_lookup_value(pr, "SBMAGIC_OFFSET", &off, NULL) || switch (chn->driver->id) {
blkid_probe_lookup_value(pr, "SBMAGIC", NULL, &len) || case BLKID_CHAIN_SUBLKS:
len == 0 || off == NULL) rc = blkid_probe_lookup_value(pr, "SBMAGIC_OFFSET", &off, NULL);
if (!rc)
rc = blkid_probe_lookup_value(pr, "SBMAGIC", NULL, &len);
break;
case BLKID_CHAIN_PARTS:
rc = blkid_probe_lookup_value(pr, "PTMAGIC_OFFSET", &off, NULL);
if (!rc)
rc = blkid_probe_lookup_value(pr, "PTMAGIC", NULL, &len);
break;
default:
return 0;
}
if (rc || len == 0 || off == NULL)
return 0; return 0;
offset = strtoll(off, NULL, 10); offset = strtoll(off, NULL, 10);

View File

@ -142,35 +142,51 @@ add_offset(struct wipe_desc *wp0, loff_t offset, int zap)
static struct wipe_desc * static struct wipe_desc *
get_desc_for_probe(struct wipe_desc *wp, blkid_probe pr) get_desc_for_probe(struct wipe_desc *wp, blkid_probe pr)
{ {
const char *off, *type, *usage, *mag; const char *off, *type, *mag, *p, *usage = NULL;
size_t len; size_t len;
loff_t offset;
int rc;
if (blkid_probe_lookup_value(pr, "TYPE", &type, NULL) == 0 && /* superblocks */
blkid_probe_lookup_value(pr, "SBMAGIC_OFFSET", &off, NULL) == 0 && if (blkid_probe_lookup_value(pr, "TYPE", &type, NULL) == 0) {
blkid_probe_lookup_value(pr, "SBMAGIC", &mag, &len) == 0 && rc = blkid_probe_lookup_value(pr, "SBMAGIC_OFFSET", &off, NULL);
blkid_probe_lookup_value(pr, "USAGE", &usage, NULL) == 0) { if (!rc)
rc = blkid_probe_lookup_value(pr, "SBMAGIC", &mag, &len);
if (rc)
return wp;
loff_t offset = strtoll(off, NULL, 10); /* partitions */
const char *p; } else if (blkid_probe_lookup_value(pr, "PTTYPE", &type, NULL) == 0) {
rc = blkid_probe_lookup_value(pr, "PTMAGIC_OFFSET", &off, NULL);
if (!rc)
rc = blkid_probe_lookup_value(pr, "PTMAGIC", &mag, &len);
if (rc)
return wp;
usage = "partition table";
} else
return wp;
wp = add_offset(wp, offset, 0); offset = strtoll(off, NULL, 10);
if (!wp)
return NULL;
wp = add_offset(wp, offset, 0);
if (!wp)
return NULL;
if (usage || blkid_probe_lookup_value(pr, "USAGE", &usage, NULL) == 0)
wp->usage = xstrdup(usage); wp->usage = xstrdup(usage);
wp->type = xstrdup(type);
wp->on_disk = 1;
wp->magic = xmalloc(len); wp->type = xstrdup(type);
memcpy(wp->magic, mag, len); wp->on_disk = 1;
wp->len = len;
if (blkid_probe_lookup_value(pr, "LABEL", &p, NULL) == 0) wp->magic = xmalloc(len);
wp->label = xstrdup(p); memcpy(wp->magic, mag, len);
wp->len = len;
if (blkid_probe_lookup_value(pr, "UUID", &p, NULL) == 0) if (blkid_probe_lookup_value(pr, "LABEL", &p, NULL) == 0)
wp->uuid = xstrdup(p); wp->label = xstrdup(p);
}
if (blkid_probe_lookup_value(pr, "UUID", &p, NULL) == 0)
wp->uuid = xstrdup(p);
return wp; return wp;
} }
@ -179,7 +195,6 @@ static blkid_probe
new_probe(const char *devname, int mode) new_probe(const char *devname, int mode)
{ {
blkid_probe pr; blkid_probe pr;
int rc;
if (!devname) if (!devname)
return NULL; return NULL;
@ -198,24 +213,14 @@ new_probe(const char *devname, int mode)
if (!pr) if (!pr)
goto error; goto error;
blkid_probe_enable_superblocks(pr, 0); /* enabled by default ;-( */
blkid_probe_enable_partitions(pr, 1);
rc = blkid_do_fullprobe(pr);
blkid_probe_enable_partitions(pr, 0);
if (rc == 0) {
const char *type = NULL;
blkid_probe_lookup_value(pr, "PTTYPE", &type, NULL);
warnx(_("WARNING: %s: appears to contain '%s' "
"partition table"), devname, type);
}
blkid_probe_enable_superblocks(pr, 1); blkid_probe_enable_superblocks(pr, 1);
blkid_probe_set_superblocks_flags(pr, BLKID_SUBLKS_MAGIC | blkid_probe_set_superblocks_flags(pr, BLKID_SUBLKS_MAGIC |
BLKID_SUBLKS_TYPE | BLKID_SUBLKS_USAGE | BLKID_SUBLKS_TYPE | BLKID_SUBLKS_USAGE |
BLKID_SUBLKS_LABEL | BLKID_SUBLKS_UUID); BLKID_SUBLKS_LABEL | BLKID_SUBLKS_UUID);
blkid_probe_enable_partitions(pr, 1);
blkid_probe_set_partitions_flags(pr, BLKID_PARTS_MAGIC);
return pr; return pr;
error: error:
err(EXIT_FAILURE, _("error: %s: probing initialization failed"), devname); err(EXIT_FAILURE, _("error: %s: probing initialization failed"), devname);