btrfsck: Exit and print error message when not able to open a device
authorThadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
Wed, 21 Jan 2009 18:59:36 +0000 (13:59 -0500)
committerChris Mason <chris.mason@oracle.com>
Wed, 21 Jan 2009 18:59:36 +0000 (13:59 -0500)
If btrfsck is not able to open a device, it segfaults. This fixes it and
prints an error message too.

btrfsck.c
disk-io.c

index c50de7d..1fcc372 100644 (file)
--- a/btrfsck.c
+++ b/btrfsck.c
@@ -2075,6 +2075,9 @@ int main(int ac, char **av)
        radix_tree_init();
        root = open_ctree(av[1], 0, 0);
 
+       if (root == NULL)
+               return 1;
+
        ret = check_extents(root);
        if (ret)
                goto out;
index c15cf53..e49c220 100644 (file)
--- a/disk-io.c
+++ b/disk-io.c
@@ -530,6 +530,7 @@ struct btrfs_root *open_ctree(const char *filename, u64 sb_bytenr, int writes)
 
        fp = open(filename, flags, 0600);
        if (fp < 0) {
+               fprintf (stderr, "Coult not open %s\n", filename);
                return NULL;
        }
        root = open_ctree_fd(fp, filename, sb_bytenr, writes);