[Ocfs2-tools-commits] zab commits r248 - in trunk/fsck.ocfs2: . include

svn-commits at oss.oracle.com svn-commits at oss.oracle.com
Wed Sep 22 19:18:26 CDT 2004


Author: zab
Date: 2004-09-22 19:18:24 -0500 (Wed, 22 Sep 2004)
New Revision: 248

Added:
   trunk/fsck.ocfs2/include/problem.h
   trunk/fsck.ocfs2/include/util.h
   trunk/fsck.ocfs2/problem.c
   trunk/fsck.ocfs2/util.c
Modified:
   trunk/fsck.ocfs2/Makefile
   trunk/fsck.ocfs2/fsck.c
   trunk/fsck.ocfs2/include/fsck.h
   trunk/fsck.ocfs2/pass1.c
Log:
o Add the start of the 'problem' constructs to start doing real work
o brought in e2fsck's return code bit mask
o Add -n and -p support
o check and fix non-zero dtime as the first problem user


Modified: trunk/fsck.ocfs2/Makefile
===================================================================
--- trunk/fsck.ocfs2/Makefile	2004-09-21 23:06:17 UTC (rev 247)
+++ trunk/fsck.ocfs2/Makefile	2004-09-23 00:18:24 UTC (rev 248)
@@ -22,8 +22,8 @@
   DEFINES += -D__ILP32__
 endif
 
-CFILES = fsck.c pass1.c
-HFILES = include/pass1.h
+CFILES = fsck.c pass1.c problem.c util.c
+HFILES = include/fsck.h include/pass1.h include/problem.h include/util.h
 
 OBJS = $(subst .c,.o,$(CFILES))
 

Modified: trunk/fsck.ocfs2/fsck.c
===================================================================
--- trunk/fsck.ocfs2/fsck.c	2004-09-21 23:06:17 UTC (rev 247)
+++ trunk/fsck.ocfs2/fsck.c	2004-09-23 00:18:24 UTC (rev 248)
@@ -61,8 +61,6 @@
 {
 	errcode_t ret;
 
-	memset(ost, 0, sizeof(*ost));
-
 	ret = ocfs2_block_bitmap_new(fs, "inodes in use", 
 				     &ost->ost_used_inodes);
 	if (ret) {
@@ -113,9 +111,11 @@
 	char *filename;
 	ocfs2_filesys *fs;
 	int64_t blkno, blksize;
-	o2fsck_state ost;
-	int c, ret;
+	o2fsck_state _ost, *ost = &_ost;
+	int c, ret, rw = OCFS2_FLAG_RW;
 
+	memset(ost, 0, sizeof(o2fsck_state));
+	ost->ost_ask = 1;
 
 	/* These mean "autodetect" */
 	blksize = 0;
@@ -123,7 +123,7 @@
 
 	initialize_ocfs_error_table();
 
-	while((c = getopt(argc, argv, "s:B:")) != EOF) {
+	while((c = getopt(argc, argv, "nps:B:")) != EOF) {
 		switch (c) {
 			case 's':
 				blkno = read_number(optarg);
@@ -147,6 +147,18 @@
 				}
 				break;
 
+			case 'n':
+				ost->ost_ask = 0;
+				ost->ost_answer = 0;
+				rw = OCFS2_FLAG_RO;
+				break;
+
+			/* "preen" don't ask and force fixing */
+			case 'p':
+				ost->ost_ask = 0;
+				ost->ost_answer = 1;
+				break;
+
 			default:
 				print_usage();
 				return 1;
@@ -170,7 +182,7 @@
 
 	/* XXX we'll decide on a policy for using o_direct in the future.
 	 * for now we want to test against loopback files in ext3, say. */
-	ret = ocfs2_open(filename, OCFS2_FLAG_RO | OCFS2_FLAG_BUFFERED, blkno,
+	ret = ocfs2_open(filename, rw | OCFS2_FLAG_BUFFERED, blkno,
 			 blksize, &fs);
 	if (ret) {
 		com_err(argv[0], ret,
@@ -178,7 +190,7 @@
 		goto out;
 	}
 
-	if (o2fsck_state_init(fs, argv[0], &ost)) {
+	if (o2fsck_state_init(fs, argv[0], ost)) {
 		fprintf(stderr, "error allocating run-time state, exiting..\n");
 		return 1;
 	}
@@ -194,7 +206,7 @@
 		fs->fs_clusters,
 		fs->fs_blocks);
 
-	ret = o2fsck_pass1(fs, &ost);
+	ret = o2fsck_pass1(fs, ost);
 	if (ret)
 		com_err(argv[0], ret, "pass1 failed");
 

Modified: trunk/fsck.ocfs2/include/fsck.h
===================================================================
--- trunk/fsck.ocfs2/include/fsck.h	2004-09-21 23:06:17 UTC (rev 247)
+++ trunk/fsck.ocfs2/include/fsck.h	2004-09-23 00:18:24 UTC (rev 248)
@@ -32,6 +32,11 @@
 
 	ocfs2_bitmap	*ost_found_blocks;
 	ocfs2_bitmap	*ost_dup_blocks;
+
+	/* whether or not we should be asking questions of the user, and 
+	 * if not, what the answer should be instead. */
+	unsigned	ost_ask:1,
+			ost_answer:1;
 } o2fsck_state;
 
 #endif /* __O2FSCK_FSCK_H__ */

Added: trunk/fsck.ocfs2/include/problem.h
===================================================================
--- trunk/fsck.ocfs2/include/problem.h	2004-09-21 23:06:17 UTC (rev 247)
+++ trunk/fsck.ocfs2/include/problem.h	2004-09-23 00:18:24 UTC (rev 248)
@@ -0,0 +1,35 @@
+/*
+ * problem.h
+ *
+ * Copyright (C) 2002 Oracle Corporation.  All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 021110-1307, USA.
+ *
+ * Author: Zach Brown
+ */
+
+#ifndef __O2FSCK_PROBLEM_H__
+#define __O2FSCK_PROBLEM_H__
+
+#define FIX_DEFYES (1 << 0)
+#define FIX_DEFNO  (1 << 1)
+
+#include "fsck.h"
+
+int should_fix(o2fsck_state *ost, unsigned flags, const char *fmt, ...);
+
+#endif /* __O2FSCK_PROBLEM_H__ */
+

Added: trunk/fsck.ocfs2/include/util.h
===================================================================
--- trunk/fsck.ocfs2/include/util.h	2004-09-21 23:06:17 UTC (rev 247)
+++ trunk/fsck.ocfs2/include/util.h	2004-09-23 00:18:24 UTC (rev 248)
@@ -0,0 +1,48 @@
+/*
+ * util.h
+ *
+ * Copyright (C) 2002 Oracle Corporation.  All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 021110-1307, USA.
+ *
+ * Author: Zach Brown
+ */
+
+#ifndef __O2FSCK_UTIL_H__
+#define __O2FSCK_UTIL_H__
+
+#include <stdlib.h>
+
+/* we duplicate e2fsck's error codes to make everyone's life easy */
+#define FSCK_OK          0      /* No errors */
+#define FSCK_NONDESTRUCT 1      /* File system errors corrected */
+#define FSCK_REBOOT      2      /* System should be rebooted */
+#define FSCK_UNCORRECTED 4      /* File system errors left uncorrected */
+#define FSCK_ERROR       8      /* Operational error */
+#define FSCK_USAGE       16     /* Usage or syntax error */
+#define FSCK_CANCELED    32     /* Aborted with a signal or ^C */
+#define FSCK_LIBRARY     128    /* Shared library error */
+
+/* no va_list variant of com_err */
+#define fatal_error(errcode, fmt...) do {				\
+	com_err("o2fsck", errcode, fmt);				\
+	exit(FSCK_ERROR);						\
+} while (0)
+
+void o2fsck_write_inode(ocfs2_filesys *fs, uint64_t blkno, ocfs2_dinode *di);
+
+#endif /* __O2FSCK_UTIL_H__ */
+

Modified: trunk/fsck.ocfs2/pass1.c
===================================================================
--- trunk/fsck.ocfs2/pass1.c	2004-09-21 23:06:17 UTC (rev 247)
+++ trunk/fsck.ocfs2/pass1.c	2004-09-23 00:18:24 UTC (rev 248)
@@ -29,6 +29,8 @@
 
 #include "fsck.h"
 #include "pass1.h"
+#include "problem.h"
+#include "util.h"
 
 const char *whoami = "pass1";
 
@@ -47,8 +49,8 @@
  * - a bitmap of data blocks duplicated between inodes
  */
 
-static void o2fsck_verify_inode_fields(o2fsck_state *ost, uint64_t blkno, 
-					ocfs2_dinode *di)
+static void o2fsck_verify_inode_fields(ocfs2_filesys *fs, o2fsck_state *ost, 
+				       uint64_t blkno, ocfs2_dinode *di)
 {
 	int was_set;
 
@@ -75,6 +77,16 @@
 		goto bad;
 	}
 
+	if (di->i_dtime) {
+		if (should_fix(ost, FIX_DEFYES, 
+		    "Inode %llu is in use but has a non-zero dtime.", 
+		    di->i_blkno)) {
+
+			di->i_dtime = 0ULL;
+			o2fsck_write_inode(fs, blkno, di);
+		}
+	}
+
 	ocfs2_bitmap_set(ost->ost_used_inodes, blkno, &was_set);
 	if (was_set) {
 		fprintf(stderr, "duplicate inode %llu?\n", blkno);
@@ -193,7 +205,7 @@
 		if (blkno == 0)
 			break;
 
-		o2fsck_verify_inode_fields(ost, blkno, di);
+		o2fsck_verify_inode_fields(fs, ost, blkno, di);
 		/* XXX be able to mark the blocks in the inode as 
 		 * bad if the inode was bad */
 		o2fsck_verify_inode_data(fs, ost, blkno, di);

Added: trunk/fsck.ocfs2/problem.c
===================================================================
--- trunk/fsck.ocfs2/problem.c	2004-09-21 23:06:17 UTC (rev 247)
+++ trunk/fsck.ocfs2/problem.c	2004-09-23 00:18:24 UTC (rev 248)
@@ -0,0 +1,111 @@
+/* -*- mode: c; c-basic-offset: 8; -*-
+ * vim: noexpandtab sw=8 ts=8 sts=0:
+ *
+ * problem.c
+ *
+ * These routines serve the same purpose as e2fsck's "fix_problem()"
+ *
+ * Copyright (C) 2004 Oracle.  All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License, version 2,  as published by the Free Software Foundation.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 021110-1307, USA.
+ *
+ * Authors: Zach Brown
+ */
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdarg.h>
+
+#include "ocfs2.h"
+
+#include "problem.h"
+#include "util.h"
+
+static char read_a_char(int fd)
+{
+	char c;
+	ssize_t ret;
+
+	ret = read(fd, &c, sizeof(c));
+	if (ret != sizeof(c))
+		return EOF;
+
+	return c;
+}
+
+/* 
+ * this checks the user's intent.  someday soon it will check command line flags
+ * and have a notion of grouping, as well
+ */
+int should_fix(o2fsck_state *ost, unsigned flags, const char *fmt, ...)
+{
+	va_list ap;
+	char c;
+
+	/* paranoia for jokers that claim to default to both */
+	if((flags & FIX_DEFYES) && (flags & FIX_DEFNO))
+		flags &= ~(FIX_DEFYES|FIX_DEFNO);
+
+	va_start(ap, fmt);
+	vprintf(fmt, ap);
+	va_end(ap);
+
+	if (!ost->ost_ask) {
+		if (ost->ost_answer)
+			printf("  Fixing.\n");
+		else
+			printf("  Ignoring\n");
+		return ost->ost_answer;
+	}
+
+	printf(" Fix? ");
+	if (flags & FIX_DEFYES)
+		printf(" <y> ");
+	else if (flags & FIX_DEFNO)
+		printf(" <n> ");
+
+	fflush(stdout);
+
+	/* no curses, no nothin.  overly regressive? */
+	while ((c = read_a_char(fileno(stdin))) != EOF) {
+
+		/* XXX control-c, we're done? */
+		if (c == 3) {
+			printf("cancelled!\n");
+			exit(FSCK_ERROR);
+		}
+
+		/* straight answers */
+		if (c == 'y' || c == 'Y')
+			return 1;
+		if (c == 'n' || c == 'N')
+			return 0;
+
+		/* space or CR lead to applying the optional default */
+		if (c == ' ' || c == '\n') {
+			if (flags & FIX_DEFYES)
+				return 1;
+			if (flags & FIX_DEFNO)
+				return 0;
+		}
+
+		/* otherwise keep asking */
+	}
+
+	printf("input failed?\n");
+	exit(FSCK_ERROR);
+
+	return 0;
+}

Added: trunk/fsck.ocfs2/util.c
===================================================================
--- trunk/fsck.ocfs2/util.c	2004-09-21 23:06:17 UTC (rev 247)
+++ trunk/fsck.ocfs2/util.c	2004-09-23 00:18:24 UTC (rev 248)
@@ -0,0 +1,41 @@
+/* -*- mode: c; c-basic-offset: 8; -*-
+ * vim: noexpandtab sw=8 ts=8 sts=0:
+ *
+ * util.c
+ *
+ * file system checker for OCFS2
+ *
+ * Copyright (C) 2004 Oracle.  All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License, version 2,  as published by the Free Software Foundation.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 021110-1307, USA.
+ *
+ * Authors: Zach Brown
+ */
+#include "ocfs2.h"
+
+#include "util.h"
+
+void o2fsck_write_inode(ocfs2_filesys *fs, uint64_t blkno, ocfs2_dinode *di)
+{
+	errcode_t ret;
+
+	if (blkno != di->i_blkno)
+		fatal_error(0, "Asked to write inode with i_blkno %llu to "
+				"different block %llu.\n", di->i_blkno, blkno);
+
+	ret = ocfs2_write_inode(fs, blkno, (char *)di);
+	if (ret)
+		fatal_error(ret, "while writing inode %llu", di->i_blkno);
+}



More information about the Ocfs2-tools-commits mailing list