使用libparted库写个程序来打印我们的设备信息(2)

这一节我们将设备的分区打印出来。

 

代码如下:

#include <parted/parted.h> #include <stdio.h> int main(int argc, char* argv[]) { ped_device_probe_all(); PedDevice *dev = 0; while((dev = ped_device_get_next(dev))) { printf("/n ==============================================/n"); printf("device model: %s/n", dev->model); printf("path: %s/n",dev->path); long long size = (dev->sector_size * dev->length)/(1024*1024*1024); printf("size: %lld G/n", size); PedDisk* disk = ped_disk_new(dev); PedPartition* part = 0; while((part = ped_disk_next_partition(disk, part))) { //略过不是分区的空间 if ((part->type & PED_PARTITION_METADATA) || (part->type & PED_PARTITION_FREESPACE) || (part->type & PED_PARTITION_EXTENDED)) continue; printf("++++++++++++++++++++++++++++++++++++/n"); printf("partition: %s/n", ped_partition_get_path(part)); if(part->fs_type) printf("fs_type: %s/n", part->fs_type->name); else printf("fs_type: (null)/n"); //printf("partition start:%lld/n", part->geom.start); //printf("partition end: %lld/n", part->geom.end); printf("partition length:%lld M/n", (part->geom.length * dev->sector_size)/(1024*1024)); } } return 0; }

编译:gcc -g -Wall -lparted main.c

运行:sudo ./a.out

运行结果(部分截图):

使用libparted库写个程序来打印我们的设备信息(2)_第1张图片

你可能感兴趣的:(gcc,null,Path,disk)