Subject: Re: ^T for fsck
To: Michael Richardson <mcr@sandelman.ottawa.on.ca>
From: Assar Westerlund <assar@netbsd.org>
List: tech-userlevel
Date: 03/05/2001 14:09:06
--=-=-=

Michael Richardson <mcr@sandelman.ottawa.on.ca> writes:
>     der> Actually, shouldn't they go to /dev/tty?  (Ideally, it seems to me
> 
>   Yes, I think you would be right...

New patches included below.  /dev/tty seems the right thing to me for
the extreme rare cases of someone wanting to do fsck >/tmp/bla and see
how it goes.  And as I understood the consensus it seemed that
SA_RESTART should be enough to not cause bad things to happen.  The
code still uses signal() instead of sigaction() but since that calls
sigaction() with SA_RESTART it should be ok.  Any more comments?
Anyone against commiting this patch?

/assar

--=-=-=
Content-Disposition: attachment; filename=fsck2-siginfo.diff

Index: extern.h
===================================================================
RCS file: /cvsroot/basesrc/sbin/fsck_ffs/extern.h,v
retrieving revision 1.13
diff -u -w -r1.13 extern.h
--- extern.h	2001/02/04 21:25:54	1.13
+++ extern.h	2001/03/05 13:06:27
@@ -79,3 +79,6 @@
 
 void	swap_cg __P((struct cg *, struct cg *));
 void copyback_cg __P((struct bufarea *));
+void		infohandler __P((int));
+
+extern FILE	*tty;
Index: fsck.h
===================================================================
RCS file: /cvsroot/basesrc/sbin/fsck_ffs/fsck.h,v
retrieving revision 1.24
diff -u -w -r1.24 fsck.h
--- fsck.h	2001/02/04 21:25:54	1.24
+++ fsck.h	2001/03/05 13:06:27
@@ -216,6 +216,8 @@
 ufs_daddr_t n_blks;		/* number of blocks in use */
 ufs_daddr_t n_files;		/* number of files in use */
 
+sig_atomic_t	got_siginfo;	/* received a SIGINFO */
+
 #define	clearinode(dp)	(*(dp) = zino)
 struct	dinode zino;
 
Index: main.c
===================================================================
RCS file: /cvsroot/basesrc/sbin/fsck_ffs/main.c,v
retrieving revision 1.39
diff -u -w -r1.39 main.c
--- main.c	2001/02/23 07:51:41	1.39
+++ main.c	2001/03/05 13:06:27
@@ -66,6 +66,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <paths.h>
 
 #include "fsck.h"
 #include "extern.h"
@@ -73,6 +74,8 @@
 
 int	returntosingle;
 
+FILE	*tty;
+
 int	main __P((int, char *[]));
 
 static int	argtoi __P((int, char *, char *, int));
@@ -88,6 +91,8 @@
 	int ch;
 	int ret = 0;
 
+	tty = fopen(_PATH_TTY, "w");
+
 	if (getrlimit(RLIMIT_DATA, &r) == 0) {
 		r.rlim_cur = r.rlim_max;
 		(void) setrlimit(RLIMIT_DATA, &r);
@@ -161,6 +166,7 @@
 		(void)signal(SIGINT, catch);
 	if (preen)
 		(void)signal(SIGQUIT, catchquit);
+	signal(SIGINFO, infohandler);
 
 	while (argc-- > 0)
 		(void)checkfilesys(blockcheck(*argv++), 0, 0L, 0);
Index: pass1.c
===================================================================
RCS file: /cvsroot/basesrc/sbin/fsck_ffs/pass1.c,v
retrieving revision 1.23
diff -u -w -r1.23 pass1.c
--- pass1.c	2001/01/05 02:02:57	1.23
+++ pass1.c	2001/03/05 13:06:27
@@ -95,6 +95,14 @@
 	n_files = n_blks = 0;
 	resetinodebuf();
 	for (c = 0; c < sblock->fs_ncg; c++) {
+		if (got_siginfo) {
+			if (tty != NULL)
+				fprintf(tty,
+				"%s: phase 1: cyl group %d of %d (%d%%)\n",
+				cdevname(), c, sblock->fs_ncg,
+				c * 100 / sblock->fs_ncg);
+			got_siginfo = 0;
+		}
 		for (i = 0; i < sblock->fs_ipg; i++, inumber++) {
 			if (inumber < ROOTINO)
 				continue;
Index: pass1b.c
===================================================================
RCS file: /cvsroot/basesrc/sbin/fsck_ffs/pass1b.c,v
retrieving revision 1.13
diff -u -w -r1.13 pass1b.c
--- pass1b.c	1998/03/18 17:01:24	1.13
+++ pass1b.c	2001/03/05 13:06:27
@@ -52,6 +52,7 @@
 
 #include "fsck.h"
 #include "extern.h"
+#include "fsutil.h"
 
 static  struct dups *duphead;
 static int pass1bcheck __P((struct inodesc *));
@@ -70,6 +71,14 @@
 	duphead = duplist;
 	inumber = 0;
 	for (c = 0; c < sblock->fs_ncg; c++) {
+		if (got_siginfo) {
+			if (tty != NULL)
+				fprintf(tty,
+				"%s: phase 1b: cyl group %d of %d (%d%%)\n",
+				cdevname(), c, sblock->fs_ncg,
+				c * 100 / sblock->fs_ncg);
+			got_siginfo = 0;
+		}
 		for (i = 0; i < sblock->fs_ipg; i++, inumber++) {
 			if (inumber < ROOTINO)
 				continue;
Index: pass2.c
===================================================================
RCS file: /cvsroot/basesrc/sbin/fsck_ffs/pass2.c,v
retrieving revision 1.29
diff -u -w -r1.29 pass2.c
--- pass2.c	2001/01/09 05:51:14	1.29
+++ pass2.c	2001/03/05 13:06:27
@@ -142,6 +142,15 @@
 	curino.id_func = pass2check;
 	inpend = &inpsort[inplast];
 	for (inpp = inpsort; inpp < inpend; inpp++) {
+		if (got_siginfo) {
+			if (tty != NULL)
+				fprintf(tty,
+				"%s: phase 2: dir %d of %ld (%ld%%)\n",
+				cdevname(),
+				inpp - inpsort, inplast,
+				(inpp - inpsort) * 100 / inplast);
+			got_siginfo = 0;
+		}
 		inp = *inpp;
 		if (inp->i_isize == 0)
 			continue;
Index: pass3.c
===================================================================
RCS file: /cvsroot/basesrc/sbin/fsck_ffs/pass3.c,v
retrieving revision 1.12
diff -u -w -r1.12 pass3.c
--- pass3.c	2001/01/10 08:22:20	1.12
+++ pass3.c	2001/03/05 13:06:27
@@ -50,16 +50,26 @@
 
 #include "fsck.h"
 #include "extern.h"
+#include "fsutil.h"
 
 void
 pass3()
 {
-	struct inoinfo **inpp, *inp;
+	struct inoinfo*inp;
 	ino_t orphan;
-	int loopcnt;
+	int loopcnt, inpindex;
 
-	for (inpp = &inpsort[inplast - 1]; inpp >= inpsort; inpp--) {
-		inp = *inpp;
+	for (inpindex = inplast - 1; inpindex >= 0; inpindex--) {
+		if (got_siginfo) {
+			if (tty != NULL)
+				fprintf(tty,
+				"%s: phase 3: dir %ld of %ld (%ld%%)\n",
+			        cdevname(),
+			        inplast - inpindex - 1, inplast,
+			        (inplast - inpindex - 1) * 100 / inplast);
+			got_siginfo = 0;
+		}
+		inp = inpsort[inpindex];
 		if (inp->i_number == ROOTINO ||
 		    !(inp->i_parent == 0 || statemap[inp->i_number] == DSTATE))
 			continue;
Index: pass4.c
===================================================================
RCS file: /cvsroot/basesrc/sbin/fsck_ffs/pass4.c,v
retrieving revision 1.14
diff -u -w -r1.14 pass4.c
--- pass4.c	1997/09/20 06:16:32	1.14
+++ pass4.c	2001/03/05 13:06:27
@@ -69,6 +69,15 @@
 	idesc.id_type = ADDR;
 	idesc.id_func = pass4check;
 	for (inumber = ROOTINO; inumber <= lastino; inumber++) {
+		if (got_siginfo) {
+			if (tty != NULL)
+				fprintf(tty,
+				"%s: phase 4: inode %u of %u (%u%%)\n",
+				cdevname(), inumber, lastino,
+				inumber * 100 / lastino);
+			got_siginfo = 0;
+		}
+
 		idesc.id_number = inumber;
 		switch (statemap[inumber]) {
 
Index: pass5.c
===================================================================
RCS file: /cvsroot/basesrc/sbin/fsck_ffs/pass5.c,v
retrieving revision 1.26
diff -u -w -r1.26 pass5.c
--- pass5.c	2001/01/26 17:37:16	1.26
+++ pass5.c	2001/03/05 13:06:27
@@ -185,6 +185,14 @@
 	for (i = fs->fs_size; i < j; i++)
 		setbmap(i);
 	for (c = 0; c < fs->fs_ncg; c++) {
+		if (got_siginfo) {
+			if (tty != NULL)
+				fprintf(tty,
+				"%s: phase 5: cyl group %d of %d (%d%%)\n",
+			        cdevname(), c, fs->fs_ncg,
+			        c * 100 / fs->fs_ncg);
+			got_siginfo = 0;
+		}
 		getblk(&cgblk, cgtod(fs, c), fs->fs_cgsize);
 		memcpy(cg, cgblk.b_un.b_cg, fs->fs_cgsize);
 		if((doswap && !needswap) || (!doswap && needswap))
Index: utilities.c
===================================================================
RCS file: /cvsroot/basesrc/sbin/fsck_ffs/utilities.c,v
retrieving revision 1.30
diff -u -w -r1.30 utilities.c
--- utilities.c	2001/02/04 21:25:54	1.30
+++ utilities.c	2001/03/05 13:06:27
@@ -694,3 +694,10 @@
 			n32[i] = bswap32(o32[i]);
 	}
 }
+
+void
+infohandler(sig)
+	int sig;
+{
+	got_siginfo = 1;
+}

--=-=-=--