Deleted Added
full compact
preen.c (37000) preen.c (41474)
1/*
2 * Copyright (c) 1990, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

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

27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34#ifndef lint
1/*
2 * Copyright (c) 1990, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

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

27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34#ifndef lint
35#if 0
36static const char sccsid[] = "@(#)preen.c 8.5 (Berkeley) 4/28/95";
35static const char sccsid[] = "@(#)preen.c 8.5 (Berkeley) 4/28/95";
37#endif
38static const char rcsid[] =
39 "$Id$";
40#endif /* not lint */
41
42#include <sys/param.h>
43#include <sys/stat.h>
44#include <sys/wait.h>
45
46#include <ufs/ufs/dinode.h>
47
48#include <ctype.h>
36#endif /* not lint */
37
38#include <sys/param.h>
39#include <sys/stat.h>
40#include <sys/wait.h>
41
42#include <ufs/ufs/dinode.h>
43
44#include <ctype.h>
49#include
45#include <errno.h>
50#include <fstab.h>
51#include <string.h>
52
53#include "fsck.h"
54
55struct part {
56 struct part *next; /* forward link of partitions on disk */
57 char *name; /* device name */

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

88 register struct part *pt;
89 int ret, pid, retcode, passno, sumstatus, status;
90 long auxdata;
91 char *name;
92
93 sumstatus = 0;
94 for (passno = 1; passno <= 2; passno++) {
95 if (setfsent() == 0) {
46#include <fstab.h>
47#include <string.h>
48
49#include "fsck.h"
50
51struct part {
52 struct part *next; /* forward link of partitions on disk */
53 char *name; /* device name */

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

84 register struct part *pt;
85 int ret, pid, retcode, passno, sumstatus, status;
86 long auxdata;
87 char *name;
88
89 sumstatus = 0;
90 for (passno = 1; passno <= 2; passno++) {
91 if (setfsent() == 0) {
96 warnx("can't open checklist file: %s", _PATH_FSTAB);
92 fprintf(stderr, "Can't open checklist file: %s\n",
93 _PATH_FSTAB);
97 return (8);
98 }
99 while ((fsp = getfsent()) != 0) {
100 if ((auxdata = (*docheck)(fsp)) == 0)
101 continue;
102 if (preen == 0 ||
103 (passno == 1 && fsp->fs_passno == 1)) {
104 if ((name = blockcheck(fsp->fs_spec)) != 0) {

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

217 while (isdigit((u_char)*p))
218 p++;
219 len = (size_t)(p - name);
220 for (dk = disks, dkp = &disks; dk; dkp = &dk->next, dk = dk->next) {
221 if (strncmp(dk->name, name, len) == 0 &&
222 dk->name[len] == 0)
223 return (dk);
224 }
94 return (8);
95 }
96 while ((fsp = getfsent()) != 0) {
97 if ((auxdata = (*docheck)(fsp)) == 0)
98 continue;
99 if (preen == 0 ||
100 (passno == 1 && fsp->fs_passno == 1)) {
101 if ((name = blockcheck(fsp->fs_spec)) != 0) {

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

214 while (isdigit((u_char)*p))
215 p++;
216 len = (size_t)(p - name);
217 for (dk = disks, dkp = &disks; dk; dkp = &dk->next, dk = dk->next) {
218 if (strncmp(dk->name, name, len) == 0 &&
219 dk->name[len] == 0)
220 return (dk);
221 }
225 if ((*dkp = (struct disk *)malloc(sizeof(struct disk))) == NULL)
226 errx(8, "out of memory");
222 if ((*dkp = (struct disk *)malloc(sizeof(struct disk))) == NULL) {
223 fprintf(stderr, "out of memory");
224 exit (8);
225 }
227 dk = *dkp;
226 dk = *dkp;
228 if ((dk->name = malloc(len + 1)) == NULL)
229 errx(8, "out of memory");
227 if ((dk->name = malloc(len + 1)) == NULL) {
228 fprintf(stderr, "out of memory");
229 exit (8);
230 }
230 (void)strncpy(dk->name, name, len);
231 dk->name[len] = '\0';
232 dk->part = NULL;
233 dk->next = NULL;
234 dk->pid = 0;
235 ndisks++;
236 return (dk);
237}

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

244 struct disk *dk = finddisk(name);
245 register struct part *pt, **ppt = &dk->part;
246
247 for (pt = dk->part; pt; ppt = &pt->next, pt = pt->next)
248 if (strcmp(pt->name, name) == 0) {
249 printf("%s in fstab more than once!\n", name);
250 return;
251 }
231 (void)strncpy(dk->name, name, len);
232 dk->name[len] = '\0';
233 dk->part = NULL;
234 dk->next = NULL;
235 dk->pid = 0;
236 ndisks++;
237 return (dk);
238}

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

245 struct disk *dk = finddisk(name);
246 register struct part *pt, **ppt = &dk->part;
247
248 for (pt = dk->part; pt; ppt = &pt->next, pt = pt->next)
249 if (strcmp(pt->name, name) == 0) {
250 printf("%s in fstab more than once!\n", name);
251 return;
252 }
252 if ((*ppt = (struct part *)malloc(sizeof(struct part))) == NULL)
253 errx(8, "out of memory");
253 if ((*ppt = (struct part *)malloc(sizeof(struct part))) == NULL) {
254 fprintf(stderr, "out of memory");
255 exit (8);
256 }
254 pt = *ppt;
257 pt = *ppt;
255 if ((pt->name = malloc(strlen(name) + 1)) == NULL)
256 errx(8, "out of memory");
258 if ((pt->name = malloc(strlen(name) + 1)) == NULL) {
259 fprintf(stderr, "out of memory");
260 exit (8);
261 }
257 (void)strcpy(pt->name, name);
262 (void)strcpy(pt->name, name);
258 if ((pt->fsname = malloc(strlen(fsname) + 1)) == NULL)
259 errx(8, "out of memory");
263 if ((pt->fsname = malloc(strlen(fsname) + 1)) == NULL) {
264 fprintf(stderr, "out of memory");
265 exit (8);
266 }
260 (void)strcpy(pt->fsname, fsname);
261 pt->next = NULL;
262 pt->auxdata = auxdata;
263}
264
265static int
266startdisk(dk, checkit)
267 register struct disk *dk;
268 int (*checkit)(char *, char *, long, int);
269{
270 register struct part *pt = dk->part;
271
272 dk->pid = fork();
273 if (dk->pid < 0) {
267 (void)strcpy(pt->fsname, fsname);
268 pt->next = NULL;
269 pt->auxdata = auxdata;
270}
271
272static int
273startdisk(dk, checkit)
274 register struct disk *dk;
275 int (*checkit)(char *, char *, long, int);
276{
277 register struct part *pt = dk->part;
278
279 dk->pid = fork();
280 if (dk->pid < 0) {
274 warn("fork");
281 perror("fork");
275 return (8);
276 }
277 if (dk->pid == 0)
278 exit((*checkit)(pt->name, pt->fsname, pt->auxdata, 1));
279 nrun++;
280 return (0);
281}
282
283char *
284blockcheck(origname)
285 char *origname;
286{
287 struct stat stslash, stblock, stchar;
288 char *newname, *raw;
289 struct fstab *fsinfo;
282 return (8);
283 }
284 if (dk->pid == 0)
285 exit((*checkit)(pt->name, pt->fsname, pt->auxdata, 1));
286 nrun++;
287 return (0);
288}
289
290char *
291blockcheck(origname)
292 char *origname;
293{
294 struct stat stslash, stblock, stchar;
295 char *newname, *raw;
296 struct fstab *fsinfo;
290 int retried = 0, l;
297 int retried = 0, len;
291
292 hotroot = 0;
293 if (stat("/", &stslash) < 0) {
298
299 hotroot = 0;
300 if (stat("/", &stslash) < 0) {
294 warn("/");
295 printf("Can't stat root\n");
301 printf("Can't stat /: %s\n", strerror(errno));
296 return (origname);
297 }
298 newname = origname;
299retry:
300 if (stat(newname, &stblock) < 0) {
302 return (origname);
303 }
304 newname = origname;
305retry:
306 if (stat(newname, &stblock) < 0) {
301 warn("%s", newname);
302 printf("Can't stat %s\n", newname);
307 printf("Can't stat %s: %s\n", newname, strerror(errno));
303 return (origname);
304 }
305 if ((stblock.st_mode & S_IFMT) == S_IFBLK) {
306 if (stslash.st_dev == stblock.st_rdev)
307 hotroot++;
308 raw = rawname(newname);
309 if (stat(raw, &stchar) < 0) {
308 return (origname);
309 }
310 if ((stblock.st_mode & S_IFMT) == S_IFBLK) {
311 if (stslash.st_dev == stblock.st_rdev)
312 hotroot++;
313 raw = rawname(newname);
314 if (stat(raw, &stchar) < 0) {
310 warn("%s", raw);
311 printf("Can't stat %s\n", raw);
315 printf("Can't stat %s: %s\n", raw, strerror(errno));
312 return (origname);
313 }
314 if ((stchar.st_mode & S_IFMT) == S_IFCHR) {
315 return (raw);
316 } else {
317 printf("%s is not a character device\n", raw);
318 return (origname);
319 }
320 } else if ((stblock.st_mode & S_IFMT) == S_IFCHR && !retried) {
316 return (origname);
317 }
318 if ((stchar.st_mode & S_IFMT) == S_IFCHR) {
319 return (raw);
320 } else {
321 printf("%s is not a character device\n", raw);
322 return (origname);
323 }
324 } else if ((stblock.st_mode & S_IFMT) == S_IFCHR && !retried) {
321 newname = unrawname(origname);
325 newname = unrawname(newname);
322 retried++;
323 goto retry;
324 } else if ((stblock.st_mode & S_IFMT) == S_IFDIR && !retried) {
326 retried++;
327 goto retry;
328 } else if ((stblock.st_mode & S_IFMT) == S_IFDIR && !retried) {
325 l = strlen(origname) - 1;
326 if (l > 0 && origname[l] == '/')
329 len = strlen(origname) - 1;
330 if (len > 0 && origname[len] == '/')
327 /* remove trailing slash */
331 /* remove trailing slash */
328 origname[l] = '\0';
329 if(!(fsinfo=getfsfile(origname))) {
332 origname[len] = '\0';
333 if ((fsinfo = getfsfile(origname)) == NULL) {
330 printf("Can't resolve %s to character special device",
331 origname);
332 return (0);
333 }
334 newname = fsinfo->fs_spec;
335 retried++;
336 goto retry;
337 }

--- 42 unchanged lines hidden ---
334 printf("Can't resolve %s to character special device",
335 origname);
336 return (0);
337 }
338 newname = fsinfo->fs_spec;
339 retried++;
340 goto retry;
341 }

--- 42 unchanged lines hidden ---