Commit Graph

751 Commits

Author SHA1 Message Date
Karel Zak c709dbcdb5 libfdisk: (docs) add missing comment
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-07-22 10:44:47 +02:00
Karel Zak f11fe35f5e libfdisk: (docs) add missing references
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-07-22 10:33:53 +02:00
Karel Zak 29e204d117 docs: reword others "allow to"
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-07-14 14:31:29 +02:00
Yuri Chornoivan aa1c7a7686 More typo fixes by fossies 2020-07-13 15:33:42 +03:00
Yuri Chornoivan 311e33afef Fix minor typos 2020-07-09 20:14:32 +03:00
Karel Zak d118738095 libfdisk: (gpt) fix compiler warning [-Wmaybe-uninitialized]
Make sure that variables used in  gpt_calculate_* are always initialized.

Addresses: https://github.com/karelzak/util-linux/issues/1091
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-07-03 12:30:59 +02:00
Toni Uhlig 9eba847689
libfdisk, unshare: fix gcc-4.9.4 warnings
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
2020-06-19 20:37:33 +02:00
Karel Zak 967b8c2579 libfdisk: (docs) document new functions
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-06-09 10:50:42 +02:00
Karel Zak c7fce443b1 libfdisk: (dos) be more explicit in fdisk_verify_disklabel() output
Let's print number of detected errors or "No errors detected." for
MBR. We already use the same for GPT.

The patch also modifies fdisk_verify_disklabel() return code to inform
caller about number of issues.

Addresses: https://github.com/karelzak/util-linux/issues/1051
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-05-27 17:49:26 +02:00
Karel Zak 83fdb880b9 libfdisk: (dos) fix default partition start
The current code implements the default start as first free space, but
it does not check if the space is large enough.

Addresses: https://github.com/karelzak/util-linux/issues/1044
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-05-21 15:37:59 +02:00
Karel Zak 1001633991 libfdisk: (dos) be more robust about max number of partitions
It seems the previous MAXIMUM_PARTS bug fix has not been generic
enough. Let's use the check for all dos_add_partition().

This patch also remove libfdisk attempt to be smart and search for
unused primary partition. If you need more than 60 partition in MBR
than you have a different problem that cannot be solved by libfdisk
...

References: b80fb30a5b
Addresses: https://github.com/karelzak/util-linux/issues/1022
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-05-18 14:13:33 +02:00
Karel Zak 6a4d53ce64 libfdisk: fix partition calculation for BLKPG_* ioctls
The include/partx.h interface we use in util-linux uses 512-byte
sectors, but libfdisk uses real sector sizes.

Signed-off-by: Karel Zak <kzak@redhat.com>
2020-05-06 13:32:46 +02:00
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