Anonymous avatar Anonymous committed 7f84713

Implement some of the advanced partition printing in fdisk. It can be considered broken, as it doesn't work as in Linux fdisk, but at least it displays correct values. (fdisk@sv.gnu.org/fdisk--main--0--patch-53)
fdisk@sv.gnu.org/fdisk--main--0--patch-53
Keywords:

Comments (0)

Files changed (2)

 };
 #define DOS_DATA_SIZE sizeof(struct DosPDCopyMem)
 
-#define NOT_PARTITION (PED_PARTITION_FREESPACE | PED_PARTITION_METADATA)
+
 
 struct DOSGeomList {
 	PedGeometry geom;
 	/* We check that order of the partitions is really wrong */
 	for (walk = ped_disk_next_partition(disk,NULL); walk;
 	     walk = ped_disk_next_partition(disk,walk)) {
-		if (walk->type & NOT_PARTITION)
+		if (!ped_partition_is_active(walk))
 			continue;
 		if (walk->type & PED_PARTITION_LOGICAL) {
 			j++;
 	/* We save the partitions */
 	for (walk = ped_disk_next_partition(disk,NULL); walk;
 	     walk = ped_disk_next_partition(disk,walk)) {
-		if (walk->type & NOT_PARTITION)
+		if (!ped_partition_is_active(walk))
 			continue;
 
 		/* We save the partition in the list */
 {
 	int end_cyl,end_head,end_sector;
 	char *part_chs = NULL;
+	/* TODO: Calculate, instead of parsing the string */
 	part_chs = ped_unit_format_custom(part->disk->dev,part->geom.end,
 	                                  PED_UNIT_CHS);
 	sscanf(part_chs, "%d,%d,%d", &end_cyl, &end_head, &end_sector);
 	/* We count the allocated sectors */
 	for (part = ped_disk_next_partition(disk,NULL); part;
 	     part = ped_disk_next_partition(disk,part)) {
-		if (part->type & NOT_PARTITION)
+		if (!ped_partition_is_active(part))
 			continue;
 		check_partition_consistency(part);
 
 	return 0;
 }
 
+#define sector(s)	((s) & 0x3f)
+#define cylinder(s, c)	((c) | (((s) & 0xc0) << 2))
+
+
+void
+part_xprint (PedDisk **disk, int extend)
+{
+	PedPartition *part;
+	PedDevice *dev = (*disk)->dev;
+	PedCHSGeometry *chs = &(dev->bios_geom);
+
+	int is_boot, start_cyl, start_head, start_sector, 
+	             end_cyl, end_head, end_sector;
+
+	char *part_chs = NULL;
+
+	printf(_("\nDisk %s: %d heads, %d sectors, %d cylinders\n\n"),
+	       dev->path, chs->heads, chs->sectors, chs->cylinders);
+	printf(_("Nr AF  Hd Sec     Cyl  Hd Sec     Cyl      Start       Size ID\n"));
+
+	for (part = ped_disk_next_partition (*disk, NULL); part;
+	     part = ped_disk_next_partition (*disk, part)) {
+		if (!ped_partition_is_active(part))
+			continue;
+		
+		/* We skip primary partitions, if needed */
+		if (extend && !part->type)
+			continue;  
+
+
+		/* TODO: Calculate, instead of parsing the string */
+		part_chs = ped_unit_format_custom(dev, part->geom.start,
+	                                          PED_UNIT_CHS);
+		sscanf(part_chs, "%d,%d,%d", &start_cyl, &start_head, &start_sector);
+		ped_free(part_chs);
+
+		part_chs = ped_unit_format_custom(dev, part->geom.end,
+	                                          PED_UNIT_CHS);
+		sscanf(part_chs, "%d,%d,%d", &end_cyl, &end_head, &end_sector);
+		ped_free(part_chs);
+
+
+		is_boot = ped_partition_get_flag(part,PED_PARTITION_BOOT);
+		
+		printf("%2d %02x%4d%4d%8d%4d%4d%8d%11lld%11lld %02x\n",
+		       part->num, is_boot ? 0x80 : 0, 
+		       start_head, start_sector, start_cyl,
+		       end_head, end_sector, end_cyl,
+		       part->geom.start, part->geom.length, 
+		       get_disk_specific_system_type(part, NULL)); 
+		
+			
+		check_partition_consistency(part);
+	}
+}
+
+/* This is only run in Linux fdisk compatibility mode */
+static int
+do_xprint (PedDisk **disk)
+{
+	part_xprint(disk,0);
+	return 1;
+}
+
+static int
+do_eprint (PedDisk **disk)
+{
+	part_xprint(disk,1);
+	return 1;
+}
+
+
 static void
 print_partition_size(PedDisk *disk)
 {
 static int
 do_change_sectors(PedDisk **disk)
 {
-	PedSector sectors = (*disk)->dev->bios_geom.sectors;
-	if (fdisk_command_line_get_llinteger(_("Number of sectors"), &sectors)) {
+	int sectors = (*disk)->dev->bios_geom.sectors;
+	if (fdisk_command_line_get_integer(_("Number of sectors"), &sectors)) {
 		(*disk)->dev->bios_geom.sectors = sectors;
 		return 1;
 	}
 static int
 do_change_heads(PedDisk **disk)
 {
-	PedSector heads = (*disk)->dev->bios_geom.heads;
-	if (fdisk_command_line_get_llinteger(_("Number of heads"), &heads)) {
+	int heads = (*disk)->dev->bios_geom.heads;
+	if (fdisk_command_line_get_integer(_("Number of heads"), &heads)) {
 		(*disk)->dev->bios_geom.heads = heads;
 		return 1;
 	}
 static int
 do_change_cylinders(PedDisk **disk)
 {
-	PedSector cylinders = (*disk)->dev->bios_geom.cylinders;
-	if (fdisk_command_line_get_llinteger(_("Number of cylinders"), &cylinders)) {
+	int cylinders = (*disk)->dev->bios_geom.cylinders;
+	if (fdisk_command_line_get_integer(_("Number of cylinders"), &cylinders)) {
 		(*disk)->dev->bios_geom.cylinders = cylinders;
 		return 1;
 	}
 _(" c   change number of cylinders"),
 NULL), NULL, 1));
 
+  if (fdisk_compatibility_mode)
+	fdisk_command_register (fdisk_ex_menu_commands, fdisk_command_create (
+		str_list_create_unique ("e", _("e"), NULL),
+		do_eprint,
+		str_list_create (
+_(" e   list extended partitions"),
+NULL), NULL, 1));
+
 	fdisk_command_register (fdisk_ex_menu_commands, fdisk_command_create (
 		str_list_create_unique ("f", _("f"), NULL),
 		do_fix_partition_order,
 _(" m   print this menu"),
 NULL), NULL, 1));
  }
+  if (fdisk_compatibility_mode)
+	fdisk_command_register (fdisk_ex_menu_commands, fdisk_command_create (
+		str_list_create_unique ("p", _("p"), NULL),
+		do_xprint,
+		str_list_create (
+_(" p   print the partition table"),
+NULL), NULL, 1));
+  else
 	fdisk_command_register (fdisk_ex_menu_commands, fdisk_command_create (
 		str_list_create_unique ("p", _("p"), NULL),
 		do_print,
 	if (!disk) 
 	        return 1;
 	/* Show the size of the partition */
-	if (fdisk_part_size) {
+	if (fdisk_part_size)
 		print_partition_size(disk);
-	}
+
 	/* List the specified disk. */
 	if (fdisk_list_table)
 	         do_list_devices(disk);
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.