Commit Graph

789 Commits

Author SHA1 Message Date
Karel Zak 89c0297bcc libfdisk: fix alignment logic for tiny partitions
Addresses: https://github.com/karelzak/util-linux/issues/1018 (second case)
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-04-29 11:10:54 +02:00
Karel Zak b80fb30a5b libfdisk: make sure we check for maximal number of partitions
Addresses: https://github.com/karelzak/util-linux/issues/1018
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-04-28 12:58:42 +02:00
Karel Zak 243fff1dc6 libfdisk: (script) fix partno_from_devname()
Addresses: https://github.com/karelzak/util-linux/issues/1015
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-04-27 11:15:00 +02:00
Rosen Penev ad296391f9
[clang-tidy] fix wrong *cmp usage
Found with bugprone-suspicious-string-compare

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-04-20 13:21:00 -07:00
Rosen Penev 042f62dfc5
[clang-tidy] do not use else after return
Found with readability-else-after-return

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-04-20 13:20:59 -07:00
Karel Zak ca6e434a7d libfdisk: remove unwanted assert()
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-03-24 10:52:54 +01:00
Gaël PORTAY 3468dda9c3 libfdisk: (script) fix segmentation fault
This patch fixes a segmentation fault that occurs if the name value is
empty (i.e. name=).

Signed-off-by: Gaël PORTAY <gael.portay@collabora.com>
2020-03-20 16:28:33 -04:00
Karel Zak f94e753b35 libfdisk: add partition type aliases and shortcuts
Now, the type shortcuts are supported for sfdisk scripts only.

Unfortunately, the current implementation is not generic enough
and it's also fragile as 'E' shortcut is in collision with 0x0E
type for MBR. The another issue is 'L' which makes shortcuts useless
for fdisk where 'L' is used for another purpose in dialogs.

This patch introduces partition type aliases as extension to
shortcuts. The definition of the shortcut is part of the label
definition and it's not more hardcoded in sfdisk script code.

This patch also introduces 'Ex' shortcut as replacement for (now
deprecated) 'E'.

Signed-off-by: Karel Zak <kzak@redhat.com>
2020-03-03 15:59:49 +01:00
Karel Zak ce8985cc71 libfdisk: (gpt) partition name default to empty string
Just for backward compatibility, otherwise it's strange ;-)

Signed-off-by: Karel Zak <kzak@redhat.com>
2020-02-25 12:41:10 +01:00
Karel Zak f4189a087a libfdisk: add missing comments
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-02-25 12:25:17 +01:00
Karel Zak 487b57f58b libfdisk: use ul_encode_to_utf8()
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-02-25 12:21:32 +01:00
Sami Kerola d8ed9e038c
libfdisk: fix pointer wraparound warning
libfdisk/src/gpt.c:1713:6: warning: assuming pointer wraparound does not
occur when comparing P +- C1 with P +- C2 [-Wstrict-overflow]

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-02-15 15:24:02 +00:00
Karel Zak b7c015d1c5 libfdisk: (docs) fix typos
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-02-05 14:50:05 +01:00
Karel Zak 387ac2771f libfdisk: (gpt) add functionality to move backup header
- add fdisk_gpt_disable_relocation() to disable move backup header to standard location

- add fdisk_gpt_enable_minimize() to move backup header behind last partition

Note that fdisk_gpt_disable_relocation() has to be used before fdisk_assign_device(),
because automatic relocation is done when libfdisk reads the header from the device.

For example:
	lb = fdisk_get_label(cxt, "gpt");

	fdisk_gpt_disable_relocation(lb, 1);
	fdisk_assign_device(cxt, devname, 0);

For fdisk_gpt_enable_minimize() it's not important as recalculation is
done before write, for example:

	fdisk_assign_device(cxt, devname, 0);
	fdisk_gpt_enable_minimize(fdisk_get_label(cxt, NULL), 1);

	... add partition, etc ...

	fdisk_write_disklabel(cxt);

Signed-off-by: Karel Zak <kzak@redhat.com>
2020-02-05 14:37:41 +01:00
Karel Zak 36cd4b3c46 libfdisk: (gpt) add GPT debug mask
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-02-05 14:17:23 +01:00
Karel Zak afb27a8e4c libfdisk: (gpt) cleanup and consolidate write code
- add fsync after write
- use write_all()
- use the same code for all write steps

Signed-off-by: Karel Zak <kzak@redhat.com>
2020-02-05 14:15:23 +01:00
Karel Zak d74b16bdf1 libfdisk: (script) fix memory leak
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-02-04 15:54:10 +01:00
Karel Zak d8c68b52cc libfdisk: (script) accept sector-size, ignore unknown headers
- add sector-size between supported headers (already in --dump output)

- report unknown headers by -ENOTSUP

- ignore ENOTSUP in sfdisk (but print warning) and in fdisk_script_read_file()

Addresses: https://github.com/karelzak/util-linux/issues/949
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-02-04 15:11:19 +01:00
Karel Zak caa37b6e18 libfdisk: fix __copy_partition()
The code called free() for pointers copied from the source partition.

Addresses: https://github.com/systemd/systemd/pull/14677
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-01-28 12:46:39 +01:00
Karel Zak dfe28f0e01 libfdisk: make sure we use NULL after free
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-01-28 12:29:44 +01:00
Karel Zak b1bc5ae39e libfdisk: (gpt) cleanup entries array size calculations
- move all calculations to inline functions
- remove duplicate code
- keep the same names for the same stuff

Signed-off-by: Karel Zak <kzak@redhat.com>
2020-01-23 15:50:53 +01:00
Karel Zak 3c3b7648c9 libfdisk: fix const char mess
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-01-23 15:50:42 +01:00
Karel Zak e5f3144616 libfdisk: add fdisk_set_disklabel_id_from_string()
We have fdisk_set_disklabel_id(), but it's old ask-API based function.
It's not comfortable if you want to avoid dialog or template.

Addresses: https://github.com/karelzak/util-linux/issues/916
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-01-23 15:50:12 +01:00
Karel Zak 24cee7157a docs: update year in libs docs
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-01-06 12:59:45 +01:00
Karel Zak 4af92de983 build-sys: remove duplicate includes
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-12-10 13:50:18 +01:00
Karel Zak 96c2b09fcb libfdisk: move GPT partition types to include/
We need the array use in another tools too. Let's follow the way we
use for MBR and keep it in include/.

Signed-off-by: Karel Zak <kzak@redhat.com>
2019-12-04 12:37:22 +01:00
Karel Zak b4251e5151 libfdisk: improve Sun partitions calculation [lgtm scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-12-03 15:07:58 +01:00
Evan Green ae1e82e0b5 libfdisk: Space before first partition may not be aligned
libfdisk chooses a grain of 1MB fairly arbitrarily, and this granule
may not be honored by other utilities. GPT disks formatted elsewhere
may have space before the first partition, AND a partition that exists
solely below 1MB. If this occurs, cfdisk ends up adding a free space
region where end < start, resulting in a 16 Exabyte free region.

That's too many exabytes.

This happens because the start gets rounded up to the granule size in
new_freespace() but the end is left alone. The logs show it best:

23274: libfdisk:      CXT: [0x572d878]: initialized:  last=34, grain=2048
23274: libfdisk:      CXT: [0x572d878]: partno=10, start=64
23274: libfdisk:      CXT: [0x572d878]: freespace analyze: partno=10, start=64, end=64
23274: libfdisk:      CXT: [0x572d878]: LBA           34 aligned-up           2048 [grain=2048s]
23274: libfdisk:      CXT: [0x572d878]: LBA           63 aligned-down            0 [grain=2048s]
23274: libfdisk:      CXT: [0x572d878]: LBA           34 aligned-near            0 [grain=2048s]
23274: libfdisk:      CXT: [0x572d878]: 0 in range <2048..0> aligned to 2048
23274: libfdisk:     PART: [0x574bb98]: alloc
23274: libfdisk:      TAB: [0x5749d58]: adding freespace
23274: libfdisk:      TAB: [0x5749d58]: insert entry 0x574bb98 pre=0x574a820 [start=2048, end=63, size=18446744073709549632, freespace  ]

Avoid this by aligning the last value like new_freespace() does.

Signed-off-by: Evan Green <evangreen86@gmail.com>
2019-11-12 14:38:26 -08:00
Karel Zak 7cbde88185 libfdisk: consolidate strdup() use
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-10-31 12:25:08 +01:00
Elliott Mitchell 2bb3aa36b2 cleanup: Remove some spurious spaces
Sorry detail-oriented people tend to wipe these out if they notice them.
Add in automated tools and lots of excess end-of-line spaces get wiped
out.

Addresses: https://github.com/karelzak/util-linux/pull/849
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-10-01 13:01:43 +02:00
Karel Zak 1d84470388 libfdisk: (gpt) fix hybrid MBR detection, fix 'w'
* current code overwrites hybrid MBR because EE partition
  is expected from fist sector, this is not true for hybrid MBR

* print "The partition table has been altered." message also for
  nested contexts

* remove "You have to sync the MBR manually" message

Addresses: https://github.com/karelzak/util-linux/issues/851
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-10-01 12:51:04 +02:00
Elliott Mitchell eb913f6b98 fdisk: Correct handling of hybrid MBR
The traditional MBR has pretty well NO limitations on slices.  They can
be a single misaligned sector if desired.  While this is undesireable
for most real world uses, for the few places they're still used extra
limitations cause breakage not safety.

Signed-off-by: Karel Zak <kzak@redhat.com>
2019-10-01 12:04:02 +02:00
Andrius Štikonas 2ebc944fa4 docs: fix mixtyped constant.
Signed-off-by: Andrius Štikonas <andrius@stikonas.eu>
2019-09-26 15:55:48 +02:00
Karel Zak e3cabf33e5 libfdisk: (bsd) cast before ask [lgtm scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-09-20 15:43:12 +02:00
Karel Zak 2815af9ed4 libfdisk: (gpt) cast number of entries [lgtm scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-09-20 15:40:14 +02:00
Karel Zak e56ca06815 libfdisk: add sector-size to dump
We do not use sector-size from dumps to create partition tables,
because it's always necessary to use real device specific settings.

The new sector-size value is usable when you use the dump as
a description of the device or disk image.

Addresses: https://github.com/karelzak/util-linux/issues/869
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-09-16 10:29:41 +02:00
Ernesto A. Fernández b221b9a9d7 libfdisk: (gpt) add GUID for APFS containers
Add the partition type GUID for the Apple File System to gpt_parttypes.

Signed-off-by: Ernesto A. Fernández <ernesto.mnd.fernandez@gmail.com>
2019-09-10 12:40:32 +02:00
Karel Zak e4e0b1a6f0 libfdisk: cleanup fdisk_deassign_device() docs
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-09-06 15:07:43 +02:00
Karel Zak 1116884cf7 libfdisk: use grain as small as possible
The current implementation does not allow to move partition for
example in +/-1 sector range, because free space analyze is by default
based on regular grain used for partitioning (=1MiB).

Signed-off-by: Karel Zak <kzak@redhat.com>
2019-09-06 13:09:30 +02:00
Karel Zak b161f810b0 libdisk: write sample output to stdout
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-08-30 16:05:50 +02:00
Karel Zak 975b321b5d libfidk: (dos) fix tiny partitions calculation
The code uses last_sector -= 1 for tiny partitions. This does not make
sense. This stupidity has been introduced by (my) badly commented commit
09a4ca5e45 ... sorry.

Fortunately, this issue is visible only for tiny partitions on large
devices (partitions where size < grain; usual grain is 1MiB) if the last
sector is specified by relative notation (+size{siffix}).

Note that "last -= 1" makes sense when the "last" is align to the
optimal I/O boundary; in this case we need to set the end of the
partition one sector before the boundary. For tiny devices it does not
makes sense as we do not align these partitions.

Addresses: https://github.com/karelzak/util-linux/issues/843
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-08-22 14:00:32 +02:00
Karel Zak 08474fde66 libfdisk: (script) support shortcuts in the type= field
The unnamed-field format supports partition type shortcuts:

	",1MiB,L'

but for named-field format it requires full type:

 (mbr)	"size=1MiB,type=83"
 (gpt)  "size=1MiB,type=0FC63DAF-8483-4772-8E79-3D69D8477DE4"

This patch implements type shortcuts also for named-field format:

	"size=1MiB,type=L"

to make it more user-friendly and unified.

Addresses: https://github.com/karelzak/util-linux/issues/837
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-08-08 10:34:27 +02:00
Karel Zak cb74ebad25 libfdisk: refer to partx(8) rather than to kpartx(8)
Reported-by: Petr Pisar <petr.pisar@atlas.cz>
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-08-06 12:24:33 +02:00
Karel Zak 10c39f03a1 libfdisk: improve partition copy on resize
It seems pretty fragile to copy also reference counting and reference
to table list.

Addresses: https://github.com/karelzak/util-linux/pull/822
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-07-22 12:09:38 +02:00
Vojtech Trefny 79f37ec4e1 libfdisk: Fix double free of *_chs strings in fdisk_partition
__copy_partition doesn't duplicate these strings which leads to
occasional double free.

Signed-off-by: Vojtech Trefny <vtrefny@redhat.com>
2019-07-19 13:42:49 +02:00
Karel Zak 1ace839781 libfdisk: don't use NTFS as MBR
Same as 7c643ed285.

Signed-off-by: Karel Zak <kzak@redhat.com>
2019-07-17 12:42:39 +02:00
Karel Zak 7c643ed285 libfdisk: don't use FAT as MBR
The current libfdisk MBR detection is too weak, the result is that it
reuses MBR from FAT. The correct behavior is to create a new MBR, wipe
first sector (on write) and warn about obsolete FAT superblock.

Reported-by: Mike Fleetwood <mike.fleetwood@googlemail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-07-17 12:11:38 +02:00
Sami Kerola 34813bdd29
libfdisk: fix variable shadowing
libfdisk/src/context.c:678:7: warning: declaration of ‘rc’ shadows a
previous local [-Wshadow]

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2019-07-12 21:45:50 +01:00
Marcos Mello f1424a9423 libfdisk: fix typos 2019-06-20 08:22:25 -03:00
Karel Zak 7571ec08a1 libfdisk: add fdisk_assign_device_by_fd()
It's possible that caller has the device already opened for some
other task, so let's reuse the file descriptor.

Requested-by: Lennart Poettering <lennart@poettering.net>
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-06-18 13:30:42 +02:00
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