1 From davem@piglet.twiddle.net Tue Apr 13 03:50:39 1999
2 Return-Path: <davem@piglet.twiddle.net>
3 Received: from lacrosse.redhat.com (root@lacrosse.redhat.com [207.175.42.154])
4 by devserv.devel.redhat.com (8.8.7/8.8.7) with ESMTP id DAA25723;
5 Tue, 13 Apr 1999 03:50:37 -0400
6 Received: from mail.redhat.com (mail.redhat.com [199.183.24.239])
7 by lacrosse.redhat.com (8.8.7/8.8.7) with ESMTP id DAA21788;
8 Tue, 13 Apr 1999 03:50:36 -0400
9 Received: from piglet.twiddle.net (davem@piglet.twiddle.net [207.104.6.26])
10 by mail.redhat.com (8.8.7/8.8.7) with ESMTP id DAA09990;
11 Tue, 13 Apr 1999 03:50:34 -0400
12 Received: (from davem@localhost)
13 by piglet.twiddle.net (8.8.7/8.8.7) id AAA27448;
14 Tue, 13 Apr 1999 00:50:34 -0700
15 Date: Tue, 13 Apr 1999 00:50:34 -0700
16 Message-Id: <199904130750.AAA27448@piglet.twiddle.net>
17 X-Authentication-Warning: piglet.twiddle.net: davem set sender to davem@piglet.twiddle.net using -f
18 From: David Miller <davem@twiddle.net>
20 CC: jbj@redhat.com, msw@redhat.com
21 Subject: [PATCH] fix for sparc64 quotas
22 Reply-To: davem@redhat.com
28 Please add this patch to the quota package, it fixes
29 BugZilla BugID 2147. I verified it on sparc and sparc64
30 RH6.0 machines, it should work just fine on other systems as well as
31 the changed behavior is controlled by ifdef __sparc__ checks.
33 I will close that BugID when this goes into a build and I re-verify
34 that it is indeed fixed.
36 --- quota-1.66/utils/dqblk.h.~1~ Tue Apr 13 07:22:43 1999
37 +++ quota-1.66/utils/dqblk.h Tue Apr 13 07:30:59 1999
39 +#if !defined(__sparc__) || defined(__sparc_v9__)
40 +/* We don't want any of this crap on anything other than 32bit sparc userland. */
41 +#define ondisk_dqblk dqblk
42 +#define CONVERT_TO_USER_DQUOT(__d, __s) memcpy((__d), (__s), sizeof(*(__d)))
43 +#define CONVERT_TO_KERNEL_DQUOT(__d, __s) memcpy((__d), (__s), sizeof(*(__d)))
44 +#define DQUOT_CONVERT_INIT() do { } while(0)
45 +#define ondisk_dqblk_size sizeof(struct dqblk)
46 +/* Leave dqoff as is... */
49 +#include <sys/utsname.h>
51 +extern int need_dquot_convert;
53 +#define DQUOT_CONVERT_INIT() \
54 +do { struct utsname name; \
56 + need_dquot_convert = 0; \
57 + ret = uname(&name); \
59 + if(name.machine[5] != '\0') \
60 + need_dquot_convert = 1; \
64 +struct ondisk_dqblk {
65 + u_int32_t dqb_bhardlimit; /* absolute limit on disk blks alloc */
66 + u_int32_t dqb_bsoftlimit; /* preferred limit on disk blks */
67 + u_int32_t dqb_curblocks; /* current block count */
68 + u_int32_t dqb_ihardlimit; /* maximum # allocated inodes */
69 + u_int32_t dqb_isoftlimit; /* preferred inode limit */
70 + u_int32_t dqb_curinodes; /* current # allocated inodes */
71 + u_int64_t dqb_btime; /* time limit for excessive disk use */
72 + u_int64_t dqb_itime; /* time limit for excessive files */
75 +#define ondisk_dqblk_size \
76 + (need_dquot_convert ? \
77 + sizeof(struct ondisk_dqblk) : \
78 + sizeof(struct dqblk))
81 +#define dqoff(__id) ((loff_t) ((__id) * ondisk_dqblk_size))
83 +#define CONVERT_TO_USER_DQUOT(__d, __s) \
84 +do { memcpy((__d), (__s), sizeof(struct dqblk)); \
85 + if(need_dquot_convert != 0) { \
86 + (__d)->dqb_btime = (time_t) (__s)->dqb_btime; \
87 + (__d)->dqb_itime = (time_t) (__s)->dqb_itime; \
91 +#define CONVERT_TO_KERNEL_DQUOT(__d, __s) \
92 +do { memcpy((__d), (__s), ondisk_dqblk_size); \
93 + if(need_dquot_convert != 0) { \
94 + (__d)->dqb_btime = (u_int64_t) (__s)->dqb_btime; \
95 + (__d)->dqb_itime = (u_int64_t) (__s)->dqb_itime; \
100 --- quota-1.66/utils/quota.c.~1~ Tue Apr 13 04:02:15 1999
101 +++ quota-1.66/utils/quota.c Tue Apr 13 07:28:09 1999
108 +int need_dquot_convert;
110 extern char *qfextension[];
115 extern int optind, errno;
117 + DQUOT_CONVERT_INIT();
119 while ((ch = getopt(argc, argv, "ugvqV")) != EOF) {
123 * Initialize unix authentication
125 clnt->cl_auth = authunix_create_default();
126 - clnt_control(clnt, CLSET_TIMEOUT, &timeout);
127 + clnt_control(clnt, CLSET_TIMEOUT, (char *) &timeout);
129 result = rquotaproc_getquota_2(&args.ext_arg, clnt);
130 if (result != NULL && result->status == Q_OK) {
132 * Initialize unix authentication
134 clnt->cl_auth = authunix_create_default();
135 - clnt_control(clnt, CLSET_TIMEOUT, &timeout);
136 + clnt_control(clnt, CLSET_TIMEOUT, (char *) &timeout);
138 result = rquotaproc_getquota_1(&args.arg, clnt);
139 if (result != NULL && result->status == Q_OK) {
142 if (strcmp(mnt->mnt_type, MNTTYPE_NFS)) {
143 if (quotactl(qcmd, mnt->mnt_fsname, id, (caddr_t)&qup->dqblk) != 0) {
144 + struct ondisk_dqblk od_dqblk;
146 if (errno == ENOSYS || errno == ESRCH )
148 if ((fd = open(qfpathname, O_RDONLY)) < 0) {
152 lseek(fd, (long) dqoff(id), L_SET);
153 - switch (read(fd, &qup->dqblk, sizeof(struct dqblk))) {
154 + switch (read(fd, &od_dqblk, ondisk_dqblk_size)) {
157 * Convert implicit 0 quota (EOF) into an
160 memset((caddr_t)&qup->dqblk, 0, sizeof(struct dqblk));
162 - case sizeof(struct dqblk): /* OK */
163 + case sizeof(struct ondisk_dqblk): /* OK */
164 + CONVERT_TO_USER_DQUOT(&qup->dqblk, &od_dqblk);
167 fprintf(stderr, "quota: read error");
168 --- quota-1.66/utils/edquota.c.~1~ Tue Apr 13 04:02:15 1999
169 +++ quota-1.66/utils/edquota.c Tue Apr 13 07:27:52 1999
172 #include "pathnames.h"
176 +int need_dquot_convert;
178 extern char *qfextension[];
179 char *quotagroup = QUOTAGROUP;
180 char tmpfil[] = _PATH_TMP;
183 int tflag = 0, pflag = 0;
185 + DQUOT_CONVERT_INIT();
193 if (quotactl(qcmd, mnt->mnt_fsname, id, (caddr_t) &qup->dqblk) != 0) {
194 + struct ondisk_dqblk od_dqblk;
195 if ((errno == EOPNOTSUPP || errno == ENOSYS || errno == ENOPKG) && !warned) {
197 fprintf(stderr, "Warning: %s\n",
199 (void) fchmod(fd, 0640);
202 - lseek(fd, (long) (id * sizeof(struct dqblk)), L_SET);
203 - switch (read(fd, &qup->dqblk, sizeof(struct dqblk))) {
204 + lseek(fd, (long) dqoff(id), L_SET);
205 + switch (read(fd, &od_dqblk, ondisk_dqblk_size)) {
208 * Convert implicit 0 quota (EOF) into an
210 bzero((caddr_t) & qup->dqblk,
211 sizeof(struct dqblk));
213 - case sizeof(struct dqblk): /* OK */
214 + case sizeof(struct ondisk_dqblk): /* OK */
215 + CONVERT_TO_USER_DQUOT(&qup->dqblk, &od_dqblk);
218 fprintf(stderr, "edquota: read error in ");
220 if ((fd = open(qup->qfname, O_WRONLY)) < 0) {
223 - lseek(fd, (long) id * (long) sizeof(struct dqblk), 0);
224 - if (write(fd, &qup->dqblk, sizeof(struct dqblk)) !=
225 - sizeof(struct dqblk)) {
226 + struct ondisk_dqblk od_dqblk;
228 + CONVERT_TO_KERNEL_DQUOT(&od_dqblk, &qup->dqblk);
229 + lseek(fd, (long) dqoff(id), 0);
230 + if (write(fd, &od_dqblk, ondisk_dqblk_size) !=
231 + ondisk_dqblk_size) {
232 fprintf(stderr, "edquota: ");
235 --- quota-1.66/utils/repquota.c.~1~ Tue Apr 13 04:02:15 1999
236 +++ quota-1.66/utils/repquota.c Tue Apr 13 06:59:57 1999
243 +int need_dquot_convert;
245 extern char *qfextension[];
252 + DQUOT_CONVERT_INIT();
254 while ((ch = getopt(argc, argv, "aguv")) != EOF) {
258 register struct fileusage *fup;
261 + struct ondisk_dqblk od_dqblk;
264 static struct dqblk zerodqblk;
268 for (id = 0;; id++) {
269 - fread(&dqbuf, sizeof(struct dqblk), 1, qf);
270 + fread(&od_dqblk, ondisk_dqblk_size, 1, qf);
273 + CONVERT_TO_USER_DQUOT(&dqbuf, &od_dqblk);
274 if (dqbuf.dqb_curinodes == 0 && dqbuf.dqb_curblocks == 0)
276 if ((fup = lookup(id, type)) == 0)
277 --- quota-1.66/utils/quotacheck.c.~1~ Tue Apr 13 04:02:15 1999
278 +++ quota-1.66/utils/quotacheck.c Tue Apr 13 07:13:01 1999
280 #include <ext2fs/ext2fs.h>
285 +int need_dquot_convert;
287 #define DEF_BLOCKSIZE 1024
288 #define NODQUOT (struct dquot *)NULL
291 char *usr_qfnp, *grp_qfnp;
292 register struct mntent *mnt;
294 + DQUOT_CONVERT_INIT();
296 while ((ch = getopt(argc, argv, "avugdR")) != EOF) {
301 void dump_to_file(char *fsname, char *quotafile, int type)
303 + struct ondisk_dqblk od_dqblk;
307 @@ -635,15 +642,16 @@
308 * quotafile. Only dump new gracetimes when creating a new
311 - if (read(fd, &dq_dqb, sizeof(struct dqblk)) <= 0) {
312 + if (read(fd, &od_dqblk, ondisk_dqblk_size) <= 0) {
313 memset((caddr_t *)&dq_dqb, 0, sizeof(struct dqblk));
314 dq_dqb.dqb_btime = MAX_DQ_TIME;
315 dq_dqb.dqb_itime = MAX_IQ_TIME;
316 - write(fd, &dq_dqb, sizeof(struct dqblk));
317 + CONVERT_TO_KERNEL_DQUOT(&od_dqblk, &dq_dqb);
318 + write(fd, &od_dqblk, ondisk_dqblk_size);
321 if (fstat(fd, &st) == 0) {
322 - max_id = (st.st_size / sizeof(struct dqblk)) - 1;
323 + max_id = (st.st_size / ondisk_dqblk_size) - 1;
324 if (max_id < highestid[type])
325 max_id = highestid[type];
328 for (id = 0; id <= max_id; id++) {
329 memset((caddr_t)&dq_dqb, 0, sizeof(struct dqblk));
331 - if (lseek(fd, dqoff(id), SEEK_SET) == dqoff(id))
332 - read(fd, &dq_dqb, sizeof(struct dqblk));
334 + if (lseek(fd, dqoff(id), SEEK_SET) == dqoff(id)) {
335 + read(fd, &od_dqblk, ondisk_dqblk_size);
336 + CONVERT_TO_USER_DQUOT(&dq_dqb, &od_dqblk);
338 if ((dquot = lookup_dquot(id, type)) != NODQUOT) {
339 dq_curinodes = dquot->dq_curinodes;
340 dq_curblocks = dquot->dq_curblocks;
342 if (quotactl(QCMD(Q_SETUSE, type), fsname, id, (caddr_t)&dq_dqb) == 0)
345 - if (lseek(fd, dqoff(id), SEEK_SET) == dqoff(id))
346 - write(fd, &dq_dqb, sizeof(struct dqblk));
347 + if (lseek(fd, dqoff(id), SEEK_SET) == dqoff(id)) {
348 + CONVERT_TO_KERNEL_DQUOT(&od_dqblk, &dq_dqb);
349 + write(fd, &od_dqblk, ondisk_dqblk_size);
354 --- quota-1.66/utils/rquota_server.c.~1~ Tue Apr 13 04:02:15 1999
355 +++ quota-1.66/utils/rquota_server.c Tue Apr 13 07:28:21 1999
362 #define TYPE_EXTENDED 0x01
366 ext_getquota_args *ext_args;
369 + struct ondisk_dqblk od_dqblk;
372 char *pathname, *devicename, *qfpathname;
374 if ((fd = open(qfpathname, O_RDONLY)) < 0)
376 lseek(fd, (long) dqoff(id), L_SET);
377 - switch (read(fd, &dq_dqb, sizeof(struct dqblk))) {
378 + switch (read(fd, &od_dqblk, ondisk_dqblk_size)) {
381 * Convert implicit 0 quota (EOF) into an
384 memset((caddr_t)&dq_dqb, 0, sizeof(struct dqblk));
386 - case sizeof(struct dqblk): /* OK */
387 + case sizeof(struct ondisk_dqblk): /* OK */
388 + CONVERT_TO_USER_DQUOT(&dq_dqb, &od_dqblk);
392 --- quota-1.66/utils/rquota_svc.c.~1~ Sun Nov 17 08:59:46 1996
393 +++ quota-1.66/utils/rquota_svc.c Tue Apr 13 07:03:30 1999
395 #include <netinet/in.h>
400 +int need_dquot_convert;
403 #define SIG_PF void(*)(int)
406 int main(int argc, char **argv)
408 register SVCXPRT *transp;
410 + DQUOT_CONVERT_INIT();
412 (void) pmap_unset(RQUOTAPROG, RQUOTAVERS);
413 (void) pmap_unset(RQUOTAPROG, EXT_RQUOTAVERS);
414 --- quota-1.66/utils/warnquota.c.~1~ Tue Apr 13 04:02:15 1999
415 +++ quota-1.66/utils/warnquota.c Tue Apr 13 07:10:14 1999
422 +int need_dquot_convert;
424 #define MAIL_CMD "/usr/lib/sendmail -t"
425 #define FROM "support@localhost"
426 #define SUBJECT "Disk Quota usage on system"
428 void read_quotafile(char *qfilename, char *devicename)
431 + struct ondisk_dqblk od_dqblk;
434 if ((fd = open(qfilename, O_RDONLY)) < 0) {
435 @@ -141,10 +146,12 @@
439 - while (read(fd, &dq_dqb, sizeof(struct dqblk)) == sizeof(struct dqblk)) {
440 + while (read(fd, &od_dqblk, ondisk_dqblk_size) == ondisk_dqblk_size) {
441 if ((dq_bsoftlimit && dq_curblocks >= dq_bsoftlimit) ||
442 - (dq_isoftlimit && dq_curinodes >= dq_isoftlimit))
443 + (dq_isoftlimit && dq_curinodes >= dq_isoftlimit)) {
444 + CONVERT_TO_USER_DQUOT(&dq_dqb, &od_dqblk);
445 add_offence(id, devicename, &dq_dqb);
452 main(int argc, char **argv)
454 + DQUOT_CONVERT_INIT();
458 --- quota-1.66/utils/rquota_clnt.c.~1~ Thu Jul 20 11:27:40 1995
459 +++ quota-1.66/utils/rquota_clnt.c Tue Apr 13 07:19:19 1999
461 static getquota_rslt res;
463 bzero((char *)&res, sizeof(res));
464 - if (clnt_call(clnt, RQUOTAPROC_GETQUOTA, xdr_getquota_args, argp, xdr_getquota_rslt, &res, TIMEOUT) != RPC_SUCCESS) {
465 + if (clnt_call(clnt, RQUOTAPROC_GETQUOTA,
466 + (xdrproc_t) xdr_getquota_args,
468 + (xdrproc_t) xdr_getquota_rslt,
469 + (caddr_t) &res, TIMEOUT) != RPC_SUCCESS) {
474 static getquota_rslt res;
476 bzero((char *)&res, sizeof(res));
477 - if (clnt_call(clnt, RQUOTAPROC_GETACTIVEQUOTA, xdr_getquota_args, argp, xdr_getquota_rslt, &res, TIMEOUT) != RPC_SUCCESS) {
478 + if (clnt_call(clnt, RQUOTAPROC_GETACTIVEQUOTA,
479 + (xdrproc_t) xdr_getquota_args,
481 + (xdrproc_t) xdr_getquota_rslt,
482 + (caddr_t) &res, TIMEOUT) != RPC_SUCCESS) {
487 static getquota_rslt res;
489 bzero((char *)&res, sizeof(res));
490 - if (clnt_call(clnt, RQUOTAPROC_GETQUOTA, xdr_ext_getquota_args, argp, xdr_getquota_rslt, &res, TIMEOUT) != RPC_SUCCESS) {
491 + if (clnt_call(clnt, RQUOTAPROC_GETQUOTA,
492 + (xdrproc_t) xdr_ext_getquota_args,
494 + (xdrproc_t) xdr_getquota_rslt,
495 + (caddr_t) &res, TIMEOUT) != RPC_SUCCESS) {
500 static getquota_rslt res;
502 bzero((char *)&res, sizeof(res));
503 - if (clnt_call(clnt, RQUOTAPROC_GETACTIVEQUOTA, xdr_ext_getquota_args, argp, xdr_getquota_rslt, &res, TIMEOUT) != RPC_SUCCESS) {
504 + if (clnt_call(clnt, RQUOTAPROC_GETACTIVEQUOTA,
505 + (xdrproc_t) xdr_ext_getquota_args,
507 + (xdrproc_t) xdr_getquota_rslt,
508 + (caddr_t) &res, TIMEOUT) != RPC_SUCCESS) {