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>
Was:
Mentioned function returns -1 if adding of primary partition is
impossible. Caller treats this value as size_t (res variable) and then
compares it for negative values, totally ignoring errors.
Becomes:
Now function takes address to variable and fills it with partition
number. Caller treats return value as int and use it appropriately.
[kzak@redhat.com: - don't mix return code and partno at all]
Signed-off-by: Boris Egorov <egorov@linux.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
The GPT first usable LBA is usually aligned to grain (1MiB), but for small
(<=4MiB) devices we strictly follow sector sizes.
In this case there is a small space in front of the aligned begin of
the first partition. This useless space should not be offered for the
next partitions.
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 32768 bytes
Disklabel type: gpt
Disk identifier: 041E2D54-AD0C-4C7E-A50D-363D23058D47
Device Start End Size Type
/dev/sdb1 40 2087 1M Linux filesystem
Command (m for help): n
Partition number (2-128, default 2):
First sector (34-8158, default 2088):
^^
first usable LBA is 34, but first aligned (recommended) LBA is 40, we
use it for the first partition. All this is correct, but the space
before the first partition should be ignored. Fixed version:
Command (m for help): n
Partition number (2-128, default 2):
First sector (2088-8158, default 2088):
^^^^
Note this problem does not exist for "normal" (large) devices where
first usable LBA is aligned to grain.
Reported-by: Boaz Harrosh <boaz@plexistor.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
* use check_ prefix for checking functions
* use plural in function names where we work with more partitions than one
* always use "ents" when when we work with gpt entries array
Signed-off-by: Karel Zak <kzak@redhat.com>
The current offset of cxt->dev_fd may not be still 0, notably when
blkdev_get_size has to resort to using blkdev_find_size
Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org
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>
* this patch add to dos driver support for fdisk_partition->size_explicit
to avoid unexpected last sector alignment for sizes explicitly specified
in sectors
* add support for small "first LBA", the current default is to use
1MiB offset for the first partition and for each EBR. This is not
backwardly compatible and it makes impossible to apply sfdisk
scripts/dumps from old systems, because original offset can be
smaller than 2048 sectors (old sfdisk default is 1 sector).
The solution is on the fly to detect this situation and change
fdisk_context->first_lba to 1 sector. Nasty.
Signed-off-by: Karel Zak <kzak@redhat.com>
* check if there is space for primary partitions, if no and extended
exists then create logical partitions
* create extended if @pa->type is extended partition
Signed-off-by: Karel Zak <kzak@redhat.com>
The zero index is absolutely valid for extended partition (it means
extended partition could be the first partition on the device).
Reported-by: Christoph Hoopmann <christophhoopmann@gmail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
If you delete logical partition and then create a new one than fdisk
(and cfdisk) might write EBR to the first sector on the device. That's
wrong of course; because you will lost MBR (primary partitions).
(Probably introduced by commit bcddbe9688
where code completely clears EBR stuff.)
Reported-by: Michał Górny <mgorny@gentoo.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
The fdisk_dump_* prefix will be used for sfdisk-like functionality.
The patch also add FDISK_ prefix to fdisk_get_unit() options.
Signed-off-by: Karel Zak <kzak@redhat.com>
For example
$ LIBMOUNT_DEBUG=tab,cache findmnt
to debug only TAB and CACHE subsystem.
Signed-off-by: Ondrej Oprala <ooprala@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
This patch restores the original fdisk behavior and always prints
information about misaligned partitions in 'p'print output.
Signed-off-by: Karel Zak <kzak@redhat.com>
Storage Spaces is Microsoft's logical volume management.
It has been around since Windows 8.
Cc: Karel Zak <kzak@redhat.com>
Signed-off-by: Sergei Antonov <saproj@gmail.com>
Fixing plain typos, miswordings, inconsistent periods, some missing
angular brackets, and a proper pluralization (even when it involves
a constant, because for some languages the precise value matters).
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
... this allows to avoid unnecessary sync() from cfdisk.
Reported-by: Benno Schulenberg <bensberg@justemail.net>
Signed-off-by: Karel Zak <kzak@redhat.com>
* 'minor-fixes' of git://github.com/kerolasa/lelux-utiliteetit:
lscpu: avoid double free
libsmartcols: avoid variable dereference after release
libfdisk: do not do the same thing twice in single if statement
whereis: avoid printing uninitialized string
setpriv: avoid alloca() use xmalloc() instead
dmesg: avoid unnecessary variable assignment
fdisk: avoid code duplication
mkfs.cramfs: use defined failure name rather than magic value
fdformat: match variable and print format types
cfdisk: add braces to ensure operation order
lscpu: avoid use of bzero() in favor of memset()
setterm: remove unnecessary variable
cal: remove unnused structure and definition
textual: fix some typos
$ ~/util-linux/fdisk -b 4096 xxx
..
Segmentation fault
The buffer has to be reinitialized always when we apply a new
device properties (e.g. sector size).
Reported-by: Bernhard Voelker <mail@bernhard-voelker.de>
Signed-off-by: Karel Zak <kzak@redhat.com>
The second argument was very likely meant to be 'be->offset'.
Maintainers review & sign-off will further verify this change being
correct.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
The check() function counts number of used sectors, but it counts only
partitions. This is mistake, the area before the first partition is
also "used" place (boot loaders or we have to align the first partition
to disk I/O limits, etc).
Signed-off-by: Karel Zak <kzak@redhat.com>
Many people report a problem with the message if (cylinders <= 1024 &&
start != total) fprintf(stderr, _("Partition %d: previous sectors %d
disagrees with " "total %d\n"), n, start, total);
This message comes from the fact that the previous code caluclates the
total number of sectors in the wrong way.
The formula should be total = (real_c * heads + h) * sectors + real_s;
As a Cylinder consists of some heads * sectors A Head consists of some
sectors and finally sectors are the smallest unit
Signed-off-by: Karel Zak <kzak@redhat.com>
The function is no critical for fdisk functionality. The SUN label
verification will check for less issues. All the verification code is
optional ('v' fdisk command).
Signed-off-by: Karel Zak <kzak@redhat.com>
* rename flags functions to scols_table_enable_*
* rename *_no_foo() functions to _nofoo()
* output formats are mutually exclusive, so don't use flags there
* don't assume symbols in scols_new_table(), use scols_table_set_symbols()
Signed-off-by: Karel Zak <kzak@redhat.com>
Don't use fallback to read-only mode in fdisk_context_assign_device(),
it's application responsibility open the device in the right mode.
The commands fdisk and cfdisk check (and report) read-only mode now.
Reported-by: Maciej Małecki <me@mmalecki.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
* 'common_debug' of https://github.com/ooprala/util-linux:
clean up redundant macros and defines
libfdisk: use include/debug.h
libblkid: use include/debug.h
libmount: further debug.h integration
libcommon: don't mention lib versions in debug macros
libcommon: define more debugging macros
libmount: use macros from include/debug.h
libcommon: add common debugging routines
* care about endianess
* don't use by compiler packed struct with bit array for GPT
attributes, it's more robust use it as bitmap stored in uint64_t.
Signed-off-by: Karel Zak <kzak@redhat.com>
- deallocate sector buffer and deincrement part_max when delete last
logical partition
- zap obsolete EBR on begin of the extended partition when no logical
partition defined
Signed-off-by: Karel Zak <kzak@redhat.com>
* use separate function to get free space
* allow to use label-specific get_freespace() function
(this is necessary for MBR extended partitions mess)
Signed-off-by: Karel Zak <kzak@redhat.com>
The include/tt.h has to be used only internally by the library (for
example to convert fdisk_table to string).
The fdisk_ask API should not be more used for complex tasks like print
partition table. The application has to use fdisk_get_table() and
fdisk_table_to_string() or something else.
Signed-off-by: Karel Zak <kzak@redhat.com>
* add generic fdisk_iter iterator
* use fdisk_table to convert partition table to human readable output
* clean up partition.c API (don't use reference to fdisk_context in
fdisk_partition struct)
* extern table.c API to use fdisk_iter iterator
* remove old fdisk_list_partitions()
Signed-off-by: Karel Zak <kzak@redhat.com>
Let's use more generic:
fdisk_get_partition()
fdisk_partition_get_parttype()
rather than fdisk_get_partition_type().
The patch also improves fdisk_get_partition() semantic to allocate
a new partition struct if the argument is NULL.
Signed-off-by: Karel Zak <kzak@redhat.com>
This change adds a struct fdisk_column to provide generic description
for information about partitions. The struct is used for tt tables as
well as lists of possible columns for specified label driver.
We use the same concept in all applications linked with tt.c (lsblk,
findmnt, partx, ...) where is possible to dynamically change columns,
order of the columns etc. Now it will be possible to do the same with
fdisk.
And it's also possible to use FDISK_COL_* Ids to address data, for
example:
fdisk_partition_get_data(cxt, FDISK_COL_SIZE, 1, &data);
returns a string with human readable size (<num>{MGT}) of the second
partition.
Signed-off-by: Karel Zak <kzak@redhat.com>
The _DEPENDENCIES has to be used for dependencies on another in-tree
files, but _LIBADD is to specify additional libs (including external
libs).
Reported-by: oleid <notifications@github.com>
Signed-off-by: Karel Zak <kzak@redhat.com>