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 static 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 int enable_extrefs_flag(struct btrfs_root *root)
70 struct btrfs_trans_handle *trans;
71 struct btrfs_super_block *disk_super;
74 disk_super = root->fs_info->super_copy;
75 super_flags = btrfs_super_incompat_flags(disk_super);
76 super_flags |= BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF;
77 trans = btrfs_start_transaction(root, 1);
78 btrfs_set_super_incompat_flags(disk_super, super_flags);
79 btrfs_commit_transaction(trans, root);
84 static int enable_skinny_metadata(struct btrfs_root *root)
86 struct btrfs_trans_handle *trans;
87 struct btrfs_super_block *disk_super;
90 disk_super = root->fs_info->super_copy;
91 super_flags = btrfs_super_incompat_flags(disk_super);
92 super_flags |= BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA;
93 trans = btrfs_start_transaction(root, 1);
94 btrfs_set_super_incompat_flags(disk_super, super_flags);
95 btrfs_commit_transaction(trans, root);
100 static void print_usage(void)
102 fprintf(stderr, "usage: btrfstune [options] device\n");
103 fprintf(stderr, "\t-S value\tenable/disable seeding\n");
104 fprintf(stderr, "\t-r \t\tenable extended inode refs\n");
105 fprintf(stderr, "\t-x enable skinny metadata extent refs\n");
108 int main(int argc, char *argv[])
110 struct btrfs_root *root;
112 int extrefs_flag = 0;
113 int seeding_flag = 0;
114 int seeding_value = 0;
120 int c = getopt(argc, argv, "S:rx");
126 seeding_value = atoi(optarg);
140 argc = argc - optind;
141 device = argv[optind];
147 if (!(seeding_flag + extrefs_flag + skinny_flag)) {
149 "ERROR: At least one option should be assigned.\n");
154 if (check_mounted(device)) {
155 fprintf(stderr, "%s is mounted\n", device);
159 root = open_ctree(device, 0, OPEN_CTREE_WRITES);
162 fprintf(stderr, "Open ctree failed\n");
167 ret = update_seeding_flag(root, seeding_value);
173 enable_extrefs_flag(root);
178 enable_skinny_metadata(root);
185 root->fs_info->readonly = 1;
187 fprintf(stderr, "btrfstune failed\n");