Commit Graph
130 Commits
Author SHA1 Message Date
Luca Boccassi 8dcfecc833 Merge pull request #26410 from DaanDeMeyer/xattr-symlink
Copy symlink xattrs
2023-02-15 19:55:04 +00:00
Yu Watanabe 0b75493da0 tree-wide: fix typo and comment style update 2023-02-15 10:08:16 +09:00
Daan De Meyer c17cfe6ef7 copy: Make copy_xattr() more generic
Let's make copy_xattr() a little more generic in preparation for
copying symlink xattrs.
2023-02-14 12:51:40 +01:00
Lennart Poettering 1d93c00386 dissect: show sector size in info output 2023-01-18 10:47:17 +01:00
Lennart Poettering 22ee78a898 loop-util: always tell kernel explicitly about loopback sector size
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.
2023-01-18 10:47:17 +01:00
Yu Watanabe 01a33cf7e8 dissect: reduce indent in mtree_print_item() 2022-12-26 16:42:29 +09:00
Yu Watanabe 5ffa6a0af4 dissect: do not trigger assertion on error
recurse_dir() does not provide 'sx' on error.

Fixes #25862.
2022-12-26 16:42:29 +09:00
Yu Watanabe 167f2c1a2b dissect: use assert() when no side effect 2022-12-26 16:42:29 +09:00
Lennart Poettering 83802e9abd dissect: remove one more use of basename()
And while we are at it, make use of path_extract_filename() return value
that indicates whether the path was suffixed with a slash.
2022-12-23 15:04:19 +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 6c07d57075 dissect: add a mode for operating on an in-memory copy of a DDI, instead of directly on it
This is useful for operating in ephemeral, writable mode on any image,
including read-only ones. It also has the benefit of not keeping the
image file's filesystem busy.

Inspired by the discussions in #25648
2022-12-08 12:48:06 +01:00
Lennart Poettering 0305cf6e9d dissect: add simple --discover command 2022-12-07 17:57:22 +01:00
Lennart Poettering 5acb31a683 dissect: show color in log output 2022-12-06 12:25:00 +09:00
Yu Watanabe 41a95b18bd dissect: support to unmount image without root partition
Fixes #25480.
2022-12-02 02:58:44 +09:00
Yu Watanabe 040d343903 dissect: use sd-device to find and open loopback block device 2022-12-02 02:52:06 +09:00
Lennart Poettering 73d88b806b dissect: rework DISSECT_IMAGE_ADD_PARTITION_DEVICES + DISSECT_IMAGE_OPEN_PARTITION_DEVICES
Curently, these two flags were implied by dissect_loop_device(), but
that's not right, because this means systemd-gpt-auto-generator will
dissect the root block device with these flags set and that's not
desirable: the generator should not cause the partition devices to be
created (we don't intend to use them right-away after all, but expect
udev to find/probe them first, and then mount them though .mount units).
And there's no point in opening the partition devices, since we do not
intend to mount them via fds either.

Hence, rework this: instead of implying the flags, specify them
explicitly.

While we are at it, let's also rename the flags to make them more
descriptive:

DISSECT_IMAGE_MANAGE_PARTITION_DEVICES becomes
DISSECT_IMAGE_ADD_PARTITION_DEVICES, since that's really all this does:
add the partition devices via BLKPG.

DISSECT_IMAGE_OPEN_PARTITION_DEVICES becomes
DISSECT_IMAGE_PIN_PARTITION_DEVICES, since we not only open the devices,
but keep the devices open continously (i.e. we "pin" them).

Also, drop the DISSECT_IMAGE_BLOCK_DEVICE combination flag, since it is
misleading, i.e. it suggests it was appropriate to specify on all
dissected blocking devices, but that's precisely not the case, see the
systemd-gpt-auto-generator case. My guess is that the confusion around
this was actually the cause for this bug we are addressing here.

Fixes: #25528
2022-12-01 11:32:30 +01:00
Daan De Meyer 46fddd8eb6 Merge pull request #24803 from DaanDeMeyer/repart-copy-deny-list
repart: Don't descend into directories assigned to other partitions
2022-11-11 13:19:58 +01:00
Daan De Meyer a424958aa6 copy: Support passing a deny list of files/directories to not copy 2022-11-10 16:40:31 +01:00
Lennart Poettering 5db8b0bcad dissect: make image name bold 2022-11-10 16:00:59 +01:00
Lennart Poettering b387778c5b dissect: also parse out the top-level GPT table uuid and expose this as image UUID
systemd-repart generates this in a suitably stable fashion, hence let's
actually use it as an identifier for the image. As a first step parse
it, and show it.
2022-11-10 16:00:59 +01:00
Lennart Poettering db02190eec dissect: add a new "--mtree" switch for generating a BSD mtree(5) compatible file manifest 2022-11-09 22:20:51 +01:00
Lennart Poettering 06186c4c99 dissect: add new --with command 2022-11-09 14:57:23 +01:00
Lennart Poettering fab2294646 dissect: officially support initrd DDIs (to implement 2nd stage initrds)
Let's complete support for DDI discovery, and also support 2nd stage
initrds.
2022-11-09 14:43:55 +01:00
Lennart Poettering 2e1f76f6ea dissect: open pager in --list mode, output might be long 2022-11-09 11:52:50 +01:00
Lennart Poettering a245225e2d dissect: simplify flags for recurse_dir()
We are not interested in the struct dirent data, hence there's no point
in passing RECURSE_DIR_ENSURE_TYPE. Let's drop it, and thus avoid some
extrac work on file systems where readdir() does not report .d_type.

Also drop RECURSE_DIR_SAME_MOUNT, because DDIs after all may contain
multiple partitions, and we mount them all together. The --list command
really should report the full set of files in an image.
2022-11-09 11:44:17 +01:00
Lennart Poettering 0f01320ec7 dissect: remove unused variable 2022-11-09 11:41:38 +01:00
Yu Watanabe bf18862267 Merge pull request #25291 from keszybz/util-cleanup
Split/rename util.c+h and def.h
2022-11-09 09:23:17 +09:00
Lennart Poettering bb69ec9507 dissect: grey out trailing slash in --list output
Given this is just auxiliary info, let's make it a tiny bit less visible
then the main part of the path.
2022-11-08 21:35:34 +01:00
Zbigniew Jędrzejewski-Szmek d6b4d1c7c4 basic: move version() to build.h+c 2022-11-08 13:41:14 +01:00
Lennart Poettering cfb623b6e7 dissect: get rid of basename() use 2022-11-05 19:18:39 +01:00
Antonio Alvarez Feijoo 0cf1692493 dissect: add --list option
New option to print the paths of all the files and directories in the image to
stdout.
2022-10-31 21:11:09 +01:00
Lennart Poettering a94a199cff dissect: mention DDI moniker in --help text 2022-10-25 18:57:59 +02:00
Antonio Alvarez Feijoo 1b967529d2 dissect: add missing --umount to the help output 2022-10-19 14:42:42 +02:00
Yu Watanabe de3b7f168e loop-util: rename loop_device_open() -> loop_device_open_from_path()
No functional changes, just preparation for later commits.
2022-09-28 17:42:37 +09:00
Daan De Meyer 738edfe667 dissect: Log when we fail to load the verity signature partition 2022-09-23 12:24:09 +02:00
Lennart Poettering add0c9b8bf Merge pull request #24768 from keszybz/table-not-available-2
Adjust table n/a text in more places
2022-09-22 14:17:40 +02:00
Zbigniew Jędrzejewski-Szmek c8b62cf600 shared/format-table: use enum instead of Table.empty_string
All users were setting this to some static string (usually "-"), so let's
simplify things by not doing strdup, but instead limiting callers to a fixed
set of values. In preparation for the next commit, the function is renamed from
"empty" to "replacement", because it'll be used for more than empty fields. I
didn't do the whole string-table setup, because it's all used internally in one
file and this way we can immediately assert if an invalid value is passed in.

Some callers were (void)ing the error, others were ignoring it, and others
propagating. It's nicer to remove the boilerplate.
2022-09-22 10:16:05 +02:00
Yu Watanabe e330f97a89 tree-wide: drop unused reference to DecryptedImage 2022-09-18 23:47:20 +09:00
Yu Watanabe 3044d343dd tree-wide: use dissected_image_relinquish() 2022-09-18 23:47:20 +09:00
Yu Watanabe 64dd3a245f dissect-image: use loop backing file or device node as name of the image
Note, currently, for each call of dissect_loop_device_and_warn(), the
specified name is equivalent to the path passed to loop_device_make_by_path().
Hence, this should not change the current behavios.
2022-09-07 20:45:24 +09:00
Yu Watanabe bad31660ed dissect-image: introduce dissect_loop_device() which takes LoopDevice object 2022-09-03 01:32:01 +09:00
Yu Watanabe 4fe46c349d sd-device: rename devpath_from_devnum() -> devname_from_devnum()
In sd-device, `devpath` is a kind of syspath without '/sys' prefix, e.g.
/devices/pci0000:00/0000:00:1c.4/0000:3c:00.0/nvme/nvme0/nvme0n1,
and `devname` is a path to the device node, e.g. /dev/nvme0n1.

Let's use the consistent name for the helper function.
2022-09-03 00:42:31 +09:00
Lennart Poettering 7f52206a2b loop-util: rework how we lock loopback block devices
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.
2022-09-01 22:05:32 +02:00
Lennart Poettering 234c2e16e5 dissect: drop partition removal code
This reverts a major chunk of 75d7e04eb4

Now that the loopback device code already destroys the partitions we
don't have to do this here anymore.

I am sure the right place to delete the partitions is in the loopback
code, since we really only should do that for loopback devices, see
bug #24431, and not on "real" block devices.

I am also not convinced dropping partitions the dissection logic doesn't
care about is a good idea, after all. The dissection stuff should
probably not consider itself the "owner" of the block devices it
analyzes, but take a more passive role: figure out what is what, but not
modify it.

Fixes: #24431
2022-09-01 22:05:10 +02:00
Lennart Poettering e8383058b2 dissect: don't remove partitions explicitly on umount anymore
We do that now automatically when releasing the loopback device, hence
we can drop the redundant try entirely.
2022-09-01 20:42:17 +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
Lennart Poettering 45519d13a4 tree-wide: port things dirname_malloc() → path_extract_directory() 2022-08-23 15:10:15 +02:00
Daan De Meyer ac1f1adfc6 dissect: Add systemd-dissect --umount
This command takes a mountpoint, unmounts it and makes sure the
underlying partition devices and block device are removed before
exiting.

To mirror the --mount operation, we also add a --rmdir option which
does the opposite of --mkdir, and a -U option which is a shortcut
for --umount --rmdir.
2022-08-03 20:55:32 +02:00
Pavel Zhukov 19df770fe1 Add sys/file.h for LOCK_
Fixes build with musl:
| ../git/src/shared/dissect-image.c: In function 'mount_image_privately_interactively':
| ../git/src/shared/dissect-image.c:2986:34: error: 'LOCK_SH' undeclared (first use in this function)
|  2986 |         r = loop_device_flock(d, LOCK_SH);
|       |                                  ^~~~~~~
2022-06-21 16:07:58 +01:00
Daan De Meyer 75d7e04eb4 dissect-image: Explicitly remove partitions when done with image
When closing a loop device, the kernel will asynchronously remove
the probed partitions. This can lead to race conditions where we
try to reuse a partition device that still needs to be removed by
the kernel. To avoid such issues, let's explicitly try to remove
any partitions using BLKPG_DEL_PARTITION when we're done with an
image.

To make sure we don't try to remove partitions when we want them
to remain (e.g. systemd-dissect --mount), we add
dissected_image_relinquish() in a similar vein to loop_device_relinquish()
and decrypted_image_relinquish().
2022-05-23 18:15:16 +01:00