[Ocfs-tools-commits]
jlbec commits r137 - in trunk/ocfs2/libocfs2: . include
svn-commits at oss.oracle.com
svn-commits at oss.oracle.com
Fri Jul 2 21:00:51 CDT 2004
Author: jlbec
Date: 2004-07-02 20:00:49 -0500 (Fri, 02 Jul 2004)
New Revision: 137
Added:
trunk/ocfs2/libocfs2/lookup.c
Modified:
trunk/ocfs2/libocfs2/
trunk/ocfs2/libocfs2/Makefile
trunk/ocfs2/libocfs2/dirblock.c
trunk/ocfs2/libocfs2/include/filesys.h
trunk/ocfs2/libocfs2/ocfs2_err.et.in
Log:
o Lookup operations.
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
dir_iterate
ocfs2_err.et
+ cscope*
stamp-md5
.*.sw?
.*.cmd
ocfs2_err.c
ocfs2_err.h
libocfs2.a
unix_io
openfs
inode
extents
dir_iterate
lookup
ocfs2_err.et
Modified: trunk/ocfs2/libocfs2/Makefile
===================================================================
--- trunk/ocfs2/libocfs2/Makefile 2004-07-03 00:20:04 UTC (rev 136)
+++ trunk/ocfs2/libocfs2/Makefile 2004-07-03 01:00:49 UTC (rev 137)
@@ -31,7 +31,7 @@
CFLAGS += $(OPTIMIZE)
ifneq ($(OCFS2_DEBUG_EXE),)
-BIN_PROGRAMS += unix_io openfs inode extents dir_iterate
+BIN_PROGRAMS += unix_io openfs inode extents dir_iterate lookup
unix_io: unix_io.c libocfs2.a
$(CC) $(CFLAGS) $(LOCAL_CFLAGS) $(CPPFLAGS) $(LOCAL_CPPFLAGS) \
@@ -57,6 +57,11 @@
$(CC) $(CFLAGS) $(LOCAL_CFLAGS) $(CPPFLAGS) $(LOCAL_CPPFLAGS) \
$(INCLUDES) $(DEFINES) $(VERMAGIC) \
$(COM_ERR_LIBS) -DDEBUG_EXE -o $@ $^
+
+lookup: lookup.c libocfs2.a
+ $(CC) $(CFLAGS) $(LOCAL_CFLAGS) $(CPPFLAGS) $(LOCAL_CPPFLAGS) \
+ $(INCLUDES) $(DEFINES) $(VERMAGIC) \
+ $(COM_ERR_LIBS) -DDEBUG_EXE -o $@ $^
endif
CFILES = \
unix_io.c \
@@ -68,7 +73,8 @@
mkjournal.c \
extents.c \
dirblock.c \
- dir_iterate.c
+ dir_iterate.c \
+ lookup.c
HFILES = \
include/jfs_user.h \
Modified: trunk/ocfs2/libocfs2/dirblock.c
===================================================================
--- trunk/ocfs2/libocfs2/dirblock.c 2004-07-03 00:20:04 UTC (rev 136)
+++ trunk/ocfs2/libocfs2/dirblock.c 2004-07-03 01:00:49 UTC (rev 137)
@@ -77,7 +77,7 @@
dirent = (struct ocfs2_dir_entry *) p;
#ifdef OCFS2_ENABLE_SWAPFS
if (do_swap) {
- dirent->inode = le32_to_cpu(dirent->inode);
+ dirent->inode = le64_to_cpu(dirent->inode);
dirent->rec_len = le16_to_cpu(dirent->rec_len);
}
#endif
@@ -125,12 +125,12 @@
if ((dirent->rec_len < 8) ||
(dirent->rec_len % 4)) {
ocfs2_free(&buf);
- return (EXT2_ET_DIR_CORRUPTED);
+ return (OCFS2_ET_DIR_CORRUPTED);
}
p += dirent->rec_len;
if (do_swap) {
- dirent->inode = ext2fs_swab32(dirent->inode);
- dirent->rec_len = ext2fs_swab16(dirent->rec_len);
+ dirent->inode = cpu_to_le64(dirent->inode);
+ dirent->rec_len = cpu_to_le16(dirent->rec_len);
}
}
retval = io_write_block(fs->fs_io, block, 1, buf);
Modified: trunk/ocfs2/libocfs2/include/filesys.h
===================================================================
--- trunk/ocfs2/libocfs2/include/filesys.h 2004-07-03 00:20:04 UTC (rev 136)
+++ trunk/ocfs2/libocfs2/include/filesys.h 2004-07-03 01:00:49 UTC (rev 137)
@@ -188,5 +188,9 @@
void *priv_data),
void *priv_data);
+errcode_t ocfs2_lookup(ocfs2_filesys *fs, uint64_t dir,
+ const char *name, int namelen, char *buf,
+ uint64_t *inode);
+
#endif /* _FILESYS_H */
Added: trunk/ocfs2/libocfs2/lookup.c
===================================================================
--- trunk/ocfs2/libocfs2/lookup.c 2004-07-03 00:20:04 UTC (rev 136)
+++ trunk/ocfs2/libocfs2/lookup.c 2004-07-03 01:00:49 UTC (rev 137)
@@ -0,0 +1,248 @@
+/* -*- mode: c; c-basic-offset: 8; -*-
+ * vim: noexpandtab sw=8 ts=8 sts=0:
+ *
+ * lookup.c
+ *
+ * Directory lookup 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/lookup.c
+ * Copyright (C) 1993, 1994, 1994, 1995 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"
+
+
+struct lookup_struct {
+ const char *name;
+ int len;
+ uint64_t *inode;
+ int found;
+};
+
+#ifdef __TURBOC__
+ #pragma argsused
+#endif
+static int lookup_proc(struct ocfs2_dir_entry *dirent,
+ int offset,
+ int blocksize,
+ char *buf,
+ void *priv_data)
+{
+ struct lookup_struct *ls = (struct lookup_struct *) priv_data;
+
+ if (ls->len != (dirent->name_len & 0xFF))
+ return 0;
+ if (strncmp(ls->name, dirent->name, (dirent->name_len & 0xFF)))
+ return 0;
+ *ls->inode = dirent->inode;
+ ls->found++;
+ return OCFS2_DIRENT_ABORT;
+}
+
+
+errcode_t ocfs2_lookup(ocfs2_filesys *fs, uint64_t dir,
+ const char *name, int namelen, char *buf,
+ uint64_t *inode)
+{
+ errcode_t retval;
+ struct lookup_struct ls;
+
+ ls.name = name;
+ ls.len = namelen;
+ ls.inode = inode;
+ ls.found = 0;
+
+ retval = ocfs2_dir_iterate(fs, dir, 0, buf, lookup_proc, &ls);
+ if (retval)
+ return retval;
+
+ return (ls.found) ? 0 : OCFS2_ET_FILE_NOT_FOUND;
+}
+
+
+
+#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: lookup [-i <start_blkno>] <filename> <path_to_find>\n");
+}
+
+
+extern int opterr, optind;
+extern char *optarg;
+
+int main(int argc, char *argv[])
+{
+ errcode_t ret;
+ uint64_t blkno, result_blkno;
+ int c, indent;
+ char *filename, *lookup_path, *buf;
+ char *p;
+ char lookup_name[256];
+ ocfs2_filesys *fs;
+
+ blkno = 0;
+
+ 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];
+ optind++;
+
+ if (optind >= argc) {
+ fprintf(stdout, "Missing path to lookup\n");
+ print_usage();
+ return 1;
+ }
+ lookup_path = 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;
+ }
+
+ if (!blkno)
+ blkno = OCFS2_RAW_SB(fs->fs_super)->s_root_blkno;
+
+ for (p = lookup_path; *p == '/'; p++);
+
+ lookup_path = p;
+
+ fprintf(stdout, "/ (%llu)\n", blkno);
+
+ indent = 0;
+ for (p = lookup_path; ; p++) {
+ if (*p && *p != '/')
+ continue;
+
+ memcpy(lookup_name, lookup_path, p - lookup_path);
+ lookup_name[p - lookup_path] = '\0';
+ ret = ocfs2_lookup(fs, blkno, lookup_name,
+ strlen(lookup_name), NULL,
+ &result_blkno);
+ if (ret) {
+ com_err(argv[0], ret,
+ "while looking up \"%s\" in inode %llu on \"%s\"\n",
+ lookup_name, blkno, filename);
+ goto out_free;
+ }
+
+ indent += 4;
+ for (c = 0; c < indent; c++)
+ fprintf(stdout, " ");
+ fprintf(stdout, "%s (%llu)\n", lookup_name,
+ result_blkno);
+
+ blkno = result_blkno;
+
+ for (; *p == '/'; p++);
+
+ lookup_path = p;
+
+ if (!*p)
+ break;
+ }
+
+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/ocfs2_err.et.in
===================================================================
--- trunk/ocfs2/libocfs2/ocfs2_err.et.in 2004-07-03 00:20:04 UTC (rev 136)
+++ trunk/ocfs2/libocfs2/ocfs2_err.et.in 2004-07-03 01:00:49 UTC (rev 137)
@@ -74,4 +74,7 @@
ec OCFS2_ET_NO_DIRECTORY,
"OCFS2 inode is not a directory"
+ec OCFS2_ET_FILE_NOT_FOUND,
+ "File not found by ocfs2_lookup"
+
end
More information about the Ocfs-tools-commits
mailing list