[Ocfs-tools-commits]
smushran commits r97 - in trunk/ocfs2/debugfs.ocfs2: . include
svn-commits at oss.oracle.com
svn-commits at oss.oracle.com
Thu Jun 24 20:06:23 CDT 2004
Author: smushran
Date: 2004-06-24 19:06:21 -0500 (Thu, 24 Jun 2004)
New Revision: 97
Added:
trunk/ocfs2/debugfs.ocfs2/include/utils.h
trunk/ocfs2/debugfs.ocfs2/utils.c
Modified:
trunk/ocfs2/debugfs.ocfs2/
trunk/ocfs2/debugfs.ocfs2/Makefile
trunk/ocfs2/debugfs.ocfs2/commands.c
trunk/ocfs2/debugfs.ocfs2/dump.c
trunk/ocfs2/debugfs.ocfs2/include/commands.h
trunk/ocfs2/debugfs.ocfs2/include/dump.h
trunk/ocfs2/debugfs.ocfs2/include/main.h
trunk/ocfs2/debugfs.ocfs2/include/readfs.h
trunk/ocfs2/debugfs.ocfs2/main.c
trunk/ocfs2/debugfs.ocfs2/readfs.c
Log:
stat [blknum] and ls [blknum] working
Property changes on: trunk/ocfs2/debugfs.ocfs2
___________________________________________________________________
Name: svn:ignore
- cscope.out
debugfs.ocfs
cscope.files
+ cscope.out
debugfs.ocfs2
cscope.files
Modified: trunk/ocfs2/debugfs.ocfs2/Makefile
===================================================================
--- trunk/ocfs2/debugfs.ocfs2/Makefile 2004-06-23 02:28:23 UTC (rev 96)
+++ trunk/ocfs2/debugfs.ocfs2/Makefile 2004-06-25 00:06:21 UTC (rev 97)
@@ -11,8 +11,8 @@
CFLAGS += -Wall -O2
-CFILES = main.c commands.c dump.c readfs.c
-HFILES = main.h commands.h dump.h readfs.h
+CFILES = main.c commands.c dump.c readfs.c utils.c
+HFILES = include/main.h include/commands.h include/dump.h include/readfs.h include/utils.h
OBJS = $(subst .c,.o,$(CFILES))
Modified: trunk/ocfs2/debugfs.ocfs2/commands.c
===================================================================
--- trunk/ocfs2/debugfs.ocfs2/commands.c 2004-06-23 02:28:23 UTC (rev 96)
+++ trunk/ocfs2/debugfs.ocfs2/commands.c 2004-06-25 00:06:21 UTC (rev 97)
@@ -1,3 +1,27 @@
+/*
+ * commands.c
+ *
+ * handles debugfs commands
+ *
+ * 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 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.
+ *
+ * Authors: Sunil Mushran, Manish Singh
+ */
#include <main.h>
#include <commands.h>
@@ -3,24 +27,6 @@
#include <dump.h>
#include <readfs.h>
+#include <utils.h>
-#if 0
-#define _GNU_SOURCE
-
-#include <string.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-
-#include <glib.h>
-
-#include <readline/readline.h>
-
-#include <linux/types.h>
-#include <ocfs2_fs.h>
-#endif
-
typedef void (*PrintFunc) (void *buf);
typedef gboolean (*WriteFunc) (char **data, void *buf);
@@ -36,7 +42,6 @@
CommandFunc func;
};
-
static Command *find_command (char *cmd);
static char **get_data (void);
@@ -58,15 +63,18 @@
static void do_super (char **args);
static void do_inode (char **args);
-
extern gboolean allow_write;
-static char *device = NULL;
-static int dev_fd = -1;
-static __u32 blksz_bits = 0;
-static char *curdir = NULL;
-static char superblk[512];
-static char rootin[512];
+char *device = NULL;
+int dev_fd = -1;
+__u32 blksz_bits = 0;
+__u32 clstrsz_bits = 0;
+__u64 root_blkno = 0;
+__u64 sysdir_blkno = 0;
+char *curdir = NULL;
+char *superblk = NULL;
+char *rootin = NULL;
+char *sysdirin = NULL;
static Command commands[] =
{
@@ -151,6 +159,8 @@
{
char *dev = args[1];
ocfs2_dinode *inode;
+ ocfs2_super_block *sb;
+ __u32 len;
if (device)
do_close (NULL);
@@ -164,18 +174,31 @@
device = g_strdup (dev);
- if (read_super_block (dev_fd, superblk, sizeof(superblk), &blksz_bits) != -1)
+ if (read_super_block (dev_fd, &superblk) != -1)
curdir = g_strdup ("/");
- /* read root inode */
inode = (ocfs2_dinode *)superblk;
- if ((pread64(dev_fd, rootin, sizeof(rootin),
- (inode->id2.i_super.s_root_blkno << blksz_bits))) == -1) {
- LOG_INTERNAL("%s", strerror(errno));
- goto bail;
- }
+ sb = &(inode->id2.i_super);
+ /* set globals */
+ clstrsz_bits = sb->s_clustersize_bits;
+ blksz_bits = sb->s_blocksize_bits;
+ root_blkno = sb->s_root_blkno;
+ sysdir_blkno = sb->s_system_dir_blkno;
-bail:
+ /* read root inode */
+ len = 1 << blksz_bits;
+ if (!(rootin = malloc(len)))
+ DBGFS_FATAL("%s", strerror(errno));
+ if ((pread64(dev_fd, rootin, len, (root_blkno << blksz_bits))) == -1)
+ DBGFS_FATAL("%s", strerror(errno));
+
+ /* read sysdir inode */
+ len = 1 << blksz_bits;
+ if (!(sysdirin = malloc(len)))
+ DBGFS_FATAL("%s", strerror(errno));
+ if ((pread64(dev_fd, sysdirin, len, (sysdir_blkno << blksz_bits))) == -1)
+ DBGFS_FATAL("%s", strerror(errno));
+
return ;
} /* do_open */
@@ -194,8 +217,9 @@
g_free (curdir);
curdir = NULL;
- memset (superblk, 0, sizeof(superblk));
- memset (rootin, 0, sizeof(rootin));
+ safefree (superblk);
+ safefree (rootin);
+ safefree (sysdirin);
} else
printf ("device not open\n");
@@ -208,23 +232,7 @@
*/
static void do_cd (char **args)
{
-#if 0
- char *newdir, *dir = args[1];
- if (!dir)
- {
- printf ("No directory given\n");
- return;
- }
-
- if (dir[0] == '/')
- newdir = g_strdup (dir);
- else
- newdir = g_strconcat (curdir, "/", dir, NULL);
-
- g_free (curdir);
- curdir = newdir;
-#endif
} /* do_cd */
/*
@@ -233,27 +241,60 @@
*/
static void do_ls (char **args)
{
-#if 0
- ocfs_super *vcb;
- __u64 off;
+ char *opts = args[1];
+ ocfs2_dinode *inode;
+ ocfs2_extent_rec *rec;
+ __u32 blknum;
+ char *buf = NULL;
+ int i;
+ GArray *arr = NULL;
+ __u32 len;
+ __u64 off;
- if (strcmp (curdir, "/") != 0)
- {
- vcb = get_fake_vcb (dev_fd, header, 0);
- find_file_entry(vcb, header->root_off, "/", curdir, FIND_MODE_DIR, &off);
- free (vcb);
- }
- else
- off = header->root_off;
+ len = 1 << blksz_bits;
+ if (!(buf = malloc(len)))
+ DBGFS_FATAL("%s", strerror(errno));
- if (off <= 0)
- {
- printf ("Invalid directory %s\n", curdir);
- return;
- }
+ if (opts) {
+ blknum = atoi(opts);
+ if ((read_inode (dev_fd, blknum, buf, len)) == -1) {
+ printf("Not an inode\n");
+ goto bail;
+ }
+ inode = (ocfs2_dinode *)buf;
+ } else {
+ inode = (ocfs2_dinode *)rootin;
+ }
- walk_dir_nodes (dev_fd, off, curdir, NULL);
-#endif
+ if (!S_ISDIR(inode->i_mode)) {
+ printf("Not a dir\n");
+ goto bail;
+ }
+
+ arr = g_array_new(0, 1, sizeof(ocfs2_extent_rec));
+
+ traverse_extents (dev_fd, &(inode->id2.i_list), arr, 0);
+
+ safefree (buf);
+
+ for (i = 0; i < arr->len; ++i) {
+ rec = &(g_array_index(arr, ocfs2_extent_rec, i));
+ off = rec->e_blkno << blksz_bits;
+ len = rec->e_clusters << clstrsz_bits;
+ if (!(buf = malloc (len)))
+ DBGFS_FATAL("%s", strerror(errno));
+ if ((pread64(dev_fd, buf, len, off)) == -1)
+ DBGFS_FATAL("%s", strerror(errno));
+ dump_dir_entry ((struct ocfs2_dir_entry *)buf);
+ safefree (buf);
+ }
+
+bail:
+ safefree (buf);
+ if (arr)
+ g_array_free (arr, 1);
+ return ;
+
} /* do_ls */
/*
@@ -262,12 +303,7 @@
*/
static void do_pwd (char **args)
{
-#if 0
- if (!curdir)
- curdir = g_strdup ("/");
-
- printf ("%s\n", curdir);
-#endif
+ printf ("%s\n", curdir ? curdir : "No dir");
} /* do_pwd */
/*
@@ -303,124 +339,7 @@
*/
static void do_read (char **args)
{
-#if 0
- PrintFunc func;
- char *type = args[1];
- loff_t offset = -1;
- void *buf;
- int nodenum = 0;
- if (!device)
- {
- printf ("Device not open\n");
- return;
- }
-
- if (!type)
- {
- printf ("No type given\n");
- return;
- }
-
- if (strcasecmp (type, "dir_node") == 0 ||
- strcasecmp (type, "ocfs_dir_node") == 0)
- {
- char *dirarg = args[2];
-
- func = print_dir_node;
-
- if (dirarg && *dirarg)
- {
- if (dirarg[0] == '/')
- {
- if (strcmp (dirarg, "/") == 0)
- {
- printf ("Name: /\n");
- offset = header->root_off;
- }
- }
- }
- else
- {
- printf ("No name or offset\n");
- return;
- }
- }
- else if (strcasecmp (type, "file_entry") == 0 ||
- strcasecmp (type, "ocfs_file_entry") == 0)
- {
- func = print_file_entry;
- }
- else if (strcasecmp (type, "publish") == 0 ||
- strcasecmp (type, "ocfs_publish") == 0)
- {
- func = print_publish;
-
- if (args[2])
- {
- nodenum = strtol (args[2], NULL, 10);
- nodenum = MAX(0, nodenum);
- nodenum = MIN(31, nodenum);
- }
-
- offset = header->publ_off + nodenum * 512;
- }
- else if (strcasecmp (type, "vote") == 0 ||
- strcasecmp (type, "ocfs_vote") == 0)
- {
- func = print_vote;
-
- if (args[2])
- {
- nodenum = strtol (args[2], NULL, 10);
- nodenum = MAX(0, nodenum);
- nodenum = MIN(31, nodenum);
- }
-
- offset = header->vote_off + nodenum * 512;
- }
- else if (strcasecmp (type, "vol_disk_hdr") == 0 ||
- strcasecmp (type, "ocfs_vol_disk_hdr") == 0)
- {
- func = print_vol_disk_hdr;
- offset = 0;
- }
- else if (strcasecmp (type, "vol_label") == 0 ||
- strcasecmp (type, "ocfs_vol_label") == 0)
- {
- func = print_vol_label;
- offset = 512;
- }
- else
- {
- printf ("Invalid type\n");
- return;
- }
-
- if (offset == -1)
- {
- if (!args[2])
- {
- printf ("No offset given\n");
- return;
- }
- else
- offset = strtoll (args[2], NULL, 10);
- }
-
- printf ("Reading %s for node %d at offset %lld\n", type, nodenum, offset);
-
- buf = g_malloc (512);
-
- myseek64 (dev_fd, offset, SEEK_SET);
-
- if (read (dev_fd, buf, 512) != -1)
- func (buf);
- else
- printf ("Couldn't read\n");
-
- g_free (buf);
-#endif
} /* do_read */
/*
@@ -429,142 +348,7 @@
*/
static void do_write (char **args)
{
-#if 0
- WriteFunc func;
- char *type = args[1];
- loff_t offset = -1;
- void *buf;
- int nodenum = 0;
- char **data;
- if (!device)
- {
- printf ("Device not open\n");
- return;
- }
-
- if (!type)
- {
- printf ("No type given\n");
- return;
- }
-
- if (strcasecmp (type, "dir_node") == 0 ||
- strcasecmp (type, "ocfs_dir_node") == 0)
- {
- char *dirarg = args[2];
-
- func = write_dir_node;
-
- if (dirarg && *dirarg)
- {
- if (dirarg[0] == '/')
- {
- if (strcmp (dirarg, "/") == 0)
- {
- printf ("Name: /\n");
- offset = header->root_off;
- }
- }
- }
- else
- {
- printf ("No name or offset\n");
- return;
- }
- }
- else if (strcasecmp (type, "file_entry") == 0 ||
- strcasecmp (type, "ocfs_file_entry") == 0)
- {
- func = write_file_entry;
- }
- else if (strcasecmp (type, "publish") == 0 ||
- strcasecmp (type, "ocfs_publish") == 0)
- {
- func = write_publish;
-
- if (args[2])
- {
- nodenum = strtol (args[2], NULL, 10);
- nodenum = MAX(0, nodenum);
- nodenum = MIN(31, nodenum);
- }
-
- offset = header->publ_off + nodenum * 512;
- }
- else if (strcasecmp (type, "vote") == 0 ||
- strcasecmp (type, "ocfs_vote") == 0)
- {
- func = write_vote;
-
- if (args[2])
- {
- nodenum = strtol (args[2], NULL, 10);
- nodenum = MAX(0, nodenum);
- nodenum = MIN(31, nodenum);
- }
-
- offset = header->vote_off + nodenum * 512;
- }
- else if (strcasecmp (type, "vol_disk_hdr") == 0 ||
- strcasecmp (type, "ocfs_vol_disk_hdr") == 0)
- {
- func = write_vol_disk_hdr;
- offset = 0;
- }
- else if (strcasecmp (type, "vol_label") == 0 ||
- strcasecmp (type, "ocfs_vol_label") == 0)
- {
- func = write_vol_label;
- offset = 512;
- }
- else
- {
- printf ("Invalid type\n");
- return;
- }
-
- if (offset == -1)
- {
- if (!args[2])
- {
- printf ("No offset given\n");
- return;
- }
- else
- offset = strtoll (args[2], NULL, 10);
- }
-
- printf ("Writing %s for node %d at offset %lld\n", type, nodenum, offset);
-
- data = get_data ();
-
- myseek64 (dev_fd, offset, SEEK_SET);
-
- buf = g_malloc (512);
-
- if (read (dev_fd, buf, 512) != -1)
- {
- if (!func (data, buf))
- {
- printf ("Invalid data\n");
- return;
- }
- }
- else
- {
- printf ("Couldn't read\n");
- return;
- }
-
- myseek64 (dev_fd, offset, SEEK_SET);
-
- if (write (dev_fd, buf, 512) == -1)
- printf ("Write failed\n");
-
- g_strfreev (data);
- g_free (buf);
-#endif
} /* do_write */
/*
@@ -573,21 +357,23 @@
*/
static void do_help (char **args)
{
- printf ("curdev\t\t\tShow current device\n");
- printf ("open\t\t\tOpen a device\n");
- printf ("close\t\t\tClose a device\n");
- printf ("cd\t\t\tChange working directory\n");
- printf ("pwd\t\t\tPrint working directory\n");
- printf ("ls\t\t\tList directory\n");
- printf ("rm\t\t\tRemove a file\n");
- printf ("mkdir\t\t\tMake a directory\n");
- printf ("rmdir\t\t\tRemove a directory\n");
- printf ("dump, cat\t\tDump contents of a file\n");
- printf ("lcd\t\t\tChange current local working directory\n");
- printf ("read\t\t\tRead a low level structure\n");
- printf ("write\t\t\tWrite a low level structure\n");
- printf ("help, ?\t\t\tThis information\n");
- printf ("quit, q\t\t\tExit the program\n");
+ printf ("curdev\t\t\t\tShow current device\n");
+ printf ("open [device]\t\t\tOpen a device\n");
+ printf ("close\t\t\t\tClose a device\n");
+ printf ("show_super_stats, stats [-h]\tShow superblock\n");
+ printf ("show_inode_info, stat [blknum]\tShow inode\n");
+// printf ("cd\t\t\tChange working directory\n");
+ printf ("pwd\t\t\t\tPrint working directory\n");
+ printf ("ls [blknum]\t\t\tList directory\n");
+// printf ("rm\t\t\t\tRemove a file\n");
+// printf ("mkdir\t\t\t\tMake a directory\n");
+// printf ("rmdir\t\t\t\tRemove a directory\n");
+// printf ("dump, cat\t\t\tDump contents of a file\n");
+// printf ("lcd\t\t\t\tChange current local working directory\n");
+// printf ("read\t\t\t\tRead a low level structure\n");
+// printf ("write\t\t\t\tWrite a low level structure\n");
+ printf ("help, ?\t\t\t\tThis information\n");
+ printf ("quit, q\t\t\t\tExit the program\n");
} /* do_help */
/*
@@ -605,31 +391,7 @@
*/
static void do_dump (char **args)
{
-#if 0
- char *fname = args[1], *filename, *out = args[2];
- ocfs_super *vcb;
- if (!fname)
- {
- printf ("No filename given\n");
- return;
- }
-
- if (!out)
- {
- printf ("No output given\n");
- return;
- }
-
- if (fname[0] == '/')
- filename = g_strdup (fname);
- else
- filename = g_strconcat (curdir, "/", fname, NULL);
-
- vcb = get_fake_vcb (dev_fd, header, 0);
- suck_file (vcb, filename, out);
- g_free (filename);
-#endif
} /* do_dump */
/*
@@ -638,18 +400,7 @@
*/
static void do_lcd (char **args)
{
-#if 0
- char *dir = args[1];
- if (!dir)
- {
- printf ("Directory not given\n");
- return;
- }
-
- if (chdir (dir) == -1)
- printf ("Could not change directory\n");
-#endif
} /* do_lcd */
/*
@@ -667,32 +418,7 @@
*/
static char ** get_data (void)
{
-#if 0
- char *line, **ret;
- GPtrArray *arr;
-
- arr = g_ptr_array_new ();
-
- while (1)
- {
- line = readline ("");
-
- if (line && strchr (line, '='))
- g_ptr_array_add (arr, line);
- else
- break;
- }
-
- if (line)
- free (line);
-
- ret = (char **) arr->pdata;
-
- g_ptr_array_free (arr, FALSE);
-
- return ret;
-#endif
- return NULL;
+ return NULL;
} /* get_data */
/*
@@ -723,10 +449,30 @@
{
char *opts = args[1];
ocfs2_dinode *inode;
+ __u32 blknum;
+ char *buf = NULL;
+ __u32 buflen;
- inode = (ocfs2_dinode *)rootin;
+ buflen = 1 << blksz_bits;
+ if (!(buf = malloc(buflen)))
+ DBGFS_FATAL("%s", strerror(errno));
+
+ if (opts) {
+ blknum = atoi(opts);
+ if ((read_inode (dev_fd, blknum, buf, buflen)) == -1) {
+ printf("Not an inode\n");
+ goto bail;
+ }
+ inode = (ocfs2_dinode *)buf;
+ } else {
+ inode = (ocfs2_dinode *)rootin;
+ }
+
dump_inode(inode);
+ traverse_extents (dev_fd, &(inode->id2.i_list), NULL, 1);
+
+bail:
+ safefree (buf);
return ;
} /* do_inode */
-
Modified: trunk/ocfs2/debugfs.ocfs2/dump.c
===================================================================
--- trunk/ocfs2/debugfs.ocfs2/dump.c 2004-06-23 02:28:23 UTC (rev 96)
+++ trunk/ocfs2/debugfs.ocfs2/dump.c 2004-06-25 00:06:21 UTC (rev 97)
@@ -1,3 +1,27 @@
+/*
+ * dump.c
+ *
+ * dumps ocfs2 structures
+ *
+ * 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 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.
+ *
+ * Authors: Sunil Mushran
+ */
#include <main.h>
#include <commands.h>
@@ -3,4 +27,5 @@
#include <dump.h>
#include <readfs.h>
+#include <utils.h>
/*
@@ -55,6 +80,7 @@
ocfs2_disk_lock *dl;
int i;
__u16 mode;
+ GString *flags = NULL;
/*
Inode: 32001 Type: directory Mode: 0755 Flags: 0x0 Generation: 721849
@@ -101,9 +127,31 @@
mode = in->i_mode & (S_IRWXU | S_IRWXG | S_IRWXO);
- printf("Inode: %llu Type: %s Mode: 0%0u Flags: 0x%x Generation: %u\n",
- in->i_blkno, str, mode, in->i_flags, in->i_generation);
+ flags = g_string_new(NULL);
+ if (in->i_flags & OCFS2_VALID_FL)
+ g_string_append (flags, "valid ");
+ if (in->i_flags & OCFS2_UNUSED2_FL)
+ g_string_append (flags, "unused2 ");
+ if (in->i_flags & OCFS2_ORPHANED_FL)
+ g_string_append (flags, "orphan ");
+ if (in->i_flags & OCFS2_UNUSED3_FL)
+ g_string_append (flags, "unused3 ");
+ if (in->i_flags & OCFS2_SYSTEM_FL)
+ g_string_append (flags, "system ");
+ if (in->i_flags & OCFS2_SUPER_BLOCK_FL)
+ g_string_append (flags, "superblock ");
+ if (in->i_flags & OCFS2_LOCAL_ALLOC_FL)
+ g_string_append (flags, "localbitmap ");
+ if (in->i_flags & OCFS2_BITMAP_FL)
+ g_string_append (flags, "globalbitmap ");
+ if (in->i_flags & OCFS2_JOURNAL_FL)
+ g_string_append (flags, "journal ");
+ if (in->i_flags & OCFS2_DLM_FL)
+ g_string_append (flags, "dlm ");
+ printf("Inode: %llu Type: %s Mode: 0%0u Flags: %s Generation: %u\n",
+ in->i_blkno, str, mode, flags->str, in->i_generation);
+
pw = getpwuid(in->i_uid);
gr = getgrgid(in->i_gid);
printf("User: %d (%s) Group: %d (%s) Size: %llu\n",
@@ -134,5 +182,76 @@
printf("Sub Alloc Node: %u Sub Alloc Blknum: %llu\n",
in->i_suballoc_node, in->i_suballoc_blkno); /* ?? */
+ if (flags)
+ g_string_free (flags, 1);
return ;
} /* dump_inode */
+
+/*
+ * dump_extent_list()
+ *
+ */
+void dump_extent_list (ocfs2_extent_list *ext)
+{
+ ocfs2_extent_rec *rec;
+ int i;
+
+ printf("Tree Depth: %d Count: %u Next Free Rec: %u\n",
+ ext->l_tree_depth, ext->l_count, ext->l_next_free_rec);
+
+ if (!ext->l_next_free_rec)
+ goto bail;
+
+ printf("## File Offset Num Clusters Disk Offset\n");
+
+ for (i = 0; i < ext->l_next_free_rec; ++i) {
+ rec = &(ext->l_recs[i]);
+ printf("%-2d %-11u %-12u %llu\n", i, rec->e_cpos,
+ rec->e_clusters, rec->e_blkno);
+ }
+
+bail:
+ return ;
+} /* dump_extent_list */
+
+/*
+ * dump_extent_block()
+ *
+ */
+void dump_extent_block (ocfs2_extent_block *blk)
+{
+ printf ("SubAlloc Blknum: %llu SubAlloc Node: %u\n",
+ blk->h_suballoc_blkno, blk->h_suballoc_node);
+
+ printf ("Blknum: %llu Parent: %llu Next Leaf: %llu\n",
+ blk->h_blkno, blk->h_parent_blk, blk->h_next_leaf_blk);
+
+ return ;
+} /* dump_extent_block */
+
+/*
+ * dump_dir_entry()
+ *
+ */
+void dump_dir_entry (struct ocfs2_dir_entry *dir)
+{
+ char *p;
+ struct ocfs2_dir_entry *rec;
+
+ p = (char *)dir;
+
+ printf("%-15s %-6s %-7s %-4s %-4s\n",
+ "Inode", "Reclen", "Namelen", "Type", "Name");
+
+ while (1) {
+ rec = (struct ocfs2_dir_entry *)p;
+ if (!rec->inode)
+ break;
+ printf("%-15llu %-6u %-7u %-4u %*s\n", rec->inode,
+ rec->rec_len, rec->name_len, rec->file_type,
+ rec->name_len, rec->name);
+ p += rec->rec_len;
+ }
+
+ return ;
+} /* dump_dir_entry */
Modified: trunk/ocfs2/debugfs.ocfs2/include/commands.h
===================================================================
--- trunk/ocfs2/debugfs.ocfs2/include/commands.h 2004-06-23 02:28:23 UTC (rev 96)
+++ trunk/ocfs2/debugfs.ocfs2/include/commands.h 2004-06-25 00:06:21 UTC (rev 97)
@@ -1,3 +1,28 @@
+/*
+ * commands.h
+ *
+ * Function prototypes, macros, etc. for related 'C' files
+ *
+ * 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 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.
+ *
+ * Authors: Sunil Mushran
+ */
+
#ifndef __COMMANDS_H__
#define __COMMANDS_H__
Modified: trunk/ocfs2/debugfs.ocfs2/include/dump.h
===================================================================
--- trunk/ocfs2/debugfs.ocfs2/include/dump.h 2004-06-23 02:28:23 UTC (rev 96)
+++ trunk/ocfs2/debugfs.ocfs2/include/dump.h 2004-06-25 00:06:21 UTC (rev 97)
@@ -1,9 +1,35 @@
+/*
+ * dump.h
+ *
+ * Function prototypes, macros, etc. for related 'C' files
+ *
+ * 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 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.
+ *
+ * Authors: Sunil Mushran
+ */
-
#ifndef __DUMP_H__
#define __DUMP_H__
void dump_super_block (ocfs2_super_block *sb);
void dump_inode (ocfs2_dinode *in);
+void dump_extent_list (ocfs2_extent_list *ext);
+void dump_extent_block (ocfs2_extent_block *blk);
+void dump_dir_entry (struct ocfs2_dir_entry *dir);
#endif /* __DUMP_H__ */
Modified: trunk/ocfs2/debugfs.ocfs2/include/main.h
===================================================================
--- trunk/ocfs2/debugfs.ocfs2/include/main.h 2004-06-23 02:28:23 UTC (rev 96)
+++ trunk/ocfs2/debugfs.ocfs2/include/main.h 2004-06-25 00:06:21 UTC (rev 97)
@@ -1,3 +1,27 @@
+/*
+ * main.h
+ *
+ * Function prototypes, macros, etc. for related 'C' files
+ *
+ * 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 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.
+ *
+ * Authors: Sunil Mushran
+ */
#ifndef __MAIN_H__
#define __MAIN_H__
@@ -26,12 +50,18 @@
#include <ocfs2_fs.h>
#include <ocfs1_fs_compat.h>
-#define LOG_INTERNAL(fmt, arg...) \
- do { \
- fprintf(stdout, "INTERNAL ERROR: "); \
- fprintf(stdout, fmt, ## arg); \
- fprintf(stdout, ", %s, %d\n", __FILE__, __LINE__); \
- fflush(stdout); \
- } while (0)
+#define safefree(_p) do {if (_p) { free(_p); (_p) = NULL; } } while (0)
+#define DBGFS_FATAL(fmt, arg...) ({ fprintf(stderr, "ERROR at %s, %d: " fmt ". EXITING!!!\n", \
+ __FILE__, __LINE__, ##arg); \
+ exit(1); \
+ })
+
+#define DBGFS_FATAL_STR(str) DBGFS_FATAL(str, "")
+
+#define DBGFS_WARN(fmt, arg...) fprintf(stderr, "WARNING at %s, %d: " fmt ".\n", \
+ __FILE__, __LINE__, ##arg)
+
+#define DBGFS_WARN_STR(str) DBGFS_WARN(str, "")
+
#endif /* __MAIN_H__ */
Modified: trunk/ocfs2/debugfs.ocfs2/include/readfs.h
===================================================================
--- trunk/ocfs2/debugfs.ocfs2/include/readfs.h 2004-06-23 02:28:23 UTC (rev 96)
+++ trunk/ocfs2/debugfs.ocfs2/include/readfs.h 2004-06-25 00:06:21 UTC (rev 97)
@@ -1,3 +1,27 @@
+/*
+ * readfs.h
+ *
+ * Function prototypes, macros, etc. for related 'C' files
+ *
+ * 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 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.
+ *
+ * Authors: Sunil Mushran
+ */
#ifndef __READFS_H__
#define __READFS_H__
@@ -2,3 +26,5 @@
-int read_super_block(int fd, char *buf, int len, __u32 *bits);
+int read_super_block (int fd, char **buf);
+int read_inode (int fd, __u32 blknum, char *buf, int buflen);
+int traverse_extents (int fd, ocfs2_extent_list *ext, GArray *arr, int dump);
Added: trunk/ocfs2/debugfs.ocfs2/include/utils.h
===================================================================
--- trunk/ocfs2/debugfs.ocfs2/include/utils.h 2004-06-23 02:28:23 UTC (rev 96)
+++ trunk/ocfs2/debugfs.ocfs2/include/utils.h 2004-06-25 00:06:21 UTC (rev 97)
@@ -0,0 +1,31 @@
+/*
+ * utils.h
+ *
+ * Function prototypes, macros, etc. for related 'C' files
+ *
+ * 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 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.
+ *
+ * Authors: Sunil Mushran
+ */
+
+#ifndef __UTILS_H__
+#define __UTILS_H__
+
+void add_extent_rec (GArray *arr, ocfs2_extent_rec *rec);
+
+#endif /* __UTILS_H__ */
Modified: trunk/ocfs2/debugfs.ocfs2/main.c
===================================================================
--- trunk/ocfs2/debugfs.ocfs2/main.c 2004-06-23 02:28:23 UTC (rev 96)
+++ trunk/ocfs2/debugfs.ocfs2/main.c 2004-06-25 00:06:21 UTC (rev 97)
@@ -1,3 +1,27 @@
+/*
+ * main.c
+ *
+ * entry point for debugfs.ocfs2
+ *
+ * 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 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.
+ *
+ * Authors: Sunil Mushran, Manish Singh
+ */
#include <main.h>
#include <commands.h>
@@ -3,18 +27,6 @@
#include <dump.h>
#include <readfs.h>
+#include <utils.h>
-#if 0
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-
-#include <glib.h>
-
-#include <readline/readline.h>
-#include <readline/history.h>
-
-#include "inc/commands.h"
-#endif
-
#define PROMPT "debugfs: "
Modified: trunk/ocfs2/debugfs.ocfs2/readfs.c
===================================================================
--- trunk/ocfs2/debugfs.ocfs2/readfs.c 2004-06-23 02:28:23 UTC (rev 96)
+++ trunk/ocfs2/debugfs.ocfs2/readfs.c 2004-06-25 00:06:21 UTC (rev 97)
@@ -1,3 +1,27 @@
+/*
+ * readfs.c
+ *
+ * reads ocfs2 structures
+ *
+ * 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 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.
+ *
+ * Authors: Sunil Mushran
+ */
#include <main.h>
#include <commands.h>
@@ -3,25 +27,34 @@
#include <dump.h>
#include <readfs.h>
+#include <utils.h>
+extern __u32 blksz_bits;
+extern __u32 clstrsz_bits;
+
/*
* read_super_block()
*
*/
-int read_super_block(int fd, char *buf, int buflen, __u32 *bits)
+int read_super_block (int fd, char **buf)
{
int ret = -1;
__u64 off;
ocfs1_vol_disk_hdr *hdr;
ocfs2_dinode *di;
+ __u32 bits = 9;
+ __u32 buflen;
- if ((ret = pread64(fd, buf, buflen, 0)) == -1) {
- LOG_INTERNAL("%s", strerror(errno));
- goto bail;
- }
+ buflen = 1 << bits;
+ if (!(*buf = malloc(buflen)))
+ DBGFS_FATAL("%s", strerror(errno));
- hdr = (ocfs1_vol_disk_hdr *)buf;
+ if ((ret = pread64(fd, *buf, buflen, 0)) == -1)
+ DBGFS_FATAL("%s", strerror(errno));
+
+ hdr = (ocfs1_vol_disk_hdr *)*buf;
if (memcmp(hdr->signature, OCFS1_VOLUME_SIGNATURE,
strlen (OCFS1_VOLUME_SIGNATURE)) == 0) {
printf("OCFS1 detected. Use debugocfs.\n");
+ safefree (*buf);
goto bail;
}
@@ -32,15 +65,18 @@
* blocksizes. 4096 is the maximum blocksize because it is
* the minimum clustersize.
*/
- for (*bits = 9; *bits < 13; (*bits)++) {
- off = OCFS2_SUPER_BLOCK_BLKNO << *bits;
-
- if ((ret = pread64(fd, buf, buflen, off)) == -1) {
- LOG_INTERNAL("%s", strerror(errno));
- goto bail;
+ for (bits = 9; bits < 13; bits++) {
+ if (!*buf) {
+ buflen = 1 << bits;
+ if (!(*buf = malloc(buflen)))
+ DBGFS_FATAL("%s", strerror(errno));
}
- di = (ocfs2_dinode *) buf;
+ off = OCFS2_SUPER_BLOCK_BLKNO << bits;
+ if ((ret = pread64(fd, *buf, buflen, off)) == -1)
+ DBGFS_FATAL("%s", strerror(errno));
+
+ di = (ocfs2_dinode *) *buf;
if (memcmp(di->i_signature, OCFS2_SUPER_BLOCK_SIGNATURE,
strlen(OCFS2_SUPER_BLOCK_SIGNATURE))) {
printf("Not an OCFS2 volume.\n");
@@ -49,7 +85,75 @@
ret = 0;
break;
}
+ safefree (*buf);
}
bail:
return ret;
} /* read_super_block */
+
+/*
+ * read_inode()
+ *
+ */
+int read_inode (int fd, __u32 blknum, char *buf, int buflen)
+{
+ __u64 off;
+ ocfs2_dinode *inode;
+ int ret = 0;
+
+ off = (__u64)(blknum << blksz_bits);
+
+ if ((pread64(fd, buf, buflen, off)) == -1)
+ DBGFS_FATAL("%s", strerror(errno));
+
+ inode = (ocfs2_dinode *)buf;
+
+ if (memcmp(inode->i_signature, OCFS2_FILE_ENTRY_SIGNATURE,
+ sizeof(OCFS2_FILE_ENTRY_SIGNATURE)))
+ ret = -1;
+
+ return ret;
+} /* read_inode */
+
+/*
+ * traverse_extents()
+ *
+ */
+int traverse_extents (int fd, ocfs2_extent_list *ext, GArray *arr, int dump)
+{
+ ocfs2_extent_block *blk;
+ ocfs2_extent_rec *rec;
+ int ret = 0;
+ __u64 off;
+ char *buf = NULL;
+ __u32 buflen;
+ int i;
+
+ if (dump)
+ dump_extent_list (ext);
+
+ for (i = 0; i < ext->l_next_free_rec; ++i) {
+ rec = &(ext->l_recs[i]);
+ if (ext->l_tree_depth == -1)
+ add_extent_rec (arr, rec);
+ else {
+ buflen = 1 << blksz_bits;
+ if (!(buf = malloc(buflen)))
+ DBGFS_FATAL("%s", strerror(errno));
+
+ off = (__u64)rec->e_blkno << blksz_bits;
+ if ((pread64 (fd, buf, buflen, off)) == -1)
+ DBGFS_FATAL("%s", strerror(errno));
+
+ blk = (ocfs2_extent_block *)buf;
+
+ if (dump)
+ dump_extent_block (blk);
+
+ traverse_extents (fd, &(blk->h_list), arr, dump);
+ }
+ }
+
+ safefree (buf);
+ return ret;
+} /* traverse_extents */
Added: trunk/ocfs2/debugfs.ocfs2/utils.c
===================================================================
--- trunk/ocfs2/debugfs.ocfs2/utils.c 2004-06-23 02:28:23 UTC (rev 96)
+++ trunk/ocfs2/debugfs.ocfs2/utils.c 2004-06-25 00:06:21 UTC (rev 97)
@@ -0,0 +1,50 @@
+/*
+ * utils.c
+ *
+ * utility functions
+ *
+ * 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 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.
+ *
+ * Authors: Sunil Mushran
+ */
+
+#include <main.h>
+#include <commands.h>
+#include <dump.h>
+#include <readfs.h>
+#include <utils.h>
+
+/*
+ * add_extent_rec()
+ *
+ */
+void add_extent_rec (GArray *arr, ocfs2_extent_rec *rec)
+{
+ ocfs2_extent_rec *new;
+
+ if (!arr)
+ return ;
+
+ if (!(new = malloc(sizeof(ocfs2_extent_rec))))
+ DBGFS_FATAL();
+
+ memcpy(new, rec, sizeof(ocfs2_extent_rec));
+ g_array_append_vals(arr, new, 1);
+
+ return ;
+} /* add_extent_rec */
More information about the Ocfs-tools-commits
mailing list