]> git.sesse.net Git - bcachefs-tools-debian/blobdiff - tools-util.c
Update bcachefs sources to 1a739db0b256 bcachefs; guard against overflow in btree...
[bcachefs-tools-debian] / tools-util.c
index f6e9a4789b3bc143fdb101339a8982a4417bc23a..5b0c1bf5d5dddf3f8c04462472608ee76ef86166 100644 (file)
@@ -225,14 +225,14 @@ int open_for_format(struct dev_opts *dev, bool force)
        if (ret < 0)
                die("Error opening device to format %s: %s", dev->path, strerror(-ret));
 
-       if (force)
-               return 0;
-
        if (!(pr = blkid_new_probe()))
                die("blkid error 1");
        if (blkid_probe_set_device(pr, dev->bdev->bd_buffered_fd, 0, 0))
                die("blkid error 2");
-       if (blkid_probe_enable_partitions(pr, true))
+       if (blkid_probe_enable_partitions(pr, true) ||
+           blkid_probe_enable_superblocks(pr, true) ||
+           blkid_probe_set_superblocks_flags(pr,
+                       BLKID_SUBLKS_LABEL|BLKID_SUBLKS_TYPE|BLKID_SUBLKS_MAGIC))
                die("blkid error 3");
        if (blkid_do_fullprobe(pr) < 0)
                die("blkid error 4");
@@ -247,11 +247,15 @@ int open_for_format(struct dev_opts *dev, bool force)
                else
                        printf("%s contains a %s filesystem\n",
                               dev->path, fs_type);
-               fputs("Proceed anyway?", stdout);
-               if (!ask_yn())
-                       exit(EXIT_FAILURE);
-               while (blkid_do_probe(pr) == 0)
-                       blkid_do_wipe(pr, 0);
+               if (!force) {
+                       fputs("Proceed anyway?", stdout);
+                       if (!ask_yn())
+                               exit(EXIT_FAILURE);
+               }
+               while (blkid_do_probe(pr) == 0) {
+                       if (blkid_do_wipe(pr, 0))
+                               die("Failed to wipe preexisting metadata.");
+               }
        }
 
        blkid_free_probe(pr);
@@ -289,14 +293,13 @@ static int range_cmp(const void *_l, const void *_r)
 
 void ranges_sort_merge(ranges *r)
 {
-       struct range *t, *i;
        ranges tmp = { 0 };
 
        sort(r->data, r->nr, sizeof(r->data[0]), range_cmp, NULL);
 
        /* Merge contiguous ranges: */
        darray_for_each(*r, i) {
-               t = tmp.nr ?  &tmp.data[tmp.nr - 1] : NULL;
+               struct range *t = tmp.nr ?  &tmp.data[tmp.nr - 1] : NULL;
 
                if (t && t->end >= i->start)
                        t->end = max(t->end, i->end);
@@ -310,8 +313,6 @@ void ranges_sort_merge(ranges *r)
 
 void ranges_roundup(ranges *r, unsigned block_size)
 {
-       struct range *i;
-
        darray_for_each(*r, i) {
                i->start = round_down(i->start, block_size);
                i->end  = round_up(i->end, block_size);
@@ -320,8 +321,6 @@ void ranges_roundup(ranges *r, unsigned block_size)
 
 void ranges_rounddown(ranges *r, unsigned block_size)
 {
-       struct range *i;
-
        darray_for_each(*r, i) {
                i->start = round_up(i->start, block_size);
                i->end  = round_down(i->end, block_size);
@@ -673,7 +672,7 @@ struct bbpos bbpos_parse(char *buf)
        if (!(field = strsep(&s, ":")))
                die("invalid bbpos %s", buf);
 
-       ret.btree = read_string_list_or_die(field, bch2_btree_ids, "btree id");
+       ret.btree = read_string_list_or_die(field, __bch2_btree_ids, "btree id");
 
        if (!s)
                die("invalid bbpos %s", buf);