diff --git a/include/libuzfs.h b/include/libuzfs.h index fcb423bc3b0d..ec76c44bbd25 100644 --- a/include/libuzfs.h +++ b/include/libuzfs.h @@ -225,8 +225,10 @@ extern int libuzfs_dentry_delete(libuzfs_inode_handle_t *ihp, extern int libuzfs_dentry_lookup(libuzfs_inode_handle_t *ihp, const char *name, uint64_t *value); -extern int libuzfs_dentry_iterate(libuzfs_inode_handle_t *ihp, - uint64_t whence, uint32_t size, char *buf, uint32_t *num); +typedef int (*dir_emit_func_t)(void *arg, uint64_t whence, + const char *name, uint64_t value); +extern int libuzfs_dentry_iterate(libuzfs_inode_handle_t *dihp, + uint64_t whence, void *arg, dir_emit_func_t dir_emit); extern int libuzfs_fs_create(const char *fsname); extern void libuzfs_fs_destroy(const char *fsname); diff --git a/lib/libuzfs/libuzfs.c b/lib/libuzfs/libuzfs.c index 3853fd662f96..66d75750ffcc 100644 --- a/lib/libuzfs/libuzfs.c +++ b/lib/libuzfs/libuzfs.c @@ -233,12 +233,6 @@ libuzfs_inode_handle_rele(libuzfs_inode_handle_t *ihp) mutex_exit(mp); } -typedef struct dir_emit_ctx { - char *buf; - char *cur; - uint32_t size; -} dir_emit_ctx_t; - static void dump_debug_buffer(void) { @@ -2209,44 +2203,14 @@ libuzfs_dentry_lookup(libuzfs_inode_handle_t *dihp, return (libuzfs_zap_lookup(dihp->dhp, dihp->ino, name, 8, 1, value)); } -static boolean_t -dir_emit(dir_emit_ctx_t *ctx, uint64_t whence, uint64_t value, char *name, - uint32_t name_len) -{ - int size = offsetof(struct uzfs_dentry, name) + name_len + 1; - - // ensure dentry is aligned to 8 bytes to make Rust happy - size = roundup(size, sizeof (uint64_t)); - if (ctx->cur + size > ctx->buf + ctx->size) { - return (B_TRUE); - } - - struct uzfs_dentry *dentry = (struct uzfs_dentry *)ctx->cur; - dentry->size = size; - dentry->whence = whence; - dentry->value = value; - memcpy(dentry->name, name, name_len + 1); - - ctx->cur += size; - - return (B_FALSE); -} - int libuzfs_dentry_iterate(libuzfs_inode_handle_t *dihp, - uint64_t whence, uint32_t size, char *buf, uint32_t *num) + uint64_t whence, void *arg, dir_emit_func_t dir_emit) { int error = 0; zap_cursor_t zc; zap_attribute_t zap; boolean_t done = B_FALSE; - dir_emit_ctx_t ctx; - - *num = 0; - ctx.buf = buf; - ctx.cur = buf; - ctx.size = size; - memset(ctx.buf, 0, size); libuzfs_dataset_handle_t *dhp = dihp->dhp; uint64_t dino = dihp->ino; @@ -2275,17 +2239,12 @@ libuzfs_dentry_iterate(libuzfs_inode_handle_t *dihp, zap_cursor_advance(&zc); whence = zap_cursor_serialize(&zc); - done = dir_emit(&ctx, whence, zap.za_first_integer, zap.za_name, - strlen(zap.za_name)); + done = dir_emit(arg, whence, zap.za_name, zap.za_first_integer); if (done) break; - (*num)++; } zap_cursor_fini(&zc); - if (error == ENOENT) { - error = 0; - } return (error); } diff --git a/lib/libzpool/kernel.c b/lib/libzpool/kernel.c index 8b170afd0e0d..3ab7fbfc9687 100644 --- a/lib/libzpool/kernel.c +++ b/lib/libzpool/kernel.c @@ -294,13 +294,9 @@ kstat_seq_show_named(struct seq_file *f, kstat_named_t *knp) switch (knp->data_type) { case KSTAT_DATA_CHAR: - knp->value.c[15] = '\0'; /* NULL terminate */ + knp->value.c[15] = '\0'; seq_printf(f, "%-16s", knp->value.c); break; - /* - * NOTE - We need to be more careful able what tokens are - * used for each arch, for now this is correct for x86_64. - */ case KSTAT_DATA_INT32: seq_printf(f, "%d", knp->value.i32); break; @@ -344,7 +340,6 @@ kstat_seq_show_intr(struct seq_file *f, kstat_intr_t *kip) static int kstat_seq_show_io(struct seq_file *f, kstat_io_t *kip) { - /* though wlentime & friends are signed, they will never be negative */ seq_printf(f, "%-8llu %-8llu %-8u %-8u %-8llu %-8llu " "%-8llu %-8llu %-8llu %-8llu %-8u %-8u\n",