]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
chattr-util: drop mostly unused 'previous' argument from chattr_path() and friends
authorYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 3 Mar 2025 07:18:29 +0000 (16:18 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 3 Mar 2025 15:47:12 +0000 (00:47 +0900)
18 files changed:
src/basic/chattr-util.h
src/basic/efivars.c
src/basic/fs-util.c
src/core/efi-random.c
src/libsystemd/sd-journal/test-journal-append.c
src/libsystemd/sd-journal/test-journal-flush.c
src/libsystemd/sd-journal/test-journal-init.c
src/libsystemd/sd-journal/test-journal-interleaving.c
src/libsystemd/sd-journal/test-journal-stream.c
src/libsystemd/sd-journal/test-journal-verify.c
src/libsystemd/sd-journal/test-journal.c
src/repart/repart.c
src/shared/btrfs-util.c
src/shared/copy.c
src/shared/discover-image.c
src/shared/import-util.c
src/shared/install-file.c
src/shared/journal-file-util.c

index 1fe38e32b15dd4e56126a22a3d8a0308b871c529..dee6d2ddd3ffb2ad49027cc9f70cb53aba247b13 100644 (file)
@@ -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);
index bebe302184feffa69bbc9dc58b0d4c6ce42792e9..e4fd869165ef8f88bae8d5c3ee0485d32c5e8469 100644 (file)
@@ -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);
         }
index 88e37cd6a24704ef892b01ceac2337ddd2c49322..71753b5ef293b7e2103423135f32939a745150aa 100644 (file)
@@ -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;
         }
index f3af300825fffcd860632a6b8e8b5a94a5ad97ad..d11b9a65e54cfdf3c2f2811f4dd628a4bc303855 100644 (file)
@@ -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)
index b7e7c7811fcc06d58030c42f1cde7a45d9776f86..ff4f86329b8ea0fde7997d476d529836f5260ac0 100644 (file)
@@ -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);
 
index b06645a4716722d2e24f2688d6e9253b8053b4d7..309220e20a5c6270b118836b1b7bfccfa98994da 100644 (file)
@@ -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"));
 
index ef66efdabf1fec4d20d2baf9ddb884b0ca64bceb..45663b0dbec6444a2d25d257e3ef60bb225a6910 100644 (file)
@@ -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);
index 1000df76804cd64e1b258c88b17dfd49b280d9de..f9b755a8ce356c3c5d7bfd63bfdfba0163356586 100644 (file)
@@ -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);
 }
index 00c0435fd4c9408704c001157a0f267679bad714..c8103bf113a2798dc12cf15981b42b07c74999e5 100644 (file)
@@ -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);
index dde40bf3774acf58dcc724af9c9ea558afc3f839..9bf4f86258735da0b40a1ad0bcb250979974670a 100644 (file)
@@ -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");
 
index 19a6d2d91cf52899db63342e35d05184d0052463..8892bec2cbf8cdf692f5aa149b991abef1b4e3ef 100644 (file)
@@ -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) {
index 88333550247ef113d9af8b55601f0006f8c4341c..edbd18cca2e9098596019cbb686d2c4d130b42e7 100644 (file)
@@ -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);
         }
index 9ae22d8aa561d2788cccfa5097af88565027cb95..2daddc797916215f352c72070a60f70a81a241fd 100644 (file)
@@ -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)
index 6a008f2dbe88063332efc06b1bd0b33cd812c68e..789ed00181d853c9102ab994efb3540f2a98c1e2 100644 (file)
@@ -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)
index d6afa53a6bfc65f014945c33bc1ed78b2923320f..d162df596f5130490ff0c24fa3707959f94eccb5 100644 (file)
@@ -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;
 
index bcdc21f79ec67f1bbe52b54a62041a6351da1071..1a396a6570c5c030e32128022eb941a9bbc34f45 100644 (file)
@@ -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,
index c0a220427676a35444865c512c7ab7cbc6f0e981..adccf47c9d7a6be8252c55e2a2959da7b48374b2 100644 (file)
@@ -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;
 
index 8df165d2f144f9db833768b2bf68c71b137e3f46..383c1354f3328ee78a2a58ddbd5472f7105b7697 100644 (file)
@@ -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;