btrfs-progs: sb-mod: add preliminary support for non-u64 types
[platform/upstream/btrfs-progs.git] / btrfs-zero-log.c
index 88998e9..2fce59e 100644 (file)
  * Boston, MA 021110-1307, USA.
  */
 
-#define _XOPEN_SOURCE 500
-#define _GNU_SOURCE 1
+#include "kerncompat.h"
+
 #include <stdio.h>
-#include <stdlib.h>
 #include <unistd.h>
-#include <fcntl.h>
-#include <sys/stat.h>
-#include "kerncompat.h"
 #include "ctree.h"
 #include "disk-io.h"
-#include "print-tree.h"
 #include "transaction.h"
-#include "list.h"
-#include "version.h"
 #include "utils.h"
+#include "help.h"
 
-static void print_usage(void) __attribute__((noreturn));
-static void print_usage(void)
+__attribute__((noreturn)) static void print_usage(void)
 {
-       fprintf(stderr, "usage: btrfs-zero-log dev\n");
-       fprintf(stderr, "%s\n", BTRFS_BUILD_VERSION);
+       printf("usage: btrfs-zero-log dev\n");
        exit(1);
 }
 
-int main(int ac, char **av)
+int main(int argc, char **argv)
 {
        struct btrfs_root *root;
        struct btrfs_trans_handle *trans;
+       struct btrfs_super_block *sb;
        int ret;
 
-       set_argv0(av);
-       if (check_argc_exact(ac, 2))
+       set_argv0(argv);
+       if (check_argc_exact(argc - optind, 1))
                print_usage();
 
        radix_tree_init();
 
-       if((ret = check_mounted(av[1])) < 0) {
-               fprintf(stderr, "Could not check mount status: %s\n", strerror(-ret));
+       printf("WARNING: this utility is deprecated, please use 'btrfs rescue zero-log'\n\n");
+
+       if ((ret = check_mounted(argv[optind])) < 0) {
+               fprintf(stderr, "ERROR: could not check mount status: %s\n", strerror(-ret));
                goto out;
-       } else if(ret) {
-               fprintf(stderr, "%s is currently mounted. Aborting.\n", av[1]);
+       } else if (ret) {
+               fprintf(stderr, "ERROR: %s is currently mounted\n", argv[optind]);
                ret = -EBUSY;
                goto out;
        }
 
-       root = open_ctree(av[1], 0, OPEN_CTREE_WRITES);
-
-       if (root == NULL)
+       root = open_ctree(argv[optind], 0, OPEN_CTREE_WRITES | OPEN_CTREE_PARTIAL);
+       if (!root) {
+               fprintf(stderr, "ERROR: cannot open ctree\n");
                return 1;
+       }
 
+       sb = root->fs_info->super_copy;
+       printf("Clearing log on %s, previous log_root %llu, level %u\n",
+                       argv[optind],
+                       (unsigned long long)btrfs_super_log_root(sb),
+                       (unsigned)btrfs_super_log_root_level(sb));
        trans = btrfs_start_transaction(root, 1);
+       BUG_ON(IS_ERR(trans));
        btrfs_set_super_log_root(root->fs_info->super_copy, 0);
        btrfs_set_super_log_root_level(root->fs_info->super_copy, 0);
        btrfs_commit_transaction(trans, root);