preen.c (180187) | preen.c (207736) |
---|---|
1/* $NetBSD: preen.c,v 1.18 1998/07/26 20:02:36 mycroft Exp $ */ 2 3/* 4 * Copyright (c) 1990, 1993 5 * The Regents of the University of California. All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions --- 14 unchanged lines hidden (view full) --- 23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 * SUCH DAMAGE. 30 * | 1/* $NetBSD: preen.c,v 1.18 1998/07/26 20:02:36 mycroft Exp $ */ 2 3/* 4 * Copyright (c) 1990, 1993 5 * The Regents of the University of California. All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions --- 14 unchanged lines hidden (view full) --- 23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 * SUCH DAMAGE. 30 * |
31 * $FreeBSD: head/sbin/quotacheck/preen.c 180187 2008-07-02 15:51:59Z des $ | 31 * $FreeBSD: head/sbin/quotacheck/preen.c 207736 2010-05-07 00:41:12Z mckusick $ |
32 */ 33 34#include <sys/cdefs.h> 35#ifndef lint 36#if 0 37static char sccsid[] = "@(#)preen.c 8.5 (Berkeley) 4/28/95"; 38#else 39__RCSID("$NetBSD: preen.c,v 1.18 1998/07/26 20:02:36 mycroft Exp $"); 40#endif 41#endif /* not lint */ 42 43#include <sys/param.h> 44#include <sys/stat.h> 45#include <sys/wait.h> 46#include <sys/queue.h> 47 | 32 */ 33 34#include <sys/cdefs.h> 35#ifndef lint 36#if 0 37static char sccsid[] = "@(#)preen.c 8.5 (Berkeley) 4/28/95"; 38#else 39__RCSID("$NetBSD: preen.c,v 1.18 1998/07/26 20:02:36 mycroft Exp $"); 40#endif 41#endif /* not lint */ 42 43#include <sys/param.h> 44#include <sys/stat.h> 45#include <sys/wait.h> 46#include <sys/queue.h> 47 |
48#include <ufs/ufs/quota.h> 49 |
|
48#include <err.h> 49#include <ctype.h> | 50#include <err.h> 51#include <ctype.h> |
52#include <fcntl.h> |
|
50#include <fstab.h> | 53#include <fstab.h> |
54#include <libutil.h> |
|
51#include <string.h> 52#include <stdio.h> 53#include <stdlib.h> 54#include <unistd.h> 55 56#include "quotacheck.h" 57 58struct partentry { 59 TAILQ_ENTRY(partentry) p_entries; 60 char *p_devname; /* device name */ | 55#include <string.h> 56#include <stdio.h> 57#include <stdlib.h> 58#include <unistd.h> 59 60#include "quotacheck.h" 61 62struct partentry { 63 TAILQ_ENTRY(partentry) p_entries; 64 char *p_devname; /* device name */ |
61 char *p_mntpt; /* mount point */ 62 char *p_type; /* file system type */ 63 struct quotaname *p_quota; /* quota file info ptr */ | 65 const char *p_mntpt; /* mount point */ 66 struct quotafile *p_qfu; /* user quota file info ptr */ 67 struct quotafile *p_qfg; /* group quota file info */ |
64}; 65 66TAILQ_HEAD(part, partentry) badh; 67 68struct diskentry { 69 TAILQ_ENTRY(diskentry) d_entries; 70 char *d_name; /* disk base name */ 71 TAILQ_HEAD(prt, partentry) d_part; /* list of partitions on disk */ 72 int d_pid; /* 0 or pid of fsck proc */ 73}; 74 75TAILQ_HEAD(disk, diskentry) diskh; 76 77static struct diskentry *finddisk(const char *); | 68}; 69 70TAILQ_HEAD(part, partentry) badh; 71 72struct diskentry { 73 TAILQ_ENTRY(diskentry) d_entries; 74 char *d_name; /* disk base name */ 75 TAILQ_HEAD(prt, partentry) d_part; /* list of partitions on disk */ 76 int d_pid; /* 0 or pid of fsck proc */ 77}; 78 79TAILQ_HEAD(disk, diskentry) diskh; 80 81static struct diskentry *finddisk(const char *); |
78static void addpart(const char *, const char *, const char *, 79 struct quotaname *); | 82static void addpart(struct fstab *, struct quotafile *, struct quotafile *); |
80static int startdisk(struct diskentry *); 81extern void *emalloc(size_t); 82extern char *estrdup(const char *); 83 84int | 83static int startdisk(struct diskentry *); 84extern void *emalloc(size_t); 85extern char *estrdup(const char *); 86 87int |
85checkfstab(void) | 88checkfstab(int uflag, int gflag) |
86{ 87 struct fstab *fs; 88 struct diskentry *d, *nextdisk; 89 struct partentry *p; 90 int ret, pid, retcode, passno, sumstatus, status, nextpass; | 89{ 90 struct fstab *fs; 91 struct diskentry *d, *nextdisk; 92 struct partentry *p; 93 int ret, pid, retcode, passno, sumstatus, status, nextpass; |
91 char *name; 92 struct quotaname *qnp; | 94 struct quotafile *qfu, *qfg; |
93 94 TAILQ_INIT(&badh); 95 TAILQ_INIT(&diskh); 96 97 sumstatus = 0; 98 99 nextpass = 0; 100 for (passno = 1; nextpass != INT_MAX; passno = nextpass) { 101 nextpass = INT_MAX; 102 if (setfsent() == 0) { 103 warnx("Can't open checklist file: %s\n", _PATH_FSTAB); 104 return (8); 105 } 106 while ((fs = getfsent()) != 0) { | 95 96 TAILQ_INIT(&badh); 97 TAILQ_INIT(&diskh); 98 99 sumstatus = 0; 100 101 nextpass = 0; 102 for (passno = 1; nextpass != INT_MAX; passno = nextpass) { 103 nextpass = INT_MAX; 104 if (setfsent() == 0) { 105 warnx("Can't open checklist file: %s\n", _PATH_FSTAB); 106 return (8); 107 } 108 while ((fs = getfsent()) != 0) { |
107 name = fs->fs_spec; | |
108 if (fs->fs_passno > passno && fs->fs_passno < nextpass) 109 nextpass = fs->fs_passno; 110 111 if (passno != fs->fs_passno) 112 continue; 113 | 109 if (fs->fs_passno > passno && fs->fs_passno < nextpass) 110 nextpass = fs->fs_passno; 111 112 if (passno != fs->fs_passno) 113 continue; 114 |
114 if ((qnp = needchk(fs)) == NULL) | 115 qfu = NULL; 116 if (uflag) 117 qfu = quota_open(fs, USRQUOTA, O_CREAT|O_RDWR); 118 qfg = NULL; 119 if (gflag) 120 qfg = quota_open(fs, GRPQUOTA, O_CREAT|O_RDWR); 121 if (qfu == NULL && qfg == NULL) |
115 continue; 116 117 if (passno == 1) { | 122 continue; 123 124 if (passno == 1) { |
118 sumstatus = chkquota(name, fs->fs_file, qnp); 119 | 125 sumstatus = chkquota(fs->fs_spec, qfu, qfg); 126 if (qfu) 127 quota_close(qfu); 128 if (qfg) 129 quota_close(qfg); |
120 if (sumstatus) 121 return (sumstatus); 122 continue; 123 } | 130 if (sumstatus) 131 return (sumstatus); 132 continue; 133 } |
124 if (name == NULL) { 125 (void) fprintf(stderr, 126 "BAD DISK NAME %s\n", fs->fs_spec); 127 sumstatus |= 8; 128 continue; 129 } 130 addpart(fs->fs_vfstype, name, fs->fs_file, qnp); | 134 addpart(fs, qfu, qfg); |
131 } 132 133 if (passno == 1) 134 continue; 135 136 TAILQ_FOREACH(nextdisk, &diskh, d_entries) { 137 if ((ret = startdisk(nextdisk)) != 0) 138 return ret; --- 13 unchanged lines hidden (view full) --- 152 retcode = WEXITSTATUS(status); 153 else 154 retcode = 0; 155 156 p = TAILQ_FIRST(&d->d_part); 157 158 if (WIFSIGNALED(status)) { 159 (void) fprintf(stderr, | 135 } 136 137 if (passno == 1) 138 continue; 139 140 TAILQ_FOREACH(nextdisk, &diskh, d_entries) { 141 if ((ret = startdisk(nextdisk)) != 0) 142 return ret; --- 13 unchanged lines hidden (view full) --- 156 retcode = WEXITSTATUS(status); 157 else 158 retcode = 0; 159 160 p = TAILQ_FIRST(&d->d_part); 161 162 if (WIFSIGNALED(status)) { 163 (void) fprintf(stderr, |
160 "%s: %s (%s): EXITED WITH SIGNAL %d\n", 161 p->p_type, p->p_devname, p->p_mntpt, | 164 "%s: (%s): EXITED WITH SIGNAL %d\n", 165 p->p_devname, p->p_mntpt, |
162 WTERMSIG(status)); 163 retcode = 8; 164 } 165 166 TAILQ_REMOVE(&d->d_part, p, p_entries); 167 168 if (retcode != 0) { 169 TAILQ_INSERT_TAIL(&badh, p, p_entries); 170 sumstatus |= retcode; 171 } else { | 166 WTERMSIG(status)); 167 retcode = 8; 168 } 169 170 TAILQ_REMOVE(&d->d_part, p, p_entries); 171 172 if (retcode != 0) { 173 TAILQ_INSERT_TAIL(&badh, p, p_entries); 174 sumstatus |= retcode; 175 } else { |
172 free(p->p_type); | |
173 free(p->p_devname); | 176 free(p->p_devname); |
177 if (p->p_qfu) 178 quota_close(p->p_qfu); 179 if (p->p_qfg) 180 quota_close(p->p_qfg); |
|
174 free(p); 175 } 176 d->d_pid = 0; 177 178 if (TAILQ_EMPTY(&d->d_part)) { 179 TAILQ_REMOVE(&diskh, d, d_entries); 180 } else { 181 if ((ret = startdisk(d)) != 0) --- 9 unchanged lines hidden (view full) --- 191 192 (void) fprintf(stderr, 193 "THE FOLLOWING FILE SYSTEM%s HAD AN %s\n\t", 194 TAILQ_NEXT(p, p_entries) ? "S" : "", 195 "UNEXPECTED INCONSISTENCY:"); 196 197 for (; p; p = TAILQ_NEXT(p, p_entries)) 198 (void) fprintf(stderr, | 181 free(p); 182 } 183 d->d_pid = 0; 184 185 if (TAILQ_EMPTY(&d->d_part)) { 186 TAILQ_REMOVE(&diskh, d, d_entries); 187 } else { 188 if ((ret = startdisk(d)) != 0) --- 9 unchanged lines hidden (view full) --- 198 199 (void) fprintf(stderr, 200 "THE FOLLOWING FILE SYSTEM%s HAD AN %s\n\t", 201 TAILQ_NEXT(p, p_entries) ? "S" : "", 202 "UNEXPECTED INCONSISTENCY:"); 203 204 for (; p; p = TAILQ_NEXT(p, p_entries)) 205 (void) fprintf(stderr, |
199 "%s: %s (%s)%s", p->p_type, p->p_devname, 200 p->p_mntpt, TAILQ_NEXT(p, p_entries) ? ", " : "\n"); | 206 "%s: (%s)%s", p->p_devname, p->p_mntpt, 207 TAILQ_NEXT(p, p_entries) ? ", " : "\n"); |
201 202 return sumstatus; 203 } 204 (void) endfsent(); 205 return (0); 206} 207 208 --- 28 unchanged lines hidden (view full) --- 237 d->d_pid = 0; 238 239 TAILQ_INSERT_TAIL(&diskh, d, d_entries); 240 241 return d; 242} 243 244static void | 208 209 return sumstatus; 210 } 211 (void) endfsent(); 212 return (0); 213} 214 215 --- 28 unchanged lines hidden (view full) --- 244 d->d_pid = 0; 245 246 TAILQ_INSERT_TAIL(&diskh, d, d_entries); 247 248 return d; 249} 250 251static void |
245addpart(const char *type, const char *devname, const char *mntpt, 246 struct quotaname *qnp) | 252addpart(struct fstab *fs, struct quotafile *qfu, struct quotafile *qfg) |
247{ | 253{ |
248 struct diskentry *d = finddisk(devname); | 254 struct diskentry *d = finddisk(fs->fs_spec); |
249 struct partentry *p; 250 251 TAILQ_FOREACH(p, &d->d_part, p_entries) | 255 struct partentry *p; 256 257 TAILQ_FOREACH(p, &d->d_part, p_entries) |
252 if (strcmp(p->p_devname, devname) == 0) { 253 warnx("%s in fstab more than once!\n", devname); | 258 if (strcmp(p->p_devname, fs->fs_spec) == 0) { 259 warnx("%s in fstab more than once!\n", fs->fs_spec); |
254 return; 255 } 256 257 p = emalloc(sizeof(*p)); | 260 return; 261 } 262 263 p = emalloc(sizeof(*p)); |
258 p->p_devname = estrdup(devname); 259 p->p_mntpt = estrdup(mntpt); 260 p->p_type = estrdup(type); 261 p->p_quota = qnp; | 264 p->p_devname = estrdup(blockcheck(fs->fs_spec)); 265 if (qfu != NULL) 266 p->p_mntpt = quota_fsname(qfu); 267 else 268 p->p_mntpt = quota_fsname(qfg); 269 p->p_qfu = qfu; 270 p->p_qfg = qfg; |
262 263 TAILQ_INSERT_TAIL(&d->d_part, p, p_entries); 264} 265 266 267static int 268startdisk(struct diskentry *d) 269{ 270 struct partentry *p = TAILQ_FIRST(&d->d_part); 271 272 d->d_pid = fork(); 273 if (d->d_pid < 0) { 274 perror("fork"); 275 return (8); 276 } 277 if (d->d_pid == 0) | 271 272 TAILQ_INSERT_TAIL(&d->d_part, p, p_entries); 273} 274 275 276static int 277startdisk(struct diskentry *d) 278{ 279 struct partentry *p = TAILQ_FIRST(&d->d_part); 280 281 d->d_pid = fork(); 282 if (d->d_pid < 0) { 283 perror("fork"); 284 return (8); 285 } 286 if (d->d_pid == 0) |
278 exit(chkquota(p->p_devname, p->p_mntpt, p->p_quota)); | 287 exit(chkquota(p->p_devname, p->p_qfu, p->p_qfg)); |
279 return (0); 280} | 288 return (0); 289} |