summaryrefslogtreecommitdiff
path: root/extra/quota-tools/quotaon.diff
blob: 6a43cee6ce1afa7f654626371c4cb298a6225fb8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
# Description: Fix quotaon to work with XFS and print all informational messages only in verbose mode
# Author: Jan Kara

diff -u quota/quotaon.c quota-tools/quotaon.c
--- quota/quotaon.c	2010-07-28 11:14:02.000000000 +0200
+++ quota-tools/quotaon.c	2010-06-15 10:11:30.000000000 +0200
@@ -42,6 +42,7 @@
 #include <getopt.h>
 #include <string.h>
 #include <stdlib.h>
+#include <stdarg.h>
 
 #include "quotaon.h"
 #include "quota.h"
@@ -145,6 +146,19 @@
 	}
 }
 
+int pinfo(char *fmt, ...)
+{
+	va_list arg;
+	int ret;
+
+	if (!(flags & FL_VERBOSE))
+		return 0;
+	va_start(arg, fmt);
+	ret = vprintf(fmt, arg);
+	va_end(arg);
+	return ret;
+}
+
 /*
  *	Enable/disable rsquash on given filesystem
  */
@@ -171,10 +185,10 @@
 		errstr(_("set root_squash on %s: %s\n"), quotadev, strerror(errno));
 		return 1;
 	}
-	if ((flags & STATEFLAG_VERBOSE) && (flags & STATEFLAG_OFF))
-		printf(_("%s: %s root_squash turned off\n"), quotadev, type2name(type));
-	else if ((flags & STATEFLAG_VERBOSE) && (flags & STATEFLAG_ON))
-		printf(_("%s: %s root_squash turned on\n"), quotadev, type2name(type));
+	if (flags & STATEFLAG_OFF)
+		pinfo(_("%s: %s root_squash turned off\n"), quotadev, type2name(type));
+	else if (flags & STATEFLAG_ON)
+		pinfo(_("%s: %s root_squash turned on\n"), quotadev, type2name(type));
 #endif
 	return 0;
 }
@@ -195,8 +209,7 @@
 			errstr(_("quotactl on %s [%s]: %s\n"), quotadev, quotadir, strerror(errno));
 			return 1;
 		}
-		if (flags & STATEFLAG_VERBOSE)
-			printf(_("%s [%s]: %s quotas turned off\n"), quotadev, quotadir, type2name(type));
+		pinfo(_("%s [%s]: %s quotas turned off\n"), quotadev, quotadir, type2name(type));
 		return 0;
 	}
 	if (kernel_iface == IFACE_GENERIC) {
@@ -218,8 +231,7 @@
 			errstr(_("Quota format not supported in kernel.\n"));
 		return 1;
 	}
-	if (flags & STATEFLAG_VERBOSE)
-		printf(_("%s [%s]: %s quotas turned on\n"), quotadev, quotadir, type2name(type));
+	pinfo(_("%s [%s]: %s quotas turned on\n"), quotadev, quotadir, type2name(type));
 	return 0;
 }
 
@@ -268,8 +280,6 @@
 	int sflags, ret = 0;
 
 	sflags = flags & FL_OFF ? STATEFLAG_OFF : STATEFLAG_ON;
-	if (flags & FL_VERBOSE)
-		sflags |= STATEFLAG_VERBOSE;
 	if (flags & FL_ALL)
 		sflags |= STATEFLAG_ALL;
 
@@ -281,10 +291,7 @@
 			errstr(_("Cannot change state of XFS quota. It's not compiled in kernel.\n"));
 			return 1;
 		}
-		if ((flags & FL_OFF && (kern_quota_on(mnt->mnt_fsname, USRQUOTA, QF_XFS) != -1
-		    || kern_quota_on(mnt->mnt_fsname, GRPQUOTA, QF_XFS) != -1))
-		    || (!(flags & FL_OFF) && kern_quota_on(mnt->mnt_fsname, type, QF_XFS) == -1))
-			ret = xfs_newstate(mnt, type, extra, sflags);
+		ret = xfs_newstate(mnt, type, extra, sflags);
 	}
 	else if (meta_qf_fstype(mnt->mnt_type)) {
 		if (!hasquota(mnt, type, 0))
@@ -376,7 +383,7 @@
 	while ((mnt = get_next_mount())) {
 		if (nfs_fstype(mnt->mnt_type)) {
 			if (!(flags & FL_ALL))
-				fprintf(stderr, "%s: Quota cannot be turned on on NFS filesystem\n", mnt->mnt_fsname);
+				errstr(_("%s: Quota cannot be turned on on NFS filesystem\n"), mnt->mnt_fsname);
 			continue;
 		}
 
diff -u quota/quotaon.h quota-tools/quotaon.h
--- quota/quotaon.h	2010-02-18 09:44:11.000000000 +0100
+++ quota-tools/quotaon.h	2010-06-12 12:06:08.000000000 +0200
@@ -13,7 +13,7 @@
 #define STATEFLAG_ON		0x01
 #define STATEFLAG_OFF		0x02
 #define STATEFLAG_ALL		0x04
-#define STATEFLAG_VERBOSE	0x08
 
 typedef int (newstate_t) (struct mntent * mnt, int type, char *file, int flags);
 extern int xfs_newstate(struct mntent *mnt, int type, char *file, int flags);
+extern int pinfo(char *fmt, ...);
diff -u quota/quotaon_xfs.c quota-tools/quotaon_xfs.c
--- quota/quotaon_xfs.c	2010-07-26 18:48:24.000000000 +0200
+++ quota-tools/quotaon_xfs.c	2010-06-15 10:11:30.000000000 +0200
@@ -59,8 +59,8 @@
 			    return 1;
 		    case Q_XFS_QUOTAON:
 			    if (roothack) {
-				    printf(_("Enabling %s quota on root filesystem"
-					     " (reboot to take effect)\n"), type2name(type));
+				    pinfo(_("Enabling %s quota on root filesystem"
+					    " (reboot to take effect)\n"), type2name(type));
 				    return 1;
 			    }
 			    errstr(_("Enable XFS %s quota accounting during mount\n"),
@@ -79,12 +79,12 @@
 			    return -1;
 		    case Q_XFS_QUOTAON:
 			    if (roothack) {
-				    printf(_("Enabling %s quota on root filesystem"
-					     " (reboot to take effect)\n"), type2name(type));
+				    pinfo(_("Enabling %s quota on root filesystem"
+					    " (reboot to take effect)\n"), type2name(type));
 				    return 1;
 			    }
 			    if (xopts & XFS_QUOTA_UDQ_ENFD || xopts & XFS_QUOTA_GDQ_ENFD) {
-				    printf(_("Enabling %s quota enforcement on %s\n"), type2name(type), dev);
+				    pinfo(_("Enabling %s quota enforcement on %s\n"), type2name(type), dev);
 				    return 1;
 			    }
 			    errstr(_("Already accounting %s quota on %s\n"),
@@ -92,7 +92,7 @@
 			    return -1;
 		    case Q_XFS_QUOTAOFF:
 			    if (xopts & XFS_QUOTA_UDQ_ACCT || xopts & XFS_QUOTA_GDQ_ACCT) {
-				    printf(_("Disabling %s quota accounting on %s\n"),
+				    pinfo(_("Disabling %s quota accounting on %s\n"),
 					   type2name(type), dev);
 			    	    return 1;
 			    }
@@ -121,9 +121,9 @@
 				    return -1;
 			    }
 			    if (xopts & XFS_QUOTA_UDQ_ACCT || xopts & XFS_QUOTA_GDQ_ACCT)
-			    	    acctstr = _("and accounting ");
-			    printf(_("Disabling %s quota enforcement %son %s\n"),
-				   type2name(type), acctstr, dev);
+		    		    acctstr = _("and accounting ");
+			    pinfo(_("Disabling %s quota enforcement %son %s\n"),
+				  type2name(type), acctstr, dev);
 			    return 1;
 		  }
 		  break;
@@ -146,10 +146,10 @@
 		errstr(_("quotactl on %s: %s\n"), dev, strerror(errno));
 		return 1;
 	}
-	if ((flags & STATEFLAG_VERBOSE) && qoff)
-		printf(_("%s: %s quotas turned off\n"), dev, type2name(type));
-	else if ((flags & STATEFLAG_VERBOSE) && !qoff)
-		printf(_("%s: %s quotas turned on\n"), dev, type2name(type));
+	if (qoff)
+		pinfo(_("%s: %s quotas turned off\n"), dev, type2name(type));
+	else
+		pinfo(_("%s: %s quotas turned on\n"), dev, type2name(type));
 	return 0;
 }
 
@@ -168,8 +168,7 @@
 		return 1;
 	}
 
-	if (flags & STATEFLAG_VERBOSE)
-		printf(_("%s: deleted %s quota blocks\n"), dev, type2name(type));
+	pinfo(_("%s: deleted %s quota blocks\n"), dev, type2name(type));
 	return 0;
 }
 
@@ -208,16 +207,12 @@
 	}
 #endif /* XFS_ROOTHACK */
 
-	if (xarg == NULL) {	/* both acct & enfd on/off */
-		xopts |= (type == USRQUOTA) ?
-			(XFS_QUOTA_UDQ_ACCT | XFS_QUOTA_UDQ_ENFD) :
-			(XFS_QUOTA_GDQ_ACCT | XFS_QUOTA_GDQ_ENFD);
+	if (xarg == NULL) {	/* only enfd on/off */
+		xopts |= (type == USRQUOTA) ? XFS_QUOTA_UDQ_ENFD :
+			XFS_QUOTA_GDQ_ENFD;
 		err = xfs_onoff((char *)dev, type, flags, roothack, xopts);
 	}
 	else if (strcmp(xarg, "account") == 0) {
-		/* only useful if we want root accounting only */
-		if (!roothack || !(flags & STATEFLAG_ON))
-			goto done;
 		xopts |= (type == USRQUOTA) ? XFS_QUOTA_UDQ_ACCT : XFS_QUOTA_GDQ_ACCT;
 		err = xfs_onoff((char *)dev, type, flags, roothack, xopts);
 	}
@@ -231,7 +226,6 @@
 	}
 	else
 		die(1, _("Invalid argument \"%s\"\n"), xarg);
-      done:
 	free((char *)dev);
 	return err;
 }