Commit Graph

182 Commits

Author SHA1 Message Date
Benno Schulenberg 3f43f5d05e sfdisk: show that the command --verify optionally takes device names
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2015-06-17 11:01:33 +02:00
Karel Zak a592b4b580 sfdisk: add --json
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-06-15 13:23:36 +02:00
Karel Zak 9d9a1b8760 libfdisk: (gpt) add extra check for First/Last LBA
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-04-23 12:32:36 +02:00
Karel Zak a53e37f9d4 sfdisk: don't use BLKRRPART to check loopdev usage
It seesm that kernel always returns EINVAL for BLKRRPART on loop
devices, we call the ioctl to check if nobody else uses the device.

Signed-off-by: Karel Zak <kzak@redhat.com>
2015-04-17 10:32:48 +02:00
Karel Zak 2928068a3c sfdisk: accept empty partitions from dump
Old sfdisk uses:
  dev/sdc2 : start=        0, size=        0, Id= 0

for undefined MBR partitions. Let's follow this behaviour.

Reported-by: Ruediger Meier <sweet_f_a@gmx.de>
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-04-16 17:51:18 +02:00
Karel Zak 6265639505 sfdisk: enable bootbits protection
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1210428
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-04-13 13:41:10 +02:00
Karel Zak d754d5540f sfdisk: improve -N warnings
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-04-13 12:08:50 +02:00
Karel Zak 3ba8e422a0 sfdisk: cleanup prompt usage
Let's use fgets-like callback only when compiled with readline,
otherwise (and also for non-tty) print prompt by printf().

Reported-by: Ruediger Meier <sweet_f_a@gmx.de>
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-03-27 15:04:58 +01:00
Karel Zak 703ab08256 sfdisk: fix -a vs. -A bug
The -A has been originally used for --activate, since v2.26 it's used
for --append. This is stupid mistake. This patch reverts the change to:

 -A, --activate
 -a, --append

Note that --append is a new command line option in v2.26.

Addresses: https://bugs.archlinux.org/task/44349
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-03-26 18:21:53 +01:00
Karel Zak 7159b496d5 sfdisk: add readline support
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-03-25 16:06:39 +01:00
Karel Zak da25898b7a sfdisk: add missing --color
The util already support lib/colors.c stuff, but without command line
option.

Signed-off-by: Karel Zak <kzak@redhat.com>
2015-02-25 12:37:04 +01:00
Sami Kerola cd2a6f1cfd rpmatch: use symbolic value when evaluation return codes
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-02-24 12:42:06 +01:00
Sami Kerola 6340e9137f sfdisk: include rpmatch.h
Some libc's do not have rpmatch(), and they need the workaround in the
header file.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-02-16 11:08:24 +01:00
Benno Schulenberg 57eae22317 textual: sort the options in the usage text of sfdisk alphabetically
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2015-02-10 12:23:15 +01:00
Karel Zak 54efd37875 sfdisk: fix --id fallthrough [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-01-28 14:50:38 +01:00
Karel Zak bf031d89ea libfdisk: support unknown partition types in sfdisk scripts
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1183234
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-01-28 09:57:03 +01:00
Karel Zak 9bbcf43f88 libfdisk: don't use off_t in public API
It's better to use exact and explicitly defined types (e.g. uint64_t)
rather than something like off_t to make code more portable.

[reported with gcc (Ubuntu 4.4.3-4ubuntu5.1) 4.4.3)]

The patch also fixes one debug message.

Reported-by: Benno Schulenberg <bensberg@justemail.net>
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-01-26 12:26:00 +01:00
Yuri Chornoivan 6e834d67ee textual: fix various minor typos 2015-01-26 11:38:38 +01:00
Benno Schulenberg 54fefa078e textual: fix spellos and inconsistencies in several program messages
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2015-01-26 11:17:55 +01:00
Karel Zak ce9f568c25 libfdisk: accept Start offset in {B,M,G..}iB in sfdisk scripts
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-01-20 14:20:47 +01:00
Karel Zak 8de07279bb sfdisk: fix --bytes
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-01-19 12:26:37 +01:00
Karel Zak 354f8cc8cf libfdiskL add API to print SIZE field in bytes
The patch also add --bytes to fdisk and fdisk.

Signed-off-by: Karel Zak <kzak@redhat.com>
2015-01-19 11:24:48 +01:00
Benno Schulenberg 451dbcfae1 textual: add a docstring to most of the utilities
This adds a concise description of a tool to its usage text.

A first form of this patch was proposed by Steven Honeyman
(see http://www.spinics.net/lists/util-linux-ng/msg09994.html).

Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2015-01-06 11:27:38 +01:00
Benno Schulenberg edac3e2c2e sfdisk: in the usage text show -v for --version instead of -V
In sfdisk -V is taken by --verify.  Use for the description of --version
the same indentation as for --help, not that of the other options.

Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2014-12-19 09:57:28 +01:00
Karel Zak a1ef792fda libfdisk: rename and move function
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-11-26 17:33:07 +01:00
Karel Zak 333c376138 libfdisk: (dos) allow to maximize partition
The struct fdisk_partition has special flag "end_follow_default" to
make the partition large as much as possible. This patch makes this
flag usable for fdisk_set_partition() function.

Command line example (enlarge the first partition):

	# echo ',+' | ./sfdisk -N1 /dev/sdb
	...
	Disk /dev/sdb: 100 MiB, 104857600 bytes, 204800 sectors
	...
	Old situation:
	Device     Boot Start   End Sectors Size Id Type
	/dev/sdb1        2048 22527   20480  10M 83 Linux
			      ^^^^^
	New situation:
	Device     Boot Start    End Sectors Size Id Type
	/dev/sdb1        2048 204799  202752  99M 83 Linux
			      ^^^^^^

Signed-off-by: Karel Zak <kzak@redhat.com>
2014-11-20 13:11:38 +01:00
Sami Kerola 5d36513976 sfdisk: return deterministic value from sfdisk_deinit()
disk-utils/sfdisk.c:222:9: warning: variable 'rc' is uninitialized when
used here [-Wuninitialized]
        return rc;
disk-utils/sfdisk.c:208:8: note: initialize the variable 'rc' to silence
this warning
        int rc;

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-10-31 10:38:55 +01:00
Karel Zak 819d9a2975 include/debug: fix typo
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-24 11:19:23 +02:00
Sami Kerola f0f2be20ed sfdisk: fix compiler warnings about uninitialized variables
warning: 'str' may be used uninitialized in this function [-Wmaybe-uninitialized]

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-10-20 14:07:21 +02:00
Karel Zak dfc6db2a35 libfdisk: cleanup parttype API
* add reference counting
 * add functions to set allocated types

Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-15 14:10:25 +02:00
Karel Zak ecf40cda76 libfdisk: make it possible to use zero for size and start
The zero may be valid size and start of the partition. This patch
introduces:

	fdisk_partition_has_start()
	fdisk_partition_has_size()
	fdisk_partition_unset_size()
	fdisk_partition_unset_start()

to make it possible to work with zero. The feature is internally
implemented by magic constant ((type) -1) for undefined sizes and
offsets.

Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-15 12:17:40 +02:00
Karel Zak 3692c28d06 tests: add PMBR sfdisk test
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-13 13:30:28 +02:00
Karel Zak 90dc69e40a sfdisk: leave on error
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-10 12:52:24 +02:00
Karel Zak 05af8bd4f0 sfdisk: ask on EOF
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-09 12:23:59 +02:00
Karel Zak 8be199ea2b sfdisk: cleanup isatty() usage
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-08 13:00:56 +02:00
Karel Zak e1422de3d8 sfdisk: add --label-nested for hybrid GPT
regular disk label:
	# sfdisk --list /dev/sdb
	..
	Disklabel type: gpt
	Disk identifier: 9DF9A9F1-0654-4E7A-9A5E-36E66D60FD79

	Device     Start    End Sectors Size Type
	/dev/sdb1   2048  22527   20480  10M Linux filesystem
	/dev/sdb2  22528  43007   20480  10M Linux swap
	/dev/sdb3  43008 204766  161759  79M Linux filesystem

nested (PMBR):
	# sfdisk --list --label-nested dos /dev/sdb
	...
	Disklabel type: dos
	Disk identifier: 0x00000000

	Device     Boot Start    End Sectors  Size Id Type
	/dev/sdb1           1 204799  204799  100M ee GPT

and for example:
        # sfdisk --label-nested dos /dev/sdb <<EOF
        1, 2047, ee
        , 10M, L
        , 10M, S
        ,,

creates hybrid GPT (PMBR partitions point to the same location as GPT)

Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-07 14:55:33 +02:00
Karel Zak a8a4887bcd libfdisk: fix sun and sgi to be usable from sfdisk
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-07 14:55:33 +02:00
Karel Zak 01f9286cb1 sfdisk: add --output <list> for print command(s)
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-07 14:55:32 +02:00
Karel Zak bc9e854709 sfdisk: add --part-attrs
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-07 14:55:32 +02:00
Karel Zak e36fb07af6 sfdisk: cleanup option names
Rename options to --part-{label,uuid,type} to be compatible with
another tools (like lsblk, parts, etc).

Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-07 14:55:32 +02:00
Karel Zak 351fad5069 sfdisk: add --name
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-07 14:55:32 +02:00
Karel Zak 3a5bdedf6a sfdisk: add --uuid command
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-07 14:55:32 +02:00
Karel Zak 347a7f7756 sfdisk: add --append
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-07 14:55:32 +02:00
Karel Zak e54b1c6fcb sfdisk: be sensitive to PT limits
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-07 14:55:32 +02:00
Karel Zak ab02d87e4f sfdisk: add --backup and --backup-file
The option --backup force sfdisk to store *all* fragments of the
partition table (including MBR partition tables store in the
extended partitions) to

	$HOME/sfdisk-<devname>-<offset>.bak

The options -O, -backup-file <path> allows to override the default
path, but sfdisk still appends <devname>-<offset>.bak to the <path>.
The backup files always contain only raw data from the device, so it's
possible to use dd(1) to restore original data on the device.

The original sfdisk also supported -O <file>, but semantic was little
bit different:

   - all was based on 512-byte sectors
   - all sectors was stored to the one file in format
	  <offset>|<sector>|<offset>|...

this original concept makes the backup files specific to sfdisk and with
dependence on sector size.

The new concept is the same we already use for wipefs(8) backup files.

Example (disk with GPT):

   # sfdisk /dev/sda --backup

   Welcome to sfdisk (util-linux 2.25.202-f4deb-dirty).
   Changes will remain in memory only, until you decide to write them.
   Be careful before using the write command.

   Backup files:
          PMBR (offset     0, size   512): /root/sfdisk-sda-0x00000000.bak
    GPT Header (offset   512, size   512): /root/sfdisk-sda-0x00000200.bak
   GPT Entries (offset  1024, size 16384): /root/sfdisk-sda-0x00000400.bak

Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-07 14:55:32 +02:00
Karel Zak db48b6a189 sfdisk: add --no-reread and --force
and also check if the device is in use.

Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-07 14:55:32 +02:00
Karel Zak f01f252857 sfdisk: add --no-act
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-07 14:55:32 +02:00
Karel Zak 35ce145f6a sfdisk: add deprecated --Linux
The sfdisk does not care about compatibility with classic DOS
partitioning, and it does not warn about incompatibility with DOS at
all. It means that --Linux is default and it's unnecessary to use
this option.

It's the same situation like with "--unit S", these options are very
probably often used in scripts, and these all is default now. So for
backward compatibility new sfdisk accepts these options on command
line, but prints "option is deprecated" warning message.

Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-07 14:55:32 +02:00
Karel Zak f0edb076ed sfdisk: add --quiet
Note that original sfdisk implementation suppressed warning
messages for --quiet.

Now we keep warning and error messages visible, but suppress
extra info messages only (for example to make it more usable in
scripts). IMHO suppress warnings is bad idea.

Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-07 14:55:32 +02:00
Karel Zak d420a7f9f6 sfdisk: add --unit and --show-geometry, update deprecated.txt
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-07 14:55:32 +02:00
Karel Zak 21ca986d71 sfdisk: cleanup sync() usage, fix --activate
* use sync() only if we change disk layout
 * don't use sync() when we change details (like partition type)

Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-07 14:55:32 +02:00
Karel Zak 2e73a998f4 sfdisk: use fdisk_set_partition_type()
This is more simple than the generic fdisk_set_partition() API.

Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-07 14:55:32 +02:00
Karel Zak 43a1ccecda sfdisk: cleanup usage() and long options
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-07 14:55:31 +02:00
Karel Zak 8eab3194ce sfdisk: add --parttype
The patch also makes --{id,change-id,print-id} deprecated in favour
of --parttype. The original --id is too generic option name and the
--print-id and --change-id are unnecessary and inconsistent with
another sfdisk options (e.g. we don't have --change-bootable)

Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-07 14:55:31 +02:00
Karel Zak d2c47697e1 sfdisk: add --verify
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-07 14:55:31 +02:00
Karel Zak 058dd97a1c sfdisk: add --list-types
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-07 14:55:31 +02:00
Karel Zak 2aa36b7372 sfdisk: add missing stuff to usage()
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-07 14:55:31 +02:00
Karel Zak 0ecf3ab504 libfdisk: (dos) implement fdisk_set_partition() backend
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-07 14:55:31 +02:00
Karel Zak b4df449f53 sfdisk: support -N for primary partitions
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-07 14:55:31 +02:00
Karel Zak e881349460 sfdisk: require confirmation before write to the device
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-07 14:55:31 +02:00
Karel Zak 3186f4a927 sfdisk: improve UI
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-07 14:55:31 +02:00
Karel Zak d5bee4bb59 libfdisk: cleanup script size= code
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-07 14:55:31 +02:00
Karel Zak c3bc748352 libfdisk: return partno when add new partition
* improve the way how sfdisk report results
 * the API change simplify applications

Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-07 14:55:31 +02:00
Karel Zak 7324f1bf8c sfdisk: implement command_fdisk()
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-07 14:55:31 +02:00
Karel Zak 254b1dfcc3 sfdisk: cleanup comments and command_activate()
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-07 14:55:31 +02:00
Karel Zak 54b13b0c5c sfdisk: add --activate
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-07 14:55:31 +02:00
Karel Zak 148f6e6d1c sfdisk: add comments, remove unnecessary function
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-07 14:55:31 +02:00
Karel Zak d2eb145785 sfdisk: add --show-size
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-07 14:55:31 +02:00
Karel Zak e3bb13d96c sfdisk: update usage()
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-07 14:55:30 +02:00
Karel Zak 8a8d204cd1 sfdisk: add --dump functionality
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-07 14:55:30 +02:00
Karel Zak 207de32a97 sfdisk: --list just one device
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-07 14:55:30 +02:00
Karel Zak 9c1f9dd3a0 sfdisk: implement --list
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-07 14:55:30 +02:00
Karel Zak 1881390de2 sfdisk: basic main() and friends
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-07 14:55:30 +02:00
Benno Schulenberg 1d23119072 textual: remove some inconsistent periods from error messages
While doing so, also improve translatability and some wordings.

Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2014-08-11 14:51:54 +02:00
Lauri Nurmi 58ac82ae2f sfdisk: use pluralized translation. 2014-07-28 11:45:30 +02:00
Karel Zak 83b69e409c sfdisk: use sysfs_devno_is_wholedisk()
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-06-17 12:16:05 +02:00
Petr Uzel ee6369973e sfdisk: suppress Linux-irrelevant warnings with -L
Sfdisk prints out a warning about extended partition not
starting at a cylinder boundary. Since this is irrelevant
for linux, the -L option should suppress this warning.

Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
2014-05-27 16:12:54 +02:00
Benno Schulenberg aa06617f6e textual: remove square brackets from around three dots
Also improve some option descriptions here and there.

Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2014-05-06 11:12:13 +02:00
Karel Zak 4ddd86d5d9 build-sys: ove fdisks to disk-utils
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-03-11 11:35:15 +01:00
Karel Zak 5c36a0eb7c Imported from util-linux-2.9i tarball. 2006-12-07 00:25:37 +01:00
Karel Zak 2b6fc908bc Imported from util-linux-2.8 tarball. 2006-12-07 00:25:35 +01:00
Karel Zak fd6b7a7ffc Imported from util-linux-2.7.1 tarball. 2006-12-07 00:25:34 +01:00