#include <string.h>
#include "alloc-util.h"
+#include "btrfs.h"
#include "chase.h"
#include "fd-util.h"
#include "format-util.h"
return mkdir_p_internal(prefix, path, mode, uid, gid, flags, mkdirat_errno_wrapper);
}
-int mkdir_p_root(const char *root, const char *p, uid_t uid, gid_t gid, mode_t m) {
+int mkdir_p_root(const char *root, const char *p, uid_t uid, gid_t gid, mode_t m, char **subvolumes) {
_cleanup_free_ char *pp = NULL, *bn = NULL;
_cleanup_close_ int dfd = -EBADF;
int r;
return r;
else {
/* Extracting the parent dir worked, hence we aren't top-level? Recurse up first. */
- r = mkdir_p_root(root, pp, uid, gid, m);
+ r = mkdir_p_root(root, pp, uid, gid, m, subvolumes);
if (r < 0)
return r;
if (r < 0)
return r;
- if (mkdirat(dfd, bn, m) < 0) {
- if (errno == EEXIST)
+ if (path_strv_contains(subvolumes, p))
+ r = btrfs_subvol_make_fallback(dfd, bn, m);
+ else
+ r = RET_NERRNO(mkdirat(dfd, bn, m));
+ if (r < 0) {
+ if (r == -EEXIST)
return 0;
- return -errno;
+ return r;
}
if (uid_is_valid(uid) || gid_is_valid(gid)) {
int mkdir_parents_safe(const char *prefix, const char *path, mode_t mode, uid_t uid, gid_t gid, MkdirFlags flags);
int mkdir_p(const char *path, mode_t mode);
int mkdir_p_safe(const char *prefix, const char *path, mode_t mode, uid_t uid, gid_t gid, MkdirFlags flags);
-int mkdir_p_root(const char *root, const char *p, uid_t uid, gid_t gid, mode_t m);
+int mkdir_p_root(const char *root, const char *p, uid_t uid, gid_t gid, mode_t m, char **subvolumes);
/* The following are used to implement the mkdir_xyz_label() calls, don't use otherwise. */
typedef int (*mkdirat_func_t)(int dir_fd, const char *pathname, mode_t mode);
if (r < 0)
return log_error_errno(r, "Failed to extract directory from '%s': %m", *target);
- r = mkdir_p_root(root, dn, UID_INVALID, GID_INVALID, 0755);
+ r = mkdir_p_root(root, dn, UID_INVALID, GID_INVALID, 0755, NULL);
if (r < 0)
return log_error_errno(r, "Failed to create parent directory '%s': %m", dn);
if (r < 0)
return log_error_errno(r, "Failed to extract directory from '%s': %m", *target);
- r = mkdir_p_root(root, dn, UID_INVALID, GID_INVALID, 0755);
+ r = mkdir_p_root(root, dn, UID_INVALID, GID_INVALID, 0755, NULL);
if (r < 0)
return log_error_errno(r, "Failed to create parent directory: %m");
STRV_FOREACH(d, p->make_directories) {
- r = mkdir_p_root(root, *d, UID_INVALID, GID_INVALID, 0755);
+ r = mkdir_p_root(root, *d, UID_INVALID, GID_INVALID, 0755, NULL);
if (r < 0)
return log_error_errno(r, "Failed to create directory '%s' in file system: %m", *d);
}
if (directory) {
/* Automatically create missing mount points inside the image, if necessary. */
- r = mkdir_p_root(where, directory, uid_shift, (gid_t) uid_shift, 0755);
+ r = mkdir_p_root(where, directory, uid_shift, (gid_t) uid_shift, 0755, NULL);
if (r < 0 && r != -EROFS)
return r;
assert_se(mkdtemp_malloc("/tmp/test-mkdir-XXXXXX", &tmp) >= 0);
assert_se(p = path_join(tmp, "run/aaa/bbb"));
- assert_se(mkdir_p_root(tmp, "/run/aaa/bbb", UID_INVALID, GID_INVALID, 0755) >= 0);
+ assert_se(mkdir_p_root(tmp, "/run/aaa/bbb", UID_INVALID, GID_INVALID, 0755, NULL) >= 0);
assert_se(is_dir(p, false) > 0);
assert_se(is_dir(p, true) > 0);
p = mfree(p);
assert_se(p = path_join(tmp, "var/run/hoge/foo/baz"));
- assert_se(mkdir_p_root(tmp, "/var/run/hoge/foo/baz", UID_INVALID, GID_INVALID, 0755) >= 0);
+ assert_se(mkdir_p_root(tmp, "/var/run/hoge/foo/baz", UID_INVALID, GID_INVALID, 0755, NULL) >= 0);
assert_se(is_dir(p, false) > 0);
assert_se(is_dir(p, true) > 0);
p = mfree(p);
assert_se(p = path_join(tmp, "not-exists"));
- assert_se(mkdir_p_root(p, "/aaa", UID_INVALID, GID_INVALID, 0755) == -ENOENT);
+ assert_se(mkdir_p_root(p, "/aaa", UID_INVALID, GID_INVALID, 0755, NULL) == -ENOENT);
p = mfree(p);
assert_se(p = path_join(tmp, "regular-file"));
assert_se(touch(p) >= 0);
- assert_se(mkdir_p_root(p, "/aaa", UID_INVALID, GID_INVALID, 0755) == -ENOTDIR);
+ assert_se(mkdir_p_root(p, "/aaa", UID_INVALID, GID_INVALID, 0755, NULL) == -ENOTDIR);
/* FIXME: The tests below do not work.
p = mfree(p);