[Ocfs-tools-commits]
jlbec commits r114 - in trunk: . ocfs2 ocfs2/libocfs2
ocfs2/libocfs2/include
svn-commits at oss.oracle.com
svn-commits at oss.oracle.com
Mon Jun 28 21:23:57 CDT 2004
Author: jlbec
Date: 2004-06-28 20:23:54 -0500 (Mon, 28 Jun 2004)
New Revision: 114
Added:
trunk/ocfs2/libocfs2/include/memory.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
Modified:
trunk/Config.make.in
trunk/configure.in
trunk/ocfs2/Makefile
trunk/ocfs2/libocfs2/
trunk/ocfs2/libocfs2/Makefile
Log:
o libocfs2 memory routines
o libocfs2 com_err setup
o libocfs2 io routines
Modified: trunk/Config.make.in
===================================================================
--- trunk/Config.make.in 2004-06-29 01:20:14 UTC (rev 113)
+++ trunk/Config.make.in 2004-06-29 01:23:54 UTC (rev 114)
@@ -37,6 +37,8 @@
CPPFLAGS = @CPPFLAGS@
LDFLAGS = @LDFLAGS@
+COM_ERR_LIBS = @COM_ERR_LIBS@
+
GLIB_CFLAGS = @GLIB_CFLAGS@
GLIB_LIBS = @GLIB_LIBS@
Modified: trunk/configure.in
===================================================================
--- trunk/configure.in 2004-06-29 01:20:14 UTC (rev 113)
+++ trunk/configure.in 2004-06-29 01:23:54 UTC (rev 114)
@@ -124,6 +124,13 @@
AC_SUBST(OCFS_TRACE)
AC_MSG_RESULT($enable_trace)
+COM_ERR_LIBS=
+AC_CHECK_LIB(com_err, com_err, COM_ERR_LIBS=-lcom_err)
+if test "x$COM_ERR_LIBS" = "x"; then
+ AC_MSG_ERROR([Unable to find com_err library])
+fi
+AC_SUBST(COM_ERR_LIBS)
+
GLIB_REQUIRED_VERSION=1.2.8
GTK_REQUIRED_VERSION=1.2.8
@@ -156,4 +163,5 @@
load_ocfs/load_ocfs.8
ocfstool/ocfstool.8
vendor/common/ocfs-tools.spec
+ocfs2/libocfs2/ocfs2_err.et
])
Modified: trunk/ocfs2/Makefile
===================================================================
--- trunk/ocfs2/Makefile 2004-06-29 01:20:14 UTC (rev 113)
+++ trunk/ocfs2/Makefile 2004-06-29 01:23:54 UTC (rev 114)
@@ -2,6 +2,6 @@
include $(TOPDIR)/Preamble.make
-SUBDIRS = mkfs.ocfs2 debugfs.ocfs2
+SUBDIRS = mkfs.ocfs2 debugfs.ocfs2 libocfs2
include $(TOPDIR)/Postamble.make
Property changes on: trunk/ocfs2/libocfs2
___________________________________________________________________
Name: svn:ignore
- cscope*
stamp-md5
.*.sw?
.*.cmd
+ cscope*
stamp-md5
.*.sw?
.*.cmd
ocfs2_err.c
ocfs2_err.h
libocfs2.a
unix_io
ocfs2_err.et
Modified: trunk/ocfs2/libocfs2/Makefile
===================================================================
--- trunk/ocfs2/libocfs2/Makefile 2004-06-29 01:20:14 UTC (rev 113)
+++ trunk/ocfs2/libocfs2/Makefile 2004-06-29 01:23:54 UTC (rev 114)
@@ -11,7 +11,7 @@
INCLUDES = -I. -Iinclude
-LIBRARIES = libocfs.a
+LIBRARIES = libocfs2.a
CFLAGS = $(OPTS) -fno-strict-aliasing $(WARNINGS)
@@ -30,27 +30,44 @@
CFLAGS += $(OPTIMIZE)
+ifneq ($(OCFS2_DEBUG_EXE),)
+DEFINES += -DDEBUG_EXE
+
+BIN_PROGRAMS += unix_io
+
+unix_io: unix_io.o memory.o ocfs2_err.o
+ $(LINK) $(COM_ERR) $(COM_ERR_LIBS)
+
+endif
CFILES = \
- mounted.c \
+ unix_io.c \
+ memory.c
HFILES = \
- include/kernel-jbh.h \
+ include/kernel-jbd.h \
include/kernel-list.h \
include/ocfs2_fs.h \
include/ocfs2_disk_dlm.h \
- include/ocfs1_fs_compat.h
+ include/ocfs1_fs_compat.h \
+ include/memory.h
+
+HFILES_GEN = \
+ ocfs2_err.h
+$(CFILES): $(HFILES) $(HFILES_GEN)
-$(CFILES): $(HFILES)
+OBJS = $(subst .c,.o,$(CFILES)) \
+ ocfs2_err.o
-OBJS = $(subst .c,.o,$(CFILES))
+ocfs2_err.c ocfs2_err.h: ocfs2_err.et
+ compile_et ocfs2_err.et
-libocfs.a: $(OBJS)
+libocfs2.a: $(OBJS)
rm -f $@
$(AR) r $@ $^
$(RANLIB) $@
-DIST_FILES = $(CFILES) $(HFILES)
+DIST_FILES = $(CFILES) $(HFILES) ocfs2_err.et.in
DIST_RULES = dist-subdircreate
Added: trunk/ocfs2/libocfs2/include/memory.h
===================================================================
--- trunk/ocfs2/libocfs2/include/memory.h 2004-06-29 01:20:14 UTC (rev 113)
+++ trunk/ocfs2/libocfs2/include/memory.h 2004-06-29 01:23:54 UTC (rev 114)
@@ -0,0 +1,40 @@
+/* -*- mode: c; c-basic-offset: 8; -*-
+ * vim: noexpandtab sw=8 ts=8 sts=0:
+ *
+ * memory.h
+ *
+ * Memory 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 _MEMORY_H
+#define _MEMORY_H
+
+errcode_t ocfs2_malloc(unsigned long size, void *ptr);
+errcode_t ocfs2_malloc0(unsigned long size, void *ptr);
+errcode_t ocfs2_free(void *ptr);
+errcode_t ocfs2_realloc(unsigned long size, void *ptr);
+errcode_t ocfs2_realloc0(unsigned long size, void *ptr,
+ unsigned long old_size);
+errcode_t ocfs2_malloc_blocks(io_channel *channel, int num_blocks,
+ void *ptr);
+errcode_t ocfs2_malloc_block(io_channel *channel, void *ptr);
+
+#endif /* _MEMORY_H */
Added: trunk/ocfs2/libocfs2/include/unix_io.h
===================================================================
--- trunk/ocfs2/libocfs2/include/unix_io.h 2004-06-29 01:20:14 UTC (rev 113)
+++ trunk/ocfs2/libocfs2/include/unix_io.h 2004-06-29 01:23:54 UTC (rev 114)
@@ -0,0 +1,44 @@
+/* -*- mode: c; c-basic-offset: 8; -*-
+ * vim: noexpandtab sw=8 ts=8 sts=0:
+ *
+ * unix_io.h
+ *
+ * I/O 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 _UNIX_IO_H
+#define _UNIX_IO_H
+
+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);
+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,
+ const char *data);
+#endif /* _UNIX_IO_H */
Added: trunk/ocfs2/libocfs2/memory.c
===================================================================
--- trunk/ocfs2/libocfs2/memory.c 2004-06-29 01:20:14 UTC (rev 113)
+++ trunk/ocfs2/libocfs2/memory.c 2004-06-29 01:23:54 UTC (rev 114)
@@ -0,0 +1,126 @@
+/* -*- mode: c; c-basic-offset: 8; -*-
+ * vim: noexpandtab sw=8 ts=8 sts=0:
+ *
+ * memory.c
+ *
+ * Memory 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
+ *
+ * Portions of this code from e2fsprogs/lib/ext2fs/ext2fs.h
+ * Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
+ * 2002 by Theodore Ts'o.
+ */
+
+#define _XOPEN_SOURCE 600
+#define _LARGEFILE64_SOURCE
+
+#include <string.h>
+#include <stdlib.h>
+#include <errno.h>
+
+#include "ocfs2_err.h"
+
+#include "unix_io.h"
+#include "memory.h"
+
+errcode_t ocfs2_malloc(unsigned long size, void *ptr)
+{
+ void **pp = (void **)ptr;
+
+ *pp = malloc(size);
+ if (!*pp)
+ return OCFS2_ET_NO_MEMORY;
+ return 0;
+}
+
+errcode_t ocfs2_malloc0(unsigned long size, void *ptr)
+{
+ errcode_t ret;
+ void **pp = (void **)ptr;
+
+ ret = ocfs2_malloc(size, ptr);
+ if (ret)
+ return ret;
+
+ memset(*pp, 0, size);
+ return 0;
+}
+
+errcode_t ocfs2_free(void *ptr)
+{
+ void **pp = (void **)ptr;
+
+ free(*pp);
+ *pp = NULL;
+ return 0;
+}
+
+errcode_t ocfs2_realloc(unsigned long size, void *ptr)
+{
+ void *p;
+ void **pp = (void **)ptr;
+
+ p = realloc(*pp, size);
+ if (!p)
+ return OCFS2_ET_NO_MEMORY;
+ *pp = p;
+ return 0;
+}
+
+errcode_t ocfs2_realloc0(unsigned long size, void *ptr,
+ unsigned long old_size)
+{
+ errcode_t ret;
+ char *p;
+ void **pp = (void **)ptr;
+
+ ret = ocfs2_realloc(size, ptr);
+ if (ret)
+ return ret;
+
+ if (size > old_size) {
+ p = (char *)(*pp);
+ memset(p + old_size, 0, size - old_size);
+ }
+ return 0;
+}
+
+errcode_t ocfs2_malloc_blocks(io_channel *channel, int num_blocks,
+ void *ptr)
+{
+ errcode_t ret;
+ int blksize;
+ void **pp = (void **)ptr;
+
+ io_get_blksize(channel, &blksize);
+
+ ret = posix_memalign(pp, blksize, num_blocks * blksize);
+ if (!ret)
+ return 0;
+ if (errno == ENOMEM)
+ return OCFS2_ET_NO_MEMORY;
+ /* blksize better be valid */
+ abort();
+}
+
+errcode_t ocfs2_malloc_block(io_channel *channel, void *ptr)
+{
+ return ocfs2_malloc_blocks(channel, 0, ptr);
+}
Added: trunk/ocfs2/libocfs2/ocfs2_err.et.in
===================================================================
--- trunk/ocfs2/libocfs2/ocfs2_err.et.in 2004-06-29 01:20:14 UTC (rev 113)
+++ trunk/ocfs2/libocfs2/ocfs2_err.et.in 2004-06-29 01:23:54 UTC (rev 114)
@@ -0,0 +1,29 @@
+#
+# Copyright (C) 2004 Oracle Corporation
+#
+# Authors: Joel Becker
+#
+ error_table ocfs
+
+ec OCFS2_ET_BASE,
+ "OCFS2 Library version @VERSION@"
+
+ec OCFS2_ET_BAD_DEVICE_NAME,
+ "Illegal or malformed device name"
+
+ec OCFS2_ET_IO,
+ "I/O error on channel"
+
+ec OCFS2_ET_SHORT_READ,
+ "Attempt to read block from filesystem resulted in short read"
+
+ec OCFS2_ET_SHORT_WRITE,
+ "Attempt to read block from filesystem resulted in short write"
+
+ec OCFS2_ET_NO_MEMORY,
+ "Memory allocation failed"
+
+ec OCFS2_ET_INVALID_ARGUMENT,
+ "Invalid argument passed to OCFS2 library"
+
+ end
Added: trunk/ocfs2/libocfs2/unix_io.c
===================================================================
--- trunk/ocfs2/libocfs2/unix_io.c 2004-06-29 01:20:14 UTC (rev 113)
+++ trunk/ocfs2/libocfs2/unix_io.c 2004-06-29 01:23:54 UTC (rev 114)
@@ -0,0 +1,442 @@
+/* -*- mode: c; c-basic-offset: 8; -*-
+ * vim: noexpandtab sw=8 ts=8 sts=0:
+ *
+ * unix_io.c
+ *
+ * I/O routines for the OCFS2 userspace library.
+ *
+ * Copyright (C) 2002, 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 this code from e2fsprogs/lib/ext2fs/unix_io.c
+ * Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
+ * 2002 by Theodore Ts'o.
+ */
+
+#define _XOPEN_SOURCE 500
+#define _LARGEFILE64_SOURCE
+
+#include <string.h>
+#include <sys/types.h>
+#include <stdint.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <errno.h>
+#include <fcntl.h>
+#ifdef __linux__
+#include <sys/time.h>
+#include <sys/resource.h>
+#include <sys/utsname.h>
+#endif
+
+#include "ocfs2_err.h"
+
+#include "unix_io.h"
+#include "memory.h"
+
+
+#define OCFS2_MIN_BLKSIZE 512
+
+struct _io_channel {
+ char *io_name;
+ int io_blksize;
+ int io_flags;
+ int io_error;
+ int io_fd;
+};
+
+
+errcode_t io_open(const char *name, int flags, io_channel **channel)
+{
+ errcode_t ret;
+ io_channel *chan = NULL;
+#ifdef __linux__
+ struct stat stat_buf;
+ struct utsname ut;
+#endif
+
+ if (!name || !*name)
+ return OCFS2_ET_BAD_DEVICE_NAME;
+
+ ret = ocfs2_malloc0(sizeof(struct _io_channel), &chan);
+ if (ret)
+ return ret;
+
+ ret = ocfs2_malloc(strlen(name)+1, &chan->io_name);
+ if (ret)
+ goto out_chan;
+ strcpy(chan->io_name, name);
+ chan->io_blksize = OCFS2_MIN_BLKSIZE;
+ chan->io_flags = (flags & OCFS2_FLAG_RW) ? O_RDWR : O_RDONLY;
+ chan->io_error = 0;
+
+ ret = OCFS2_ET_IO;
+ chan->io_fd = open64(name, chan->io_flags);
+ if (chan->io_fd < 0) {
+ chan->io_error = errno;
+ goto out_name;
+ }
+
+ /* Workaround from e2fsprogs */
+#ifdef __linux__
+#undef RLIM_INFINITY
+#if (defined(__alpha__) || ((defined(__sparc__) || defined(__mips__)) && (SIZEOF_LONG == 4)))
+#define RLIM_INFINITY ((unsigned long)(~0UL>>1))
+#else
+#define RLIM_INFINITY (~0UL)
+#endif
+ /*
+ * Work around a bug in 2.4.10-2.4.18 kernels where writes to
+ * block devices are wrongly getting hit by the filesize
+ * limit. This workaround isn't perfect, since it won't work
+ * if glibc wasn't built against 2.2 header files. (Sigh.)
+ *
+ */
+ if ((flags & OCFS2_FLAG_RW) &&
+ (uname(&ut) == 0) &&
+ ((ut.release[0] == '2') && (ut.release[1] == '.') &&
+ (ut.release[2] == '4') && (ut.release[3] == '.') &&
+ (ut.release[4] == '1') && (ut.release[5] >= '0') &&
+ (ut.release[5] < '8')) &&
+ (fstat(chan->io_fd, &stat_buf) == 0) &&
+ (S_ISBLK(stat_buf.st_mode))) {
+ struct rlimit rlim;
+
+ rlim.rlim_cur = rlim.rlim_max = (unsigned long) RLIM_INFINITY;
+ setrlimit(RLIMIT_FSIZE, &rlim);
+ getrlimit(RLIMIT_FSIZE, &rlim);
+ if (((unsigned long) rlim.rlim_cur) <
+ ((unsigned long) rlim.rlim_max)) {
+ rlim.rlim_cur = rlim.rlim_max;
+ setrlimit(RLIMIT_FSIZE, &rlim);
+ }
+ }
+#endif
+
+ *channel = chan;
+ return 0;
+
+out_name:
+ ocfs2_free(&chan->io_name);
+
+out_chan:
+ ocfs2_free(&chan);
+
+ *channel = NULL;
+ return ret;
+}
+
+errcode_t io_close(io_channel *channel)
+{
+ errcode_t ret = 0;
+
+ if (close(channel->io_fd) < 0)
+ ret = errno;
+
+ ocfs2_free(&channel->io_name);
+ ocfs2_free(&channel);
+
+ return ret;
+}
+
+int io_get_error(io_channel *channel)
+{
+ return channel->io_error;
+}
+
+errcode_t io_set_blksize(io_channel *channel, int blksize)
+{
+ if (blksize % OCFS2_MIN_BLKSIZE)
+ return OCFS2_ET_INVALID_ARGUMENT;
+
+ if (!blksize)
+ blksize = OCFS2_MIN_BLKSIZE;
+
+ if (channel->io_blksize != blksize)
+ channel->io_blksize = blksize;
+
+ return 0;
+}
+
+errcode_t io_get_blksize(io_channel *channel, int *blksize)
+{
+ *blksize = channel->io_blksize;
+
+ return 0;
+}
+
+errcode_t io_read_block(io_channel *channel, int64_t blkno, int count,
+ char *data)
+{
+ int ret;
+ ssize_t size, tot, rd;
+ uint64_t location;
+
+ /* -ative means count is in bytes */
+ size = (count < 0) ? -count : count * channel->io_blksize;
+ location = blkno * channel->io_blksize;
+
+ tot = 0;
+ while (tot < size) {
+ rd = pread64(channel->io_fd, data + tot,
+ size - tot, location + tot);
+ ret = OCFS2_ET_IO;
+ if (rd < 0) {
+ channel->io_error = errno;
+ goto out;
+ }
+
+ if (!rd)
+ goto out;
+
+ tot += rd;
+ }
+
+ ret = 0;
+
+out:
+ if (!ret && tot != size) {
+ ret = OCFS2_ET_SHORT_READ;
+ memset(data + tot, 0, size - tot);
+ }
+
+ return ret;
+}
+
+errcode_t io_write_block(io_channel *channel, int64_t blkno, int count,
+ const char *data)
+{
+ int ret;
+ ssize_t size, tot, wr;
+ uint64_t location;
+
+ /* -ative means count is in bytes */
+ size = (count < 0) ? -count : count * channel->io_blksize;
+ location = blkno * channel->io_blksize;
+
+ tot = 0;
+ while (tot < size) {
+ wr = pwrite64(channel->io_fd, data + tot,
+ size - tot, location + tot);
+ ret = OCFS2_ET_IO;
+ if (wr < 0) {
+ channel->io_error = errno;
+ goto out;
+ }
+
+ if (!wr)
+ goto out;
+
+ tot += wr;
+ }
+
+ ret = 0;
+out:
+ if (!ret && (tot != size))
+ ret = OCFS2_ET_SHORT_WRITE;
+
+ return ret;
+}
+
+
+#ifdef DEBUG_EXE
+#include <stdio.h>
+#include <stdlib.h>
+#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 dump_u32(uint32_t *val)
+{
+ int i;
+ uint8_t *bytes = (uint8_t *)val;
+
+ for (i = 0; i < sizeof(uint32_t); i++)
+ fprintf(stdout, "%02X", bytes[i]);
+}
+
+static void dump_block(int64_t blkno, int blksize, char *buf)
+{
+ int offset, i;
+ uint32_t *vals = (uint32_t *)buf;
+
+ fprintf(stdout, "Dumping block %lld (%d bytes):\n", blkno,
+ blksize);
+
+ for (i = 0; i < (blksize / sizeof(uint32_t)); i++) {
+ if (!(i % 4)) {
+ if (i)
+ fprintf(stdout, "\n");
+ fprintf(stdout, "0x%08X\t",
+ i * sizeof(uint32_t));
+ }
+ dump_u32(&vals[i]);
+ fprintf(stdout, " ");
+ }
+ fprintf(stdout, "\n");
+}
+
+static void print_usage(void)
+{
+ fprintf(stderr,
+ "Usage: unix_io [-b <blkno>] [-c <count>] [-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, count, blksize;
+ char *filename;
+ io_channel *channel;
+ char *blks;
+
+ /* Some simple defaults */
+ blksize = 512;
+ blkno = 0;
+ count = 1;
+
+ initialize_ocfs_error_table();
+
+ while((c = getopt(argc, argv, "b:c:B:")) != EOF) {
+ switch (c) {
+ case 'b':
+ blkno = read_number(optarg);
+ if (blkno < 0) {
+ fprintf(stderr,
+ "Invalid blkno: %s\n",
+ optarg);
+ print_usage();
+ return 1;
+ }
+ break;
+
+ case 'c':
+ count = read_number(optarg);
+ if (!count) {
+ fprintf(stderr,
+ "Invalid count: %s\n",
+ optarg);
+ print_usage();
+ return 1;
+ }
+ break;
+
+ case 'B':
+ blksize = read_number(optarg);
+ if (!count) {
+ fprintf(stderr,
+ "Invalid blksize: %s\n",
+ optarg);
+ print_usage();
+ return 1;
+ }
+ break;
+
+ default:
+ print_usage();
+ return 1;
+ break;
+ }
+ }
+
+ if (blksize % OCFS2_MIN_BLKSIZE) {
+ fprintf(stderr, "Invalid blocksize: %lld\n", blksize);
+ print_usage();
+ return 1;
+ }
+ if (count < 0) {
+ if (-count > (int64_t)INT_MAX) {
+ fprintf(stderr, "Count is too large: %lld\n",
+ count);
+ print_usage();
+ return 1;
+ }
+ count = -count / blksize;
+ } else {
+ if ((count * blksize) > INT_MAX) {
+ fprintf(stderr, "Count is too large: %lld\n",
+ count);
+ print_usage();
+ return 1;
+ }
+ }
+
+ if (optind >= argc) {
+ fprintf(stderr, "Missing filename\n");
+ print_usage();
+ return 1;
+ }
+
+ filename = argv[optind];
+
+ ret = io_open(filename, OCFS2_FLAG_RO, &channel);
+ if (ret) {
+ com_err(argv[0], ret,
+ "while opening file \"%s\"", filename);
+ goto out;
+ }
+
+ ret = ocfs2_malloc_blocks(channel, (int)count, &blks);
+ if (ret) {
+ com_err(argv[0], ret,
+ "while allocating %d blocks", count);
+ goto out_channel;
+ }
+
+ ret = io_read_block(channel, blkno, (int)count, blks);
+ if (ret) {
+ com_err(argv[0], ret,
+ "while reading %d blocks at block %lld (%s)",
+ (int)count, blkno,
+ strerror(io_get_error(channel)));
+ goto out_blocks;
+ }
+
+ for (c = 0; c < count; c++)
+ dump_block(blkno + c, blksize, blks + (c * blksize));
+
+out_blocks:
+ ocfs2_free(&blks);
+
+out_channel:
+ ret = io_close(channel);
+ if (ret) {
+ com_err(argv[0], ret,
+ "while closing file \"%s\"", filename);
+ }
+
+out:
+ return 0;
+}
+#endif /* DEBUG_EXE */
More information about the Ocfs-tools-commits
mailing list