From: Karel Zak Date: Thu, 18 Feb 2010 21:53:44 +0000 (+0100) Subject: libblkid: add support for partition flags/attributes X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=75838802d7108081d95ef3ab342f0cb0c08dec63;p=util-linux libblkid: add support for partition flags/attributes Signed-off-by: Karel Zak --- diff --git a/shlibs/blkid/src/blkid.h.in b/shlibs/blkid/src/blkid.h.in index 59c05ab4..edeb8b57 100644 --- a/shlibs/blkid/src/blkid.h.in +++ b/shlibs/blkid/src/blkid.h.in @@ -279,6 +279,7 @@ extern blkid_loff_t blkid_partition_get_start(blkid_partition par); extern blkid_loff_t blkid_partition_get_size(blkid_partition par); extern int blkid_partition_get_type(blkid_partition par); extern const char *blkid_partition_get_type_string(blkid_partition par); +extern unsigned long long blkid_partition_get_flags(blkid_partition par); extern int blkid_partition_is_logical(blkid_partition par); extern int blkid_partition_is_extended(blkid_partition par); extern int blkid_partition_is_primary(blkid_partition par); diff --git a/shlibs/blkid/src/blkid.sym b/shlibs/blkid/src/blkid.sym index ea674f75..dfde6891 100644 --- a/shlibs/blkid/src/blkid.sym +++ b/shlibs/blkid/src/blkid.sym @@ -122,4 +122,5 @@ BLKID_2.18 { global: blkid_probe_all_removable; blkid_partlist_devno_to_partition; + blkid_partition_get_flags; } BLKID_2.17; diff --git a/shlibs/blkid/src/partitions/dos.c b/shlibs/blkid/src/partitions/dos.c index 8bf3a8b6..c9865b75 100644 --- a/shlibs/blkid/src/partitions/dos.c +++ b/shlibs/blkid/src/partitions/dos.c @@ -100,6 +100,7 @@ static int parse_dos_extended(blkid_probe pr, blkid_parttable tab, goto err; blkid_partition_set_type(par, p->sys_type); + blkid_partition_set_flags(par, p->boot_ind); ct_nodata = 0; } /* The first nested ext.partition should be a link to the next @@ -210,6 +211,7 @@ static int probe_dos_pt(blkid_probe pr, const struct blkid_idmag *mag) goto err; blkid_partition_set_type(par, p->sys_type); + blkid_partition_set_flags(par, p->boot_ind); } /* Linux uses partition numbers greater than 4 diff --git a/shlibs/blkid/src/partitions/gpt.c b/shlibs/blkid/src/partitions/gpt.c index eba8803b..56949013 100644 --- a/shlibs/blkid/src/partitions/gpt.c +++ b/shlibs/blkid/src/partitions/gpt.c @@ -353,6 +353,8 @@ static int probe_gpt_pt(blkid_probe pr, const struct blkid_idmag *mag) blkid_partition_set_type_uuid(par, (const unsigned char *) &e->partition_type_guid); + + blkid_partition_set_flags(par, e->attributes); } return 0; diff --git a/shlibs/blkid/src/partitions/minix.c b/shlibs/blkid/src/partitions/minix.c index 91cb87ce..0887d1a3 100644 --- a/shlibs/blkid/src/partitions/minix.c +++ b/shlibs/blkid/src/partitions/minix.c @@ -78,6 +78,7 @@ static int probe_minix_pt(blkid_probe pr, const struct blkid_idmag *mag) goto err; blkid_partition_set_type(par, p->sys_type); + blkid_partition_set_flags(par, p->boot_ind); } return 0; diff --git a/shlibs/blkid/src/partitions/partitions.c b/shlibs/blkid/src/partitions/partitions.c index 579e1690..d3ba6f29 100644 --- a/shlibs/blkid/src/partitions/partitions.c +++ b/shlibs/blkid/src/partitions/partitions.c @@ -39,6 +39,8 @@ * * @PART_ENTRY_TYPE: partition type, 0xNN (e.g 0x82) or type UUID (gpt only) * + * @PART_ENTRY_FLAGS: partition flags (e.g. boot_ind) or attributes (e.g. gpt attributes) + * * Example: * * @@ -158,6 +160,8 @@ struct blkid_struct_partition { int type; /* partition type */ char typestr[37]; /* partition type string (GPT and Mac) */ + unsigned long long flags; /* partition flags / attributes */ + int partno; /* partition number */ char uuid[37]; /* UUID (when supported by PT), e.g GPT */ unsigned char name[128]; /* Partition in UTF8 name (when supporte by PT), e.g. Mac */ @@ -727,7 +731,11 @@ static int blkid_partitions_probe_partition(blkid_probe pr) (unsigned char *) v, strlen(v) + 1); else blkid_probe_sprintf_value(pr, "PART_ENTRY_TYPE", - "0x%02x", blkid_partition_get_type(par)); + "0x%x", blkid_partition_get_type(par)); + + if (blkid_partition_get_flags(par)) + blkid_probe_sprintf_value(pr, "PART_ENTRY_FLAGS", + "0x%llx", blkid_partition_get_flags(par)); } rc = 0; nothing: @@ -1156,3 +1164,23 @@ const char *blkid_partition_get_type_string(blkid_partition par) return par && *par->typestr ? par->typestr : NULL; } + +int blkid_partition_set_flags(blkid_partition par, unsigned long long flags) +{ + if (!par) + return -1; + par->flags = flags; + return 0; +} + +/** + * blkid_partition_get_flags + * @par: partition + * + * Returns: partition flags (or attributes for gpt). + */ +unsigned long long blkid_partition_get_flags(blkid_partition par) +{ + return par ? par->flags : 0; +} + diff --git a/shlibs/blkid/src/partitions/partitions.h b/shlibs/blkid/src/partitions/partitions.h index c007def8..190918f9 100644 --- a/shlibs/blkid/src/partitions/partitions.h +++ b/shlibs/blkid/src/partitions/partitions.h @@ -40,6 +40,8 @@ extern int blkid_partition_set_type_string(blkid_partition par, extern int blkid_partition_set_type_uuid(blkid_partition par, const unsigned char *uuid); +extern int blkid_partition_set_flags(blkid_partition par, unsigned long long flags); + /* * partition probers */ diff --git a/shlibs/blkid/src/partitions/solaris_x86.c b/shlibs/blkid/src/partitions/solaris_x86.c index e62eb468..ce102bd8 100644 --- a/shlibs/blkid/src/partitions/solaris_x86.c +++ b/shlibs/blkid/src/partitions/solaris_x86.c @@ -122,6 +122,7 @@ static int probe_solaris_pt(blkid_probe pr, const struct blkid_idmag *mag) goto err; blkid_partition_set_type(par, le16_to_cpu(p->s_tag)); + blkid_partition_set_flags(par, le16_to_cpu(p->s_flag)); } return 0; diff --git a/shlibs/blkid/src/partitions/sun.c b/shlibs/blkid/src/partitions/sun.c index 30fe4ea7..10c555ab 100644 --- a/shlibs/blkid/src/partitions/sun.c +++ b/shlibs/blkid/src/partitions/sun.c @@ -132,6 +132,7 @@ static int probe_sun_pt(blkid_probe pr, const struct blkid_idmag *mag) blkid_loff_t start; blkid_loff_t size; uint16_t type = infos ? be16_to_cpu(infos[i].id) : 0; + uint16_t flags = infos ? be16_to_cpu(infos[i].flags) : 0; blkid_partition par; start = be32_to_cpu(p->start_cylinder) * spc; @@ -145,6 +146,7 @@ static int probe_sun_pt(blkid_probe pr, const struct blkid_idmag *mag) goto err; blkid_partition_set_type(par, type); + blkid_partition_set_flags(par, flags); } return 0; diff --git a/shlibs/blkid/src/partitions/unixware.c b/shlibs/blkid/src/partitions/unixware.c index 2a36b938..ac11a46d 100644 --- a/shlibs/blkid/src/partitions/unixware.c +++ b/shlibs/blkid/src/partitions/unixware.c @@ -157,6 +157,7 @@ static int probe_unixware_pt(blkid_probe pr, const struct blkid_idmag *mag) goto err; blkid_partition_set_type(par, tag); + blkid_partition_set_flags(par, flg); } return 0;