]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - quota/path.c
libxcmd: don't check generic library commands
[thirdparty/xfsprogs-dev.git] / quota / path.c
1 /*
2 * Copyright (c) 2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 #include "command.h"
20 #include "input.h"
21 #include "init.h"
22 #include "quota.h"
23
24 static cmdinfo_t path_cmd;
25 static cmdinfo_t print_cmd;
26
27 static void
28 printpath(
29 struct fs_path *path,
30 int index,
31 int number,
32 int braces)
33 {
34 fs_quota_stat_t qstat;
35 fs_project_t *prj;
36 int c;
37
38 if (index == 0) {
39 printf(_("%s%sFilesystem Pathname\n"),
40 number ? _(" ") : "",
41 foreign_allowed ? _(" ") : "");
42 }
43 if (number)
44 printf(_("%c%03d%c "), braces? '[':' ', index, braces? ']':' ');
45 if (foreign_allowed)
46 printf("%s", (path->fs_flags & FS_FOREIGN) ? "(F) " : " ");
47 printf(_("%-19s %s"), path->fs_dir, path->fs_name);
48 if (path->fs_flags & FS_PROJECT_PATH) {
49 prj = getprprid(path->fs_prid);
50 printf(_(" (project %u"), path->fs_prid);
51 if (prj)
52 printf(_(", %s"), prj->pr_name);
53 printf(")");
54 } else if (xfsquotactl(XFS_GETQSTAT, path->fs_name, 0, 0,
55 (void *)&qstat) == 0 && qstat.qs_flags) {
56 c = 0;
57 printf(" (");
58 if (qstat.qs_flags & XFS_QUOTA_UDQ_ENFD)
59 c = printf("uquota");
60 else if (qstat.qs_flags & XFS_QUOTA_UDQ_ACCT)
61 c = printf("uqnoenforce");
62 if (qstat.qs_flags & XFS_QUOTA_GDQ_ENFD)
63 c = printf("%sgquota", c ? ", " : "");
64 else if (qstat.qs_flags & XFS_QUOTA_GDQ_ACCT)
65 c = printf("%sgqnoenforce", c ? ", " : "");
66 if (qstat.qs_flags & XFS_QUOTA_PDQ_ENFD)
67 printf("%spquota", c ? ", " : "");
68 else if (qstat.qs_flags & XFS_QUOTA_PDQ_ACCT)
69 printf("%spqnoenforce", c ? ", " : "");
70 printf(")");
71 }
72 printf("\n");
73 }
74
75 static int
76 pathlist_f(void)
77 {
78 int i;
79 struct fs_path *path;
80
81 for (i = 0; i < fs_count; i++) {
82 path = &fs_table[i];
83 /* Table is ordered xfs first, then foreign */
84 if (path->fs_flags & FS_FOREIGN && !foreign_allowed)
85 break;
86 printpath(path, i, 1, path == fs_path);
87 }
88 return 0;
89 }
90
91 static int
92 print_f(
93 int argc,
94 char **argv)
95 {
96 int i;
97 struct fs_path *path;
98
99 for (i = 0; i < fs_count; i++) {
100 path = &fs_table[i];
101 if (path->fs_flags & FS_FOREIGN && !foreign_allowed)
102 break;
103 printpath(path, i, 0, 0);
104 }
105 return 0;
106 }
107
108 static int
109 path_f(
110 int argc,
111 char **argv)
112 {
113 int i;
114 int max = foreign_allowed ? fs_count : xfs_fs_count;
115
116 if (fs_count == 0) {
117 printf(_("No paths are available\n"));
118 return 0;
119 }
120
121 if (argc <= 1)
122 return pathlist_f();
123
124 i = atoi(argv[1]);
125 if (i < 0 || i >= max) {
126 printf(_("value %d is out of range (0-%d)\n"),
127 i, max - 1);
128 } else {
129 fs_path = &fs_table[i];
130 pathlist_f();
131 }
132 return 0;
133 }
134
135 void
136 path_init(void)
137 {
138 path_cmd.name = "path";
139 path_cmd.altname = "paths";
140 path_cmd.args = _("[N]");
141 path_cmd.cfunc = path_f;
142 path_cmd.argmin = 0;
143 path_cmd.argmax = 1;
144 path_cmd.flags = CMD_FLAG_ONESHOT | CMD_FLAG_FOREIGN_OK;
145 path_cmd.oneline = _("set current path, or show the list of paths");
146
147 print_cmd.name = "print";
148 print_cmd.altname = "p";
149 print_cmd.cfunc = print_f;
150 print_cmd.argmin = 0;
151 print_cmd.argmax = 0;
152 print_cmd.flags = CMD_FLAG_ONESHOT | CMD_FLAG_FOREIGN_OK;
153 print_cmd.oneline = _("list known mount points and projects");
154
155 if (expert)
156 add_command(&path_cmd);
157 add_command(&print_cmd);
158 }