]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blame - quota/path.c
xfsprogs: Release v6.7.0
[thirdparty/xfsprogs-dev.git] / quota / path.c
CommitLineData
959ef981 1// SPDX-License-Identifier: GPL-2.0
5aead01d 2/*
da23017d
NS
3 * Copyright (c) 2005 Silicon Graphics, Inc.
4 * All Rights Reserved.
5aead01d
NS
5 */
6
6b803e5a
CH
7#include "command.h"
8#include "input.h"
5aead01d
NS
9#include "init.h"
10#include "quota.h"
11
12static cmdinfo_t path_cmd;
13static cmdinfo_t print_cmd;
14
15static void
16printpath(
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) {
69832389
BD
27 printf(_("%s%sFilesystem Pathname\n"),
28 number ? _(" ") : "",
29 foreign_allowed ? _(" ") : "");
5aead01d 30 }
69832389 31 if (number)
5aead01d 32 printf(_("%c%03d%c "), braces? '[':' ', index, braces? ']':' ');
69832389
BD
33 if (foreign_allowed)
34 printf("%s", (path->fs_flags & FS_FOREIGN) ? "(F) " : " ");
5aead01d
NS
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,
69832389 43 (void *)&qstat) == 0 && qstat.qs_flags) {
5aead01d
NS
44 c = 0;
45 printf(" (");
46 if (qstat.qs_flags & XFS_QUOTA_UDQ_ENFD)
9d473f44 47 c = printf("uquota");
5aead01d 48 else if (qstat.qs_flags & XFS_QUOTA_UDQ_ACCT)
9d473f44 49 c = printf("uqnoenforce");
5aead01d
NS
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)
d0bbcbcb 55 printf("%spquota", c ? ", " : "");
5aead01d 56 else if (qstat.qs_flags & XFS_QUOTA_PDQ_ACCT)
d0bbcbcb 57 printf("%spqnoenforce", c ? ", " : "");
5aead01d
NS
58 printf(")");
59 }
60 printf("\n");
61}
62
63static int
64pathlist_f(void)
65{
66 int i;
bb80e3d6 67 struct fs_path *path;
5aead01d 68
bb80e3d6
BD
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 }
5aead01d
NS
76 return 0;
77}
78
79static int
80print_f(
81 int argc,
82 char **argv)
83{
84 int i;
bb80e3d6 85 struct fs_path *path;
5aead01d 86
bb80e3d6
BD
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 }
5aead01d
NS
93 return 0;
94}
95
96static int
97path_f(
98 int argc,
99 char **argv)
100{
0717a7db 101 int i;
bb80e3d6 102 int max = foreign_allowed ? fs_count : xfs_fs_count;
0717a7db 103
f285712b
BN
104 if (fs_count == 0) {
105 printf(_("No paths are available\n"));
106 return 0;
107 }
108
5aead01d
NS
109 if (argc <= 1)
110 return pathlist_f();
111
0717a7db 112 i = atoi(argv[1]);
bb80e3d6 113 if (i < 0 || i >= max) {
5aead01d 114 printf(_("value %d is out of range (0-%d)\n"),
bb80e3d6 115 i, max - 1);
5aead01d
NS
116 } else {
117 fs_path = &fs_table[i];
118 pathlist_f();
119 }
120 return 0;
121}
122
123void
124path_init(void)
125{
ad765595
AM
126 path_cmd.name = "path";
127 path_cmd.altname = "paths";
5aead01d
NS
128 path_cmd.args = _("[N]");
129 path_cmd.cfunc = path_f;
130 path_cmd.argmin = 0;
131 path_cmd.argmax = 1;
7a9b7314 132 path_cmd.flags = CMD_FLAG_ONESHOT | CMD_FLAG_FOREIGN_OK;
5aead01d
NS
133 path_cmd.oneline = _("set current path, or show the list of paths");
134
ad765595
AM
135 print_cmd.name = "print";
136 print_cmd.altname = "p";
5aead01d
NS
137 print_cmd.cfunc = print_f;
138 print_cmd.argmin = 0;
139 print_cmd.argmax = 0;
7a9b7314 140 print_cmd.flags = CMD_FLAG_ONESHOT | CMD_FLAG_FOREIGN_OK;
5aead01d
NS
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}