diff options
Diffstat (limited to 'c_src/tools-util.c')
-rw-r--r-- | c_src/tools-util.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/c_src/tools-util.c b/c_src/tools-util.c index 43c9b789..3df2b004 100644 --- a/c_src/tools-util.c +++ b/c_src/tools-util.c @@ -185,6 +185,24 @@ unsigned get_blocksize(int fd) /* Open a block device, do magic blkid stuff to probe for existing filesystems: */ int open_for_format(struct dev_opts *dev, bool force) { + int blkid_version_code = blkid_get_library_version(NULL, NULL); + if (blkid_version_code < 2401) { + if (force) { + fprintf( + stderr, + "Continuing with out of date libblkid %s because --force was passed.\n", + BLKID_VERSION); + } else { + // Reference for picking 2.40.1: + // https://mirrors.edge.kernel.org/pub/linux/utils/util-linux/v2.40/v2.40.1-ReleaseNotes + // https://github.com/util-linux/util-linux/issues/3103 + die( + "Refusing to format when using libblkid %s\n" + "libblkid >= 2.40.1 is required to check for existing filesystems\n" + "Earlier versions may not recognize some bcachefs filesystems.\n", BLKID_VERSION); + } + } + blkid_probe pr; const char *fs_type = NULL, *fs_label = NULL; size_t fs_type_len, fs_label_len; @@ -708,6 +726,21 @@ struct bbpos_range bbpos_range_parse(char *buf) return (struct bbpos_range) { .start = start, .end = end }; } +unsigned version_parse(char *buf) +{ + char *s = buf; + char *major_str = strsep(&s, "."); + char *minor_str = strsep(&s, "."); + + unsigned major, minor; + + if (kstrtouint(major_str, 10, &major) || + kstrtouint(minor_str, 10, &minor)) + die("invalid version"); + + return BCH_VERSION(major, minor); +} + darray_str get_or_split_cmdline_devs(int argc, char *argv[]) { darray_str ret = {}; |