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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>