]>
Commit | Line | Data |
---|---|---|
1 | // SPDX-License-Identifier: GPL-2.0 | |
2 | /* | |
3 | * Copyright (c) 2005 Silicon Graphics, Inc. | |
4 | * All Rights Reserved. | |
5 | */ | |
6 | ||
7 | #include "command.h" | |
8 | #include "input.h" | |
9 | #include "init.h" | |
10 | #include "quota.h" | |
11 | ||
12 | static cmdinfo_t path_cmd; | |
13 | static cmdinfo_t print_cmd; | |
14 | ||
15 | static void | |
16 | printpath( | |
17 | struct fs_path *path, | |
18 | int index, | |
19 | int number, | |
20 | int braces) | |
21 | { | |
22 | fs_quota_stat_t qstat; | |
23 | fs_project_t *prj; | |
24 | int c; | |
25 | ||
26 | if (index == 0) { | |
27 | printf(_("%s%sFilesystem Pathname\n"), | |
28 | number ? _(" ") : "", | |
29 | foreign_allowed ? _(" ") : ""); | |
30 | } | |
31 | if (number) | |
32 | printf(_("%c%03d%c "), braces? '[':' ', index, braces? ']':' '); | |
33 | if (foreign_allowed) | |
34 | printf("%s", (path->fs_flags & FS_FOREIGN) ? "(F) " : " "); | |
35 | printf(_("%-19s %s"), path->fs_dir, path->fs_name); | |
36 | if (path->fs_flags & FS_PROJECT_PATH) { | |
37 | prj = getprprid(path->fs_prid); | |
38 | printf(_(" (project %u"), path->fs_prid); | |
39 | if (prj) | |
40 | printf(_(", %s"), prj->pr_name); | |
41 | printf(")"); | |
42 | } else if (xfsquotactl(XFS_GETQSTAT, path->fs_name, 0, 0, | |
43 | (void *)&qstat) == 0 && qstat.qs_flags) { | |
44 | c = 0; | |
45 | printf(" ("); | |
46 | if (qstat.qs_flags & XFS_QUOTA_UDQ_ENFD) | |
47 | c = printf("uquota"); | |
48 | else if (qstat.qs_flags & XFS_QUOTA_UDQ_ACCT) | |
49 | c = printf("uqnoenforce"); | |
50 | if (qstat.qs_flags & XFS_QUOTA_GDQ_ENFD) | |
51 | c = printf("%sgquota", c ? ", " : ""); | |
52 | else if (qstat.qs_flags & XFS_QUOTA_GDQ_ACCT) | |
53 | c = printf("%sgqnoenforce", c ? ", " : ""); | |
54 | if (qstat.qs_flags & XFS_QUOTA_PDQ_ENFD) | |
55 | printf("%spquota", c ? ", " : ""); | |
56 | else if (qstat.qs_flags & XFS_QUOTA_PDQ_ACCT) | |
57 | printf("%spqnoenforce", c ? ", " : ""); | |
58 | printf(")"); | |
59 | } | |
60 | printf("\n"); | |
61 | } | |
62 | ||
63 | static int | |
64 | pathlist_f(void) | |
65 | { | |
66 | int i; | |
67 | struct fs_path *path; | |
68 | ||
69 | for (i = 0; i < fs_count; i++) { | |
70 | path = &fs_table[i]; | |
71 | /* Table is ordered xfs first, then foreign */ | |
72 | if (path->fs_flags & FS_FOREIGN && !foreign_allowed) | |
73 | break; | |
74 | printpath(path, i, 1, path == fs_path); | |
75 | } | |
76 | return 0; | |
77 | } | |
78 | ||
79 | static int | |
80 | print_f( | |
81 | int argc, | |
82 | char **argv) | |
83 | { | |
84 | int i; | |
85 | struct fs_path *path; | |
86 | ||
87 | for (i = 0; i < fs_count; i++) { | |
88 | path = &fs_table[i]; | |
89 | if (path->fs_flags & FS_FOREIGN && !foreign_allowed) | |
90 | break; | |
91 | printpath(path, i, 0, 0); | |
92 | } | |
93 | return 0; | |
94 | } | |
95 | ||
96 | static int | |
97 | path_f( | |
98 | int argc, | |
99 | char **argv) | |
100 | { | |
101 | int i; | |
102 | int max = foreign_allowed ? fs_count : xfs_fs_count; | |
103 | ||
104 | if (fs_count == 0) { | |
105 | printf(_("No paths are available\n")); | |
106 | return 0; | |
107 | } | |
108 | ||
109 | if (argc <= 1) | |
110 | return pathlist_f(); | |
111 | ||
112 | i = atoi(argv[1]); | |
113 | if (i < 0 || i >= max) { | |
114 | printf(_("value %d is out of range (0-%d)\n"), | |
115 | i, max - 1); | |
116 | } else { | |
117 | fs_path = &fs_table[i]; | |
118 | pathlist_f(); | |
119 | } | |
120 | return 0; | |
121 | } | |
122 | ||
123 | void | |
124 | path_init(void) | |
125 | { | |
126 | path_cmd.name = "path"; | |
127 | path_cmd.altname = "paths"; | |
128 | path_cmd.args = _("[N]"); | |
129 | path_cmd.cfunc = path_f; | |
130 | path_cmd.argmin = 0; | |
131 | path_cmd.argmax = 1; | |
132 | path_cmd.flags = CMD_FLAG_ONESHOT | CMD_FLAG_FOREIGN_OK; | |
133 | path_cmd.oneline = _("set current path, or show the list of paths"); | |
134 | ||
135 | print_cmd.name = "print"; | |
136 | print_cmd.altname = "p"; | |
137 | print_cmd.cfunc = print_f; | |
138 | print_cmd.argmin = 0; | |
139 | print_cmd.argmax = 0; | |
140 | print_cmd.flags = CMD_FLAG_ONESHOT | CMD_FLAG_FOREIGN_OK; | |
141 | print_cmd.oneline = _("list known mount points and projects"); | |
142 | ||
143 | if (expert) | |
144 | add_command(&path_cmd); | |
145 | add_command(&print_cmd); | |
146 | } |