Subject: bin/599: fsck can't check filesystem images in files
To: None <gnats-admin@sun-lamp.cs.berkeley.edu>
From: der Mouse <mouse@Collatz.McRCIM.McGill.EDU>
List: netbsd-bugs
Date: 11/29/1994 17:05:07
>Number:         599
>Category:       bin
>Synopsis:       fsck can't check filesystem images in files
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    gnats-admin (Utility Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Nov 29 17:05:04 1994
>Originator:     der Mouse
>Organization:
	Dis-
>Release:        NetBSD/sparc 1.0
>Environment:
	NetBSD/sparc, SPARC IPC, though it really doesn't matter.
>Description:
	fsck contains code to ensure that it always runs on the
	character special device.  This code can make it impossible to
	do otherwise reasonable things such as fsck filesystem images
	contained in ordinary files.
>How-To-Repeat:
	# dd if=/dev/rsd0a bs=512 of=filesystem-image
	# fsck filesystem-image
	Can't make sense out of name filesystem-image
	Can't stat (null): Bad address
	# 
>Fix:
	Apply the following, then use "fsck -f filesystem-image".

	diff -c -r -s /sources/1.0-usr-src/sbin/fsck/main.c /usr/src/sbin/fsck/main.c
	*** /sources/1.0-usr-src/sbin/fsck/main.c	Wed Jun  8 15:00:24 1994
	--- /usr/src/sbin/fsck/main.c	Tue Nov 29 17:40:28 1994
	***************
	*** 63,75 ****
	  {
	  	int ch;
	  	int ret, maxrun = 0;
	  	extern int docheck(), checkfilesys();
	  	extern char *optarg, *blockcheck();
	  	extern int optind;
	  
	  	sync();
	! 	while ((ch = getopt(argc, argv, "dpnNyYb:c:l:m:")) != EOF) {
	  		switch (ch) {
	  		case 'p':
	  			preen++;
	  			break;
	--- 63,80 ----
	  {
	  	int ch;
	  	int ret, maxrun = 0;
	+ 	int forcename = 0;
	  	extern int docheck(), checkfilesys();
	  	extern char *optarg, *blockcheck();
	  	extern int optind;
	  
	  	sync();
	! 	while ((ch = getopt(argc, argv, "fdpnNyYb:c:l:m:")) != EOF) {
	  		switch (ch) {
	+ 		case 'f':
	+ 			forcename ++;
	+ 			break;
	+ 
	  		case 'p':
	  			preen++;
	  			break;
	***************
	*** 122,128 ****
	  		(void)signal(SIGQUIT, catchquit);
	  	if (argc) {
	  		while (argc-- > 0)
	! 			(void)checkfilesys(blockcheck(*argv++), 0, 0L, 0);
	  		exit(0);
	  	}
	  	ret = checkfstab(preen, maxrun, docheck, checkfilesys);
	--- 127,133 ----
	  		(void)signal(SIGQUIT, catchquit);
	  	if (argc) {
	  		while (argc-- > 0)
	! 			(void)checkfilesys(forcename?*argv++:blockcheck(*argv++), 0, 0L, 0);
	  		exit(0);
	  	}
	  	ret = checkfstab(preen, maxrun, docheck, checkfilesys);
	*** /sources/1.0-usr-src/sbin/fsck/fsck.8	Wed Jun  8 15:00:20 1994
	--- /usr/src/sbin/fsck/fsck.8	Tue Nov 29 19:51:06 1994
	***************
	*** 49,54 ****
	--- 49,55 ----
	  .Op Fl y
	  .Op Fl n
	  .Op Fl m Ar mode
	+ .Op Fl f
	  .Op Ar filesystem
	  .Ar ...
	  .Sh DESCRIPTION
	***************
	*** 178,183 ****
	--- 179,201 ----
	  .Ql CONTINUE? ,
	  which is assumed to be affirmative;
	  do not open the filesystem for writing.
	+ .It Fl f
	+ .Nm fsck
	+ normally tries to ensure that it runs on the character special device
	+ for the filesystem.  In certain special circumstances, this can be a
	+ problem, such as when trying to
	+ .Nm fsck
	+ disk images stored in files.  The
	+ .Fl f
	+ option tells fsck that any filesystem names on the command line are to
	+ be taken literally, no matter what they appear to be, thus allowing you
	+ to fsck disk images in files, filesystems on disk devices with
	+ nonstandard naming schemes, or anything else.  (If you need this
	+ option, you will often have to answer yes to a
	+ .Dq Li "<foo> is not a character device"
	+ /
	+ .Dq Li "CONTINUE? [yn]"
	+ question as well.)
	  .It Fl c
	  Convert the filesystem to the specified level.
	  Note that the level of a filesystem can only be raised.

					der Mouse

			    mouse@collatz.mcrcim.mcgill.edu
>Audit-Trail:
>Unformatted: