summaryrefslogtreecommitdiffstats
path: root/libfdisk/src/table.c
Commit message (Collapse)AuthorAgeFilesLines
* libfdisk: fix fdisk_script_get_table()Karel Zak2019-06-171-1/+1
| | | | | | Make sure we never return NULL and we reuse the table in code. Signed-off-by: Karel Zak <kzak@redhat.com>
* various: fix 'uninitialized when used' warnings [clang]Sami Kerola2019-02-181-1/+1
| | | | | | | This change fixes "warning: variable 'var' may be uninitialized when used here [-Wconditional-uninitialized]" warnings reported in various files. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* libfdisk: sanity check, to prevent overlapping partitions from being partly ↵Fabian.Kirsch@dlr.de2019-02-181-2/+7
| | | | | | | | | | | | | | | | reported as free i noticed wrongly reported free space when looking with cfdisk on an USB drive prepared with the latest alpine *.iso[1]. Feel free to apply below patch, which fixed the issue for me. Greetings Fabian [1]: http://dl-cdn.alpinelinux.org/alpine/v3.9/releases/x86/alpine-extended-3.9.0-x86.iso Signed-off-by: Karel Zak <kzak@redhat.com>
* libfdisk: use list_add_tail() in more robust wayKarel Zak2019-02-181-0/+3
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libfdisk: allow to start freespace for zeroKarel Zak2018-01-111-1/+1
| | | | | | | This is necessary for disk labels like SUN where whole disk is possible to address by partitions. Signed-off-by: Karel Zak <kzak@redhat.com>
* libfdisk: improve table print debugsKarel Zak2017-07-191-5/+12
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libfdisk: use BLKPG ioctls to inform kernel about changesKarel Zak2017-07-141-0/+69
| | | | | | | | | | | | | This patch introduces fdisk_reread_changes(). The function is less invasive alternative to fdisk_reread_partition_table(). The new function uses BLKPG ioctls for modified partitions. The another partitions are not affected. This solution allows to successfully use fdisks on disk where some partitions are still use (mounted). For example if you want to resize the last partition on the device. Signed-off-by: Karel Zak <kzak@redhat.com>
* libfdisk: Distinguish between first LBA sector and partitionTobias Stoeckmann2016-08-291-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | An insufficient check leads to an invalid free space output, as seen here: $ dd if=/dev/zero of=cfdisk.iso bs=1M count=1 $ losetup -f cfdisk.iso $ echo w | fdisk /dev/loop0 $ echo '1,1' | sfdisk /dev/loop0 --append $ echo '3,' | sfdisk /dev/loop0 --append $ sfdisk --list-free /dev/loop0 Start End Sectors Size 1 2 2 1K $ _ In this case, libfdisk fails to notice that it tries to calculate space between two partitions, not between start of disk and first partition. Currently, the code tries to achieve that by checking the address of the last "partition", which is the first_lba block. Now if the first partition is merely 1 block in size, the "last" address is still equal to the first_lba block, which renders the check in libfdisk for the next partition invalid. I chose to use "nparts == 0" for this check, because the partitions are properly sorted before iterating over them. Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
* libfdisk: Fix assert error in free space handlingTobias Stoeckmann2016-08-291-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | An off-by-one issue exists in fdisk_get_freespaces. It can trigger an assert, as seen here: $ dd if=/dev/zero of=cfdisk.iso bs=1M count=1 $ losetup -f cfdisk.iso $ echo w | fdisk /dev/loop0 $ echo '1,2' | sfdisk /dev/loop0 --append $ echo '3,' | sfdisk /dev/loop0 --append $ sfdisk --list-free /dev/loop0 Aborted $ _ Problem here is an invalid "grain" processing. A grain is considered expected free space between partitions which can be required for proper alignment. Normally, it's 1 MB but in this case our iso is merely 1 MB so the grain is reduced to 1 byte. The if-condition in question checks for "last + grain <= pa->start" and therefore even triggers if there is no space between them (due to equal check). Eventually, the start block address is higher than the end block address which triggers the assert(). Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
* misc: Fix various typosSebastian Rasmussen2016-05-311-4/+4
| | | | | | | Fix various typos in error messages, warnings, debug strings, comments and names of static functions. Signed-off-by: Sebastian Rasmussen <sebras@gmail.com>
* libfdisk: don't offer zero length freespaceKarel Zak2016-04-251-5/+16
| | | | | Reported-by: Kay Sievers <kay@vrfy.org> Signed-off-by: Karel Zak <kzak@redhat.com>
* misc: again fixing many printf format stringsRuediger Meier2016-03-071-4/+8
| | | | | | | | | | | | | | | | | | | This is again a huge patch regarding printf format strings to fix compiler warnings seen on clang/OSX. I'm trying to follow these rules strictly: #type #format #cast uintmax_t %ju - intmax_t %jd - uint64_t PRIu64 - int64_t PRId64 - size_t %zu - ssize_t %zd - ino_t %ju (uintmax_t) off_t %jd (intmax_t) Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* libfdisk: fix partition move/resize codeKarel Zak2015-09-171-1/+6
| | | | | | | | | - verify that the new partition fits to the area if the size of the has not been modified - fix remaining space calculation (yes, brown-paper-bag bug..) - offer also space before first partition as free space Signed-off-by: Karel Zak <kzak@redhat.com>
* Fix trivial typosYuri Chornoivan2015-08-251-1/+1
|
* libfdisk: cleanup assert() usageKarel Zak2015-08-041-10/+0Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libfdisk: add fdisk_table_get_partition_by_partno()Karel Zak2015-04-221-0/+34
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libfdisk: ignore whole-disk partition when check orderKarel Zak2015-02-101-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libfdisk: fix issues with very small partitionsKarel Zak2015-02-031-3/+5
| | | | | | | | | | | | - cfdisk: minimal partitions size is 1 sector - dos: when align last sector then don't set partition size to zero for very small partitions. - don't ignore tiny partitions before free space when define free-space start offset - improve some debug messages Reported-by: Benno Schulenberg <bensberg@justemail.net> Signed-off-by: Karel Zak <kzak@redhat.com>
* libfdisk: cleanup gtk-docs warningsKarel Zak2015-01-131-2/+3
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* maint: fix shadow declarationSami Kerola2015-01-071-3/+3
| | | | | | | | | | | | | | | | This change fixes all shadow declarations. The worth while to mention fix is with libfdisk sun geometry. It comes from bitops.h cpu_to_be16 macro that further expands from include/bits/byteswap.h that has the shadowing. libfdisk/src/sun.c:961:173: warning: declaration of '__v' shadows a previous local [-Wshadow] libfdisk/src/sun.c:961:69: warning: shadowed declaration is here [-Wshadow] libfdisk/src/sun.c:961:178: warning: declaration of '__x' shadows a previous local [-Wshadow] libfdisk/src/sun.c:961:74: warning: shadowed declaration is here [-Wshadow] That could have caused earlier some unexpected results. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* libfdisk: fix bug in cmp_numbers() and partitions sortingKarel Zak2014-12-041-2/+37
| | | | | Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1170191 Signed-off-by: Karel Zak <kzak@redhat.com>
* libfdisk: remove 'end' from struct fdisk_partitionKarel Zak2014-12-041-8/+30
| | | | | | This struct member duplicate "start+size". Signed-off-by: Karel Zak <kzak@redhat.com>
* libfdisk: rename sector_t to fdisk_sector_tKarel Zak2014-12-041-8/+7Star
| | | | | | .. just to avoid too generic names for public API. Signed-off-by: Karel Zak <kzak@redhat.com>
* libfdisk: fix cfdisk freespace analyzeKarel Zak2014-12-041-0/+6
| | | | | | | | | The problem is how fdisk_partition_cmp_start() compare numbers, the function returns result from "a->start - b->start", unfortunately the numbers are uint64, but function returns "int". Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1170191 Signed-off-by: Karel Zak <kzak@redhat.com>
* libfdisk: add API docsKarel Zak2014-11-261-3/+5
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* agetty: fix typoKarel Zak2014-11-211-0/+10
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libfdisk: fix table_add_freespace(), add debug messagesKarel Zak2014-11-131-4/+19
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libfdisk: cleanup partno APIKarel Zak2014-10-151-1/+3
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libfdisk: make it possible to use zero for size and startKarel Zak2014-10-151-3/+8
| | | | | | | | | | | | | | | | 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>
* sfdisk: be sensitive to PT limitsKarel Zak2014-10-071-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* sfdisk: improve UIKarel Zak2014-10-071-1/+5
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libfdisk: return partno when add new partitionKarel Zak2014-10-071-1/+1
| | | | | | | * improve the way how sfdisk report results * the API change simplify applications Signed-off-by: Karel Zak <kzak@redhat.com>
* libfdisk: add fdisk_apply_table() and fdisk_delete_all_partitions()Karel Zak2014-08-291-2/+34
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libfdisk: vary basic dump parsing functionsKarel Zak2014-08-251-1/+0Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libfdisk: remove debug dump function, cleanup APIKarel Zak2014-08-221-22/+1Star
| | | | | | | 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>
* libfdisk: more docsKarel Zak2014-08-141-3/+9
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libfdisk: remove dependence on libsmartcolsKarel Zak2014-08-131-94/+0Star
| | | | | | It's application business to convert libfdisk_table to string. Signed-off-by: Karel Zak <kzak@redhat.com>
* libfdisk: fix %ju -> %zuKarel Zak2014-05-131-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libfdisk: add generic function to check partitions orderKarel Zak2014-04-161-0/+23
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libsmartcols: clean up flags usageKarel Zak2014-04-031-1/+1
| | | | | | | | | * 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>
* libfdisk: fix freesapce detection for nested partitionsKarel Zak2014-04-031-7/+9
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* cfdisk: clean up scols usageKarel Zak2014-04-031-2/+5
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libfdisk: clean up scols usageKarel Zak2014-04-031-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* Use libsmartcols in libfdisk and cfdiskOndrej Oprala2014-04-031-11/+13
| | | | Signed-off-by: Ondrej Oprala <ooprala@redhat.com>
* libfdisk: clean up debug outputKarel Zak2014-03-211-13/+14
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libfdisk: use new debug functionsKarel Zak2014-03-211-13/+13
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libfdisk: don't count special whole-disk partitionsKarel Zak2014-03-111-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libfdisk: add dump functions, make freespace code genericKarel Zak2014-03-111-60/+117
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libfdisk: (dos) fix ext_index usageKarel Zak2014-03-111-3/+5
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libfdisk: remove label specific get_freespaceKarel Zak2014-03-111-60/+46Star
| | | | | | | - it seems we can use improved nested<->container relationship rather than implement DOS specific function Signed-off-by: Karel Zak <kzak@redhat.com>