From: Yu Watanabe Date: Mon, 3 Mar 2025 07:18:29 +0000 (+0900) Subject: chattr-util: drop mostly unused 'previous' argument from chattr_path() and friends X-Git-Tag: v258-rc1~1197^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a997f3387f4a252a343a3491c619940cbd673432;p=thirdparty%2Fsystemd.git chattr-util: drop mostly unused 'previous' argument from chattr_path() and friends --- diff --git a/src/basic/chattr-util.h b/src/basic/chattr-util.h index 1fe38e32b15..dee6d2ddd3f 100644 --- a/src/basic/chattr-util.h +++ b/src/basic/chattr-util.h @@ -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); diff --git a/src/basic/efivars.c b/src/basic/efivars.c index bebe302184f..e4fd869165e 100644 --- a/src/basic/efivars.c +++ b/src/basic/efivars.c @@ -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); } diff --git a/src/basic/fs-util.c b/src/basic/fs-util.c index 88e37cd6a24..71753b5ef29 100644 --- a/src/basic/fs-util.c +++ b/src/basic/fs-util.c @@ -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; } diff --git a/src/core/efi-random.c b/src/core/efi-random.c index f3af300825f..d11b9a65e54 100644 --- a/src/core/efi-random.c +++ b/src/core/efi-random.c @@ -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) diff --git a/src/libsystemd/sd-journal/test-journal-append.c b/src/libsystemd/sd-journal/test-journal-append.c index b7e7c7811fc..ff4f86329b8 100644 --- a/src/libsystemd/sd-journal/test-journal-append.c +++ b/src/libsystemd/sd-journal/test-journal-append.c @@ -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); diff --git a/src/libsystemd/sd-journal/test-journal-flush.c b/src/libsystemd/sd-journal/test-journal-flush.c index b06645a4716..309220e20a5 100644 --- a/src/libsystemd/sd-journal/test-journal-flush.c +++ b/src/libsystemd/sd-journal/test-journal-flush.c @@ -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")); diff --git a/src/libsystemd/sd-journal/test-journal-init.c b/src/libsystemd/sd-journal/test-journal-init.c index ef66efdabf1..45663b0dbec 100644 --- a/src/libsystemd/sd-journal/test-journal-init.c +++ b/src/libsystemd/sd-journal/test-journal-init.c @@ -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); diff --git a/src/libsystemd/sd-journal/test-journal-interleaving.c b/src/libsystemd/sd-journal/test-journal-interleaving.c index 1000df76804..f9b755a8ce3 100644 --- a/src/libsystemd/sd-journal/test-journal-interleaving.c +++ b/src/libsystemd/sd-journal/test-journal-interleaving.c @@ -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); } diff --git a/src/libsystemd/sd-journal/test-journal-stream.c b/src/libsystemd/sd-journal/test-journal-stream.c index 00c0435fd4c..c8103bf113a 100644 --- a/src/libsystemd/sd-journal/test-journal-stream.c +++ b/src/libsystemd/sd-journal/test-journal-stream.c @@ -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); diff --git a/src/libsystemd/sd-journal/test-journal-verify.c b/src/libsystemd/sd-journal/test-journal-verify.c index dde40bf3774..9bf4f862587 100644 --- a/src/libsystemd/sd-journal/test-journal-verify.c +++ b/src/libsystemd/sd-journal/test-journal-verify.c @@ -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"); diff --git a/src/libsystemd/sd-journal/test-journal.c b/src/libsystemd/sd-journal/test-journal.c index 19a6d2d91cf..8892bec2cbf 100644 --- a/src/libsystemd/sd-journal/test-journal.c +++ b/src/libsystemd/sd-journal/test-journal.c @@ -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) { diff --git a/src/repart/repart.c b/src/repart/repart.c index 88333550247..edbd18cca2e 100644 --- a/src/repart/repart.c +++ b/src/repart/repart.c @@ -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); } diff --git a/src/shared/btrfs-util.c b/src/shared/btrfs-util.c index 9ae22d8aa56..2daddc79791 100644 --- a/src/shared/btrfs-util.c +++ b/src/shared/btrfs-util.c @@ -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) diff --git a/src/shared/copy.c b/src/shared/copy.c index 6a008f2dbe8..789ed00181d 100644 --- a/src/shared/copy.c +++ b/src/shared/copy.c @@ -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) diff --git a/src/shared/discover-image.c b/src/shared/discover-image.c index d6afa53a6bf..d162df596f5 100644 --- a/src/shared/discover-image.c +++ b/src/shared/discover-image.c @@ -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; diff --git a/src/shared/import-util.c b/src/shared/import-util.c index bcdc21f79ec..1a396a6570c 100644 --- a/src/shared/import-util.c +++ b/src/shared/import-util.c @@ -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, diff --git a/src/shared/install-file.c b/src/shared/install-file.c index c0a22042767..adccf47c9d7 100644 --- a/src/shared/install-file.c +++ b/src/shared/install-file.c @@ -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; diff --git a/src/shared/journal-file-util.c b/src/shared/journal-file-util.c index 8df165d2f14..383c1354f33 100644 --- a/src/shared/journal-file-util.c +++ b/src/shared/journal-file-util.c @@ -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;