Anonymous avatar Anonymous committed 208b795

Merge with alignment patch from Milko Krachounov, fix all compiler warnings

Comments (0)

Files changed (9)

-This is cfdisk.info, produced by makeinfo version 4.7 from cfdisk.texi.
+This is cfdisk.info, produced by makeinfo version 4.13 from cfdisk.texi.
 
-   Copyright (C) 2006 Free Software Foundation, Inc.
+Copyright (C) 2006 Free Software Foundation, Inc.
 
    Permission is granted to copy, distribute and/or modify this document
 under the terms of the GNU Free Documentation License, Version 1.1 or
 
 
 Tag Table:
-Node: Top661
-Node: About1031
-Node: Name1145
-Node: Using cfdisk1289
-Node: Invoking cfdisk1484
-Node: Overview1633
-Node: Options3510
-Node: Units4336
-Node: Usage5789
-Node: Flags15301
-Node: Bugs16767
-Node: See also16945
-Node: Copying this manual17087
-Node: GNU Free Documentation License17304
+Node: Top659
+Node: About1029
+Node: Name1143
+Node: Using cfdisk1287
+Node: Invoking cfdisk1482
+Node: Overview1631
+Node: Options3508
+Node: Units4334
+Node: Usage5787
+Node: Flags15299
+Node: Bugs16765
+Node: See also16943
+Node: Copying this manual17085
+Node: GNU Free Documentation License17302
 
 End Tag Table
-This is fdisk.info, produced by makeinfo version 4.7 from fdisk.texi.
+This is fdisk.info, produced by makeinfo version 4.13 from fdisk.texi.
 
-   Copyright (C) 2006 Free Software Foundation, Inc.
+Copyright (C) 2006 Free Software Foundation, Inc.
 
    Permission is granted to copy, distribute and/or modify this document
 under the terms of the GNU Free Documentation License, Version 1.1 or
 
 
 Tag Table:
-Node: Top657
-Node: About1023
-Node: Name1135
-Node: Using fdisk1490
-Node: Invoking fdisk1683
-Node: Overview1826
-Node: Options3586
-Node: Commands and usage6063
-Node: Units13496
-Node: Bugs14718
-Node: See also15542
-Node: Copying this manual15684
-Node: GNU Free Documentation License15900
+Node: Top655
+Node: About1021
+Node: Name1133
+Node: Using fdisk1488
+Node: Invoking fdisk1681
+Node: Overview1824
+Node: Options3584
+Node: Commands and usage6061
+Node: Units13494
+Node: Bugs14716
+Node: See also15540
+Node: Copying this manual15682
+Node: GNU Free Documentation License15898
 
 End Tag Table
 	{"version",	'v', NULL,	N_("displays the version")},
 	{"arrow-cursor", 'a', NULL, 	N_("use an arrow cursor instead of reverse video")},
 	{"new-table",	'z', NULL,	N_("create a new partition table on the disk")},
+	{"align",	'A', N_("TYPE"),N_("use align TYPE, can be none, cyl, min or opt")},
 	{"units",	'u', N_("UNIT"),N_("sets the default display units to UNIT")},
 	{"list-partition-types", 't', NULL, N_("displays a list of supported partition types")},
         {NULL, 0, NULL, NULL}
 }
 
 /* TODO: Not perfect */
-static is_key_ok (int key, const char* ok_keys, MenuOptions opts) {
+static int is_key_ok (int key, const char* ok_keys, MenuOptions opts) {
 
 	if (opts & MENU_ARROWS) {
 		switch (key) {
 	}
 	ped_disk_destroy(c->disk);
 	c->disk = ped_disk_new(c->dev);
+	init_disk_flags(c->disk);
 	uiquery.need_commit = 0;
 	if (part) {
 		*part = ped_disk_get_partition(c->disk,partnum);
 	}
+	return 1;
 }
 
 
 	type_keys[i++] = 'b'; /* The BSD disklabel can be counted as a regular partition */
 	PedPartitionType type = 0;
 	PartPos pos;
-	int key,success = 1,done;
+	int key;
 	UIOpts opts = UI_DEFAULT;
 	if (!((*part)->type & PED_PARTITION_FREESPACE)) {
 		warning_waitkey(N_("Report a bug in the function menu_new and win a cookie."));
 	return 1;	
 }
 
-do_edit (Context *c, PedPartition **part) {
+int do_edit (Context *c, PedPartition **part) {
 	char devname[SMALLBUF];
-	PedDevice *dev;
 	if (uiquery.need_commit) {
 	        ped_exception_throw (
 				     PED_EXCEPTION_ERROR,
 	/* We reset this back to its default state */
 	uiquery.need_commit = 0;
 	ped_device_end_external_access(c->disk->dev);
+	return 1;
 }
 static int
 do_resize (Context *c, PedPartition **part) {
 	PedFileSystem *fs = NULL;
 	PedSector first,last;
 	PartPos pos;
-	UIOpts opts = UI_WARN_COMMIT;
+	UIOpts opts = UI_WARN_COMMIT | UI_SNAP_TO_START;
 	if (!((*part)->type & PED_PARTITION_EXTENDED)) {
 		if ((*part)->fs_type && (*part)->fs_type->ops->resize) {
 			menu_title(_("What do you want to do?"));
 			opts |= UI_NO_FS_RESIZE;
 		}
 	}
-	char buf[SMALLBUF];
 
 	pos.start.sector = (*part)->geom.start;
 	pos.end.sector = (*part)->geom.end;
 	};
 	const char keys[] = { 'g', 'c', ESC, '\0' };
 	int key;
-	PedPartition *temp;
-
 
 	menu_title(_("This will try to rescue broken or deleted partitions")); 
 	key = do_menu(rescue_menu, 8, MENU_BUTTON | MENU_TITLE, keys, NULL);
 	if (temp && temp->type & PED_PARTITION_FREESPACE)
 		temp = disk_get_prev_nmd_partition(c->disk, temp); 
 
-	if (!(*part)->type & PED_PARTITION_EXTENDED)
+	if (((*part)->type & PED_PARTITION_EXTENDED) == 0)
 		return 0;
 	if (!ped_disk_minimize_extended_partition(c->disk)) {
 		warning_waitkey(N_("Couldn't minimize the extended partition"));
 		case 'C': ped_unit_set_default(PED_UNIT_CHS); return 1;
 		
 	}
+
+	 ped_unit_set_default(PED_UNIT_CYLINDER);
+	return 0;
 }
 
 /* I'm not quite sure we should let the user do this... */
 		{ 0, NULL }
 	};
 #endif
-	int i;
 
 	if (!ped_partition_is_flag_available(part,flag))
 		return;
    have and havent aren't perfect, but work for our purposes */
 static int
 do_plist (Context *c, PedPartition **part, PedPartitionType have, PedPartitionType havent) {
-	int key = 0, i, redraw = 1, selnum = 0, start = 0;
+	int key = 0, redraw = 1, selnum = 0, start = 0;
 	const char* keys;
 	PedPartition *selected = NULL;
-	PedPartition *temp,*memp;
+	PedPartition *temp;
 	MenuOptions menu_opts = MENU_BUTTON | MENU_ARROWS;
 	MenuItem *part_menu;
 	int menupos = 0;
 			else do_quit (0,NULL);
 		} else {
 			ped_exception_leave_all();
+			if (!init_disk_flags(disk))
+				do_quit(1,_("Internal error initializing disk flags"));
 		}
 	} else {
 		if (!perform_mklabel (dev, &disk, NULL))
 main (int argc, char **argv) {
 	PedUnit unit = -1;
 	char *devname;
+	AlignType align_type;
 	PedDevice *dev;
 #ifdef HAVE_GETOPT_H
 	static struct option long_options[] = {
 		{ "new-table", no_argument, NULL, 'z' },
 		{ "version", no_argument, NULL, 'v' },
 		{ "arrow-cursor", no_argument, NULL, 'a' },
+		{ "align", required_argument, NULL, 'A' },
 		{ "units", required_argument, NULL, 'u' },
 		{ "help", no_argument, NULL, 'h' },
 		{ "list-partition-types", no_argument, NULL, 't' },
 	};
 
 	int opt,option_index;
-	while ((opt = getopt_long(argc,argv, "hazvtu:", long_options, &option_index)) != -1) {
+	while ((opt = getopt_long(argc,argv, "hazvtA:u:", long_options, &option_index)) != -1) {
 #else
 	int opt;
-	while ((opt = getopt(argc,argv,"hazvtu:")) != -1) {
+	while ((opt = getopt(argc,argv,"hazvtA:u:")) != -1) {
 #endif		
 		switch (opt) {
 			case 'v':
 			case 'z': 
 				new_table = 1;
 				break;
+			case 'A':
+				align_type = string_to_align_type(optarg);
+				if (align_type == ALIGNMENT_INVALID)
+					print_usage();
+				partition_align_type = align_type;
+				break;
 			case 'u':
 				unit = ped_unit_get_by_name(optarg);
 				break;
 		exit(1);
 	}
 	do_ui(devname, dev);
+	return 0;
 }
 
 int compat_mode = 1; /* Start compatible with fdisk and cfdisk */
 
+/* This variable is global and referred from fdisk.c and cfdisk.c
+ * The value specifies how the partitions will be aligned,
+ * values of ALIGNMENT_OPTIMAL and ALIGNMENT_MINIMAL are handled
+ * by the functions in this file, while ALIGNMENT_CYLINDER is 
+ * handled by fdisk.c and cfdisk.c.
+ */
+
+AlignType partition_align_type = ALIGNMENT_NONE;
+
 /* Here we store the struct with interface functions */
 static UICalls *uiquery;
 
 	return ped_disk_extended_partition (disk) != 0;
 }
 
+/* This function returns a device constraint that is optionally
+ * aligned if partition_align_type is either ALIGNMENT_OPTIMAL
+ * or ALIGNMENT_MINIMAL.
+ */
+static PedConstraint *
+_get_aligned_device_constraint(PedDevice *dev)
+{
+    if (partition_align_type == ALIGNMENT_OPTIMAL)
+        return ped_device_get_optimal_aligned_constraint(dev);
+    else if (partition_align_type == ALIGNMENT_MINIMAL)
+        return ped_device_get_minimal_aligned_constraint(dev);
+    else
+        return ped_device_get_constraint(dev);
+}
 
 
+/* Return a new geometry aligned according to partition_align_type.
+ * Returns NULL if it didn't succeed.
+ */
+static PedGeometry *
+_get_aligned_geometry(PedGeometry *geometry, int keep_inside)
+{
+	PedConstraint *constraint;
+	PedGeometry * new;
+
+	constraint = _get_aligned_device_constraint(geometry->dev);
+	if (keep_inside) {
+		constraint = constraint_intersect_and_destroy(
+				constraint,
+				ped_constraint_new_from_max(geometry));
+	}
+
+	new = ped_constraint_solve_nearest(constraint, geometry);
+	ped_constraint_destroy(constraint);
+	return new;
+}
+
+/* Returns 1 if the partition is aligned correctly in regards to
+ * align_type.
+ */
+static int
+_is_partition_aligned(PedPartition *part, AlignType align_type)
+{
+    
+    PedAlignment *alignment = NULL;
+
+    switch (partition_align_type) {
+        case ALIGNMENT_OPTIMAL:
+            alignment = ped_device_get_optimum_alignment (part->disk->dev);
+            break;
+        case ALIGNMENT_MINIMAL:
+            alignment = ped_device_get_minimum_alignment (part->disk->dev);
+            break;
+				default:
+						;
+    }
+        
+    if (!alignment)
+        return 1;
+
+    int aligned = 1;
+    if (alignment->grain_size == 0)
+        aligned = 0;
+    else if (part->geom.start % alignment->grain_size != alignment->offset)
+        aligned = 0;
+    ped_alignment_destroy(alignment);
+
+    return aligned;
+}
+
+/* Warn the user if the partition isn't aligned correctly 
+ * as specified by the partition_align_type global.
+ * Returns 1 if the partition is correctly aligned, or
+ * if the user accepted the partition as it is. Otherwise,
+ * return 0.
+ */
+static int
+_partition_warn_unaligned(PedPartition *part)
+{
+    if (_is_partition_aligned(part, partition_align_type))
+        return 1;
+
+    if (ped_exception_throw(PED_EXCEPTION_WARNING, 
+                            PED_EXCEPTION_IGNORE_CANCEL,
+                            _("The resulting partition is not properly "
+                              "aligned for best performance"))
+            == PED_EXCEPTION_CANCEL)
+        return 0;
+
+    return 1;                            
+}
 
 static int
 _partition_warn_busy (PedPartition* part)
 		constraint = ped_device_get_constraint(dev);
 	PedSector start = geom->start-before;
 	start = (start > 0 ? start : 0);
-	PedSector end = geom->start+after;
+	PedSector end = geom->end+after;
 	end = (end < dev->length-1LL ? end : dev->length-1LL);
 	ped_geometry_set (geom, start, end-start+1);
 	new_geom = ped_constraint_solve_nearest (constraint, geom);
 
 }
 
+AlignType 
+string_to_align_type(const char *name)
+{
+    if (!strcmp(name, "none"))
+        return ALIGNMENT_NONE;
+    if (!strncmp(name, "opt", 3))
+        return ALIGNMENT_OPTIMAL;
+    if (!strncmp(name, "min", 3))
+        return ALIGNMENT_MINIMAL;
+    if (!strncmp(name, "cyl", 3))
+        return ALIGNMENT_CYLINDER;
+    return ALIGNMENT_INVALID;
+}
+
+int
+init_disk_flags(PedDisk *disk)
+{
+    if (ped_disk_is_flag_available(disk, PED_DISK_CYLINDER_ALIGNMENT))
+        if (!ped_disk_set_flag(disk, PED_DISK_CYLINDER_ALIGNMENT,
+                               partition_align_type == ALIGNMENT_CYLINDER))
+            return 0;
+    return 1;
+}
 
 /* PedSector is signed, so we can use this to move in both directions */
 static int
 			   the sector with the range so that the sector is equal
 			   to the desired result */
 			if (where == 'b') {
-				/* As the start is not equal to the end of
-				   the partition, we will add some fuzz */
-				/* FIXME */
-				pos->start.range = ped_geometry_new(dev,
-							first, 64LL);
+				/* Fuzzing both start and end with range->length. 
+				 * TODO: range->length / 2 might be a better choice
+				 *       ...or a constraint with a range for min and max
+				 *       size based on this constraint which isn't possible
+				 *       with the API right now.
+				 */
+				pos->start.range = ped_geometry_new(dev, first, 1);
+				fuzzify(pos->start.range, dev, NULL, 
+					range->length, range->length);
+				pos->start.sector = first;
 
-				pos->start.sector = first;
 				/* Desired: end = first+length-1LL */
 				pos->end.sector = length;
 				pos->end.range = range;
 				move_sector(dev,&(pos->end),first-1LL);
 			}
 			else if (where == 'e') {
-				/* If the end has changed, we will add some fuzz */
-				if (pos->end.sector != last)
-					pos->end.range = ped_geometry_new(dev,
-							last-63LL, 64LL);
+				/* Fuzzing both start and end with range->length */
+				pos->end.range = ped_geometry_new(dev, last, 1);
+				fuzzify(pos->end.range, dev, NULL, 
+					range->length, range->length);
+				pos->end.sector = last;
 
-				pos->end.sector = last;
 				/* Desired: start = last-length+1LL */
 				pos->start.sector = length;
 				pos->start.range = range;
 				move_sector(dev,&(pos->start),last-2*length+1LL);
 			}
 			else if (where == 's') {
+				/* If UI_SNAP_TO_START isn't true, add fuzz to the
+				 * start, otherwise don't.
+				 */
+				pos->start.range = ped_geometry_new(dev, pos->start.sector, 1);
+				if (!(*opts & UI_SNAP_TO_START))
+					fuzzify(pos->start.range, dev, NULL, 
+						range->length, range->length);
+
 				/* Desired: end = start+length-1LL */
 				pos->end.sector = length;
 				pos->end.range = range;
 		PedDisk* new_disk = ped_disk_new (dev);
 		if (!new_disk)
 			return 0;
+		if (!init_disk_flags(new_disk)) {
+			ped_disk_destroy(new_disk);
+			return 0;
+		}
 		*value = new_disk;
 	}
 	return 1;
 }
 
 /* Looks for the first suitable free space for a new partition */
-place_part_start(PedDisk *disk, PartPos *pos, PedPartitionType type) {
+int place_part_start(PedDisk *disk, PartPos *pos, PedPartitionType type) {
+	PedGeometry *aligned;
 	PedPartition *part = NULL;
 	type = (type & PED_PARTITION_LOGICAL) | PED_PARTITION_FREESPACE;
 	for (part = ped_disk_next_partition(disk, NULL);
 	     part; part = ped_disk_next_partition(disk,part)) {
 		if (part->type == type) {
-			pos->start.sector = part->geom.start;
+			aligned = _get_aligned_geometry(&part->geom, 1);
+
+			pos->start.sector = aligned->start;
 			pos->start.range = ped_geometry_new (disk->dev,
-				 		part->geom.start, 8LL);
+				 		aligned->start, 1);
+			ped_geometry_destroy(aligned);
 			return 1;
 		}
 	}
 /* This function looks where to place the end of a new partition */
 static int
 place_part_end(PedDisk *disk, PartPos *pos) {
+	PedGeometry *aligned;
 	PedPartition *part = ped_disk_get_partition_by_sector(disk,
 							pos->start.sector);
 	if (part->type & PED_PARTITION_FREESPACE) {
-		pos->end.sector = part->geom.end;
+		aligned = _get_aligned_geometry(&part->geom, 1);
+
+		pos->end.sector = aligned->end;
 		pos->end.range = ped_geometry_new (disk->dev,
-				 	part->geom.end - 7LL, 8LL);
+				 	aligned->end, 1);
+		ped_geometry_destroy(aligned);
 		return 1;
 	}
 	else
   
   if (!get_sector (start, disk->dev, &(pos->start), -1LL, opts))
     return 0;
-  
+
   /* If we are creating a new partition and want to look where to
      place its end ... */
   if (opts & PLACE_END_NEWPART)
 	      goto error;
 	  }
 
-        *disk = ped_disk_new_fresh (dev, type);
-        if (!*disk)
+        PedDisk *new_disk = ped_disk_new_fresh (dev, type);
+        if (!new_disk)
 	  goto error;
 
+	if (!init_disk_flags(new_disk)) {
+		ped_disk_destroy(new_disk);
+		goto error;
+	}
+
+	*disk = new_disk;
+
         /*if (!ped_disk_commit (*disk))
                 goto error;*/
 	uiquery->need_commit = 1;
 	/* Check if the partition occupying the space before the place we
 	   are trying to put this one, requires a metadata sectors after it,
 	   and if so, increase the range of the constraint */
-
-
 	fuzzify(pos->start.range, disk->dev, NULL, 0,
 		metadata_tail_sectors(
 			disk_get_prev_nmd_partition(
                         pos->start.range, pos->end.range);
         PED_ASSERT (user_constraint != NULL, return 0);
 
-        dev_constraint = ped_device_get_constraint (disk->dev);
+        dev_constraint = _get_aligned_device_constraint(disk->dev);
         PED_ASSERT (dev_constraint != NULL, return 0);
 
         final_constraint = ped_constraint_intersect (user_constraint,
                         end_usr   = ped_unit_format (disk->dev, pos->end.sector);
                         start_sol = ped_unit_format (disk->dev, part->geom.start);
                         end_sol   = ped_unit_format (disk->dev, part->geom.end);
-			/* TODO: With the changes from 06/08/06, we might remove
-			   the "if" and warn the user always if this is out of
-			   range */
-			if (opts & UI_CUSTOM_VALUES)
+			if (!ped_geometry_test_sector_inside(pos->start.range, 
+			                                     part->geom.start) ||
+			    !ped_geometry_test_sector_inside(pos->end.range,
+			    				     part->geom.end))
 				switch (ped_exception_throw (
 					PED_EXCEPTION_WARNING,
 					PED_EXCEPTION_YES_NO,
 						/* undo partition addition */
 						goto error_remove_part;
 				}
+			if (!_partition_warn_unaligned(part))
+				goto error_remove_part;
                 } else {
                         goto error_remove_part;
                 }
 	/* We need to make this NULL here, for cfdisk's usage */
 	if (newpart) *newpart = NULL;
         ped_disk_remove_partition (disk, part);
-error_destroy_all_constraints:
+//error_destroy_all_constraints:
         ped_constraint_destroy (final_constraint);
 error_destroy_simple_constraints:
         ped_constraint_destroy (user_constraint);
         ped_constraint_destroy (dev_constraint);
-error_destroy_part:
+//error_destroy_part:
         ped_partition_destroy (part);
 error:
         if (pos->start.range != NULL)
         switch (ex_opt) {
                 case PED_EXCEPTION_CANCEL: return -1;
                 case PED_EXCEPTION_NO: return 0;
+								default: 
+																			 ;
         }
 
         ped_partition_set_system (part, fs_type);
 
 error_remove_partition:
         ped_disk_remove_partition (disk, part);
-error_partition_destroy:
+//error_partition_destroy:
         ped_partition_destroy (part);
-error_constraint_done:
+//error_constraint_done:
         ped_constraint_done (&constraint);
-error:
+//error:
         return 0;
 }
 
 void
 print_partition_types() {
 	PedFileSystemType *walk;
-	char buf[SMALLBUF];
 	for (walk = ped_file_system_type_get_next(NULL); walk; walk = ped_file_system_type_get_next(walk)) {
 		int i = 0;
 		printf ("%-15s",walk->name);
 enum _UIOpts {
 	UI_DEFAULT = 0,
 	/* Warn the user if the operation commits the data to the disk */
-	UI_WARN_COMMIT = 1,
+	UI_WARN_COMMIT = 1 << 0,
 	/* Allow the user to adjust start/end on resize, etc */
-	UI_CUSTOM_VALUES = 2,
+	UI_CUSTOM_VALUES = 1 << 1,
 	/* Allow the user to specify the partition type */
-	UI_SPECIFY_PART_TYPE = 4,
+	UI_SPECIFY_PART_TYPE = 1 << 2,
+    /* Prefer the beginning to be snapped to the old begining
+     * e.g. during resize */
+    UI_SNAP_TO_START = 1 << 3,
 	/* Option specific for each function */
-	UI_FUNCTION_SPECIFIC_1 = 8,
-	UI_FUNCTION_SPECIFIC_2 = 16
+	UI_FUNCTION_SPECIFIC_1 = 1 << 4,
+	UI_FUNCTION_SPECIFIC_2 = 1 << 5
 };
 
+typedef enum _AlignType AlignType;
+enum _AlignType {
+    /* ALIGNMENT_INVALID shouldn't be assigned to partition_align_type */
+    ALIGNMENT_INVALID = 0,
+    ALIGNMENT_NONE,
+    ALIGNMENT_MINIMAL,
+    ALIGNMENT_CYLINDER,
+    ALIGNMENT_OPTIMAL
+};
+
+extern AlignType partition_align_type;
+
 /* Structures used to specify partition position */
 typedef struct _SectPos SectPos;
 struct _SectPos {
 extern int fix_part_position(PedDevice *dev, PedSector *start, PedSector *end,
                              PedSector first, PedSector last);
 
+/* This function converts none, cyl*, opt*, and min* to an AlignType */
+extern AlignType string_to_align_type(const char *);
+
+/* This function takes care of initializing the alignment flags
+ * and should be called after a disk is created. Returns 1 on success */
+extern int init_disk_flags(PedDisk *);
+
 /* Choose the partition position */
 extern int
 query_part_position(const char* prompt, const void* context, PartPos* pos,
 #include <unistd.h>
 #include <fcntl.h>
 #include <limits.h>
+#include <errno.h>
 
 #ifdef ENABLE_MTRACE
 #include <mcheck.h>
 #endif /* GNU_EXT */
   { "interactive", no_argument, NULL, 'i', "where necessary, prompts for user intervention"},
   { "script", no_argument, NULL, 'p', "never prompts for user intervention"},
+  { "align", required_argument, NULL, 'A', "specify align to be none, cyl, min or opt"},
   { "sector-units", no_argument, NULL, 'u', "use sectors instead of cylinder as a default unit"},
   { "sector-size", required_argument, NULL, 'b', "specify the sector size in bytes"},
-  { "cilyndres", required_argument, NULL, 'C', "specify the number of cylinders, actually does nothing"},
+  { "cylinders", required_argument, NULL, 'C', "specify the number of cylinders, actually does nothing"},
   { "heads", required_argument, NULL, 'H', "in lfdisk, specify the number of heads of the disk"},
   { "sectors", required_argument, NULL, 'S', "in lfdisk, specify the number of sectors per track"},
   { "list-partition-types", no_argument, NULL, 't', "displays a list of supported partition types"},
  * to this string 
  *
  * NOTE: I will make function to build dynamic in the future */
-static const char* short_option_string = "hlipvLGs:utb:C:H:S:r";
+static const char* short_option_string = "hlipvLGs:A:utb:C:H:S:r";
 
 
 
 static char* label_type_msg_start = N_("LABEL-TYPE is one of: ");
 static char* flag_msg_start =	N_("FLAG is one of: ");
 static char* unit_msg_start =	N_("UNIT is one of: ");
-static char* part_type_msg =	N_("PART-TYPE is one of: primary, logical, "
-			           "extended\n");
+// unused
+//static char* part_type_msg =	N_("PART-TYPE is one of: primary, logical, "
+//			           "extended\n");
 static char* fs_type_msg_start = N_("FS-TYPE is one of: ");
 static char* start_end_msg =	N_("START and END are disk locations, such as "
 		"4GB or 10%.  Negative values count from the end of the disk.  "
                 "For example, -1s specifies exactly the last sector.\n");
-static char* state_msg =	N_("STATE is one of: on, off\n");
-static char* device_msg =	N_("DEVICE is usually /dev/hda or /dev/sda\n");
-static char* name_msg =		N_("NAME is any word you want\n");
+// unused
+//static char* state_msg =	N_("STATE is one of: on, off\n");
+// static char* device_msg =	N_("DEVICE is usually /dev/hda or /dev/sda\n");
+// static char* name_msg =		N_("NAME is any word you want\n");
 static char* resize_msg_start = N_("The partition must have one of the "
 				   "following FS-TYPEs: ");
 
 	return result;
 }
 #endif
+// unused 
+#if 0
 static void
 help_on (char* topic)
 {
 
         fdisk_command_print_help (cmd);
 }
-
+#endif
 
 static int
 _disk_reread(PedDisk **disk) {
 
 	ped_disk_destroy(*disk);
 
-	*disk = ped_disk_new(dev);
+	if((*disk = ped_disk_new(dev)) == NULL)
+		return 0;
+
+	init_disk_flags(*disk);
 	uiquery.need_commit = 0;
-
+	
+	return 1;
 }
 
 static int
 	return perform_check(*disk,NULL);
 }
 
+#if 0
 static int
 do_cp (PedDisk** disk)
 {
 	return perform_cp(*disk,NULL,UI_WARN_COMMIT);
 }
+#endif
 
 void
 fdisk_print_options_help ()
 	return perform_mklabel(dev,disk,type);
 }
 
+// unused
+#if 0
 static int
 do_mklabel (PedDisk** disk)
 {
 
 	return perform_mklabel(dev,disk,type);
 }
-
+#endif
 static int
 do_mkfs (PedDisk** disk)
 {
 do_mkpart (PedDisk **disk)
 {
 	PartPos			 pos;
-	PedPartition* 		 part;
 	PedPartitionType	 part_type = 0;
 	const PedFileSystemType	*fs_type = ped_file_system_type_get ("ext2");
 	char*			 peek_word;
 	}
 	return 1;
 }
-
+// unused
+#if 0
 static int
 do_name (PedDisk** disk)
 {
 	return perform_name(*disk, NULL, NULL);
 }
+#endif
 
 /* TODO: REMOVE */
 #if 0
 }
 #endif
 
+#if 0
 /* Prints a sector out, first in compact form, and then with a percentage.
  * Eg: 32Gb (40%)
  */
 	PED_FREE (compact);
 	PED_FREE (percent);
 }
-
+#endif
+
+#if 0
 static int
 partition_print (PedPartition* part)
 {
 	ped_file_system_close (fs);
 	return 1;
 }
+#endif
 
 static int
 do_quit (PedDisk** disk)
 			label_disk = ped_disk_new_fresh (label_dev,
 					ped_disk_type_get ("bsd"));
 		}
+		init_disk_flags(label_disk);
 		in_menu = 2;
 		logical_offset = count_logical_partition(*disk);
 		fdisk_interactive_menu(&label_disk, fdisk_bsd_menu_commands, 2);
 	  do_quit (disk);*/
 
 	return 1;
-
-error:
-	return 0;
 }
 
 #define sector(s)	((s) & 0x3f)
 	{
 		print_sector((*disk)->dev, part->prev->geom.start);
 	}
-
+	return 1;
 }
 
 void
 	else {
 		PedCHSGeometry* 	chs;
 		PedSector               sectors;
-		PedSector		cyl_size;
 		PedSector		cyl_start;
 		PedSector		cyl_end;
 		PedSector		sect_size;
 			if (!disk) // Not fatal error
 				continue;
 
+			init_disk_flags(disk);
 			if (fdisk_print_raw)
 				do_raw (&disk);
 			else
         exit(0);
 }
 
+#if 0
 static PedPartitionType
 _disk_get_part_type_for_sector (PedDisk* disk, PedSector sector)
 {
 
 	return PED_PARTITION_LOGICAL;
 }
+#endif
+
 #if 0
 /* This function checks if "part" contains a file system, and returs
  * 	0 if either no file system was found, or the user declined to add it.
 	PedSector first,last;
 	PedConstraint *constraint = NULL;
 	PedPartitionType desired;
-	UIOpts ui_opts = UI_WARN_COMMIT;
+	UIOpts ui_opts = UI_WARN_COMMIT | UI_SNAP_TO_START;
 
 	if (!get_partition (_("Partition"), *disk, &part))
                 	return 0;
 	return perform_rm (*disk, NULL);
 }
 
+#if 0
 static int
 do_select (PedDisk** disk)
 {
 	if (!(*disk = ped_disk_new (dev)))
 	        return 0;
 
+	/* Initialize the disk flags */
+	if (!init_disk_flags(*disk)) {
+		ped_disk_destroy(*disk);
+		*disk = NULL;
+		return 0;
+	}
+
+
 	/* Tell the user we are using the new device. */
 	fdisk_print_using_dev (dev);
 
 
 	return 1;
 }
-
+#endif
+
+#if 0
 static int
 do_set (PedDisk** disk)
 {
   return perform_set (*disk, NULL, 0, UI_DEFAULT);
 }
-
+#endif
 static int
 do_toggle_boot_flag (PedDisk** disk)
 {
 do_fix_partition_order (PedDisk **disk)
 {
 	fix_partition_order(*disk);
+	return 1;
 }
 
 /* The next three are for lfdisk compatibility with fdisk */
 static int
 _parse_options (int* argc_ptr, char*** argv_ptr)
 {
-  int opt;
+  int opt, align_type;
   struct option *options_table, *ptr;
 
   /* Build option table we need two pointers because getopt long
 	case 't':
 	  print_partition_types();
 	  break;
+	case 'A':
+	  align_type = string_to_align_type(optarg);
+	  if (align_type == ALIGNMENT_INVALID) {
+	      fdisk_usage_msg();
+	      return 0;
+	  }
+      partition_align_type = align_type;
+      break;
 	case 'u':
 	  ped_unit_set_default(PED_UNIT_SECTOR);
 	  cylinder_unit = 0;
   free(options_table);
   
   return 1;
-/* what is? */
-error:
-  return 0;
 }
 
 static PedDevice*
  error_done_commands:
   _done_commands ();
   _done_messages ();
-  
- error_done_ui:
+ 
+ // unused	
+ //error_done_ui:
   fdisk_done_ui ();
   
  error:
 fdisk (int argc, char** argv)
 {
   PedDevice* dev;
-  PedDisk* disk;
   
   if (argc <= 1)
     {
 #include <string.h>
 #include <stdint.h>
 #include <sys/stat.h>
+#include <unistd.h>
 #include <fcntl.h>
+#include <ctype.h>
 #include "hacks.h"
 #include "sys_types.h"
 
 	else
 	#endif
 	return NULL;
+	return NULL; // avoid warning
 }
 
 
 
 /* not 0 when fdisk should print the partition table? */
 extern int fdisk_list_table;
+extern int init_disk_flags(PedDisk *disk);
+extern void fdisk_print_partition_size(PedDisk *disk);
+extern void fdisk_do_list_devices (PedDisk* disk);
 
 #if HAVE_LOCALE_H
 # include <locale.h>
   sigjmp_buf	 jmp_state;
 } readline_state;
 
-static PedExceptionOption current_exception_opt = 0;
+// unused
+//static PedExceptionOption current_exception_opt = 0;
 
 /* If we don't want the possibilities to appear on the prompt, this
    should be set to 0. TODO: Making this without a global variable
    might be a good idea */
-static prompt_possibilities = 1;
+static int prompt_possibilities = 1;
 
 
 #if HAVE_LIBREADLINE
 int
 fdisk_interactive_mode(PedDevice **dev, FdiskCommand* cmd_list[])
 {
-  char*	line;
   PedDisk *disk;
-  StrList* list;
   StrList* command_names = fdisk_command_get_names (cmd_list);
     
   puts (interface_name);
 		  "content won't be recoverable.\n"));
 	  if((disk = ped_disk_new_fresh(*dev, ped_disk_type_get("msdos"))) == NULL)
 	    return EXIT_FAILURE;
+	  if(!init_disk_flags(disk)) {
+	  	ped_disk_destroy(disk);
+		return EXIT_FAILURE;
+	  }
 	}
       else
 	{
 	  char *str;
 
 	  for(label_type = ped_disk_type_get_next(NULL);
-	      label_type = ped_disk_type_get_next(label_type); )
+	      label_type != NULL;
+				label_type = ped_disk_type_get_next(label_type) )
 	    {
 	      supp = str_list_append(supp, label_type->name);
 	      supp = str_list_append(supp, " ");
 	  if(!disk)
 	    return EXIT_FAILURE; /* what bad? :( */
 
+	  if (!init_disk_flags(disk)) {
+	  	ped_disk_destroy(disk);
+	  	return EXIT_FAILURE;
+	  }
+	  
 	  /* Free other resources */
 	  free(str);
 	  free(supported_types);
       disk = ped_disk_new(*dev);
       if(!disk)
 	return EXIT_FAILURE;
+      if(!init_disk_flags(disk)) {
+	ped_disk_destroy(disk);
+        return EXIT_FAILURE;
+      }
     }
   
   /***
 int
 fdisk_interactive_menu (PedDisk** disk, FdiskCommand* cmd_list[], int menu)
 {
-	char*		line;
-	StrList*	list;
 	StrList*	command_names = fdisk_command_get_names (cmd_list);
 
 	/* FIXME yucky, nasty, evil hack */
 	return valid;
 }
 
-fdisk_command_line_get_llinteger (const char* prompt, long long* value)
+int fdisk_command_line_get_llinteger (const char* prompt, long long* value)
 {
 	char	def_str [22];
 	char*	input;

tests/check_advanced.c

 	disk2 = ped_disk_new(dev2);
 	//fail_unless(1, "hm");
 
+	init_disk_flags(disk2);
 
 	srand(129312);
 	int i;
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.