btrfs-progs: check: lowmem: Fix false alert about orphan inode
[platform/upstream/btrfs-progs.git] / btrfs-zero-log.c
index 4c4ed10..2fce59e 100644 (file)
 #include "disk-io.h"
 #include "transaction.h"
 #include "utils.h"
+#include "help.h"
 
 __attribute__((noreturn)) static void print_usage(void)
 {
-       fprintf(stderr, "usage: btrfs-zero-log dev\n");
+       printf("usage: btrfs-zero-log dev\n");
        exit(1);
 }
 
@@ -39,23 +40,23 @@ int main(int argc, char **argv)
        int ret;
 
        set_argv0(argv);
-       if (check_argc_exact(argc, 2))
+       if (check_argc_exact(argc - optind, 1))
                print_usage();
 
        radix_tree_init();
 
        printf("WARNING: this utility is deprecated, please use 'btrfs rescue zero-log'\n\n");
 
-       if ((ret = check_mounted(argv[1])) < 0) {
+       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, "ERROR: %s is currently mounted\n", argv[1]);
+               fprintf(stderr, "ERROR: %s is currently mounted\n", argv[optind]);
                ret = -EBUSY;
                goto out;
        }
 
-       root = open_ctree(argv[1], 0, OPEN_CTREE_WRITES | OPEN_CTREE_PARTIAL);
+       root = open_ctree(argv[optind], 0, OPEN_CTREE_WRITES | OPEN_CTREE_PARTIAL);
        if (!root) {
                fprintf(stderr, "ERROR: cannot open ctree\n");
                return 1;
@@ -63,10 +64,11 @@ int main(int argc, char **argv)
 
        sb = root->fs_info->super_copy;
        printf("Clearing log on %s, previous log_root %llu, level %u\n",
-                       argv[1],
+                       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);