Commit Graph

109 Commits

Author SHA1 Message Date
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
Karel Zak f1151463ff po: merge changes
Signed-off-by: Karel Zak <kzak@redhat.com>
2010-06-30 14:46:19 +02:00
Karel Zak 278f63c0e6 fdisk: extend -c and -u options to support old DOS stuff
The DOS mode and cylinders as display units are disabled by default
now. For users who need old DOS behavior is it necessary to extend
-c (compatibility) and -u (units) command line options. The change is
backwardly compatible (so people who already uses -u and -c are not
affected with this change). New form:

 -c[=<mode>]   where <mode> is 'dos' or 'nondos' (default)
 -u[=<units>]  where <units> is 'cylinders' or 'sectors' (default)

For example old deprecated DOS behavior could be enabled by:

  fdisk -u=cylinders -c=dos /dev/sda

Signed-off-by: Karel Zak <kzak@redhat.com>
2010-06-16 10:52:20 +02:00
Karel Zak 0b1f769f28 fdisk: disable DOS mode and cylinders by default
Signed-off-by: Karel Zak <kzak@redhat.com>
2010-06-15 13:13:05 +02:00
Benno Schulenberg 40fe88d097 fdisk: remove erroneous <size> argument from -u option in help text
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2010-06-15 12:54:25 +02:00
Benno Schulenberg 4911d2bc4f fdisk: untangle the reporting of deprecated mode and unit
Translatable messages should not be split into parts that are
conditionally concatenated.  Preferably they should each form
a complete message.

Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
Signed-off-by: Karel Zak <kzak@redhat.com>
2010-06-15 12:53:48 +02:00
Karel Zak 6a2de3f131 fdisk: improve 'move begin of partition' command
The 'b' command ("move beginning of data in a partition")
implementation is too restricted. For example:

     Device Boot      Start         End      Blocks   Id  System
  /dev/sdb1            2048       22527       10240   83  Linux
  ....
  Partition number (1-4): 1
  New beginning of data (2048-22527, default 2048):
                         ^^^^^^^^^^

the range is defined by the current partition size. New version:

  Partition number (1-4): 1
  New beginning of data (1-22527, default 2048):
                         ^^^^^^^

allows to move the begin to arbitrary place if the place is not
allocated by any other partition. This is useful for people who don't
want to use the default partitioning (1MiB offset, 1MiB grain).

The 'b' command is expert command and does not force users to use an
aligned LBA (fdisk(8) still prints warning (in 'p' command) if any
partition is not aligned to the physical sector boundary).

Signed-off-by: Karel Zak <kzak@redhat.com>
2010-04-28 14:40:46 +02:00
Karel Zak 147e1e73c9 fdisk: improve add partition dialog
old version:
	Partition number (1-4):

new version:
	Partition number (1-4, default 1):

where the default value is the first non-used primary partition.

Signed-off-by: Karel Zak <kzak@redhat.com>
2010-04-28 10:10:39 +02:00
Karel Zak 7f152745c3 fdisk: fix -b <sectorsize>
The old fdisk (<2.17) does not differentiate between logical and
physical sector size, it uses the <sectorsize> for everything.

Now, we have logical and physical sectors size, but the -b option
changes the logical size only. The second bug is that "fdisk -b <sz>"
does not read topology information (it means that all I/O limits and
physical sector size are 512 (default).

The backwardly compatible bug fix is to override both sizes, logical
and physical if "-b" is used.

In future we can add a special option for physical size only.

Signed-off-by: Karel Zak <kzak@redhat.com>
2010-03-19 15:56:27 +01:00
Pádraig Brady b8d22034f1 fdisk: correctly truncate and align translated partition names
* fdisk/Makefile.am: Depend on the mbsalign module.
* fdisk/fdisk.c: Align using mbsalign rather than printf.

[kzak@redhat.com: - use size_t for width to fix gcc warning]

Reported-by: Makoto Kato <m_kato@ga2.so-net.ne.jp>
Signed-off-by: Pádraig Brady <P@draigBrady.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2010-03-16 15:29:01 +01:00
Karel Zak a47e839cd7 fdisk: don't use 1MiB grain on small devices
Signed-off-by: Karel Zak <kzak@redhat.com>
2010-02-15 16:46:05 +01:00
Karel Zak 9b15ea8048 fdisk: use 1MiB offset and grain always when possible
It would be nice to minimize dependence between the disk layout and
disk topology. We have to follow disk topology for alignment_offset
and huge (> 1MiB) I/O sizes only. For all others disks we can use 1MiB
grain and 1MiB offset.

Reported-by: "H. Peter Anvin" <hpa@zytor.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2010-02-15 16:08:02 +01:00
Karel Zak 78498b7b90 fdisk: add -c option (switch off DOS mode)
* add -c to allows to switch off DOS mode from command line

 * recommend sectors (command 'u' or option -u)

Signed-off-by: Karel Zak <kzak@redhat.com>
2010-02-15 14:43:49 +01:00
Karel Zak d42ef322d0 fdisk: fix ALIGN_UP
Signed-off-by: Karel Zak <kzak@redhat.com>
2010-02-15 14:43:49 +01:00
Karel Zak e57fb0dec0 fdisk: fallback for topology values
Signed-off-by: Karel Zak <kzak@redhat.com>
2010-02-15 14:43:33 +01:00
Karel Zak 3b19e88dab fdisk: cleanup help, add -h option
Signed-off-by: Karel Zak <kzak@redhat.com>
2010-02-15 10:08:03 +01:00
Karel Zak 99bdcd5fbd fdisk: use more elegant way to count and check alignment
Signed-off-by: Karel Zak <kzak@redhat.com>
2010-02-12 21:43:03 +01:00
Karel Zak a8a86a1c5e fdisk: cleanup warnings
* don't print:

	The number of cylinders for this disk is set to 12161.
	There is nothing wrong with that, but this is larger than 1024,
	and could in certain setups cause problems with:
	1) software that runs at boot time (e.g., old versions of LILO)
	2) booting and partitioning software from other OSs
	   (e.g., DOS FDISK, OS/2 FDISK)

  we really don't care about MS-DOS or extremely old LILO.

* inform users that DOS-compatible mode is bad and deprecated thing
  (It's difficult to use 2048 sectors grain or 4KiB sectors or
   alignment_offset in DOS mode where all is based on cylinders...)

* don't check for cylinders boundary in non-DOS mode

* inform about sector and I/O sizes

Signed-off-by: Karel Zak <kzak@redhat.com>
2010-02-09 11:18:53 +01:00
Karel Zak 7ded5afc57 fdisk: fix default first sector
The previous release 2.17 introduces aligned defaults for the first
and last sectors on the partition. Unfortunately, there is endless
loop when the code looks for first unused aligned sector.

Signed-off-by: Karel Zak <kzak@redhat.com>
2010-02-09 11:06:42 +01:00
Karel Zak 40c7aaf395 fdisk: cleanup alignment, default to 1MiB offset
* add heuristic to detect that the device does not provide
  topology information. We can use topology if:

	- alignment_offset is not 0
	- or optimal_io_size is not 0
	- or minimal_io_size is not power of 2

* default to 1MiB offset for the start of the first partition
  if topology is unknown. This (2048 512-byte sectors)
  is Windows Vista default.

* use optimal_io_size, minimal_io_size or 1MiB as a grain for
  partitions alignment

Note that this all is used when DOS-compatible mode is disabled.

Signed-off-by: Karel Zak <kzak@redhat.com>
2010-02-09 10:55:56 +01:00
Karel Zak 1d07e336ca fdisk: fix check_alignment()
The old version of check_alignment() does not work with extended
partitions.

Signed-off-by: Karel Zak <kzak@redhat.com>
2010-02-09 10:32:29 +01:00
Karel Zak 2b9e638a0f fdisk: don't check alignment_offset against geometry
The alignment_offset is compensation for DOS compatible partitioning.

It usually matches with disk geometry (e.g. 63 sectors), but the
offset is also exported from phy.disks to RAIDs there the geometry
don't match with the offset. So.. don't print unnecessary warning.

Signed-off-by: Karel Zak <kzak@redhat.com>
2010-02-09 10:27:34 +01:00
Karel Zak f80915d220 fdisk: use "optimal I/O size" in warnings
Signed-off-by: Karel Zak <kzak@redhat.com>
2010-01-28 23:34:05 +01:00
Karel Zak 69a6d78a0e fdisk: use optimal_io_size
* rename the minimum_io_size variable to io_size
 * use blkid_topology_get_optimal_io_size() for io_size initialization
 * use blkid_topology_get_minimum_io_size() as a fallback solution for
   io_size initialization

Signed-off-by: Karel Zak <kzak@redhat.com>
2010-01-28 19:42:04 +01:00
Karel Zak e90709421a fdisk: sleep-after-sync and fsync usage
It seems that sleep() after sync() is unnecessary legacy. It's very
probably unnecessary since kernel 1.3.20. For example the libparted
does not to use sleep() at all.

It seems that more important is fsync() usage in fdisks. For more
details see

  http://marc.theaimsgroup.com/?l=linux-kernel&m=105545785306867&w=3
  http://marc.theaimsgroup.com/?l=linux-kernel&m=105545848607353&w=3
  http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=276369

Currently we use fsync() in fdisk only. This patch also add fsync() to
sfdisk and cfdisk.

Addresses: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=276369
Addresses: http://bugzilla.redhat.com/show_bug.cgi?id=502639
Signed-off-by: Karel Zak <kzak@redhat.com>
2010-01-06 11:12:43 +01:00
Karel Zak 04c944419d po: fix msgid bugs
Reported-by: Petr Pisar <petr.pisar@atlas.cz>
Signed-off-by: Karel Zak <kzak@redhat.com>
2009-12-10 13:04:41 +01:00
Karel Zak 81dc64f8c0 fdisk: offer aligned first sector
Typical "new partition" dialog looks like:

     Partition number (1-4): 1
     First sector (4-818687, default 4):
                             ^^^^^^^^^

The range (e.g. 4-818687) depends on fdisk mode (DOS/non-DOS), but the
default value should be always aligned.

For example RAID5 device in the DOS mode:

   Disk /dev/md0: 419 MB, 419168256 bytes
   2 heads, 4 sectors/track, 102336 cylinders, total 818688 sectors
   Units = sectors of 1 * 512 = 512 bytes
   Sector size (logical/physical): 512 bytes / 65536 bytes
   Disk identifier: 0x081479c3

   ....

   Command (m for help): n
   Command action
      e   extended
      p   primary partition (1-4)
   p
   Partition number (1-4): 1
   First sector (4-818687, default 128):    <---- !!!
   Using default value 128
   Last sector, +sectors or +size{K,M,G} (128-818687, default 818687): +10M

   Command (m for help): p

   ....

       Device Boot      Start         End      Blocks   Id  System
   /dev/md0p1             128       20607       10240   83  Linux

For non-DOS mode the range will be:

   First sector (128-818687, default 128):

Signed-off-by: Karel Zak <kzak@redhat.com>
2009-11-18 11:25:10 +01:00
Karel Zak b7e76f8ef1 fdisk: align end of partition when defined by +size{K,M,G}
It's better to have disks without gaps between partitions, so it's
better to align ends of partitions.

Note, we don't care about end of partitions when the last sector has
been explicitly requested by user.

Signed-off-by: Karel Zak <kzak@redhat.com>
2009-11-18 11:25:10 +01:00
Karel Zak 8e23f2d20f fdisk: check for partition boundary
Disk /dev/md0: 419 MB, 419168256 bytes
2 heads, 4 sectors/track, 102336 cylinders, total 818688 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 65536 bytes
Disk identifier: 0x081479c3

    Device Boot      Start         End      Blocks   Id  System
/dev/md0p1             200      818687      409244   83  Linux
Partition 1 does not start on physical block boundary.

Signed-off-by: Karel Zak <kzak@redhat.com>
2009-11-18 11:25:10 +01:00
Karel Zak 8947b52ba0 fdisk: print info and recommendations about alignment
* inform user that phy.sector > log.sector
 * warn user when alignment_offset is not provided does, DOS-compatible
   mode is enabled and the default geo.sectors are not aligned
 * suggest to change display units to sectors (oh yes, fdisk
   default are cylinders...)

Signed-off-by: Karel Zak <kzak@redhat.com>
2009-11-18 11:25:10 +01:00
Karel Zak edd7b95838 fdisk: use minimal_io_size for the first partition
Signed-off-by: Karel Zak <kzak@redhat.com>
2009-11-18 11:25:09 +01:00
Karel Zak b39a46413f fdisk: add basic routines for LBA alignment
Signed-off-by: Karel Zak <kzak@redhat.com>
2009-11-18 11:25:09 +01:00