dissect-image: Return mount point fd if requested

This commit is contained in:
Daan De Meyer
2022-12-22 13:00:31 +01:00
parent 6aa90884a0
commit a133d2c366
13 changed files with 23 additions and 1 deletions

View File

@@ -625,6 +625,7 @@ static int run(int argc, char *argv[]) {
DISSECT_IMAGE_RELAX_VAR_CHECK |
DISSECT_IMAGE_READ_ONLY,
&unlink_dir,
/* ret_dir_fd= */ NULL,
&loop_device);
if (r < 0)
return r;

View File

@@ -467,6 +467,7 @@ static int run(int argc, char *argv[]) {
DISSECT_IMAGE_GENERIC_ROOT |
DISSECT_IMAGE_RELAX_VAR_CHECK,
&unlink_dir,
/* ret_dir_fd= */ NULL,
&loop_device);
if (r < 0)
return r;

View File

@@ -1366,6 +1366,7 @@ static int run(int argc, char *argv[]) {
DISSECT_IMAGE_RELAX_VAR_CHECK |
DISSECT_IMAGE_VALIDATE_OS,
&mounted_dir,
/* ret_dir_fd= */ NULL,
&loop_device);
if (r < 0)
return r;

View File

@@ -1389,6 +1389,7 @@ static int run(int argc, char *argv[]) {
DISSECT_IMAGE_FSCK |
DISSECT_IMAGE_GROWFS,
&unlink_dir,
/* ret_dir_fd= */ NULL,
&loop_device);
if (r < 0)
return r;

View File

@@ -2125,6 +2125,7 @@ static int run(int argc, char *argv[]) {
DISSECT_IMAGE_RELAX_VAR_CHECK |
(arg_action == ACTION_UPDATE_CATALOG ? DISSECT_IMAGE_FSCK|DISSECT_IMAGE_GROWFS : DISSECT_IMAGE_READ_ONLY),
&unlink_dir,
/* ret_dir_fd= */ NULL,
&loop_device);
if (r < 0)
return r;

View File

@@ -147,6 +147,7 @@ static int run(int argc, char *argv[]) {
DISSECT_IMAGE_FSCK |
DISSECT_IMAGE_GROWFS,
&unlink_dir,
/* ret_dir_fd= */ NULL,
&loop_device);
if (r < 0)
return r;

View File

@@ -6429,6 +6429,7 @@ static int run(int argc, char *argv[]) {
DISSECT_IMAGE_USR_NO_ROOT |
DISSECT_IMAGE_REQUIRE_ROOT,
&mounted_dir,
/* ret_dir_fd= */ NULL,
&loop_device);
if (r < 0)
return r;

View File

@@ -3315,6 +3315,7 @@ int mount_image_privately_interactively(
const char *image,
DissectImageFlags flags,
char **ret_directory,
int *ret_dir_fd,
LoopDevice **ret_loop_device) {
_cleanup_(verity_settings_done) VeritySettings verity = VERITY_SETTINGS_DEFAULT;
@@ -3388,6 +3389,16 @@ int mount_image_privately_interactively(
if (r < 0)
return log_error_errno(r, "Failed to relinquish DM and loopback block devices: %m");
if (ret_dir_fd) {
_cleanup_close_ int dir_fd = -EBADF;
dir_fd = open(created_dir, O_CLOEXEC|O_DIRECTORY);
if (dir_fd < 0)
return log_error_errno(errno, "Failed to open mount point directory: %m");
*ret_dir_fd = TAKE_FD(dir_fd);
}
*ret_directory = TAKE_PTR(created_dir);
*ret_loop_device = TAKE_PTR(d);

View File

@@ -183,7 +183,7 @@ bool dissected_image_verity_candidate(const DissectedImage *image, PartitionDesi
bool dissected_image_verity_ready(const DissectedImage *image, PartitionDesignator d);
bool dissected_image_verity_sig_ready(const DissectedImage *image, PartitionDesignator d);
int mount_image_privately_interactively(const char *path, DissectImageFlags flags, char **ret_directory, LoopDevice **ret_loop_device);
int mount_image_privately_interactively(const char *path, DissectImageFlags flags, char **ret_directory, int *ret_dir_fd, LoopDevice **ret_loop_device);
int verity_dissect_and_mount(int src_fd, const char *src, const char *dest, const MountOptions *options, const char *required_host_os_release_id, const char *required_host_os_release_version_id, const char *required_host_os_release_sysext_level, const char *required_sysext_scope);

View File

@@ -1222,6 +1222,7 @@ static int run(int argc, char *argv[]) {
DISSECT_IMAGE_RELAX_VAR_CHECK |
DISSECT_IMAGE_VALIDATE_OS,
&mounted_dir,
/* ret_dir_fd= */ NULL,
&loop_device);
if (r < 0)
return r;

View File

@@ -881,6 +881,7 @@ static int process_image(
DISSECT_IMAGE_GENERIC_ROOT |
DISSECT_IMAGE_REQUIRE_ROOT,
&mounted_dir,
/* ret_dir_fd= */ NULL,
&loop_device);
if (r < 0)
return r;

View File

@@ -2180,6 +2180,7 @@ static int run(int argc, char *argv[]) {
DISSECT_IMAGE_FSCK |
DISSECT_IMAGE_GROWFS,
&unlink_dir,
/* ret_dir_fd= */ NULL,
&loop_device);
if (r < 0)
return r;

View File

@@ -4142,6 +4142,7 @@ static int run(int argc, char *argv[]) {
DISSECT_IMAGE_FSCK |
DISSECT_IMAGE_GROWFS,
&unlink_dir,
/* ret_dir_fd= */ NULL,
&loop_device);
if (r < 0)
return r;