summaryrefslogtreecommitdiff
path: root/src/shared/loop-util.h
Commit message (Collapse)AuthorAgeFilesLines
* loop-util: Add loop_device_make_by_path_at()Daan De Meyer2023-03-231-1/+6
| | | | | | | On top of taking a directory file descriptor, we use xopenat() so that the function can also be used to work on existing file descriptors to image files including all the logic to use O_DIRECT and fallback to O_RDONLY if needed.
* loop-util: add API for selecting "lo_file_name" field for a loopback deviceLennart Poettering2023-03-091-0/+1
|
* loop-util: add call for setting the autoclear flag at arbitrary timesLennart Poettering2023-03-091-0/+2
|
* loop-util: keep track of inode/devnum of backing fileLennart Poettering2023-03-091-2/+4
|
* loop-util: always tell kernel explicitly about loopback sector sizeLennart Poettering2023-01-181-3/+4
| | | | | | Let's not leave the sector size unspecified: either set a user supplied value, or auto-detect the right size by probing the disk image accordingly.
* loop-util: add new loop_device_make_by_path_memory() helperLennart Poettering2022-12-081-0/+1
| | | | | This uses the new memfd_clone_fd() call to make an in-memory copy of some file before setting up a loopback block device on it.
* Implement --luks-sector-size for homedAidan Dang2022-10-071-1/+1
|
* loop-util: re-introduce loop_device_open() which takes sd_device objectYu Watanabe2022-09-281-7/+3
| | | | | | Then, this makes loop_device_open_from_fd() or _from_path() be wrappers of loop_device_open() with block_device_new_from_fd() or _from_path(), respectively.
* loop-util: rename loop_device_open() -> loop_device_open_from_path()Yu Watanabe2022-09-281-2/+5
| | | | No functional changes, just preparation for later commits.
* loop-util: introduce reference counter for LoopDeviceYu Watanabe2022-09-181-0/+2
|
* loop-util: save backing file of loopback block deviceYu Watanabe2022-09-071-0/+1
| | | | It will be used in later commits.
* loop-util: store sd_device object for the loop deviceYu Watanabe2022-09-061-0/+3
| | | | It will be used in later commits.
* loop-util: introduce loop_device_open_full()Yu Watanabe2022-09-051-1/+4
|
* loop-util: make clearer how LoopDevice objects that do not encapsulate an ↵Lennart Poettering2022-09-011-1/+4
| | | | actual loopback device are set up
* loop-util: rework how we lock loopback block devicesLennart Poettering2022-09-011-3/+4
| | | | | | | | | | | | | | | | | | | | Let's rework how we lock loopback block devices in two ways: 1. Lock a separate fd, instead of the main block device fd. We already did that for our internal locking when allocating loopback block devices, but do so for the exposed locking (i.e. loop_device_flock()), too, so that the lock is independent of the main fd we actually use of IO. 2. Instead of locking the device during allocation of the loopback device, then unlocking it (which will make udev run), and then re-locking things if we need, let's instead just keep the lock the whole time, to make things a bit safer and faster, and not have to wait for udev at all. This is done by adding a "lock_op" parameter to loop device allocation functions that declares the initial state of the lock, and is one of LOCK_UN/LOCK_SH/LOCK_EX. This change also shortens a lot of code, since we allocate + immediately lock loopback devices pretty much everywhere.
* loop-util: Add loop_device_unrelinquish()Daan De Meyer2022-08-031-0/+1
| | | | | Allows taking ownership of a loop device which makes sure that loop_device_unrefp() will try to destroy it when it runs.
* loop: parse and store disk sequence numberLuca Boccassi2021-07-281-0/+1
| | | | | | | When loop devices are re-used, the disk sequence number is increased. Parse it when creating a loop device and store it. The kernel will never return DISKSEQ=0, so use it to signal that it's not supported by the current kernel.
* loop-util: track CLOCK_MONOTONIC timestamp immediately before attaching a ↵Lennart Poettering2021-04-201-0/+2
| | | | | | | | | | | | | | | | | | | loopback device This is similar to the preceding work to store the uevent seqnum, but this stores the CLOCK_MONOTONIC timestamp. Why? This allows to validate udev database entries, to determine if they were created *after* we attached the device. The uevent seqnum logic allows us to validate uevent, and the timestamp database entries, hence together we should be able to validate both sources of truth for us. (note that this is all racy, just a bit less racy, since we cannot atomically attach loopback devices and get the timestamp for it, the same way we can't get the uevent seqnum. Thus is shortens the race window, but doesn#t close it).
* loop-util: read kernel's uevent seqnum right before attaching a loopback deviceLennart Poettering2021-04-201-0/+1
| | | | | | | | Later, this will allow us to ignore uevents from earlier attachments a bit better, as we can compare uevent seqnums with this boundary. It's not a full fix for the race though, since we cannot atomically determine the uevent and attach the device, but it at least shortens the window a bit.
* loop-util: store device major/minor in LoopDevice objectLennart Poettering2021-04-191-0/+1
| | | | | Let's store this away. It's useful when matching up mounts (i.e. struct stat's .st_dev field) with loopback devices.
* license: LGPL-2.1+ -> LGPL-2.1-or-laterYu Watanabe2020-11-091-1/+1
|
* loop-util: define API for syncing loopback deviceLennart Poettering2020-08-241-0/+1
|
* shared/loop-util: rename functionZbigniew Jędrzejewski-Szmek2019-12-181-1/+1
| | | | As suggested in https://github.com/systemd/systemd/pull/14261#pullrequestreview-332398625.
* shared/loop-util: drop inline function with one useZbigniew Jędrzejewski-Szmek2019-12-061-4/+0
|
* loop-util: add api for locking the block device with flock()Lennart Poettering2019-12-021-0/+2
|
* loop-util: allow refreshing offsetLennart Poettering2019-12-021-1/+1
|
* loop-util: allow creating loopback block devices with offset/lengthLennart Poettering2019-12-021-1/+5
|
* loop-util: add API to refresh loopback device size and opening existing ↵Lennart Poettering2019-12-021-0/+3
| | | | loopback block devices
* loop-util: accept loopback flags when creating loopback deviceLennart Poettering2019-12-021-2/+2
| | | | This way callers can choose if they want partition scanning or not.
* tree-wide: remove Lennart's copyright linesLennart Poettering2018-06-141-4/+0
| | | | | | | | | | | These lines are generally out-of-date, incomplete and unnecessary. With SPDX and git repository much more accurate and fine grained information about licensing and authorship is available, hence let's drop the per-file copyright notice. Of course, removing copyright lines of others is problematic, hence this commit only removes my own lines and leaves all others untouched. It might be nicer if sooner or later those could go away too, making git the only and accurate source of authorship information.
* tree-wide: drop 'This file is part of systemd' blurbLennart Poettering2018-06-141-2/+0
| | | | | | | | | | | | | | | | This part of the copyright blurb stems from the GPL use recommendations: https://www.gnu.org/licenses/gpl-howto.en.html The concept appears to originate in times where version control was per file, instead of per tree, and was a way to glue the files together. Ultimately, we nowadays don't live in that world anymore, and this information is entirely useless anyway, as people are very welcome to copy these files into any projects they like, and they shouldn't have to change bits that are part of our copyright header for that. hence, let's just get rid of this old cruft, and shorten our codebase a bit.
* tree-wide: drop license boilerplateZbigniew Jędrzejewski-Szmek2018-04-061-13/+0
| | | | | | | | | | Files which are installed as-is (any .service and other unit files, .conf files, .policy files, etc), are left as is. My assumption is that SPDX identifiers are not yet that well known, so it's better to retain the extended header to avoid any doubt. I also kept any copyright lines. We can probably remove them, but it'd nice to obtain explicit acks from all involved authors before doing that.
* Add SPDX license identifiers to source files under the LGPLZbigniew Jędrzejewski-Szmek2017-11-191-0/+1
| | | | | This follows what the kernel is doing, c.f. https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=5fd54ace4721fc5ce2bb5aef6318fcf17f421460.
* dissect: add small "systemd-dissect" tool as wrapper around dissect-image.cLennart Poettering2016-12-071-1/+3
| | | | | | | | | | | This adds a small tool that may be used to look into OS images, and mount them to any place. This is mostly a friendlier version of test-dissect-image.c. I am not sure this should really become a proper command of systemd, hence for now do not install it into bindir, but simply libexecdir. This tool is already pretty useful since you can mount image files with it, honouring the various partitions correctly. I figure this is going to become more interesting if the dissctor learns luks and verity support.
* util-lib: split out image dissecting code and loopback code from nspawnLennart Poettering2016-12-071-0/+39
This adds two new APIs to systemd: - loop-util.h is a simple internal API for allocating, setting up and releasing loopback block devices. - dissect-image.h is an internal API for taking apart disk images and figuring out what the purpose of each partition is. Both APIs are basically refactored versions of similar code in nspawn. This rework should permit us to reuse this in other places than just nspawn in the future. Specifically: to implement RootImage= in the service image, similar to RootDirectory=, but operating on a disk image; to unify the gpt-auto-discovery generator code with the discovery logic in nspawn; to add new API to machined for determining the OS version of a disk image (i.e. not just running containers). This PR does not make any such changes however, it just provides the new reworked API. The reworked code is also slightly more powerful than the nspawn original one. When pointing it to an image or block device with a naked file system (i.e. no partition table) it will simply make it the root device.