Deleted Added
sdiff udiff text old ( 75557 ) new ( 75927 )
full compact
1/*
2 * Copyright (c) 1980, 1986, 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

--- 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
41#if 0
42static char sccsid[] = "@(#)main.c 8.6 (Berkeley) 5/14/95";
43#endif
44static const char rcsid[] =
45 "$FreeBSD: head/sbin/fsck_ffs/main.c 75557 2001-04-16 22:22:21Z mckusick $";
46#endif /* not lint */
47
48#include <sys/param.h>
49#include <sys/stat.h>
50#include <sys/file.h>
51#include <sys/time.h>
52#include <sys/mount.h>
53#include <sys/resource.h>

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

58
59#include <err.h>
60#include <errno.h>
61#include <fstab.h>
62#include <paths.h>
63
64#include "fsck.h"
65
66int returntosingle;
67
68static void usage __P((void));
69static int argtoi __P((int flag, char *req, char *str, int base));
70static int docheck __P((struct fstab *fsp));
71static int checkfilesys __P((char *filesys, char *mntpt, long auxdata,
72 int child));
73static struct statfs *getmntpt __P((const char *));
74int main __P((int argc, char *argv[]));
75
76int
77main(argc, argv)
78 int argc;
79 char *argv[];
80{
81 int ch;
82 struct rlimit rlimit;
83 int ret = 0;
84
85 sync();
86 skipclean = 1;
87 while ((ch = getopt(argc, argv, "b:Bc:dfm:npy")) != -1) {
88 switch (ch) {
89 case 'b':
90 skipclean = 0;
91 bflag = argtoi('b', "number", optarg, 10);
92 printf("Alternate super block location: %d\n", bflag);
93 break;
94
95 case 'B':

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

104 case 'd':
105 debug++;
106 break;
107
108 case 'f':
109 skipclean = 0;
110 break;
111
112 case 'm':
113 lfmode = argtoi('m', "mode", optarg, 8);
114 if (lfmode &~ 07777)
115 errx(EEXIT, "bad mode to -m: %o", lfmode);
116 printf("** lost+found creation mode %o\n", lfmode);
117 break;
118
119 case 'n':

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

149 * Push up our allowed memory limit so we can cope
150 * with huge filesystems.
151 */
152 if (getrlimit(RLIMIT_DATA, &rlimit) == 0) {
153 rlimit.rlim_cur = rlimit.rlim_max;
154 (void)setrlimit(RLIMIT_DATA, &rlimit);
155 }
156 while (argc-- > 0)
157 (void)checkfilesys(blockcheck(*argv++), 0, 0L, 0);
158
159 if (returntosingle)
160 ret = 2;
161 exit(ret);
162}
163
164static int
165argtoi(flag, req, str, base)

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

188{
189 ufs_daddr_t n_ffree, n_bfree;
190 struct ufs_args args;
191 struct dups *dp;
192 struct statfs *mntp;
193 struct zlncnt *zlnp;
194 ufs_daddr_t blks;
195 ufs_daddr_t files;
196 int cylno;
197
198 if (preen && child)
199 (void)signal(SIGQUIT, voidquit);
200 cdevname = filesys;
201 if (debug && preen)
202 pwarn("starting\n");
203 sblock_init();
204
205 /*
206 * If we are to do a background check:
207 * Get the mount point information of the filesystem
208 * create snapshot file
209 * return created snapshot file
210 * if not found, clear bkgrdflag and proceed with normal fsck
211 */
212 mntp = getmntpt(filesys);
213 if (bkgrdflag) {
214 if (mntp == NULL) {
215 bkgrdflag = 0;
216 pfatal("NOT MOUNTED, CANNOT RUN IN BACKGROUND\n");
217 } else if ((mntp->f_flags & MNT_SOFTDEP) == 0) {
218 bkgrdflag = 0;
219 pfatal("NOT USING SOFT UPDATES, %s\n",
220 "CANNOT RUN IN BACKGROUND");

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

427 printf("\n***** REBOOT NOW *****\n");
428 sync();
429 return (4);
430 }
431 return (0);
432}
433
434/*
435 * Get the directory that the device is mounted on.
436 */
437static struct statfs *
438getmntpt(name)
439 const char *name;
440{
441 struct stat devstat, mntdevstat;
442 char device[sizeof(_PATH_DEV) - 1 + MNAMELEN];
443 char *devname;
444 struct statfs *mntbuf;
445 int i, mntsize;
446
447 if (stat(name, &devstat) != 0 ||
448 !(S_ISCHR(devstat.st_mode) || S_ISBLK(devstat.st_mode)))
449 return (NULL);
450 mntsize = getmntinfo(&mntbuf, MNT_NOWAIT);
451 for (i = 0; i < mntsize; i++) {
452 if (strcmp(mntbuf[i].f_fstypename, "ufs") != 0)
453 continue;
454 devname = mntbuf[i].f_mntfromname;
455 if (*devname != '/') {
456 strcpy(device, _PATH_DEV);
457 strcat(device, devname);
458 devname = device;
459 }
460 if (stat(devname, &mntdevstat) == 0 &&
461 mntdevstat.st_rdev == devstat.st_rdev)
462 return (&mntbuf[i]);
463 }
464 return (NULL);
465}
466
467static void
468usage()
469{
470 extern char *__progname;
471
472 (void) fprintf(stderr,
473 "Usage: %s [-dfnpy] [-B be|le] [-b block] [-c level] [-m mode] "
474 "filesystem ...\n",
475 __progname);
476 exit(1);
477}