|
| 1 | +/* |
| 2 | + * Print partition name and flags *only*, not including any other |
| 3 | + * meta-data whatsoever. |
| 4 | + * |
| 5 | + * Written by Lucas C. Villa Real <lucasvr@gobolinux.org> |
| 6 | + * Released under the GNU GPL version 2 or above. |
| 7 | + */ |
| 8 | +#include <stdio.h> |
| 9 | +#include <parted/parted.h> |
| 10 | + |
| 11 | +int main(int argc, char **argv) |
| 12 | +{ |
| 13 | + PedPartitionFlag flag = 0; |
| 14 | + PedPartition *part = NULL; |
| 15 | + PedDevice *dev = NULL; |
| 16 | + PedDisk *disk = NULL; |
| 17 | + char *user_dev; |
| 18 | + char buf[128]; |
| 19 | + size_t n = sizeof(buf); |
| 20 | + |
| 21 | + user_dev = argc > 1 ? argv[1] : NULL; |
| 22 | + |
| 23 | + ped_device_probe_all(); |
| 24 | + while ((dev = ped_device_get_next(dev))) { |
| 25 | + if (user_dev && strcmp(user_dev, dev->path)) |
| 26 | + continue; |
| 27 | + disk = ped_disk_new(dev); |
| 28 | + while ((part = ped_disk_next_partition(disk, part))) { |
| 29 | + if (part->num < 0) |
| 30 | + continue; |
| 31 | + memset(buf, 0, sizeof(buf)); |
| 32 | + snprintf(buf, sizeof(buf)-1, "%s%d:", dev->path, part->num); |
| 33 | + n -= strlen(buf) + 1; |
| 34 | + while ((flag = ped_partition_flag_next(flag))) { |
| 35 | + if (ped_partition_get_flag(part, flag)) { |
| 36 | + if (n > 0) { |
| 37 | + strncat(buf, ped_partition_flag_get_name(flag), n); |
| 38 | + n = sizeof(buf) - strlen(buf) - 1; |
| 39 | + } |
| 40 | + if (n > 0) { |
| 41 | + strncat(buf, ",", n); |
| 42 | + n--; |
| 43 | + } |
| 44 | + } |
| 45 | + } |
| 46 | + if (buf[strlen(buf)-1] == ',') |
| 47 | + buf[strlen(buf)-1] = '\0'; |
| 48 | + printf("%s\n", buf); |
| 49 | + flag = 0; |
| 50 | + } |
| 51 | + part = NULL; |
| 52 | + ped_disk_destroy(disk); |
| 53 | + } |
| 54 | + return 0; |
| 55 | +} |
0 commit comments