Drag this code kicking and screaming into the twenty-first century.
This commit is contained in:
parent
397b67d93b
commit
7ea4b30a5a
@ -57,17 +57,17 @@ __RCSID("$NetBSD: preen.c,v 1.18 1998/07/26 20:02:36 mycroft Exp $");
|
||||
|
||||
struct partentry {
|
||||
TAILQ_ENTRY(partentry) p_entries;
|
||||
char *p_devname; /* device name */
|
||||
char *p_devname; /* device name */
|
||||
char *p_mntpt; /* mount point */
|
||||
char *p_type; /* file system type */
|
||||
char *p_type; /* file system type */
|
||||
struct quotaname *p_quota; /* quota file info ptr */
|
||||
};
|
||||
|
||||
TAILQ_HEAD(part, partentry) badh;
|
||||
|
||||
struct diskentry {
|
||||
TAILQ_ENTRY(diskentry) d_entries;
|
||||
char *d_name; /* disk base name */
|
||||
TAILQ_ENTRY(diskentry) d_entries;
|
||||
char *d_name; /* disk base name */
|
||||
TAILQ_HEAD(prt, partentry) d_part; /* list of partitions on disk */
|
||||
int d_pid; /* 0 or pid of fsck proc */
|
||||
};
|
||||
@ -82,7 +82,7 @@ extern void *emalloc(size_t);
|
||||
extern char *estrdup(const char *);
|
||||
|
||||
int
|
||||
checkfstab()
|
||||
checkfstab(void)
|
||||
{
|
||||
struct fstab *fs;
|
||||
struct diskentry *d, *nextdisk;
|
||||
@ -120,7 +120,7 @@ checkfstab()
|
||||
if (sumstatus)
|
||||
return (sumstatus);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (name == NULL) {
|
||||
(void) fprintf(stderr,
|
||||
"BAD DISK NAME %s\n", fs->fs_spec);
|
||||
@ -139,7 +139,7 @@ checkfstab()
|
||||
}
|
||||
|
||||
while ((pid = wait(&status)) != -1) {
|
||||
TAILQ_FOREACH(d, &diskh, d_entries)
|
||||
TAILQ_FOREACH(d, &diskh, d_entries)
|
||||
if (d->d_pid == pid)
|
||||
break;
|
||||
|
||||
@ -226,7 +226,7 @@ finddisk(const char *name)
|
||||
if (len == 0)
|
||||
len = strlen(name);
|
||||
|
||||
TAILQ_FOREACH(d, &diskh, d_entries)
|
||||
TAILQ_FOREACH(d, &diskh, d_entries)
|
||||
if (strncmp(d->d_name, name, len) == 0 && d->d_name[len] == 0)
|
||||
return d;
|
||||
|
||||
|
@ -133,9 +133,7 @@ int update(char *, char *, int);
|
||||
void usage(void);
|
||||
|
||||
int
|
||||
main(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
struct fstab *fs;
|
||||
struct passwd *pw;
|
||||
@ -216,17 +214,16 @@ main(argc, argv)
|
||||
}
|
||||
|
||||
void
|
||||
usage()
|
||||
usage(void)
|
||||
{
|
||||
(void)fprintf(stderr, "%s\n%s\n",
|
||||
(void)fprintf(stderr, "%s\n%s\n",
|
||||
"usage: quotacheck [-guv] [-l maxrun] -a",
|
||||
" quotacheck [-guv] filesystem ...");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
struct quotaname *
|
||||
needchk(fs)
|
||||
struct fstab *fs;
|
||||
needchk(struct fstab *fs)
|
||||
{
|
||||
struct quotaname *qnp;
|
||||
char *qfnp;
|
||||
@ -260,9 +257,7 @@ static int sblock_try[] = SBLOCKSEARCH;
|
||||
* Scan the specified file system to check quota(s) present on it.
|
||||
*/
|
||||
int
|
||||
chkquota(fsname, mntpt, qnp)
|
||||
char *fsname, *mntpt;
|
||||
struct quotaname *qnp;
|
||||
chkquota(char *fsname, char *mntpt, struct quotaname *qnp)
|
||||
{
|
||||
struct fileusage *fup;
|
||||
union dinode *dp;
|
||||
@ -363,7 +358,7 @@ chkquota(fsname, mntpt, qnp)
|
||||
* to be negative to prevent generating 100GB+
|
||||
* quota files.
|
||||
*/
|
||||
if ((int)DIP(dp, di_uid) < 0 ||
|
||||
if ((int)DIP(dp, di_uid) < 0 ||
|
||||
(int)DIP(dp, di_gid) < 0) {
|
||||
if (vflag) {
|
||||
if (aflag)
|
||||
@ -375,7 +370,7 @@ chkquota(fsname, mntpt, qnp)
|
||||
continue;
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
* Do not account for file system snapshot files
|
||||
* or the actual quota data files to be consistent
|
||||
* with how they are handled inside the kernel.
|
||||
@ -419,9 +414,7 @@ chkquota(fsname, mntpt, qnp)
|
||||
* Update a specified quota file.
|
||||
*/
|
||||
int
|
||||
update(fsname, quotafile, type)
|
||||
char *fsname, *quotafile;
|
||||
int type;
|
||||
update(char *fsname, char *quotafile, int type)
|
||||
{
|
||||
struct fileusage *fup;
|
||||
FILE *qfi, *qfo;
|
||||
@ -475,7 +468,7 @@ update(fsname, quotafile, type)
|
||||
lastid = (sb.st_size / sizeof(struct dqblk)) - 1;
|
||||
else
|
||||
lastid = 0;
|
||||
for (id = 0, offset = 0; id <= lastid;
|
||||
for (id = 0, offset = 0; id <= lastid;
|
||||
id++, offset += sizeof(struct dqblk)) {
|
||||
if (fread((char *)&dqbuf, sizeof(struct dqblk), 1, qfi) == 0)
|
||||
dqbuf = zerodqbuf;
|
||||
@ -542,7 +535,7 @@ update(fsname, quotafile, type)
|
||||
}
|
||||
fwrite((char *)&dqbuf, sizeof(struct dqblk), 1, qfo);
|
||||
(void) quotactl(fsname, QCMD(Q_SETUSE, type), id,
|
||||
(caddr_t)&dqbuf);
|
||||
(caddr_t)&dqbuf);
|
||||
fup->fu_curinodes = 0;
|
||||
fup->fu_curblocks = 0;
|
||||
}
|
||||
@ -559,9 +552,7 @@ update(fsname, quotafile, type)
|
||||
* Check to see if target appears in list of size cnt.
|
||||
*/
|
||||
int
|
||||
oneof(target, list, cnt)
|
||||
char *target, *list[];
|
||||
int cnt;
|
||||
oneof(char *target, char *list[], int cnt)
|
||||
{
|
||||
int i;
|
||||
|
||||
@ -575,7 +566,7 @@ oneof(target, list, cnt)
|
||||
* Determine the group identifier for quota files.
|
||||
*/
|
||||
int
|
||||
getquotagid()
|
||||
getquotagid(void)
|
||||
{
|
||||
struct group *gr;
|
||||
|
||||
@ -588,10 +579,7 @@ getquotagid()
|
||||
* Check to see if a particular quota is to be enabled.
|
||||
*/
|
||||
int
|
||||
hasquota(fs, type, qfnamep)
|
||||
struct fstab *fs;
|
||||
int type;
|
||||
char **qfnamep;
|
||||
hasquota(struct fstab *fs, int type, char **qfnamep)
|
||||
{
|
||||
char *opt;
|
||||
char *cp;
|
||||
@ -642,9 +630,7 @@ hasquota(fs, type, qfnamep)
|
||||
* Lookup an id of a specific type.
|
||||
*/
|
||||
struct fileusage *
|
||||
lookup(id, type)
|
||||
u_long id;
|
||||
int type;
|
||||
lookup(u_long id, int type)
|
||||
{
|
||||
struct fileusage *fup;
|
||||
|
||||
@ -658,11 +644,7 @@ lookup(id, type)
|
||||
* Add a new file usage id if it does not already exist.
|
||||
*/
|
||||
struct fileusage *
|
||||
addid(id, type, name, fsname)
|
||||
u_long id;
|
||||
int type;
|
||||
char *name;
|
||||
char *fsname;
|
||||
addid(u_long id, int type, char *name, char *fsname)
|
||||
{
|
||||
struct fileusage *fup, **fhp;
|
||||
int len;
|
||||
@ -686,7 +668,7 @@ addid(id, type, name, fsname)
|
||||
if (vflag) {
|
||||
if (aflag && fsname != NULL)
|
||||
(void)printf("%s: ", fsname);
|
||||
printf("unknown %cid: %lu\n",
|
||||
printf("unknown %cid: %lu\n",
|
||||
type == USRQUOTA ? 'u' : 'g', id);
|
||||
}
|
||||
}
|
||||
@ -773,7 +755,7 @@ setinodebuf(ino_t inum)
|
||||
* Free up data structures used to scan inodes.
|
||||
*/
|
||||
void
|
||||
freeinodebuf()
|
||||
freeinodebuf(void)
|
||||
{
|
||||
|
||||
if (inodebuf != NULL)
|
||||
@ -785,10 +767,7 @@ freeinodebuf()
|
||||
* Read specified disk blocks.
|
||||
*/
|
||||
void
|
||||
bread(bno, buf, cnt)
|
||||
ufs2_daddr_t bno;
|
||||
char *buf;
|
||||
long cnt;
|
||||
bread(ufs2_daddr_t bno, char *buf, long cnt)
|
||||
{
|
||||
|
||||
if (lseek(fi, (off_t)bno * dev_bsize, SEEK_SET) < 0 ||
|
||||
@ -800,12 +779,8 @@ bread(bno, buf, cnt)
|
||||
* Display updated block and i-node counts.
|
||||
*/
|
||||
void
|
||||
printchanges(fsname, type, dp, fup, id)
|
||||
char *fsname;
|
||||
int type;
|
||||
struct dqblk *dp;
|
||||
struct fileusage *fup;
|
||||
u_long id;
|
||||
printchanges(char *fsname, int type, struct dqblk *dp,
|
||||
struct fileusage *fup, u_long id)
|
||||
{
|
||||
if (!vflag)
|
||||
return;
|
||||
@ -833,7 +808,7 @@ printchanges(fsname, type, dp, fup, id)
|
||||
(void)printf("\tinodes %lu -> %lu", (u_long)dp->dqb_curinodes,
|
||||
(u_long)fup->fu_curinodes);
|
||||
if (dp->dqb_curblocks != fup->fu_curblocks)
|
||||
(void)printf("\tblocks %lu -> %lu",
|
||||
(void)printf("\tblocks %lu -> %lu",
|
||||
(u_long)dp->dqb_curblocks,
|
||||
(u_long)fup->fu_curblocks);
|
||||
(void)printf("\n");
|
||||
|
@ -98,7 +98,7 @@ int writetimes(struct quotause *, int, int);
|
||||
int writeprivs(struct quotause *, int, char *, int);
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
struct quotause *qup, *protoprivs, *curprivs;
|
||||
long id, protoid;
|
||||
@ -245,7 +245,7 @@ main(int argc, char **argv)
|
||||
curprivs->fsname);
|
||||
}
|
||||
}
|
||||
putprivs(id, quotatype, protoprivs);
|
||||
putprivs(id, quotatype, protoprivs);
|
||||
}
|
||||
}
|
||||
exit(0);
|
||||
@ -279,7 +279,7 @@ main(int argc, char **argv)
|
||||
}
|
||||
|
||||
static void
|
||||
usage()
|
||||
usage(void)
|
||||
{
|
||||
fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n",
|
||||
"usage: edquota [-u] [-f fspath] [-p username] username ...",
|
||||
@ -299,9 +299,7 @@ usage()
|
||||
* getinoquota as to the interpretation of quota types.
|
||||
*/
|
||||
int
|
||||
getentry(name, quotatype)
|
||||
const char *name;
|
||||
int quotatype;
|
||||
getentry(const char *name, int quotatype)
|
||||
{
|
||||
struct passwd *pw;
|
||||
struct group *gr;
|
||||
@ -331,13 +329,10 @@ getentry(name, quotatype)
|
||||
* Collect the requested quota information.
|
||||
*/
|
||||
struct quotause *
|
||||
getprivs(id, quotatype, fspath)
|
||||
register long id;
|
||||
int quotatype;
|
||||
char *fspath;
|
||||
getprivs(long id, int quotatype, char *fspath)
|
||||
{
|
||||
register struct fstab *fs;
|
||||
register struct quotause *qup, *quptail;
|
||||
struct fstab *fs;
|
||||
struct quotause *qup, *quptail;
|
||||
struct quotause *quphead;
|
||||
int qcmd, qupsize, fd;
|
||||
char *qfpathname;
|
||||
@ -358,7 +353,7 @@ getprivs(id, quotatype, fspath)
|
||||
if ((qup = (struct quotause *)malloc(qupsize)) == NULL)
|
||||
errx(2, "out of memory");
|
||||
if (quotactl(fs->fs_file, qcmd, id, &qup->dqblk) != 0) {
|
||||
if (errno == EOPNOTSUPP && !warned) {
|
||||
if (errno == EOPNOTSUPP && !warned) {
|
||||
warned++;
|
||||
warnx("warning: quotas are not compiled into this kernel");
|
||||
sleep(3);
|
||||
@ -421,12 +416,9 @@ getprivs(id, quotatype, fspath)
|
||||
* Store the requested quota information.
|
||||
*/
|
||||
void
|
||||
putprivs(id, quotatype, quplist)
|
||||
long id;
|
||||
int quotatype;
|
||||
struct quotause *quplist;
|
||||
putprivs(long id, int quotatype, struct quotause *quplist)
|
||||
{
|
||||
register struct quotause *qup;
|
||||
struct quotause *qup;
|
||||
int qcmd, fd;
|
||||
struct dqblk dqbuf;
|
||||
|
||||
@ -463,7 +455,7 @@ putprivs(id, quotatype, quplist)
|
||||
/*
|
||||
* Reset time limit if have a soft limit and were
|
||||
* previously under it, but are now over it
|
||||
* or if there previously was no soft limit, but
|
||||
* or if there previously was no soft limit, but
|
||||
* now have one and are over it.
|
||||
*/
|
||||
if (dqbuf.dqb_bsoftlimit && id != 0 &&
|
||||
@ -499,8 +491,7 @@ putprivs(id, quotatype, quplist)
|
||||
* Take a list of priviledges and get it edited.
|
||||
*/
|
||||
int
|
||||
editit(tmpf)
|
||||
char *tmpf;
|
||||
editit(char *tmpf)
|
||||
{
|
||||
long omask;
|
||||
int pid, status;
|
||||
@ -521,7 +512,7 @@ editit(tmpf)
|
||||
return (0);
|
||||
}
|
||||
if (pid == 0) {
|
||||
register const char *ed;
|
||||
const char *ed;
|
||||
|
||||
sigsetmask(omask);
|
||||
setgid(getgid());
|
||||
@ -542,13 +533,9 @@ editit(tmpf)
|
||||
* Convert a quotause list to an ASCII file.
|
||||
*/
|
||||
int
|
||||
writeprivs(quplist, outfd, name, quotatype)
|
||||
struct quotause *quplist;
|
||||
int outfd;
|
||||
char *name;
|
||||
int quotatype;
|
||||
writeprivs(struct quotause *quplist, int outfd, char *name, int quotatype)
|
||||
{
|
||||
register struct quotause *qup;
|
||||
struct quotause *qup;
|
||||
FILE *fd;
|
||||
|
||||
ftruncate(outfd, 0);
|
||||
@ -576,16 +563,14 @@ writeprivs(quplist, outfd, name, quotatype)
|
||||
* Merge changes to an ASCII file into a quotause list.
|
||||
*/
|
||||
int
|
||||
readprivs(quplist, inname)
|
||||
struct quotause *quplist;
|
||||
char *inname;
|
||||
readprivs(struct quotause *quplist, char *inname)
|
||||
{
|
||||
register struct quotause *qup;
|
||||
struct quotause *qup;
|
||||
FILE *fd;
|
||||
unsigned long bhardlimit, bsoftlimit, curblocks;
|
||||
unsigned long ihardlimit, isoftlimit, curinodes;
|
||||
int cnt;
|
||||
register char *cp;
|
||||
char *cp;
|
||||
struct dqblk dqblk;
|
||||
char *fsp, line1[BUFSIZ], line2[BUFSIZ];
|
||||
|
||||
@ -686,12 +671,9 @@ readprivs(quplist, inname)
|
||||
* Convert a quotause list to an ASCII file of grace times.
|
||||
*/
|
||||
int
|
||||
writetimes(quplist, outfd, quotatype)
|
||||
struct quotause *quplist;
|
||||
int outfd;
|
||||
int quotatype;
|
||||
writetimes(struct quotause *quplist, int outfd, int quotatype)
|
||||
{
|
||||
register struct quotause *qup;
|
||||
struct quotause *qup;
|
||||
FILE *fd;
|
||||
|
||||
ftruncate(outfd, 0);
|
||||
@ -715,14 +697,12 @@ writetimes(quplist, outfd, quotatype)
|
||||
* Merge changes of grace times in an ASCII file into a quotause list.
|
||||
*/
|
||||
int
|
||||
readtimes(quplist, inname)
|
||||
struct quotause *quplist;
|
||||
char *inname;
|
||||
readtimes(struct quotause *quplist, char *inname)
|
||||
{
|
||||
register struct quotause *qup;
|
||||
struct quotause *qup;
|
||||
FILE *fd;
|
||||
int cnt;
|
||||
register char *cp;
|
||||
char *cp;
|
||||
time_t itime, btime, iseconds, bseconds;
|
||||
long l_itime, l_btime;
|
||||
char *fsp, bunits[10], iunits[10], line1[BUFSIZ];
|
||||
@ -788,8 +768,7 @@ readtimes(quplist, inname)
|
||||
* Convert seconds to ASCII times.
|
||||
*/
|
||||
char *
|
||||
cvtstoa(secs)
|
||||
time_t secs;
|
||||
cvtstoa(time_t secs)
|
||||
{
|
||||
static char buf[20];
|
||||
|
||||
@ -811,10 +790,7 @@ cvtstoa(secs)
|
||||
* Convert ASCII input times to seconds.
|
||||
*/
|
||||
int
|
||||
cvtatos(period, units, seconds)
|
||||
time_t period;
|
||||
char *units;
|
||||
time_t *seconds;
|
||||
cvtatos(time_t period, char *units, time_t *seconds)
|
||||
{
|
||||
|
||||
if (bcmp(units, "second", 6) == 0)
|
||||
@ -837,10 +813,9 @@ cvtatos(period, units, seconds)
|
||||
* Free a list of quotause structures.
|
||||
*/
|
||||
void
|
||||
freeprivs(quplist)
|
||||
struct quotause *quplist;
|
||||
freeprivs(struct quotause *quplist)
|
||||
{
|
||||
register struct quotause *qup, *nextqup;
|
||||
struct quotause *qup, *nextqup;
|
||||
|
||||
for (qup = quplist; qup; qup = nextqup) {
|
||||
nextqup = qup->next;
|
||||
@ -852,10 +827,9 @@ freeprivs(quplist)
|
||||
* Check whether a string is completely composed of digits.
|
||||
*/
|
||||
int
|
||||
alldigits(s)
|
||||
register const char *s;
|
||||
alldigits(const char *s)
|
||||
{
|
||||
register int c;
|
||||
int c;
|
||||
|
||||
c = *s++;
|
||||
do {
|
||||
@ -869,10 +843,7 @@ alldigits(s)
|
||||
* Check to see if a particular quota is to be enabled.
|
||||
*/
|
||||
int
|
||||
hasquota(fs, type, qfnamep)
|
||||
struct fstab *fs;
|
||||
int type;
|
||||
char **qfnamep;
|
||||
hasquota(struct fstab *fs, int type, char **qfnamep)
|
||||
{
|
||||
char *opt;
|
||||
char *cp;
|
||||
|
@ -106,17 +106,14 @@ union dinode {
|
||||
(dp)->dp1.field : (dp)->dp2.field)
|
||||
|
||||
static union dinode *
|
||||
get_inode(fd,super,ino)
|
||||
int fd;
|
||||
struct fs *super;
|
||||
ino_t ino;
|
||||
get_inode(int fd, struct fs *super, ino_t ino)
|
||||
{
|
||||
static caddr_t ipbuf;
|
||||
static struct cg *cgp;
|
||||
static ino_t last;
|
||||
static int cg;
|
||||
struct ufs2_dinode *di2;
|
||||
|
||||
|
||||
if (fd < 0) { /* flush cache */
|
||||
if (ipbuf) {
|
||||
free(ipbuf);
|
||||
@ -128,7 +125,7 @@ get_inode(fd,super,ino)
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
if (!ipbuf || ino < last || ino >= last + INOCNT(super)) {
|
||||
if (super->fs_magic == FS_UFS2_MAGIC &&
|
||||
(!cgp || cg != ino_to_cg(super, ino))) {
|
||||
@ -150,7 +147,7 @@ get_inode(fd,super,ino)
|
||||
|| read(fd, ipbuf, INOSZ(super)) != (ssize_t)INOSZ(super))
|
||||
err(1, "read inodes");
|
||||
}
|
||||
|
||||
|
||||
if (super->fs_magic == FS_UFS1_MAGIC)
|
||||
return ((union dinode *)
|
||||
&((struct ufs1_dinode *)ipbuf)[ino % INOCNT(super)]);
|
||||
@ -167,12 +164,10 @@ get_inode(fd,super,ino)
|
||||
#define actualblocks(fs, dp) DIP(fs, dp, di_blocks)
|
||||
#endif
|
||||
|
||||
static int virtualblocks(super, dp)
|
||||
struct fs *super;
|
||||
union dinode *dp;
|
||||
static int virtualblocks(struct fs *super, union dinode *dp)
|
||||
{
|
||||
register off_t nblk, sz;
|
||||
|
||||
off_t nblk, sz;
|
||||
|
||||
sz = DIP(super, dp, di_size);
|
||||
#ifdef COMPAT
|
||||
if (lblkno(super,sz) >= NDADDR) {
|
||||
@ -180,11 +175,11 @@ static int virtualblocks(super, dp)
|
||||
if (sz == nblk)
|
||||
nblk += super->fs_bsize;
|
||||
}
|
||||
|
||||
|
||||
return sz / 1024;
|
||||
|
||||
|
||||
#else /* COMPAT */
|
||||
|
||||
|
||||
if (lblkno(super,sz) >= NDADDR) {
|
||||
nblk = blkroundup(super,sz);
|
||||
sz = lblkno(super,nblk);
|
||||
@ -196,20 +191,18 @@ static int virtualblocks(super, dp)
|
||||
}
|
||||
} else
|
||||
nblk = fragroundup(super,sz);
|
||||
|
||||
|
||||
return nblk / 512;
|
||||
#endif /* COMPAT */
|
||||
}
|
||||
|
||||
static int
|
||||
isfree(super, dp)
|
||||
struct fs *super;
|
||||
union dinode *dp;
|
||||
isfree(struct fs *super, union dinode *dp)
|
||||
{
|
||||
#ifdef COMPAT
|
||||
return (DIP(super, dp, di_mode) & IFMT) == 0;
|
||||
#else /* COMPAT */
|
||||
|
||||
|
||||
switch (DIP(super, dp, di_mode) & IFMT) {
|
||||
case IFIFO:
|
||||
case IFLNK: /* should check FASTSYMLINK? */
|
||||
@ -240,11 +233,11 @@ static struct user {
|
||||
static int nusers;
|
||||
|
||||
static void
|
||||
inituser()
|
||||
inituser(void)
|
||||
{
|
||||
register int i;
|
||||
register struct user *usr;
|
||||
|
||||
int i;
|
||||
struct user *usr;
|
||||
|
||||
if (!nusers) {
|
||||
nusers = 8;
|
||||
if (!(users =
|
||||
@ -259,12 +252,12 @@ inituser()
|
||||
}
|
||||
|
||||
static void
|
||||
usrrehash()
|
||||
usrrehash(void)
|
||||
{
|
||||
register int i;
|
||||
register struct user *usr, *usrn;
|
||||
int i;
|
||||
struct user *usr, *usrn;
|
||||
struct user *svusr;
|
||||
|
||||
|
||||
svusr = users;
|
||||
nusers <<= 1;
|
||||
if (!(users = (struct user *)calloc(nusers,sizeof(struct user))))
|
||||
@ -280,19 +273,18 @@ usrrehash()
|
||||
}
|
||||
|
||||
static struct user *
|
||||
user(uid)
|
||||
uid_t uid;
|
||||
user(uid_t uid)
|
||||
{
|
||||
register struct user *usr;
|
||||
register int i;
|
||||
struct user *usr;
|
||||
int i;
|
||||
struct passwd *pwd;
|
||||
|
||||
|
||||
while (1) {
|
||||
for (usr = users + (uid&(nusers - 1)), i = nusers; --i >= 0;
|
||||
usr--) {
|
||||
if (!usr->name) {
|
||||
usr->uid = uid;
|
||||
|
||||
|
||||
if (!(pwd = getpwuid(uid))) {
|
||||
if ((usr->name = (char *)malloc(7)))
|
||||
sprintf(usr->name,"#%d",uid);
|
||||
@ -303,9 +295,9 @@ user(uid)
|
||||
}
|
||||
if (!usr->name)
|
||||
errx(1, "allocate users");
|
||||
|
||||
|
||||
return usr;
|
||||
|
||||
|
||||
} else if (usr->uid == uid)
|
||||
return usr;
|
||||
|
||||
@ -317,8 +309,7 @@ user(uid)
|
||||
}
|
||||
|
||||
static int
|
||||
cmpusers(v1,v2)
|
||||
const void *v1, *v2;
|
||||
cmpusers(const void *v1, const void *v2)
|
||||
{
|
||||
const struct user *u1, *u2;
|
||||
u1 = (const struct user *)v1;
|
||||
@ -331,21 +322,18 @@ cmpusers(v1,v2)
|
||||
cmpusers))
|
||||
|
||||
static void
|
||||
uses(uid,blks,act)
|
||||
uid_t uid;
|
||||
daddr_t blks;
|
||||
time_t act;
|
||||
uses(uid_t uid, daddr_t blks, time_t act)
|
||||
{
|
||||
static time_t today;
|
||||
register struct user *usr;
|
||||
|
||||
struct user *usr;
|
||||
|
||||
if (!today)
|
||||
time(&today);
|
||||
|
||||
|
||||
usr = user(uid);
|
||||
usr->count++;
|
||||
usr->space += blks;
|
||||
|
||||
|
||||
if (today - act > 90L * 24L * 60L * 60L)
|
||||
usr->spc90 += blks;
|
||||
if (today - act > 60L * 24L * 60L * 60L)
|
||||
@ -367,11 +355,11 @@ struct fsizes {
|
||||
} *fsizes;
|
||||
|
||||
static void
|
||||
initfsizes()
|
||||
initfsizes(void)
|
||||
{
|
||||
register struct fsizes *fp;
|
||||
register int i;
|
||||
|
||||
struct fsizes *fp;
|
||||
int i;
|
||||
|
||||
for (fp = fsizes; fp; fp = fp->fsz_next) {
|
||||
for (i = FSZCNT; --i >= 0;) {
|
||||
fp->fsz_count[i] = 0;
|
||||
@ -381,17 +369,14 @@ initfsizes()
|
||||
}
|
||||
|
||||
static void
|
||||
dofsizes(fd, super, name)
|
||||
int fd;
|
||||
struct fs *super;
|
||||
char *name;
|
||||
dofsizes(int fd, struct fs *super, char *name)
|
||||
{
|
||||
ino_t inode, maxino;
|
||||
union dinode *dp;
|
||||
daddr_t sz, ksz;
|
||||
struct fsizes *fp, **fsp;
|
||||
register int i;
|
||||
|
||||
int i;
|
||||
|
||||
maxino = super->fs_ncg * super->fs_ipg - 1;
|
||||
#ifdef COMPAT
|
||||
if (!(fsizes = (struct fsizes *)malloc(sizeof(struct fsizes))))
|
||||
@ -456,16 +441,13 @@ dofsizes(fd, super, name)
|
||||
}
|
||||
|
||||
static void
|
||||
douser(fd, super, name)
|
||||
int fd;
|
||||
struct fs *super;
|
||||
char *name;
|
||||
douser(int fd, struct fs *super, char *name)
|
||||
{
|
||||
ino_t inode, maxino;
|
||||
struct user *usr, *usrs;
|
||||
union dinode *dp;
|
||||
register int n;
|
||||
|
||||
int n;
|
||||
|
||||
maxino = super->fs_ncg * super->fs_ipg - 1;
|
||||
for (inode = 0; inode < maxino; inode++) {
|
||||
errno = 0;
|
||||
@ -499,16 +481,13 @@ douser(fd, super, name)
|
||||
}
|
||||
|
||||
static void
|
||||
donames(fd, super, name)
|
||||
int fd;
|
||||
struct fs *super;
|
||||
char *name;
|
||||
donames(int fd, struct fs *super, char *name)
|
||||
{
|
||||
int c;
|
||||
ino_t inode;
|
||||
ino_t maxino;
|
||||
union dinode *dp;
|
||||
|
||||
|
||||
maxino = super->fs_ncg * super->fs_ipg - 1;
|
||||
/* first skip the name of the filesystem */
|
||||
while ((c = getchar()) != EOF && (c < '0' || c > '9'))
|
||||
@ -544,7 +523,7 @@ donames(fd, super, name)
|
||||
}
|
||||
|
||||
static void
|
||||
usage()
|
||||
usage(void)
|
||||
{
|
||||
#ifdef COMPAT
|
||||
fprintf(stderr,"usage: quot [-nfcvha] [filesystem ...]\n");
|
||||
@ -561,12 +540,11 @@ static int sblock_try[] = SBLOCKSEARCH;
|
||||
static char superblock[SBLOCKSIZE];
|
||||
|
||||
void
|
||||
quot(name,mp)
|
||||
char *name, *mp;
|
||||
quot(char *name, char *mp)
|
||||
{
|
||||
int i, fd;
|
||||
struct fs *fs;
|
||||
|
||||
|
||||
get_inode(-1, NULL, 0); /* flush cache */
|
||||
inituser();
|
||||
initfsizes();
|
||||
@ -606,9 +584,7 @@ quot(name,mp)
|
||||
}
|
||||
|
||||
int
|
||||
main(argc,argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
char all = 0;
|
||||
struct statfs *mp;
|
||||
@ -616,7 +592,7 @@ main(argc,argv)
|
||||
char dev[MNAMELEN + 1];
|
||||
char *nm;
|
||||
int cnt;
|
||||
|
||||
|
||||
func = douser;
|
||||
#ifndef COMPAT
|
||||
header = getbsize(&headerlen,&blocksize);
|
||||
|
@ -75,7 +75,7 @@ static void usage(void);
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
register struct fstab *fs;
|
||||
struct fstab *fs;
|
||||
char *qfnp, *whoami;
|
||||
long argnum, done = 0;
|
||||
int ch, i, offmode = 0, errs = 0;
|
||||
@ -142,7 +142,7 @@ main(int argc, char **argv)
|
||||
}
|
||||
|
||||
static void
|
||||
usage()
|
||||
usage(void)
|
||||
{
|
||||
|
||||
fprintf(stderr, "%s\n%s\n%s\n%s\n",
|
||||
@ -186,11 +186,9 @@ quotaonoff(fs, offmode, type, qfpathname)
|
||||
* Check to see if target appears in list of size cnt.
|
||||
*/
|
||||
int
|
||||
oneof(target, list, cnt)
|
||||
register char *target, *list[];
|
||||
int cnt;
|
||||
oneof(char *target, char *list[], int cnt)
|
||||
{
|
||||
register int i;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < cnt; i++)
|
||||
if (strcmp(target, list[i]) == 0)
|
||||
@ -202,10 +200,7 @@ oneof(target, list, cnt)
|
||||
* Check to see if a particular quota is to be enabled.
|
||||
*/
|
||||
int
|
||||
hasquota(fs, type, qfnamep)
|
||||
struct fstab *fs;
|
||||
int type;
|
||||
char **qfnamep;
|
||||
hasquota(struct fstab *fs, int type, char **qfnamep)
|
||||
{
|
||||
char *opt;
|
||||
char *cp;
|
||||
@ -254,8 +249,7 @@ hasquota(fs, type, qfnamep)
|
||||
* Verify filesystem is mounted and not readonly.
|
||||
*/
|
||||
int
|
||||
readonly(fs)
|
||||
register struct fstab *fs;
|
||||
readonly(struct fstab *fs)
|
||||
{
|
||||
struct statfs fsbuf;
|
||||
|
||||
|
@ -102,11 +102,11 @@ char *timeprt(time_t);
|
||||
static void usage(void);
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
register struct fstab *fs;
|
||||
register struct passwd *pw;
|
||||
register struct group *gr;
|
||||
struct fstab *fs;
|
||||
struct passwd *pw;
|
||||
struct group *gr;
|
||||
int ch, gflag = 0, uflag = 0, errs = 0;
|
||||
long i, argnum, done = 0;
|
||||
char *qfnp;
|
||||
@ -181,7 +181,7 @@ main(int argc, char **argv)
|
||||
}
|
||||
|
||||
static void
|
||||
usage()
|
||||
usage(void)
|
||||
{
|
||||
fprintf(stderr, "%s\n%s\n",
|
||||
"usage: repquota [-v] [-g] [-n] [-u] -a",
|
||||
@ -190,12 +190,9 @@ usage()
|
||||
}
|
||||
|
||||
int
|
||||
repquota(fs, type, qfpathname)
|
||||
register struct fstab *fs;
|
||||
int type;
|
||||
char *qfpathname;
|
||||
repquota(struct fstab *fs, int type, char *qfpathname)
|
||||
{
|
||||
register struct fileusage *fup;
|
||||
struct fileusage *fup;
|
||||
FILE *qf;
|
||||
u_long id;
|
||||
struct dqblk dqbuf;
|
||||
@ -272,11 +269,9 @@ repquota(fs, type, qfpathname)
|
||||
* Check to see if target appears in list of size cnt.
|
||||
*/
|
||||
int
|
||||
oneof(target, list, cnt)
|
||||
register char *target, *list[];
|
||||
int cnt;
|
||||
oneof(char *target, char *list[], int cnt)
|
||||
{
|
||||
register int i;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < cnt; i++)
|
||||
if (strcmp(target, list[i]) == 0)
|
||||
@ -288,10 +283,7 @@ oneof(target, list, cnt)
|
||||
* Check to see if a particular quota is to be enabled.
|
||||
*/
|
||||
int
|
||||
hasquota(fs, type, qfnamep)
|
||||
struct fstab *fs;
|
||||
int type;
|
||||
char **qfnamep;
|
||||
hasquota(struct fstab *fs, int type, char **qfnamep)
|
||||
{
|
||||
char *opt;
|
||||
char *cp;
|
||||
@ -342,11 +334,9 @@ hasquota(fs, type, qfnamep)
|
||||
* Lookup an id of a specific type.
|
||||
*/
|
||||
struct fileusage *
|
||||
lookup(id, type)
|
||||
u_long id;
|
||||
int type;
|
||||
lookup(u_long id, int type)
|
||||
{
|
||||
register struct fileusage *fup;
|
||||
struct fileusage *fup;
|
||||
|
||||
for (fup = fuhead[type][id & (FUHASH-1)]; fup != 0; fup = fup->fu_next)
|
||||
if (fup->fu_id == id)
|
||||
@ -358,10 +348,7 @@ lookup(id, type)
|
||||
* Add a new file usage id if it does not already exist.
|
||||
*/
|
||||
struct fileusage *
|
||||
addid(id, type, name)
|
||||
u_long id;
|
||||
int type;
|
||||
char *name;
|
||||
addid(u_long id, int type, char *name)
|
||||
{
|
||||
struct fileusage *fup, **fhp;
|
||||
int len;
|
||||
@ -392,8 +379,7 @@ addid(id, type, name)
|
||||
* Calculate the grace period and return a printable string for it.
|
||||
*/
|
||||
char *
|
||||
timeprt(seconds)
|
||||
time_t seconds;
|
||||
timeprt(time_t seconds)
|
||||
{
|
||||
time_t hours, minutes;
|
||||
static char buf[20];
|
||||
|
Loading…
Reference in New Issue
Block a user