]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - quota/path.c
Update copyright/license notices to match SGI legal prefered boilerplate.
[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 <xfs/command.h>
20 #include <xfs/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(_("%sFilesystem Pathname\n"),
40 number ? _(" ") : "");
41 }
42 if (number) {
43 printf(_("%c%03d%c "), braces? '[':' ', index, braces? ']':' ');
44 }
45 printf(_("%-19s %s"), path->fs_dir, path->fs_name);
46 if (path->fs_flags & FS_PROJECT_PATH) {
47 prj = getprprid(path->fs_prid);
48 printf(_(" (project %u"), path->fs_prid);
49 if (prj)
50 printf(_(", %s"), prj->pr_name);
51 printf(")");
52 } else if (xfsquotactl(XFS_GETQSTAT, path->fs_name, 0, 0,
53 (void *)&qstat) == 0 && qstat.qs_flags) {
54 c = 0;
55 printf(" (");
56 if (qstat.qs_flags & XFS_QUOTA_UDQ_ENFD)
57 c = printf("%suquota", c ? ", " : "");
58 else if (qstat.qs_flags & XFS_QUOTA_UDQ_ACCT)
59 c = printf("%suqnoenforce", c ? ", " : "");
60 if (qstat.qs_flags & XFS_QUOTA_GDQ_ENFD)
61 c = printf("%sgquota", c ? ", " : "");
62 else if (qstat.qs_flags & XFS_QUOTA_GDQ_ACCT)
63 c = printf("%sgqnoenforce", c ? ", " : "");
64 if (qstat.qs_flags & XFS_QUOTA_PDQ_ENFD)
65 c = printf("%spquota", c ? ", " : "");
66 else if (qstat.qs_flags & XFS_QUOTA_PDQ_ACCT)
67 c = printf("%spqnoenforce", c ? ", " : "");
68 printf(")");
69 }
70 printf("\n");
71 }
72
73 static int
74 pathlist_f(void)
75 {
76 int i;
77
78 for (i = 0; i < fs_count; i++)
79 printpath(&fs_table[i], i, 1, &fs_table[i] == fs_path);
80 return 0;
81 }
82
83 static int
84 print_f(
85 int argc,
86 char **argv)
87 {
88 int i;
89
90 for (i = 0; i < fs_count; i++)
91 printpath(&fs_table[i], i, 0, 0);
92 return 0;
93 }
94
95 static int
96 path_f(
97 int argc,
98 char **argv)
99 {
100 int i;
101
102 if (argc <= 1)
103 return pathlist_f();
104
105 i = atoi(argv[1]);
106 if (i < 0 || i >= fs_count) {
107 printf(_("value %d is out of range (0-%d)\n"),
108 i, fs_count-1);
109 } else {
110 fs_path = &fs_table[i];
111 pathlist_f();
112 }
113 return 0;
114 }
115
116 void
117 path_init(void)
118 {
119 path_cmd.name = _("path");
120 path_cmd.altname = _("paths");
121 path_cmd.args = _("[N]");
122 path_cmd.cfunc = path_f;
123 path_cmd.argmin = 0;
124 path_cmd.argmax = 1;
125 path_cmd.oneline = _("set current path, or show the list of paths");
126
127 print_cmd.name = _("print");
128 print_cmd.altname = _("p");
129 print_cmd.cfunc = print_f;
130 print_cmd.argmin = 0;
131 print_cmd.argmax = 0;
132 print_cmd.oneline = _("list known mount points and projects");
133
134 if (expert)
135 add_command(&path_cmd);
136 add_command(&print_cmd);
137 }