Commit Graph

140 Commits

Author SHA1 Message Date
Karel Zak 099c7a94ce fdisk: add missing break
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-01-31 21:06:42 +01:00
Karel Zak baec3e4913 fdisk: fix poor coding style
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-01-17 16:26:08 +01:00
Francesco Cosoleto 0c38188028 fdisk: fix last sector dialog bug after an incorrect input with suffix
If user input in a last sector dialog was out of range and with suffix, and if
this was followed by accepting the default value, then the used last sector was
erroneously default - 1.

Reported-by: Gerardo Exequiel Pozzi <vmlinuz386@yahoo.com.ar>
Signed-off-by: Francesco Cosoleto <cosoleto@gmail.com>
2012-01-16 21:53:00 +01:00
Francesco Cosoleto 2c911261ff fdisk: rename read_int_sx() and some related variables
Signed-off-by: Francesco Cosoleto <cosoleto@gmail.com>
2012-01-16 21:52:47 +01:00
Francesco Cosoleto 0c48d37192 fdisk: fix incorrect position of is_ide_cdrom_or_tape() call
Reported-by: Guillem Jover <guillem@hadrons.org>
Signed-off-by: Francesco Cosoleto <cosoleto@gmail.com>
2012-01-04 11:35:26 +01:00
Davidlohr Bueso 3b622ddd72 fdisk: use CDROM_GET_CAPABILITY ioctl
And replace the current archaic logic of is_ide_cdrom_or_tape().

Signed-off-by: Davidlohr Bueso <dave@gnu.org>
2012-01-02 13:43:06 +01:00
Francesco Cosoleto dae4880508 fdisk: improve some messages
Signed-off-by: Francesco Cosoleto <cosoleto@gmail.com>
2011-12-16 14:04:10 +01:00
Francesco Cosoleto 8db8295d82 fdisk: Fix bad invalid flag 0x00000 warning message
This splits check_dos_label() and dos_init() off from get_boot() and gets
rid of the invalid flag 0x00000 warning message due to a check for MBR
signs in zeroized buffer:

	memset(MBRbuffer, 0, 512);

	if (what == create_empty_dos)
		goto got_dos_table;
[...]
got_dos_table:
	if (!valid_part_table_flag(MBRbuffer)) {
[...]
	if (!valid_part_table_flag(pe->sectorbuffer))
		fprintf(stderr, _("Warning: invalid flag 0x%04x of partition "
[...]

Signed-off-by: Francesco Cosoleto <cosoleto@gmail.com>
2011-12-16 14:04:09 +01:00
Francesco Cosoleto 4a96a62a09 fdisk: avoid an intermediate variable in command_prompt()
Signed-off-by: Francesco Cosoleto <cosoleto@gmail.com>
2011-12-16 14:04:07 +01:00
Francesco Cosoleto b152082db3 fdisk: don't use get_existing_partition() if disk label isn't dos
Signed-off-by: Francesco Cosoleto <cosoleto@gmail.com>
2011-12-16 14:04:06 +01:00
Francesco Cosoleto 058fdbba0f fdisk: remove unused guess_device_type() function
Signed-off-by: Francesco Cosoleto <cosoleto@gmail.com>
2011-12-16 14:04:05 +01:00
Francesco Cosoleto ad30333e1d fdisk: get rid of get_boot(create_empty_sun) call
create_sunlabel() should create a new empty SUN disklabel without checking data
itself writes to memory and initialize internal related fdisk variables.

Signed-off-by: Francesco Cosoleto <cosoleto@gmail.com>
2011-12-16 14:04:04 +01:00
Francesco Cosoleto 97a2f1b8ba fdisk: get rid of type_open global variable
Signed-off-by: Francesco Cosoleto <cosoleto@gmail.com>
2011-12-16 14:04:03 +01:00
Francesco Cosoleto ea4824f1ad fdisk: rename try() and tryprocpt() functions
Signed-off-by: Francesco Cosoleto <cosoleto@gmail.com>
2011-12-16 14:04:02 +01:00
Francesco Cosoleto e27b42d56f fdisk: drop one parameter from try() function
Signed-off-by: Francesco Cosoleto <cosoleto@gmail.com>
2011-12-16 14:04:01 +01:00
Francesco Cosoleto 883c5f7158 fdisk: move code for renaming SGI bootfile to SGI module
This moves the code for renaming SGI bootfile from command_prompt() to
sgi_set_bootfilename() function.

Signed-off-by: Francesco Cosoleto <cosoleto@gmail.com>
2011-12-16 14:04:00 +01:00
Francesco Cosoleto bd83de2d66 fdisk: remove possibly_osf_label variable that is only assigned
Signed-off-by: Francesco Cosoleto <cosoleto@gmail.com>
2011-12-16 14:03:59 +01:00
Francesco Cosoleto 1025b5ab08 fdisk: remove unused 'require' member in enum action
Signed-off-by: Francesco Cosoleto <cosoleto@gmail.com>
2011-12-16 14:03:58 +01:00
Francesco Cosoleto 47104bae89 fdisk: split delete_partition() off from dos_delete_partition()
This accidentally fixes a mistake printing the "Partition n is deleted"
message as the 'i' variable get decremented or incremented in case of
logical partitions.

Signed-off-by: Francesco Cosoleto <cosoleto@gmail.com>
2011-11-14 15:07:28 +01:00
Francesco Cosoleto a8c6fddb2e fdisk: use ngettext() in str_units() for plural forms
Signed-off-by: Francesco Cosoleto <cosoleto@gmail.com>
2011-11-14 15:07:13 +01:00
Francesco Cosoleto 7c54823c82 fdisk: enable expert menu with SGI label
This allows the creation of a new label if the disk already has an existing
SGI disklabel without working around this problem such as creating a DOS
disklabel or overwriting with zero the partition table (problem reported in
'Gentoo Linux/MIPS Handbook').

Signed-off-by: Francesco Cosoleto <cosoleto@gmail.com>
2011-11-14 14:27:18 +01:00
Francesco Cosoleto c482303ef7 fdisk: rewrite print menu system
DOS and SGI label menus are unchanged. BSD label command
descriptions change slightly to use a common form.

This also removes an useless menu entry in SUN label menu to
edit bsd disklabel.

Signed-off-by: Francesco Cosoleto <cosoleto@gmail.com>
2011-11-14 14:27:18 +01:00
Francesco Cosoleto 56c07b9609 fdisk: move command prompt code to a separate function
Signed-off-by: Francesco Cosoleto <cosoleto@gmail.com>
2011-11-14 14:27:18 +01:00
Francesco Cosoleto e97a991aff fdisk: rename bselect, xselect functions
Signed-off-by: Francesco Cosoleto <cosoleto@gmail.com>
2011-11-14 14:23:32 +01:00
Petr Uzel 960cf5737e misc: use %m in format string instead of %s and strerror(errno)
Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
2011-09-27 15:46:07 +02:00
Francesco Cosoleto 9777759ad6 fdisk: print welcome message
This adds a welcome message with util-linux version number, information
about fdisk behaviour that doesn't write to disk after a command (unlike
gparted) and a warning about possible data loss.

The message appears just before the first command prompt.

Signed-off-by: Francesco Cosoleto <cosoleto@gmail.com>
2011-08-30 10:54:37 +02:00
Francesco Cosoleto a75ba1319e fdisk: print partition deleted message
Signed-off-by: Francesco Cosoleto <cosoleto@gmail.com>
2011-08-30 10:53:39 +02:00
Francesco Cosoleto 20aa2570e8 fdisk: print a message with size and type of created partition
Signed-off-by: Francesco Cosoleto <cosoleto@gmail.com>
2011-08-30 10:53:22 +02:00
Karel Zak e99da659a9 fdisk: fix compiler warnings [-Wunused-parameter -Wsign-compare]
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-08-01 15:27:35 +02:00
Francesco Cosoleto 365acc9765 fdisk: use a single variable for the current disklabel
Using a variable for each supported partition table type doesn't seem necessary.

This fixes also a minor bug in switching from SGI label to SUN label: the expert
menu isn't available as sgi_label variable remains set to true.

Code a bit more clear as *_label names have similarity with names such as
"sgilabel", "struct sun_label".

Signed-off-by: Francesco Cosoleto <cosoleto@gmail.com>
2011-07-11 12:01:42 +02:00
Francesco Cosoleto 7439604895 fdisk: accept digits-space-suffix format
This is for users who are used to separate with a space numbers from units.

Signed-off-by: Francesco Cosoleto <cosoleto@gmail.com>
2011-05-10 14:33:33 +02:00
Francesco Cosoleto 11187bfadd fdisk: print logical partition number while adding it
[kzak@redhat.com: - merged two Francesco's patches]

Signed-off-by: Karel Zak <kzak@redhat.com>
Signed-off-by: Francesco Cosoleto <cosoleto@gmail.com>
2011-05-10 14:13:14 +02:00
Francesco Cosoleto b25c9df7c7 fdisk: quit from partition type dialog after invalid response
This gets rid of the while() loop and fixes indentation.

Signed-off-by: Francesco Cosoleto <cosoleto@gmail.com>
2011-05-10 13:50:16 +02:00
Francesco Cosoleto 37b4484fe6 fdisk: add a default response for the partition type dialog
The default response is 'p' until three primary partitions are created,
then 'e'.

The original idea is from Karel Zak.

Signed-off-by: Francesco Cosoleto <cosoleto@gmail.com>
2011-05-10 13:50:11 +02:00
Francesco Cosoleto ffde29b2bd fdisk: change primary or extended partition type dialog
Mainly this appends a colon for the prompt, reverses order of the list,
reports the number of primary partitions used and unused.

Old version:
 Command action
    e   extended
    p   primary partition (1-4)
 p

New version:
 Partition type:
    p   primary (0 primary, 0 extended, 4 free)
    e   extended
 Select: p

Old version:
 Command action
    l   logical (5 or over)
    p   primary partition (1-4)
 l

New version:
 Partition type:
    p   primary (0 primary, 1 extended, 3 free)
    l   logical (numbered from 5)
 Select: l

Signed-off-by: Francesco Cosoleto <cosoleto@gmail.com>
2011-05-10 13:50:06 +02:00
Francesco Cosoleto 63c3e98f21 fdisk: improve error message for missing extended partition
Signed-off-by: Francesco Cosoleto <cosoleto@gmail.com>
2011-05-03 12:59:03 +02:00
Francesco Cosoleto f01c41e5ff fdisk: fix "invalid partition number for type" error message
You can't input a partition number here.

Signed-off-by: Francesco Cosoleto <cosoleto@gmail.com>
2011-05-03 12:59:01 +02:00
Karel Zak 64d15476c0 build-sys: don't use HAVE_LIBBLKID_INTERNAL macro
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-03-16 17:45:53 +01:00
Francesco Cosoleto c845f12cac fdisk: more meaningful error messages (use err.h)
[kzak@redhat.com: - minor changes in error messages]

Signed-off-by: Francesco Cosoleto <cosoleto@gmail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-01-23 23:33:45 +01:00
Francesco Cosoleto 52b38677e2 fdisk: use xalloc lib
Signed-off-by: Francesco Cosoleto <cosoleto@gmail.com>
2011-01-23 23:05:08 +01:00
Francesco Cosoleto 7c1db6b47a fdisk: replace fatal(usage) with a separate usage() function
Signed-off-by: Francesco Cosoleto <cosoleto@gmail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-01-23 23:04:06 +01:00
Karel Zak 8feb31e532 fdisk: re-print prompt after maybe_exit()
after
	Do you really want to quit? n

the read_chars() has to re-print the original prompt and ask again
for new input. For example:

Partition number (1-4, default 3):               <-- CTRL-D
Do you really want to quit? n
Partition number (1-4, default 3): 3             <-- ask again
First sector (411648-1023999, default 411648):

Signed-off-by: Karel Zak <kzak@redhat.com>
2011-01-05 16:50:47 +01:00
Francesco Cosoleto e66ac5d344 include: add fallback for rpmatch()
Simple replacement code with hardcoded y/n responses to allow
compilation on systems without rpmatch() such as Cygwin.

Signed-off-by: Francesco Cosoleto <cosoleto@gmail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-01-05 16:18:08 +01:00
Francesco Cosoleto aead9d139d fdisk: quit with a single CTRL-D, confirm if necessary
Signed-off-by: Francesco Cosoleto <cosoleto@gmail.com>
2011-01-05 16:12:02 +01:00
Karel Zak 6bec87105c fdisk: use canonicalized names for -l (and sfdisk -d)
.. no more /dev/dm-X in "fdisk -l" and "sfdisk -d" output, always use
/dev/mapper/<name>.

Signed-off-by: Karel Zak <kzak@redhat.com>
2010-12-17 01:28:59 +01:00
Markus Rinne 263644840f fdisk: eliminate redundant call to open()
Don't use open() in get_boot() if it's called with an argument try_only,
because the file has already been opened by the caller.

Signed-off-by: Markus Rinne <markus.ka.rinne@gmail.com>
2010-09-30 22:52:42 +02:00
Karel Zak 7d22c8e27c fdisk: fix alignment check for non-512-byte logical sectors
# modprobe scsi_debug dev_size_mb=1024 sector_size=4096

 # fdisk /dev/sdb

  Command (m for help): n
  Command action
    e   extended
    p   primary partition (1-4)
  p
  Partition number (1-4, default 1):
  Using default value 1
  First sector (256-262143, default 256): 257
  Last sector, +sectors or +size{K,M,G} (257-262143, default 262143): +100M

  Command (m for help): p

  Disk /dev/sdb: 1073 MB, 1073741824 bytes
  32 heads, 32 sectors/track, 256 cylinders, total 262144 sectors
  Units = sectors of 1 * 4096 = 4096 bytes
  Sector size (logical/physical): 4096 bytes / 4096 bytes
  I/O size (minimum/optimal): 4096 bytes / 262144 bytes
  Disk identifier: 0x16db2bb0

    Device Boot      Start         End      Blocks   Id  System
  /dev/sdb1            257       25855      102396   83  Linux
  Partition 1 does not start on physical sector boundary.
  ^^^^^^^^

 The warning is nonsense. The logical and physical sector size is the
 same. It means that every LBA is always aligned to physical sector
 boundary.

 Note that this bug does not mean that fdisk produces unaligned
 partitions. The problem is that fdisk forces to use bigger gaps
 between aligned LBAs, for example:

   correctly aligned LBA are: 256, 257, 258, ...  [N+1]
   fdisk assumes:             256, 264, 272, ...  [N+(sector_size/512)]

Reported-by: JOB NELSON <job_nelson@hotmail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2010-08-23 13:38:41 +02:00
Karel Zak 06023c2e97 fdisk: don't keep internally device size in 512-byte sectors
All fdisk code uses sector_size variable, so there should not be an
exception where we use 512-byte sectors.

Signed-off-by: Karel Zak <kzak@redhat.com>
2010-08-23 12:22:39 +02:00
Karel Zak f9936f4dc0 fdisk: update MBR after ID change
Reported-by: Bernard Pidoux <bpidoux@free.fr>
Signed-off-by: Karel Zak <kzak@redhat.com>
2010-08-09 13:08:33 +02:00
François Revol d063af0604 fdisk: fix use of non portable type
Signed-off-by: François Revol <revol@free.fr>
Signed-off-by: Karel Zak <kzak@redhat.com>
2010-07-26 11:37:19 +02:00