2 * Copyright (C) 2008 Oracle. All rights reserved.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public
6 * License v2 as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public
14 * License along with this program; if not, write to the
15 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16 * Boston, MA 021110-1307, USA.
19 #define _XOPEN_SOURCE 500
23 #include <sys/types.h>
28 #include "kerncompat.h"
31 #include "transaction.h"
37 int update_seeding_flag(struct btrfs_root *root, int set_flag)
39 struct btrfs_trans_handle *trans;
40 struct btrfs_super_block *disk_super;
43 disk_super = &root->fs_info->super_copy;
44 super_flags = btrfs_super_flags(disk_super);
46 if (super_flags & BTRFS_SUPER_FLAG_SEEDING) {
47 fprintf(stderr, "seeding flag is already set on %s\n",
51 super_flags |= BTRFS_SUPER_FLAG_SEEDING;
53 if (!(super_flags & BTRFS_SUPER_FLAG_SEEDING)) {
54 fprintf(stderr, "seeding flag is not set on %s\n",
58 super_flags &= ~BTRFS_SUPER_FLAG_SEEDING;
61 trans = btrfs_start_transaction(root, 1);
62 btrfs_set_super_flags(disk_super, super_flags);
63 btrfs_commit_transaction(trans, root);
68 static void print_usage(void)
70 fprintf(stderr, "usage: btrfstune [options] device\n");
71 fprintf(stderr, "\t-S value\tenable/disable seeding\n");
74 int main(int argc, char *argv[])
76 struct btrfs_root *root;
79 int seeding_value = 0;
83 int c = getopt(argc, argv, "S:");
89 seeding_value = atoi(optarg);
98 device = argv[optind];
104 if (check_mounted(device)) {
105 fprintf(stderr, "%s is mounted\n", device);
109 root = open_ctree(device, 0, 1);
112 ret = update_seeding_flag(root, seeding_value);
120 root->fs_info->readonly = 1;