]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
fs-util: Add XO_SUBVOLUME flag for xopenat()
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Mon, 14 Aug 2023 13:32:22 +0000 (15:32 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Mon, 14 Aug 2023 16:46:08 +0000 (18:46 +0200)
When specified, xopenat() will try to create a btrfs subvolume and
fall back to creating a regular directory.

src/basic/fs-util.c
src/basic/fs-util.h

index 804440ef2a5b1f90a5d2da021f0b839759ec60e6..a9336f1a67587dccd14de607b23498aab9d51031 100644 (file)
@@ -9,6 +9,7 @@
 #include <unistd.h>
 
 #include "alloc-util.h"
+#include "btrfs.h"
 #include "dirent-util.h"
 #include "fd-util.h"
 #include "fileio.h"
@@ -1110,7 +1111,10 @@ int xopenat(int dir_fd, const char *path, int open_flags, XOpenFlags xopen_flags
         }
 
         if (FLAGS_SET(open_flags, O_DIRECTORY|O_CREAT)) {
-                r = RET_NERRNO(mkdirat(dir_fd, path, mode));
+                if (FLAGS_SET(xopen_flags, XO_SUBVOLUME))
+                        r = btrfs_subvol_make_fallback(dir_fd, path, mode);
+                else
+                        r = RET_NERRNO(mkdirat(dir_fd, path, mode));
                 if (r == -EEXIST) {
                         if (FLAGS_SET(open_flags, O_EXCL))
                                 return -EEXIST;
index a19836d13892b15b00ccd05e3e2118f0f10da98f..1023ab73cac34c3ee60463102e43ad24790e205f 100644 (file)
@@ -133,7 +133,8 @@ int open_mkdir_at(int dirfd, const char *path, int flags, mode_t mode);
 int openat_report_new(int dirfd, const char *pathname, int flags, mode_t mode, bool *ret_newly_created);
 
 typedef enum XOpenFlags {
-        XO_LABEL = 1 << 0,
+        XO_LABEL     = 1 << 0,
+        XO_SUBVOLUME = 1 << 1,
 } XOpenFlags;
 
 int xopenat(int dir_fd, const char *path, int open_flags, XOpenFlags xopen_flags, mode_t mode);