]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blame - quota/path.c
libxcmd: populate fs table with xfs entries first, foreign entries last
[thirdparty/xfsprogs-dev.git] / quota / path.c
CommitLineData
5aead01d 1/*
da23017d
NS
2 * Copyright (c) 2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
5aead01d 4 *
da23017d
NS
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
5aead01d
NS
7 * published by the Free Software Foundation.
8 *
da23017d
NS
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.
5aead01d 13 *
da23017d
NS
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
5aead01d
NS
17 */
18
6b803e5a
CH
19#include "command.h"
20#include "input.h"
5aead01d
NS
21#include "init.h"
22#include "quota.h"
23
24static cmdinfo_t path_cmd;
25static cmdinfo_t print_cmd;
26
27static void
28printpath(
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 }
29647c8d 45 printf("%s ", (path->fs_flags & FS_FOREIGN) ? "(F)" : " ");
5aead01d
NS
46 printf(_("%-19s %s"), path->fs_dir, path->fs_name);
47 if (path->fs_flags & FS_PROJECT_PATH) {
48 prj = getprprid(path->fs_prid);
49 printf(_(" (project %u"), path->fs_prid);
50 if (prj)
51 printf(_(", %s"), prj->pr_name);
52 printf(")");
53 } else if (xfsquotactl(XFS_GETQSTAT, path->fs_name, 0, 0,
54 (void *)&qstat) == 0 && qstat.qs_flags) {
55 c = 0;
56 printf(" (");
57 if (qstat.qs_flags & XFS_QUOTA_UDQ_ENFD)
9d473f44 58 c = printf("uquota");
5aead01d 59 else if (qstat.qs_flags & XFS_QUOTA_UDQ_ACCT)
9d473f44 60 c = printf("uqnoenforce");
5aead01d
NS
61 if (qstat.qs_flags & XFS_QUOTA_GDQ_ENFD)
62 c = printf("%sgquota", c ? ", " : "");
63 else if (qstat.qs_flags & XFS_QUOTA_GDQ_ACCT)
64 c = printf("%sgqnoenforce", c ? ", " : "");
65 if (qstat.qs_flags & XFS_QUOTA_PDQ_ENFD)
d0bbcbcb 66 printf("%spquota", c ? ", " : "");
5aead01d 67 else if (qstat.qs_flags & XFS_QUOTA_PDQ_ACCT)
d0bbcbcb 68 printf("%spqnoenforce", c ? ", " : "");
5aead01d
NS
69 printf(")");
70 }
71 printf("\n");
72}
73
74static int
75pathlist_f(void)
76{
77 int i;
bb80e3d6 78 struct fs_path *path;
5aead01d 79
bb80e3d6
BD
80 for (i = 0; i < fs_count; i++) {
81 path = &fs_table[i];
82 /* Table is ordered xfs first, then foreign */
83 if (path->fs_flags & FS_FOREIGN && !foreign_allowed)
84 break;
85 printpath(path, i, 1, path == fs_path);
86 }
5aead01d
NS
87 return 0;
88}
89
90static int
91print_f(
92 int argc,
93 char **argv)
94{
95 int i;
bb80e3d6 96 struct fs_path *path;
5aead01d 97
bb80e3d6
BD
98 for (i = 0; i < fs_count; i++) {
99 path = &fs_table[i];
100 if (path->fs_flags & FS_FOREIGN && !foreign_allowed)
101 break;
102 printpath(path, i, 0, 0);
103 }
5aead01d
NS
104 return 0;
105}
106
107static int
108path_f(
109 int argc,
110 char **argv)
111{
0717a7db 112 int i;
bb80e3d6 113 int max = foreign_allowed ? fs_count : xfs_fs_count;
0717a7db 114
f285712b
BN
115 if (fs_count == 0) {
116 printf(_("No paths are available\n"));
117 return 0;
118 }
119
5aead01d
NS
120 if (argc <= 1)
121 return pathlist_f();
122
0717a7db 123 i = atoi(argv[1]);
bb80e3d6 124 if (i < 0 || i >= max) {
5aead01d 125 printf(_("value %d is out of range (0-%d)\n"),
bb80e3d6 126 i, max - 1);
5aead01d
NS
127 } else {
128 fs_path = &fs_table[i];
129 pathlist_f();
130 }
131 return 0;
132}
133
134void
135path_init(void)
136{
ad765595
AM
137 path_cmd.name = "path";
138 path_cmd.altname = "paths";
5aead01d
NS
139 path_cmd.args = _("[N]");
140 path_cmd.cfunc = path_f;
141 path_cmd.argmin = 0;
142 path_cmd.argmax = 1;
29647c8d 143 path_cmd.flags = CMD_FLAG_GLOBAL | CMD_FLAG_FOREIGN_OK;
5aead01d
NS
144 path_cmd.oneline = _("set current path, or show the list of paths");
145
ad765595
AM
146 print_cmd.name = "print";
147 print_cmd.altname = "p";
5aead01d
NS
148 print_cmd.cfunc = print_f;
149 print_cmd.argmin = 0;
150 print_cmd.argmax = 0;
29647c8d 151 print_cmd.flags = CMD_FLAG_GLOBAL | CMD_FLAG_FOREIGN_OK;
5aead01d
NS
152 print_cmd.oneline = _("list known mount points and projects");
153
154 if (expert)
155 add_command(&path_cmd);
156 add_command(&print_cmd);
157}