char *devname;
blkid_probe pr;
blkid_partlist ls;
- blkid_parttable root_tab = NULL;
+ blkid_parttable root_tab;
if (argc < 2) {
fprintf(stderr, "usage: %s <device|file> "
if (!ls)
errx(EXIT_FAILURE, "%s: failed to read partitions\n", devname);
+ /*
+ * Print info about the primary (root) partition table
+ */
+ root_tab = blkid_partlist_get_table(ls);
+ if (!root_tab)
+ 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",
+ blkid_probe_get_size(pr),
+ blkid_probe_get_sectorsize(pr),
+ blkid_parttable_get_type(root_tab),
+ blkid_parttable_get_offset(root_tab));
+
+ /*
+ * List partitions
+ */
nparts = blkid_partlist_numof_partitions(ls);
if (!nparts)
- errx(EXIT_FAILURE, "%s: does not contains any "
- "known partition table\n", devname);
+ goto done;
for (i = 0; i < nparts; i++) {
const char *p;
blkid_partition par = blkid_partlist_get_partition(ls, i);
blkid_parttable tab = blkid_partition_get_table(par);
- if (i == 0) {
- root_tab = tab;
- printf("size: %llu, sector size: %u, "
- "PT: %s, offset: %llu\n---\n",
- (unsigned long long) blkid_probe_get_size(pr),
- blkid_probe_get_sectorsize(pr),
- blkid_parttable_get_type(tab),
- (unsigned long long) blkid_parttable_get_offset(tab));
- }
printf("#%d: %10llu %10llu 0x%x",
blkid_partition_get_partno(par),
(unsigned long long) blkid_partition_get_start(par),
blkid_partition_get_type(par));
if (root_tab != tab)
- /* subpartition */
+ /* subpartition (BSD, Minix, ...) */
printf(" (%s)", blkid_parttable_get_type(tab));
p = blkid_partition_get_name(par);
putc('\n', stdout);
}
+done:
blkid_free_probe(pr);
-
return EXIT_SUCCESS;
}
extern blkid_partlist blkid_probe_get_partitions(blkid_probe pr);
extern int blkid_partlist_numof_partitions(blkid_partlist ls);
+extern blkid_parttable blkid_partlist_get_table(blkid_partlist ls);
extern blkid_partition blkid_partlist_get_partition(blkid_partlist ls, int n);
extern blkid_partition blkid_partlist_devno_to_partition(blkid_partlist ls, dev_t devno);
global:
blkid_partition_get_flags;
blkid_partlist_devno_to_partition;
+ blkid_partlist_get_table;
blkid_probe_all_removable;
blkid_probe_get_fd;
blkid_probe_get_offset;
* 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)
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));
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
*
* 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.
*/