static void ptable_print(void *arg, const char *pname, const struct ptable_entry *part) { struct ptable *table; struct disk *dp, bsd; char line[80], size[6]; dp = (struct disk *)arg; sprintf(line, " %s%s: %s", dp->file ? "disk0": dp->name, pname, parttype2str(part->type)); humanize_number(size, sizeof(size), (part->end - part->start + 1) * dp->sectorsize, "", HN_AUTOSCALE, HN_B | HN_NOSPACE | HN_DECIMAL); printf("%-*s%s\n", PWIDTH, line, size); if (part->type == PART_FREEBSD) { sprintf(line, "%s%s", dp->file ? "disk0": dp->name, pname); bsd.name = line; bsd.fd = dp->fd; bsd.file = 0; /* to use dp->name in the next sprintf */ bsd.offset = dp->offset + part->start; bsd.sectorsize = dp->sectorsize; bsd.mediasize = (part->end - part->start + 1) * dp->sectorsize; table = ptable_open(&bsd, bsd.mediasize / bsd.sectorsize, bsd.sectorsize, diskread); if (table == NULL) return; ptable_iterate(table, &bsd, ptable_print); ptable_close(table); } }
/* * Serve para libertar toda a memória alocada pela função anterior. */ int table_skel_destroy() { if(sharedPtable) { ptable_close(sharedPtable); } //em caso de sucesso return 0; }
static void inspect_disk(struct disk *dp) { struct ptable *table; table = ptable_open(dp, dp->mediasize / dp->sectorsize, dp->sectorsize, diskread); if (table == NULL) { printf("ptable_open failed\n"); return; } printf("Partition table detected: %s\n", ptable_type2str(table)); ptable_iterate(table, dp, ptable_print); ptable_close(table); }