This way callers can choose if they want partition scanning or not.
/* SPDX-License-Identifier: LGPL-2.1+ */
#include <errno.h>
+#include <linux/loop.h>
#include <sched.h>
#include <stdio.h>
#include <sys/mount.h>
r = loop_device_make_by_path(root_image,
dissect_image_flags & DISSECT_IMAGE_READ_ONLY ? O_RDONLY : O_RDWR,
+ LO_FLAGS_PARTSCAN,
&loop_device);
if (r < 0)
return log_debug_errno(r, "Failed to create loop device for root image: %m");
/* SPDX-License-Identifier: LGPL-2.1+ */
#include <fcntl.h>
-#include <stdio.h>
#include <getopt.h>
+#include <linux/loop.h>
+#include <stdio.h>
#include "architecture.h"
#include "dissect-image.h"
if (r <= 0)
return r;
- r = loop_device_make_by_path(arg_image, (arg_flags & DISSECT_IMAGE_READ_ONLY) ? O_RDONLY : O_RDWR, &d);
+ r = loop_device_make_by_path(arg_image, (arg_flags & DISSECT_IMAGE_READ_ONLY) ? O_RDONLY : O_RDWR, LO_FLAGS_PARTSCAN, &d);
if (r < 0)
return log_error_errno(r, "Failed to set up loopback device: %m");
goto finish;
}
- r = loop_device_make_by_path(arg_image, arg_read_only ? O_RDONLY : O_RDWR, &loop);
+ r = loop_device_make_by_path(arg_image, arg_read_only ? O_RDONLY : O_RDWR, LO_FLAGS_PARTSCAN, &loop);
if (r < 0) {
log_error_errno(r, "Failed to set up loopback block device: %m");
goto finish;
/* SPDX-License-Identifier: LGPL-2.1+ */
+#include <linux/loop.h>
+
#include "bus-common-errors.h"
#include "bus-error.h"
#include "conf-files.h"
assert(path);
- r = loop_device_make_by_path(path, O_RDONLY, &d);
+ r = loop_device_make_by_path(path, O_RDONLY, LO_FLAGS_PARTSCAN, &d);
if (r == -EISDIR) {
/* We can't turn this into a loop-back block device, and this returns EISDIR? Then this is a directory
* tree and not a raw device. It's easy then. */
#include "loop-util.h"
#include "stat-util.h"
-int loop_device_make(int fd, int open_flags, LoopDevice **ret) {
+int loop_device_make(int fd, int open_flags, uint32_t loop_flags, LoopDevice **ret) {
const struct loop_info64 info = {
- .lo_flags = LO_FLAGS_AUTOCLEAR|LO_FLAGS_PARTSCAN|(open_flags == O_RDONLY ? LO_FLAGS_READ_ONLY : 0),
+ /* Use the specified flags, but configure the read-only flag from the open flags, and force autoclear */
+ .lo_flags = (loop_flags & ~LO_FLAGS_READ_ONLY) | ((loop_flags & O_ACCMODE) == O_RDONLY ? LO_FLAGS_READ_ONLY : 0) | LO_FLAGS_AUTOCLEAR,
};
_cleanup_close_ int control = -1, loop = -1;
return d->fd;
}
-int loop_device_make_by_path(const char *path, int open_flags, LoopDevice **ret) {
+int loop_device_make_by_path(const char *path, int open_flags, uint32_t loop_flags, LoopDevice **ret) {
_cleanup_close_ int fd = -1;
assert(path);
if (fd < 0)
return -errno;
- return loop_device_make(fd, open_flags, ret);
+ return loop_device_make(fd, open_flags, loop_flags, ret);
}
LoopDevice* loop_device_unref(LoopDevice *d) {
bool relinquished;
};
-int loop_device_make(int fd, int open_flags, LoopDevice **ret);
-int loop_device_make_by_path(const char *path, int open_flags, LoopDevice **ret);
+int loop_device_make(int fd, int open_flags, uint32_t loop_flags, LoopDevice **ret);
+int loop_device_make_by_path(const char *path, int open_flags, uint32_t loop_flags, LoopDevice **ret);
LoopDevice* loop_device_unref(LoopDevice *d);
DEFINE_TRIVIAL_CLEANUP_FUNC(LoopDevice*, loop_device_unref);
#include <errno.h>
#include <fcntl.h>
+#include <linux/fs.h>
+#include <linux/loop.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/file.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <unistd.h>
-#include <linux/fs.h>
#include "alloc-util.h"
#include "btrfs-util.h"
_cleanup_(loop_device_unrefp) LoopDevice *d = NULL;
_cleanup_(dissected_image_unrefp) DissectedImage *m = NULL;
- r = loop_device_make_by_path(i->path, O_RDONLY, &d);
+ r = loop_device_make_by_path(i->path, O_RDONLY, LO_FLAGS_PARTSCAN, &d);
if (r < 0)
return r;
/* SPDX-License-Identifier: LGPL-2.1+ */
#include <fcntl.h>
+#include <linux/loop.h>
#include <stdio.h>
#include "dissect-image.h"
return EXIT_FAILURE;
}
- r = loop_device_make_by_path(argv[1], O_RDONLY, &d);
+ r = loop_device_make_by_path(argv[1], O_RDONLY, LO_FLAGS_PARTSCAN, &d);
if (r < 0) {
log_error_errno(r, "Failed to set up loopback device: %m");
return EXIT_FAILURE;