From 19f87d1d366694d0ad8b504f7fd88476e3cdc018 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Fri, 23 Apr 2010 13:35:20 +0200 Subject: libblkid: add blkid_partlist_get_table() Signed-off-by: Karel Zak --- shlibs/blkid/src/partitions/partitions.c | 33 +++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) (limited to 'shlibs/blkid/src/partitions') diff --git a/shlibs/blkid/src/partitions/partitions.c b/shlibs/blkid/src/partitions/partitions.c index 259284d84..9c151ef62 100644 --- a/shlibs/blkid/src/partitions/partitions.c +++ b/shlibs/blkid/src/partitions/partitions.c @@ -278,9 +278,6 @@ int blkid_probe_filter_partitions_type(blkid_probe pr, int flag, char *names[]) * use more blkid_partlist objects in the same time you have to create * more blkid_probe handlers (see blkid_new_probe()). * - * TODO: add blkid_ref() and blkid_unref() to allows to use blkid_partlist - * independently on libblkid probing stuff. - * * Returns: list of partitions, or NULL in case of error. */ blkid_partlist blkid_probe_get_partitions(blkid_probe pr) @@ -607,9 +604,10 @@ static int partitions_probe(blkid_probe pr, struct blkid_chain *chn) name = idinfos[i]->name; /* all checks passed */ - blkid_probe_set_value(pr, "PTTYPE", - (unsigned char *) name, strlen(name) + 1); - + if (!chn->binary) + blkid_probe_set_value(pr, "PTTYPE", + (unsigned char *) name, + strlen(name) + 1); DBG(DEBUG_LOWPROBE, printf("<-- leaving probing loop (type=%s) [PARTS idx=%d]\n", name, chn->idx)); @@ -878,6 +876,22 @@ int blkid_partlist_numof_partitions(blkid_partlist ls) return ls ? ls->nparts : -1; } +/** + * blkid_partlist_get_table: + * + * Returns top-level partition table or NULL of there is not a partition table + * on the device. + */ +blkid_parttable blkid_partlist_get_table(blkid_partlist ls) +{ + if (!ls || list_empty(&ls->l_tabs)) + return NULL; + + return list_entry(ls->l_tabs.next, + struct blkid_struct_parttable, t_tabs); +} + + /** * blkid_partlist_get_partition: * @ls: partitions list @@ -885,11 +899,8 @@ int blkid_partlist_numof_partitions(blkid_partlist ls) * * It's possible that the list of partitions is *empty*, but there is a valid * partition table on the disk. This happen when on-disk details about - * partitions are unknown, but we are able to detect partition table magic - * string only. The nice example is AIX. If your question is: "Is there any - * partition table?", use: - * - * blkid_probe_lookup_value(pr, "PTTYPE", &type, NULL); + * partitions are unknown or the partition table is empty. The nice example is + * AIX. See also blkid_partlist_get_table(). * * Returns: partition object or NULL in case or error. */ -- cgit v1.2.3-55-g7522