} ChattrApplyFlags;
int chattr_full(int dir_fd, const char *path, unsigned value, unsigned mask, unsigned *ret_previous, unsigned *ret_final, ChattrApplyFlags flags);
-static inline int chattr_at(int dir_fd, const char *path, unsigned value, unsigned mask, unsigned *previous) {
- return chattr_full(dir_fd, path, value, mask, previous, NULL, 0);
+static inline int chattr_at(int dir_fd, const char *path, unsigned value, unsigned mask) {
+ return chattr_full(dir_fd, path, value, mask, NULL, NULL, 0);
}
-static inline int chattr_fd(int fd, unsigned value, unsigned mask, unsigned *previous) {
- return chattr_full(fd, NULL, value, mask, previous, NULL, 0);
+static inline int chattr_fd(int fd, unsigned value, unsigned mask) {
+ return chattr_full(fd, NULL, value, mask, NULL, NULL, 0);
}
-static inline int chattr_path(const char *path, unsigned value, unsigned mask, unsigned *previous) {
- return chattr_full(AT_FDCWD, path, value, mask, previous, NULL, 0);
+static inline int chattr_path(const char *path, unsigned value, unsigned mask) {
+ return chattr_full(AT_FDCWD, path, value, mask, NULL, NULL, 0);
}
int read_attr_fd(int fd, unsigned *ret);
* to protect them for accidental removal and modification. We are not changing these variables
* accidentally however, hence let's unset the bit first. */
- r = chattr_path(p, 0, FS_IMMUTABLE_FL, &saved_flags);
+ r = chattr_full(AT_FDCWD, p,
+ /* value = */ 0,
+ /* mask = */ FS_IMMUTABLE_FL,
+ /* ret_previous = */ &saved_flags,
+ /* ret_final = */ NULL,
+ /* flags = */ 0);
if (r < 0 && r != -ENOENT)
log_debug_errno(r, "Failed to drop FS_IMMUTABLE_FL flag from '%s', ignoring: %m", p);
/* Restore the original flags field, just in case */
if (fd < 0)
- q = chattr_path(p, saved_flags, FS_IMMUTABLE_FL, NULL);
+ q = chattr_path(p, saved_flags, FS_IMMUTABLE_FL);
else
- q = chattr_fd(fd, saved_flags, FS_IMMUTABLE_FL, NULL);
+ q = chattr_fd(fd, saved_flags, FS_IMMUTABLE_FL);
if (q < 0)
log_debug_errno(q, "Failed to restore FS_IMMUTABLE_FL on '%s', ignoring: %m", p);
}
}
if (FLAGS_SET(xopen_flags, XO_NOCOW)) {
- r = chattr_fd(fd, FS_NOCOW_FL, FS_NOCOW_FL, NULL);
+ r = chattr_fd(fd, FS_NOCOW_FL, FS_NOCOW_FL);
if (r < 0 && !ERRNO_IS_NOT_SUPPORTED(r))
goto error;
}
/* Paranoia: let's restrict access modes of these a bit, so that unprivileged users can't use them to
* identify the system or gain too much insight into what we might have credited to the entropy
* pool. */
- r = chattr_fd(fd, 0, FS_IMMUTABLE_FL, NULL);
+ r = chattr_fd(fd, 0, FS_IMMUTABLE_FL);
if (r < 0)
log_warning_errno(r, "Failed to drop FS_IMMUTABLE_FL from LoaderSystemToken EFI variable, ignoring: %m");
if (fchmod(fd, 0600) < 0)
assert_se(mkdtemp_malloc("/tmp/journal-append-XXXXXX", &tempdir) >= 0);
assert_se(chdir(tempdir) >= 0);
- (void) chattr_path(tempdir, FS_NOCOW_FL, FS_NOCOW_FL, NULL);
+ (void) chattr_path(tempdir, FS_NOCOW_FL, FS_NOCOW_FL);
log_debug("Opening journal %s/system.journal", tempdir);
assert_se(m = mmap_cache_new());
assert_se(mkdtemp_malloc("/var/tmp/test-journal-flush.XXXXXX", &dn) >= 0);
- (void) chattr_path(dn, FS_NOCOW_FL, FS_NOCOW_FL, NULL);
+ (void) chattr_path(dn, FS_NOCOW_FL, FS_NOCOW_FL);
assert_se(fn = path_join(dn, "test.journal"));
log_info("Running %d loops", I);
assert_se(mkdtemp(t));
- (void) chattr_path(t, FS_NOCOW_FL, FS_NOCOW_FL, NULL);
+ (void) chattr_path(t, FS_NOCOW_FL, FS_NOCOW_FL);
for (i = 0; i < I; i++) {
r = sd_journal_open(&j, SD_JOURNAL_LOCAL_ONLY | SD_JOURNAL_ASSUME_IMMUTABLE);
/* Speed up things a bit on btrfs, ensuring that CoW is turned off for all files created in our
* directory during the test run */
- (void) chattr_path(path, FS_NOCOW_FL, FS_NOCOW_FL, NULL);
+ (void) chattr_path(path, FS_NOCOW_FL, FS_NOCOW_FL);
*ret = TAKE_PTR(path);
}
assert_se(mkdtemp(t));
assert_se(chdir(t) >= 0);
- (void) chattr_path(t, FS_NOCOW_FL, FS_NOCOW_FL, NULL);
+ (void) chattr_path(t, FS_NOCOW_FL, FS_NOCOW_FL);
assert_se(journal_file_open(-EBADF, "one.journal", O_RDWR|O_CREAT, JOURNAL_COMPRESS, 0666, UINT64_MAX, NULL, m, NULL, &one) == 0);
assert_se(journal_file_open(-EBADF, "two.journal", O_RDWR|O_CREAT, JOURNAL_COMPRESS, 0666, UINT64_MAX, NULL, m, NULL, &two) == 0);
assert_se(mkdtemp(t));
assert_se(chdir(t) >= 0);
- (void) chattr_path(t, FS_NOCOW_FL, FS_NOCOW_FL, NULL);
+ (void) chattr_path(t, FS_NOCOW_FL, FS_NOCOW_FL);
log_info("Generating a test journal");
/* Speed up things a bit on btrfs, ensuring that CoW is turned off for all files created in our
* directory during the test run */
- (void) chattr_path(path, FS_NOCOW_FL, FS_NOCOW_FL, NULL);
+ (void) chattr_path(path, FS_NOCOW_FL, FS_NOCOW_FL);
}
static void test_non_empty_one(void) {
log_warning_errno(r, "Failed to read file attributes of %s, ignoring: %m", arg_node);
if (FLAGS_SET(attrs, FS_NOCOW_FL)) {
- r = chattr_fd(fd, FS_NOCOW_FL, FS_NOCOW_FL, NULL);
+ r = chattr_fd(fd, FS_NOCOW_FL, FS_NOCOW_FL);
if (r < 0 && !ERRNO_IS_NOT_SUPPORTED(r))
return log_error_errno(r, "Failed to disable copy-on-write on %s: %m", temp);
}
* it: the IMMUTABLE bit. Let's use this here, if this is requested. */
if (flags & BTRFS_SNAPSHOT_FALLBACK_IMMUTABLE)
- (void) chattr_at(new_fd, subvolume, FS_IMMUTABLE_FL, FS_IMMUTABLE_FL, NULL);
+ (void) chattr_at(new_fd, subvolume, FS_IMMUTABLE_FL, FS_IMMUTABLE_FL);
} else {
r = btrfs_subvol_set_read_only_at(new_fd, subvolume, true);
if (r < 0)
} else
/* If the NOCOW flag is set on the source, make the copy NOCOW as well. If the source
* is not NOCOW, don't do anything in particular with the copy. */
- (void) chattr_fd(fdt, FS_NOCOW_FL, FS_NOCOW_FL, /*previous=*/ NULL);
+ (void) chattr_fd(fdt, FS_NOCOW_FL, FS_NOCOW_FL);
}
return 0;
return r;
if (chattr_mask != 0)
- (void) chattr_fd(fdt, chattr_flags, chattr_mask & CHATTR_EARLY_FL, NULL);
+ (void) chattr_fd(fdt, chattr_flags, chattr_mask & CHATTR_EARLY_FL);
r = copy_bytes_full(fdf, fdt, UINT64_MAX, copy_flags & ~COPY_LOCK_BSD, NULL, NULL, progress_bytes, userdata);
if (r < 0)
unsigned nocow = FLAGS_SET(copy_flags, COPY_NOCOW_AFTER) ? FS_NOCOW_FL : 0;
if ((chattr_mask | nocow) != 0)
- (void) chattr_fd(fdt, chattr_flags | nocow, (chattr_mask & ~CHATTR_EARLY_FL) | nocow, NULL);
+ (void) chattr_fd(fdt, chattr_flags | nocow, (chattr_mask & ~CHATTR_EARLY_FL) | nocow);
if (copy_flags & (COPY_FSYNC|COPY_FSYNC_FULL)) {
if (fsync(fdt) < 0) {
return r;
if (chattr_mask != 0)
- (void) chattr_fd(fdt, chattr_flags, chattr_mask & CHATTR_EARLY_FL, NULL);
+ (void) chattr_fd(fdt, chattr_flags, chattr_mask & CHATTR_EARLY_FL);
r = copy_file_fd_at_full(dir_fdf, from, fdt, copy_flags, progress_bytes, userdata);
if (r < 0)
unsigned nocow = FLAGS_SET(copy_flags, COPY_NOCOW_AFTER) ? FS_NOCOW_FL : 0;
if ((chattr_mask | nocow) != 0)
- (void) chattr_fd(fdt, chattr_flags | nocow, (chattr_mask & ~CHATTR_EARLY_FL) | nocow, NULL);
+ (void) chattr_fd(fdt, chattr_flags | nocow, (chattr_mask & ~CHATTR_EARLY_FL) | nocow);
r = close_nointr(TAKE_FD(fdt)); /* even if this fails, the fd is now invalidated */
if (r < 0)
case IMAGE_DIRECTORY:
/* Allow deletion of read-only directories */
- (void) chattr_path(i->path, 0, FS_IMMUTABLE_FL, NULL);
+ (void) chattr_path(i->path, 0, FS_IMMUTABLE_FL);
r = rm_rf(i->path, REMOVE_ROOT|REMOVE_PHYSICAL|REMOVE_SUBVOLUME);
if (r < 0)
return r;
(void) read_attr_at(AT_FDCWD, i->path, &file_attr);
if (file_attr & FS_IMMUTABLE_FL)
- (void) chattr_path(i->path, 0, FS_IMMUTABLE_FL, NULL);
+ (void) chattr_path(i->path, 0, FS_IMMUTABLE_FL);
_fallthrough_;
case IMAGE_SUBVOLUME:
/* Restore the immutable bit, if it was set before */
if (file_attr & FS_IMMUTABLE_FL)
- (void) chattr_path(new_path, FS_IMMUTABLE_FL, FS_IMMUTABLE_FL, NULL);
+ (void) chattr_path(new_path, FS_IMMUTABLE_FL, FS_IMMUTABLE_FL);
free_and_replace(i->path, new_path);
free_and_replace(i->name, nn);
a read-only subvolume, but at least something, and
we can read the value back. */
- r = chattr_path(i->path, b ? FS_IMMUTABLE_FL : 0, FS_IMMUTABLE_FL, NULL);
+ r = chattr_path(i->path, b ? FS_IMMUTABLE_FL : 0, FS_IMMUTABLE_FL);
if (r < 0)
return r;
int import_set_nocow_and_log(int fd, const char *path) {
int r;
- r = chattr_fd(fd, FS_NOCOW_FL, FS_NOCOW_FL, NULL);
+ r = chattr_fd(fd, FS_NOCOW_FL, FS_NOCOW_FL);
if (r < 0)
return log_full_errno(
ERRNO_IS_NOT_SUPPORTED(r) ? LOG_DEBUG : LOG_WARNING,
return r;
}
- r = chattr_fd(fd, FS_IMMUTABLE_FL, FS_IMMUTABLE_FL, NULL);
+ r = chattr_fd(fd, FS_IMMUTABLE_FL, FS_IMMUTABLE_FL);
if (r < 0)
return r;
* copy all data to a new file without the NOCOW flag set. */
if (f->archive) {
- r = chattr_fd(f->fd, 0, FS_NOCOW_FL, NULL);
+ r = chattr_fd(f->fd, 0, FS_NOCOW_FL);
if (r >= 0)
continue;