int main(int ac, char **av) { struct btrfs_root *root; struct btrfs_trans_handle *trans; int ret; if (ac != 2) print_usage(); radix_tree_init(); if((ret = check_mounted(av[1])) < 0) { fprintf(stderr, "Could not check mount status: %s\n", strerror(-ret)); goto out; } else if(ret) { fprintf(stderr, "%s is currently mounted. Aborting.\n", av[1]); ret = -EBUSY; goto out; } root = open_ctree(av[1], 0, OPEN_CTREE_WRITES); if (root == NULL) return 1; trans = btrfs_start_transaction(root, 1); 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); close_ctree(root); out: return !!ret; }
static int cmd_rescue_zero_log(int argc, char **argv) { struct btrfs_root *root; struct btrfs_trans_handle *trans; struct btrfs_super_block *sb; char *devname; int ret; clean_args_no_options(argc, argv, cmd_rescue_zero_log_usage); if (check_argc_exact(argc, 2)) usage(cmd_rescue_zero_log_usage); devname = argv[optind]; ret = check_mounted(devname); if (ret < 0) { errno = -ret; error("could not check mount status: %m"); goto out; } else if (ret) { error("%s is currently mounted", devname); ret = -EBUSY; goto out; } root = open_ctree(devname, 0, OPEN_CTREE_WRITES | OPEN_CTREE_PARTIAL); if (!root) { error("could not open ctree"); return 1; } sb = root->fs_info->super_copy; printf("Clearing log on %s, previous log_root %llu, level %u\n", devname, (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(sb, 0); btrfs_set_super_log_root_level(sb, 0); btrfs_commit_transaction(trans, root); close_ctree(root); out: return !!ret; }
int main(int ac, char **av) { 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)) print_usage(); radix_tree_init(); printf("WARNING: this utility is deprecated, please use 'btrfs rescue zero-log'\n\n"); if ((ret = check_mounted(av[1])) < 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", av[1]); ret = -EBUSY; goto out; } root = open_ctree(av[1], 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", av[1], (unsigned long long)btrfs_super_log_root(sb), (unsigned)btrfs_super_log_root_level(sb)); trans = btrfs_start_transaction(root, 1); 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); close_ctree(root); out: return !!ret; }