[Ocfs2-tools-devel] [PATCH 03/11] libocfs2: Add function ocfs2_get_max_inode_count()

Sunil Mushran sunil.mushran at oracle.com
Fri Sep 30 12:22:13 PDT 2011


Add function ocfs2_get_max_inode_count() in the inode scan interface.
This function computes the maximum number of inodes that can be created
in the file system without extending the allocator.

This will be used to provide progress in Pass 1 of fsck.

Signed-off-by: Sunil Mushran <sunil.mushran at oracle.com>
---
 include/ocfs2/ocfs2.h |    1 +
 libocfs2/inode_scan.c |   28 ++++++++++++++++++++++------
 2 files changed, 23 insertions(+), 6 deletions(-)

diff --git a/include/ocfs2/ocfs2.h b/include/ocfs2/ocfs2.h
index 5d46313..9fcb2ce 100644
--- a/include/ocfs2/ocfs2.h
+++ b/include/ocfs2/ocfs2.h
@@ -603,6 +603,7 @@ errcode_t ocfs2_open_inode_scan(ocfs2_filesys *fs,
 void ocfs2_close_inode_scan(ocfs2_inode_scan *scan);
 errcode_t ocfs2_get_next_inode(ocfs2_inode_scan *scan,
 			       uint64_t *blkno, char *inode);
+uint64_t ocfs2_get_max_inode_count(ocfs2_inode_scan *scan);
 
 errcode_t ocfs2_open_dir_scan(ocfs2_filesys *fs, uint64_t dir, int flags,
 			      ocfs2_dir_scan **ret_scan);
diff --git a/libocfs2/inode_scan.c b/libocfs2/inode_scan.c
index e5d2bae..d215f56 100644
--- a/libocfs2/inode_scan.c
+++ b/libocfs2/inode_scan.c
@@ -6,7 +6,7 @@
  * Scan all inodes in an OCFS2 filesystem.  For the OCFS2 userspace
  * library.
  *
- * Copyright (C) 2004 Oracle.  All rights reserved.
+ * Copyright (C) 2004, 2011 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
@@ -17,11 +17,6 @@
  * 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.
- *
  * Ideas taken from e2fsprogs/lib/ext2fs/inode_scan.c
  *   Copyright (C) 1993, 1994, 1995, 1996, 1997 Theodore Ts'o.
  */
@@ -258,6 +253,27 @@ static int get_next_inode_alloc(ocfs2_inode_scan *scan)
 	return 0;
 }
 
+uint64_t ocfs2_get_max_inode_count(ocfs2_inode_scan *scan)
+{
+	struct ocfs2_dinode *di = NULL;
+	uint64_t count = 0;
+	int i;
+
+	if (!scan || !scan->num_inode_alloc)
+		return 0;
+
+	for (i = 0; i < scan->num_inode_alloc; i++) {
+		if (scan->inode_alloc[i])
+			di = scan->inode_alloc[i]->ci_inode;
+		if (!di)
+			continue;
+		count += ocfs2_clusters_to_blocks(scan->fs, di->i_clusters);
+		di = NULL;
+	}
+
+	return count;
+}
+
 errcode_t ocfs2_get_next_inode(ocfs2_inode_scan *scan,
 			       uint64_t *blkno, char *inode)
 {
-- 
1.7.4.1




More information about the Ocfs2-tools-devel mailing list