2 * Copyright (C) 2012 STRATO. 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 #include <sys/ioctl.h>
28 static const char * const quota_cmd_group_usage[] = {
29 "btrfs quota <command> [options] <path>",
33 int quota_ctl(int cmd, int argc, char **argv)
39 struct btrfs_ioctl_quota_ctl_args args;
41 if (check_argc_exact(argc, 2))
44 memset(&args, 0, sizeof(args));
47 fd = open_file_or_dir(path);
49 fprintf(stderr, "ERROR: can't access '%s'\n", path);
53 ret = ioctl(fd, BTRFS_IOC_QUOTA_CTL, &args);
57 fprintf(stderr, "ERROR: quota command failed: %s\n",
64 static const char * const cmd_quota_enable_usage[] = {
65 "btrfs quota enable <path>",
66 "Enable subvolume quota support for a filesystem.",
67 "Any data already present on the filesystem will not count towards",
68 "the space usage numbers. It is recommended to enable quota for a",
69 "filesystem before writing any data to it.",
73 static int cmd_quota_enable(int argc, char **argv)
75 int ret = quota_ctl(BTRFS_QUOTA_CTL_ENABLE, argc, argv);
77 usage(cmd_quota_enable_usage);
81 static const char * const cmd_quota_disable_usage[] = {
82 "btrfs quota disable <path>",
83 "Disable subvolume quota support for a filesystem.",
87 static int cmd_quota_disable(int argc, char **argv)
89 int ret = quota_ctl(BTRFS_QUOTA_CTL_DISABLE, argc, argv);
91 usage(cmd_quota_disable_usage);
95 static const char * const cmd_quota_rescan_usage[] = {
96 "btrfs quota rescan <path>",
97 "Rescan the subvolume for a changed quota setting.",
98 "Not yet implemented.",
102 static int cmd_quota_rescan(int argc, char **argv)
104 int ret = quota_ctl(BTRFS_QUOTA_CTL_RESCAN, argc, argv);
106 usage(cmd_quota_rescan_usage);
110 const struct cmd_group quota_cmd_group = {
111 quota_cmd_group_usage, NULL, {
112 { "enable", cmd_quota_enable, cmd_quota_enable_usage, NULL, 0 },
113 { "disable", cmd_quota_disable, cmd_quota_disable_usage, 0, 0 },
114 { "rescan", cmd_quota_rescan, cmd_quota_rescan_usage, NULL, 0 },
119 int cmd_quota(int argc, char **argv)
121 return handle_command_group("a_cmd_group, argc, argv);