Add blkid_parttable_get_id() function.
Signed-off-by: Karel Zak <kzak@redhat.com>
blkid_partlist_devno_to_partition
blkid_partlist_get_table
<SUBSECTION>
+blkid_parttable_get_id
blkid_parttable_get_offset
blkid_parttable_get_parent
blkid_parttable_get_type
errx(EXIT_FAILURE, "%s: does not contains any "
"known partition table\n", devname);
- printf("size: %jd, sector size: %u, PT: %s, offset: %jd\n---\n",
+ printf("size: %jd, sector size: %u, PT: %s, offset: %jd, id=%s\n---\n",
blkid_probe_get_size(pr),
blkid_probe_get_sectorsize(pr),
blkid_parttable_get_type(root_tab),
- blkid_parttable_get_offset(root_tab));
+ blkid_parttable_get_offset(root_tab),
+ blkid_parttable_get_id(root_tab));
/*
* List partitions
extern const char *blkid_parttable_get_type(blkid_parttable tab)
__ul_attribute__((warn_unused_result));
+extern const char *blkid_parttable_get_id(blkid_parttable tab)
+ __ul_attribute__((warn_unused_result));
+
extern blkid_loff_t blkid_parttable_get_offset(blkid_parttable tab)
__ul_attribute__((warn_unused_result));
extern blkid_partition blkid_parttable_get_parent(blkid_parttable tab)
BLKID_2.23 {
global:
blkid_probe_step_back;
+ blkid_parttable_get_id;
} BLKID_2.21;
blkid_partlist ls;
struct dos_partition *p0, *p;
unsigned char *data;
- uint32_t start, size;
+ uint32_t start, size, id;
data = blkid_probe_get_sector(pr, 0);
if (!data)
if (!tab)
goto err;
+ id = dos_parttable_id(data);
+ if (id) {
+ char buf[37];
+
+ snprintf(buf, sizeof(buf), "0x%08x", id);
+ blkid_parttable_set_id(tab, (unsigned char *) buf);
+ }
+
+
/* Parse primary partitions */
for (p = p0, i = 0; i < 4; i++, p++) {
blkid_partition par;
#define BLKID_MSDOS_PT_OFFSET 0x1be
/* assemble badly aligned little endian integer */
-static inline unsigned int assemble4le(unsigned char *p)
+static inline unsigned int assemble4le(const unsigned char *p)
{
return p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24);
}
return mbr[510] == 0x55 && mbr[511] == 0xaa ? 1 : 0;
}
+static inline unsigned int dos_parttable_id(const unsigned char *mbr)
+{
+ return assemble4le(&mbr[440]);
+}
+
#endif /* BLKID_PARTITIONS_DOS_H */
if (!tab)
goto err;
+ guid = h->disk_guid;
+ swap_efi_guid(&guid);
+ blkid_parttable_set_id(tab, (const unsigned char *) &guid);
+
ssf = blkid_probe_get_sectorsize(pr) / 512;
fu = le64_to_cpu(h->first_usable_lba);
blkid_loff_t offset; /* begin of the partition table */
int nparts; /* number of partitions */
blkid_partition parent; /* parent of nested partition table */
+ char id[37]; /* PT identifier (e.g. UUID for GPT) */
struct list_head t_tabs; /* all tables */
};
return NULL;
}
+int blkid_parttable_set_id(blkid_parttable tab, const unsigned char *id)
+{
+ if (!tab)
+ return -1;
+
+ if (strcmp(tab->type, "gpt") == 0)
+ blkid_unparse_uuid(id, tab->id, sizeof(tab->id));
+ else if (strcmp(tab->type, "dos") == 0)
+ strncpy(tab->id, (const char *) id, sizeof(tab->id));
+
+ return 0;
+}
+
+/**
+ * blkid_parttable_get_id:
+ * @tab: partition table
+ *
+ * The ID is GPT disk UUID or DOS disk ID (in hex format).
+ *
+ * Returns: partition table ID (for example GPT disk UUID) or NULL
+ */
+const char *blkid_parttable_get_id(blkid_parttable tab)
+{
+ return tab && tab->id && *tab->id ? tab->id : NULL;
+}
+
+
int blkid_partition_set_type(blkid_partition par, int type)
{
if (!par)
extern blkid_parttable blkid_partlist_new_parttable(blkid_partlist ls,
const char *type, blkid_loff_t offset);
+extern int blkid_parttable_set_id(blkid_parttable tab, const unsigned char *id);
+
extern blkid_partition blkid_partlist_add_partition(blkid_partlist ls,
blkid_parttable tab,
blkid_loff_t start, blkid_loff_t size);