Hello everyone,
   I write this list because the discussion is quite technical.

I was trying to create a test for a program that uses libparted. This program 
creates random partitions in the available spaces, trying to align them 
according to the type of table. There is something I do not understand in the 
libparted behavior and I would like to understand with you if it is correct.

To show you better I created a minimal program that creates a new table and 
shows the default status. 

>>> WARNING: THIS PROGRAM MODIFIES THE DEVICE! <<<

To compile the code: 

gcc -c -o ped-disk-new-fresh sourcefile.c -lparted

To run the program:

/path/to/ped-disk-new-fresh DEVICE-PATH DISK-TYPE

DISK-TYPE is one of PedDiskType name (msdos|sun|dvh|gpt...).

The first thing is that the sun disklabel type does not support the 
PED_DISK_TYPE_CYLINDER_ALIGNMENT flag. 

In the file `INCLUDEPATH/parted/disk.h' I read this:


  enum _PedDiskFlag {
    /* This flag (which defaults to true) controls if disk types for
       which cylinder alignment is optional do cylinder alignment when a
       new partition gets added.
       This flag is available for msdos and sun disklabels (for sun labels
       it only controls the aligning of the end of the partition) */
       PED_DISK_CYLINDER_ALIGNMENT=1,
       ...

But running the program I get this output:


user@host:~/$ sudo ./ped-disk-new-fresh /dev/sdb sun
type: sun
Features:
PED_DISK_TYPE_EXTENDED: no
PED_DISK_TYPE_PARTITION_NAME: no
Flags:
PED_DISK_CYLINDER_ALIGNMENT: unavailable
PED_DISK_GPT_PMBR_BOOT: unavailable
Partitions:
---
Num: -1:
Type: 4 (free)
Start: 0s (0.00MiB)
End: 16097129s (7860MiB)
---
Num: -1:
Type: 8 (metadata)
Start: 16097130s (7860MiB)
End: 16099327s (7861MiB)


The second thing concerns dvh disks. When we create a new disk, the parted 
library automatically creates the header volume. But is it correct to be 
indicated as (logical|freespace)? This is the output I see:

user@host:~/$ sudo ./ped-disk-new-fresh /dev/sdb dvh
type: dvh
Features:
PED_DISK_TYPE_EXTENDED: yes
PED_DISK_TYPE_PARTITION_NAME: yes
Flags:
PED_DISK_CYLINDER_ALIGNMENT: unavailable
PED_DISK_GPT_PMBR_BOOT: unavailable
Partitions:
---
Num: 9:
Type: 2 (extended)
Start: 0s (0.00MiB)
End: 4095s (2.00MiB)
---
Num: -1:
Type: 9 (metadata)
Start: 0s (0.00MiB)
End: 0s (0.00MiB)
---
Num: -1:
Type: 5 (free)
Start: 1s (0.00MiB)
End: 4095s (2.00MiB)
---
Num: -1:
Type: 4 (free)
Start: 4096s (2.00MiB)
End: 16099327s (7861MiB)

Output of util-linux fdisk on the device shows:

Disklabel type: sgi

Device     Start      End      Sectors  Size Id Type       Attrs
/dev/sdb9  0     4095     4096       2M  0  SGI volhdr 
/dev/sdb11     0 16099327 16099328  7.7G  6  SGI volume 

Is this behavior correct?

One last thing: what does libparted do when a new partition is added? How 
should alignment be handled? Libparted allows you to add misaligned partitions?

Greetings,
  Christian.
#include <parted/parted.h>


int main(int argc, char *argv[])
{
	PedDevice *dev;
	PedDiskType *type;
	PedDisk *disk;
	PedPartition *part;

	if(argc < 3)
	{
		printf("usage: %s <dev-path> <disk-type>\n", argv[0]);

		exit(EXIT_FAILURE);
	}

	if((dev = ped_device_get(argv[1])) == NULL
			|| (type = ped_disk_type_get(argv[2])) == NULL
			|| (disk = ped_disk_new_fresh(dev, type)) == NULL)
		exit(EXIT_FAILURE);
	
	printf("type: %s\n"
			   "Features:\n"
				 "  PED_DISK_TYPE_EXTENDED: %s\n"
				 "  PED_DISK_TYPE_PARTITION_NAME: %s\n"
				 "Flags:\n"
         "  PED_DISK_CYLINDER_ALIGNMENT: %s\n"
				 "  PED_DISK_GPT_PMBR_BOOT: %s\n",
				 type->name,
				 ped_disk_type_check_feature(type, PED_DISK_TYPE_EXTENDED) ? "yes" : "no",
				 ped_disk_type_check_feature(type, PED_DISK_TYPE_PARTITION_NAME) ? "yes" : "no",
				 ped_disk_is_flag_available(disk, PED_DISK_CYLINDER_ALIGNMENT) ?
				   ped_disk_get_flag(disk, PED_DISK_CYLINDER_ALIGNMENT) ? "true" : "false" : "unavailable",
				 ped_disk_is_flag_available(disk, PED_DISK_GPT_PMBR_BOOT) ?
				   ped_disk_get_flag(disk, PED_DISK_GPT_PMBR_BOOT) ? "true" : "false" : "unavailable");

	printf("Partitions:\n");

	for(part = ped_disk_next_partition(disk, NULL);
			part != NULL;
			part = ped_disk_next_partition(disk, part))
	{
		char *s, *e;
		char *sm, *em;

		s = ped_unit_format_custom(dev, part->geom.start, PED_UNIT_SECTOR);
		sm = ped_unit_format_custom(dev, part->geom.start, PED_UNIT_MEBIBYTE);
		e = ped_unit_format_custom(dev, part->geom.end, PED_UNIT_SECTOR);
		em = ped_unit_format_custom(dev, part->geom.end, PED_UNIT_MEBIBYTE);

		printf("---\n"
				   "  Num: %d:\n"
				   "  Type: %d (%s)\n"
					 "  Start: %s (%s)\n"
					 "  End: %s (%s)\n",
					 part->num,
					 part->type,
					 ped_partition_type_get_name(part->type),
					 s, sm, e, em);

		free(s);
		free(e);
	}

	ped_disk_commit(disk);

	return EXIT_SUCCESS;
}

Reply via email to