2008-01-26 12:03:26 +00:00
|
|
|
/* $NetBSD: preen.c,v 1.18 1998/07/26 20:02:36 mycroft Exp $ */
|
|
|
|
|
1994-05-26 06:35:07 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1990, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
2008-01-26 12:03:26 +00:00
|
|
|
*
|
|
|
|
* $FreeBSD$
|
1994-05-26 06:35:07 +00:00
|
|
|
*/
|
|
|
|
|
2008-01-26 12:03:26 +00:00
|
|
|
#include <sys/cdefs.h>
|
2003-05-03 18:41:59 +00:00
|
|
|
#ifndef lint
|
2008-01-26 12:03:26 +00:00
|
|
|
#if 0
|
|
|
|
static char sccsid[] = "@(#)preen.c 8.5 (Berkeley) 4/28/95";
|
|
|
|
#else
|
|
|
|
__RCSID("$NetBSD: preen.c,v 1.18 1998/07/26 20:02:36 mycroft Exp $");
|
2003-05-03 18:41:59 +00:00
|
|
|
#endif
|
2008-01-26 12:03:26 +00:00
|
|
|
#endif /* not lint */
|
1994-05-26 06:35:07 +00:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/wait.h>
|
2008-01-26 12:03:26 +00:00
|
|
|
#include <sys/queue.h>
|
1997-03-12 16:58:35 +00:00
|
|
|
|
2009-12-27 06:28:01 +00:00
|
|
|
#include <ufs/ufs/quota.h>
|
|
|
|
|
2008-01-26 12:03:26 +00:00
|
|
|
#include <err.h>
|
1997-03-12 16:58:35 +00:00
|
|
|
#include <ctype.h>
|
2009-12-27 06:28:01 +00:00
|
|
|
#include <fcntl.h>
|
1994-05-26 06:35:07 +00:00
|
|
|
#include <fstab.h>
|
2009-12-27 06:28:01 +00:00
|
|
|
#include <libutil.h>
|
1994-05-26 06:35:07 +00:00
|
|
|
#include <string.h>
|
2002-08-09 16:25:32 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2008-01-26 12:03:26 +00:00
|
|
|
#include "quotacheck.h"
|
1997-03-11 12:20:21 +00:00
|
|
|
|
2008-01-26 12:03:26 +00:00
|
|
|
struct partentry {
|
|
|
|
TAILQ_ENTRY(partentry) p_entries;
|
2008-07-02 15:51:59 +00:00
|
|
|
char *p_devname; /* device name */
|
2009-12-27 06:28:01 +00:00
|
|
|
const char *p_mntpt; /* mount point */
|
|
|
|
struct quotafile *p_qfu; /* user quota file info ptr */
|
|
|
|
struct quotafile *p_qfg; /* group quota file info */
|
2008-01-26 12:03:26 +00:00
|
|
|
};
|
1994-05-26 06:35:07 +00:00
|
|
|
|
2008-01-26 12:03:26 +00:00
|
|
|
TAILQ_HEAD(part, partentry) badh;
|
1994-05-26 06:35:07 +00:00
|
|
|
|
2008-01-26 12:03:26 +00:00
|
|
|
struct diskentry {
|
2008-07-02 15:51:59 +00:00
|
|
|
TAILQ_ENTRY(diskentry) d_entries;
|
|
|
|
char *d_name; /* disk base name */
|
2008-01-26 12:03:26 +00:00
|
|
|
TAILQ_HEAD(prt, partentry) d_part; /* list of partitions on disk */
|
|
|
|
int d_pid; /* 0 or pid of fsck proc */
|
|
|
|
};
|
1994-05-26 06:35:07 +00:00
|
|
|
|
2008-01-26 12:03:26 +00:00
|
|
|
TAILQ_HEAD(disk, diskentry) diskh;
|
1994-05-26 06:35:07 +00:00
|
|
|
|
2008-01-26 12:03:26 +00:00
|
|
|
static struct diskentry *finddisk(const char *);
|
2009-12-27 06:28:01 +00:00
|
|
|
static void addpart(struct fstab *, struct quotafile *, struct quotafile *);
|
2008-01-26 12:03:26 +00:00
|
|
|
static int startdisk(struct diskentry *);
|
|
|
|
extern void *emalloc(size_t);
|
|
|
|
extern char *estrdup(const char *);
|
1997-03-11 12:20:21 +00:00
|
|
|
|
1995-04-02 14:52:29 +00:00
|
|
|
int
|
2009-12-27 06:28:01 +00:00
|
|
|
checkfstab(int uflag, int gflag)
|
1994-05-26 06:35:07 +00:00
|
|
|
{
|
2008-01-26 12:03:26 +00:00
|
|
|
struct fstab *fs;
|
|
|
|
struct diskentry *d, *nextdisk;
|
|
|
|
struct partentry *p;
|
|
|
|
int ret, pid, retcode, passno, sumstatus, status, nextpass;
|
2009-12-27 06:28:01 +00:00
|
|
|
struct quotafile *qfu, *qfg;
|
2008-01-26 12:03:26 +00:00
|
|
|
|
|
|
|
TAILQ_INIT(&badh);
|
|
|
|
TAILQ_INIT(&diskh);
|
1994-05-26 06:35:07 +00:00
|
|
|
|
|
|
|
sumstatus = 0;
|
2008-01-26 12:03:26 +00:00
|
|
|
|
|
|
|
nextpass = 0;
|
|
|
|
for (passno = 1; nextpass != INT_MAX; passno = nextpass) {
|
|
|
|
nextpass = INT_MAX;
|
1994-05-26 06:35:07 +00:00
|
|
|
if (setfsent() == 0) {
|
2008-01-26 12:03:26 +00:00
|
|
|
warnx("Can't open checklist file: %s\n", _PATH_FSTAB);
|
1994-05-26 06:35:07 +00:00
|
|
|
return (8);
|
|
|
|
}
|
2008-01-26 12:03:26 +00:00
|
|
|
while ((fs = getfsent()) != 0) {
|
|
|
|
if (fs->fs_passno > passno && fs->fs_passno < nextpass)
|
|
|
|
nextpass = fs->fs_passno;
|
|
|
|
|
|
|
|
if (passno != fs->fs_passno)
|
|
|
|
continue;
|
|
|
|
|
2009-12-27 06:28:01 +00:00
|
|
|
qfu = NULL;
|
|
|
|
if (uflag)
|
|
|
|
qfu = quota_open(fs, USRQUOTA, O_CREAT|O_RDWR);
|
|
|
|
qfg = NULL;
|
|
|
|
if (gflag)
|
|
|
|
qfg = quota_open(fs, GRPQUOTA, O_CREAT|O_RDWR);
|
|
|
|
if (qfu == NULL && qfg == NULL)
|
2008-01-26 12:03:26 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (passno == 1) {
|
2009-12-27 06:28:01 +00:00
|
|
|
sumstatus = chkquota(fs->fs_spec, qfu, qfg);
|
|
|
|
if (qfu)
|
|
|
|
quota_close(qfu);
|
|
|
|
if (qfg)
|
|
|
|
quota_close(qfg);
|
2008-01-26 12:03:26 +00:00
|
|
|
if (sumstatus)
|
|
|
|
return (sumstatus);
|
|
|
|
continue;
|
2008-07-02 15:51:59 +00:00
|
|
|
}
|
2009-12-27 06:28:01 +00:00
|
|
|
addpart(fs, qfu, qfg);
|
1994-05-26 06:35:07 +00:00
|
|
|
}
|
2008-01-26 12:03:26 +00:00
|
|
|
|
|
|
|
if (passno == 1)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
TAILQ_FOREACH(nextdisk, &diskh, d_entries) {
|
|
|
|
if ((ret = startdisk(nextdisk)) != 0)
|
|
|
|
return ret;
|
1994-05-26 06:35:07 +00:00
|
|
|
}
|
2008-01-26 12:03:26 +00:00
|
|
|
|
1994-05-26 06:35:07 +00:00
|
|
|
while ((pid = wait(&status)) != -1) {
|
2008-07-02 15:51:59 +00:00
|
|
|
TAILQ_FOREACH(d, &diskh, d_entries)
|
2008-01-26 12:03:26 +00:00
|
|
|
if (d->d_pid == pid)
|
1994-05-26 06:35:07 +00:00
|
|
|
break;
|
2008-01-26 12:03:26 +00:00
|
|
|
|
|
|
|
if (d == NULL) {
|
|
|
|
warnx("Unknown pid %d\n", pid);
|
1994-05-26 06:35:07 +00:00
|
|
|
continue;
|
|
|
|
}
|
2008-01-26 12:03:26 +00:00
|
|
|
|
1994-05-26 06:35:07 +00:00
|
|
|
if (WIFEXITED(status))
|
|
|
|
retcode = WEXITSTATUS(status);
|
|
|
|
else
|
|
|
|
retcode = 0;
|
2008-01-26 12:03:26 +00:00
|
|
|
|
|
|
|
p = TAILQ_FIRST(&d->d_part);
|
|
|
|
|
1994-05-26 06:35:07 +00:00
|
|
|
if (WIFSIGNALED(status)) {
|
2008-01-26 12:03:26 +00:00
|
|
|
(void) fprintf(stderr,
|
2009-12-27 06:28:01 +00:00
|
|
|
"%s: (%s): EXITED WITH SIGNAL %d\n",
|
|
|
|
p->p_devname, p->p_mntpt,
|
2008-01-26 12:03:26 +00:00
|
|
|
WTERMSIG(status));
|
1994-05-26 06:35:07 +00:00
|
|
|
retcode = 8;
|
|
|
|
}
|
2008-01-26 12:03:26 +00:00
|
|
|
|
|
|
|
TAILQ_REMOVE(&d->d_part, p, p_entries);
|
|
|
|
|
1994-05-26 06:35:07 +00:00
|
|
|
if (retcode != 0) {
|
2008-01-26 12:03:26 +00:00
|
|
|
TAILQ_INSERT_TAIL(&badh, p, p_entries);
|
1994-05-26 06:35:07 +00:00
|
|
|
sumstatus |= retcode;
|
2008-01-26 12:03:26 +00:00
|
|
|
} else {
|
|
|
|
free(p->p_devname);
|
2009-12-27 06:28:01 +00:00
|
|
|
if (p->p_qfu)
|
|
|
|
quota_close(p->p_qfu);
|
|
|
|
if (p->p_qfg)
|
|
|
|
quota_close(p->p_qfg);
|
2008-01-26 12:03:26 +00:00
|
|
|
free(p);
|
|
|
|
}
|
|
|
|
d->d_pid = 0;
|
|
|
|
|
|
|
|
if (TAILQ_EMPTY(&d->d_part)) {
|
|
|
|
TAILQ_REMOVE(&diskh, d, d_entries);
|
|
|
|
} else {
|
|
|
|
if ((ret = startdisk(d)) != 0)
|
|
|
|
return ret;
|
1994-05-26 06:35:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-01-26 12:03:26 +00:00
|
|
|
|
1994-05-26 06:35:07 +00:00
|
|
|
if (sumstatus) {
|
2008-01-26 12:03:26 +00:00
|
|
|
p = TAILQ_FIRST(&badh);
|
|
|
|
if (p == NULL)
|
1994-05-26 06:35:07 +00:00
|
|
|
return (sumstatus);
|
2008-01-26 12:03:26 +00:00
|
|
|
|
|
|
|
(void) fprintf(stderr,
|
|
|
|
"THE FOLLOWING FILE SYSTEM%s HAD AN %s\n\t",
|
|
|
|
TAILQ_NEXT(p, p_entries) ? "S" : "",
|
|
|
|
"UNEXPECTED INCONSISTENCY:");
|
|
|
|
|
|
|
|
for (; p; p = TAILQ_NEXT(p, p_entries))
|
|
|
|
(void) fprintf(stderr,
|
2009-12-27 06:28:01 +00:00
|
|
|
"%s: (%s)%s", p->p_devname, p->p_mntpt,
|
|
|
|
TAILQ_NEXT(p, p_entries) ? ", " : "\n");
|
2008-01-26 12:03:26 +00:00
|
|
|
|
|
|
|
return sumstatus;
|
1994-05-26 06:35:07 +00:00
|
|
|
}
|
2008-01-26 12:03:26 +00:00
|
|
|
(void) endfsent();
|
1994-05-26 06:35:07 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2008-01-26 12:03:26 +00:00
|
|
|
|
|
|
|
static struct diskentry *
|
|
|
|
finddisk(const char *name)
|
1994-05-26 06:35:07 +00:00
|
|
|
{
|
2008-01-26 12:03:26 +00:00
|
|
|
const char *p;
|
|
|
|
size_t len = 0;
|
|
|
|
struct diskentry *d;
|
1994-05-26 06:35:07 +00:00
|
|
|
|
1998-04-07 12:43:57 +00:00
|
|
|
p = strrchr(name, '/');
|
2008-01-26 12:03:26 +00:00
|
|
|
if (p == NULL)
|
|
|
|
p = name;
|
|
|
|
else
|
1998-04-07 12:43:57 +00:00
|
|
|
p++;
|
2008-01-26 12:03:26 +00:00
|
|
|
for (; *p && !isdigit(*p); p++)
|
|
|
|
continue;
|
|
|
|
for (; *p && isdigit(*p); p++)
|
|
|
|
continue;
|
|
|
|
len = p - name;
|
|
|
|
if (len == 0)
|
|
|
|
len = strlen(name);
|
|
|
|
|
2008-07-02 15:51:59 +00:00
|
|
|
TAILQ_FOREACH(d, &diskh, d_entries)
|
2008-01-26 12:03:26 +00:00
|
|
|
if (strncmp(d->d_name, name, len) == 0 && d->d_name[len] == 0)
|
|
|
|
return d;
|
|
|
|
|
|
|
|
d = emalloc(sizeof(*d));
|
|
|
|
d->d_name = estrdup(name);
|
|
|
|
d->d_name[len] = '\0';
|
|
|
|
TAILQ_INIT(&d->d_part);
|
|
|
|
d->d_pid = 0;
|
|
|
|
|
|
|
|
TAILQ_INSERT_TAIL(&diskh, d, d_entries);
|
|
|
|
|
|
|
|
return d;
|
1994-05-26 06:35:07 +00:00
|
|
|
}
|
|
|
|
|
1997-03-11 12:20:21 +00:00
|
|
|
static void
|
2009-12-27 06:28:01 +00:00
|
|
|
addpart(struct fstab *fs, struct quotafile *qfu, struct quotafile *qfg)
|
1994-05-26 06:35:07 +00:00
|
|
|
{
|
2009-12-27 06:28:01 +00:00
|
|
|
struct diskentry *d = finddisk(fs->fs_spec);
|
2008-01-26 12:03:26 +00:00
|
|
|
struct partentry *p;
|
1994-05-26 06:35:07 +00:00
|
|
|
|
2008-01-26 12:03:26 +00:00
|
|
|
TAILQ_FOREACH(p, &d->d_part, p_entries)
|
2009-12-27 06:28:01 +00:00
|
|
|
if (strcmp(p->p_devname, fs->fs_spec) == 0) {
|
|
|
|
warnx("%s in fstab more than once!\n", fs->fs_spec);
|
1994-05-26 06:35:07 +00:00
|
|
|
return;
|
|
|
|
}
|
2008-01-26 12:03:26 +00:00
|
|
|
|
|
|
|
p = emalloc(sizeof(*p));
|
2009-12-27 06:28:01 +00:00
|
|
|
p->p_devname = estrdup(blockcheck(fs->fs_spec));
|
|
|
|
if (qfu != NULL)
|
|
|
|
p->p_mntpt = quota_fsname(qfu);
|
|
|
|
else
|
|
|
|
p->p_mntpt = quota_fsname(qfg);
|
|
|
|
p->p_qfu = qfu;
|
|
|
|
p->p_qfg = qfg;
|
2008-01-26 12:03:26 +00:00
|
|
|
|
|
|
|
TAILQ_INSERT_TAIL(&d->d_part, p, p_entries);
|
1994-05-26 06:35:07 +00:00
|
|
|
}
|
|
|
|
|
2008-01-26 12:03:26 +00:00
|
|
|
|
1997-03-11 12:20:21 +00:00
|
|
|
static int
|
2008-01-26 12:03:26 +00:00
|
|
|
startdisk(struct diskentry *d)
|
1994-05-26 06:35:07 +00:00
|
|
|
{
|
2008-01-26 12:03:26 +00:00
|
|
|
struct partentry *p = TAILQ_FIRST(&d->d_part);
|
1994-05-26 06:35:07 +00:00
|
|
|
|
2008-01-26 12:03:26 +00:00
|
|
|
d->d_pid = fork();
|
|
|
|
if (d->d_pid < 0) {
|
1998-12-03 02:27:35 +00:00
|
|
|
perror("fork");
|
1994-05-26 06:35:07 +00:00
|
|
|
return (8);
|
|
|
|
}
|
2008-01-26 12:03:26 +00:00
|
|
|
if (d->d_pid == 0)
|
2009-12-27 06:28:01 +00:00
|
|
|
exit(chkquota(p->p_devname, p->p_qfu, p->p_qfg));
|
1994-05-26 06:35:07 +00:00
|
|
|
return (0);
|
|
|
|
}
|