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 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 |
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; |
85 while ((ch = getopt(argc, argv, "b:Bc:dfFm:npy")) != -1) { |
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 |
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) |
159 (void)checkfilesys(*argv++, 0, 0L, 0); |
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; |
198 int cylno, size; |
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 */ |
221 sblock_init(); |
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 } |
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 */ |
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/* |
467 * Get the mount point information for name. |
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; |
476 struct statfs *mntbuf, *statfsp; 477 int i, mntsize, isdev; |
478 |
479 if (stat(name, &devstat) != 0) |
480 return (NULL); |
481 if (S_ISCHR(devstat.st_mode) || S_ISBLK(devstat.st_mode)) 482 isdev = 1; 483 else 484 isdev = 0; |
485 mntsize = getmntinfo(&mntbuf, MNT_NOWAIT); 486 for (i = 0; i < mntsize; i++) { |
487 statfsp = &mntbuf[i]; 488 devname = statfsp->f_mntfromname; |
489 if (*devname != '/') { 490 strcpy(device, _PATH_DEV); 491 strcat(device, devname); |
492 strcpy(statfsp->f_mntfromname, device); |
493 } |
494 if (isdev == 0) { 495 if (strcmp(name, statfsp->f_mntonname)) 496 continue; 497 return (statfsp); 498 } |
499 if (stat(devname, &mntdevstat) == 0 && 500 mntdevstat.st_rdev == devstat.st_rdev) |
501 return (statfsp); |
502 } |
503 statfsp = NULL; 504 return (statfsp); |
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} |