[Ocfs2-tools-commits] smushran commits r1124 - in
branches/ocfs2-tools-1.0/debugfs.ocfs2: . include
svn-commits at oss.oracle.com
svn-commits at oss.oracle.com
Tue Nov 8 20:34:23 CST 2005
Author: smushran
Signed-off-by: mfasheh
Date: 2005-11-08 20:34:21 -0600 (Tue, 08 Nov 2005)
New Revision: 1124
Added:
branches/ocfs2-tools-1.0/debugfs.ocfs2/find_inode_paths.c
branches/ocfs2-tools-1.0/debugfs.ocfs2/include/find_inode_paths.h
Modified:
branches/ocfs2-tools-1.0/debugfs.ocfs2/Makefile
branches/ocfs2-tools-1.0/debugfs.ocfs2/commands.c
branches/ocfs2-tools-1.0/debugfs.ocfs2/dump.c
branches/ocfs2-tools-1.0/debugfs.ocfs2/include/dump.h
branches/ocfs2-tools-1.0/debugfs.ocfs2/include/main.h
Log:
find_inode_paths added to debugfs as locate
Signed-Off-by: mfasheh
Modified: branches/ocfs2-tools-1.0/debugfs.ocfs2/Makefile
===================================================================
--- branches/ocfs2-tools-1.0/debugfs.ocfs2/Makefile 2005-11-09 02:33:15 UTC (rev 1123)
+++ branches/ocfs2-tools-1.0/debugfs.ocfs2/Makefile 2005-11-09 02:34:21 UTC (rev 1124)
@@ -17,7 +17,7 @@
CFLAGS = -Wall -O2
endif
-CFILES = main.c commands.c dump.c utils.c journal.c
+CFILES = main.c commands.c dump.c utils.c journal.c find_inode_paths.c
HFILES = \
include/main.h \
Modified: branches/ocfs2-tools-1.0/debugfs.ocfs2/commands.c
===================================================================
--- branches/ocfs2-tools-1.0/debugfs.ocfs2/commands.c 2005-11-09 02:33:15 UTC (rev 1123)
+++ branches/ocfs2-tools-1.0/debugfs.ocfs2/commands.c 2005-11-09 02:34:21 UTC (rev 1124)
@@ -60,6 +60,7 @@
static void do_chroot (char **args);
static void do_slotmap (char **args);
static void do_encode_lockres (char **args);
+static void do_locate (char **args);
dbgfs_gbls gbls;
@@ -75,6 +76,7 @@
{ "help", do_help },
{ "?", do_help },
{ "lcd", do_lcd },
+ { "locate", do_locate },
{ "logdump", do_logdump },
{ "ls", do_ls },
{ "open", do_open },
@@ -585,6 +587,7 @@
printf ("group <block#>\t\t\t\tShow chain group\n");
printf ("help, ?\t\t\t\t\tThis information\n");
printf ("lcd <directory>\t\t\t\tChange directory on a mounted flesystem\n");
+ printf ("locate <filespec>\t\t\tList all paths to the inode\n");
printf ("logdump <slot#>\t\t\t\tPrints journal file for the node slot\n");
printf ("ls [-l] <filespec>\t\t\tList directory\n");
printf ("open <device>\t\t\t\tOpen a device\n");
@@ -1120,3 +1123,17 @@
return ;
}
+
+/*
+ * do_locate()
+ *
+ */
+static void do_locate(char **args)
+{
+ uint64_t blkno;
+
+ if (process_inode_args(args, &blkno))
+ return ;
+
+ find_inode_paths(gbls.fs, args, blkno, stdout);
+}
Modified: branches/ocfs2-tools-1.0/debugfs.ocfs2/dump.c
===================================================================
--- branches/ocfs2-tools-1.0/debugfs.ocfs2/dump.c 2005-11-09 02:33:15 UTC (rev 1123)
+++ branches/ocfs2-tools-1.0/debugfs.ocfs2/dump.c 2005-11-09 02:34:21 UTC (rev 1124)
@@ -568,3 +568,8 @@
return ;
}
+
+void dump_inode_path (FILE *out, uint64_t blkno, char *path)
+{
+ fprintf (out, "\t%"PRIu64"\t%s\n", blkno, path);
+}
Added: branches/ocfs2-tools-1.0/debugfs.ocfs2/find_inode_paths.c
===================================================================
--- branches/ocfs2-tools-1.0/debugfs.ocfs2/find_inode_paths.c 2005-11-09 02:33:15 UTC (rev 1123)
+++ branches/ocfs2-tools-1.0/debugfs.ocfs2/find_inode_paths.c 2005-11-09 02:34:21 UTC (rev 1124)
@@ -0,0 +1,133 @@
+/* -*- mode: c; c-basic-offset: 8; -*-
+ * vim: noexpandtab sw=8 ts=8 sts=0:
+ *
+ * find_inode_paths.c
+ *
+ * Takes an inode block number and find all paths leading to it.
+ *
+ * Copyright (C) 2004, 2005 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.
+ *
+ * This code is a port of e2fsprogs/lib/ext2fs/dir_iterate.c
+ * Copyright (C) 1993, 1994, 1994, 1995, 1996, 1997 Theodore Ts'o.
+ */
+
+#include <main.h>
+
+struct walk_path {
+ char *argv0;
+ FILE *out;
+ ocfs2_filesys *fs;
+ char *path;
+ int found;
+ uint64_t inode;
+};
+
+static int walk_tree_func(struct ocfs2_dir_entry *dentry, int offset,
+ int blocksize, char *buf, void *priv_data)
+{
+ errcode_t ret;
+ int len, oldval;
+ int reti = 0;
+ char *old_path, *path;
+ struct walk_path *wp = priv_data;
+
+ if (!strncmp(dentry->name, ".", dentry->name_len) ||
+ !strncmp(dentry->name, "..", dentry->name_len))
+ return 0;
+
+ len = strlen(wp->path);
+
+ if (len + dentry->name_len > 4095) {
+ com_err(wp->argv0, OCFS2_ET_NO_SPACE,
+ "name is too long in %s\n", wp->path);
+ return OCFS2_DIRENT_ABORT;
+ }
+
+ ret = ocfs2_malloc0(4096, &path);
+ if (ret) {
+ com_err(wp->argv0, ret,
+ "while allocating path memory in %s\n", wp->path);
+ return OCFS2_DIRENT_ABORT;
+ }
+
+ memcpy(path, wp->path, len);
+ memcpy(path + len, dentry->name, dentry->name_len);
+ if (dentry->file_type == OCFS2_FT_DIR)
+ path[len + dentry->name_len] = '/';
+
+ oldval = 0;
+
+ if (dentry->inode == wp->inode) {
+ dump_inode_path (wp->out, dentry->inode, path);
+ ++wp->found;
+ }
+
+ if (dentry->file_type == OCFS2_FT_DIR) {
+ old_path = wp->path;
+ wp->path = path;
+ ret = ocfs2_dir_iterate(wp->fs, dentry->inode, 0, NULL,
+ walk_tree_func, wp);
+ if (ret) {
+ com_err(wp->argv0, ret, "while walking %s", wp->path);
+ reti = OCFS2_DIRENT_ABORT;
+ }
+ wp->path = old_path;
+ }
+
+ ocfs2_free(&path);
+
+ return reti;
+}
+
+errcode_t find_inode_paths(ocfs2_filesys *fs, char **args, uint64_t blkno,
+ FILE *out)
+{
+ errcode_t ret = 0;
+ struct walk_path wp;
+
+ wp.argv0 = args[0];
+ wp.out = out;
+ wp.found = 0;
+ wp.inode = blkno;
+ wp.fs = fs;
+
+ /* Walk system dir */
+ wp.path = "//";
+ ret = ocfs2_dir_iterate(fs,
+ OCFS2_RAW_SB(fs->fs_super)->s_system_dir_blkno,
+ 0, NULL, walk_tree_func, &wp);
+ if (ret) {
+ com_err(args[0], ret, "while walking system dir");
+ goto bail;
+ }
+
+ /* Walk root dir */
+ wp.path = "/";
+ ret = ocfs2_dir_iterate(fs,
+ OCFS2_RAW_SB(fs->fs_super)->s_root_blkno,
+ 0, NULL, walk_tree_func, &wp);
+ if (ret) {
+ com_err(args[0], ret, "while walking root dir");
+ goto bail;
+ }
+
+ if (!wp.found)
+ com_err(args[0], OCFS2_ET_FILE_NOT_FOUND, " ");
+
+bail:
+ return ret;
+}
Modified: branches/ocfs2-tools-1.0/debugfs.ocfs2/include/dump.h
===================================================================
--- branches/ocfs2-tools-1.0/debugfs.ocfs2/include/dump.h 2005-11-09 02:33:15 UTC (rev 1123)
+++ branches/ocfs2-tools-1.0/debugfs.ocfs2/include/dump.h 2005-11-09 02:34:21 UTC (rev 1124)
@@ -50,5 +50,6 @@
void dump_jbd_unknown (FILE *out, uint64_t start, uint64_t end);
void dump_slots (FILE *out, char *buf, uint32_t len);
void dump_fast_symlink (FILE *out, char *link);
+void dump_inode_path (FILE *out, uint64_t blkno, char *path);
#endif /* __DUMP_H__ */
Added: branches/ocfs2-tools-1.0/debugfs.ocfs2/include/find_inode_paths.h
===================================================================
--- branches/ocfs2-tools-1.0/debugfs.ocfs2/include/find_inode_paths.h 2005-11-09 02:33:15 UTC (rev 1123)
+++ branches/ocfs2-tools-1.0/debugfs.ocfs2/include/find_inode_paths.h 2005-11-09 02:34:21 UTC (rev 1124)
@@ -0,0 +1,31 @@
+/*
+ * find_inode_path.h
+ *
+ * Function prototypes, macros, etc. for related 'C' files
+ *
+ * Copyright (C) 2005 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 as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * 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.
+ *
+ */
+
+#ifndef _FIND_INODE_PATH_H_
+#define _FIND_INODE_PATH_H_
+
+errcode_t find_inode_paths(ocfs2_filesys *fs, char **args, uint64_t blkno,
+ FILE *out);
+
+#endif /* _FIND_INODE_PATH_H_ */
Modified: branches/ocfs2-tools-1.0/debugfs.ocfs2/include/main.h
===================================================================
--- branches/ocfs2-tools-1.0/debugfs.ocfs2/include/main.h 2005-11-09 02:33:15 UTC (rev 1123)
+++ branches/ocfs2-tools-1.0/debugfs.ocfs2/include/main.h 2005-11-09 02:34:21 UTC (rev 1124)
@@ -156,6 +156,7 @@
#include <kernel-list.h>
#include <utils.h>
#include <journal.h>
+#include <find_inode_paths.h>
#include <dump.h>
#endif /* __MAIN_H__ */
More information about the Ocfs2-tools-commits
mailing list