[Ocfs-tools-commits]
jlbec commits r117 - in trunk: . ocfs2/libocfs2
ocfs2/libocfs2/include
svn-commits at oss.oracle.com
svn-commits at oss.oracle.com
Tue Jun 29 20:13:46 CDT 2004
Author: jlbec
Date: 2004-06-29 19:13:43 -0500 (Tue, 29 Jun 2004)
New Revision: 117
Added:
trunk/ocfs2/libocfs2/closefs.c
trunk/ocfs2/libocfs2/freefs.c
trunk/ocfs2/libocfs2/include/byteorder.h
trunk/ocfs2/libocfs2/include/filesys.h
trunk/ocfs2/libocfs2/openfs.c
Modified:
trunk/configure.in
trunk/ocfs2/libocfs2/
trunk/ocfs2/libocfs2/Makefile
trunk/ocfs2/libocfs2/include/ocfs2_fs.h
trunk/ocfs2/libocfs2/include/unix_io.h
trunk/ocfs2/libocfs2/memory.c
trunk/ocfs2/libocfs2/ocfs2_err.et.in
trunk/ocfs2/libocfs2/unix_io.c
Log:
o Basic openfs()
Modified: trunk/configure.in
===================================================================
--- trunk/configure.in 2004-06-29 18:04:59 UTC (rev 116)
+++ trunk/configure.in 2004-06-30 00:13:43 UTC (rev 117)
@@ -131,6 +131,8 @@
fi
AC_SUBST(COM_ERR_LIBS)
+AC_C_BIGENDIAN()
+
AC_MSG_CHECKING(for debug executables)
AC_ARG_ENABLE(debugexe, [ --enable-debugexe=[yes/no] Enable debug executables for library source files [default=no]],,enable_debugexe=no)
OCFS2_DEBUG_EXE=
Property changes on: trunk/ocfs2/libocfs2
___________________________________________________________________
Name: svn:ignore
- cscope*
stamp-md5
.*.sw?
.*.cmd
ocfs2_err.c
ocfs2_err.h
libocfs2.a
unix_io
ocfs2_err.et
+ cscope*
stamp-md5
.*.sw?
.*.cmd
ocfs2_err.c
ocfs2_err.h
libocfs2.a
unix_io
openfs
ocfs2_err.et
Modified: trunk/ocfs2/libocfs2/Makefile
===================================================================
--- trunk/ocfs2/libocfs2/Makefile 2004-06-29 18:04:59 UTC (rev 116)
+++ trunk/ocfs2/libocfs2/Makefile 2004-06-30 00:13:43 UTC (rev 117)
@@ -31,17 +31,24 @@
CFLAGS += $(OPTIMIZE)
ifneq ($(OCFS2_DEBUG_EXE),)
-BIN_PROGRAMS += unix_io
+BIN_PROGRAMS += unix_io openfs
unix_io: unix_io.c libocfs2.a
$(CC) $(CFLAGS) $(LOCAL_CFLAGS) $(CPPFLAGS) $(LOCAL_CPPFLAGS) \
$(INCLUDES) $(DEFINES) $(VERMAGIC) \
$(COM_ERR_LIBS) -DDEBUG_EXE -o $@ $^
+openfs: openfs.c libocfs2.a
+ $(CC) $(CFLAGS) $(LOCAL_CFLAGS) $(CPPFLAGS) $(LOCAL_CPPFLAGS) \
+ $(INCLUDES) $(DEFINES) $(VERMAGIC) \
+ $(COM_ERR_LIBS) -DDEBUG_EXE -o $@ $^
endif
CFILES = \
unix_io.c \
- memory.c
+ memory.c \
+ openfs.c \
+ closefs.c \
+ freefs.c
HFILES = \
include/kernel-jbd.h \
@@ -49,7 +56,10 @@
include/ocfs2_fs.h \
include/ocfs2_disk_dlm.h \
include/ocfs1_fs_compat.h \
- include/memory.h
+ include/memory.h \
+ include/unix_io.h \
+ include/byteorder.h \
+ include/filesys.h
HFILES_GEN = \
ocfs2_err.h
Added: trunk/ocfs2/libocfs2/closefs.c
===================================================================
--- trunk/ocfs2/libocfs2/closefs.c 2004-06-29 18:04:59 UTC (rev 116)
+++ trunk/ocfs2/libocfs2/closefs.c 2004-06-30 00:13:43 UTC (rev 117)
@@ -0,0 +1,73 @@
+/* -*- mode: c; c-basic-offset: 8; -*-
+ * vim: noexpandtab sw=8 ts=8 sts=0:
+ *
+ * closefs.c
+ *
+ * Close an OCFS2 filesystem. 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/closefs.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_flush(ocfs2_filesys *fs)
+{
+ return 0;
+}
+
+errcode_t ocfs2_close(ocfs2_filesys *fs)
+{
+ errcode_t ret;
+
+ if (fs->fs_flags & OCFS2_FLAG_DIRTY) {
+ ret = ocfs2_flush(fs);
+ if (ret)
+ return ret;
+ }
+
+ ocfs2_freefs(fs);
+ return 0;
+}
Added: trunk/ocfs2/libocfs2/freefs.c
===================================================================
--- trunk/ocfs2/libocfs2/freefs.c 2004-06-29 18:04:59 UTC (rev 116)
+++ trunk/ocfs2/libocfs2/freefs.c 2004-06-30 00:13:43 UTC (rev 117)
@@ -0,0 +1,69 @@
+/* -*- mode: c; c-basic-offset: 8; -*-
+ * vim: noexpandtab sw=8 ts=8 sts=0:
+ *
+ * freefs.c
+ *
+ * Free an OCFS2 filesystem. 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/freefs.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 "filesys.h"
+
+void ocfs2_freefs(ocfs2_filesys *fs)
+{
+ if (!fs)
+ abort();
+
+ if (fs->fs_orig_super)
+ ocfs2_free(&fs->fs_orig_super);
+ if (fs->fs_super)
+ ocfs2_free(&fs->fs_super);
+ if (fs->fs_devname)
+ ocfs2_free(&fs->fs_devname);
+ if (fs->fs_io)
+ io_close(fs->fs_io);
+
+ ocfs2_free(&fs);
+}
Added: trunk/ocfs2/libocfs2/include/byteorder.h
===================================================================
--- trunk/ocfs2/libocfs2/include/byteorder.h 2004-06-29 18:04:59 UTC (rev 116)
+++ trunk/ocfs2/libocfs2/include/byteorder.h 2004-06-30 00:13:43 UTC (rev 117)
@@ -0,0 +1,39 @@
+/* -*- mode: c; c-basic-offset: 8; -*-
+ * vim: noexpandtab sw=8 ts=8 sts=0:
+ *
+ * byteorder.h
+ *
+ * Byteswapping!
+ *
+ * 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
+ */
+
+#ifndef _BYTEORDER_H
+#define _BYTEORDER_H
+
+/*
+ * This is a hack, using the kernel parts, until we get something
+ * stable in userspace....unless everyone is happy with this??
+ */
+
+#define __KERNEL__
+#include <asm/byteorder.h>
+#undef __KERNEL__
+
+#endif /* _BYTEORDER_H */
Added: trunk/ocfs2/libocfs2/include/filesys.h
===================================================================
--- trunk/ocfs2/libocfs2/include/filesys.h 2004-06-29 18:04:59 UTC (rev 116)
+++ trunk/ocfs2/libocfs2/include/filesys.h 2004-06-30 00:13:43 UTC (rev 117)
@@ -0,0 +1,64 @@
+/* -*- mode: c; c-basic-offset: 8; -*-
+ * vim: noexpandtab sw=8 ts=8 sts=0:
+ *
+ * filesys.h
+ *
+ * Filesystem object routines 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
+ */
+
+#ifndef _FILESYS_H
+#define _FILESYS_H
+
+#define OCFS2_LIB_FEATURE_INCOMPAT_SUPP OCFS2_FEATURE_INCOMPAT_SUPP
+#define OCFS2_LIB_FEATURE_RO_COMPAT_SUPP OCFS2_FEATURE_RO_COMPAT_SUPP
+
+/* Flags for the ocfs2_filesys structure */
+#define OCFS2_FLAG_RO 0x00
+#define OCFS2_FLAG_RW 0x01
+#define OCFS2_FLAG_CHANGED 0x02
+#define OCFS2_FLAG_DIRTY 0x04
+#define OCFS2_FLAG_SWAP_BYTES 0x08
+
+typedef struct _ocfs2_filesys ocfs2_filesys;
+
+struct _ocfs2_filesys {
+ char *fs_devname;
+ uint32_t fs_flags;
+ io_channel *fs_io;
+ ocfs2_dinode *fs_super;
+ ocfs2_dinode *fs_orig_super;
+ unsigned int fs_blocksize;
+ unsigned int fs_clustersize;
+ uint32_t fs_umask;
+
+ /* Reserved for the use of the calling application. */
+ void *fs_private;
+};
+
+
+errcode_t ocfs2_open(const char *name, int flags, int superblock,
+ unsigned int blksize, ocfs2_filesys **ret_fs);
+errcode_t ocfs2_flush(ocfs2_filesys *fs);
+errcode_t ocfs2_close(ocfs2_filesys *fs);
+void ocfs2_freefs(ocfs2_filesys *fs);
+
+#endif /* _FILESYS_H */
+
Modified: trunk/ocfs2/libocfs2/include/ocfs2_fs.h
===================================================================
--- trunk/ocfs2/libocfs2/include/ocfs2_fs.h 2004-06-29 18:04:59 UTC (rev 116)
+++ trunk/ocfs2/libocfs2/include/ocfs2_fs.h 2004-06-30 00:13:43 UTC (rev 117)
@@ -49,6 +49,7 @@
* As OCFS2 has a minimum clustersize of 4K, it has a maximum blocksize
* of 4K
*/
+#define OCFS2_MIN_BLOCKSIZE 512
#define OCFS2_MAX_BLOCKSIZE 4096
/* Object signatures */
@@ -231,8 +232,8 @@
* ocfs2_extent_block.h_list, respectively.
*/
typedef struct _ocfs2_extent_list {
-/*00*/ __s16 l_tree_depth; /* Extent tree depth from this
- point. -1 means data extents
+/*00*/ __u16 l_tree_depth; /* Extent tree depth from this
+ point. 0 means data extents
hang directly off this
header (a leaf) */
__u16 l_count; /* Number of extent records */
Modified: trunk/ocfs2/libocfs2/include/unix_io.h
===================================================================
--- trunk/ocfs2/libocfs2/include/unix_io.h 2004-06-29 18:04:59 UTC (rev 116)
+++ trunk/ocfs2/libocfs2/include/unix_io.h 2004-06-30 00:13:43 UTC (rev 117)
@@ -29,14 +29,11 @@
typedef struct _io_channel io_channel;
-#define OCFS2_FLAG_RO 0x00
-#define OCFS2_FLAG_RW 0x01
-
errcode_t io_open(const char *name, int flags, io_channel **channel);
errcode_t io_close(io_channel *channel);
int io_get_error(io_channel *channel);
errcode_t io_set_blksize(io_channel *channel, int blksize);
-errcode_t io_get_blksize(io_channel *channel, int *blksize);
+int io_get_blksize(io_channel *channel);
errcode_t io_read_block(io_channel *channel, int64_t blkno, int count,
char *data);
errcode_t io_write_block(io_channel *channel, int64_t blkno, int count,
Modified: trunk/ocfs2/libocfs2/memory.c
===================================================================
--- trunk/ocfs2/libocfs2/memory.c 2004-06-29 18:04:59 UTC (rev 116)
+++ trunk/ocfs2/libocfs2/memory.c 2004-06-30 00:13:43 UTC (rev 117)
@@ -110,7 +110,7 @@
int blksize;
void **pp = (void **)ptr;
- io_get_blksize(channel, &blksize);
+ blksize = io_get_blksize(channel);
ret = posix_memalign(pp, blksize, num_blocks * blksize);
if (!ret)
Modified: trunk/ocfs2/libocfs2/ocfs2_err.et.in
===================================================================
--- trunk/ocfs2/libocfs2/ocfs2_err.et.in 2004-06-29 18:04:59 UTC (rev 116)
+++ trunk/ocfs2/libocfs2/ocfs2_err.et.in 2004-06-30 00:13:43 UTC (rev 117)
@@ -26,4 +26,22 @@
ec OCFS2_ET_INVALID_ARGUMENT,
"Invalid argument passed to OCFS2 library"
+ec OCFS2_ET_OCFS_REV,
+ "Device contains an OCFS volume"
+
+ec OCFS2_ET_BAD_MAGIC,
+ "Bad magic number in superblock"
+
+ec OCFS2_ET_UNEXPECTED_BLOCK_SIZE,
+ "Filesystem has unexpected block size"
+
+ec OCFS2_ET_CORRUPT_SUPERBLOCK,
+ "The OCFS2 superblock is corrupt"
+
+ec OCFS2_ET_UNSUPP_FEATURE,
+ "Filesystem has unsupported feature(s)"
+
+ec OCFS2_ET_RO_UNSUPP_FEATURE,
+ "Filesystem has unsupported read-only feature(s)"
+
end
Added: trunk/ocfs2/libocfs2/openfs.c
===================================================================
--- trunk/ocfs2/libocfs2/openfs.c 2004-06-29 18:04:59 UTC (rev 116)
+++ trunk/ocfs2/libocfs2/openfs.c 2004-06-30 00:13:43 UTC (rev 117)
@@ -0,0 +1,342 @@
+/* -*- mode: c; c-basic-offset: 8; -*-
+ * vim: noexpandtab sw=8 ts=8 sts=0:
+ *
+ * openfs.c
+ *
+ * Open an OCFS2 filesystem. 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/openfs.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"
+
+
+static errcode_t ocfs2_validate_ocfs1_header(ocfs2_filesys *fs)
+{
+ errcode_t ret;
+ char *blk;
+ ocfs1_vol_disk_hdr *hdr;
+
+ ret = ocfs2_malloc_block(fs->fs_io, &blk);
+ if (ret)
+ return ret;
+
+ ret = io_read_block(fs->fs_io, 0, 1, blk);
+ if (ret)
+ goto out;
+ hdr = (ocfs1_vol_disk_hdr *)blk;
+
+ ret = OCFS2_ET_OCFS_REV;
+ if (le32_to_cpu(hdr->major_version) == OCFS1_MAJOR_VERSION)
+ goto out;
+ if (!memcmp(hdr->signature, OCFS1_VOLUME_SIGNATURE,
+ strlen(OCFS1_VOLUME_SIGNATURE)))
+ goto out;
+
+ ret = 0;
+
+out:
+ ocfs2_free(&blk);
+
+ return ret;
+}
+
+static errcode_t ocfs2_read_super(ocfs2_filesys *fs, int superblock)
+{
+ errcode_t ret;
+ char *blk;
+ ocfs2_dinode *di;
+
+ ret = ocfs2_malloc_block(fs->fs_io, &blk);
+ if (ret)
+ return ret;
+
+ ret = io_read_block(fs->fs_io, superblock, 1, blk);
+ if (ret)
+ goto out_blk;
+ di = (ocfs2_dinode *)blk;
+
+ ret = OCFS2_ET_BAD_MAGIC;
+ if (memcmp(di->i_signature, OCFS2_SUPER_BLOCK_SIGNATURE,
+ strlen(OCFS2_SUPER_BLOCK_SIGNATURE)))
+ goto out_blk;
+
+ fs->fs_super = di;
+
+ /* FIXME: Swap the sucker here
+ * ocfs2_swap_inode()
+ * ocfs2_swap_super()
+ */
+
+ return 0;
+
+out_blk:
+ ocfs2_free(&blk);
+
+ return ret;
+}
+
+errcode_t ocfs2_open(const char *name, int flags, int superblock,
+ unsigned int block_size, ocfs2_filesys **ret_fs)
+{
+ ocfs2_filesys *fs;
+ errcode_t ret;
+
+ ret = ocfs2_malloc0(sizeof(ocfs2_filesys), &fs);
+ if (ret)
+ return ret;
+
+ fs->fs_flags = flags;
+ fs->fs_umask = 022;
+
+ ret = io_open(name, (flags & (OCFS2_FLAG_RO | OCFS2_FLAG_RW)),
+ &fs->fs_io);
+ if (ret)
+ goto out;
+
+ ret = ocfs2_malloc(strlen(name)+1, &fs->fs_devname);
+ if (ret)
+ goto out;
+ strcpy(fs->fs_devname, name);
+
+ ret = ocfs2_validate_ocfs1_header(fs);
+ if (ret)
+ goto out;
+
+ if (superblock) {
+ ret = OCFS2_ET_INVALID_ARGUMENT;
+ if (!block_size)
+ goto out;
+ io_set_blksize(fs->fs_io, block_size);
+ ret = ocfs2_read_super(fs, superblock);
+ } else {
+ superblock = OCFS2_SUPER_BLOCK_BLKNO;
+ if (block_size) {
+ io_set_blksize(fs->fs_io, block_size);
+ ret = ocfs2_read_super(fs, superblock);
+ } else {
+ for (block_size = io_get_blksize(fs->fs_io);
+ block_size <= OCFS2_MAX_BLOCKSIZE;
+ block_size <<= 1) {
+ io_set_blksize(fs->fs_io, block_size);
+ ret = ocfs2_read_super(fs, superblock);
+ if (ret == OCFS2_ET_BAD_MAGIC)
+ continue;
+ break;
+ }
+ }
+ }
+ if (ret)
+ goto out;
+
+ fs->fs_blocksize = block_size;
+ if (superblock == OCFS2_SUPER_BLOCK_BLKNO) {
+ ret = ocfs2_malloc_block(fs->fs_io, &fs->fs_orig_super);
+ if (ret)
+ goto out;
+ memcpy((char *)fs->fs_orig_super,
+ (char *)fs->fs_super, fs->fs_blocksize);
+ }
+
+#if 0
+ ret = OCFS2_ET_REV_TOO_HIGH;
+ if (fs->fs_super->id2.i_super.s_major_rev_level >
+ OCFS2_LIB_CURRENT_REV)
+ goto out;
+#endif
+
+ ret = OCFS2_ET_UNSUPP_FEATURE;
+ if (OCFS2_RAW_SB(fs->fs_super)->s_feature_incompat &
+ ~OCFS2_LIB_FEATURE_INCOMPAT_SUPP)
+ goto out;
+
+ ret = OCFS2_ET_RO_UNSUPP_FEATURE;
+ if ((flags & OCFS2_FLAG_RW) &&
+ (OCFS2_RAW_SB(fs->fs_super)->s_feature_ro_compat &
+ ~OCFS2_LIB_FEATURE_RO_COMPAT_SUPP))
+ goto out;
+
+ ret = OCFS2_ET_CORRUPT_SUPERBLOCK;
+ if (!OCFS2_RAW_SB(fs->fs_super)->s_blocksize_bits)
+ goto out;
+ if (fs->fs_super->i_blkno != superblock)
+ goto out;
+ if ((OCFS2_RAW_SB(fs->fs_super)->s_clustersize_bits < 12) ||
+ (OCFS2_RAW_SB(fs->fs_super)->s_clustersize_bits > 20))
+ goto out;
+ if (!OCFS2_RAW_SB(fs->fs_super)->s_root_blkno ||
+ !OCFS2_RAW_SB(fs->fs_super)->s_system_dir_blkno)
+ goto out;
+ if (OCFS2_RAW_SB(fs->fs_super)->s_max_nodes > OCFS2_MAX_NODES)
+ goto out;
+
+ ret = OCFS2_ET_UNEXPECTED_BLOCK_SIZE;
+ if (block_size !=
+ (1 << OCFS2_RAW_SB(fs->fs_super)->s_blocksize_bits))
+ goto out;
+
+ fs->fs_clustersize =
+ 1 << OCFS2_RAW_SB(fs->fs_super)->s_clustersize_bits;
+
+ /* FIXME: Read the system dir */
+
+ *ret_fs = fs;
+ return 0;
+
+out:
+ ocfs2_freefs(fs);
+
+ return ret;
+}
+
+#ifdef DEBUG_EXE
+#include <getopt.h>
+#include <limits.h>
+
+static int64_t read_number(const char *num)
+{
+ int64_t val;
+ char *ptr;
+
+ val = strtoll(num, &ptr, 0);
+ if (!ptr || *ptr)
+ return 0;
+
+ return val;
+}
+
+static void print_usage(void)
+{
+ fprintf(stderr,
+ "Usage: openfs [-s <superblock>] [-B <blksize>]\n"
+ " <filename>\n");
+}
+
+extern int opterr, optind;
+extern char *optarg;
+
+int main(int argc, char *argv[])
+{
+ errcode_t ret;
+ int c;
+ int64_t blkno, blksize;
+ char *filename;
+ ocfs2_filesys *fs;
+
+ /* These mean "autodetect" */
+ blksize = 0;
+ blkno = 0;
+
+ initialize_ocfs_error_table();
+
+ while((c = getopt(argc, argv, "s:B:")) != EOF) {
+ switch (c) {
+ case 's':
+ blkno = read_number(optarg);
+ if (blkno < OCFS2_SUPER_BLOCK_BLKNO) {
+ fprintf(stderr,
+ "Invalid blkno: %s\n",
+ optarg);
+ print_usage();
+ return 1;
+ }
+ break;
+
+ case 'B':
+ blksize = read_number(optarg);
+ if (blksize < OCFS2_MIN_BLOCKSIZE) {
+ fprintf(stderr,
+ "Invalid blksize: %s\n",
+ optarg);
+ print_usage();
+ return 1;
+ }
+ break;
+
+ default:
+ print_usage();
+ return 1;
+ break;
+ }
+ }
+
+ if (blksize % OCFS2_MIN_BLOCKSIZE) {
+ fprintf(stderr, "Invalid blocksize: %lld\n", blksize);
+ print_usage();
+ return 1;
+ }
+
+ if (optind >= argc) {
+ fprintf(stderr, "Missing filename\n");
+ print_usage();
+ return 1;
+ }
+
+ filename = argv[optind];
+
+ ret = ocfs2_open(filename, OCFS2_FLAG_RO, blkno, blksize, &fs);
+ if (ret) {
+ com_err(argv[0], ret,
+ "while opening file \"%s\"", filename);
+ goto out;
+ }
+
+ fprintf(stdout, "OCFS2 filesystem on \"%s\":\n", filename);
+ fprintf(stdout,
+ "\tblocksize = %d\n"
+ "\tclustersize = %d\n",
+ fs->fs_blocksize,
+ fs->fs_clustersize);
+
+ 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/unix_io.c
===================================================================
--- trunk/ocfs2/libocfs2/unix_io.c 2004-06-29 18:04:59 UTC (rev 116)
+++ trunk/ocfs2/libocfs2/unix_io.c 2004-06-30 00:13:43 UTC (rev 117)
@@ -31,6 +31,7 @@
#define _XOPEN_SOURCE 600 /* Triggers ISOC99, UNIX98 in features.h */
#define _LARGEFILE64_SOURCE
+#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <stdint.h>
@@ -44,15 +45,19 @@
#include <sys/utsname.h>
#endif
+#include <linux/types.h>
+
#include <et/com_err.h>
#include "ocfs2_err.h"
#include "unix_io.h"
#include "memory.h"
+#include "ocfs2_fs.h" /* For OCFS2_MIN_BLOCKSIZE */
-#define OCFS2_MIN_BLKSIZE 512
+#include "filesys.h"
+
struct _io_channel {
char *io_name;
int io_blksize;
@@ -82,7 +87,7 @@
if (ret)
goto out_chan;
strcpy(chan->io_name, name);
- chan->io_blksize = OCFS2_MIN_BLKSIZE;
+ chan->io_blksize = OCFS2_MIN_BLOCKSIZE;
chan->io_flags = (flags & OCFS2_FLAG_RW) ? O_RDWR : O_RDONLY;
chan->io_error = 0;
@@ -162,11 +167,11 @@
errcode_t io_set_blksize(io_channel *channel, int blksize)
{
- if (blksize % OCFS2_MIN_BLKSIZE)
+ if (blksize % OCFS2_MIN_BLOCKSIZE)
return OCFS2_ET_INVALID_ARGUMENT;
if (!blksize)
- blksize = OCFS2_MIN_BLKSIZE;
+ blksize = OCFS2_MIN_BLOCKSIZE;
if (channel->io_blksize != blksize)
channel->io_blksize = blksize;
@@ -174,11 +179,9 @@
return 0;
}
-errcode_t io_get_blksize(io_channel *channel, int *blksize)
+int io_get_blksize(io_channel *channel)
{
- *blksize = channel->io_blksize;
-
- return 0;
+ return channel->io_blksize;
}
errcode_t io_read_block(io_channel *channel, int64_t blkno, int count,
@@ -355,7 +358,7 @@
case 'B':
blksize = read_number(optarg);
- if (!count) {
+ if (!blksize) {
fprintf(stderr,
"Invalid blksize: %s\n",
optarg);
@@ -371,7 +374,7 @@
}
}
- if (blksize % OCFS2_MIN_BLKSIZE) {
+ if (blksize % OCFS2_MIN_BLOCKSIZE) {
fprintf(stderr, "Invalid blocksize: %lld\n", blksize);
print_usage();
return 1;
More information about the Ocfs-tools-commits
mailing list