[PATCH] Prevent btrfsck to run on mounted filesystems

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



As recently discussed on the list, btrfsck should only be run on unmounted filesystems. This patch adds a short check for the mount status at the beginning of btrfsck. If the FS is mounted, the program aborts showing an error message.

Signed-off-by: Andi Drebes <lists-receive@xxxxxxxxxxxxxxxxxxx>
---
diff --git a/btrfsck.c b/btrfsck.c
index 73f1836..87ae776 100644
--- a/btrfsck.c
+++ b/btrfsck.c
@@ -28,6 +28,7 @@
 #include "transaction.h"
 #include "list.h"
 #include "version.h"
+#include "utils.h"
 
 static u64 bytes_used = 0;
 static u64 total_csum_bytes = 0;
@@ -2819,6 +2820,16 @@ int main(int ac, char **av)
 	if (ac < 2)
 		print_usage();
 
+	ret = check_mounted(av[1]);
+	if (ret < 0) {
+		fprintf(stderr, "error checking %s mount status\n", av[1]);
+		return 1;
+	}
+	if (ret == 1) {
+		fprintf(stderr, "%s is mounted. btrfsck can only be run on an unmounted filesystem.\n", av[1]);
+		return 1;
+	}
+
 	radix_tree_init();
 	cache_tree_init(&root_cache);
 	root = open_ctree(av[1], 0, 0);
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Filesystem Development]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux