[Ocfs-tools-commits]
smushran commits r125 - in trunk/ocfs2/debugfs.ocfs2: . include
svn-commits at oss.oracle.com
svn-commits at oss.oracle.com
Thu Jul 1 14:40:17 CDT 2004
Author: smushran
Date: 2004-07-01 13:40:14 -0500 (Thu, 01 Jul 2004)
New Revision: 125
Added:
trunk/ocfs2/debugfs.ocfs2/include/jbd.h
trunk/ocfs2/debugfs.ocfs2/include/journal.h
trunk/ocfs2/debugfs.ocfs2/journal.c
Modified:
trunk/ocfs2/debugfs.ocfs2/Makefile
trunk/ocfs2/debugfs.ocfs2/commands.c
trunk/ocfs2/debugfs.ocfs2/dump.c
trunk/ocfs2/debugfs.ocfs2/main.c
trunk/ocfs2/debugfs.ocfs2/readfs.c
trunk/ocfs2/debugfs.ocfs2/utils.c
Log:
journal printed
Modified: trunk/ocfs2/debugfs.ocfs2/Makefile
===================================================================
--- trunk/ocfs2/debugfs.ocfs2/Makefile 2004-06-30 23:52:15 UTC (rev 124)
+++ trunk/ocfs2/debugfs.ocfs2/Makefile 2004-07-01 18:40:14 UTC (rev 125)
@@ -11,8 +11,8 @@
CFLAGS += -Wall -O2
-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
+CFILES = main.c commands.c dump.c readfs.c utils.c journal.c
+HFILES = include/main.h include/commands.h include/dump.h include/readfs.h include/utils.h include/journal.h
OBJS = $(subst .c,.o,$(CFILES))
Modified: trunk/ocfs2/debugfs.ocfs2/commands.c
===================================================================
--- trunk/ocfs2/debugfs.ocfs2/commands.c 2004-06-30 23:52:15 UTC (rev 124)
+++ trunk/ocfs2/debugfs.ocfs2/commands.c 2004-07-01 18:40:14 UTC (rev 125)
@@ -28,6 +28,7 @@
#include <dump.h>
#include <readfs.h>
#include <utils.h>
+#include <journal.h>
typedef void (*PrintFunc) (void *buf);
typedef gboolean (*WriteFunc) (char **data, void *buf);
@@ -65,6 +66,7 @@
static void do_config (char **args);
static void do_publish (char **args);
static void do_vote (char **args);
+static void do_journal (char **args);
extern gboolean allow_write;
@@ -117,8 +119,10 @@
{ "nodes", do_config },
{ "publish", do_publish },
- { "vote", do_vote }
+ { "vote", do_vote },
+ { "logdump", do_journal }
+
};
@@ -372,24 +376,18 @@
static void do_help (char **args)
{
printf ("curdev\t\t\t\tShow current device\n");
- printf ("open [device]\t\t\tOpen a 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 ("show_inode_info, stat <blknum>\tShow inode\n");
printf ("pwd\t\t\t\tPrint working directory\n");
- printf ("ls [blknum]\t\t\tList directory\n");
- printf ("cat [blknum]\t\t\tPrints file on stdout\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 ("ls <blknum>\t\t\tList directory\n");
+ printf ("cat <blknum> [outfile]\t\tPrints or concatenates file to stdout/outfile\n");
+ printf ("dump <blknum> <outfile>\t\tDumps file to outfile\n");
printf ("nodes\t\t\t\tList of nodes\n");
printf ("publish\t\t\t\tPublish blocks\n");
printf ("vote\t\t\t\tVote blocks\n");
+ printf ("logdump <blknum>\t\tPrints journal file\n");
printf ("help, ?\t\t\t\tThis information\n");
printf ("quit, q\t\t\t\tExit the program\n");
} /* do_help */
@@ -609,3 +607,32 @@
return ;
} /* do_dump */
+
+/*
+ * do_journal()
+ *
+ */
+static void do_journal (char **args)
+{
+ char *logbuf = NULL;
+ __u64 blknum = 0;
+ __s32 len = 0;
+
+ if (args[1])
+ blknum = strtoull (args[1], NULL, 0);
+ if (!blknum)
+ goto bail;
+
+ if (dev_fd == -1)
+ printf ("device not open\n");
+ else {
+ if ((len = read_file (dev_fd, blknum, -1, &logbuf)) == -1)
+ goto bail;
+ read_journal (logbuf, (__u64)len);
+ }
+
+bail:
+ safefree (logbuf);
+ return ;
+} /* do_journal */
+
Modified: trunk/ocfs2/debugfs.ocfs2/dump.c
===================================================================
--- trunk/ocfs2/debugfs.ocfs2/dump.c 2004-06-30 23:52:15 UTC (rev 124)
+++ trunk/ocfs2/debugfs.ocfs2/dump.c 2004-07-01 18:40:14 UTC (rev 125)
@@ -28,6 +28,7 @@
#include <dump.h>
#include <readfs.h>
#include <utils.h>
+#include <journal.h>
extern char *superblk;
extern __u32 blksz_bits;
Added: trunk/ocfs2/debugfs.ocfs2/include/jbd.h
===================================================================
--- trunk/ocfs2/debugfs.ocfs2/include/jbd.h 2004-06-30 23:52:15 UTC (rev 124)
+++ trunk/ocfs2/debugfs.ocfs2/include/jbd.h 2004-07-01 18:40:14 UTC (rev 125)
@@ -0,0 +1,124 @@
+/*
+ * jbd.h
+ *
+ * header file extracted from linux/include/linux/jbd.h
+ *
+ * Originally written by Stephen C. Tweedie <sct at redhat.com>
+ *
+ * Copyright 1998-2000 Red Hat, Inc --- All Rights Reserved
+ *
+ * This file is part of the Linux kernel and is made available under
+ * the terms of the GNU General Public License, version 2, or at your
+ * option, any later version, incorporated herein by reference.
+ *
+ * Definitions for transaction data structures for the buffer cache
+ * filesystem journaling support.
+ */
+
+#ifndef _JBD_H_
+#define _JBD_H_
+
+/*
+ * Internal structures used by the logging mechanism:
+ */
+
+#define JFS_MAGIC_NUMBER 0xc03b3998U /* The first 4 bytes of /dev/random! */
+
+/*
+ * On-disk structures
+ */
+
+/*
+ * Descriptor block types:
+ */
+
+#define JFS_DESCRIPTOR_BLOCK 1
+#define JFS_COMMIT_BLOCK 2
+#define JFS_SUPERBLOCK_V1 3
+#define JFS_SUPERBLOCK_V2 4
+#define JFS_REVOKE_BLOCK 5
+
+/*
+ * Standard header for all descriptor blocks:
+ */
+typedef struct journal_header_s
+{
+ __u32 h_magic;
+ __u32 h_blocktype;
+ __u32 h_sequence;
+} journal_header_t;
+
+/*
+ * The block tag: used to describe a single buffer in the journal
+ */
+typedef struct journal_block_tag_s
+{
+ __u32 t_blocknr; /* The on-disk block number */
+ __u32 t_flags; /* See below */
+} journal_block_tag_t;
+
+/*
+ * The revoke descriptor: used on disk to describe a series of blocks to
+ * be revoked from the log
+ */
+typedef struct journal_revoke_header_s
+{
+ journal_header_t r_header;
+ int r_count; /* Count of bytes used in the block */
+} journal_revoke_header_t;
+
+/* Definitions for the journal tag flags word: */
+#define JFS_FLAG_ESCAPE 1 /* on-disk block is escaped */
+#define JFS_FLAG_SAME_UUID 2 /* block has same uuid as previous */
+#define JFS_FLAG_DELETED 4 /* block deleted by this transaction */
+#define JFS_FLAG_LAST_TAG 8 /* last tag in this descriptor block */
+
+/*
+ * The journal superblock. All fields are in big-endian byte order.
+ */
+typedef struct journal_superblock_s
+{
+/* 0x0000 */
+ journal_header_t s_header;
+
+/* 0x000C */
+ /* Static information describing the journal */
+ __u32 s_blocksize; /* journal device blocksize */
+ __u32 s_maxlen; /* total blocks in journal file */
+ __u32 s_first; /* first block of log information */
+
+/* 0x0018 */
+ /* Dynamic information describing the current state of the log */
+ __u32 s_sequence; /* first commit ID expected in log */
+ __u32 s_start; /* blocknr of start of log */
+
+/* 0x0020 */
+ /* Error value, as set by journal_abort(). */
+ __s32 s_errno;
+
+/* 0x0024 */
+ /* Remaining fields are only valid in a version-2 superblock */
+ __u32 s_feature_compat; /* compatible feature set */
+ __u32 s_feature_incompat; /* incompatible feature set */
+ __u32 s_feature_ro_compat; /* readonly-compatible feature set */
+/* 0x0030 */
+ __u8 s_uuid[16]; /* 128-bit uuid for journal */
+
+/* 0x0040 */
+ __u32 s_nr_users; /* Nr of filesystems sharing log */
+
+ __u32 s_dynsuper; /* Blocknr of dynamic superblock copy*/
+
+/* 0x0048 */
+ __u32 s_max_transaction; /* Limit of journal blocks per trans.*/
+ __u32 s_max_trans_data; /* Limit of data blocks per trans. */
+
+/* 0x0050 */
+ __u32 s_padding[44];
+
+/* 0x0100 */
+ __u8 s_users[16*48]; /* ids of all fs'es sharing the log */
+/* 0x0400 */
+} journal_superblock_t;
+
+#endif /* _JBD_H_ */
Added: trunk/ocfs2/debugfs.ocfs2/include/journal.h
===================================================================
--- trunk/ocfs2/debugfs.ocfs2/include/journal.h 2004-06-30 23:52:15 UTC (rev 124)
+++ trunk/ocfs2/debugfs.ocfs2/include/journal.h 2004-07-01 18:40:14 UTC (rev 125)
@@ -0,0 +1,38 @@
+/*
+ * journal.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, Mark Fasheh
+ */
+
+#ifndef _JOURNAL_H_
+#define _JOURNAL_H_
+
+#include <jbd.h>
+
+void read_journal (char *buf, __u64 buflen);
+void print_header (journal_header_t *header, char *hdr);
+void print_super_block (journal_superblock_t *sb);
+void print_metadata_blocks (int start, int end);
+void print_tag_flag (__u32 flags);
+void print_jbd_block (journal_header_t *header);
+
+#endif /* _JOURNAL_H_ */
Added: trunk/ocfs2/debugfs.ocfs2/journal.c
===================================================================
--- trunk/ocfs2/debugfs.ocfs2/journal.c 2004-06-30 23:52:15 UTC (rev 124)
+++ trunk/ocfs2/debugfs.ocfs2/journal.c 2004-07-01 18:40:14 UTC (rev 125)
@@ -0,0 +1,259 @@
+/*
+ * journal.c
+ *
+ * reads the journal file
+ *
+ * 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, Mark Fasheh
+ */
+
+#include <main.h>
+#include <commands.h>
+#include <dump.h>
+#include <readfs.h>
+#include <utils.h>
+#include <journal.h>
+
+extern __u32 blksz_bits;
+
+/*
+ * read_journal()
+ *
+ */
+void read_journal (char *buf, __u64 buflen)
+{
+ char *block;
+ int blocknum;
+ journal_header_t *header;
+ int last_metadata = 0;
+ __u32 blksize = 1 << blksz_bits;
+ __u64 len;
+ char *p;
+
+ len = buflen;
+ p = buf;
+ blocknum = -1;
+
+ while (len) {
+ blocknum++;
+ block = p;
+ header = (journal_header_t *) block;
+ if (blocknum == 0) {
+ printf("block %d: ", blocknum);
+ print_super_block((journal_superblock_t *) block);
+ } else if (header->h_magic == ntohl(JFS_MAGIC_NUMBER)) {
+ if (last_metadata > 0) {
+ print_metadata_blocks(last_metadata,
+ blocknum - 1);
+ last_metadata = 0;
+ }
+ printf("block %d: ", blocknum);
+ print_jbd_block(header);
+ } else {
+ if (last_metadata == 0)
+ last_metadata = blocknum;
+// continue;
+ }
+
+ p += blksize;
+ len -= blksize;
+ }
+
+ if (last_metadata > 0)
+ print_metadata_blocks(last_metadata, blocknum);
+
+ return ;
+} /* read_journal */
+
+#define PRINT_FIELD(name, size, field) printf("\t" #field ":\t\t" size \
+ "\n", ntohl(name->field))
+
+/*
+ * print_header()
+ *
+ */
+void print_header (journal_header_t *header, char *hdr)
+{
+ printf("\t%s->h_magic:\t\t0x%x\n", hdr, ntohl(header->h_magic));
+ printf("\t%s->h_blocktype:\t\t%u ", hdr, ntohl(header->h_blocktype));
+
+ switch (ntohl(header->h_blocktype)) {
+ case JFS_DESCRIPTOR_BLOCK:
+ printf("(JFS_DESCRIPTOR_BLOCK)");
+ break;
+ case JFS_COMMIT_BLOCK:
+ printf("(JFS_COMMIT_BLOCK)");
+ break;
+ case JFS_SUPERBLOCK_V1:
+ printf("(JFS_SUPERBLOCK_V1)");
+ break;
+ case JFS_SUPERBLOCK_V2:
+ printf("(JFS_SUPERBLOCK_V2)");
+ break;
+ case JFS_REVOKE_BLOCK:
+ printf("(JFS_REVOKE_BLOCK)");
+ break;
+ }
+ printf("\n");
+ printf("\t%s->h_sequence:\t\t%u\n", hdr, ntohl(header->h_sequence));
+ return;
+} /* print_header */
+
+/*
+ * print_super_block()
+ *
+ */
+void print_super_block (journal_superblock_t *sb)
+{
+ int i;
+
+ printf("Journal Superblock\n");
+
+ print_header(&(sb->s_header), "s_header");
+
+ PRINT_FIELD(sb, "%u", s_blocksize);
+ PRINT_FIELD(sb, "%u", s_maxlen);
+ PRINT_FIELD(sb, "%u", s_first);
+ PRINT_FIELD(sb, "%u", s_sequence);
+ PRINT_FIELD(sb, "%u", s_start);
+ PRINT_FIELD(sb, "%d", s_errno);
+ PRINT_FIELD(sb, "%u", s_feature_compat);
+ PRINT_FIELD(sb, "%u", s_feature_incompat);
+ PRINT_FIELD(sb, "%u", s_feature_ro_compat);
+
+ printf("\ts_uuid[16]:\t\t");
+ for(i = 0; i < 16; i++)
+ printf("%x ", sb->s_uuid[i]);
+ printf("\n");
+
+
+ PRINT_FIELD(sb, "%u", s_nr_users);
+ PRINT_FIELD(sb, "%u", s_dynsuper);
+ PRINT_FIELD(sb, "%u", s_max_transaction);
+ PRINT_FIELD(sb, "%u", s_max_trans_data);
+
+ return;
+} /* print_super_block */
+
+
+/*
+ * print_metadata_blocks()
+ *
+ */
+void print_metadata_blocks (int start, int end)
+{
+ if (start == end)
+ printf("block %d: ", start);
+ else
+ printf("block %d --> block %d: ", start, end);
+ printf("Filesystem Metadata\n\n");
+ return;
+} /* print_metadata_blocks */
+
+/*
+ * print_tag_flag()
+ *
+ */
+void print_tag_flag (__u32 flags)
+{
+
+ if (flags == 0) {
+ printf("(none)");
+ goto done;
+ }
+ if (flags & JFS_FLAG_ESCAPE)
+ printf("JFS_FLAG_ESCAPE ");
+ if (flags & JFS_FLAG_SAME_UUID)
+ printf("JFS_FLAG_SAME_UUID ");
+ if (flags & JFS_FLAG_DELETED)
+ printf("JFS_FLAG_DELETED ");
+ if (flags & JFS_FLAG_LAST_TAG)
+ printf("JFS_FLAG_LAST_TAG");
+done:
+ return;
+} /* print_tag_flag */
+
+/*
+ * print_jbd_block()
+ *
+ */
+void print_jbd_block (journal_header_t *header)
+{
+ int i;
+ int j;
+ int count = 0;
+ /* for descriptors */
+ journal_block_tag_t *tag;
+ journal_revoke_header_t *revoke;
+ char *blk = (char *) header;
+ __u32 *blocknr;
+ char *uuid;
+
+ switch(ntohl(header->h_blocktype)) {
+ case JFS_DESCRIPTOR_BLOCK:
+ printf("Journal Descriptor\n");
+ print_header(header, "hdr");
+ for(i = sizeof(journal_header_t); i < (1 << blksz_bits);
+ i+=sizeof(journal_block_tag_t)) {
+ tag = (journal_block_tag_t *) &blk[i];
+ printf("\ttag[%d]->t_blocknr:\t\t%u\n", count,
+ ntohl(tag->t_blocknr));
+ printf("\ttag[%d]->t_flags:\t\t", count);
+ print_tag_flag(ntohl(tag->t_flags));
+ printf("\n");
+ if (tag->t_flags & htonl(JFS_FLAG_LAST_TAG))
+ break;
+
+ /* skip the uuid. */
+ if (!(tag->t_flags & htonl(JFS_FLAG_SAME_UUID))) {
+ uuid = &blk[i + sizeof(journal_block_tag_t)];
+ printf("\ttag[%d] uuid:\t\t", count);
+ for(j = 0; j < 16; j++)
+ printf("%x ", uuid[j]);
+ printf("\n");
+ i += 16;
+ }
+ count++;
+ }
+ break;
+
+ case JFS_COMMIT_BLOCK:
+ printf("Journal Commit Block\n");
+ print_header(header, "hdr");
+ break;
+
+ case JFS_REVOKE_BLOCK:
+ printf("Journal Revoke Block\n");
+ print_header(header, "r_header");
+ revoke = (journal_revoke_header_t *) blk;
+ printf("\tr_count:\t\t%d\n", ntohl(revoke->r_count));
+ count = (ntohl(revoke->r_count) -
+ sizeof(journal_revoke_header_t)) / sizeof(__u32);
+ blocknr = (__u32 *) &blk[sizeof(journal_revoke_header_t)];
+ for(i = 0; i < count; i++)
+ printf("\trevoke[%d]:\t\t%u\n", i, ntohl(blocknr[i]));
+ break;
+
+ default:
+ printf("Unknown block type\n");
+ break;
+ }
+
+ return;
+} /* print_jbd_block */
Modified: trunk/ocfs2/debugfs.ocfs2/main.c
===================================================================
--- trunk/ocfs2/debugfs.ocfs2/main.c 2004-06-30 23:52:15 UTC (rev 124)
+++ trunk/ocfs2/debugfs.ocfs2/main.c 2004-07-01 18:40:14 UTC (rev 125)
@@ -28,6 +28,7 @@
#include <dump.h>
#include <readfs.h>
#include <utils.h>
+#include <journal.h>
#define PROMPT "debugfs: "
Modified: trunk/ocfs2/debugfs.ocfs2/readfs.c
===================================================================
--- trunk/ocfs2/debugfs.ocfs2/readfs.c 2004-06-30 23:52:15 UTC (rev 124)
+++ trunk/ocfs2/debugfs.ocfs2/readfs.c 2004-07-01 18:40:14 UTC (rev 125)
@@ -28,6 +28,7 @@
#include <dump.h>
#include <readfs.h>
#include <utils.h>
+#include <journal.h>
extern __u32 blksz_bits;
extern __u32 clstrsz_bits;
@@ -335,8 +336,10 @@
}
ret = 0;
- if (buf)
+ if (buf) {
*buf = newbuf;
+ ret = newlen;
+ }
bail:
safefree (inode_buf);
Modified: trunk/ocfs2/debugfs.ocfs2/utils.c
===================================================================
--- trunk/ocfs2/debugfs.ocfs2/utils.c 2004-06-30 23:52:15 UTC (rev 124)
+++ trunk/ocfs2/debugfs.ocfs2/utils.c 2004-07-01 18:40:14 UTC (rev 125)
@@ -28,6 +28,7 @@
#include <dump.h>
#include <readfs.h>
#include <utils.h>
+#include <journal.h>
/*
* add_extent_rec()
More information about the Ocfs-tools-commits
mailing list