bcachefs: Kill bch_scnmemcpy()
authorKent Overstreet <kent.overstreet@gmail.com>
Sun, 20 Feb 2022 09:52:44 +0000 (04:52 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:09:24 +0000 (17:09 -0400)
bch_scnmemcpy was for printing length-limited strings that might not
have a terminating null - turns out sprintf & pr_buf can do this with
%.*s.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
fs/bcachefs/dirent.c
fs/bcachefs/disk_groups.c
fs/bcachefs/journal_io.c
fs/bcachefs/util.c
fs/bcachefs/util.h
fs/bcachefs/xattr.c

index 6f699b7..a43a244 100644 (file)
@@ -122,9 +122,9 @@ void bch2_dirent_to_text(struct printbuf *out, struct bch_fs *c,
 {
        struct bkey_s_c_dirent d = bkey_s_c_to_dirent(k);
 
-       bch_scnmemcpy(out, d.v->d_name,
-                     bch2_dirent_name_bytes(d));
-       pr_buf(out, " -> %llu type %s",
+       pr_buf(out, "%.*s -> %llu type %s",
+              bch2_dirent_name_bytes(d),
+              d.v->d_name,
               d.v->d_type != DT_SUBVOL
               ? le64_to_cpu(d.v->d_inum)
               : le32_to_cpu(d.v->d_child_subvol),
index a27fc4f..e411606 100644 (file)
@@ -76,8 +76,9 @@ static int bch2_sb_disk_groups_validate(struct bch_sb *sb,
        for (g = sorted; g + 1 < sorted + nr_groups; g++)
                if (!BCH_GROUP_DELETED(g) &&
                    !group_cmp(&g[0], &g[1])) {
-                       pr_buf(err, "duplicate label %llu.", BCH_GROUP_PARENT(g));
-                       bch_scnmemcpy(err, g->label, strnlen(g->label, sizeof(g->label)));
+                       pr_buf(err, "duplicate label %llu.%.*s",
+                              BCH_GROUP_PARENT(g),
+                              (int) sizeof(g->label), g->label);
                        goto err;
                }
 
@@ -376,9 +377,7 @@ void bch2_disk_path_to_text(struct printbuf *out,
                v = path[--nr];
                g = groups->entries + v;
 
-               bch_scnmemcpy(out, g->label,
-                             strnlen(g->label, sizeof(g->label)));
-
+               pr_buf(out, "%.*s", (int) sizeof(g->label), g->label);
                if (nr)
                        pr_buf(out, ".");
        }
index 56ba821..4f0904a 100644 (file)
@@ -595,7 +595,7 @@ static void journal_entry_log_to_text(struct printbuf *out, struct bch_fs *c,
        struct jset_entry_log *l = container_of(entry, struct jset_entry_log, entry);
        unsigned bytes = vstruct_bytes(entry) - offsetof(struct jset_entry_log, d);
 
-       bch_scnmemcpy(out, l->d, strnlen(l->d, bytes));
+       pr_buf(out, "%.*s", bytes, l->d);
 }
 
 struct jset_entry_ops {
index e7675b4..971f404 100644 (file)
@@ -581,19 +581,6 @@ void memcpy_from_bio(void *dst, struct bio *src, struct bvec_iter src_iter)
        }
 }
 
-void bch_scnmemcpy(struct printbuf *out,
-                  const char *src, size_t len)
-{
-       size_t n = printbuf_remaining(out);
-
-       if (n) {
-               n = min(n - 1, len);
-               memcpy(out->pos, src, n);
-               out->pos += n;
-               *out->pos = '\0';
-       }
-}
-
 #include "eytzinger.h"
 
 static int alignment_ok(const void *base, size_t align)
index e047e78..fc8ffa6 100644 (file)
@@ -281,8 +281,6 @@ static inline void printbuf_newline(struct printbuf *buf)
                pr_buf(buf, " ");
 }
 
-void bch_scnmemcpy(struct printbuf *, const char *, size_t);
-
 int bch2_strtoint_h(const char *, int *);
 int bch2_strtouint_h(const char *, unsigned int *);
 int bch2_strtoll_h(const char *, long long *);
index a5122db..9cce395 100644 (file)
@@ -111,11 +111,11 @@ void bch2_xattr_to_text(struct printbuf *out, struct bch_fs *c,
        else
                pr_buf(out, "(unknown type %u)", xattr.v->x_type);
 
-       bch_scnmemcpy(out, xattr.v->x_name,
-                     xattr.v->x_name_len);
-       pr_buf(out, ":");
-       bch_scnmemcpy(out, xattr_val(xattr.v),
-                     le16_to_cpu(xattr.v->x_val_len));
+       pr_buf(out, "%.*s:%.*s",
+              xattr.v->x_name_len,
+              xattr.v->x_name,
+              le16_to_cpu(xattr.v->x_val_len),
+              (char *) xattr_val(xattr.v));
 }
 
 static int bch2_xattr_get_trans(struct btree_trans *trans, struct bch_inode_info *inode,