[ Pobierz całość w formacie PDF ]

ped_disk_probe function takes the device to be probed as an argument and returns the
type of the disk label on it.
The following example probes a given block device and prints the name of the disk
label type found on it.
5 of 8 07/24/2010 01:30 PM
Libparted Handbook - IlugCal http://web.archive.org/web/20080630020636/http:...
#include
#include
#include
int main (int argc, char* argv[])
{
PedDevice* device;
PedDiskType* type;
if (argc != 2)
error (EXIT_FAILURE, 0, "wrong number of arguments");
device = ped_device_get (argv[1]);
if (device == NULL)
goto error;
type = ped_disk_probe (device);
if (type == NULL)
goto error_destroy_device;
puts (type->name);
ped_device_destroy (device);
return 0;
error_destroy_device:
ped_device_destroy (device);
error:
return 1;
}
Reading
We can read the disk label of a block device using the ped_disk_new function. This
creates a volatile representation of the disk label on the device in the memory in the
form of a PedDisk instance.
The following example displays the partitions present on a specified block device by
first reading the disk label on the device. Each partition is an instance of PedPartition.
For each partition we display the partition number, the starting sector, size in sectors
and the file system name (if any).
6 of 8 07/24/2010 01:30 PM
Libparted Handbook - IlugCal http://web.archive.org/web/20080630020636/http:...
#include
#include
#include
int main (int argc, char* argv[])
{
PedDevice* device;
PedDisk* disk;
PedPartition* part;
if (argc != 2)
error (EXIT_FAILURE, 0, "wrong number of arguments");
device = ped_device_get (argv[1]);
if (device == NULL)
goto error;
disk = ped_disk_new (device);
if (disk == NULL)
goto error_destroy_device;
printf ("%3s ýÿs ýÿs ýÿs\n", "no.", "start", "size", "fs");
for (part = ped_disk_next_partition (disk, NULL); part;
part = ped_disk_next_partition (disk, part))
{
if (part->num
continue;
printf ("= ýÿlld ýÿlld ýÿs\n", part->num,
part->geom.start,
part->geom.length,
(part->fs_type) ? part->fs_type->name : "");
}
ped_disk_destroy (disk);
ped_device_destroy (device);
return 0;
error_destroy_device:
ped_device_destroy (device);
error:
return 1;
}
Note
All the examples in this page require Libparted to be installed on the system for
compilation. Pass -lparted to GCC for linking the code against the library.
user@box ~$ gcc foo.c -lparted
It is advisable not to experiment with the actual block devices, like /dev/hda,
/dev/sda, etc.. It is better one uses a loop device to try out the examples. A loop
device is nothing but a file, and the size of the device is the same as the size of
the file. You can create a loop device (say /tmp/devloop) using the dd command.
7 of 8 07/24/2010 01:30 PM
Libparted Handbook - IlugCal http://web.archive.org/web/20080630020636/http:...
user@box ~$ dd if=/dev/zero of=/tmp/devloop bs=512 count=40960
External Links
GNU Parted home page: http://www.gnu.org/software/parted/
GNU Parted wiki: http://parted.alioth.debian.org/
Retrieved from "http://www.ilug-cal.org/wiki/index.php/Libparted_Handbook"
This page was last modified 13:11, 19 September 2007.
This page has been accessed 2,053 times.
Content is available under Attribution-Noncommercial 3.0 .
About IlugCal
Disclaimers
Design of this site is based on the theme used at the Tango Project, available
under the terms and conditions of the Creative Commons Attribution Share-Alike
license.
8 of 8 07/24/2010 01:30 PM [ Pobierz całość w formacie PDF ]

  • zanotowane.pl
  • doc.pisz.pl
  • pdf.pisz.pl
  • forum-gsm.htw.pl