Let's add a flag for xopenat() that immediately makes a file NOCOW
after opening it if it's supported.
#include "alloc-util.h"
#include "btrfs.h"
+#include "chattr-util.h"
#include "dirent-util.h"
#include "fd-util.h"
#include "fileio.h"
goto error;
}
+ if (FLAGS_SET(xopen_flags, XO_NOCOW)) {
+ r = chattr_fd(fd, FS_NOCOW_FL, FS_NOCOW_FL, NULL);
+ if (r < 0 && !ERRNO_IS_NOT_SUPPORTED(r))
+ goto error;
+ }
+
return TAKE_FD(fd);
error:
typedef enum XOpenFlags {
XO_LABEL = 1 << 0,
XO_SUBVOLUME = 1 << 1,
+ XO_NOCOW = 1 << 2,
} XOpenFlags;
int open_mkdir_at_full(int dirfd, const char *path, int flags, XOpenFlags xopen_flags, mode_t mode);