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

svn-commits at oss.oracle.com svn-commits at oss.oracle.com
Fri Jul 2 20:20:06 CDT 2004


Author: jlbec
Date: 2004-07-02 19:20:04 -0500 (Fri, 02 Jul 2004)
New Revision: 136

Added:
   trunk/ocfs2/libocfs2/dir_iterate.c
   trunk/ocfs2/libocfs2/dirblock.c
   trunk/ocfs2/libocfs2/include/dir_iterate.h
Modified:
   trunk/ocfs2/libocfs2/
   trunk/ocfs2/libocfs2/Makefile
   trunk/ocfs2/libocfs2/include/filesys.h
   trunk/ocfs2/libocfs2/inode.c
   trunk/ocfs2/libocfs2/ocfs2_err.et.in
Log:

o Directory iteration, straight from ext2




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
inode
extents
ocfs2_err.et

   + cscope*
stamp-md5
.*.sw?
.*.cmd
ocfs2_err.c
ocfs2_err.h
libocfs2.a
unix_io
openfs
inode
extents
dir_iterate
ocfs2_err.et


Modified: trunk/ocfs2/libocfs2/Makefile
===================================================================
--- trunk/ocfs2/libocfs2/Makefile	2004-07-02 23:02:28 UTC (rev 135)
+++ trunk/ocfs2/libocfs2/Makefile	2004-07-03 00:20:04 UTC (rev 136)
@@ -31,7 +31,7 @@
 CFLAGS += $(OPTIMIZE)
 
 ifneq ($(OCFS2_DEBUG_EXE),)
-BIN_PROGRAMS += unix_io openfs inode extents
+BIN_PROGRAMS += unix_io openfs inode extents dir_iterate
 
 unix_io: unix_io.c libocfs2.a
 	$(CC) $(CFLAGS) $(LOCAL_CFLAGS) $(CPPFLAGS) $(LOCAL_CPPFLAGS) \
@@ -52,6 +52,11 @@
 	$(CC) $(CFLAGS) $(LOCAL_CFLAGS) $(CPPFLAGS) $(LOCAL_CPPFLAGS) \
 		$(INCLUDES) $(DEFINES) $(VERMAGIC) \
 		$(COM_ERR_LIBS) -DDEBUG_EXE -o $@ $^
+
+dir_iterate: dir_iterate.c libocfs2.a
+	$(CC) $(CFLAGS) $(LOCAL_CFLAGS) $(CPPFLAGS) $(LOCAL_CPPFLAGS) \
+		$(INCLUDES) $(DEFINES) $(VERMAGIC) \
+		$(COM_ERR_LIBS) -DDEBUG_EXE -o $@ $^
 endif
 CFILES = 		\
 	unix_io.c	\
@@ -61,7 +66,9 @@
 	freefs.c	\
 	inode.c		\
 	mkjournal.c	\
-	extents.c
+	extents.c	\
+	dirblock.c	\
+	dir_iterate.c
 
 HFILES =				\
 	include/jfs_user.h		\
@@ -74,7 +81,8 @@
 	include/memory.h		\
 	include/unix_io.h		\
 	include/byteorder.h		\
-	include/filesys.h
+	include/filesys.h		\
+	include/dir_iterate.h
 
 HFILES_GEN =		\
 	ocfs2_err.h

Added: trunk/ocfs2/libocfs2/dir_iterate.c
===================================================================
--- trunk/ocfs2/libocfs2/dir_iterate.c	2004-07-02 23:02:28 UTC (rev 135)
+++ trunk/ocfs2/libocfs2/dir_iterate.c	2004-07-03 00:20:04 UTC (rev 136)
@@ -0,0 +1,384 @@
+/* -*- mode: c; c-basic-offset: 8; -*-
+ * vim: noexpandtab sw=8 ts=8 sts=0:
+ *
+ * dirblock.c
+ *
+ * Directory block 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
+ *
+ *  This code is a port of e2fsprogs/lib/ext2fs/dir_iterate.c
+ *  Copyright (C) 1993, 1994, 1994, 1995, 1996, 1997 Theodore Ts'o.
+ */
+
+#define _XOPEN_SOURCE 600 /* Triggers magic in features.h */
+#define _LARGEFILE64_SOURCE
+
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <sys/stat.h>
+#include <time.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"
+
+#include "dir_iterate.h"
+
+/*
+ * This function checks to see whether or not a potential deleted
+ * directory entry looks valid.  What we do is check the deleted entry
+ * and each successive entry to make sure that they all look valid and
+ * that the last deleted entry ends at the beginning of the next
+ * undeleted entry.  Returns 1 if the deleted entry looks valid, zero
+ * if not valid.
+ */
+static int ocfs2_validate_entry(char *buf, int offset, int final_offset)
+{
+	struct ocfs2_dir_entry *dirent;
+	
+	while (offset < final_offset) {
+		dirent = (struct ocfs2_dir_entry *)(buf + offset);
+		offset += dirent->rec_len;
+		if ((dirent->rec_len < 8) ||
+		    ((dirent->rec_len % 4) != 0) ||
+		    (((dirent->name_len & 0xFF)+8) > dirent->rec_len))
+			return 0;
+	}
+	return (offset == final_offset);
+}
+
+errcode_t ocfs2_dir_iterate2(ocfs2_filesys *fs,
+			     uint64_t dir,
+			     int flags,
+			     char *block_buf,
+			     int (*func)(uint64_t	dir,
+					 int		entry,
+					 struct ocfs2_dir_entry *dirent,
+					 int	offset,
+					 int	blocksize,
+					 char	*buf,
+					 void	*priv_data),
+			     void *priv_data)
+{
+	struct		dir_context	ctx;
+	errcode_t	retval;
+	
+	retval = ocfs2_check_directory(fs, dir);
+	if (retval)
+		return retval;
+	
+	ctx.dir = dir;
+	ctx.flags = flags;
+	if (block_buf)
+		ctx.buf = block_buf;
+	else {
+		retval = ocfs2_malloc_block(fs->fs_io, &ctx.buf);
+		if (retval)
+			return retval;
+	}
+	ctx.func = func;
+	ctx.priv_data = priv_data;
+	ctx.errcode = 0;
+	retval = ocfs2_block_iterate(fs, dir, 0,
+				     ocfs2_process_dir_block, &ctx);
+	if (!block_buf)
+		ocfs2_free(&ctx.buf);
+	if (retval)
+		return retval;
+	return ctx.errcode;
+}
+
+struct xlate {
+	int (*func)(struct ocfs2_dir_entry *dirent,
+		    int		offset,
+		    int		blocksize,
+		    char	*buf,
+		    void	*priv_data);
+	void *real_private;
+};
+
+static int xlate_func(uint64_t dir,
+		      int entry,
+		      struct ocfs2_dir_entry *dirent, int offset,
+		      int blocksize, char *buf, void *priv_data)
+{
+	struct xlate *xl = (struct xlate *) priv_data;
+
+	return (*xl->func)(dirent, offset, blocksize, buf, xl->real_private);
+}
+
+extern errcode_t ocfs2_dir_iterate(ocfs2_filesys *fs, 
+				   uint64_t dir,
+				   int flags,
+				   char *block_buf,
+				   int (*func)(struct ocfs2_dir_entry *dirent,
+					       int	offset,
+					       int	blocksize,
+					       char	*buf,
+					       void	*priv_data),
+				   void *priv_data)
+{
+	struct xlate xl;
+	
+	xl.real_private = priv_data;
+	xl.func = func;
+
+	return ocfs2_dir_iterate2(fs, dir, flags, block_buf,
+				  xlate_func, &xl);
+}
+
+
+/*
+ * Helper function which is private to this module.  Used by
+ * ocfs2_dir_iterate() and ocfs2_dblist_dir_iterate()
+ */
+int ocfs2_process_dir_block(ocfs2_filesys *fs,
+			    uint64_t	blocknr,
+			    uint64_t	blockcnt,
+			    void	*priv_data)
+{
+	struct dir_context *ctx = (struct dir_context *) priv_data;
+	unsigned int	offset = 0;
+	unsigned int	next_real_entry = 0;
+	int		ret = 0;
+	int		changed = 0;
+	int		do_abort = 0;
+	int		entry, size;
+	struct ocfs2_dir_entry *dirent;
+
+	if (blockcnt < 0)
+		return 0;
+
+	entry = blockcnt ? OCFS2_DIRENT_OTHER_FILE :
+		OCFS2_DIRENT_DOT_FILE;
+	
+	ctx->errcode = ocfs2_read_dir_block(fs, blocknr, ctx->buf);
+	if (ctx->errcode)
+		return OCFS2_BLOCK_ABORT;
+
+	while (offset < fs->fs_blocksize) {
+		dirent = (struct ocfs2_dir_entry *) (ctx->buf + offset);
+		if (((offset + dirent->rec_len) > fs->fs_blocksize) ||
+		    (dirent->rec_len < 8) ||
+		    ((dirent->rec_len % 4) != 0) ||
+		    (((dirent->name_len & 0xFF)+8) > dirent->rec_len)) {
+			ctx->errcode = OCFS2_ET_DIR_CORRUPTED;
+			return OCFS2_BLOCK_ABORT;
+		}
+		if (!dirent->inode &&
+		    !(ctx->flags & OCFS2_DIRENT_FLAG_INCLUDE_EMPTY))
+			goto next;
+
+		ret = (ctx->func)(ctx->dir,
+				  (next_real_entry > offset) ?
+				  OCFS2_DIRENT_DELETED_FILE : entry,
+				  dirent, offset,
+				  fs->fs_blocksize, ctx->buf,
+				  ctx->priv_data);
+		if (entry < OCFS2_DIRENT_OTHER_FILE)
+			entry++;
+			
+		if (ret & OCFS2_DIRENT_CHANGED)
+			changed++;
+		if (ret & OCFS2_DIRENT_ABORT) {
+			do_abort++;
+			break;
+		}
+next:		
+ 		if (next_real_entry == offset)
+			next_real_entry += dirent->rec_len;
+ 
+ 		if (ctx->flags & OCFS2_DIRENT_FLAG_INCLUDE_REMOVED) {
+			size = ((dirent->name_len & 0xFF) + 11) & ~3;
+
+			if (dirent->rec_len != size)  {
+				unsigned int final_offset;
+
+				final_offset = offset + dirent->rec_len;
+				offset += size;
+				while (offset < final_offset &&
+				       !ocfs2_validate_entry(ctx->buf,
+							     offset,
+							     final_offset))
+					offset += 4;
+				continue;
+			}
+		}
+		offset += dirent->rec_len;
+	}
+
+	if (changed) {
+		ctx->errcode = ocfs2_write_dir_block(fs, blocknr,
+						     ctx->buf);
+		if (ctx->errcode)
+			return OCFS2_BLOCK_ABORT;
+	}
+	if (do_abort)
+		return OCFS2_BLOCK_ABORT;
+	return 0;
+}
+
+
+#ifdef DEBUG_EXE
+#include <getopt.h>
+
+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: dir_iterate -i <inode_blkno> <filename>\n");
+}
+
+static int walk_names_func(struct ocfs2_dir_entry *dentry,
+			   int offset,
+			   int blocksize,
+			   char *buf,
+			   void *priv_data)
+{
+	char name[256];
+
+	memcpy(name, dentry->name, dentry->name_len);
+	name[dentry->name_len] = '\0';
+
+	fprintf(stdout, "% 20llu %s\n", dentry->inode, name);
+
+	return 0;
+}
+
+
+
+extern int opterr, optind;
+extern char *optarg;
+
+int main(int argc, char *argv[])
+{
+	errcode_t ret;
+	uint64_t blkno;
+	int c;
+	char *filename, *buf;
+	ocfs2_filesys *fs;
+	ocfs2_dinode *di;
+
+	blkno = OCFS2_SUPER_BLOCK_BLKNO;
+
+	initialize_ocfs_error_table();
+
+	while ((c = getopt(argc, argv, "i:")) != EOF) {
+		switch (c) {
+			case 'i':
+				blkno = read_number(optarg);
+				if (blkno <= OCFS2_SUPER_BLOCK_BLKNO) {
+					fprintf(stderr,
+						"Invalid inode block: %s\n",
+						optarg);
+					print_usage();
+					return 1;
+				}
+				break;
+
+			default:
+				print_usage();
+				return 1;
+				break;
+		}
+	}
+
+	if (optind >= argc) {
+		fprintf(stderr, "Missing filename\n");
+		print_usage();
+		return 1;
+	}
+	filename = argv[optind];
+	
+	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;
+	}
+
+
+	ret = ocfs2_read_inode(fs, blkno, buf);
+	if (ret) {
+		com_err(argv[0], ret,
+			"while reading inode %llu", blkno);
+		goto out_free;
+	}
+
+	di = (ocfs2_dinode *)buf;
+
+	fprintf(stdout, "OCFS2 inode %llu on \"%s\"\n",
+		blkno, filename);
+
+	ret = ocfs2_dir_iterate(fs, blkno, 0, NULL,
+				walk_names_func, NULL);
+	if (ret) {
+		com_err(argv[0], ret,
+			"while listing inode %llu on \"%s\"\n",
+			blkno, filename);
+		goto out_free;
+	}
+
+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 */
+
+

Added: trunk/ocfs2/libocfs2/dirblock.c
===================================================================
--- trunk/ocfs2/libocfs2/dirblock.c	2004-07-02 23:02:28 UTC (rev 135)
+++ trunk/ocfs2/libocfs2/dirblock.c	2004-07-03 00:20:04 UTC (rev 136)
@@ -0,0 +1,144 @@
+/* -*- mode: c; c-basic-offset: 8; -*-
+ * vim: noexpandtab sw=8 ts=8 sts=0:
+ *
+ * dirblock.c
+ *
+ * Directory block 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
+ *
+ *  This code is a port of e2fsprogs/lib/ext2fs/dirblock.c
+ *  Copyright (C) 1995, 1996 Theodore Ts'o.
+ */
+
+#define _XOPEN_SOURCE 600 /* Triggers magic in features.h */
+#define _LARGEFILE64_SOURCE
+
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <sys/stat.h>
+#include <time.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"
+
+
+errcode_t ocfs2_read_dir_block(ocfs2_filesys *fs, uint64_t block,
+                               void *buf)
+{
+	errcode_t	retval;
+	char		*p, *end;
+	struct ocfs2_dir_entry *dirent;
+	unsigned int	name_len, rec_len;
+#ifdef OCFS2_ENABLE_SWAPFS
+	unsigned int	do_swap;
+#endif
+	
+
+ 	retval = io_read_block(fs->fs_io, block, 1, buf);
+	if (retval)
+		return retval;
+#ifdef OCFS2_ENABLE_SWAPFS
+	do_swap = (fs->fs_flags & (OCFS2_FLAG_SWAP_BYTES|
+				OCFS2_FLAG_SWAP_BYTES_READ)) != 0;
+#endif
+	p = (char *) buf;
+	end = (char *) buf + fs->fs_blocksize;
+	while (p < end-8) {
+		dirent = (struct ocfs2_dir_entry *) p;
+#ifdef OCFS2_ENABLE_SWAPFS
+		if (do_swap) {
+			dirent->inode = le32_to_cpu(dirent->inode);
+			dirent->rec_len = le16_to_cpu(dirent->rec_len);
+		}
+#endif
+		name_len = dirent->name_len;
+		rec_len = dirent->rec_len;
+		if ((rec_len < 8) || (rec_len % 4)) {
+			rec_len = 8;
+			retval = OCFS2_ET_DIR_CORRUPTED;
+		}
+		if (((name_len & 0xFF) + 8) > dirent->rec_len)
+			retval = OCFS2_ET_DIR_CORRUPTED;
+		p += rec_len;
+	}
+	return retval;
+}
+
+errcode_t ocfs2_write_dir_block(ocfs2_filesys *fs, uint64_t block,
+                                void *inbuf)
+{
+#ifdef OCFS2_ENABLE_SWAPFS
+	int		do_swap = 0;
+	errcode_t	retval;
+	char		*p, *end;
+	char		*buf = 0;
+	struct ocfs2_dir_entry *dirent;
+
+	if ((fs->fs_flags & OCFS2_FLAG_SWAP_BYTES) ||
+	    (fs->fs_flags & OCFS2_FLAG_SWAP_BYTES_WRITE))
+		do_swap = 1;
+
+#ifndef WORDS_BIGENDIAN
+	if (!do_swap)
+		return io_write_block(fs->fs_io, block, 1,
+                                      (char *) inbuf);
+#endif
+
+	retval = ocfs2_malloc_block(fs->fs_io, &buf);
+	if (retval)
+		return retval;
+	memcpy(buf, inbuf, fs->fs_blocksize);
+	p = buf;
+	end = buf + fs->fs_blocksize;
+	while (p < end) {
+		dirent = (struct ocfs2_dir_entry *) p;
+		if ((dirent->rec_len < 8) ||
+		    (dirent->rec_len % 4)) {
+			ocfs2_free(&buf);
+			return (EXT2_ET_DIR_CORRUPTED);
+		}
+		p += dirent->rec_len;
+		if (do_swap) {
+			dirent->inode = ext2fs_swab32(dirent->inode);
+			dirent->rec_len = ext2fs_swab16(dirent->rec_len);
+		}
+	}
+ 	retval = io_write_block(fs->fs_io, block, 1, buf);
+	ocfs2_free(&buf);
+	return retval;
+#else
+ 	return io_write_block(fs->fs_io, block, 1, (char *) inbuf);
+#endif
+}
+
+

Added: trunk/ocfs2/libocfs2/include/dir_iterate.h
===================================================================
--- trunk/ocfs2/libocfs2/include/dir_iterate.h	2004-07-02 23:02:28 UTC (rev 135)
+++ trunk/ocfs2/libocfs2/include/dir_iterate.h	2004-07-03 00:20:04 UTC (rev 136)
@@ -0,0 +1,50 @@
+/* -*- mode: c; c-basic-offset: 8; -*-
+ * vim: noexpandtab sw=8 ts=8 sts=0:
+ *
+ * dir_iterate.h
+ *
+ * Structures for dir iteration 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 _DIR_ITERATE_H
+#define _DIR_ITERATE_H
+
+struct dir_context {
+	uint64_t dir;
+	int flags;
+	char *buf;
+	int (*func)(uint64_t dir,
+		    int entry,
+		    struct ocfs2_dir_entry *dirent,
+		    int offset,
+		    int blocksize,
+		    char *buf,
+		    void *priv_data);
+	void *priv_data;
+	errcode_t errcode;
+};
+
+extern int ocfs2_process_dir_block(ocfs2_filesys *fs,
+				   uint64_t	blocknr,
+				   uint64_t	blockcnt,
+				   void		*priv_data);
+
+#endif  /* _DIR_ITERATE_H */

Modified: trunk/ocfs2/libocfs2/include/filesys.h
===================================================================
--- trunk/ocfs2/libocfs2/include/filesys.h	2004-07-02 23:02:28 UTC (rev 135)
+++ trunk/ocfs2/libocfs2/include/filesys.h	2004-07-03 00:20:04 UTC (rev 136)
@@ -84,6 +84,22 @@
 #define OCFS2_BLOCK_FLAG_APPEND		0x01
 
 
+/* Return flags for the directory iterator functions */
+#define OCFS2_DIRENT_CHANGED	1
+#define OCFS2_DIRENT_ABORT	2
+#define OCFS2_DIRENT_ERROR	3
+
+/* Directory iterator flags */
+#define OCFS2_DIRENT_FLAG_INCLUDE_EMPTY		1
+#define OCFS2_DIRENT_FLAG_INCLUDE_REMOVED	2
+
+/* Directory constants */
+#define OCFS2_DIRENT_DOT_FILE		1
+#define OCFS2_DIRENT_DOT_DOT_FILE	2
+#define OCFS2_DIRENT_OTHER_FILE		3
+#define OCFS2_DIRENT_DELETED_FILE	4
+
+
 typedef struct _ocfs2_filesys ocfs2_filesys;
 
 struct _ocfs2_filesys {
@@ -113,6 +129,7 @@
 			   char *inode_buf);
 errcode_t ocfs2_write_inode(ocfs2_filesys *fs, uint64_t blkno,
 			    char *inode_buf);
+errcode_t ocfs2_check_directory(ocfs2_filesys *fs, uint64_t dir);
 
 errcode_t ocfs2_create_journal_superblock(ocfs2_filesys *fs,
 					  uint32_t size, int flags,
@@ -143,5 +160,33 @@
 					  void *priv_data),
 			      void *priv_data);
 
+errcode_t ocfs2_read_dir_block(ocfs2_filesys *fs, uint64_t block,
+			       void *buf);
+errcode_t ocfs2_write_dir_block(ocfs2_filesys *fs, uint64_t block,
+				void *buf);
+
+errcode_t ocfs2_dir_iterate2(ocfs2_filesys *fs,
+			     uint64_t dir,
+			     int flags,
+			     char *block_buf,
+			     int (*func)(uint64_t	dir,
+					 int		entry,
+					 struct ocfs2_dir_entry *dirent,
+					 int	offset,
+					 int	blocksize,
+					 char	*buf,
+					 void	*priv_data),
+			     void *priv_data);
+extern errcode_t ocfs2_dir_iterate(ocfs2_filesys *fs, 
+				   uint64_t dir,
+				   int flags,
+				   char *block_buf,
+				   int (*func)(struct ocfs2_dir_entry *dirent,
+					       int	offset,
+					       int	blocksize,
+					       char	*buf,
+					       void	*priv_data),
+				   void *priv_data);
+
 #endif  /* _FILESYS_H */
 

Modified: trunk/ocfs2/libocfs2/inode.c
===================================================================
--- trunk/ocfs2/libocfs2/inode.c	2004-07-02 23:02:28 UTC (rev 135)
+++ trunk/ocfs2/libocfs2/inode.c	2004-07-03 00:20:04 UTC (rev 136)
@@ -53,6 +53,34 @@
 #include "filesys.h"
 
 
+errcode_t ocfs2_check_directory(ocfs2_filesys *fs, uint64_t dir)
+{
+	ocfs2_dinode *inode;
+	char *buf;
+	errcode_t ret;
+
+	if ((dir < OCFS2_SUPER_BLOCK_BLKNO) ||
+	    (dir > fs->fs_blocks))
+		return OCFS2_ET_BAD_BLKNO;
+
+	ret = ocfs2_malloc_block(fs->fs_io, &buf);
+	if (ret)
+		return ret;
+
+	ret = ocfs2_read_inode(fs, dir, buf);
+	if (ret)
+		goto out_buf;
+
+	inode = (ocfs2_dinode *)buf;
+	if (!S_ISDIR(inode->i_mode))
+		ret = OCFS2_ET_NO_DIRECTORY;
+
+out_buf:
+	ocfs2_free(&buf);
+
+	return ret;
+}
+
 errcode_t ocfs2_read_inode(ocfs2_filesys *fs, uint64_t blkno,
 			   char *inode_buf)
 {

Modified: trunk/ocfs2/libocfs2/ocfs2_err.et.in
===================================================================
--- trunk/ocfs2/libocfs2/ocfs2_err.et.in	2004-07-02 23:02:28 UTC (rev 135)
+++ trunk/ocfs2/libocfs2/ocfs2_err.et.in	2004-07-03 00:20:04 UTC (rev 136)
@@ -68,4 +68,10 @@
 ec	OCFS2_ET_CORRUPT_EXTENT_BLOCK,
 	"Extent block is corrupt"
 
+ec	OCFS2_ET_DIR_CORRUPTED,
+	"OCFS2 directory corrupted"
+
+ec	OCFS2_ET_NO_DIRECTORY,
+	"OCFS2 inode is not a directory"
+
 	end



More information about the Ocfs-tools-commits mailing list