Commit Graph

789 Commits

Author SHA1 Message Date
Karel Zak 73ec5e164c libfdisk: fix fdisk_script_get_table()
Make sure we never return NULL and we reuse the table in code.

Signed-off-by: Karel Zak <kzak@redhat.com>
2019-06-17 15:46:10 +02:00
Karel Zak 9335bfc845 libfdisk: (docs) add notes about fdisk_enable_wipe()
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-06-17 15:46:10 +02:00
Karel Zak bfdca6d728 libfdisk: add fdisk_script_set_table()
This small change improves possibility to modify by script described
PT and use script API in another tools as primary way to create
partitions.

All you need is to compose script by fdisk_script_set_header() and
fdisk_script_set_table() and than apply by fdisk_apply_script().

Requested-by: Lennart Poettering <lennart@poettering.net>
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-06-17 15:46:10 +02:00
Karel Zak cbfd67cfea libfdisk: (docs) add reference to v2.33
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-06-07 12:30:13 +02:00
Sami Kerola 620851e0cc
libfdisk: assert if self_pte() returns NULL
The self_pte() can return NULL if partitions array is not large enough,
but that should also be impossible and definitely a bug.

libfdisk/src/dos.c:984:8: warning: potential null pointer dereference [-Wnull-dereference]
libfdisk/src/dos.c:1031:8: warning: potential null pointer dereference [-Wnull-dereference]

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2019-05-22 19:45:54 +01:00
Karel Zak 04d0701ea8 libfdisk: (bsd) improve checksum calculation [-Waddress-of-packed-member]
Let's keep compilers and static analyzers happy. The idea is to use
memcpy() to copy from buffer to variable and use all label as unsigned
char rather than vectorize by unsigned short.

Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-22 17:47:04 +02:00
Karel Zak f11eedf527 libfdisk: avoid memory leak [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-15 17:12:38 +02:00
Karel Zak 845fd622ed libfdisk: avoid division by zero [clang scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-15 17:10:38 +02:00
Karel Zak 1d161441c2 libfdisk: remove unused code [clang scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-15 16:59:52 +02:00
Karel Zak 7f3a98229b libfdisk: properly check return code of add_to_partitions_array() [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-15 16:49:26 +02:00
Juerg Haefliger 834b3d07e4 libfdisk: (dos) Use strtoul to parse the label-id
Parsing of the label-id fails on 32-bit if the MSB is set. Fix that by
using strtoul instead of strtol.

Signed-off-by: Juerg Haefliger <juergh@canonical.com>
2019-02-25 14:08:56 +01:00
Karel Zak adea904a61 libfdisk: (dos) rewrite fist/last free sector functions
The current code uses first[] and last[] arrays to specify partition
ranges. This is unnecessary as we already have all in memory.

The current code offers in first and last sector dialogs ranges
without care about already used areas.

This commit makes things more readable, more user-friendly and
remove obscure first[] and last[].

Reported-by: 冰柯 <ziming_cool@126.com
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-02-25 13:59:50 +01:00
Karel Zak 3c21e32245 libfdisk: (dos) improve first unused sector for logical partitions
Make sure we probe within extended partition.

Signed-off-by: Karel Zak <kzak@redhat.com>
2019-02-18 16:38:11 +01:00
Sami Kerola 110260830d docs: fix typos [codespell]
Reference: https://github.com/codespell-project/codespell
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2019-02-18 13:22:43 +01:00
Sami Kerola 4813a5210f various: fix 'uninitialized when used' warnings [clang]
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>
2019-02-18 13:19:24 +01:00
Fabian.Kirsch@dlr.de 9a76780f86 libfdisk: sanity check, to prevent overlapping partitions from being partly 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>
2019-02-18 12:58:07 +01:00
Karel Zak 1882b3a617 libfdisk: use list_add_tail() in more robust way
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-02-18 12:35:33 +01:00
Icenowy Zheng 5d3a4aab64 libfdisk: (gpt) add HiFive Unleashed bootloader partition UUIDs
The HiFive Unleashed SBC's bootloader seeks for GPT partitions with
specific UUID for loading the next stage bootloader (ZSBL loads FSBL,
and FSBL loads BBL).

Add these partition type UUIDs.

Signed-off-by: Icenowy Zheng <icenowy@aosc.io>
2019-02-04 15:06:19 +01:00
Karel Zak 167a2b520a sfdisk: fix logical partition resize when start specified
Addresses: https://github.com/karelzak/util-linux/issues/745
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-01-31 14:16:42 +01:00
Karel Zak 8a74df7f74 libfdisk: add comment to fdisk_set_first_lba()
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-01-18 11:38:57 +01:00
Karel Zak e6effcac61 fdisk: make partition types uses more robust
* report failed partition type parsing
* make sure partition types code (from user reply) for MBR is hex

Reported-by: Jonny Grant <jg@jguk.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-01-10 12:17:19 +01:00
Ruediger Meier 7a715f731a libfdisk: fix printf format modifier
libfdisk/src/script.c: In function ‘fdisk_script_read_context’:
libfdisk/src/script.c:452:33: error: format ‘%zu’ expects argument of type ‘size_t’, but argument 4 has type ‘long unsigned int’ [-Werror=format=]
   snprintf(buf, sizeof(buf), "%zu", fdisk_get_grain_size(cxt));
                                 ^

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2018-10-04 11:56:25 +02:00
Ruediger Meier e5e3a87cdb libfdisk: fix OSX compiler warning
libfdisk/src/context.c:1354:54: error: unused parameter 'cxt' [-Werror,-Wunused-parameter]
const char *fdisk_get_devmodel(struct fdisk_context *cxt)

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2018-10-04 11:56:22 +02:00
Karel Zak ab295603e9 libfdisk: (docs) add missing function
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-09-19 12:00:59 +02:00
Karel Zak 2f35c1ead6 libfdisk: count gaps to possible size when resize
The current code counts only partition sizes when it counts possible
space, but we have gaps between the partitions. It seems better to
count all based on offsets rather than sizes.

Addresses: https://github.com/karelzak/util-linux/issues/693
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-09-17 11:58:50 +02:00
Karel Zak e4386c8cc0 libfdisk: accept grain script header
The "grain" variable is used to calculate partitions alignment. The
default is 1MiB (or minimal I/O size). The libfdisk provides API to overwrite
this default, but this feature has been nowhere accessible for
end-user.

This patch support for "grain: <size>" in libfdisk scripts.

Addresses: https://github.com/karelzak/util-linux/issues/688
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-09-12 13:26:18 +02:00
Karel Zak 745801e44a libfdisk: add fdisk_get_devmodel() and fdisk_get_devno()
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-08-30 14:01:46 +02:00
Karel Zak 4189907e6c docs: use SPDX license names
Let's use standardized names for licenses. The names used by SPDX
makes things more obvious at first glance. For complete list see:
https://spdx.org/licenses/

Note, this commit does not change any license or so...

Signed-off-by: Karel Zak <kzak@redhat.com>
2018-08-16 14:47:21 +02:00
Awal Garg 757cefbb61 libfdisk: Accept negative numbers for last sector input
[kzak@redhat.com: - add note to the man page
                  - add '-' to the dialog query
                  - cleanup functions names and libfdisk.sym]

Signed-off-by: Karel Zak <kzak@redhat.com>
2018-07-31 14:54:12 +02:00
Karel Zak ec4b88b83d libfdisk: fix compiler warnings [-Wcast-qual]
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-07-23 11:39:13 +02:00
Karel Zak b9144a43c0 libfdisk: fix compiler warning [-Wmaybe-uninitialized]
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-07-18 10:00:18 +02:00
Karel Zak e6dfbd70ea libfdisk: reduce number of asprintf() calls, check return value
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-07-04 15:16:35 +02:00
KyleMahlkuch 7377518976 libfdisk: Fix multipath partition seperators for user-friendly names
The current code assumes "-part" is the only partition sepereator
but this is not true for some distros.

For example in Ubuntu 18.04 fdisk does not print the correct names for
mpatha:

~# ls -l /dev/mapper/mpatha*
lrwxrwxrwx 1 root root 7 Feb  1 04:39 /dev/mapper/mpatha -> ../dm-0
lrwxrwxrwx 1 root root 7 Feb  1 04:38 /dev/mapper/mpatha1 -> ../dm-4
lrwxrwxrwx 1 root root 7 Feb  1 04:38 /dev/mapper/mpatha2 -> ../dm-5
lrwxrwxrwx 1 root root 7 Feb  1 04:38 /dev/mapper/mpatha3 -> ../dm-6

~# fdisk -l /dev/mapper/mpatha
Device                   Boot     Start        End   Sectors  Size Id Type
/dev/mapper/mpatha-part1           2048  419432447 419430400  200G 83 Linux
/dev/mapper/mpatha-part2      419432448  838862847 419430400  200G 83 Linux
/dev/mapper/mpatha-part3      838862848 1258291199 419428352  200G 83 Linux

Instead of assuming a partition seperator of "-part" this patch uses
access to check the file system for a partition seperator of "p" or
the absense of a partition seperator. If neither of these work the patch
defaults to "-part" like we had before this patch.
2018-07-04 15:08:00 +02:00
Karel Zak 810b313688 libfdisk: use \x<hex> to read/write partition name
Addresses: https://github.com/karelzak/util-linux/issues/656
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-07-04 14:09:16 +02:00
Vaclav Dolezal bb09ebfe54 libfdisk: fix list_del after partition reset
Signed-off-by: Vaclav Dolezal <vdolezal@redhat.com>
2018-05-09 17:29:32 +02:00
Karel Zak 01aec449f1 libfdisk: fix compiler warning [-Wunused-parameter]
Reported-by: L A Walsh <lkml@tlinx.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-05-03 10:40:37 +02:00
Karel Zak d881b77331 libfdisk: improve JSON output
* use fputs_quoted_json() for all data
* fix use of variables separator

Signed-off-by: Karel Zak <kzak@redhat.com>
2018-04-05 12:38:22 +02:00
Karel Zak 314a214517 libfdisk: (docs) fix section name
The string "DOS (MBR)" generates filename with "(...)" which is
unacceptable by kernel.org stuff.

Signed-off-by: Karel Zak <kzak@redhat.com>
2018-03-21 15:49:32 +01:00
Karel Zak cd42d02ff2 libfdisk: (docs) update year
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-03-20 18:55:49 +01:00
Karel Zak ed930a9b89 libfdisk: fix docs warnings
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-02-21 13:23:08 +01:00
Karel Zak 9070c2e200 libfdisk: (docs) add missing docs blocks
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-02-21 13:12:12 +01:00
Karel Zak f92c9f3782 libfdisk: (docs) improve enums documentation
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-02-21 12:48:20 +01:00
Ruediger Meier 73afd3f8e8 misc: fix typos using codespell
Some more funny typos, please review carefully.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2018-02-16 11:12:52 +01:00
Ruediger Meier af1bc027db build-sys: remove redundant EXTRA_DIST files
The sources of AC_CONFIG_FILES (*.in) are automatically
distributed.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2018-01-22 11:16:49 +01:00
Ruediger Meier 4beacf105e build-sys: avoid using prog_DEPENDENCIES
Use EXTRA_prog_DEPENDENCIES to have the benefit
of automake's automatic prog_DEPENDENCIES.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2018-01-22 11:16:49 +01:00
Ruediger Meier 0da03d4490 build-sys: remove unneeded dependencies on bla.h.in
We have already automakes's automatic dependencies like
  bla.h.in -> bla.h -> foo.o -> bar.la

An explicit direct dependency bla.h.in -> bar.la
is redundant and useless anyways.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2018-01-22 11:16:49 +01:00
Ruediger Meier a459f2ec33 build-sys: automake is able to find headers in builddir ...
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2018-01-22 11:16:49 +01:00
Ruediger Meier 1d667d8849 build-sys: remove generated headers from dist tar ball
Headers should only be listed in either *_HEADERS or
*_SOURCES, especially when we want nodist_*_HEADERS.

Since all the generated headers are made by configure we
don't even need to use BUILT_SOURCES or other tricks.

Also see automake docs 9.4.1 Built Sources Example:
  case "Build bindir.h from configure"

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2018-01-22 11:16:49 +01:00
Karel Zak a15dca2f6d include/debug: introduce __UL_INIT_DEBUG_FROM_STRING()
Let's make it possible to use debug.h without environment variables.

Suggested-by: J William Piggott <elseifthen@gmx.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-01-17 13:58:29 +01:00
Karel Zak e92b6f68c4 libfdisk: (script) be consistent in code with types
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-01-12 12:04:16 +01:00
Karel Zak 6d00cfb233 include/debug: don't print pointer address for SUID programs
* introduce new flag __UL_DEBUG_FL_NOADDR to suppress pointer address printing

* use __UL_DEBUG_FL_NOADDR when SUID

* move ul_debugobj() to debugobj.h, and require UL_DEBUG_CURRENT_MASK
  to provide access to the current mask from ul_debugobj(). It's better
  than modify all ul_debugobj() calls and use the global mask as
  argument.

* remove never used UL_DEBUG_DEFINE_FLAG

Reported-by: halfdog <me@halfdog.net>
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-01-12 11:01:26 +01:00
Karel Zak 9c76f85f9a libfdisk: allow to start freespace for zero
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>
2018-01-11 15:18:00 +01:00
Karel Zak f7606d2d9f libfdisk: (sun) fix n-1 bug and whole-disk
* set whole_disk variable if SUN_TAG_WHOLEDISK specified
* fix N-1 bug in add new partition according to template (script)

Addresses: https://github.com/karelzak/util-linux/issues/555
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-01-11 14:23:57 +01:00
Karel Zak 6ebc37854d libfdisk: (script) support R (RAID) and V (LVM) shortcuts
Addresses: https://github.com/karelzak/util-linux/issues/560
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-01-09 12:12:50 +01:00
Karel Zak af846e1ff9 libfdisk: (gpt) add VMware specific UUIDs
Addresses: https://github.com/karelzak/util-linux/issues/559
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-01-08 12:43:22 +01:00
Karel Zak 280b975475 libfdisk: (dos) fix max heads
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-01-02 16:50:31 +01:00
Karel Zak 2dd2880f12 libfdisk: extend API to provide label specific geometry ranges
Now fdisk provides DOS specific geometry ranges in expert menu.

Addresses: https://github.com/karelzak/util-linux/issues/556
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-01-02 16:43:22 +01:00
Karel Zak 760942e284 libfdisk: (gpt) use fdisk_warn() for failed name setting
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-12-20 12:31:10 +01:00
Vaclav Dolezal c116524184 libfdisk: return bytes processed from gpt_entry_set_name(), process rc
Made gpt_entry_set_name() return number of utf8 bytes processed on
success, so info message about change can be accurate.

Signed-off-by: Vaclav Dolezal <vdolezal@redhat.com>
2017-12-19 10:48:13 +01:00
Vaclav Dolezal f069f6fe69 libfdisk: allocate enough bytes for ucs2 to utf8 encoding
Allocate 3*number_of_ucs2_characters bytes for utf8 output.

Also as we are using calloc there's no need to write terminating null
byte.

Signed-off-by: Vaclav Dolezal <vdolezal@redhat.com>
2017-12-18 16:18:44 +01:00
Vaclav Dolezal 5be3df4afd libfdisk: gpt: properly encode string on rename
GPT partition name entry should be recorded as little endian UCS2, so I have
written proper conversion (assuming UTF8 input).

Signed-off-by: Vaclav Dolezal <vdolezal@redhat.com>
2017-12-18 16:17:49 +01:00
Sami Kerola fcf841f8d3 misc: fix typos
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-11-28 14:39:13 +01:00
Mikhail Vorobyov 9e6ccaab5b libfdisk: (sun) enhance searching of free space
Potential partition start should be aligned to cylinders. So fdisk
wouldn't consider partition's last cylinder remains as eligible space
for new partition start.
2017-11-16 14:11:19 +01:00
Mikhail Vorobyov 45ce148778 libfdisk: (sun) move aligning of the first sector before availability check
So it will check a sector which would be actualy used as the first sector
of the partition.
2017-11-16 14:11:10 +01:00
Karel Zak 9a8a3b88dc libfdisk: (gpt) move backup header after device resize
Addresses: https://github.com/karelzak/util-linux/issues/532
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-11-14 13:51:48 +01:00
Roddy Shuler cfe4691c6f libfdisk: Fix uninitialized structure
Without this, 'sfdisk -d' with certain filenames would lead to
reading an 's' from the 'type' field in fdisk_reset_labelitem
and cause a crash due to prematurely freeing the 'data.str' field.

Signed-off-by: Roddy Shuler <roddy@endlessm.com>
2017-11-02 21:22:51 -07:00
Mikhail Vorobyov 27895be260 libfdisk: (sun) fix creation of whole disk partition
sun_add_partition() allowed the 1st sector to be 0 for the 3rd partition
only if that sector was free or if other partitions covered the whole
disk. Now it's always allowed for the 1st sector to be set to 0 for
the 3rd partition.

[kzak@redhat.com: - print info about "wholedisk" before "First sector" dialog for 3rd partition
                  - default to 0 for 3rd partition start sector]

Signed-off-by: Mikhail Vorobyov <m.vorobyov@cs.msu.ru>
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-11-02 10:43:27 +01:00
Karel Zak e163adb83b build-sys: fix non-blkid compilation
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-19 13:48:52 +02:00
Karel Zak 9f20d80079 misc: cleanup UUID_STR_LEN definitions
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-15 13:25:32 +02:00
Philip Prindeville b443c1779e misc: replace magic number 37 with UUID_STR_LEN
Signed-off-by: Philip Prindeville <philipp@redfish-solutions.com>
2017-09-05 11:49:21 +02:00
Vaclav Dolezal 504c594777 libfdisk: fix fdisk_reset_partition() leaking *_chs strings.
Signed-off-by: Vaclav Dolezal <vdolezal@redhat.com>
2017-08-24 11:23:44 +02:00
Vaclav Dolezal 5cebb2ab33 libfdisk: fix two potential memory errors.
Fixes one leak and one unchecked allocation error.

[kzak@redhat.com: - don't call fdisk_ask_menu_get_result()
                    after failed fdisk_do_ask()]

Signed-off-by: Vaclav Dolezal <vdolezal@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-08-24 11:21:59 +02:00
Karel Zak b428eb14a8 libfdisk: improve alignment debug mesagges
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-08-22 15:12:36 +02:00
Karel Zak 27c284b848 libfdisk: add --grain to mkpart sample
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-08-22 14:59:42 +02:00
Karel Zak adf09b5c38 libfdisk: add fdisk_save_user_grain()
Let's provide API for applications that don't want to use the default
1MiB grain. The new function allow to use "as minimal as possible" if
grain is set by fdisk_save_user_grain() to 512.

If the phy sector size (or minimal I/O size) is greater than specified
grain size than smallest possible setting is used.

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-08-22 14:55:51 +02:00
Karel Zak 980cc4a182 libfdisk: (dos) use size-=1 when alignment not used later
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-08-22 14:54:27 +02:00
Karel Zak 1573e95514 libfdisk: improve "add partition" debug message
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-08-22 14:53:18 +02:00
Karel Zak 694a407de9 libfdisk: (gpt) fix size-1 error
If partition does not require alignment, then don't call LBA align
function and don't use size-=1 (fdisk_align_lba_in_range() returns
unmodified size and we call size=-1 more than once for the same size).

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-08-22 14:48:14 +02:00
Karel Zak dd3b72b3e9 libfdisk: add --nopartno to mkpart sample
* disable dialogs for the mkpart sample
* add --nopartno use-case to force libfdisk to use default partno(s)
* add test for this feature

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-08-01 13:51:27 +02:00
Karel Zak 537b4db151 libfdisk: allow to resize in unsorted partition table
The current code assumes that partition offsets (starts) are sorted.
This is usual situation, but unsorted partition table is also valid...

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-07-19 15:09:36 +02:00
Karel Zak 264ef9875a libfdisk: improve table print debugs
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-07-19 15:09:12 +02:00
Karel Zak ea36907965 libfdisk: support default partno in mkpart-fullspec sample
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-07-19 12:19:38 +02:00
Karel Zak 992f7cbae4 libfdisk: add fdisk_disable_dialogs()
The default (for historical reasons) is to use dialog driven partitioning.
It's possible to avoid dialogs by fdisk_partition template for
fdisk_add_partition().

Unfortunately in some case (mostly DOS driver) it's not enough, because
we need to distinguish between logical and primary partitions. If we know
that dialogs are unwanted then we can default to primary partition, etc.

This function simplify semantic of the library for non-interactive
programs.

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-07-19 11:30:57 +02:00
Karel Zak e5e704630f libfdisk: (dos) return EINVAL when delete unused partition
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-07-19 10:34:03 +02:00
Ruediger Meier 18751601a8 libfdisk: fix warning -Wunused-function
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-07-18 11:08:28 +02:00
Ruediger Meier 21be08ac8c build-sys: don't use non-existing UUID_LIBS
We've added UUID_LIBS in f77a4d1087 but I don't see what it
was good for.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-07-18 11:06:53 +02:00
Ruediger Meier ac6a6b0d3c libfdisk: use fdisk_sector_t consistently and fix printf format strings
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-07-18 11:06:53 +02:00
Karel Zak 5ecd618511 libfdisk: use BLKPG_* ioctls on linux only
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-07-17 09:47:42 +02:00
Karel Zak 8ffa3b651d libfdisk: make fdisk compliant to UEFI/GPT specification on PMBR
The PMBR partition record should be StartingCHS=0x002000 (0/0/2)
and EndingCHS=0xFFFFFF (1023/255/63)

Addresses: https://github.com/karelzak/util-linux/issues/485
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-07-14 12:48:18 +02:00
Karel Zak c0eabc5382 libfdisk: remove whitespaces
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-07-14 11:36:22 +02:00
Karel Zak 1dd63a3b05 libfdisk: use BLKPG ioctls to inform kernel about changes
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>
2017-07-14 11:34:55 +02:00
Karel Zak 0d034857f2 libfdisk: add comment
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-07-14 11:34:55 +02:00
Karel Zak b9da153254 libfdisk: add fdisk_device_is_used()
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-07-14 11:34:55 +02:00
Karel Zak 2db3cc4cf3 libfdisk: remove unnecessary fstat() call
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-07-14 11:33:30 +02:00
Karel Zak 6a1889b03b libfdisk: move fdisk_reread_partition_table() to another file
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-07-14 11:33:30 +02:00
Karel Zak 288acb4eee tests: don't use errno in output
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-07-12 12:34:22 +02:00
Karel Zak 167d7e9537 libfdisk: (dos) accept start for log.partitions on template
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-07-11 14:24:32 +02:00
Karel Zak f2b6a0c0f5 libfdisk: don't hardcode label type in samples
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-07-11 13:27:01 +02:00
Karel Zak 5fb427c8d2 libfdisk: add sample-fdisk-mkpart-fullspec
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-07-11 13:00:46 +02:00
Karel Zak 2cb4754276 libfdisk: (dos) cleanup template based partitioning
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-07-11 12:25:02 +02:00
Karel Zak 2469ba3677 libfdisk: add fdisk_reassign_device()
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-07-10 12:32:26 +02:00
Karel Zak c134c8b101 libfdisk: support logical partition resize
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-06-19 16:03:41 +02:00
Karel Zak 5ec4400dec libfdisk: allow to resize container
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-06-19 15:32:02 +02:00
Karel Zak 22f4c4641a libfdisk: add more debug messages to get-last-possible resize space
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-06-19 15:27:05 +02:00
Karel Zak 53625d1ae9 libfdisk: (dos) be more verbose on partno -ERANGE error
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-06-19 14:32:59 +02:00
Karel Zak ee9ba4fa5e libfdisk: (dos) fix primary/logical logic when follow template
This stupid bug has been introduced by e1cfb304 (v2.30) and it
disables to create extended partition by cfdisk :-(

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-06-19 11:41:02 +02:00
Sami Kerola 1b5042636f misc: fix reassigned values before old ones has been used [cppcheck]
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-06-14 12:19:20 +02:00
Ruediger Meier 92e486f80e libfdisk: fix guid usage of packed struct gpt_entry
clang issued warnings like this:

../libfdisk/src/gpt.c:371:18: warning: taking address of packed member 'type' of class or structure 'gpt_entry' may result in an unaligned pointer value [-Waddress-of-packed-member]
        guid_to_string(&e->type, str);
                        ^~~~~~~

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-13 23:38:48 +02:00
Ruediger Meier 7f387c5c21 libfdisk: cleanup sun label checksum usuage
We are using now the formerly unused function sun_pt_checksum(). This
cleanup was motivated by clang compiler warning, see below. Also nice
that we are now always using uint16_t instead of short.

Warning was:

../libfdisk/src/sun.c:177:35: warning: taking address of packed member 'csum' of class or structure 'sun_disklabel' may result in an unaligned pointer value
      [-Waddress-of-packed-member]
                while(ush < (unsigned short *)(&sunlabel->csum))

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-13 18:06:36 +02:00
Karel Zak 7dec8dfeca Merge branch 'master' of https://github.com/yurchor/util-linux
* 'master' of https://github.com/yurchor/util-linux:
  Fix minor typos
2017-06-02 11:13:39 +02:00
Ruediger Meier c0d7b11a3f build-sys: fix library order when linking
We got some errors on Alpine Linux where $LTLIBINTL is non-empty:

./.libs/libcommon.a(libcommon_la-blkdev.o): In function `open_blkdev_or_file':
lib/blkdev.c:282: undefined reference to `libintl_gettext
collect2: error: ld returned 1 exit status

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-01 03:16:48 +02:00
Sami Kerola 2e2cfdae79 libfdisk: fix variable shadowing
libfdisk/src/context.c: In function 'fdisk_assign_device':
libfdisk/src/context.c:549:7: warning: declaration of 'rc' shadows a previous local [-Wshadow]
libfdisk/src/context.c:542:10: note: shadowed declaration is here

[kzak@redhat.com: - add rc to debug message]

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-29 12:18:08 +02:00
Yuri Chornoivan 0508f347c8 Fix minor typos 2017-05-24 00:22:20 +03:00
Karel Zak f854eca369 libfdisk: update docs
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-23 14:22:04 +02:00
Karel Zak 8d3e3e6b4d libfdisk: (docs) add missing 'since' tags
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-23 14:02:14 +02:00
Karel Zak 199f8cd3b5 libfdisk: don't use errno after close()
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-17 12:43:48 +02:00
Karel Zak 274e6f6f8f libfdisk: use memcpy() for non-terminated string [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-17 12:29:50 +02:00
Karel Zak 3fdbf0ee09 libfdisk: initialize partno variable [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-17 12:28:07 +02:00
Karel Zak 0a48e2370d libmount: check fstat() return code [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-17 12:28:07 +02:00
Karel Zak 059ad53815 libfdisk: don't print uninitialized variable [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-17 12:28:07 +02:00
Karel Zak 29f2e825d8 libfdisk: add fdisk_partition_has_wipe()
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-09 14:30:02 +02:00
Karel Zak 7095232d21 libfdisk: fix NLS support
The current libfdisk code uses gettext() to translate strings. It
means it follows the default text domain (as set by textdomain(3)
usually in the main program). This is useless for public shared
library.

We have call private bindtextdomain() and use dgettext() with private
domain name to be independent on the main program. For this purpose
include/nls.h supports UL_TEXTDOMAIN_EXPLICIT to use dgettext().

Note that libfdisk will continue to use util-linux.po, rather than
keep the texts in the separate file.

The nls.h has to be included only from fdiskP.h to be sure that
nls.h works as expected for the library.

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-04-25 17:05:09 +02:00
Karel Zak 02a376f2ee libfdisk: (gpt) rename to gpt_entry_is_used()
The current function name is inconsistent with the rest of the code.

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-04-19 14:00:07 +02:00
Pavel Butsykin e6b4209d95 libfdisk: allow to change an existing extended partition
Signed-off-by: Pavel Butsykin <pbutsykin@virtuozzo.com>
2017-04-19 10:25:39 +02:00
Ruediger Meier c8df4b17d4 misc: fix some printf format strings
Fix compiler warnings seen on Linux/i586 and OSX/travis.

  #type            #format   #cast
   unsigned long    %lu       -
   uint64_t         PRIu64    -
   fdisk_sector_t   %ju       (uintmax_t)

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-04-10 15:40:58 +02:00
Karel Zak 52f35f1ecc libfdisk: (gpt) fix ents zeroize
The gpt->ents is "unsigned char" buffer now. We need to use bytes, no
number of entries...

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-04-06 13:39:44 +02:00
Karel Zak bbb574a293 libfdisk: (gpt) update nparts_max
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-04-06 13:04:09 +02:00
Karel Zak a8294f401f libfdisk: (gpt) care about SSIZE_MAX for read(2)
read(2) behavior is undefined if you want to read more  than SSIZE_MAX
bytes. Let's be paranoid and check for this...

Reported-by: Ruediger Meier <sweet_f_a@gmx.de>
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-04-06 12:13:46 +02:00
Karel Zak 9e320545bb libfdisk: (gpt) make entries array size calculation more robust
* use the same function everywhere
* keep calculation based on size_t

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-04-05 18:40:56 +02:00
Karel Zak b683c08108 libfdisk: (gpt) use size_t and gpt_get_nentries()
If possible use size_t for number of entries (partitions). It
makes code more readable and without unnecessary casts.

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-04-05 14:55:32 +02:00
Karel Zak b28df75eec libfdisk: (gpt) don't access entries array directly
We blindly assume that our sizeof(struct gpt_entry) is the same
on-disk stored header->sizeof_partition_entry.

It seems more correct would be to use sizeof specified by header to
access the entries array items. This patch introduces gpt_get_entry()
to avoid direct access to gpt->ents[].

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-04-05 14:19:13 +02:00
Karel Zak 3006dd7352 Merge branch '2017wk11' of git://github.com/kerolasa/lelux-utiliteetit
* '2017wk11' of git://github.com/kerolasa/lelux-utiliteetit:
  blkid: add control struct
  blkid: simplify version option handling
  tests: add static keyword where needed [smatch scan]
  tests: do not use plain 0 as NULL [smatch scan]
  libsmartcols: fix test variable shadowing
2017-03-24 11:59:57 +01:00
Sami Kerola 71f08e9706
tests: do not use plain 0 as NULL [smatch scan]
Likewise commit 8791804065.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-03-17 21:22:26 +00:00
Karel Zak bb6762035a libfdisk: fix compiler warning [-Wsign-compare]
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-03-16 10:01:54 +01:00
Karel Zak b2b5292541 libfdisk: fix potentially NULL pointer usage
Reported-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-03-13 15:20:56 +01:00
Karel Zak 168950e3ce libfdisk: (dos) add ID related debug messages
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-02-27 13:44:08 +01:00
Karel Zak ea4ea332a8 libfdisk: add version to debug output
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-02-27 13:16:18 +01:00
Sami Kerola 2ba641e5f3 misc: add static keyword to where needed [smatch scan]
text-utils/rev.c:68:9: warning: symbol 'buf' was not declared. Should it be
static?

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-20 12:58:49 +01:00
Sami Kerola 8791804065 misc: do not use plain 0 as NULL [smatch scan]
text-utils/tailf.c:69:21: warning: Using plain integer as NULL pointer

Since many 'struct option' has used zero as NULL make them more readable in
same go by reindenting, and using named argument requirements.

Reference: https://lwn.net/Articles/93577/
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-20 12:58:49 +01:00
Karel Zak 1c1d30c750 libfdisk: add sample-fdisk-mkpart binary
For example:
	# sample-fdisk-mkpart --device /dev/sdc 1M 2M 3M - 5M

	# fdisk -l /dev/sdc
	...
	Device     Boot Start    End Sectors Size Id Type
	/dev/sdc1        2048   4095    2048   1M 83 Linux
	/dev/sdc2        4096   8191    4096   2M 83 Linux
	/dev/sdc3        8192  14335    6144   3M 83 Linux
	/dev/sdc4       14336 204799  190464  93M  5 Extended
	/dev/sdc5       16384  26623   10240   5M 83 Linux

Addresses: https://github.com/karelzak/util-linux/issues/204
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-02-17 16:15:03 +01:00
Karel Zak 8d03f4af49 libfdisk: (dos) make it possible to create primary/logical by template
Let's check partition partno if specified to create logical or primary
partition.

Addresses: https://github.com/karelzak/util-linux/issues/204
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-02-17 16:11:37 +01:00
Karel Zak 21f1206aac libfdisk: (gpt) make sure it's GPT in public API
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-02-17 14:47:00 +01:00
Karel Zak e1cfb30466 libfdisk: verify partno from template
* verify partno from template when create a new partition
* remove unnecessary l->ext_offset check

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-02-17 13:17:48 +01:00
Karel Zak a1001292ae libfdisk: (dos) debug what we read from first sector
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-02-14 14:46:19 +01:00
Karel Zak 0cec78a3c4 libfdisk: classify collision type
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-02-14 14:23:45 +01:00
Karel Zak 37204dc60c libfdisk: check for collisions when create new label
We need to be sure that when create a new disklabel than the old label
will be removed.

Addresses: https://github.com/karelzak/util-linux/issues/410
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-02-14 13:07:54 +01:00
Karel Zak bd3457b8d9 libfdisk: fix fdisk_set_wipe_area() calls
The function expects size in sectors rather than in bytes.

Addresses: https://github.com/karelzak/util-linux/issues/410
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-02-10 16:45:18 +01:00
Karel Zak 91cce31a8e sfdisk: --quiet fixes
Addresses: https://github.com/karelzak/util-linux/issues/412
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-02-10 12:54:23 +01:00
Karel Zak f71b96bfa1 libfdisk: (gpt) add check for entries array size
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-01-25 12:00:27 +01:00
Karel Zak 5eaeb5858f libfdisk: (gpt) make calculations more robust
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-01-16 14:57:02 +01:00