* 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>
fdisk allows to overwrite existing partition if the partition has
partition type set to zero (very unusual, but possible).
This is incorrect because such partition is pretty valid (and Linux
kernel does not care about the type at all). For example:
Device Boot Start End Blocks Id System
/dev/sdb1 2048 22527 10240 83 Linux
/dev/sdb2 22528 227327 102400 0 Empty
^^^^^ ^^^^^^^^
Command (m for help): n
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p):
Using default response p
Partition number (3,4, default 3):
First sector (22528-1228799, default 22528):
^^^^^^^
.. if user follows the default then the result are overlapping
partitions:
Device Boot Start End Blocks Id System
/dev/sdb1 2048 22527 10240 83 Linux
/dev/sdb2 22528 227327 102400 0 Empty
/dev/sdb3 22528 1228799 603136 83 Linux
^^^^^
... and if you call "mkfs /dev/sdb3" then you lost data on sdb2. Sad
thing.
Reported-by: Marc MERLIN <marc@merlins.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
The SGI drive currently counts only usable partitions, that's wrong as
Linux kernel counts all partition to generate partition number. For
example:
Kernel:
sdb 8:16 0 600M 0 disk
├─sdb9 8:25 0 2M 0 part
└─sdb11 8:27 0 596.2M 0 part
Fdisk:
Pt# Device Info Start End Sectors Id System
9: /dev/sdb1 0 4095 4096 0 SGI volhdr
11: /dev/sdb2 0 1220939 1220940 6 SGI volume
Reported-by: Phillip Susi <psusi@ubuntu.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
Notes:
* fdisk don't sync hybrid MBR with GPT
* hybrid MBR is ignored and not overwritten by PBMR
* users is informed about expert command 'M' to toggle between MBR
and GPT mode. It's possible to manually modify hybrid MBR.
Signed-off-by: Karel Zak <kzak@redhat.com>
We already have all code to support this feature, unfortunately
it was not used in gpt_probe_label()...
References: https://bugzilla.redhat.com/show_bug.cgi?id=1022217
Signed-off-by: Karel Zak <kzak@redhat.com>
* GPT attributes defined by standard (e.g. legacy boot etc.)
* attributes (bits 48-63) reserved for GUID specific attributes (used for example
by MS Windows)
Signed-off-by: Karel Zak <kzak@redhat.com>
Unfortunately, fdisk_warn/info/.. function was not marked by
printf __attribute__.
We don't want to break gettext stuff now, so all compiler warnings
have been fixed by casts. This is temporary solution, after release it
will be necessary to fix all the strings.
Signed-off-by: Karel Zak <kzak@redhat.com>
.. to make 'D'ump expert command usable also for MBR.
Yes, we have -rc2 now and this is a new feature, but it's tiny change
without any interaction to the rest of the code and without gettext stuff.
Signed-off-by: Karel Zak <kzak@redhat.com>
Using consistent capitals and lowercase, adding missing periods and
a missing space, repositioning commas for clarity, improving grammar,
and aligning substrings for esthetics.
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>