[Ocfs2-tools-commits] jlbec commits r214 - in trunk: libocfs2
libocfs2/include vendor/common
svn-commits at oss.oracle.com
svn-commits at oss.oracle.com
Tue Aug 31 17:10:46 CDT 2004
Author: jlbec
Date: 2004-08-31 17:10:44 -0500 (Tue, 31 Aug 2004)
New Revision: 214
Added:
trunk/libocfs2/fileio.c
Modified:
trunk/libocfs2/Makefile
trunk/libocfs2/include/ocfs2.h
trunk/libocfs2/unix_io.c
trunk/vendor/common/
Log:
o Add ocfs2_read_whole_file() to the API in fileio.c
o Make io_open() use O_DIRECT.
Modified: trunk/libocfs2/Makefile
===================================================================
--- trunk/libocfs2/Makefile 2004-08-31 20:40:17 UTC (rev 213)
+++ trunk/libocfs2/Makefile 2004-08-31 22:10:44 UTC (rev 214)
@@ -64,7 +64,8 @@
sysfile.c \
link.c \
unlink.c \
- bitmap.c
+ bitmap.c \
+ fileio.c
HFILES = \
include/jfs_user.h \
Added: trunk/libocfs2/fileio.c
===================================================================
--- trunk/libocfs2/fileio.c 2004-08-31 20:40:17 UTC (rev 213)
+++ trunk/libocfs2/fileio.c 2004-08-31 22:10:44 UTC (rev 214)
@@ -0,0 +1,126 @@
+/* -*- mode: c; c-basic-offset: 8; -*-
+ * vim: noexpandtab sw=8 ts=8 sts=0:
+ *
+ * fileio.c
+ *
+ * I/O to files. Part of 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/fileio.c
+ * Copyright (C) 1997 Theodore Ts'o.
+ */
+
+#define _XOPEN_SOURCE 600 /* Triggers XOPEN2K in features.h */
+#define _LARGEFILE64_SOURCE
+
+#include <string.h>
+#include <limits.h>
+
+#include "ocfs2.h"
+
+struct read_whole_context {
+ char *buf;
+ char *ptr;
+ int size;
+ int offset;
+ errcode_t errcode;
+};
+
+static int read_whole_func(ocfs2_filesys *fs,
+ uint64_t blkno,
+ uint64_t bcount,
+ void *priv_data)
+{
+ struct read_whole_context *ctx = priv_data;
+
+ ctx->errcode = io_read_block(fs->fs_io, blkno,
+ 1, ctx->ptr);
+ if (ctx->errcode)
+ return OCFS2_BLOCK_ABORT;
+
+ ctx->ptr += fs->fs_blocksize;
+ ctx->offset += fs->fs_blocksize;
+
+ return 0;
+}
+
+errcode_t ocfs2_read_whole_file(ocfs2_filesys *fs,
+ uint64_t blkno,
+ char **buf,
+ int *len)
+{
+ struct read_whole_context ctx;
+ errcode_t retval;
+ char *inode_buf;
+ ocfs2_dinode *di;
+ int c_to_b_bits =
+ OCFS2_RAW_SB(fs->fs_super)->s_clustersize_bits -
+ OCFS2_RAW_SB(fs->fs_super)->s_blocksize_bits;
+
+ /* So the caller can see nothing was read */
+ *len = 0;
+ *buf = NULL;
+
+ retval = ocfs2_malloc_block(fs->fs_io, &inode_buf);
+ if (retval)
+ return retval;
+
+ retval = ocfs2_read_inode(fs, blkno, inode_buf);
+ if (retval)
+ goto out_free;
+
+ di = (ocfs2_dinode *)inode_buf;
+
+ /* Arbitrary limit for our malloc */
+ retval = OCFS2_ET_INVALID_ARGUMENT;
+ if (di->i_size > INT_MAX)
+ goto out_free;
+
+ retval = ocfs2_malloc_blocks(fs->fs_io,
+ di->i_clusters << c_to_b_bits,
+ buf);
+ if (retval)
+ goto out_free;
+
+ ctx.buf = *buf;
+ ctx.ptr = *buf;
+ ctx.size = di->i_size;
+ ctx.offset = 0;
+ ctx.errcode = 0;
+ retval = ocfs2_block_iterate(fs, blkno, 0,
+ read_whole_func, &ctx);
+
+ *len = ctx.size;
+ if (ctx.offset < ctx.size)
+ *len = ctx.offset;
+
+out_free:
+ ocfs2_free(&inode_buf);
+
+ if (!(*len)) {
+ ocfs2_free(buf);
+ *buf = NULL;
+ }
+
+ if (retval)
+ return retval;
+ return ctx.errcode;
+}
+
Modified: trunk/libocfs2/include/ocfs2.h
===================================================================
--- trunk/libocfs2/include/ocfs2.h 2004-08-31 20:40:17 UTC (rev 213)
+++ trunk/libocfs2/include/ocfs2.h 2004-08-31 22:10:44 UTC (rev 214)
@@ -312,5 +312,8 @@
errcode_t ocfs2_check_mount_point(const char *device, int *mount_flags,
char *mtpt, int mtlen);
+errcode_t ocfs2_read_whole_file(ocfs2_filesys *fs, uint64_t blkno,
+ char **buf, int *len);
+
#endif /* _FILESYS_H */
Modified: trunk/libocfs2/unix_io.c
===================================================================
--- trunk/libocfs2/unix_io.c 2004-08-31 20:40:17 UTC (rev 213)
+++ trunk/libocfs2/unix_io.c 2004-08-31 22:10:44 UTC (rev 214)
@@ -30,6 +30,7 @@
#define _XOPEN_SOURCE 600 /* Triggers ISOC99, UNIX98 in features.h */
#define _LARGEFILE64_SOURCE
+#define _GNU_SOURCE /* Because libc really doesn't want us using O_DIRECT? */
#include <string.h>
#include <sys/types.h>
@@ -76,6 +77,8 @@
strcpy(chan->io_name, name);
chan->io_blksize = OCFS2_MIN_BLOCKSIZE;
chan->io_flags = (flags & OCFS2_FLAG_RW) ? O_RDWR : O_RDONLY;
+ /* FIXME: should do a "check for success, fallback to bindraw */
+ chan->io_flags |= O_DIRECT;
chan->io_error = 0;
ret = OCFS2_ET_IO;
Property changes on: trunk/vendor/common
___________________________________________________________________
Name: svn:ignore
- ocfs-tools.spec
+ ocfs2-tools.spec
More information about the Ocfs2-tools-commits
mailing list