Commit Graph
33 Commits
Author SHA1 Message Date
Lennart Poettering c56be2c294 bootctl: add new --print-root-device option
We already have this nice code in system that determines the block
device backing the root file system, but it's only used internally in
systemd-gpt-generator. Let's make this more accessible and expose it
directly in bootctl.

It doesn't fit immediately into the topic of bootctl, but I think it's
close enough and behaves very similar to the existing "bootctl
--print-boot-path" and "--print-esp-path" tools.

If --print-root-device (or -R) is specified once, will show the block device
backing the root fs, and if specified twice (probably easier: -RR) it
will show the whole block device that block device belongs to in case it
is a partition block device.

Suggested use:

        # cfdisk `bootctl -RR`

To get access to the partition table, behind the OS install, for
whatever it might be.
2023-02-21 18:19:38 +01:00
Lennart Poettering 65046b92dc blockdev-util: add simple wrapper around BLKSSZGET
Just adds some typesafety and generates an error if the field is not
initialized in the block device yet.
2023-01-18 10:10:57 +01:00
Daan De Meyer 5228c58ebe dissect-image: Notify btrfs when we're done using a loop device
Let's explicitly let btrfs know when we're done using a loop device.
Otherwise, btrfs will keep the device UUID cached which will result
in mount() failures if we ever generate a device or filesystem with
the same UUID again.
2023-01-12 16:36:09 +01:00
Zbigniew Jędrzejewski-Szmek 254d1313ae tree-wide: use -EBADF for fd initialization
-1 was used everywhere, but -EBADF or -EBADFD started being used in various
places. Let's make things consistent in the new style.

Note that there are two candidates:
EBADF 9 Bad file descriptor
EBADFD 77 File descriptor in bad state

Since we're initializating the fd, we're just assigning a value that means
"no fd yet", so it's just a bad file descriptor, and the first errno fits
better. If instead we had a valid file descriptor that became invalid because
of some operation or state change, the other errno would fit better.

In some places, initialization is dropped if unnecessary.
2022-12-19 15:00:57 +01:00
Lennart Poettering 698bc1861e blockdev-util: move O_PATH fd conversion into btrfs_get_block_device_fd() to shorten things
And let's use a simple call to the new fd_reopen_condition() helper
there.
2022-11-29 15:34:27 +01:00
Yu Watanabe fd690a4b7f blockdev-util: introduce block_device_new_from_fd() and block_device_new_from_path()
These are possible replacements of get_block_device(),
get_block_device_harder(), path_get_whole_disk(), and friends.
2022-09-28 17:42:23 +09:00
Yu Watanabe 612fc70fc0 blockdev-util: re-implement block_get_originating() by using sd_device
And split out the core logic as block_device_get_originating().
Hopefully, this changes no behavior. Just refactoring and preparation
for later commits.
2022-09-28 17:41:09 +09:00
Yu Watanabe 446f8db66b blockdev-util: reopen file descriptor only when O_PATH is set
Prompted by 13879c54d4.
2022-09-28 17:41:09 +09:00
Yu Watanabe 7e4a0387c4 blockdev-util: split-out fd_get_devnum()
No functional changes, just preparation for later commits.
2022-09-28 17:41:09 +09:00
Lennart Poettering 13879c54d4 blockdev-util: make sure get_block_device_fd() works reliably for O_PATH, too 2022-09-20 13:52:01 +02:00
Yu Watanabe 2f9d231738 udev: use block_device_is_whole_disk()
No functional changes, just refactoring.

Note, this also makes synthesize_change() propagate the error from
synthesize_change_one(). However, the caller of synthesize_change()
ignores the failure anyway, hence the change does not take any effect.
2022-09-20 09:44:19 +02:00
Yu Watanabe 5a27af52c7 blockdev-util: change return value when a partition device is passed to partition_enumerator_new()
To make it consistent what returned by block_device_get_whole_disk().
2022-09-18 22:54:20 +09:00
Yu Watanabe 55a437f8b2 blockdev-util: introduce block_device_get_whole_disk() 2022-09-18 22:54:20 +09:00
Yu Watanabe c07186ec03 blockdev-util: split-out block_device_is_whole_disk()
No functional changes, just preparation for later commits.
2022-09-18 22:54:20 +09:00
Yu Watanabe 86f9b69a6a blockdev-util: split out blockdev_reread_partition_table()
No functional changes, just refactoring.
2022-09-10 01:19:41 +09:00
Yu Watanabe 9409174ee7 udevd: use partition enumerator at one more place
No functional changes, just refactoring.
2022-09-10 00:48:34 +09:00
Yu Watanabe 9cce72ee5d Merge pull request #24611 from yuwata/loop-util-refactoring
loop-util: several cleanups
2022-09-09 23:31:19 +09:00
Yu Watanabe e0993236d3 blockdevi-util: also check sysname when enumerating partitions 2022-09-09 22:30:19 +09:00
Yu Watanabe 833106b876 loop-util: do not try to enumerate partitions twice 2022-09-09 05:16:41 +09:00
Yu Watanabe aa0295f1d9 loop-util: move device_has_block_children() to blockdev-util.c
As the function is not only for loopback block device.

No actual code changes, just refactoring.
2022-09-07 20:45:24 +09:00
Yu Watanabe af15ee0368 blockdev-util: check if provided sd_device is for a whole block device
And split out partition_generator_new(), to make it usable in other
functions.
2022-09-07 20:45:24 +09:00
Yu Watanabe 46c3a28845 blockdev-util: make block_device_remove_all_partitions() take sd_device object
Then, it is not necessary to recreate sd_device object when we already
have.
2022-09-07 20:45:20 +09:00
Lennart Poettering 91e1ce1a7c loop-util: move resize partition ioctl call to blockdev-util.[ch]
The other BLKPG calls have wrappers in blockdev-util.[ch], let's place
them all there.

No change in behaviour.
2022-09-01 15:59:54 +02:00
Yu Watanabe ca8228295e tree-wide: use devpath_from_devnum() and device_open_from_devnum()
Fixes #24465.
2022-08-28 10:10:50 +09:00
Daan De Meyer 35d40302af blockdev-util: Add block_device_remove_all_partitions()
This function takes a block device, uses sd-device to iterate all
the partitions, and removes them one by one.
2022-08-03 20:55:32 +02:00
Daan De Meyer d25697f578 blockdev-util: Introduce block_device_add/remove_partition()
Extracted from dissect-image.c.
2022-08-03 20:55:29 +02:00
Daan De Meyer 26aa4800f8 blockdev-util: Introduce fd_get_whole_disk()
Extracted from find_devno() in udevadm-lock.c.
2022-08-03 20:55:00 +02:00
Lennart Poettering 7176f06c9e basic: split out dev_t related calls into new devno-util.[ch]
No actual code changes, just splitting out of some dev_t handling
related calls from stat-util.[ch], they are quite a number already, and
deserve their own module now I think.

Also, try to settle on the name "devnum" as the name for the concept,
instead of "devno" or "dev" or "devid". "devnum" is the name exported in
udev APIs, hence probably best to stick to that. (this just renames a
few symbols to "devum", local variables are left untouched, to make the
patch not too invasive)

No actual code changes.
2022-04-13 16:26:31 +02:00
Zbigniew Jędrzejewski-Szmek c7f0d9e5ac tree-wide: make FOREACH_DIRENT_ALL define the iterator variable
The variable is not useful outside of the loop (it'll always be null
after the loop is finished), so we can declare it inline in the loop.
This saves one variable declaration and reduces the chances that somebody
tries to use the variable outside of the loop.

For consistency, 'de' is used everywhere for the var name.
2021-12-15 16:19:13 +01:00
Lennart Poettering bcf8fc267f blockdev-util: add fd-based APIs for getting backing block device for file 2021-07-08 14:49:02 +02:00
Lennart Poettering 91358db9dc fs-util: add fd-based flavour of path_is_encrypted() 2021-07-08 09:29:33 +02:00
Lennart Poettering 0bfef8b46f blockdev-util: add fd-based flavour of get_block_device() 2021-07-08 09:29:18 +02:00
Zbigniew Jędrzejewski-Szmek b25a930f0e basic,shared: move a bunch of files to src/shared/
The goal is to move everything that requires selinux or smack
away from src/basic/. This means that src/basic/label.[ch] must move,
which implies btrfs-util.[ch], copy.[ch], and a bunch of other files
which form a cluster of internal use.

This is just moving text around, so there should be no functional difference.

test-blockdev-util is new, because path_is_encrypted() is moved to
blockdev-util.c, and so far we didn't have any tests for code there.
2021-06-24 10:11:00 +02:00