2 * This program is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU General Public
4 * License v2 as published by the Free Software Foundation.
6 * This program is distributed in the hope that it will be useful,
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9 * General Public License for more details.
11 * You should have received a copy of the GNU General Public
12 * License along with this program; if not, write to the
13 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
14 * Boston, MA 021110-1307, USA.
18 #include <sys/ioctl.h>
27 static int prop_read_only(enum prop_object_type type,
36 fd = open(object, O_RDONLY);
39 fprintf(stderr, "ERROR: open %s failed. %s\n",
40 object, strerror(-ret));
44 ret = ioctl(fd, BTRFS_IOC_SUBVOL_GETFLAGS, &flags);
47 fprintf(stderr, "ERROR: failed to get flags for %s. %s\n",
48 object, strerror(-ret));
53 if (flags & BTRFS_SUBVOL_RDONLY)
54 fprintf(stdout, "ro=true\n");
56 fprintf(stdout, "ro=false\n");
61 if (!strcmp(value, "true")) {
62 flags |= BTRFS_SUBVOL_RDONLY;
63 } else if (!strcmp(value, "false")) {
64 flags = flags & ~BTRFS_SUBVOL_RDONLY;
67 fprintf(stderr, "ERROR: invalid value for property.\n");
71 ret = ioctl(fd, BTRFS_IOC_SUBVOL_SETFLAGS, &flags);
74 fprintf(stderr, "ERROR: failed to set flags for %s. %s\n",
75 object, strerror(-ret));
85 static int prop_label(enum prop_object_type type,
93 ret = set_label((char *) object, (char *) value);
95 char label[BTRFS_LABEL_SIZE];
97 ret = get_label((char *) object, label);
99 fprintf(stdout, "label=%s\n", label);
105 const struct prop_handler prop_handlers[] = {
106 {"ro", "Set/get read-only flag of subvolume.", 0, prop_object_subvol,
108 {"label", "Set/get label of device.", 0, prop_object_dev, prop_label},