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 --- 24 unchanged lines hidden (view full) --- 33 34#ifndef lint 35static const char copyright[] = 36"@(#) Copyright (c) 1980, 1986, 1993\n\ 37 The Regents of the University of California. All rights reserved.\n"; 38#endif /* not lint */ 39 40#ifndef lint |
41static const char sccsid[] = "@(#)main.c 8.6 (Berkeley) 5/14/95"; |
42#endif /* not lint */ 43 44#include <sys/param.h> 45#include <sys/time.h> 46#include <sys/proc.h> 47#include <sys/mount.h> |
48 |
49#include <ufs/ufs/dinode.h> |
50#include <ufs/ufs/ufsmount.h> |
51#include <ufs/ffs/fs.h> |
52 53#include <ctype.h> 54#include <err.h> |
55#include <fstab.h> 56#include <stdlib.h> 57#include <unistd.h> 58#include <string.h> 59#include <stdio.h> |
60 |
61#include "fsck.h" |
62 |
63int returntosingle; 64 65static int argtoi __P((int flag, char *req, char *str, int base)); 66static int docheck __P((struct fstab *fsp)); 67static int checkfilesys __P((char *filesys, char *mntpt, long auxdata, 68 int child)); 69int main __P((int argc, char *argv[])); 70 |
71int 72main(argc, argv) 73 int argc; 74 char *argv[]; 75{ 76 int ch; 77 int ret, maxrun = 0; 78 extern char *optarg; --- 25 unchanged lines hidden (view full) --- 104 105 case 'l': 106 maxrun = argtoi('l', "number", optarg, 10); 107 break; 108 109 case 'm': 110 lfmode = argtoi('m', "mode", optarg, 8); 111 if (lfmode &~ 07777) |
112 errx(EEXIT, "bad mode to -m: %o", lfmode); |
113 printf("** lost+found creation mode %o\n", lfmode); 114 break; 115 116 case 'n': 117 case 'N': 118 nflag++; 119 yflag = 0; 120 break; 121 122 case 'y': 123 case 'Y': 124 yflag++; 125 nflag = 0; 126 break; 127 128 default: |
129 errx(EEXIT, "%c option?", ch); |
130 } 131 } 132 argc -= optind; 133 argv += optind; 134 if (signal(SIGINT, SIG_IGN) != SIG_IGN) 135 (void)signal(SIGINT, catch); 136 if (preen) 137 (void)signal(SIGQUIT, catchquit); 138 if (argc) { 139 while (argc-- > 0) 140 (void)checkfilesys(blockcheck(*argv++), 0, 0L, 0); 141 exit(0); 142 } 143 ret = checkfstab(preen, maxrun, docheck, checkfilesys); 144 if (returntosingle) 145 exit(2); 146 exit(ret); 147} 148 |
149static int |
150argtoi(flag, req, str, base) 151 int flag; 152 char *req, *str; 153 int base; 154{ 155 char *cp; 156 int ret; 157 158 ret = (int)strtol(str, &cp, base); 159 if (cp == str || *cp) |
160 errx(EEXIT, "-%c flag requires a %s", flag, req); |
161 return (ret); 162} 163 164/* 165 * Determine whether a filesystem should be checked. 166 */ |
167static int |
168docheck(fsp) 169 register struct fstab *fsp; 170{ 171 172 if (strcmp(fsp->fs_vfstype, "ufs") || 173 (strcmp(fsp->fs_type, FSTAB_RW) && 174 strcmp(fsp->fs_type, FSTAB_RO)) || 175 fsp->fs_passno == 0) 176 return (0); 177 return (1); 178} 179 180/* 181 * Check the specified filesystem. 182 */ 183/* ARGSUSED */ |
184static int |
185checkfilesys(filesys, mntpt, auxdata, child) 186 char *filesys, *mntpt; 187 long auxdata; 188 int child; 189{ |
190 ufs_daddr_t n_ffree, n_bfree; |
191 struct dups *dp; 192 struct zlncnt *zlnp; |
193 int cylno, flags; |
194 195 if (preen && child) 196 (void)signal(SIGQUIT, voidquit); 197 cdevname = filesys; 198 if (debug && preen) 199 pwarn("starting\n"); |
200 switch (setup(filesys)) { 201 case 0: |
202 if (preen) 203 pfatal("CAN'T CHECK FILE SYSTEM."); |
204 /* fall through */ 205 case -1: |
206 return (0); 207 } 208 209 if (preen && sblock.fs_clean && !fflag) { 210 pwarn("clean, %ld free ", sblock.fs_cstotal.cs_nffree + 211 sblock.fs_frag * sblock.fs_cstotal.cs_nbfree); 212 printf("(%ld frags, %ld blocks, %.1f%% fragmentation)\n", 213 sblock.fs_cstotal.cs_nffree, --- 96 unchanged lines hidden (view full) --- 310 if (cvtlevel && sblk.b_dirty) { 311 /* 312 * Write out the duplicate super blocks 313 */ 314 for (cylno = 0; cylno < sblock.fs_ncg; cylno++) 315 bwrite(fswritefd, (char *)&sblock, 316 fsbtodb(&sblock, cgsblock(&sblock, cylno)), SBSIZE); 317 } |
318 if (!hotroot) { 319 ckfini(1); 320 } else { 321 struct statfs stfs_buf; 322 /* 323 * Check to see if root is mounted read-write. 324 */ 325 if (statfs("/", &stfs_buf) == 0) 326 flags = stfs_buf.f_flags; 327 else 328 flags = 0; 329 ckfini(flags & MNT_RDONLY); 330 } |
331 free(blockmap); 332 free(statemap); 333 free((char *)lncntp); 334 if (!fsmodified) 335 return (0); 336 if (!preen) 337 printf("\n***** FILE SYSTEM WAS MODIFIED *****\n"); 338 if (rerun) 339 printf("\n***** PLEASE RERUN FSCK *****\n"); 340 if (hotroot) { |
341 struct ufs_args args; 342 int ret; |
343 /* 344 * We modified the root. Do a mount update on 345 * it, unless it is read-write, so we can continue. 346 */ |
347 if (flags & MNT_RDONLY) { 348 args.fspec = 0; 349 args.export.ex_flags = 0; 350 args.export.ex_root = 0; 351 flags |= MNT_UPDATE | MNT_RELOAD; 352 ret = mount("ufs", "/", flags, &args); 353 if (ret == 0) 354 return (0); |
355 } 356 if (!preen) 357 printf("\n***** REBOOT NOW *****\n"); 358 sync(); 359 return (4); 360 } 361 return (0); 362} |