[Ocfs-tools-commits]
jlbec commits r119 - in trunk/ocfs2/libocfs2: . include
svn-commits at oss.oracle.com
svn-commits at oss.oracle.com
Wed Jun 30 14:29:20 CDT 2004
Author: jlbec
Date: 2004-06-30 13:29:18 -0500 (Wed, 30 Jun 2004)
New Revision: 119
Added:
trunk/ocfs2/libocfs2/inode.c
Modified:
trunk/ocfs2/libocfs2/
trunk/ocfs2/libocfs2/Makefile
trunk/ocfs2/libocfs2/include/filesys.h
trunk/ocfs2/libocfs2/memory.c
trunk/ocfs2/libocfs2/ocfs2_err.et.in
Log:
o Basic read/write_inode support (doesn't swab yet)
Property changes on: trunk/ocfs2/libocfs2
___________________________________________________________________
Name: svn:ignore
- cscope*
stamp-md5
.*.sw?
.*.cmd
ocfs2_err.c
ocfs2_err.h
libocfs2.a
unix_io
openfs
ocfs2_err.et
+ cscope*
stamp-md5
.*.sw?
.*.cmd
ocfs2_err.c
ocfs2_err.h
libocfs2.a
unix_io
openfs
inode
ocfs2_err.et
Modified: trunk/ocfs2/libocfs2/Makefile
===================================================================
--- trunk/ocfs2/libocfs2/Makefile 2004-06-30 01:24:06 UTC (rev 118)
+++ trunk/ocfs2/libocfs2/Makefile 2004-06-30 18:29:18 UTC (rev 119)
@@ -31,7 +31,7 @@
CFLAGS += $(OPTIMIZE)
ifneq ($(OCFS2_DEBUG_EXE),)
-BIN_PROGRAMS += unix_io openfs
+BIN_PROGRAMS += unix_io openfs inode
unix_io: unix_io.c libocfs2.a
$(CC) $(CFLAGS) $(LOCAL_CFLAGS) $(CPPFLAGS) $(LOCAL_CPPFLAGS) \
@@ -42,6 +42,11 @@
$(CC) $(CFLAGS) $(LOCAL_CFLAGS) $(CPPFLAGS) $(LOCAL_CPPFLAGS) \
$(INCLUDES) $(DEFINES) $(VERMAGIC) \
$(COM_ERR_LIBS) -DDEBUG_EXE -o $@ $^
+
+inode: inode.c libocfs2.a
+ $(CC) $(CFLAGS) $(LOCAL_CFLAGS) $(CPPFLAGS) $(LOCAL_CPPFLAGS) \
+ $(INCLUDES) $(DEFINES) $(VERMAGIC) \
+ $(COM_ERR_LIBS) -DDEBUG_EXE -o $@ $^
endif
CFILES = \
unix_io.c \
Modified: trunk/ocfs2/libocfs2/include/filesys.h
===================================================================
--- trunk/ocfs2/libocfs2/include/filesys.h 2004-06-30 01:24:06 UTC (rev 118)
+++ trunk/ocfs2/libocfs2/include/filesys.h 2004-06-30 18:29:18 UTC (rev 119)
@@ -60,5 +60,10 @@
errcode_t ocfs2_close(ocfs2_filesys *fs);
void ocfs2_freefs(ocfs2_filesys *fs);
+errcode_t ocfs2_read_inode(ocfs2_filesys *fs, uint64_t blkno,
+ ocfs2_dinode *di);
+errcode_t ocfs2_write_inode(ocfs2_filesys *fs, uint64_t blkno,
+ ocfs2_dinode *di);
+
#endif /* _FILESYS_H */
Added: trunk/ocfs2/libocfs2/inode.c
===================================================================
--- trunk/ocfs2/libocfs2/inode.c 2004-06-30 01:24:06 UTC (rev 118)
+++ trunk/ocfs2/libocfs2/inode.c 2004-06-30 18:29:18 UTC (rev 119)
@@ -0,0 +1,226 @@
+/* -*- mode: c; c-basic-offset: 8; -*-
+ * vim: noexpandtab sw=8 ts=8 sts=0:
+ *
+ * inode.c
+ *
+ * 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
+ *
+ * Ideas taken from e2fsprogs/lib/ext2fs/inode.c
+ * Copyright (C) 1993, 1994, 1995, 1996 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 "unix_io.h"
+#include "memory.h"
+#include "byteorder.h"
+
+#include "ocfs2_fs.h"
+#include "ocfs1_fs_compat.h"
+
+#include "filesys.h"
+
+
+errcode_t ocfs2_read_inode(ocfs2_filesys *fs, uint64_t blkno,
+ ocfs2_dinode *inode)
+{
+ errcode_t ret;
+ char *blk;
+ ocfs2_dinode *di;
+
+ if ((blkno < OCFS2_SUPER_BLOCK_BLKNO) ||
+#if 0
+ (blkno > fs->fs_blocks))
+#else
+ 0)
+#endif
+ return OCFS2_ET_BAD_BLKNO;
+
+ ret = ocfs2_malloc_block(fs->fs_io, &blk);
+ if (ret)
+ return ret;
+
+ ret = io_read_block(fs->fs_io, blkno, 1, blk);
+ if (ret)
+ goto out;
+
+ di = (ocfs2_dinode *)blk;
+
+ ret = OCFS2_ET_BAD_INODE_MAGIC;
+ if (memcmp(di->i_signature, OCFS2_INODE_SIGNATURE,
+ strlen(OCFS2_INODE_SIGNATURE)))
+ goto out;
+
+ /* FIXME swap inode */
+
+ memcpy((char *)inode, blk, io_get_blksize(fs->fs_io));
+
+ ret = 0;
+out:
+ ocfs2_free(&blk);
+
+ return ret;
+}
+
+errcode_t ocfs2_write_inode(ocfs2_filesys *fs, uint64_t blkno,
+ ocfs2_dinode *inode)
+{
+ errcode_t ret;
+ char *blk;
+
+ if (!(fs->fs_flags & OCFS2_FLAG_RW))
+ return OCFS2_ET_RO_FILESYS;
+
+ if ((blkno < OCFS2_SUPER_BLOCK_BLKNO) ||
+#if 0
+ (blkno > fs->fs_blocks))
+#else
+ 0)
+#endif
+ return OCFS2_ET_BAD_BLKNO;
+
+ ret = ocfs2_malloc_block(fs->fs_io, &blk);
+ if (ret)
+ return ret;
+
+ /* FIXME Swap inode */
+ memcpy(blk, inode, io_get_blksize(fs->fs_io));
+
+ ret = io_write_block(fs->fs_io, blkno, 1, blk);
+ if (ret)
+ goto out;
+
+ fs->fs_flags |= OCFS2_FLAG_CHANGED;
+ ret = 0;
+
+out:
+ ocfs2_free(&blk);
+
+ return ret;
+}
+
+
+#ifdef DEBUG_EXE
+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: inode <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 /* DEBUG_EXE */
Modified: trunk/ocfs2/libocfs2/memory.c
===================================================================
--- trunk/ocfs2/libocfs2/memory.c 2004-06-30 01:24:06 UTC (rev 118)
+++ trunk/ocfs2/libocfs2/memory.c 2004-06-30 18:29:18 UTC (rev 119)
@@ -123,5 +123,5 @@
errcode_t ocfs2_malloc_block(io_channel *channel, void *ptr)
{
- return ocfs2_malloc_blocks(channel, 0, ptr);
+ return ocfs2_malloc_blocks(channel, 1, ptr);
}
Modified: trunk/ocfs2/libocfs2/ocfs2_err.et.in
===================================================================
--- trunk/ocfs2/libocfs2/ocfs2_err.et.in 2004-06-30 01:24:06 UTC (rev 118)
+++ trunk/ocfs2/libocfs2/ocfs2_err.et.in 2004-06-30 18:29:18 UTC (rev 119)
@@ -44,4 +44,13 @@
ec OCFS2_ET_RO_UNSUPP_FEATURE,
"Filesystem has unsupported read-only feature(s)"
+ec OCFS2_ET_BAD_INODE_MAGIC,
+ "Bad magic number in inode"
+
+ec OCFS2_ET_BAD_BLKNO,
+ "Invalid block number"
+
+ec OCFS2_ET_RO_FILESYS,
+ "Attempt to write to filesystem opened read-only"
+
end
More information about the Ocfs-tools-commits
mailing list