main.c (70050) | main.c (74556) |
---|---|
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 70050 2000-12-15 14:23:55Z iedowse $"; | 45 "$FreeBSD: head/sbin/fsck_ffs/main.c 74556 2001-03-21 09:48:03Z mckusick $"; |
46#endif /* not lint */ 47 48#include <sys/param.h> 49#include <sys/stat.h> 50#include <sys/time.h> 51#include <sys/mount.h> 52#include <sys/resource.h> 53 --- 24 unchanged lines hidden (view full) --- 78 char *argv[]; 79{ 80 int ch; 81 struct rlimit rlimit; 82 int ret = 0; 83 84 sync(); 85 skipclean = 1; | 46#endif /* not lint */ 47 48#include <sys/param.h> 49#include <sys/stat.h> 50#include <sys/time.h> 51#include <sys/mount.h> 52#include <sys/resource.h> 53 --- 24 unchanged lines hidden (view full) --- 78 char *argv[]; 79{ 80 int ch; 81 struct rlimit rlimit; 82 int ret = 0; 83 84 sync(); 85 skipclean = 1; |
86 markclean = 1; 87 while ((ch = getopt(argc, argv, "b:c:dfm:npy")) != -1) { | 86 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 | 87 switch (ch) { 88 case 'b': 89 skipclean = 0; 90 bflag = argtoi('b', "number", optarg, 10); 91 printf("Alternate super block location: %d\n", bflag); 92 break; 93 |
94 case 'B': 95 bkgrdflag = 1; 96 break; 97 |
|
95 case 'c': 96 skipclean = 0; 97 cvtlevel = argtoi('c', "conversion level", optarg, 10); 98 break; 99 100 case 'd': 101 debug++; 102 break; --- 75 unchanged lines hidden (view full) --- 178/* ARGSUSED */ 179static int 180checkfilesys(filesys, mntpt, auxdata, child) 181 char *filesys, *mntpt; 182 long auxdata; 183 int child; 184{ 185 ufs_daddr_t n_ffree, n_bfree; | 98 case 'c': 99 skipclean = 0; 100 cvtlevel = argtoi('c', "conversion level", optarg, 10); 101 break; 102 103 case 'd': 104 debug++; 105 break; --- 75 unchanged lines hidden (view full) --- 181/* ARGSUSED */ 182static int 183checkfilesys(filesys, mntpt, auxdata, child) 184 char *filesys, *mntpt; 185 long auxdata; 186 int child; 187{ 188 ufs_daddr_t n_ffree, n_bfree; |
189 struct ufs_args args; |
|
186 struct dups *dp; | 190 struct dups *dp; |
187 struct statfs *mntbuf; | 191 struct statfs *mntp; |
188 struct zlncnt *zlnp; | 192 struct zlncnt *zlnp; |
193 ufs_daddr_t blks; 194 ufs_daddr_t files; |
|
189 int cylno; 190 191 if (preen && child) 192 (void)signal(SIGQUIT, voidquit); 193 cdevname = filesys; 194 if (debug && preen) 195 pwarn("starting\n"); | 195 int cylno; 196 197 if (preen && child) 198 (void)signal(SIGQUIT, voidquit); 199 cdevname = filesys; 200 if (debug && preen) 201 pwarn("starting\n"); |
202 203 /* 204 * If we are to do a background check: 205 * Get the mount point information of the filesystem 206 * create snapshot file 207 * return created snapshot file 208 * if not found, clear bkgrdflag and proceed with normal fsck 209 */ 210 mntp = getmntpt(filesys); 211 if (bkgrdflag) { 212 if (mntp == NULL) { 213 bkgrdflag = 0; 214 pwarn("NOT MOUNTED, CANNOT RUN IN BACKGROUND\n"); 215 } else if ((mntp->f_flags & MNT_SOFTDEP) == 0) { 216 bkgrdflag = 0; 217 pwarn("NOT USING SOFT UPDATES, CANNOT RUN IN BACKGROUND\n"); 218 } else if ((mntp->f_flags & MNT_RDONLY) != 0) { 219 bkgrdflag = 0; 220 pwarn("MOUNTED READ-ONLY, CANNOT RUN IN BACKGROUND\n"); 221 } else { 222 snprintf(snapname, sizeof snapname, "%s/.fsck_snapshot", 223 mntp->f_mntonname); 224 args.fspec = snapname; 225 while (mount("ffs", mntp->f_mntonname, 226 mntp->f_flags | MNT_UPDATE | MNT_SNAPSHOT, 227 &args) < 0) { 228 if (errno == EEXIST && unlink(snapname) == 0) 229 continue; 230 bkgrdflag = 0; 231 pwarn("CANNOT CREATE SNAPSHOT %s: %s\n", 232 snapname, strerror(errno)); 233 break; 234 } 235 if (bkgrdflag != 0) 236 filesys = snapname; 237 } 238 } 239 |
|
196 switch (setup(filesys)) { 197 case 0: 198 if (preen) 199 pfatal("CAN'T CHECK FILE SYSTEM."); 200 return (0); 201 case -1: 202 pwarn("clean, %ld free ", sblock.fs_cstotal.cs_nffree + 203 sblock.fs_frag * sblock.fs_cstotal.cs_nbfree); 204 printf("(%d frags, %d blocks, %.1f%% fragmentation)\n", 205 sblock.fs_cstotal.cs_nffree, sblock.fs_cstotal.cs_nbfree, 206 sblock.fs_cstotal.cs_nffree * 100.0 / sblock.fs_dsize); 207 return (0); 208 } | 240 switch (setup(filesys)) { 241 case 0: 242 if (preen) 243 pfatal("CAN'T CHECK FILE SYSTEM."); 244 return (0); 245 case -1: 246 pwarn("clean, %ld free ", sblock.fs_cstotal.cs_nffree + 247 sblock.fs_frag * sblock.fs_cstotal.cs_nbfree); 248 printf("(%d frags, %d blocks, %.1f%% fragmentation)\n", 249 sblock.fs_cstotal.cs_nffree, sblock.fs_cstotal.cs_nbfree, 250 sblock.fs_cstotal.cs_nffree * 100.0 / sblock.fs_dsize); 251 return (0); 252 } |
209 210 /* 211 * Get the mount point information of the filesystem, if 212 * it is available. 213 */ 214 mntbuf = getmntpt(filesys); | |
215 216 /* 217 * Cleared if any questions answered no. Used to decide if 218 * the superblock should be marked clean. 219 */ 220 resolved = 1; 221 /* 222 * 1: scan inodes tallying blocks used 223 */ 224 if (preen == 0) { 225 printf("** Last Mounted on %s\n", sblock.fs_fsmnt); | 253 254 /* 255 * Cleared if any questions answered no. Used to decide if 256 * the superblock should be marked clean. 257 */ 258 resolved = 1; 259 /* 260 * 1: scan inodes tallying blocks used 261 */ 262 if (preen == 0) { 263 printf("** Last Mounted on %s\n", sblock.fs_fsmnt); |
226 if (mntbuf != NULL && mntbuf->f_flags & MNT_ROOTFS) | 264 if (mntp != NULL && mntp->f_flags & MNT_ROOTFS) |
227 printf("** Root file system\n"); 228 printf("** Phase 1 - Check Blocks and Sizes\n"); 229 } 230 pass1(); 231 232 /* 233 * 1b: locate first references to duplicates, if any 234 */ --- 32 unchanged lines hidden (view full) --- 267 printf("** Phase 5 - Check Cyl groups\n"); 268 pass5(); 269 270 /* 271 * print out summary statistics 272 */ 273 n_ffree = sblock.fs_cstotal.cs_nffree; 274 n_bfree = sblock.fs_cstotal.cs_nbfree; | 265 printf("** Root file system\n"); 266 printf("** Phase 1 - Check Blocks and Sizes\n"); 267 } 268 pass1(); 269 270 /* 271 * 1b: locate first references to duplicates, if any 272 */ --- 32 unchanged lines hidden (view full) --- 305 printf("** Phase 5 - Check Cyl groups\n"); 306 pass5(); 307 308 /* 309 * print out summary statistics 310 */ 311 n_ffree = sblock.fs_cstotal.cs_nffree; 312 n_bfree = sblock.fs_cstotal.cs_nbfree; |
313 files = maxino - ROOTINO - sblock.fs_cstotal.cs_nifree - n_files; 314 blks = n_blks + 315 sblock.fs_ncg * (cgdmin(&sblock, 0) - cgsblock(&sblock, 0)); 316 blks += cgsblock(&sblock, 0) - cgbase(&sblock, 0); 317 blks += howmany(sblock.fs_cssize, sblock.fs_fsize); 318 blks = maxfsblock - (n_ffree + sblock.fs_frag * n_bfree) - blks; 319 if (bkgrdflag && (files > 0 || blks > 0)) { 320 countdirs = sblock.fs_cstotal.cs_ndir - countdirs; 321 pwarn("Reclaimed: %d directories, %d files, %d fragments\n", 322 countdirs, files - countdirs, blks); 323 } |
|
275 pwarn("%ld files, %ld used, %ld free ", 276 n_files, n_blks, n_ffree + sblock.fs_frag * n_bfree); 277 printf("(%d frags, %d blocks, %.1f%% fragmentation)\n", 278 n_ffree, n_bfree, n_ffree * 100.0 / sblock.fs_dsize); | 324 pwarn("%ld files, %ld used, %ld free ", 325 n_files, n_blks, n_ffree + sblock.fs_frag * n_bfree); 326 printf("(%d frags, %d blocks, %.1f%% fragmentation)\n", 327 n_ffree, n_bfree, n_ffree * 100.0 / sblock.fs_dsize); |
279 if (debug && 280 (n_files -= maxino - ROOTINO - sblock.fs_cstotal.cs_nifree)) 281 printf("%d files missing\n", n_files); | |
282 if (debug) { | 328 if (debug) { |
283 n_blks += sblock.fs_ncg * 284 (cgdmin(&sblock, 0) - cgsblock(&sblock, 0)); 285 n_blks += cgsblock(&sblock, 0) - cgbase(&sblock, 0); 286 n_blks += howmany(sblock.fs_cssize, sblock.fs_fsize); 287 if (n_blks -= maxfsblock - (n_ffree + sblock.fs_frag * n_bfree)) 288 printf("%d blocks missing\n", n_blks); | 329 if (files < 0) 330 printf("%d inodes missing\n", -files); 331 if (blks < 0) 332 printf("%d blocks missing\n", -blks); |
289 if (duplist != NULL) { 290 printf("The following duplicate blocks remain:"); 291 for (dp = duplist; dp; dp = dp->next) 292 printf(" %d,", dp->dup); 293 printf("\n"); 294 } 295 if (zlnhead != NULL) { 296 printf("The following zero link count inodes remain:"); --- 19 unchanged lines hidden (view full) --- 316 fsbtodb(&sblock, cgsblock(&sblock, cylno)), SBSIZE); 317 } 318 if (rerun) 319 resolved = 0; 320 321 /* 322 * Check to see if the filesystem is mounted read-write. 323 */ | 333 if (duplist != NULL) { 334 printf("The following duplicate blocks remain:"); 335 for (dp = duplist; dp; dp = dp->next) 336 printf(" %d,", dp->dup); 337 printf("\n"); 338 } 339 if (zlnhead != NULL) { 340 printf("The following zero link count inodes remain:"); --- 19 unchanged lines hidden (view full) --- 360 fsbtodb(&sblock, cgsblock(&sblock, cylno)), SBSIZE); 361 } 362 if (rerun) 363 resolved = 0; 364 365 /* 366 * Check to see if the filesystem is mounted read-write. 367 */ |
324 if (mntbuf != NULL && (mntbuf->f_flags & MNT_RDONLY) == 0) | 368 if (bkgrdflag == 0 && mntp != NULL && (mntp->f_flags & MNT_RDONLY) == 0) |
325 resolved = 0; 326 ckfini(resolved); 327 328 for (cylno = 0; cylno < sblock.fs_ncg; cylno++) 329 if (inostathead[cylno].il_stat != NULL) 330 free((char *)inostathead[cylno].il_stat); 331 free((char *)inostathead); 332 inostathead = NULL; 333 if (fsmodified && !preen) 334 printf("\n***** FILE SYSTEM WAS MODIFIED *****\n"); 335 if (rerun) 336 printf("\n***** PLEASE RERUN FSCK *****\n"); | 369 resolved = 0; 370 ckfini(resolved); 371 372 for (cylno = 0; cylno < sblock.fs_ncg; cylno++) 373 if (inostathead[cylno].il_stat != NULL) 374 free((char *)inostathead[cylno].il_stat); 375 free((char *)inostathead); 376 inostathead = NULL; 377 if (fsmodified && !preen) 378 printf("\n***** FILE SYSTEM WAS MODIFIED *****\n"); 379 if (rerun) 380 printf("\n***** PLEASE RERUN FSCK *****\n"); |
337 if (mntbuf != NULL) { | 381 if (mntp != NULL) { |
338 struct ufs_args args; 339 int ret; 340 /* 341 * We modified a mounted filesystem. Do a mount update on 342 * it unless it is read-write, so we can continue using it 343 * as safely as possible. 344 */ | 382 struct ufs_args args; 383 int ret; 384 /* 385 * We modified a mounted filesystem. Do a mount update on 386 * it unless it is read-write, so we can continue using it 387 * as safely as possible. 388 */ |
345 if (mntbuf->f_flags & MNT_RDONLY) { | 389 if (mntp->f_flags & MNT_RDONLY) { |
346 args.fspec = 0; 347 args.export.ex_flags = 0; 348 args.export.ex_root = 0; | 390 args.fspec = 0; 391 args.export.ex_flags = 0; 392 args.export.ex_root = 0; |
349 ret = mount("ufs", mntbuf->f_mntonname, 350 mntbuf->f_flags | MNT_UPDATE | MNT_RELOAD, &args); | 393 ret = mount("ufs", mntp->f_mntonname, 394 mntp->f_flags | MNT_UPDATE | MNT_RELOAD, &args); |
351 if (ret == 0) 352 return (0); 353 pwarn("mount reload of '%s' failed: %s\n\n", | 395 if (ret == 0) 396 return (0); 397 pwarn("mount reload of '%s' failed: %s\n\n", |
354 mntbuf->f_mntonname, strerror(errno)); | 398 mntp->f_mntonname, strerror(errno)); |
355 } 356 if (!fsmodified) 357 return (0); 358 if (!preen) 359 printf("\n***** REBOOT NOW *****\n"); 360 sync(); 361 return (4); 362 } --- 47 unchanged lines hidden --- | 399 } 400 if (!fsmodified) 401 return (0); 402 if (!preen) 403 printf("\n***** REBOOT NOW *****\n"); 404 sync(); 405 return (4); 406 } --- 47 unchanged lines hidden --- |