[Ocfs-tools-commits] jlbec commits r138 - in trunk/ocfs2/libocfs2: . include

svn-commits at oss.oracle.com svn-commits at oss.oracle.com
Sat Jul 3 16:30:35 CDT 2004


Author: jlbec
Date: 2004-07-03 15:30:33 -0500 (Sat, 03 Jul 2004)
New Revision: 138

Added:
   trunk/ocfs2/libocfs2/sysfile.c
Modified:
   trunk/ocfs2/libocfs2/Makefile
   trunk/ocfs2/libocfs2/include/filesys.h
   trunk/ocfs2/libocfs2/openfs.c
Log:

o Use lookup to open the global bitmap in openfs.



Modified: trunk/ocfs2/libocfs2/Makefile
===================================================================
--- trunk/ocfs2/libocfs2/Makefile	2004-07-03 01:00:49 UTC (rev 137)
+++ trunk/ocfs2/libocfs2/Makefile	2004-07-03 20:30:33 UTC (rev 138)
@@ -74,7 +74,8 @@
 	extents.c	\
 	dirblock.c	\
 	dir_iterate.c	\
-	lookup.c
+	lookup.c	\
+	sysfile.c
 
 HFILES =				\
 	include/jfs_user.h		\

Modified: trunk/ocfs2/libocfs2/include/filesys.h
===================================================================
--- trunk/ocfs2/libocfs2/include/filesys.h	2004-07-03 01:00:49 UTC (rev 137)
+++ trunk/ocfs2/libocfs2/include/filesys.h	2004-07-03 20:30:33 UTC (rev 138)
@@ -110,8 +110,12 @@
 	ocfs2_dinode *fs_orig_super;
 	unsigned int fs_blocksize;
 	unsigned int fs_clustersize;
+	uint32_t fs_clusters;
 	uint64_t fs_blocks;
 	uint32_t fs_umask;
+	uint64_t fs_root_blkno;
+	uint64_t fs_sysdir_blkno;
+	uint64_t fs_bm_blkno;
 
 	/* Reserved for the use of the calling application. */
 	void *fs_private;
@@ -192,5 +196,7 @@
 		       const char *name, int namelen, char *buf,
 		       uint64_t *inode);
 
+errcode_t ocfs2_lookup_system_inode(ocfs2_filesys *fs, int type,
+				    int node_num, uint64_t *blkno);
 #endif  /* _FILESYS_H */
 

Modified: trunk/ocfs2/libocfs2/openfs.c
===================================================================
--- trunk/ocfs2/libocfs2/openfs.c	2004-07-03 01:00:49 UTC (rev 137)
+++ trunk/ocfs2/libocfs2/openfs.c	2004-07-03 20:30:33 UTC (rev 138)
@@ -39,8 +39,8 @@
 #include <errno.h>
 
 /* I hate glibc and gcc ... this is a hack that will go away anyway */
-#ifndef LLONG_MAX
-# define LLONG_MAX 9223372036854775807LL
+#ifndef ULLONG_MAX
+# define ULLONG_MAX 18446744073709551615ULL
 #endif
 
 #include <linux/types.h>
@@ -88,6 +88,39 @@
 	return ret;
 }
 
+static errcode_t ocfs2_get_fs_blocks(ocfs2_filesys *fs)
+{
+	errcode_t ret;
+	char *buf;
+	ocfs2_dinode *inode;
+	int c_to_b_bits =
+		OCFS2_RAW_SB(fs->fs_super)->s_clustersize_bits -
+		OCFS2_RAW_SB(fs->fs_super)->s_blocksize_bits;
+
+	ret = ocfs2_lookup_system_inode(fs, GLOBAL_BITMAP_SYSTEM_INODE,
+					0, &fs->fs_bm_blkno);
+	if (ret)
+		return ret;
+
+	ret = ocfs2_malloc_block(fs->fs_io, &buf);
+	if (ret)
+		return ret;
+
+	ret = ocfs2_read_inode(fs, fs->fs_bm_blkno, buf);
+	if (ret)
+		goto out_free;
+
+	inode = (ocfs2_dinode *)buf;
+
+	fs->fs_clusters = inode->id1.bitmap1.i_total;
+	fs->fs_blocks = (uint64_t)fs->fs_clusters << c_to_b_bits;
+
+out_free:
+	ocfs2_free(&buf);
+
+	return ret;
+}
+
 static errcode_t ocfs2_read_super(ocfs2_filesys *fs, int superblock)
 {
 	errcode_t ret;
@@ -228,10 +261,16 @@
 
 	/* FIXME: Read the system dir */
 	
-	/* FIXME: This hack will be replaced by a read of the global
-	 * bitmap inode */
-	fs->fs_blocks = LLONG_MAX;
+	fs->fs_root_blkno =
+		OCFS2_RAW_SB(fs->fs_super)->s_root_blkno;
+	fs->fs_sysdir_blkno =
+		OCFS2_RAW_SB(fs->fs_super)->s_system_dir_blkno;
 
+	fs->fs_blocks = ULLONG_MAX;
+	ret = ocfs2_get_fs_blocks(fs);
+	if (ret)
+		goto out;
+
 	*ret_fs = fs;
 	return 0;
 
@@ -336,9 +375,13 @@
 	fprintf(stdout, "OCFS2 filesystem on \"%s\":\n", filename);
 	fprintf(stdout,
 		"\tblocksize = %d\n"
- 		"\tclustersize = %d\n",
+ 		"\tclustersize = %d\n"
+		"\tclusters = %u\n"
+		"\tblocks = %llu\n",
  		fs->fs_blocksize,
-		fs->fs_clustersize);
+		fs->fs_clustersize,
+		fs->fs_clusters,
+		fs->fs_blocks);
 
 	ret = ocfs2_close(fs);
 	if (ret) {

Added: trunk/ocfs2/libocfs2/sysfile.c
===================================================================
--- trunk/ocfs2/libocfs2/sysfile.c	2004-07-03 01:00:49 UTC (rev 137)
+++ trunk/ocfs2/libocfs2/sysfile.c	2004-07-03 20:30:33 UTC (rev 138)
@@ -0,0 +1,72 @@
+/* -*- mode: c; c-basic-offset: 8; -*-
+ * vim: noexpandtab sw=8 ts=8 sts=0:
+ *
+ * sysfile.c
+ *
+ * System inode operations for the OCFS2 userspace library.
+ *
+ * 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: Joel Becker
+ */
+
+#define _XOPEN_SOURCE 600  /* Triggers XOPEN2K in features.h */
+#define _LARGEFILE64_SOURCE
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <sys/stat.h>
+#include <errno.h>
+
+#include <linux/types.h>
+
+#include <et/com_err.h>
+#include "ocfs2_err.h"
+
+#include "unix_io.h"
+#include "memory.h"
+#include "byteorder.h"
+
+#include "ocfs2_fs.h"
+#include "ocfs1_fs_compat.h"
+
+#include "filesys.h"
+
+errcode_t ocfs2_lookup_system_inode(ocfs2_filesys *fs, int type,
+				    int node_num, uint64_t *blkno)
+{
+	errcode_t ret;
+	char *buf;
+
+	ret = ocfs2_malloc0(sizeof(char) *
+			    (OCFS2_MAX_FILENAME_LENGTH + 1), &buf);
+	if (ret)
+		return ret;
+
+	ocfs2_sprintf_system_inode_name(buf, OCFS2_MAX_FILENAME_LENGTH, 
+					type, node_num);
+
+	ret = ocfs2_lookup(fs, fs->fs_sysdir_blkno, buf,
+			   strlen(buf), NULL, blkno);
+
+	ocfs2_free(&buf);
+
+	return ret;
+}



More information about the Ocfs-tools-commits mailing list