chattr-util: drop mostly unused 'previous' argument from chattr_path() and friends
This commit is contained in:
@@ -41,14 +41,14 @@ typedef enum ChattrApplyFlags {
|
||||
} 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);
|
||||
|
||||
+8
-3
@@ -238,7 +238,12 @@ int efi_set_variable(const char *variable, const void *value, size_t size) {
|
||||
* 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);
|
||||
|
||||
@@ -285,9 +290,9 @@ finish:
|
||||
|
||||
/* 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);
|
||||
}
|
||||
|
||||
+1
-1
@@ -1259,7 +1259,7 @@ int xopenat_full(int dir_fd, const char *path, int open_flags, XOpenFlags xopen_
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ void lock_down_efi_variables(void) {
|
||||
/* 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)
|
||||
|
||||
@@ -57,7 +57,7 @@ static int journal_corrupt_and_append(uint64_t start_offset, uint64_t step) {
|
||||
|
||||
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);
|
||||
|
||||
|
||||
@@ -107,7 +107,7 @@ static void test_journal_flush_one(int argc, char *argv[]) {
|
||||
|
||||
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"));
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ int main(int argc, char *argv[]) {
|
||||
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);
|
||||
|
||||
@@ -224,7 +224,7 @@ static void mkdtemp_chdir_chattr(const char *template, char **ret) {
|
||||
|
||||
/* 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);
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ static void run_test(void) {
|
||||
|
||||
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);
|
||||
|
||||
@@ -88,7 +88,7 @@ static int run_test(const char *verification_key, ssize_t max_iterations) {
|
||||
|
||||
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");
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ static void mkdtemp_chdir_chattr(char *path) {
|
||||
|
||||
/* 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) {
|
||||
|
||||
+1
-1
@@ -4324,7 +4324,7 @@ static int prepare_temporary_file(Context *context, PartitionTarget *t, uint64_t
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -1550,7 +1550,7 @@ int btrfs_subvol_snapshot_at_full(
|
||||
* 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)
|
||||
|
||||
+5
-5
@@ -790,7 +790,7 @@ static int prepare_nocow(int fdf, const char *from, int fdt, unsigned *chattr_ma
|
||||
} 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;
|
||||
@@ -1488,7 +1488,7 @@ int copy_file_at_full(
|
||||
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)
|
||||
@@ -1505,7 +1505,7 @@ int copy_file_at_full(
|
||||
|
||||
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) {
|
||||
@@ -1571,7 +1571,7 @@ int copy_file_atomic_at_full(
|
||||
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)
|
||||
@@ -1594,7 +1594,7 @@ int copy_file_atomic_at_full(
|
||||
|
||||
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)
|
||||
|
||||
@@ -1126,7 +1126,7 @@ int image_remove(Image *i) {
|
||||
|
||||
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;
|
||||
@@ -1225,7 +1225,7 @@ int image_rename(Image *i, const char *new_name, RuntimeScope scope) {
|
||||
(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:
|
||||
@@ -1266,7 +1266,7 @@ int image_rename(Image *i, const char *new_name, RuntimeScope scope) {
|
||||
|
||||
/* 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);
|
||||
@@ -1418,7 +1418,7 @@ int image_read_only(Image *i, bool b) {
|
||||
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;
|
||||
|
||||
|
||||
@@ -230,7 +230,7 @@ int import_assign_pool_quota_and_warn(const char *path) {
|
||||
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,
|
||||
|
||||
@@ -48,7 +48,7 @@ static int fs_make_very_read_only(int fd) {
|
||||
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;
|
||||
|
||||
|
||||
@@ -204,7 +204,7 @@ static void journal_file_set_offline_internal(JournalFile *f) {
|
||||
* 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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user