summaryrefslogtreecommitdiff
path: root/c_src/libbcachefs.h
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@linux.dev>2025-03-28 11:38:55 -0400
committerKent Overstreet <kent.overstreet@linux.dev>2025-03-28 11:38:55 -0400
commit7c47145f6cdf9826f9dc24c935195b58268b1ec6 (patch)
treef63e7951cbddcde3db8e0058e70dc0604abc4a74 /c_src/libbcachefs.h
parent396545c2ea073144d5cd905bc8bcfb0080549f6d (diff)
cmd_fs_usage: Fix kernel version check
This needed an access() check, like the other uses, instead of exiting if it can't be read. Factor out a small common helper for this. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'c_src/libbcachefs.h')
-rw-r--r--c_src/libbcachefs.h12
1 files changed, 8 insertions, 4 deletions
diff --git a/c_src/libbcachefs.h b/c_src/libbcachefs.h
index 619bbbd5..93a86db7 100644
--- a/c_src/libbcachefs.h
+++ b/c_src/libbcachefs.h
@@ -45,14 +45,18 @@ struct format_opts {
char *source;
};
-static inline struct format_opts format_opts_default()
+static inline unsigned bcachefs_kernel_version(void)
{
- unsigned version = !access( "/sys/module/bcachefs/parameters/version", R_OK)
+ return !access("/sys/module/bcachefs/parameters/version", R_OK)
? read_file_u64(AT_FDCWD, "/sys/module/bcachefs/parameters/version")
- : bcachefs_metadata_version_current;
+ : 0;
+}
+static inline struct format_opts format_opts_default()
+{
return (struct format_opts) {
- .version = version,
+ .version = bcachefs_kernel_version() ?:
+ bcachefs_metadata_version_current,
.superblock_size = SUPERBLOCK_SIZE_DEFAULT,
};
}