[Ocfs-tools-commits] smushran commits r88 - in trunk/ocfs2: . debugocfs debugocfs/inc

svn-commits at oss.oracle.com svn-commits at oss.oracle.com
Mon Jun 21 21:42:23 CDT 2004


Author: smushran
Date: 2004-06-21 20:42:20 -0500 (Mon, 21 Jun 2004)
New Revision: 88

Added:
   trunk/ocfs2/debugocfs/
   trunk/ocfs2/debugocfs/Cscope.make
   trunk/ocfs2/debugocfs/Makefile
   trunk/ocfs2/debugocfs/README
   trunk/ocfs2/debugocfs/commands.c
   trunk/ocfs2/debugocfs/dump.c
   trunk/ocfs2/debugocfs/inc/
   trunk/ocfs2/debugocfs/inc/commands.h
   trunk/ocfs2/debugocfs/inc/dump.h
   trunk/ocfs2/debugocfs/inc/main.h
   trunk/ocfs2/debugocfs/inc/readfs.h
   trunk/ocfs2/debugocfs/main.c
   trunk/ocfs2/debugocfs/readfs.c
Log:
first drop of debugocfs

Added: trunk/ocfs2/debugocfs/Cscope.make
===================================================================
--- trunk/ocfs2/debugocfs/Cscope.make	2004-06-22 00:55:08 UTC (rev 87)
+++ trunk/ocfs2/debugocfs/Cscope.make	2004-06-22 01:42:20 UTC (rev 88)
@@ -0,0 +1,9 @@
+.PHONY: cscope
+cscope:
+	rm -f cscope.*
+	echo "-k" >> cscope.files
+	echo "-I inc" >> cscope.files
+	find . -maxdepth 2 -name '*.c' -print >>cscope.files
+	find . -maxdepth 2 -name '*.h' -print >>cscope.files
+	find /home/smushran/lkocfs/src -maxdepth 2 -name '*.h' -print >>cscope.files
+	cscope -b

Added: trunk/ocfs2/debugocfs/Makefile
===================================================================
--- trunk/ocfs2/debugocfs/Makefile	2004-06-22 00:55:08 UTC (rev 87)
+++ trunk/ocfs2/debugocfs/Makefile	2004-06-22 01:42:20 UTC (rev 88)
@@ -0,0 +1,34 @@
+TOPDIR = ../..
+
+include $(TOPDIR)/Preamble.make
+
+BIN_PROGRAMS = debugfs.ocfs
+
+DEFINES = -DLINUX -DDEBUGOCFS -DDEBUG -DDEBUGOCFS_VERSION=\"0.0.1\"
+
+#INCLUDES = -I. -I$(TOPDIR)/ocfs2/Common/inc -I$(TOPDIR)/ocfs2/Linux/inc
+INCLUDES = -Iinc -I/home/smushran/lkocfs/src
+INCLUDES += $(GLIB_CFLAGS)
+
+CFLAGS += -Wall -O2
+
+#vpath ocfsgen%.c $(TOPDIR)/ocfs2/Common
+#vpath ocfs%.c $(TOPDIR)/ocfs2/Linux
+
+CFILES = main.c commands.c dump.c readfs.c
+HFILES = main.h commands.h dump.h readfs.h
+
+OBJS = $(subst .c,.o,$(CFILES))
+
+DIST_FILES = $(CFILES) $(HFILES) README
+
+#GEN_SRC_HEADERS = $(TOPDIR)/ocfs2/Common/inc/ocfsdisk.h $(TOPDIR)/ocfs2/Common/inc/ocfsvol.h $(TOPDIR)/ocfs2/Common/inc/ocfsconst.h $(TOPDIR)/ocfs2/Common/inc/ocfstrans.h
+
+#stamp-ops: gencode.pl $(GEN_SRC_HEADERS)
+#	./gencode.pl $(GEN_SRC_HEADERS)
+#	touch stamp-ops
+
+debugfs.ocfs: $(OBJS)
+	$(LINK) $(GLIB_LIBS) -lreadline -lncurses
+
+include $(TOPDIR)/Postamble.make

Added: trunk/ocfs2/debugocfs/README
===================================================================
--- trunk/ocfs2/debugocfs/README	2004-06-22 00:55:08 UTC (rev 87)
+++ trunk/ocfs2/debugocfs/README	2004-06-22 01:42:20 UTC (rev 88)
@@ -0,0 +1,24 @@
+Commands:
+
+curdev			Show current device
+open			Open a device
+close			Close a device
+show_super_stats -h	Dumps super block
+cd			Change working directory
+pwd			Print working directory
+ls			List directory
+dump, cat		Dump contents of a file
+lcd			Change current local working directory
+read			Read a low level structure
+write			Write a low level structure
+help, ?			This information
+quit, q			Exit the program
+
+read and write take one of: dir_node, file_entry, publish, vote, vol_disk_hdr,
+or vol_label.
+
+The output of read is the format you give to write. All the fields need not
+be given.
+
+publish and vote take node numbers optionally. dir_node and file_entry work
+with either offsets or paths. 

Added: trunk/ocfs2/debugocfs/commands.c
===================================================================
--- trunk/ocfs2/debugocfs/commands.c	2004-06-22 00:55:08 UTC (rev 87)
+++ trunk/ocfs2/debugocfs/commands.c	2004-06-22 01:42:20 UTC (rev 88)
@@ -0,0 +1,697 @@
+
+#include <main.h>
+#include <commands.h>
+#include <dump.h>
+#include <readfs.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);
+
+typedef void (*CommandFunc) (char **args);
+
+typedef struct _Command Command;
+
+struct _Command
+{
+	char        *cmd;
+	CommandFunc  func;
+};
+
+
+static Command  *find_command (char  *cmd);
+static char    **get_data     (void);
+
+static void      do_open     (char **args);
+static void      do_close    (char **args);
+static void      do_cd       (char **args);
+static void      do_ls       (char **args);
+static void      do_pwd      (char **args);
+static void      do_mkdir    (char **args);
+static void      do_rmdir    (char **args);
+static void      do_rm       (char **args);
+static void      do_read     (char **args);
+static void      do_write    (char **args);
+static void      do_quit     (char **args);
+static void      do_help     (char **args);
+static void      do_dump     (char **args);
+static void      do_lcd      (char **args);
+static void      do_curdev   (char **args);
+static void      do_super    (char **args);
+
+
+extern gboolean allow_write;
+
+static char *device = NULL;
+static int   dev_fd = -1;
+static char *curdir = NULL;
+static char header[512];
+
+static Command commands[] =
+{
+  { "open",   do_open   },
+  { "close",  do_close  },
+  { "cd",     do_cd     },
+  { "ls",     do_ls     },
+  { "pwd",    do_pwd    },
+
+  { "mkdir",  do_mkdir  },
+  { "rmdir",  do_rmdir  },
+  { "rm",     do_rm     },
+
+  { "lcd",    do_lcd    },
+
+  { "read",   do_read   },
+  { "write",  do_write  },
+
+  { "help",   do_help   },
+  { "?",      do_help   },
+
+  { "quit",   do_quit   },
+  { "q",      do_quit   },
+
+  { "dump",   do_dump   },
+  { "cat",    do_dump   },
+
+  { "curdev", do_curdev },
+  { "show_super_stats", do_super },
+};
+
+
+/*
+ * find_command()
+ *
+ */
+static Command * find_command (char *cmd)
+{
+	int i;
+
+	for (i = 0; i < sizeof (commands) / sizeof (commands[0]); i++)
+		if (strcmp (cmd, commands[i].cmd) == 0)
+			return &commands[i];
+
+	return NULL;
+}					/* find_command */
+
+/*
+ * do_command()
+ *
+ */
+void do_command (char *cmd)
+{
+	char    **args;
+	Command  *command;
+
+	if (*cmd == '\0')
+		return;
+
+	args = g_strsplit (cmd, " ", -1);
+
+	command = find_command (args[0]);
+
+	if (command)
+		command->func (args);
+	else
+		printf ("Unrecognized command: %s\n", args[0]);
+
+	g_strfreev (args);
+}					/* do_command */
+
+/*
+ * do_open()
+ *
+ */
+static void do_open (char **args)
+{
+	char *dev = args[1];
+
+	if (device)
+		do_close (NULL);
+
+	if (dev == NULL)
+		printf ("open requires a device argument\n");
+
+	dev_fd = open (dev, allow_write ? O_RDONLY : O_RDWR);
+	if (dev_fd == -1)
+		printf ("could not open device %s\n", dev);
+
+	device = g_strdup (dev);
+
+	read_super_block (dev_fd, header, sizeof(header));
+
+	return ;
+}					/* do_open */
+
+/*
+ * do_close()
+ *
+ */
+static void do_close (char **args)
+{
+	if (device) {
+		g_free (device);
+		device = NULL;
+		close (dev_fd);
+		dev_fd = -1;
+
+		g_free (curdir);
+		curdir = g_strdup ("/");
+
+		memset (header, 0, sizeof(header));
+	} else
+		printf ("device not open\n");
+
+	return ;
+}					/* do_close */
+
+/*
+ * do_cd()
+ *
+ */
+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 */
+
+/*
+ * do_ls()
+ *
+ */
+static void do_ls (char **args)
+{
+#if 0
+  ocfs_super *vcb;
+  __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;
+
+  if (off <= 0)
+    {
+      printf ("Invalid directory %s\n", curdir);
+      return;
+    }
+
+  walk_dir_nodes (dev_fd, off, curdir, NULL);
+#endif
+}					/* do_ls */
+
+/*
+ * do_pwd()
+ *
+ */
+static void do_pwd (char **args)
+{
+#if 0
+  if (!curdir)
+    curdir = g_strdup ("/");
+
+  printf ("%s\n", curdir);
+#endif
+}					/* do_pwd */
+
+/*
+ * do_mkdir()
+ *
+ */
+static void do_mkdir (char **args)
+{
+	printf ("%s\n", __FUNCTION__);
+}					/* do_mkdir */
+
+/*
+ * do_rmdir()
+ *
+ */
+static void do_rmdir (char **args)
+{
+	printf ("%s\n", __FUNCTION__);
+}					/* do_rmdir */
+
+/*
+ * do_rm()
+ *
+ */
+static void do_rm (char **args)
+{
+  printf ("%s\n", __FUNCTION__);
+}					/* do_rm */
+
+/*
+ * do_read()
+ *
+ */
+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 */
+
+/*
+ * do_write()
+ *
+ */
+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 */
+
+/*
+ * do_help()
+ *
+ */
+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");
+}					/* do_help */
+
+/*
+ * do_quit()
+ *
+ */
+static void do_quit (char **args)
+{
+	exit (0);
+}					/* do_quit */
+
+/*
+ * do_dump()
+ *
+ */
+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 */
+
+/*
+ * do_lcd()
+ *
+ */
+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 */
+
+/*
+ * do_curdev()
+ *
+ */
+static void do_curdev (char **args)
+{
+	printf ("%s\n", device ? device : "No device");
+}					/* do_curdev */
+
+/*
+ * get_data()
+ *
+ */
+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;
+}					/* get_data */
+
+/*
+ * do_super()
+ *
+ */
+static void do_super (char **args)
+{
+	char *opts = args[1];
+	ocfs2_dinode *in;
+	ocfs2_super_block *sb;
+
+	if (opts && !strncmp(opts, "-h", 2)) {
+		in = (ocfs2_dinode *)header;
+		sb = &(in->id2.i_super);
+		dump_inode(in);
+		dump_super_block(sb);
+	}
+
+	return ;
+}					/* do_super */
+

Added: trunk/ocfs2/debugocfs/dump.c
===================================================================
--- trunk/ocfs2/debugocfs/dump.c	2004-06-22 00:55:08 UTC (rev 87)
+++ trunk/ocfs2/debugocfs/dump.c	2004-06-22 01:42:20 UTC (rev 88)
@@ -0,0 +1,77 @@
+
+#include <main.h>
+#include <commands.h>
+#include <dump.h>
+#include <readfs.h>
+
+/*
+ * dump_super_block()
+ *
+ */
+void dump_super_block(ocfs2_super_block *sb)
+{
+	int i;
+
+	printf("\trevision = %u.%u\n", sb->s_major_rev_level, sb->s_minor_rev_level);
+	printf("\tmount count = %u\n", sb->s_mnt_count);
+	printf("\tmax mount cnt = %u\n", sb->s_max_mnt_count);
+	printf("\tstate = %u\n", sb->s_state);
+	printf("\terrors = %u\n", sb->s_errors);
+	printf("\tcheck interval = %u\n", sb->s_checkinterval);
+	printf("\tlast check = %llu\n", sb->s_lastcheck);
+	printf("\tcreator os = %u\n", sb->s_creator_os);
+	printf("\tfeature compat = %u\n", sb->s_feature_compat);
+	printf("\tfeature incompat = %u\n", sb->s_feature_incompat);
+	printf("\tfeature ro compat = %u\n", sb->s_feature_ro_compat);
+	printf("\troot blknum = %llu\n", sb->s_root_blkno);
+	printf("\tsys dir blknum = %llu\n", sb->s_system_dir_blkno);
+	printf("\tblksize bits = %u\n", sb->s_blocksize_bits);
+	printf("\tclustersize bits = %u\n", sb->s_clustersize_bits);
+	printf("\tmax nodes = %u\n", sb->s_max_nodes);
+	printf("\tlabel = %s\n", sb->s_label);
+	printf("\tuuid = ");
+	for (i = 0; i < 16; i++)
+		printf("%02X ", sb->s_uuid[i]);
+	printf("\n");
+
+	return ;
+}				/* dump_super_block */
+
+/*
+ * dump_inode()
+ *
+ */
+void dump_inode(ocfs2_dinode *in)
+{
+	struct passwd *pw;
+	struct group *gr;
+	char *s;
+
+	printf("\tsignature = %s\n", in->i_signature);
+	printf("\tgeneration = %u\n", in->i_generation);
+	printf("\tsuballoc node = %u\n", in->i_suballoc_node); /* ?? */
+	printf("\tsuballoc blkno = %llu\n", in->i_suballoc_blkno);
+	pw = getpwuid(in->i_uid);
+	printf("\tuid = %u (%s)\n", in->i_uid, (pw ? pw->pw_name : "unknown"));
+	gr = getgrgid(in->i_gid);
+	printf("\tgid = %u (%s)\n", in->i_gid, (gr ? gr->gr_name : "unknown"));
+	printf("\tsize = %llu\n", in->i_size);
+	printf("\tmode = 0%0u\n", in->i_mode);
+	printf("\tlinks cnt = %u\n", in->i_links_count);
+	printf("\tflags = %u\n", in->i_flags);
+
+	s = ctime((time_t*)&in->i_atime);
+	printf("\tatime = %s", s);
+	s = ctime((time_t*)&in->i_ctime);
+	printf("\tctime = %s", s);
+	s = ctime((time_t*)&in->i_mtime);
+	printf("\tmtime = %s", s);
+	s = ctime((time_t*)&in->i_dtime);
+
+	printf("\tdtime = %s", s);
+	printf("\tblock num = %llu\n", in->i_blkno);
+	printf("\tclusters = %u\n", in->i_clusters);
+	printf("\tlast extblk = %llu\n", in->i_last_eb_blk);
+
+	return ;
+}				/* dump_inode */

Added: trunk/ocfs2/debugocfs/inc/commands.h
===================================================================
--- trunk/ocfs2/debugocfs/inc/commands.h	2004-06-22 00:55:08 UTC (rev 87)
+++ trunk/ocfs2/debugocfs/inc/commands.h	2004-06-22 01:42:20 UTC (rev 88)
@@ -0,0 +1,6 @@
+#ifndef __COMMANDS_H__
+#define __COMMANDS_H__
+
+void  do_command (char *cmd);
+
+#endif /* __COMMANDS_H__ */

Added: trunk/ocfs2/debugocfs/inc/dump.h
===================================================================
--- trunk/ocfs2/debugocfs/inc/dump.h	2004-06-22 00:55:08 UTC (rev 87)
+++ trunk/ocfs2/debugocfs/inc/dump.h	2004-06-22 01:42:20 UTC (rev 88)
@@ -0,0 +1,9 @@
+
+
+#ifndef __DUMP_H__
+#define __DUMP_H__
+
+void dump_super_block (ocfs2_super_block *sb);
+void dump_inode (ocfs2_dinode *in);
+
+#endif		/* __DUMP_H__ */

Added: trunk/ocfs2/debugocfs/inc/main.h
===================================================================
--- trunk/ocfs2/debugocfs/inc/main.h	2004-06-22 00:55:08 UTC (rev 87)
+++ trunk/ocfs2/debugocfs/inc/main.h	2004-06-22 01:42:20 UTC (rev 88)
@@ -0,0 +1,37 @@
+
+#ifndef __MAIN_H__
+#define __MAIN_H__
+
+#define _GNU_SOURCE
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <pwd.h>
+#include <grp.h>
+#include <time.h>
+
+#include <glib.h>
+
+#include <readline/readline.h>
+#include <readline/history.h>
+
+#include <linux/types.h>
+
+#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)
+
+#endif		/* __MAIN_H__ */

Added: trunk/ocfs2/debugocfs/inc/readfs.h
===================================================================
--- trunk/ocfs2/debugocfs/inc/readfs.h	2004-06-22 00:55:08 UTC (rev 87)
+++ trunk/ocfs2/debugocfs/inc/readfs.h	2004-06-22 01:42:20 UTC (rev 88)
@@ -0,0 +1,7 @@
+
+#ifndef __READFS_H__
+#define __READFS_H__
+
+int read_super_block(int fd, char *buf, int len);
+
+#endif		/* __READFS_H__ */

Added: trunk/ocfs2/debugocfs/main.c
===================================================================
--- trunk/ocfs2/debugocfs/main.c	2004-06-22 00:55:08 UTC (rev 87)
+++ trunk/ocfs2/debugocfs/main.c	2004-06-22 01:42:20 UTC (rev 88)
@@ -0,0 +1,124 @@
+
+#include <main.h>
+#include <commands.h>
+#include <dump.h>
+#include <readfs.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 "debugocfs: "
+
+static void  usage         (char *progname);
+static void  print_version (void);
+static char *get_line      (void);
+
+gboolean allow_write = FALSE;
+
+/*
+ * usage()
+ *
+ */
+static void usage (char *progname)
+{
+	g_print ("Usage: %s [OPTION]... [DEVICE]\n", progname);
+	g_print ("Options:\n");
+	g_print ("  -V, --version  g_print version information and exit\n");
+	g_print ("      --help     display this help and exit\n");
+	g_print ("  -w, --write    turn on write support\n");
+	exit (0);
+}					/* usage */
+
+/*
+ * print_version()
+ *
+ */
+static void print_version (void)
+{
+	g_print ("debugocfs version " DEBUGOCFS_VERSION "\n");
+}					/* print_version */
+
+/*
+ * get_line()
+ *
+ */
+static char * get_line (void)
+{
+	char *line;
+
+	line = readline (PROMPT);
+
+	if (line && *line)
+		add_history (line);
+
+	return line;
+}					/* get_line */
+
+/*
+ * main()
+ *
+ */
+int main (int argc, char **argv)
+{
+	int i;
+	char *line;
+	char *device = NULL;
+	char *arg;
+	gboolean seen_device = FALSE;
+
+	for (i = 1; i < argc; i++) {
+		arg = argv[i];
+		if ((strcmp (arg, "--write") == 0) ||
+		    (strcmp (arg, "-w") == 0)) {
+			allow_write = TRUE;
+		} else if ((strcmp (arg, "--version") == 0) ||
+			   (strcmp (arg, "-V") == 0)) {
+			print_version ();
+			exit (0);
+		} else if (strcmp (arg, "--help") == 0) {
+			usage (argv[0]);
+			exit (0);
+		} else if (!seen_device) {
+			device = g_strdup (arg);
+			seen_device = TRUE;
+		} else {
+			usage (argv[0]);
+			exit (1);
+		}
+	}
+
+	print_version ();
+
+	if (device) {
+		line = g_strdup_printf ("open %s", device);
+		do_command (line);
+		g_free (line);
+	}
+
+	while (1) {
+		line = get_line ();
+
+		if (line) {
+			if (!isatty (0))
+				printf ("%s\n", line);
+
+			do_command (line);
+			free (line);
+		} else {
+			printf ("\n");
+			exit (0);
+		}
+	}
+
+	return 0;
+}					/* main */

Added: trunk/ocfs2/debugocfs/readfs.c
===================================================================
--- trunk/ocfs2/debugocfs/readfs.c	2004-06-22 00:55:08 UTC (rev 87)
+++ trunk/ocfs2/debugocfs/readfs.c	2004-06-22 01:42:20 UTC (rev 88)
@@ -0,0 +1,56 @@
+
+#include <main.h>
+#include <commands.h>
+#include <dump.h>
+#include <readfs.h>
+
+/*
+ * read_super_block()
+ *
+ */
+int read_super_block(int fd, char *buf, int buflen)
+{
+	int ret = -1;
+	__u64 off;
+	ocfs1_vol_disk_hdr *hdr;
+	__u32 blksize;
+	ocfs2_dinode *di;
+
+	if ((ret = pread64(fd, buf, buflen, 0)) == -1) {
+		LOG_INTERNAL("%s", strerror(errno));
+		goto bail;
+	}
+
+	hdr = (ocfs1_vol_disk_hdr *)buf;
+	if (memcmp(hdr->signature, OCFS1_VOLUME_SIGNATURE,
+		   strlen (OCFS1_VOLUME_SIGNATURE)) == 0) {
+		printf("OCFS1 detected. Use debugocfs.\n");
+		goto bail;
+	}
+
+	/*
+	 * Now check at magic offset for 512, 1024, 2048, 4096
+	 * blocksizes.  4096 is the maximum blocksize because it is
+	 * the minimum clustersize.
+	 */
+	for (blksize = 512; blksize <= OCFS2_MAX_BLOCKSIZE; blksize <<= 1) {
+		off = blksize * OCFS2_SUPER_BLOCK_BLKNO;
+
+		if ((ret = pread64(fd, buf, buflen, off)) == -1) {
+			LOG_INTERNAL("%s", strerror(errno));
+			goto bail;
+		}
+
+		di = (ocfs2_dinode *) buf;
+		if (memcmp(di->i_signature, OCFS2_SUPER_BLOCK_SIGNATURE,
+			   strlen(OCFS2_SUPER_BLOCK_SIGNATURE))) {
+			printf("Not an OCFS2 volume.\n");
+			goto bail;
+		} else {
+			ret = 0;
+			break;
+		}
+	}
+bail:
+	return ret;
+}				/* read_super_block */



More information about the Ocfs-tools-commits mailing list