[Ocfs2-tools-commits] zab commits r257 - in trunk: . fsck.ocfs2
fsck.ocfs2/include libocfs2/include
svn-commits at oss.oracle.com
svn-commits at oss.oracle.com
Fri Sep 24 20:19:05 CDT 2004
Author: zab
Date: 2004-09-24 20:19:03 -0500 (Fri, 24 Sep 2004)
New Revision: 257
Added:
trunk/fsck.ocfs2/icount.c
trunk/fsck.ocfs2/include/icount.h
Modified:
trunk/Makefile
trunk/fsck.ocfs2/Makefile
trunk/fsck.ocfs2/fsck.c
trunk/fsck.ocfs2/include/fsck.h
trunk/fsck.ocfs2/include/pass1.h
trunk/fsck.ocfs2/pass1.c
trunk/fsck.ocfs2/util.c
trunk/libocfs2/include/ocfs2.h
Log:
o Add icount tracking helper for fsck
o Add fsck.ocfs2 to the tools build and fix lots of dorky compilation problems
Modified: trunk/Makefile
===================================================================
--- trunk/Makefile 2004-09-24 23:55:36 UTC (rev 256)
+++ trunk/Makefile 2004-09-25 01:19:03 UTC (rev 257)
@@ -22,7 +22,7 @@
$(error could not detect architecture for tools)
endif
-SUBDIRS = libocfs2 mkfs.ocfs2 mounted.ocfs2 ocfs2cdsl extras load_ocfs ocfs_uid_gen patches
+SUBDIRS = libocfs2 fsck.ocfs2 mkfs.ocfs2 mounted.ocfs2 ocfs2cdsl extras load_ocfs ocfs_uid_gen patches
ifdef BUILD_DEBUGOCFS2
SUBDIRS += debugfs.ocfs2
Modified: trunk/fsck.ocfs2/Makefile
===================================================================
--- trunk/fsck.ocfs2/Makefile 2004-09-24 23:55:36 UTC (rev 256)
+++ trunk/fsck.ocfs2/Makefile 2004-09-25 01:19:03 UTC (rev 257)
@@ -22,8 +22,8 @@
DEFINES += -D__ILP32__
endif
-CFILES = fsck.c pass1.c problem.c util.c
-HFILES = include/fsck.h include/pass1.h include/problem.h include/util.h
+CFILES = fsck.c icount.c pass1.c problem.c util.c
+HFILES = include/fsck.h include/icount.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-24 23:55:36 UTC (rev 256)
+++ trunk/fsck.ocfs2/fsck.c 2004-09-25 01:19:03 UTC (rev 257)
@@ -28,11 +28,14 @@
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
+#include <inttypes.h>
#include "ocfs2.h"
#include "fsck.h"
+#include "icount.h"
#include "pass1.h"
+#include "util.h"
static void print_usage(void)
{
@@ -61,6 +64,18 @@
{
errcode_t ret;
+ ret = o2fsck_icount_new(fs, &ost->ost_icount_in_inodes);
+ if (ret) {
+ com_err(whoami, ret, "while allocating inode icount");
+ return ret;
+ }
+
+ ret = o2fsck_icount_new(fs, &ost->ost_icount_refs);
+ if (ret) {
+ com_err(whoami, ret, "while allocating reference icount");
+ return ret;
+ }
+
ret = ocfs2_block_bitmap_new(fs, "inodes in use",
&ost->ost_used_inodes);
if (ret) {
@@ -106,7 +121,7 @@
return 0;
}
-void exit_if_skipping(o2fsck_state *ost)
+static void exit_if_skipping(o2fsck_state *ost)
{
if (ost->ost_force)
return;
@@ -180,7 +195,7 @@
}
if (blksize % OCFS2_MIN_BLOCKSIZE) {
- fprintf(stderr, "Invalid blocksize: %lld\n", blksize);
+ fprintf(stderr, "Invalid blocksize: %"PRId64"\n", blksize);
print_usage();
return 1;
}
@@ -216,8 +231,8 @@
/* ocfs2_open() already checked _incompat and _ro_compat */
if (OCFS2_RAW_SB(ost->ost_fs->fs_super)->s_feature_compat &
- ~OCFS2_LIB_FEATURE_COMPAT_SUPP) {
- com_err(argv[0], EXT2_ET_UNSUPP_FEATURE,
+ ~OCFS2_FEATURE_COMPAT_SUPP) {
+ com_err(argv[0], OCFS2_ET_UNSUPP_FEATURE,
"while checking _compat flags");
exit(FSCK_ERROR);
}
Added: trunk/fsck.ocfs2/icount.c
===================================================================
--- trunk/fsck.ocfs2/icount.c 2004-09-24 23:55:36 UTC (rev 256)
+++ trunk/fsck.ocfs2/icount.c 2004-09-25 01:19:03 UTC (rev 257)
@@ -0,0 +1,152 @@
+/* -*- mode: c; c-basic-offset: 8; -*-
+ * vim: noexpandtab sw=8 ts=8 sts=0:
+ *
+ * icount.c
+ *
+ * As always, we let e2fsck lead the way. A bitmap for
+ * inodes with a single i_count (the vast majority), and a
+ * tree of inode numbers with a greater count.
+ *
+ * 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 "fsck.h"
+#include "icount.h"
+
+typedef struct _icount_node {
+ struct rb_node in_node;
+ uint64_t in_blkno;
+ uint16_t in_icount;
+} icount_node;
+
+/* XXX this is currently fragile in that it requires that the caller make
+ * sure that the node doesn't already exist in the tree.
+ */
+static void icount_insert(o2fsck_icount *icount, icount_node *in)
+{
+ struct rb_node ** p = &icount->ic_multiple_tree.rb_node;
+ struct rb_node * parent = NULL;
+ icount_node *tmp_in;
+
+ while (*p)
+ {
+ parent = *p;
+ tmp_in = rb_entry(parent, icount_node, in_node);
+
+ if (in->in_blkno < tmp_in->in_blkno)
+ p = &(*p)->rb_left;
+ else if (in->in_blkno > tmp_in->in_blkno)
+ p = &(*p)->rb_right;
+ }
+
+ rb_link_node(&in->in_node, parent, p);
+ rb_insert_color(&in->in_node, &icount->ic_multiple_tree);
+}
+
+static icount_node *icount_search(o2fsck_icount *icount, uint64_t blkno)
+{
+ struct rb_node *node = icount->ic_multiple_tree.rb_node;
+ icount_node *in;
+
+ while (node) {
+ in = rb_entry(node, icount_node, in_node);
+
+ if (blkno < in->in_blkno)
+ node = node->rb_left;
+ else if (blkno > in->in_blkno)
+ node = node->rb_right;
+ else
+ return in;
+ }
+ return NULL;
+}
+
+errcode_t o2fsck_icount_update(o2fsck_icount *icount, uint64_t blkno,
+ uint16_t count)
+{
+ icount_node *in;
+
+ /* keep it simple for now by always clearing/setting */
+ if (count == 1)
+ ocfs2_bitmap_set(icount->ic_single_bm, blkno, NULL);
+ else
+ ocfs2_bitmap_clear(icount->ic_single_bm, blkno, NULL);
+
+ in = icount_search(icount, blkno);
+ if (in) {
+ if (count < 2) {
+ rb_erase(&in->in_node, &icount->ic_multiple_tree);
+ free(in);
+ } else {
+ in->in_icount = count;
+ }
+ } else if (count > 2){
+ in = calloc(1, sizeof(*in));
+ if (in == NULL)
+ return OCFS2_ET_NO_MEMORY;
+
+ in->in_blkno = blkno;
+ in->in_icount = count;
+ icount_insert(icount, in);
+ }
+ return 0;
+}
+
+errcode_t o2fsck_icount_new(ocfs2_filesys *fs, o2fsck_icount **ret)
+{
+ o2fsck_icount *icount;
+ errcode_t err;
+
+ icount = calloc(1, sizeof(*icount));
+ if (icount == NULL)
+ return OCFS2_ET_NO_MEMORY;
+
+ err = ocfs2_block_bitmap_new(fs, "inodes with single link_count",
+ &icount->ic_single_bm);
+ if (err) {
+ free(icount);
+ com_err("icount", err, "while allocating single link_count bm");
+ return err;
+ }
+
+ icount->ic_multiple_tree = RB_ROOT;
+
+ *ret = icount;
+ return 0;
+}
+
+void o2fsck_icount_free(o2fsck_icount *icount)
+{
+ struct rb_node *node;
+ icount_node *in;
+
+ ocfs2_bitmap_free(icount->ic_single_bm);
+ while((node = rb_first(&icount->ic_multiple_tree)) != NULL) {
+ in = rb_entry(node, icount_node, in_node);
+ rb_erase(node, &icount->ic_multiple_tree);
+ free(in);
+ }
+ free(icount);
+}
Modified: trunk/fsck.ocfs2/include/fsck.h
===================================================================
--- trunk/fsck.ocfs2/include/fsck.h 2004-09-24 23:55:36 UTC (rev 256)
+++ trunk/fsck.ocfs2/include/fsck.h 2004-09-25 01:19:03 UTC (rev 257)
@@ -24,8 +24,10 @@
#ifndef __O2FSCK_FSCK_H__
#define __O2FSCK_FSCK_H__
+#include "icount.h"
+
typedef struct _o2fsck_state {
- oc2fs_filesys *ost_fs;
+ ocfs2_filesys *ost_fs;
ocfs2_bitmap *ost_used_inodes;
ocfs2_bitmap *ost_bad_inodes;
@@ -35,6 +37,9 @@
ocfs2_bitmap *ost_found_blocks;
ocfs2_bitmap *ost_dup_blocks;
+ o2fsck_icount *ost_icount_in_inodes;
+ o2fsck_icount *ost_icount_refs;
+
/* flags */
unsigned ost_ask:1, /* confirm with the user */
ost_answer:1, /* answer if we don't ask the user */
Added: trunk/fsck.ocfs2/include/icount.h
===================================================================
--- trunk/fsck.ocfs2/include/icount.h 2004-09-24 23:55:36 UTC (rev 256)
+++ trunk/fsck.ocfs2/include/icount.h 2004-09-25 01:19:03 UTC (rev 257)
@@ -0,0 +1,40 @@
+/*
+ * icount.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_ICOUNT_H__
+#define __O2FSCK_ICOUNT_H__
+
+#include "ocfs2.h"
+
+typedef struct _o2fsck_icount {
+ ocfs2_bitmap *ic_single_bm;
+ struct rb_root ic_multiple_tree;
+} o2fsck_icount;
+
+errcode_t o2fsck_icount_update(o2fsck_icount *icount, uint64_t blkno,
+ uint16_t count);
+errcode_t o2fsck_icount_new(ocfs2_filesys *fs, o2fsck_icount **ret);
+void o2fsck_icount_free(o2fsck_icount *icount);
+
+#endif /* __O2FSCK_ICOUNT_H__ */
+
Modified: trunk/fsck.ocfs2/include/pass1.h
===================================================================
--- trunk/fsck.ocfs2/include/pass1.h 2004-09-24 23:55:36 UTC (rev 256)
+++ trunk/fsck.ocfs2/include/pass1.h 2004-09-25 01:19:03 UTC (rev 257)
@@ -24,7 +24,9 @@
#ifndef __O2FSCK_PASS1_H__
#define __O2FSCK_PASS1_H__
-errcode_t o2fsck_pass1(ocfs2_filesys *fs, o2fsck_state *ost);
+#include "fsck.h"
+errcode_t o2fsck_pass1(o2fsck_state *ost);
+
#endif /* __O2FSCK_PASS1_H__ */
Modified: trunk/fsck.ocfs2/pass1.c
===================================================================
--- trunk/fsck.ocfs2/pass1.c 2004-09-24 23:55:36 UTC (rev 256)
+++ trunk/fsck.ocfs2/pass1.c 2004-09-25 01:19:03 UTC (rev 257)
@@ -24,9 +24,11 @@
* Authors: Zach Brown
*/
#include <string.h>
+#include <inttypes.h>
#include "ocfs2.h"
+#include "icount.h"
#include "fsck.h"
#include "pass1.h"
#include "problem.h"
@@ -54,9 +56,6 @@
{
int was_set;
- fprintf(stdout, "inode %llu with size %llu\n",
- blkno, di->i_size);
-
/* do we want to detect and delete corrupt system dir/files here
* so we can recreate them later ? */
@@ -69,11 +68,9 @@
/* XXX it seems these are expected sometimes? */
if (memcmp(di->i_signature, OCFS2_INODE_SIGNATURE,
strlen(OCFS2_INODE_SIGNATURE))) {
- printf("inode %llu has invalid signature\n", blkno);
goto bad;
}
if (!(di->i_flags & OCFS2_VALID_FL)) {
- printf("inode %llu missing valid flag\n", blkno);
goto bad;
}
@@ -83,7 +80,8 @@
should_fix(ost, FIX_DEFYES, "Root inode isn't a directory.")) {
di->i_dtime = 0ULL;
di->i_links_count = 0ULL;
- /* icount_store(links_count) */
+ o2fsck_icount_update(ost->ost_icount_in_inodes, di->i_blkno,
+ di->i_links_count);
o2fsck_write_inode(fs, blkno, di);
}
@@ -99,7 +97,7 @@
ocfs2_bitmap_set(ost->ost_used_inodes, blkno, &was_set);
if (was_set) {
- fprintf(stderr, "duplicate inode %llu?\n", blkno);
+ fprintf(stderr, "duplicate inode %"PRIu64"?\n", blkno);
goto bad;
}
@@ -141,7 +139,7 @@
ocfs2_bitmap_set(vb->vb_ost->ost_found_blocks, blkno, &was_set);
if (was_set) {
- fprintf(stderr, "duplicate block %llu?\n", blkno);
+ fprintf(stderr, "duplicate block %"PRIu64"?\n", blkno);
ocfs2_bitmap_set(vb->vb_ost->ost_dup_blocks, blkno, NULL);
}
@@ -181,7 +179,7 @@
return ret;
}
-errcode_t o2fsck_pass1(ocfs2_filesys *fs, o2fsck_state *ost)
+errcode_t o2fsck_pass1(o2fsck_state *ost)
{
errcode_t ret;
uint64_t blkno;
Modified: trunk/fsck.ocfs2/util.c
===================================================================
--- trunk/fsck.ocfs2/util.c 2004-09-24 23:55:36 UTC (rev 256)
+++ trunk/fsck.ocfs2/util.c 2004-09-25 01:19:03 UTC (rev 257)
@@ -23,6 +23,7 @@
*
* Authors: Zach Brown
*/
+#include <inttypes.h>
#include "ocfs2.h"
#include "util.h"
@@ -32,10 +33,11 @@
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);
+ fatal_error(0, "Asked to write inode with i_blkno %"PRIu64
+ " to different block %"PRIu64".\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);
+ fatal_error(ret, "while writing inode %"PRIu64, di->i_blkno);
}
Modified: trunk/libocfs2/include/ocfs2.h
===================================================================
--- trunk/libocfs2/include/ocfs2.h 2004-09-24 23:55:36 UTC (rev 256)
+++ trunk/libocfs2/include/ocfs2.h 2004-09-25 01:19:03 UTC (rev 257)
@@ -45,6 +45,7 @@
#include "byteorder.h"
#include <kernel-list.h>
+#include <kernel-rbtree.h>
#if OCFS2_FLAT_INCLUDES
#include "ocfs2_err.h"
More information about the Ocfs2-tools-commits
mailing list