Deleted Added
full compact
main.c (75557) main.c (75927)
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[] =
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 $";
45 "$FreeBSD: head/sbin/fsck_ffs/main.c 75927 2001-04-24 22:38:08Z 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
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;
66static void usage __P((void));
67static int argtoi __P((int flag, char *req, char *str, int base));
68static int docheck __P((struct fstab *fsp));
69static int checkfilesys __P((char *filesys, char *mntpt, long auxdata,
70 int child));
71static struct statfs *getmntpt __P((const char *));
72int main __P((int argc, char *argv[]));
73
74int
75main(argc, argv)
76 int argc;
77 char *argv[];
78{
79 int ch;
80 struct rlimit rlimit;
81 int ret = 0;
82
83 sync();
84 skipclean = 1;
87 while ((ch = getopt(argc, argv, "b:Bc:dfm:npy")) != -1) {
85 while ((ch = getopt(argc, argv, "b:Bc:dfFm: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
86 switch (ch) {
87 case 'b':
88 skipclean = 0;
89 bflag = argtoi('b', "number", optarg, 10);
90 printf("Alternate super block location: %d\n", bflag);
91 break;
92
93 case 'B':

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

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

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

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

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

190{
191 ufs_daddr_t n_ffree, n_bfree;
192 struct ufs_args args;
193 struct dups *dp;
194 struct statfs *mntp;
195 struct zlncnt *zlnp;
196 ufs_daddr_t blks;
197 ufs_daddr_t files;
196 int cylno;
198 int cylno, size;
197
198 if (preen && child)
199 (void)signal(SIGQUIT, voidquit);
200 cdevname = filesys;
201 if (debug && preen)
202 pwarn("starting\n");
199
200 if (preen && child)
201 (void)signal(SIGQUIT, voidquit);
202 cdevname = filesys;
203 if (debug && preen)
204 pwarn("starting\n");
205 /*
206 * Make best effort to get the disk name. Check first to see
207 * if it is listed among the mounted filesystems. Failing that
208 * check to see if it is listed in /etc/fstab.
209 */
210 mntp = getmntpt(filesys);
211 if (mntp != NULL)
212 filesys = mntp->f_mntfromname;
213 else
214 filesys = blockcheck(filesys);
215 /*
216 * If -F flag specified, check to see whether a background check
217 * is possible and needed. If possible and needed, exit with
218 * status zero. Otherwise exit with status non-zero. A non-zero
219 * exit status will cause a foreground check to be run.
220 */
203 sblock_init();
221 sblock_init();
204
222 if (bkgrdcheck) {
223 if ((fsreadfd = open(filesys, O_RDONLY)) < 0 || readsb(0) == 0)
224 exit(3); /* Cannot read superblock */
225 close(fsreadfd);
226 if (sblock.fs_flags & FS_NEEDSFSCK)
227 exit(4); /* Earlier background failed */
228 if ((sblock.fs_flags & FS_DOSOFTDEP) == 0)
229 exit(5); /* Not running soft updates */
230 size = MIBSIZE;
231 if (sysctlnametomib("vfs.ffs.adjrefcnt", adjrefcnt, &size) < 0)
232 exit(6); /* Lacks kernel support */
233 if ((mntp == NULL && sblock.fs_clean == 1) ||
234 (mntp != NULL && (sblock.fs_flags & FS_UNCLEAN) == 0))
235 exit(7); /* Filesystem clean, report it now */
236 exit(0);
237 }
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 */
238 /*
239 * If we are to do a background check:
240 * Get the mount point information of the filesystem
241 * create snapshot file
242 * return created snapshot file
243 * if not found, clear bkgrdflag and proceed with normal fsck
244 */
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/*
245 if (bkgrdflag) {
246 if (mntp == NULL) {
247 bkgrdflag = 0;
248 pfatal("NOT MOUNTED, CANNOT RUN IN BACKGROUND\n");
249 } else if ((mntp->f_flags & MNT_SOFTDEP) == 0) {
250 bkgrdflag = 0;
251 pfatal("NOT USING SOFT UPDATES, %s\n",
252 "CANNOT RUN IN BACKGROUND");

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

459 printf("\n***** REBOOT NOW *****\n");
460 sync();
461 return (4);
462 }
463 return (0);
464}
465
466/*
435 * Get the directory that the device is mounted on.
467 * Get the mount point information for name.
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;
468 */
469static struct statfs *
470getmntpt(name)
471 const char *name;
472{
473 struct stat devstat, mntdevstat;
474 char device[sizeof(_PATH_DEV) - 1 + MNAMELEN];
475 char *devname;
444 struct statfs *mntbuf;
445 int i, mntsize;
476 struct statfs *mntbuf, *statfsp;
477 int i, mntsize, isdev;
446
478
447 if (stat(name, &devstat) != 0 ||
448 !(S_ISCHR(devstat.st_mode) || S_ISBLK(devstat.st_mode)))
479 if (stat(name, &devstat) != 0)
449 return (NULL);
480 return (NULL);
481 if (S_ISCHR(devstat.st_mode) || S_ISBLK(devstat.st_mode))
482 isdev = 1;
483 else
484 isdev = 0;
450 mntsize = getmntinfo(&mntbuf, MNT_NOWAIT);
451 for (i = 0; i < mntsize; i++) {
485 mntsize = getmntinfo(&mntbuf, MNT_NOWAIT);
486 for (i = 0; i < mntsize; i++) {
452 if (strcmp(mntbuf[i].f_fstypename, "ufs") != 0)
453 continue;
454 devname = mntbuf[i].f_mntfromname;
487 statfsp = &mntbuf[i];
488 devname = statfsp->f_mntfromname;
455 if (*devname != '/') {
456 strcpy(device, _PATH_DEV);
457 strcat(device, devname);
489 if (*devname != '/') {
490 strcpy(device, _PATH_DEV);
491 strcat(device, devname);
458 devname = device;
492 strcpy(statfsp->f_mntfromname, device);
459 }
493 }
494 if (isdev == 0) {
495 if (strcmp(name, statfsp->f_mntonname))
496 continue;
497 return (statfsp);
498 }
460 if (stat(devname, &mntdevstat) == 0 &&
461 mntdevstat.st_rdev == devstat.st_rdev)
499 if (stat(devname, &mntdevstat) == 0 &&
500 mntdevstat.st_rdev == devstat.st_rdev)
462 return (&mntbuf[i]);
501 return (statfsp);
463 }
502 }
464 return (NULL);
503 statfsp = NULL;
504 return (statfsp);
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}
505}
506
507static void
508usage()
509{
510 extern char *__progname;
511
512 (void) fprintf(stderr,
513 "Usage: %s [-dfnpy] [-B be|le] [-b block] [-c level] [-m mode] "
514 "filesystem ...\n",
515 __progname);
516 exit(1);
517}