xref: /csrg-svn/sbin/fsck/main.c (revision 16257)
112728Ssam #ifndef lint
2*16257Smckusick static char version[] = "@(#)main.c	3.1 (Berkeley) 03/31/84";
312728Ssam #endif
44428Smckusic 
56489Smckusick #include <sys/param.h>
6*16257Smckusick #include <sys/inode.h>
76489Smckusick #include <sys/fs.h>
8*16257Smckusick #include "fsck.h"
94236Smckusick 
109255Smckusick checkfilesys(filesys)
119255Smckusick 	char *filesys;
124236Smckusick {
134236Smckusick 
149255Smckusick 	devname = filesys;
159255Smckusick 	if (setup(filesys) == 0) {
164236Smckusick 		if (preen)
179255Smckusick 			pfatal("CAN'T CHECK FILE SYSTEM.");
184236Smckusick 		return;
194236Smckusick 	}
209255Smckusick /* 1: scan inodes tallying blocks used */
216837Smckusick 	if (preen == 0) {
226837Smckusick 		printf("** Last Mounted on %s\n", sblock.fs_fsmnt);
234236Smckusick 		if (hotroot)
244236Smckusick 			printf("** Root file system\n");
254236Smckusick 		printf("** Phase 1 - Check Blocks and Sizes\n");
264236Smckusick 	}
279255Smckusick 	pass1();
289255Smckusick 
299255Smckusick /* 1b: locate first references to duplicates, if any */
309255Smckusick 	if (enddup != &duplist[0]) {
319255Smckusick 		if (preen)
329255Smckusick 			pfatal("INTERNAL ERROR: dups with -p");
339255Smckusick 		printf("** Phase 1b - Rescan For More DUPS\n");
349255Smckusick 		pass1b();
359255Smckusick 	}
369255Smckusick 
3714952Smckusick /* 2: traverse directories from root to mark all connected directories */
389255Smckusick 	if (preen == 0)
399255Smckusick 		printf("** Phase 2 - Check Pathnames\n");
409255Smckusick 	pass2();
419255Smckusick 
4214952Smckusick /* 3: scan inodes looking for disconnected directories */
439255Smckusick 	if (preen == 0)
449255Smckusick 		printf("** Phase 3 - Check Connectivity\n");
459255Smckusick 	pass3();
469255Smckusick 
4714952Smckusick /* 4: scan inodes looking for disconnected files; check reference counts */
489255Smckusick 	if (preen == 0)
499255Smckusick 		printf("** Phase 4 - Check Reference Counts\n");
509255Smckusick 	pass4();
519255Smckusick 
5214952Smckusick /* 5: check resource counts in cylinder groups */
539255Smckusick 	if (preen == 0)
549255Smckusick 		printf("** Phase 5 - Check Cyl groups\n");
559255Smckusick 	pass5();
569255Smckusick 
579255Smckusick 	if (fixcg) {
589255Smckusick 		if (preen == 0)
599255Smckusick 			printf("** Phase 6 - Salvage Cylinder Groups\n");
609255Smckusick 		makecg();
619255Smckusick 		n_ffree = sblock.fs_cstotal.cs_nffree;
629255Smckusick 		n_bfree = sblock.fs_cstotal.cs_nbfree;
639255Smckusick 	}
649255Smckusick 
659255Smckusick 	pwarn("%d files, %d used, %d free (%d frags, %d blocks)\n",
669255Smckusick 	    n_files, n_blks - howmany(sblock.fs_cssize, sblock.fs_fsize),
679255Smckusick 	    n_ffree + sblock.fs_frag * n_bfree, n_ffree, n_bfree);
689255Smckusick 	if (dfile.mod) {
6914952Smckusick 		(void)time(&sblock.fs_time);
709255Smckusick 		sbdirty();
719255Smckusick 	}
729255Smckusick 	ckfini();
739255Smckusick 	free(blockmap);
749255Smckusick 	free(freemap);
759255Smckusick 	free(statemap);
7614952Smckusick 	free((char *)lncntp);
7713729Sroot 	if (!dfile.mod)
7813729Sroot 		return;
7913729Sroot 	if (!preen) {
8013729Sroot 		printf("\n***** FILE SYSTEM WAS MODIFIED *****\n");
8113729Sroot 		if (hotroot)
8213729Sroot 			printf("\n***** REBOOT UNIX *****\n");
839255Smckusick 	}
8413729Sroot 	if (hotroot) {
8513729Sroot 		sync();
8613729Sroot 		exit(4);
8713729Sroot 	}
889255Smckusick }
89