libblkid: export info about PT magic strings
Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
parent
3c83b3b22f
commit
44765fdd84
|
@ -26,6 +26,7 @@
|
|||
|
||||
/* Signature - “EFI PART” */
|
||||
#define GPT_HEADER_SIGNATURE 0x5452415020494645ULL
|
||||
#define GPT_HEADER_SIGNATURE_STR "EFI PART"
|
||||
|
||||
/* basic types */
|
||||
typedef uint16_t efi_char16_t;
|
||||
|
@ -326,6 +327,10 @@ static int probe_gpt_pt(blkid_probe pr,
|
|||
if (!tab)
|
||||
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;
|
||||
|
||||
fu = le64_to_cpu(h->first_usable_lba);
|
||||
|
|
|
@ -530,15 +530,17 @@ int blkid_is_nested_dimension(blkid_partition par,
|
|||
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;
|
||||
blkid_loff_t off;
|
||||
int rc = 1; /* = nothing detected */
|
||||
|
||||
if (pr->size <= 0 || (id->minsz && id->minsz > pr->size))
|
||||
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;
|
||||
|
||||
/* final check by probing function */
|
||||
|
@ -549,9 +551,15 @@ static int idinfo_probe(blkid_probe pr, const struct blkid_idinfo *id)
|
|||
if (rc == -1) {
|
||||
/* reset after error */
|
||||
reset_partlist(blkid_probe_get_partlist(pr));
|
||||
if (chn && !chn->binary)
|
||||
blkid_probe_chain_reset_vals(pr, chn);
|
||||
DBG(DEBUG_LOWPROBE, printf(
|
||||
"%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(
|
||||
"%s: <--- (rc = %d)\n", id->name, rc));
|
||||
}
|
||||
|
@ -594,7 +602,7 @@ static int partitions_probe(blkid_probe pr, struct blkid_chain *chn)
|
|||
continue;
|
||||
|
||||
/* apply checks from idinfo */
|
||||
if (idinfo_probe(pr, idinfos[i]) != 0)
|
||||
if (idinfo_probe(pr, idinfos[i], chn) != 0)
|
||||
continue;
|
||||
|
||||
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);
|
||||
|
||||
rc = idinfo_probe(prc, id);
|
||||
rc = idinfo_probe(prc, id, blkid_probe_get_chain(pr));
|
||||
|
||||
blkid_probe_set_partlist(prc, NULL);
|
||||
blkid_partlist_set_parent(ls, NULL);
|
||||
|
|
|
@ -15,7 +15,9 @@
|
|||
#include "partitions.h"
|
||||
|
||||
#define ULTRIX_MAXPARTITIONS 8
|
||||
|
||||
#define ULTRIX_MAGIC 0x032957
|
||||
#define ULTRIX_MAGIC_STR "\x02\x29\x57"
|
||||
|
||||
/* sector with partition table */
|
||||
#define ULTRIX_SECTOR ((16384 - sizeof(struct ultrix_disklabel)) >> 9)
|
||||
|
@ -62,6 +64,10 @@ static int probe_ultrix_pt(blkid_probe pr,
|
|||
if (!tab)
|
||||
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++) {
|
||||
if (!l->pt_part[i].pi_nblocks)
|
||||
blkid_partlist_increment_partno(ls);
|
||||
|
|
|
@ -947,11 +947,11 @@ int blkid_do_probe(blkid_probe pr)
|
|||
*/
|
||||
int blkid_do_wipe(blkid_probe pr, int dryrun)
|
||||
{
|
||||
const char *off;
|
||||
const char *off = NULL;
|
||||
size_t len = 0;
|
||||
loff_t offset, l;
|
||||
char buf[BUFSIZ];
|
||||
int fd;
|
||||
int fd, rc;
|
||||
struct blkid_chain *chn;
|
||||
|
||||
if (!pr)
|
||||
|
@ -961,9 +961,22 @@ int blkid_do_wipe(blkid_probe pr, int dryrun)
|
|||
if (!chn)
|
||||
return -1;
|
||||
|
||||
if (blkid_probe_lookup_value(pr, "SBMAGIC_OFFSET", &off, NULL) ||
|
||||
blkid_probe_lookup_value(pr, "SBMAGIC", NULL, &len) ||
|
||||
len == 0 || off == NULL)
|
||||
switch (chn->driver->id) {
|
||||
case BLKID_CHAIN_SUBLKS:
|
||||
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;
|
||||
|
||||
offset = strtoll(off, NULL, 10);
|
||||
|
|
|
@ -142,35 +142,51 @@ add_offset(struct wipe_desc *wp0, loff_t offset, int zap)
|
|||
static struct wipe_desc *
|
||||
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;
|
||||
loff_t offset;
|
||||
int rc;
|
||||
|
||||
if (blkid_probe_lookup_value(pr, "TYPE", &type, NULL) == 0 &&
|
||||
blkid_probe_lookup_value(pr, "SBMAGIC_OFFSET", &off, NULL) == 0 &&
|
||||
blkid_probe_lookup_value(pr, "SBMAGIC", &mag, &len) == 0 &&
|
||||
blkid_probe_lookup_value(pr, "USAGE", &usage, NULL) == 0) {
|
||||
/* superblocks */
|
||||
if (blkid_probe_lookup_value(pr, "TYPE", &type, NULL) == 0) {
|
||||
rc = blkid_probe_lookup_value(pr, "SBMAGIC_OFFSET", &off, NULL);
|
||||
if (!rc)
|
||||
rc = blkid_probe_lookup_value(pr, "SBMAGIC", &mag, &len);
|
||||
if (rc)
|
||||
return wp;
|
||||
|
||||
loff_t offset = strtoll(off, NULL, 10);
|
||||
const char *p;
|
||||
/* partitions */
|
||||
} 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);
|
||||
if (!wp)
|
||||
return NULL;
|
||||
offset = strtoll(off, NULL, 10);
|
||||
|
||||
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->type = xstrdup(type);
|
||||
wp->on_disk = 1;
|
||||
|
||||
wp->magic = xmalloc(len);
|
||||
memcpy(wp->magic, mag, len);
|
||||
wp->len = len;
|
||||
wp->type = xstrdup(type);
|
||||
wp->on_disk = 1;
|
||||
|
||||
if (blkid_probe_lookup_value(pr, "LABEL", &p, NULL) == 0)
|
||||
wp->label = xstrdup(p);
|
||||
wp->magic = xmalloc(len);
|
||||
memcpy(wp->magic, mag, len);
|
||||
wp->len = len;
|
||||
|
||||
if (blkid_probe_lookup_value(pr, "UUID", &p, NULL) == 0)
|
||||
wp->uuid = xstrdup(p);
|
||||
}
|
||||
if (blkid_probe_lookup_value(pr, "LABEL", &p, NULL) == 0)
|
||||
wp->label = xstrdup(p);
|
||||
|
||||
if (blkid_probe_lookup_value(pr, "UUID", &p, NULL) == 0)
|
||||
wp->uuid = xstrdup(p);
|
||||
|
||||
return wp;
|
||||
}
|
||||
|
@ -179,7 +195,6 @@ static blkid_probe
|
|||
new_probe(const char *devname, int mode)
|
||||
{
|
||||
blkid_probe pr;
|
||||
int rc;
|
||||
|
||||
if (!devname)
|
||||
return NULL;
|
||||
|
@ -198,24 +213,14 @@ new_probe(const char *devname, int mode)
|
|||
if (!pr)
|
||||
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_set_superblocks_flags(pr, BLKID_SUBLKS_MAGIC |
|
||||
BLKID_SUBLKS_TYPE | BLKID_SUBLKS_USAGE |
|
||||
BLKID_SUBLKS_LABEL | BLKID_SUBLKS_UUID);
|
||||
|
||||
blkid_probe_enable_partitions(pr, 1);
|
||||
blkid_probe_set_partitions_flags(pr, BLKID_PARTS_MAGIC);
|
||||
|
||||
return pr;
|
||||
error:
|
||||
err(EXIT_FAILURE, _("error: %s: probing initialization failed"), devname);
|
||||
|
|
Loading…
Reference in New Issue