Skip to content

Commit

Permalink
Merge pull request #347 from g2p/format-safety
Browse files Browse the repository at this point in the history
Check for a sufficiently recent libblkid before formatting
  • Loading branch information
koverstreet authored Oct 27, 2024
2 parents 5350fd2 + 8d5f44d commit 64767d6
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions c_src/tools-util.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 64767d6

Please sign in to comment.