From: Karel Zak Date: Thu, 18 Feb 2010 21:28:41 +0000 (+0100) Subject: libblkid: add blkid_partition_set_type() X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c2dacc61aa7de47f97606713de1724a96aab9d2c;p=util-linux libblkid: add blkid_partition_set_type() Signed-off-by: Karel Zak --- diff --git a/shlibs/blkid/src/partitions/bsd.c b/shlibs/blkid/src/partitions/bsd.c index 9d0d7e5e..ee15ad2f 100644 --- a/shlibs/blkid/src/partitions/bsd.c +++ b/shlibs/blkid/src/partitions/bsd.c @@ -164,6 +164,7 @@ static int probe_bsd_pt(blkid_probe pr, const struct blkid_idmag *mag) le16_to_cpu(l->d_npartitions) - BSD_MAXPARTITIONS)); for (i = 0, p = l->d_partitions; i < nparts; i++, p++) { + blkid_partition par; uint32_t start, size; /* TODO: in fdisk-mode returns all non-zero (p_size) partitions */ @@ -180,8 +181,11 @@ static int probe_bsd_pt(blkid_probe pr, const struct blkid_idmag *mag) continue; } - if (!blkid_partlist_add_partition(ls, tab, p->p_fstype, start, size)) + par = blkid_partlist_add_partition(ls, tab, start, size); + if (!par) goto err; + + blkid_partition_set_type(par, p->p_fstype); } return 0; diff --git a/shlibs/blkid/src/partitions/dos.c b/shlibs/blkid/src/partitions/dos.c index f3e8a198..8bf3a8b6 100644 --- a/shlibs/blkid/src/partitions/dos.c +++ b/shlibs/blkid/src/partitions/dos.c @@ -75,6 +75,7 @@ static int parse_dos_extended(blkid_probe pr, blkid_parttable tab, /* Parse data partition */ for (p = p0, i = 0; i < 4; i++, p++) { uint32_t abs_start; + blkid_partition par; /* the start is relative to the parental ext.partition */ start = dos_partition_start(p) * ssf; @@ -93,10 +94,12 @@ static int parse_dos_extended(blkid_probe pr, blkid_parttable tab, if (abs_start + size > ex_start + ex_size) continue; } - if (!blkid_partlist_add_partition(ls, tab, p->sys_type, - abs_start, size)) + + par = blkid_partlist_add_partition(ls, tab, abs_start, size); + if (!par) goto err; + blkid_partition_set_type(par, p->sys_type); ct_nodata = 0; } /* The first nested ext.partition should be a link to the next @@ -194,14 +197,19 @@ static int probe_dos_pt(blkid_probe pr, const struct blkid_idmag *mag) /* Parse primary partitions */ for (p = p0, i = 0; i < 4; i++, p++) { + blkid_partition par; + start = dos_partition_start(p) * ssf; size = dos_partition_size(p) * ssf; if (!size) continue; - if (!blkid_partlist_add_partition(ls, tab, p->sys_type, - start, size)) + + par = blkid_partlist_add_partition(ls, tab, start, size); + if (!par) goto err; + + blkid_partition_set_type(par, p->sys_type); } /* Linux uses partition numbers greater than 4 diff --git a/shlibs/blkid/src/partitions/gpt.c b/shlibs/blkid/src/partitions/gpt.c index 2c3a3267..eba8803b 100644 --- a/shlibs/blkid/src/partitions/gpt.c +++ b/shlibs/blkid/src/partitions/gpt.c @@ -339,8 +339,8 @@ static int probe_gpt_pt(blkid_probe pr, const struct blkid_idmag *mag) continue; } - par = blkid_partlist_add_partition(ls, tab, 0, - start * ssf, size * ssf); + par = blkid_partlist_add_partition(ls, tab, + start * ssf, size * ssf); if (!par) goto err; diff --git a/shlibs/blkid/src/partitions/mac.c b/shlibs/blkid/src/partitions/mac.c index 7f4a30b0..538b2727 100644 --- a/shlibs/blkid/src/partitions/mac.c +++ b/shlibs/blkid/src/partitions/mac.c @@ -144,7 +144,7 @@ static int probe_mac_pt(blkid_probe pr, const struct blkid_idmag *mag) start = be32_to_cpu(p->start_block) * ssf; size = be32_to_cpu(p->block_count) * ssf; - par = blkid_partlist_add_partition(ls, tab, 0, start, size); + par = blkid_partlist_add_partition(ls, tab, start, size); if (!par) goto err; diff --git a/shlibs/blkid/src/partitions/minix.c b/shlibs/blkid/src/partitions/minix.c index e2f9140f..91cb87ce 100644 --- a/shlibs/blkid/src/partitions/minix.c +++ b/shlibs/blkid/src/partitions/minix.c @@ -58,6 +58,7 @@ static int probe_minix_pt(blkid_probe pr, const struct blkid_idmag *mag) for (i = 0; i < MINIX_MAXPARTITIONS; i++, p++) { uint32_t start, size; + blkid_partition par; if (p->sys_type != BLKID_MINIX_PARTITION) continue; @@ -72,9 +73,11 @@ static int probe_minix_pt(blkid_probe pr, const struct blkid_idmag *mag) continue; } - if (!blkid_partlist_add_partition(ls, tab, - p->sys_type, start, size)) + par = blkid_partlist_add_partition(ls, tab, start, size); + if (!par) goto err; + + blkid_partition_set_type(par, p->sys_type); } return 0; diff --git a/shlibs/blkid/src/partitions/partitions.c b/shlibs/blkid/src/partitions/partitions.c index 21b6645a..579e1690 100644 --- a/shlibs/blkid/src/partitions/partitions.c +++ b/shlibs/blkid/src/partitions/partitions.c @@ -426,7 +426,7 @@ static blkid_partition new_partition(blkid_partlist ls, blkid_parttable tab) } blkid_partition blkid_partlist_add_partition(blkid_partlist ls, - blkid_parttable tab, int type, + blkid_parttable tab, blkid_loff_t start, blkid_loff_t size) { blkid_partition par = new_partition(ls, tab); @@ -434,17 +434,13 @@ blkid_partition blkid_partlist_add_partition(blkid_partlist ls, if (!par) return NULL; - par->type = type; par->start = start; par->size = size; DBG(DEBUG_LOWPROBE, - printf("parts: add partition (%p type=0x%x, " - "start=%llu, size=%llu, table=%p)\n", - par, par->type, - (unsigned long long) par->start, - (unsigned long long) par->size, - tab)); + printf("parts: add partition (%p start=%llu, size=%llu, table=%p)\n", + par, (unsigned long long) par->start, + (unsigned long long) par->size, tab)); return par; } @@ -828,6 +824,14 @@ blkid_partition blkid_partlist_devno_to_partition(blkid_partlist ls, dev_t devno return NULL; } +int blkid_partition_set_type(blkid_partition par, int type) +{ + if (!par) + return -1; + par->type = type; + return 0; +} + /** * blkid_parttable_get_type: * @tab: partition table diff --git a/shlibs/blkid/src/partitions/partitions.h b/shlibs/blkid/src/partitions/partitions.h index e017768a..c007def8 100644 --- a/shlibs/blkid/src/partitions/partitions.h +++ b/shlibs/blkid/src/partitions/partitions.h @@ -10,7 +10,7 @@ extern blkid_parttable blkid_partlist_new_parttable(blkid_partlist ls, const char *type, blkid_loff_t offset); extern blkid_partition blkid_partlist_add_partition(blkid_partlist ls, - blkid_parttable tab, int type, + blkid_parttable tab, blkid_loff_t start, blkid_loff_t size); extern int blkid_partlist_set_partno(blkid_partlist ls, int partno); @@ -32,6 +32,8 @@ extern int blkid_partition_set_utf8name(blkid_partition par, extern int blkid_partition_set_uuid(blkid_partition par, const unsigned char *uuid); +extern int blkid_partition_set_type(blkid_partition par, int type); + extern int blkid_partition_set_type_string(blkid_partition par, const unsigned char *type, size_t len); diff --git a/shlibs/blkid/src/partitions/sgi.c b/shlibs/blkid/src/partitions/sgi.c index c1094b78..3a9cd0a7 100644 --- a/shlibs/blkid/src/partitions/sgi.c +++ b/shlibs/blkid/src/partitions/sgi.c @@ -123,13 +123,17 @@ static int probe_sgi_pt(blkid_probe pr, const struct blkid_idmag *mag) uint32_t size = be32_to_cpu(p->num_blocks); uint32_t start = be32_to_cpu(p->first_block); uint32_t type = be32_to_cpu(p->type); + blkid_partition par; if (size == 0 || type == SGI_TYPE_VOLULME || type == SGI_TYPE_VOLHDR) continue; - if (!blkid_partlist_add_partition(ls, tab, type, start, size)) + par = blkid_partlist_add_partition(ls, tab, start, size); + if (!par) goto err; + + blkid_partition_set_type(par, type); } return 0; diff --git a/shlibs/blkid/src/partitions/solaris_x86.c b/shlibs/blkid/src/partitions/solaris_x86.c index fe39a103..e62eb468 100644 --- a/shlibs/blkid/src/partitions/solaris_x86.c +++ b/shlibs/blkid/src/partitions/solaris_x86.c @@ -100,6 +100,7 @@ static int probe_solaris_pt(blkid_probe pr, const struct blkid_idmag *mag) uint32_t start = le32_to_cpu(p->s_start); uint32_t size = le32_to_cpu(p->s_size); + blkid_partition par; if (size == 0 || le16_to_cpu(p->s_tag) == SOLARIS_TAG_WHOLEDISK) continue; @@ -116,9 +117,11 @@ static int probe_solaris_pt(blkid_probe pr, const struct blkid_idmag *mag) continue; } - if (!blkid_partlist_add_partition(ls, tab, - le16_to_cpu(p->s_tag), start, size)) + par = blkid_partlist_add_partition(ls, tab, start, size); + if (!par) goto err; + + blkid_partition_set_type(par, le16_to_cpu(p->s_tag)); } return 0; diff --git a/shlibs/blkid/src/partitions/sun.c b/shlibs/blkid/src/partitions/sun.c index 4ff000f3..30fe4ea7 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; + blkid_partition par; start = be32_to_cpu(p->start_cylinder) * spc; size = be32_to_cpu(p->num_sectors); @@ -139,8 +140,11 @@ static int probe_sun_pt(blkid_probe pr, const struct blkid_idmag *mag) if (type == SUN_TAG_WHOLEDISK || !size) continue; - if (!blkid_partlist_add_partition(ls, tab, type, start, size)) + par = blkid_partlist_add_partition(ls, tab, start, size); + if (!par) goto err; + + blkid_partition_set_type(par, type); } return 0; diff --git a/shlibs/blkid/src/partitions/unixware.c b/shlibs/blkid/src/partitions/unixware.c index 62dba764..2a36b938 100644 --- a/shlibs/blkid/src/partitions/unixware.c +++ b/shlibs/blkid/src/partitions/unixware.c @@ -132,6 +132,7 @@ static int probe_unixware_pt(blkid_probe pr, const struct blkid_idmag *mag) uint32_t start, size; uint16_t tag, flg; + blkid_partition par; tag = le16_to_cpu(p->s_label); flg = le16_to_cpu(p->s_flags); @@ -151,8 +152,11 @@ static int probe_unixware_pt(blkid_probe pr, const struct blkid_idmag *mag) continue; } - if (!blkid_partlist_add_partition(ls, tab, tag, start, size)) + par = blkid_partlist_add_partition(ls, tab, start, size); + if (!par) goto err; + + blkid_partition_set_type(par, tag); } return 0;