2 * Authors: Kent Overstreet <kent.overstreet@gmail.com>
16 #include <sys/types.h>
19 #include <uuid/uuid.h>
22 #include "libbcachefs.h"
23 #include "libbcachefs/opts.h"
24 #include "libbcachefs/super-io.h"
26 static void set_option_usage(void)
28 puts("bcachefs set-option \n"
29 "Usage: bcachefs set-option [OPTION].. device\n"
32 bch2_opts_usage(OPT_MOUNT);
33 puts(" -h, --help display this help and exit\n"
34 "Report bugs to <linux-bcachefs@vger.kernel.org>");
38 int cmd_set_option(int argc, char *argv[])
40 struct bch_opt_strs new_opt_strs = bch2_cmdline_opts_get(&argc, argv, OPT_MOUNT);
41 struct bch_opts new_opts = bch2_parse_opts(new_opt_strs);
42 struct bch_opts open_opts = bch2_opts_empty();
46 opt_set(open_opts, nostart, true);
48 while ((opt = getopt(argc, argv, "h")) != -1)
57 fprintf(stderr, "Please supply device(s)\n");
61 for (i = 0; i < argc; i++)
62 if (dev_mounted(argv[i]))
65 struct bch_fs *c = bch2_fs_open(argv, argc, open_opts);
67 fprintf(stderr, "error opening %s: %s\n", argv[0], strerror(-PTR_ERR(c)));
71 for (i = 0; i < bch2_opts_nr; i++) {
72 u64 v = bch2_opt_get_by_id(&new_opts, i);
74 if (!bch2_opt_defined_by_id(&new_opts, i))
77 ret = bch2_opt_check_may_set(c, i, v);
79 fprintf(stderr, "error setting %s: %i\n",
80 bch2_opt_table[i].attr.name, ret);
84 bch2_opt_set_sb(c, bch2_opt_table + i, v);
85 bch2_opt_set_by_id(&c->opts, i, v);
93 struct bchfs_handle fs = bchu_fs_open_by_dev(argv[i], &dev_idx);
95 for (i = 0; i < bch2_opts_nr; i++) {
96 if (!new_opt_strs.by_id[i])
99 char *path = mprintf("options/%s", bch2_opt_table[i].attr.name);
101 write_file_str(fs.sysfs_fd, path, new_opt_strs.by_id[i]);