Anonymous avatar Anonymous committed 0ed0f44

Fix several bugs, improve exception handling, improve creating partitions and creating filesystems on partitions, add texinfo manual. (fdisk@sv.gnu.org/fdisk--main--0--patch-21)
fdisk@sv.gnu.org/fdisk--main--0--patch-21
Keywords:

Comments (0)

Files changed (6)

+info_TEXINFOS = cfdisk.texi
 man_MANS      =	cfdisk.8
 one cylinder. It depends on the cylinder size.
 .TP
 .B chs
-use CHS display units.
+use CHS display units.
+.SH BUGS
+There are no known bugs. We are in early stages for development, so be careful.
+.SH SEE ALSO
+.BR fdisk (8),
+.BR mkfs (8),
+.BR cfdisk (8)
+The \fIcfdisk\fP program is fully documented in the
+.BR info(1)
+format
+.IR "GNU cfdisk User Manual"
+manual.
+\input texinfo   @c -*-texinfo-*-
+@setfilename cfdisk.info
+@settitle GNU cfdisk User's Manual
+
+@comment @documentencoding ISO-8859-1
+
+@set lq ``
+@set rq ''
+
+@c modifications must also be done in the titlepage
+@copying
+Copyright @copyright{} 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
+any later version published by the Free Software Foundation; with no
+Invariant Sections, with no Front-Cover Texts, and with no Back-Cover
+Texts.  A copy of the license is included in the section entitled ``GNU
+Free Documentation License''.
+@end copying
+@insertcopying
+
+@titlepage
+@title GNU cfdisk User Manual
+@subtitle GNU cfdisk
+@author Milko Krasnomirov Krachounov @email{exabyte@@3mhz.net}
+
+@c @page
+@c @vskip 0pt plus 1filll
+
+@c modifications must also be done in the copying block
+Copyright @copyright{} 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
+any later version published by the Free Software Foundation; with no
+Invariant Sections, with no Front-Cover Texts, and with no Back-Cover
+Texts.  A copy of the license is included in the section entitled ``GNU
+Free Documentation License''.
+@end titlepage
+
+
+@dircategory GNU partitioning software
+@direntry
+* cfdisk: (cfdisk).                         GNU cfdisk User Manual
+@end direntry
+
+@node Top
+@top GNU cfdisk User Manual
+
+@shortcontents
+
+@menu
+* About::
+* Using cfdisk::
+* Bugs::
+* See also::
+* Copying this manual::
+@end menu
+
+
+@node About
+@chapter About
+@menu
+* Name::
+@end menu
+
+@node Name
+@section Name
+
+GNU cfdisk @minus{} curses-based partition table manipulator (clone of Linux cfdisk)
+
+@node Using cfdisk
+@chapter Using cfdisk
+
+@menu
+* Invoking cfdisk::
+* Overview::
+* Options::
+* Units::
+* Usage::
+@end menu
+
+@node Invoking cfdisk
+@section Invoking cfdisk
+
+@b{cfdisk [options] [device]}
+
+@node Overview
+
+@section Overview
+
+Hard disks can be divided into logical disks called @i{partitions}
+(or @i{disk slices} in the BSD world), which are described in a @i{partition table}, 
+which is also called a @i{disklabel}.
+
+For ordinary use, like file storage or operation system installation, you
+will most likely need at least one partition, although with most modern operating system,
+you might also want to create several partitions, including one for swap space. For example,
+you usually create a seperate partition for home directories. For more information on what
+partitions you need for your operating system, look at its installation manual.
+
+@b{GNU cfdisk} is a menu-driven program for creating and editing partition tables. It has support
+for DOS and MAC type partition tables, BSD and SUN type disklabels and others.
+
+If you don't specify the device of the disk, cfdisk tries to look for devices and opens the first
+device available. On most GNU/Linux distributions @i{device} is usually one of the following:
+
+@c ---------------------------------------------------------------------
+@display
+@c ---------------------------------------------------------------------
+@quotation
+/dev/hda
+/dev/hdb
+/dev/sda
+/dev/sdb
+
+@end quotation
+@end display
+
+IDE disks are usually using /dev/hd[a-h] for device names, SCSI disks - /dev/sd[a-p]. The partitions will
+take the device name followed by the partition number, e.g. /dev/hda1. If you are using a GNU/Linux
+operating system, you can see @i{/usr/src/linux/Documentation/devices.txt} for more infomation on
+device naming.
+
+A DOS type partition table can have up to four `primary' partitions, which get numbers 1-4. One of the 
+primary partitions may be used as an `extended' partition, which is used as a container for more partitions,
+which are called `logical' and take numbers starting from 5.
+
+A BSD/SUN type disklabel can hold up to 8 partitions, and an IRIX/SGI type disk label, called `dvh'
+in cfdisk can hold up to 16.
+
+@node Options
+
+@section Options
+
+@table @code
+@item @b{@minus{}h, @minus{}@minus{}help}
+Displays a help message.
+
+@item @b{@minus{}v, @minus{}@minus{}version}
+Displays the program's version.
+
+@item @b{@minus{}z, @minus{}@minus{}new-table}
+Create a new partition table on the disk. This is useful if  you
+want  to  change the partition table type or want to repartition
+you entire drive. Note that this does not delete the  old  table
+on the disk until you commit the changes.
+
+
+@item @b{@minus{}u, @minus{}@minus{}units=}@i{UNIT}
+Sets the default display units to @i{UNIT}. A list of possible units
+is given below.
+
+@item @b{@minus{}l, @minus{}@minus{}list-partition-types}
+Displays a list of supported partition types and features.
+
+@end table
+
+@node Units
+
+@section Units
+
+You can choose in what unit cfdisk should display quantities like partition sizes. You can choose from sectors, percents, bytes, kilobytes, etc. Note that one kilobyte is equal to 1,000 bytes, as this is consistent with the SI prefixes and is used by hard disk manufacturers. If you prefer to see the sizes in units with binary prefixes, you should instead select one kilo binary byte (kibibyte), which is equal to 1,024 bytes. Whatever display unit you have chosen, you can always enter the quantities in the unit of your choice, for example 1000000B or 1000kB.
+
+@table @code
+
+@item @b{compact}
+Display each size in the most suitable unit from B, kB, MB, GB and TB.
+
+@item @b{B}
+One byte
+
+@item @b{kB }
+One kilobyte (1,000 bytes)
+
+@item @b{MB}
+One megabyte (1,000,000 bytes)
+
+@item @b{GB}
+One gigabyte (1,000,000,000 bytes)
+
+@item @b{TB}
+One terabyte (1,000,000,000,000 bytes)
+
+@item @b{KiB}
+One kilo binary byte (1,024 bytes)
+
+@item @b{MiB}
+One mega binary byte (1,048,576 bytes)
+
+@item @b{GiB}
+One giga binary byte (1,073,741,824 bytes)
+
+@item @b{TiB}
+One tera binary byte (1,099,511,627,776 bytes)
+
+@item @b{s}
+One sector. It depends on the sector size of the disk. You can use it if you want to see or choose the exact size in sectors.
+
+@item @b{%}
+One percent from the size of the disk
+
+@item @b{cyl}
+One cylinder. It depends on the cylinder size.
+
+@item @b{chs}
+Use CHS display units.
+
+@end table
+
+@node Usage
+
+@section Usage
+
+@b{GNU cfdisk} uses a simple menu driven interface, which attempts to be clear and easy to use. It shows a list of the partitions, showing basic information about them, such as number, size, type and filesystem. If the partition contains no filesystem, on certain partition table types the partition system type is displayed in brackets. You to navigate through the partitions using the up and down arrow keys on your keyboard. You can perform actions on the selected partition either by pressing their shortcut key, or by navigating through the menu of actions with the left and right arrow and launching it by pressing the enter key. Other choice menus are also usable with both shortcut keys and direct selection, and the Esc key is usually used to cancel the choice. The actions are not performed immediately, but only after you decide to commit the changes to the disk. Here is a list of the possible actions and their shortcut keys.
+
+@table @code
+@item @b{n}
+If you have selected a free space, creates a new partition residing on it. The possible types of the new partition, such as @i{Primary}, @i{Extended} and @i{Logical} are shown in the type column in the partition list. For example if the free space is part of the extended partition, its type will be displayed as Logical. If multiple types are possible, a choice menu will appear. You can select primary partition with the `p' key and extended partition with `e', or alternatively you can cancel the creation with `c'. You will be asked in which part of the free space you want to place the partition. You can place it in the beginning with `s', at the end with `e'. If you want to select a custom region and specify exact start and end of the partition, you should press `c'. You will then prompted about the size of the partition, the default choice creates a partition on the entire free space. Please note that you can enter the size in any of the units given above. If you don't specify a unit after the number, the default unit is used. At this point, you will be asked about the filesystem type. If you don't know what partition type suits you, check operating system documentation about supported filesystems, ext3 is usually a safe choice. The partition will be created at the close as possible to your choice and you will be warned if it is too small or too large for the filesystem you have selected.
+
+@item @b{d}
+Delete the selected partition so you can use it to create another partition on the free space left by it.
+
+@item @b{f}
+Creates a new file system on the selected partition. You will be asked to choose from a list of the filesystem types that are supported for creation. Please note that this requires that all changes you made so far are commited to the disk. If there is already a filesystem on the partition, it is destroyed.
+
+@item @b{c}
+Checks the consistency of the filesystem.  It is useful to see whether it is safe to perform operations like resize on the partitions. It performs a very basic check on the filesystem, so if you want to make a more thorough test or fix the errors on the filesystem, you should an external utility like e2fsck for ext2 or reiserfsck for reiserfs. Please note that the check is limited on some filesystem types (ext2, ext3 and reiserfs at the time of writing of the manual), but if the partition contains errors resize will gracefully fail without destroying the filesystem.
+
+@item @b{r}
+Resizes the partition without destroying the data on it, or just changes the partition size. The latter is useful if you want to resize the partition with external utilities or if you want to create a new filesystem on it. Don't use it if you don't know what you are doing. If resizing of the filesystem on the partition is supported you will be asked what to do. Pressing `r' resizes, while pressing `c' just changes the partition size. Then like when creating a new partition you will be asked to choose among the possible places and sizes to place the partition. The choices are between placing it at the beginning of the free space before it with `b', leaving its starting point fixed with `s' and placing it at end of the free space after it with `e'. You are adviced to check the partition before performing resize, and backup the data if possible. Resizing requires that all changes you made so far are commited to the disk.
+
+@item @b{o}
+Moves the partition to another place on the hard disk. You will be asked to select on which free space to put the partition and then prompted for a position and size, in the same manner as when creating a new partition. The new place of the partition can't overlap with the old one. If this is what you need, you should try using the resize function, instead. Moving the partition requires that all changes you made so far are commited to the disk.
+
+@item @b{y}
+Copies another partition over the selected one. This destroys all data on the current partition and requires all changes to be commited to the disk. You are not limited to select a partition only from the device you are currently editing. You will be asked about device and partition. You can't copy an extended partition.
+
+@item @b{s}
+Run a filesystem rescue by looking for deleted partitions within a free space. It requires that everything is commited to the disk immediately. Looking for partitions over the existing partitions is not supported and doesn't seem much meaningful, but if you need it, you can try deleting the partitions. You can select the range where to look for partitions by pressing `c', or if you want to check the whole free space, you should press `g'.
+
+@item @b{b}
+Shows a list of the flags allowing you to change them. You will most likely need this to make the partition bootable. It is not recommended to touch any flags other than the bootable flag. Do not do it, unless you know what they are for, and have in mind that changing certain flags is known not to work. You change the flag by pressing space or enter, and you leave the list with Esc.
+
+@item @b{t}
+Changes the system type on the partition. This does not convert the filesystem, it just changes the information stored in the partition. This is useful for cases where the system type on the partition doesn't match the filesystem type, for example you have an fat32 partition on an DOS type partition table, having an ext2 filesystem on it. Changing the system type is not really meaningful on all partition table types. The default is to automatically determine the system type from the current filesystem with `a'. You can also select a custom filesystem by pressing `c', but this is not recommended. Direct choosing a specific system type is not supported.
+
+@item @b{m}
+If the partition table type supports partition names, this allows you to change it. This is not working on all partition table types, as the partition names could be used for other purposes, like identifying the partition type or filesystem.
+
+@item @b{x}
+If you have selected the extended partition, this makes it as big as possible, so you have more place for partitions inside it. It should expand the partition up to the beginning of the first partition after it.
+
+@item @b{z}
+If you have selected the extended partition, this makes it as small as possible. You should need this, if you want to create more primary partitions after the logical partitions contained in the extended. If the extended partition contains no partitions, this deletes it.
+
+@item @b{u}
+This allows you to select the display units. The key shortcuts are not very convenient, so use the menu, if possible. The shortcuts are `1', `2', ..., `9', `a', ..., `e'. This changes the units used to display the sizes in the partition list and the default unit that is used on size prompts, though you are not limited to it when entering sizes. See the ``Units'' section for more information.
+
+@item @b{i}
+Displays a short info about the partition, like its device (or at least what cfdisk believes that should be its device), the system type of the partition in the partition table (most useful if you are editing a DOS type partition table), the exact start and end of the partition.
+
+@item @b{w}
+Writes the changes in the partition to the disk and notifies the operating system to reread it. Do this after you have completed editing your partition table. This might destroy data on your disk, if you have deleted partitions, and so on, so be careful. If the partition table is not re-read correctly by the operating system, you should reboot your computer.
+
+@item @b{q}
+Quits the program. If you have made changes and you haven't commited them to the disk, they will be lost.
+
+@item @b{h}
+Displays a short help. You don't need it after you have read this manual.
+
+
+@end table
+
+@node Bugs
+
+@chapter Bugs
+
+There are no known bugs. We are in early stages for development, so be careful.
+
+@node See also
+
+@chapter See also
+
+@b{fdisk}@r{(8),}
+@b{mkfs}@r{(8),}
+@b{parted}@r{(8)}
+
+@node Copying this manual
+@appendix Copying this manual
+
+@menu
+* GNU Free Documentation License::  License for copying this manual
+@end menu
+
+@include fdl.texi
+
+@bye
+
 #endif
 
 
-/* This is an ancient magic that turns a magic into a StrList, so we can display it */ 
+/* This is an ancient magic that turns a char* into a StrList, so we can display it */
 static StrList*
 _message_display_strlist(const char *msg, int *lines, int double_new_line) {
 	int x = 0, y = 0, lastword = 0, isnewline = 0, i;
-	StrList *message;
+	StrList *message = NULL;
 	char buf[SMALLBUF];
 	/* We save the lines in a string list, counting them */
 	/* TODO: It doesn't deal with tabs correctly, I hope we don't need this anyway */
 	if (lines) *lines = y;
 	return message;
 }
+static void
+strlist_draw (const char *prompt, const StrList *strlist, int opts, const StrList* selected, 
+              int selnum, int *start);
+static const StrList*
+do_strlist (const char *prompt, const StrList *strlist, int opts);
 
 static void
-_display_strlist (const StrList *message, int y) {
+_display_strlist (const char* title, const StrList *message, int y) {
 	int x, i;
 	/* TODO: Write this, for now I will test it this way */
 	y=LINES-3-MENUSIZE-y;
-	/*  */
+	if (y < INFOSIZE+4)
+		y = INFOSIZE+4;
 	i=INFOSIZE+1;
 	move(i++,0); clrtoeol();
 	mvaddch(i,0,' ');
 	for (i++; i < y; i++) {
 		move(i,0); clrtoeol();
 	}
+	mvaddstr(y-3,1,title);
+	for (x = 1; title[x-1]; x++) {
+		mvaddch(y-2,x,'=');
+	}
+	
 	const StrList *current;
 	for (current = message; current && y < LINES-MENUSIZE-3; current = current->next, y++) {
 		char *temp = str_list_convert_node(current);
 }
 
 static void 
-display_message (const char *msg) {
-	int y;
-	StrList *message = _message_display_strlist(msg,&y,1);
-	_display_strlist(message, y);
+display_message (const char* title, const char *msg) {
+	int lines;
+	StrList *message;
+	message = _message_display_strlist(msg,&lines,1);
+	_display_strlist(title, message, lines);
 	str_list_destroy(message);
 	
 }
 			print_warning(_("Invalid key"),0);
 		}
 	}
-	if (save_selection)
+	if (sel && save_selection)
 		*sel = selected;
 	return key;
 }
 	for (current = strlist, i = 0; current && y < n; current = current->next, i++) {
 		if (i < *start)
 			continue;
-		if (current == selected && !(opts & 1))
+		if (!(opts & 1) && current == selected)
 			attron(A_STANDOUT);
 		move(y,0); clrtoeol();
 		temp = str_list_convert_node(current);
 		mvaddstr(y,x,temp);
 		if (temp) free(temp);
-		if (current == selected && !(opts & 1))
+		if (!(opts & 1) && current == selected)
 			attroff(A_STANDOUT);
 		y++;
 	}
 	};
 	char keys[TINYBUF];
 	int res,i,k = 0;
+	char *title;
+	switch (ex->type) {
+		case PED_EXCEPTION_INFORMATION:
+			title = _("Information");
+			break;
+		case PED_EXCEPTION_WARNING:
+			title = _("Warning!");
+			break;
+		case PED_EXCEPTION_ERROR:
+			title = _("Error!");
+			break;
+		case PED_EXCEPTION_FATAL:
+			title = _("Fatal exception!");
+			break;
+		case PED_EXCEPTION_BUG:
+			title = _("Bug in the program");
+			break;
+		case PED_EXCEPTION_NO_FEATURE:
+			title = _("Unsupported");
+			break;
+	}
 	for (i = 0; ex_keys[i].key; i++)
 		if (ex->options & ex_keys[i].option) {
 #if 0
 	if (k < TINYBUF)
 #endif
 	keys[k] = '\0';
-	display_message(ex->message);
+	display_message(title,ex->message);
 	res = do_menu(ex_choices, 8, MENU_BUTTON, keys, NULL);
 	for (i = 0; ex_keys[i].key; i++)
 		if (ex_keys[i].key == res)
 static int
 _query_part_position(const MenuItem* menu, PedSector *start, PedSector *end, 
 		     PedSector first, PedSector last, PedConstraint *constraint, UIOpts *opts) {
-	PedSector length = *end-*start+1, min_len = 0, max_len;
+	PedSector length = *end-*start+1, min_len = 0, max_len = dev->length;
 	int key,i,done;
 	char *temp,*temp2,*def_str, keys[6], buf[SMALLBUF];
 	i = 0;
 	/* If we have a constraint, check whether we can move the partition start */
 	if (constraint && (constraint->start_align->grain_size == 0 || constraint->start_range->length == 1))
-		key = 'f';
+		key = 's';
 	else {
 		/* If there the first possible sector is not the start of the selected partition,
 			we need one choice in the menu to make the start fixed and one to move it back.
-			When it is, 'b' and 'f' do the same. We ditch 'b' for more friendly resize menu,
-			action_new should use 'f' as it doesn't matter there. 
+			When it is, 'b' and 's' do the same. We ditch 'b' for more friendly resize menu,
+			action_new should use 's' as it doesn't matter there. 
 			FIXME: I wrote this fragment better, but ruined it. Now I'm too lazy to fix it */
 		if (first < *start) keys[i++] = 'b';
-		keys[i++] = 'f'; keys[i++] = 'e'; keys[i++] = 'c';
+		keys[i++] = 's'; keys[i++] = 'e'; keys[i++] = 'c';
 		keys [i++] = ESC;
 		keys [i] = '\0';
 		/* NOTE: Run menu_title before running this function */
 			*opts |= UI_CUSTOM_VALUES;
 		} else {
 			*opts &= ~UI_CUSTOM_VALUES;
-			if (key == 'f')
+			if (key == 's')
 				max_len = last-*start+1;
 			else
 				max_len = last-first+1;
 				*end = last;
 				*start = last-length+1;
 			}
-			else if (key == 'f') {
+			else if (key == 's') {
 				*end = *start+length-1;
 			}
 		}
 /* Here we define our menu operations */
 static int
 action_new (PedPartition **part) {
+	PedPartition *temp = (*part)->prev;
 	static MenuItem part_position[] = {
-		{ 'f', N_("Begining"), N_("Create the partition at the begining of the free space") },
+		{ 's', N_("Begining"), N_("Create the partition at the begining of the free space") },
 		{ 'e', N_("End"), N_("Create the partition at the end of the free space") },
 		{ 'c', N_("Custom"), N_("Select custom start and end position of the partition") },
 		{ ESC, N_("Cancel"), N_("Do not create a partition") },
 		{ 0, NULL, NULL }
 	};
 	const char type_keys[] = {'p', 'e', ESC, '\0'};
-	PedPartitionType type;
+	PedPartitionType type = 0;
 	PedSector start, end;
 	int key,success = 1,done;
 	UIOpts opts = UI_DEFAULT;
 		return 0;
 
 	if (!do_mkpart(disk,start,end,type,NULL,part,opts,&uiquery)) {
+		if (!*part) 
+			*part = temp->next;
 		warning_waitkey(N_("Can't create partition."));
 		return 0;
 	}
 static int
 action_resize (PedPartition **part) {
 	static MenuItem part_position[] = {
-		{ 'f', N_("Fixed start"), N_("Don't move the beginning of the partition") },
+		{ 's', N_("Fixed start"), N_("Don't move the beginning of the partition") },
 		/* FIXME: Wording. */
 		{ 'b', N_("Begining"), N_("Place it as back as possible on partitions that support it") },
 		{ 'e', N_("End"), N_("Place it as forward as possible on partitions that support it") },
 action_move (PedPartition **part) {
 	/* Combine this with new partition? */
 	static MenuItem part_position[] = {
-		{ 'f', N_("Begining"), N_("Move the partition to the begining of the free space") },
+		{ 's', N_("Begining"), N_("Move the partition to the begining of the free space") },
 		{ 'e', N_("End"), N_("Move the partition to the end of the free space") },
 		{ 'c', N_("Custom"), N_("Select custom start and end position of the partition") },
 		{ ESC, N_("Cancel"), N_("Do not move the partition") },
 	};
 	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 (key == ESC) return 0;
+
+	/* Remember either the previous partition so we can select the free space */
+	temp = disk_get_prev_nmd_partition(disk, *part);
+	if (temp && temp->type & PED_PARTITION_FREESPACE)
+		temp = disk_get_prev_nmd_partition(disk, temp); 
+
 	if(!do_rescue (disk, (*part)->geom.start, (*part)->geom.end, 
 	           UI_WARN_COMMIT | (key == 'c' ? UI_CUSTOM_VALUES : 0), &uiquery)) {
 		warning_waitkey(N_("There was an error during rescue"));
 		return 0;
 	}
+	do {
+		temp = ped_disk_next_partition(disk,temp);
+	} while (temp && temp->type & PED_PARTITION_METADATA); 
+	*part = temp;
 	notice_waitkey(N_("Finished looking for partitions"));
 	return 1;
 }
 
 static int
 action_commit () {
-	if (!do_commit(disk,&uiquery)) {
+	if (!do_commit(disk,UI_WARN_COMMIT,&uiquery)) {
 		warning_waitkey(N_("Commit failed."));
 		return 0;
 	} 
 static int
 action_type (PedPartition **part) {
 	static MenuItem type_menu[] = {
-		{ 'f', N_("Auto"), N_("Try to automatically set the correct type") },
+		{ 'a', N_("Auto"), N_("Try to automatically set the correct type") },
 		{ 'c', N_("Custom"), N_("Select a custom filesystem type (for experts only)") },
 		{ ESC, N_("Cancel"), N_("Do not change the filesystem type") },
 		{ 0, NULL, NULL }
 	};
-	static char keys [] = { 'f', 'c', ESC, '\0' };
+	static char keys [] = { 'a', 'c', ESC, '\0' };
 	const PedFileSystemType *type = NULL;
 	int key;
 	menu_title(_("Set the filesystem type of the partition")); 
 
 	if (key == ESC)
 		return 0;
-	else if (key == 'f')
+	else if (key == 'a')
 		type = ped_file_system_probe(&(*part)->geom);
 	if (!do_set_system(disk,*part,type,&uiquery)) {
 		warning_waitkey(N_("Couldn't change the filesystem type"));
 
 		if (part == selected) attroff(A_STANDOUT);
 	}
-	while (y < n) {
+	/* Please note that we clean one more line */
+	while (y < n+1) {
 		move(y++,0); clrtoeol();
 	}
 	refresh();
 		mvaddstr(y++,get_center(info_model),info_model);
 	
 	if (info_size) {
-		snprintf(buf,SMALLBUF,"Disk: %s   Size: %s", devname, info_size);
+		snprintf(buf,SMALLBUF,_("Disk: %s   Disk type: %s    Size: %s"), 
+		         devname, disk->type->name, info_size);
 	}
 	else {
-		snprintf(buf,SMALLBUF,"Disk: %s", devname);
+		snprintf(buf,SMALLBUF,_("Disk: %s   Disk type: %s"), devname, disk->type->name);
 	}
 	mvaddstr(y++,get_center(buf),buf);
 	
 	if (info_heads && info_sectors && info_cylinders) {
-		snprintf(buf,SMALLBUF, "Heads: %s   Sectors per track: %s   Cylinders: %s",
+		snprintf(buf,SMALLBUF, _("Heads: %s   Sectors per track: %s   Cylinders: %s"),
 				info_heads, info_sectors, info_cylinders);
 		mvaddstr(y++,get_center(buf),buf);
 	}
 		(_("WARNING: This writes all data to disk automatically, continue?"),uiquery)) 
 			return 0;
 	/* It doesn't hurt to commit at that point, right? */
-	if (uiquery->need_commit) if (!do_commit(dst_disk,uiquery)) goto error;
+	if (uiquery->need_commit) if (!do_commit(dst_disk,UI_DEFAULT,uiquery)) goto error;
         
 
         src_disk = dst_disk;
 {
 
         PedFileSystem*          fs;
+	PedConstraint*		constraint = NULL;
 	if (opts & UI_WARN_COMMIT) {
 		if (!ask_boolean_question 
 		(_("WARNING: This writes all data to disk automatically, continue?"),uiquery)) 
         	if (!get_fs_type (_("File system"), &type, 1, uiquery))
 	                goto error;
 	}
-
+	/* We check whether we can create this partition here */
+	constraint = ped_file_system_get_create_constraint(type,disk->dev);
+	//if (!constraint) return 0;
+	if (constraint)
+		if (!ped_constraint_is_solution(constraint,&(part->geom))) {
+			if (part->geom.length < constraint->min_size) {
+				ped_exception_throw (PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
+				_("The partition is too small to create %s filesystem on it."), type->name);
+				ped_constraint_destroy(constraint);
+				return 0;
+			}
+			else if (part->geom.length > constraint->max_size) {
+				ped_exception_throw (PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
+				_("The partition is too big to create %s filesystem on it"), type->name);
+				ped_constraint_destroy(constraint);
+				return 0;
+			}
+			/* FIXME: WHAT THE?.. */
+			//else {
+			//	ped_exception_throw (PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
+			//        _("You can't create %s filesystem on this partition."), type->name);
+			//}
+			//ped_constraint_destroy(constraint);
+			//return 0;
+		}
+	ped_constraint_destroy(constraint);
 
         fs = ped_file_system_create (&part->geom, type, uiquery->timer);
         if (!fs)
 
 /* The parameter custom is 1, then the user is asked about the start and end sector *
  * If the parameter newpart is not NULL, it is set to the newly created partition */
+/* NOTE: On some occassions it changes the *newpart to NULL! */
 int
 do_mkpart (PedDisk* disk, PedSector start, PedSector end, PedPartitionType part_type,
 	const PedFileSystemType* fs_type, PedPartition **newpart, UIOpts opts, UICalls *uiquery)
         PedConstraint*           user_constraint;
         PedConstraint*           dev_constraint;
         PedConstraint*           final_constraint;
+	PedConstraint*		 fs_constraint;
        /* char*                    peek_word;*/
         char*                    part_name = NULL;
         char                     *start_usr = NULL, *end_usr = NULL;
                 if (!get_fs_type (_("File system type"), &fs_type, 0, uiquery))
                         goto error;
         }
+
         /*if (peek_word)
                 ped_free (peek_word);*/
 
+
+
         if (ped_disk_type_check_feature (disk->type,
                                          PED_DISK_TYPE_PARTITION_NAME)) 
                 uiquery->getstring(_("Partition name"), &part_name, NULL, NULL, 1); 
         /* subject to partition constraint */
         ped_exception_fetch_all();
         if (!ped_disk_add_partition (disk, part, final_constraint)) {
+		ped_exception_catch();
                 ped_exception_leave_all();
                
                 if (ped_disk_add_partition (disk, part,
                         end_usr   = ped_unit_format (disk->dev, end);
                         start_sol = ped_unit_format (disk->dev, part->geom.start);
                         end_sol   = ped_unit_format (disk->dev, part->geom.end);
+
 			if (opts & UI_CUSTOM_VALUES)
-                        switch (ped_exception_throw (
-                                PED_EXCEPTION_WARNING,
-                                PED_EXCEPTION_YES_NO,
-                                _("You requested a partition from %s to %s.\n"
-                                  "The closest location we can manage is "
-                                  "%s to %s.  "
-                                  "Is this still acceptable to you?"),
-                                start_usr, end_usr, start_sol, end_sol))
-                        {
-                                case PED_EXCEPTION_YES:
-                                        /* all is well in this state */
-                                        break;
-                                case PED_EXCEPTION_NO:
-                                case PED_EXCEPTION_UNHANDLED:
-                                default:
-                                        /* undo partition addition */
-                                        goto error_remove_part;
-                        }
+				switch (ped_exception_throw (
+					PED_EXCEPTION_WARNING,
+					PED_EXCEPTION_YES_NO,
+					_("You requested a partition from %s to %s.\n"
+					"The closest location we can manage is "
+					"%s to %s.  "
+					"Is this still acceptable to you?"),
+					start_usr, end_usr, start_sol, end_sol))
+				{
+					case PED_EXCEPTION_YES:
+						/* all is well in this state */
+						break;
+					case PED_EXCEPTION_NO:
+					case PED_EXCEPTION_UNHANDLED:
+					default:
+						/* undo partition addition */
+						goto error_remove_part;
+				}
                 } else {
                         goto error_remove_part;
                 }
-        }
-        ped_exception_catch();
+        } else {
+		ped_exception_leave_all();
+	}
+
+	/* We check whether we can create this filesystem here */
+	fs_constraint = ped_file_system_get_create_constraint(fs_type,disk->dev);
+	if (fs_constraint) {
+		if (!ped_constraint_is_solution(fs_constraint,&(part->geom))) {
+			const char *error = NULL;
+			if (part->geom.length < fs_constraint->min_size) {
+				error = _("The size of the partition is too small for %s filesystem");
+			}
+			else if (part->geom.length > fs_constraint->max_size) {
+				error = _("The size of the partition is too big for %s filesystem");
+			}
+			/* FIXME: WHAT THE?.. */
+			//else {
+			//	error = _("You can't use this partition for %s filesystem");
+			//}
+			if (error)
+				switch (ped_exception_throw (
+					PED_EXCEPTION_WARNING,
+					PED_EXCEPTION_IGNORE_CANCEL,
+					error, fs_type->name)) {
+					case PED_EXCEPTION_IGNORE:
+						/* User doesn't care */
+						break;
+					case PED_EXCEPTION_CANCEL:
+					case PED_EXCEPTION_UNHANDLED:
+					default:
+						ped_constraint_destroy(fs_constraint);
+						goto error_remove_part;
+				}
+		}
+		ped_constraint_destroy(fs_constraint);
+	}
 
         /* set minor attributes */
         if (part_name)
         return 1;
 
 error_remove_part:
+	/* We need to make this NULL here, for cfdisk's usage */
+	*newpart = NULL;
         ped_disk_remove_partition (disk, part);
 error_destroy_all_constraints:
         ped_constraint_destroy (final_constraint);
 	}
 	/* So the best we can do here is to commit */
 	if (uiquery->need_commit)
-		if (!do_commit(disk,uiquery))
+		if (!do_commit(disk,UI_DEFAULT,uiquery))
 			goto error;
 	if (!part)
         	if (!get_partition (_("Partition"), disk, &part, uiquery))
 			return 0;
 	/* Why the hell I use two seperate ifs, instead of one? I wish I knew */
 	if (uiquery->need_commit)
-		if (!do_commit(disk,uiquery))
+		if (!do_commit(disk,UI_DEFAULT,uiquery))
 			goto error;
         if (!get_sector (_("Start"), disk->dev, &start, NULL, opts & UI_CUSTOM_VALUES, uiquery))
                 goto error;
 		(_("WARNING: This writes all data to disk automatically, continue?"),uiquery)) 
 			return 0;
 	if (uiquery->need_commit)
-		if (!do_commit(disk,uiquery))
+		if (!do_commit(disk,UI_DEFAULT,uiquery))
 			goto error;
 	if (!part) 
         	if (!get_partition (_("Partition"), disk, &part, uiquery))
 }
 
 int
-do_commit (PedDisk* disk, UICalls* uiquery)
+do_commit (PedDisk* disk, UIOpts opts, UICalls* uiquery)
 {
+	if (opts & UI_WARN_COMMIT)
+		if (!ask_boolean_question 
+			(_("WARNING: This writes all data to disk, continue?"),uiquery)) 
+				return 0;
 	if (ped_disk_commit(disk)) {
 		uiquery->need_commit = 0;
 		return 1;
 extern int do_rm (PedDisk*, PedPartition*, UICalls*);
 extern int do_set_system (PedDisk*, PedPartition*, const PedFileSystemType*, UICalls*);
 extern int do_set (PedDisk*, PedPartition*, PedPartitionFlag, UIOpts, UICalls*);
-extern int do_commit (PedDisk*, UICalls*);
+extern int do_commit (PedDisk*, UIOpts, UICalls*);
 extern int do_maximize (PedDisk*, PedPartition*, UICalls*);
 
 /* Additional functions */
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.