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

svn-commits at oss.oracle.com svn-commits at oss.oracle.com
Wed Jun 30 15:02:02 CDT 2004


Author: jlbec
Date: 2004-06-30 14:01:59 -0500 (Wed, 30 Jun 2004)
New Revision: 120

Added:
   trunk/ocfs2/libocfs2/include/jfs_user.h
   trunk/ocfs2/libocfs2/mkjournal.c
Modified:
   trunk/ocfs2/libocfs2/Makefile
   trunk/ocfs2/libocfs2/include/filesys.h
   trunk/ocfs2/libocfs2/ocfs2_err.et.in
Log:
o Add journal superblock work

Modified: trunk/ocfs2/libocfs2/Makefile
===================================================================
--- trunk/ocfs2/libocfs2/Makefile	2004-06-30 18:29:18 UTC (rev 119)
+++ trunk/ocfs2/libocfs2/Makefile	2004-06-30 19:01:59 UTC (rev 120)
@@ -53,9 +53,12 @@
 	memory.c	\
 	openfs.c	\
 	closefs.c	\
-	freefs.c
+	freefs.c	\
+	inode.c		\
+	mkjournal.c
 
 HFILES =				\
+	include/jfs_user.h		\
 	include/kernel-jbd.h		\
 	include/kernel-list.h		\
 	include/ocfs2_fs.h		\

Modified: trunk/ocfs2/libocfs2/include/filesys.h
===================================================================
--- trunk/ocfs2/libocfs2/include/filesys.h	2004-06-30 18:29:18 UTC (rev 119)
+++ trunk/ocfs2/libocfs2/include/filesys.h	2004-06-30 19:01:59 UTC (rev 120)
@@ -65,5 +65,9 @@
 errcode_t ocfs2_write_inode(ocfs2_filesys *fs, uint64_t blkno,
 			    ocfs2_dinode *di);
 
+errcode_t ocfs2_create_journal_superblock(ocfs2_filesys *fs,
+					  uint32_t size, int flags,
+					  char **ret_jsb);
+
 #endif  /* _FILESYS_H */
 

Added: trunk/ocfs2/libocfs2/include/jfs_user.h
===================================================================
--- trunk/ocfs2/libocfs2/include/jfs_user.h	2004-06-30 18:29:18 UTC (rev 119)
+++ trunk/ocfs2/libocfs2/include/jfs_user.h	2004-06-30 19:01:59 UTC (rev 120)
@@ -0,0 +1,8 @@
+#ifndef _JFS_USER_H
+#define _JFS_USER_H
+
+typedef unsigned short kdev_t;
+
+#include "kernel-jbd.h"
+
+#endif /* _JFS_USER_H */

Added: trunk/ocfs2/libocfs2/mkjournal.c
===================================================================
--- trunk/ocfs2/libocfs2/mkjournal.c	2004-06-30 18:29:18 UTC (rev 119)
+++ trunk/ocfs2/libocfs2/mkjournal.c	2004-06-30 19:01:59 UTC (rev 120)
@@ -0,0 +1,199 @@
+/* -*- mode: c; c-basic-offset: 8; -*-
+ * vim: noexpandtab sw=8 ts=8 sts=0:
+ *
+ * mkjournal.c
+ *
+ * Journal creation 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
+ *
+ * Portions of the code from e2fsprogs/lib/ext2fs/mkjournal.c
+ *   Copyright (C) 2000 Theodore Ts'o.
+ */
+
+#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 "jfs_user.h"
+
+#include "unix_io.h"
+#include "memory.h"
+#include "byteorder.h"
+
+#include "ocfs2_fs.h"
+#include "ocfs1_fs_compat.h"
+
+#include "filesys.h"
+
+
+/*
+ * This function automatically sets up the journal superblock and
+ * returns it as an allocated block.
+ */
+errcode_t ocfs2_create_journal_superblock(ocfs2_filesys *fs,
+					  uint32_t size, int flags,
+					  char  **ret_jsb)
+{
+	errcode_t		retval;
+	journal_superblock_t	*jsb;
+
+	if (size < 1024)
+		return OCFS2_ET_JOURNAL_TOO_SMALL;
+
+	if ((retval = ocfs2_malloc_block(fs->fs_io, &jsb)))
+		return retval;
+
+	memset(jsb, 0, fs->fs_blocksize);
+
+	jsb->s_header.h_magic = htonl(JFS_MAGIC_NUMBER);
+	jsb->s_header.h_blocktype = htonl(JFS_SUPERBLOCK_V2);
+	jsb->s_blocksize = htonl(fs->fs_blocksize);
+	jsb->s_maxlen = htonl(size);
+	jsb->s_nr_users = htonl(1);
+	jsb->s_first = htonl(1);
+	jsb->s_sequence = htonl(1);
+	memcpy(jsb->s_uuid, OCFS2_RAW_SB(fs->fs_super)->s_uuid,
+	       sizeof(OCFS2_RAW_SB(fs->fs_super)->s_uuid));
+
+#if 0 /* Someday */
+	/*
+	 * If we're creating an external journal device, we need to
+	 * adjust these fields.
+	 */
+	if (fs->super->s_feature_incompat &
+	    EXT3_FEATURE_INCOMPAT_JOURNAL_DEV) {
+		jsb->s_nr_users = 0;
+		if (fs->blocksize == 1024)
+			jsb->s_first = htonl(3);
+		else
+			jsb->s_first = htonl(2);
+	}
+#endif
+
+	*ret_jsb = (char *) jsb;
+	return 0;
+}
+
+#ifdef DEBUG_EXE
+#if 0
+static uint64_t read_number(const char *num)
+{
+	uint64_t val;
+	char *ptr;
+
+	val = strtoull(num, &ptr, 0);
+	if (!ptr || *ptr)
+		return 0;
+
+	return val;
+}
+
+static void print_usage(void)
+{
+	fprintf(stderr,
+		"Usage: mkjournal <filename> <inode_num>\n");
+}
+
+extern int opterr, optind;
+extern char *optarg;
+
+int main(int argc, char *argv[])
+{
+	errcode_t ret;
+	uint64_t blkno;
+	char *filename, *buf;
+	ocfs2_filesys *fs;
+	ocfs2_dinode *di;
+
+	blkno = OCFS2_SUPER_BLOCK_BLKNO;
+
+	initialize_ocfs_error_table();
+
+	if (argc < 2) {
+		fprintf(stderr, "Missing filename\n");
+		print_usage();
+		return 1;
+	}
+	filename = argv[1];
+
+	if (argc > 2) {
+		blkno = read_number(argv[2]);
+		if (blkno < OCFS2_SUPER_BLOCK_BLKNO) {
+			fprintf(stderr, "Invalid blockno: %s\n",
+				blkno);
+			print_usage();
+			return 1;
+		}
+	}
+
+	ret = ocfs2_open(filename, OCFS2_FLAG_RO, 0, 0, &fs);
+	if (ret) {
+		com_err(argv[0], ret,
+			"while opening file \"%s\"", filename);
+		goto out;
+	}
+
+	ret = ocfs2_malloc_block(fs->fs_io, &buf);
+	if (ret) {
+		com_err(argv[0], ret,
+			"while allocating inode buffer");
+		goto out_close;
+	}
+
+	di = (ocfs2_dinode *)buf;
+
+	ret = ocfs2_read_inode(fs, blkno, di);
+	if (ret) {
+		com_err(argv[0], ret,
+			"while reading inode %llu", blkno);
+		goto out_free;
+	}
+
+	fprintf(stdout, "OCFS2 inode %llu on \"%s\"\n", blkno,
+		filename);
+
+
+out_free:
+	ocfs2_free(&buf);
+
+out_close:
+	ret = ocfs2_close(fs);
+	if (ret) {
+		com_err(argv[0], ret,
+			"while closing file \"%s\"", filename);
+	}
+
+out:
+	return 0;
+}
+#endif
+#endif  /* DEBUG_EXE */

Modified: trunk/ocfs2/libocfs2/ocfs2_err.et.in
===================================================================
--- trunk/ocfs2/libocfs2/ocfs2_err.et.in	2004-06-30 18:29:18 UTC (rev 119)
+++ trunk/ocfs2/libocfs2/ocfs2_err.et.in	2004-06-30 19:01:59 UTC (rev 120)
@@ -53,4 +53,7 @@
 ec	OCFS2_ET_RO_FILESYS,
 	"Attempt to write to filesystem opened read-only"
 
+ec	OCFS2_ET_JOURNAL_TOO_SMALL,
+	"Journal must be at least 1024 blocks"
+
 	end



More information about the Ocfs-tools-commits mailing list