Deleted Added
full compact
quotacheck.c (175344) quotacheck.c (175678)
1/*
2 * Copyright (c) 1980, 1990, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Robert Elz at The University of Melbourne.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 28 unchanged lines hidden (view full) ---

37 The Regents of the University of California. All rights reserved.\n";
38#endif /* not lint */
39
40#ifndef lint
41static char sccsid[] = "@(#)quotacheck.c 8.3 (Berkeley) 1/29/94";
42#endif /* not lint */
43#endif
44#include <sys/cdefs.h>
1/*
2 * Copyright (c) 1980, 1990, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Robert Elz at The University of Melbourne.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 28 unchanged lines hidden (view full) ---

37 The Regents of the University of California. All rights reserved.\n";
38#endif /* not lint */
39
40#ifndef lint
41static char sccsid[] = "@(#)quotacheck.c 8.3 (Berkeley) 1/29/94";
42#endif /* not lint */
43#endif
44#include <sys/cdefs.h>
45__FBSDID("$FreeBSD: head/sbin/quotacheck/quotacheck.c 175344 2008-01-15 06:33:20Z mpp $");
45__FBSDID("$FreeBSD: head/sbin/quotacheck/quotacheck.c 175678 2008-01-26 12:03:26Z mpp $");
46
47/*
48 * Fix up / report on disk quotas & usage
49 */
50#include <sys/param.h>
51#include <sys/disklabel.h>
52#include <sys/mount.h>
53#include <sys/stat.h>

--- 8 unchanged lines hidden (view full) ---

62#include <fstab.h>
63#include <grp.h>
64#include <pwd.h>
65#include <stdio.h>
66#include <stdlib.h>
67#include <string.h>
68#include <unistd.h>
69
46
47/*
48 * Fix up / report on disk quotas & usage
49 */
50#include <sys/param.h>
51#include <sys/disklabel.h>
52#include <sys/mount.h>
53#include <sys/stat.h>

--- 8 unchanged lines hidden (view full) ---

62#include <fstab.h>
63#include <grp.h>
64#include <pwd.h>
65#include <stdio.h>
66#include <stdlib.h>
67#include <string.h>
68#include <unistd.h>
69
70#include "quotacheck.h"
71
70char *qfname = QUOTAFILENAME;
71char *qfextension[] = INITQFNAMES;
72char *quotagroup = QUOTAGROUP;
73
74union {
75 struct fs sblk;
76 char dummy[MAXBSIZE];
77} sb_un;

--- 9 unchanged lines hidden (view full) ---

87union dinode {
88 struct ufs1_dinode dp1;
89 struct ufs2_dinode dp2;
90};
91#define DIP(dp, field) \
92 ((sblock.fs_magic == FS_UFS1_MAGIC) ? \
93 (dp)->dp1.field : (dp)->dp2.field)
94
72char *qfname = QUOTAFILENAME;
73char *qfextension[] = INITQFNAMES;
74char *quotagroup = QUOTAGROUP;
75
76union {
77 struct fs sblk;
78 char dummy[MAXBSIZE];
79} sb_un;

--- 9 unchanged lines hidden (view full) ---

89union dinode {
90 struct ufs1_dinode dp1;
91 struct ufs2_dinode dp2;
92};
93#define DIP(dp, field) \
94 ((sblock.fs_magic == FS_UFS1_MAGIC) ? \
95 (dp)->dp1.field : (dp)->dp2.field)
96
95struct quotaname {
96 long flags;
97 char grpqfname[PATH_MAX];
98 char usrqfname[PATH_MAX];
99};
100#define HASUSR 1
101#define HASGRP 2
102
103struct fileusage {
104 struct fileusage *fu_next;
105 u_long fu_curinodes;
106 u_long fu_curblocks;
107 u_long fu_id;

--- 8 unchanged lines hidden (view full) ---

116int uflag; /* check user quotas */
117int vflag; /* verbose */
118int fi; /* open disk file descriptor */
119
120struct fileusage *
121 addid(u_long, int, char *, char *);
122char *blockcheck(char *);
123void bread(ufs2_daddr_t, char *, long);
97#define HASUSR 1
98#define HASGRP 2
99
100struct fileusage {
101 struct fileusage *fu_next;
102 u_long fu_curinodes;
103 u_long fu_curblocks;
104 u_long fu_id;

--- 8 unchanged lines hidden (view full) ---

113int uflag; /* check user quotas */
114int vflag; /* verbose */
115int fi; /* open disk file descriptor */
116
117struct fileusage *
118 addid(u_long, int, char *, char *);
119char *blockcheck(char *);
120void bread(ufs2_daddr_t, char *, long);
124extern int checkfstab(int, int, void * (*)(struct fstab *),
125 int (*)(char *, char *, struct quotaname *));
126int chkquota(char *, char *, struct quotaname *);
127void freeinodebuf(void);
128union dinode *
129 getnextinode(ino_t);
130int getquotagid(void);
131int hasquota(struct fstab *, int, char **);
132struct fileusage *
133 lookup(u_long, int);
121void freeinodebuf(void);
122union dinode *
123 getnextinode(ino_t);
124int getquotagid(void);
125int hasquota(struct fstab *, int, char **);
126struct fileusage *
127 lookup(u_long, int);
134void *needchk(struct fstab *);
128struct quotaname *needchk(struct fstab *);
135int oneof(char *, char*[], int);
136void printchanges(char *, int, struct dqblk *, struct fileusage *, u_long);
137void setinodebuf(ino_t);
138int update(char *, char *, int);
139void usage(void);
140
141int
142main(argc, argv)
143 int argc;
144 char *argv[];
145{
146 struct fstab *fs;
147 struct passwd *pw;
148 struct group *gr;
129int oneof(char *, char*[], int);
130void printchanges(char *, int, struct dqblk *, struct fileusage *, u_long);
131void setinodebuf(ino_t);
132int update(char *, char *, int);
133void usage(void);
134
135int
136main(argc, argv)
137 int argc;
138 char *argv[];
139{
140 struct fstab *fs;
141 struct passwd *pw;
142 struct group *gr;
149 struct quotaname *auxdata;
143 struct quotaname *qnp;
150 int i, argnum, maxrun, errs, ch;
151 long done = 0;
152 char *name;
153
154 errs = maxrun = 0;
155 while ((ch = getopt(argc, argv, "aguvl:")) != -1) {
156 switch(ch) {
157 case 'a':

--- 33 unchanged lines hidden (view full) ---

191 if (uflag) {
192 setpwent();
193 while ((pw = getpwent()) != NULL)
194 (void) addid((u_long)pw->pw_uid, USRQUOTA, pw->pw_name,
195 NULL);
196 endpwent();
197 }
198 /*
144 int i, argnum, maxrun, errs, ch;
145 long done = 0;
146 char *name;
147
148 errs = maxrun = 0;
149 while ((ch = getopt(argc, argv, "aguvl:")) != -1) {
150 switch(ch) {
151 case 'a':

--- 33 unchanged lines hidden (view full) ---

185 if (uflag) {
186 setpwent();
187 while ((pw = getpwent()) != NULL)
188 (void) addid((u_long)pw->pw_uid, USRQUOTA, pw->pw_name,
189 NULL);
190 endpwent();
191 }
192 /*
199 * Setting maxrun (-l) makes no sense without the -a flag.
200 * Historically this was never an error, so we just warn.
193 * The maxrun (-l) option is now deprecated.
201 */
194 */
202 if (maxrun > 0 && !aflag)
203 warnx("ignoring -l without -a");
195 if (maxrun > 0)
196 warnx("the -l option is now deprecated");
204 if (aflag)
197 if (aflag)
205 exit(checkfstab(1, maxrun, needchk, chkquota));
198 exit(checkfstab());
206 if (setfsent() == 0)
207 errx(1, "%s: can't open", FSTAB);
208 while ((fs = getfsent()) != NULL) {
209 if (((argnum = oneof(fs->fs_file, argv, argc)) >= 0 ||
210 (argnum = oneof(fs->fs_spec, argv, argc)) >= 0) &&
199 if (setfsent() == 0)
200 errx(1, "%s: can't open", FSTAB);
201 while ((fs = getfsent()) != NULL) {
202 if (((argnum = oneof(fs->fs_file, argv, argc)) >= 0 ||
203 (argnum = oneof(fs->fs_spec, argv, argc)) >= 0) &&
211 (auxdata = needchk(fs)) &&
204 (qnp = needchk(fs)) &&
212 (name = blockcheck(fs->fs_spec))) {
213 done |= 1 << argnum;
205 (name = blockcheck(fs->fs_spec))) {
206 done |= 1 << argnum;
214 errs += chkquota(name, fs->fs_file, auxdata);
207 errs += chkquota(name, fs->fs_file, qnp);
215 }
216 }
217 endfsent();
218 for (i = 0; i < argc; i++)
219 if ((done & (1 << i)) == 0)
220 fprintf(stderr, "%s not found in %s\n",
221 argv[i], FSTAB);
222 exit(errs);
223}
224
225void
226usage()
227{
228 (void)fprintf(stderr, "%s\n%s\n",
229 "usage: quotacheck [-guv] [-l maxrun] -a",
230 " quotacheck [-guv] filesystem ...");
231 exit(1);
232}
233
208 }
209 }
210 endfsent();
211 for (i = 0; i < argc; i++)
212 if ((done & (1 << i)) == 0)
213 fprintf(stderr, "%s not found in %s\n",
214 argv[i], FSTAB);
215 exit(errs);
216}
217
218void
219usage()
220{
221 (void)fprintf(stderr, "%s\n%s\n",
222 "usage: quotacheck [-guv] [-l maxrun] -a",
223 " quotacheck [-guv] filesystem ...");
224 exit(1);
225}
226
234void *
227struct quotaname *
235needchk(fs)
236 struct fstab *fs;
237{
238 struct quotaname *qnp;
239 char *qfnp;
240
241 if (strcmp(fs->fs_vfstype, "ufs") ||
242 strcmp(fs->fs_type, FSTAB_RW))

--- 31 unchanged lines hidden (view full) ---

274 struct fileusage *fup;
275 union dinode *dp;
276 int cg, i, mode, errs = 0;
277 ino_t ino, inosused, userino = 0, groupino = 0;
278 dev_t dev, userdev = 0, groupdev = 0;
279 char *cp;
280 struct stat sb;
281
228needchk(fs)
229 struct fstab *fs;
230{
231 struct quotaname *qnp;
232 char *qfnp;
233
234 if (strcmp(fs->fs_vfstype, "ufs") ||
235 strcmp(fs->fs_type, FSTAB_RW))

--- 31 unchanged lines hidden (view full) ---

267 struct fileusage *fup;
268 union dinode *dp;
269 int cg, i, mode, errs = 0;
270 ino_t ino, inosused, userino = 0, groupino = 0;
271 dev_t dev, userdev = 0, groupdev = 0;
272 char *cp;
273 struct stat sb;
274
275 if (qnp == NULL)
276 err(1, "null quota information passed to chkquota()\n");
282 if ((fi = open(fsname, O_RDONLY, 0)) < 0) {
283 warn("%s", fsname);
284 return (1);
285 }
286 if ((stat(mntpt, &sb)) < 0) {
287 warn("%s", mntpt);
288 return (1);
289 }

--- 556 unchanged lines hidden ---
277 if ((fi = open(fsname, O_RDONLY, 0)) < 0) {
278 warn("%s", fsname);
279 return (1);
280 }
281 if ((stat(mntpt, &sb)) < 0) {
282 warn("%s", mntpt);
283 return (1);
284 }

--- 556 unchanged lines hidden ---