[Ocfs2-tools-devel] [PATCH 1/3] fsck.ocfs2: Move to JBD2 header and structures.

Joel Becker joel.becker at oracle.com
Fri Sep 5 23:36:40 PDT 2008


Change all defines and structures to JBD2 structures.  This is backwards
compatible with the JBD journals, and is capable of handling even the
oldest ocfs2 filesystems.

The only major functional change is to use journal_tag_size() instead of
sizeof(journal_block_tag_t) when walking the descriptor block.
fsck.ocfs2 and debugfs.ocfs2 are updated.

Signed-off-by: Joel Becker <joel.becker at oracle.com>
---
 debugfs.ocfs2/dump.c         |   18 +++--
 debugfs.ocfs2/include/dump.h |    3 +-
 debugfs.ocfs2/journal.c      |   26 +++++--
 debugfs.ocfs2/utils.c        |   36 ++++----
 fsck.ocfs2/journal.c         |   70 ++++++++--------
 include/ocfs2/jbd.h          |  124 ----------------------------
 include/ocfs2/jbd2.h         |  185 ++++++++++++++++++++++++++++++++++++++++++
 include/ocfs2/ocfs2.h        |    2 +-
 libocfs2/mkjournal.c         |    6 +-
 9 files changed, 273 insertions(+), 197 deletions(-)
 delete mode 100644 include/ocfs2/jbd.h
 create mode 100644 include/ocfs2/jbd2.h

diff --git a/debugfs.ocfs2/dump.c b/debugfs.ocfs2/dump.c
index b8e0aba..fe69f3d 100644
--- a/debugfs.ocfs2/dump.c
+++ b/debugfs.ocfs2/dump.c
@@ -513,7 +513,8 @@ void dump_jbd_superblock (FILE *out, journal_superblock_t *jsb)
  * dump_jbd_block()
  *
  */
-void dump_jbd_block (FILE *out, journal_header_t *header, uint64_t blknum)
+void dump_jbd_block (FILE *out, journal_superblock_t *jsb,
+		     journal_header_t *header, uint64_t blknum)
 {
 	int i;
 	int j;
@@ -526,20 +527,21 @@ void dump_jbd_block (FILE *out, journal_header_t *header, uint64_t blknum)
 	uint32_t *blocknr;
 	char *uuid;
 	struct ocfs2_super_block *sb = OCFS2_RAW_SB(gbls.fs->fs_super);
+	int tag_bytes = journal_tag_bytes(jsb);
 
 	tagflg = g_string_new (NULL);
 
 	fprintf (out, "\tBlock %"PRIu64": ", blknum);
 
 	switch (ntohl(header->h_blocktype)) {
-	case JFS_DESCRIPTOR_BLOCK:
+	case JBD2_DESCRIPTOR_BLOCK:
 		fprintf (out, "Journal Descriptor\n");
 		dump_jbd_header (out, header);
 
 		fprintf (out, "\t%3s %-15s %-s\n", "No.", "Blocknum", "Flags");
 
 		for (i = sizeof(journal_header_t); i < (1 << sb->s_blocksize_bits);
-		     i+=sizeof(journal_block_tag_t)) {
+		     i+=tag_bytes) {
 			tag = (journal_block_tag_t *) &blk[i];
 
 			get_tag_flag(ntohl(tag->t_flags), tagflg);
@@ -547,12 +549,12 @@ void dump_jbd_block (FILE *out, journal_header_t *header, uint64_t blknum)
 				 count, ntohl(tag->t_blocknr), tagflg->str);
 			g_string_truncate (tagflg, 0);
 
-			if (tag->t_flags & htonl(JFS_FLAG_LAST_TAG))
+			if (tag->t_flags & htonl(JBD2_FLAG_LAST_TAG))
 				break;
 
 			/* skip the uuid. */
-			if (!(tag->t_flags & htonl(JFS_FLAG_SAME_UUID))) {
-				uuid = &blk[i + sizeof(journal_block_tag_t)];
+			if (!(tag->t_flags & htonl(JBD2_FLAG_SAME_UUID))) {
+				uuid = &blk[i + tag_bytes];
 				fprintf (out, "\tUUID: ");
 				for(j = 0; j < 16; j++)
 					fprintf (out, "%02X",uuid[j]);
@@ -563,12 +565,12 @@ void dump_jbd_block (FILE *out, journal_header_t *header, uint64_t blknum)
 		}
 		break;
 
-	case JFS_COMMIT_BLOCK:
+	case JBD2_COMMIT_BLOCK:
 		fprintf(out, "Journal Commit Block\n");
 		dump_jbd_header (out, header);
 		break;
 
-	case JFS_REVOKE_BLOCK:							/*TODO*/
+	case JBD2_REVOKE_BLOCK:							/*TODO*/
 		fprintf(out, "Journal Revoke Block\n");
 		dump_jbd_header (out, header);
 		revoke = (journal_revoke_header_t *) blk;
diff --git a/debugfs.ocfs2/include/dump.h b/debugfs.ocfs2/include/dump.h
index 5310d36..525f6b9 100644
--- a/debugfs.ocfs2/include/dump.h
+++ b/debugfs.ocfs2/include/dump.h
@@ -45,7 +45,8 @@ int  dump_dir_entry (struct ocfs2_dir_entry *rec, int offset, int blocksize,
 		     char *buf, void *priv_data);
 void dump_jbd_header (FILE *out, journal_header_t *header);
 void dump_jbd_superblock (FILE *out, journal_superblock_t *jsb);
-void dump_jbd_block (FILE *out, journal_header_t *header, uint64_t blknum);
+void dump_jbd_block (FILE *out, journal_superblock_t *jsb,
+		     journal_header_t *header, uint64_t blknum);
 void dump_jbd_metadata (FILE *out, int type, char *buf, uint64_t blknum);
 void dump_jbd_unknown (FILE *out, uint64_t start, uint64_t end);
 void dump_slots (FILE *out, struct ocfs2_slot_map_extended *se,
diff --git a/debugfs.ocfs2/journal.c b/debugfs.ocfs2/journal.c
index 5f02e2a..a0c5fb2 100644
--- a/debugfs.ocfs2/journal.c
+++ b/debugfs.ocfs2/journal.c
@@ -27,8 +27,8 @@
 
 extern dbgfs_gbls gbls;
 
-static void scan_journal(FILE *out, char *buf, int len,
-			 uint64_t *blocknum, uint64_t *last_unknown)
+static void scan_journal(FILE *out, journal_superblock_t *jsb, char *buf,
+			 int len, uint64_t *blocknum, uint64_t *last_unknown)
 {
 	char *block;
 	char *p;
@@ -40,12 +40,12 @@ static void scan_journal(FILE *out, char *buf, int len,
 	while (len) {
 		block = p;
 		header = (journal_header_t *)block;
-		if (header->h_magic == ntohl(JFS_MAGIC_NUMBER)) {
+		if (header->h_magic == ntohl(JBD2_MAGIC_NUMBER)) {
 			if (*last_unknown) {
 				dump_jbd_unknown(out, *last_unknown, *blocknum);
 				*last_unknown = 0;
 			}
-			dump_jbd_block(out, header, *blocknum);
+			dump_jbd_block(out, jsb, header, *blocknum);
 		} else {
 			type = detect_block(block);
 			if (type < 0) {
@@ -71,6 +71,7 @@ static void scan_journal(FILE *out, char *buf, int len,
 errcode_t read_journal(ocfs2_filesys *fs, uint64_t blkno, FILE *out)
 {
 	char *buf = NULL;
+	char *jsb_buf = NULL;
 	char *p;
 	uint64_t blocknum;
 	uint64_t len;
@@ -81,6 +82,7 @@ errcode_t read_journal(ocfs2_filesys *fs, uint64_t blkno, FILE *out)
 	int buflenbits;
 	ocfs2_cached_inode *ci = NULL;
 	errcode_t ret;
+	journal_superblock_t *jsb;
 
 	ret = ocfs2_read_cached_inode(fs, blkno, &ci);
 	if (ret) {
@@ -88,6 +90,13 @@ errcode_t read_journal(ocfs2_filesys *fs, uint64_t blkno, FILE *out)
 		goto bail;
 	}
 
+	ret = ocfs2_malloc_block(fs->fs_io, &jsb_buf);
+	if (ret) {
+		com_err(gbls.cmd, ret,
+			"while allocating journal superblock buffer");
+		goto bail;
+	}
+
 	buflenbits = buflen >>
 			OCFS2_RAW_SB(gbls.fs->fs_super)->s_blocksize_bits;
 	ret = ocfs2_malloc_blocks(fs->fs_io, buflenbits, &buf);
@@ -98,6 +107,7 @@ errcode_t read_journal(ocfs2_filesys *fs, uint64_t blkno, FILE *out)
 
 	offset = 0;
 	blocknum = 0;
+	jsb = (journal_superblock_t *)jsb_buf;
 	while (1) {
 		ret = ocfs2_file_read(ci, buf, buflen, offset, &got);
 		if (ret) {
@@ -112,13 +122,15 @@ errcode_t read_journal(ocfs2_filesys *fs, uint64_t blkno, FILE *out)
 		len = got;
 
 		if (offset == 0) {
-			dump_jbd_superblock(out, (journal_superblock_t *)buf);
+			dump_jbd_superblock(out, jsb);
+			memcpy(jsb_buf, buf, fs->fs_blocksize);
+			ocfs2_swap_journal_superblock(jsb);
 			blocknum++;
 			p += fs->fs_blocksize;
 			len -= fs->fs_blocksize;
 		}
 
-		scan_journal(out, p, len, &blocknum, &last_unknown);
+		scan_journal(out, jsb, p, len, &blocknum, &last_unknown);
 
 		if (got < buflen)
 			break;
@@ -131,6 +143,8 @@ errcode_t read_journal(ocfs2_filesys *fs, uint64_t blkno, FILE *out)
 	}
 
 bail:
+	if (jsb_buf)
+		ocfs2_free(&jsb_buf);
 	if (buf)
 		ocfs2_free(&buf);
 	if (ci)
diff --git a/debugfs.ocfs2/utils.c b/debugfs.ocfs2/utils.c
index ff2624d..73edb9e 100644
--- a/debugfs.ocfs2/utils.c
+++ b/debugfs.ocfs2/utils.c
@@ -215,20 +215,20 @@ void get_publish_flag (uint32_t flag, GString *str)
 void get_journal_block_type (uint32_t jtype, GString *str)
 {
 	switch (jtype) {
-	case JFS_DESCRIPTOR_BLOCK:
-		g_string_append (str, "JFS_DESCRIPTOR_BLOCK");
+	case JBD2_DESCRIPTOR_BLOCK:
+		g_string_append (str, "JBD2_DESCRIPTOR_BLOCK");
 		break;
-	case JFS_COMMIT_BLOCK:
-		g_string_append (str, "JFS_COMMIT_BLOCK");
+	case JBD2_COMMIT_BLOCK:
+		g_string_append (str, "JBD2_COMMIT_BLOCK");
 		break;
-	case JFS_SUPERBLOCK_V1:
-		g_string_append (str, "JFS_SUPERBLOCK_V1");
+	case JBD2_SUPERBLOCK_V1:
+		g_string_append (str, "JBD2_SUPERBLOCK_V1");
 		break;
-	case JFS_SUPERBLOCK_V2:
-		g_string_append (str, "JFS_SUPERBLOCK_V2");
+	case JBD2_SUPERBLOCK_V2:
+		g_string_append (str, "JBD2_SUPERBLOCK_V2");
 		break;
-	case JFS_REVOKE_BLOCK:
-		g_string_append (str, "JFS_REVOKE_BLOCK");
+	case JBD2_REVOKE_BLOCK:
+		g_string_append (str, "JBD2_REVOKE_BLOCK");
 		break;
 	}
 
@@ -249,17 +249,17 @@ void get_tag_flag (uint32_t flags, GString *str)
 		goto done;
 	}
 
-	if (flags & JFS_FLAG_ESCAPE)
-		g_string_append (str, "JFS_FLAG_ESCAPE ");
+	if (flags & JBD2_FLAG_ESCAPE)
+		g_string_append (str, "JBD2_FLAG_ESCAPE ");
 
-	if (flags & JFS_FLAG_SAME_UUID)
-		g_string_append (str, "JFS_FLAG_SAME_UUID ");
+	if (flags & JBD2_FLAG_SAME_UUID)
+		g_string_append (str, "JBD2_FLAG_SAME_UUID ");
 
-	if (flags & JFS_FLAG_DELETED)
-		g_string_append (str, "JFS_FLAG_DELETED ");
+	if (flags & JBD2_FLAG_DELETED)
+		g_string_append (str, "JBD2_FLAG_DELETED ");
 
-	if (flags & JFS_FLAG_LAST_TAG)
-		g_string_append (str, "JFS_FLAG_LAST_TAG");
+	if (flags & JBD2_FLAG_LAST_TAG)
+		g_string_append (str, "JBD2_FLAG_LAST_TAG");
 
 done:
 	return ;
diff --git a/fsck.ocfs2/journal.c b/fsck.ocfs2/journal.c
index 75f500b..ae00367 100644
--- a/fsck.ocfs2/journal.c
+++ b/fsck.ocfs2/journal.c
@@ -3,30 +3,25 @@
  *
  * Copyright (C) 2000 Andreas Dilger
  * Copyright (C) 2000 Theodore Ts'o
- * Copyright (C) 2004 Oracle.  All rights reserved.
+ * Copyright (C) 2004,2008 Oracle.  All rights reserved.
  *
  * Parts of the code are based on fs/jfs/journal.c by Stephen C. Tweedie
  * Copyright (C) 1999 Red Hat Software
  *
  * 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.
+ * 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 replays the jbd journals for each slot.  First all the journals are
+ * This replays the jbd2 journals for each slot.  First all the journals are
  * walked to detect inconsistencies.  Only journals with no problems will be
  * replayed.  IO errors during replay will just result in partial journal
- * replay, just like jbd does in the kernel.  Journals that don't pass
+ * replay, just like jbd2 does in the kernel.  Journals that don't pass
  * consistency checks, like having overlapping blocks or strange fields, are
  * ignored and left for later passes to clean up.  
 
@@ -202,29 +197,31 @@ static uint64_t jwrap(journal_superblock_t *jsb, uint64_t block)
 	return block;
 }
 
-static errcode_t count_tags(ocfs2_filesys *fs, char *buf, size_t size,
-			    uint64_t *nr_ret)
+static errcode_t count_tags(ocfs2_filesys *fs, journal_superblock_t *jsb,
+			    char *buf, uint64_t *nr_ret)
 {
-	journal_block_tag_t *tag, *last;
+	char *tagp, *last;
+	journal_block_tag_t *tag;
+	int tag_bytes = journal_tag_bytes(jsb);
 	uint64_t nr = 0;
 
-	if (size < sizeof(journal_header_t) + sizeof(*tag))
+	if (jsb->s_blocksize < sizeof(journal_header_t) + tag_bytes)
 		return OCFS2_ET_BAD_JOURNAL_TAG;
 
-       	tag = (journal_block_tag_t *)&buf[sizeof(journal_header_t)];
-       	last = (journal_block_tag_t *)&buf[size - sizeof(*tag)];
+	tagp = &buf[sizeof(journal_header_t)];
+	last = &buf[jsb->s_blocksize - tag_bytes];
 
-	for(; tag <= last; tag++) {
+	for(; tagp <= last; tagp += tag_bytes) {
+		tag = (journal_block_tag_t *)tagp;
 		nr++;
 		if (ocfs2_block_out_of_range(fs, 
 					     be32_to_cpu(tag->t_blocknr)))
 			return OCFS2_ET_BAD_JOURNAL_TAG;
 
-		if (tag->t_flags & cpu_to_be32(JFS_FLAG_LAST_TAG))
+		if (tag->t_flags & cpu_to_be32(JBD2_FLAG_LAST_TAG))
 			break;
-		/* inline uuids are 16 bytes, tags are 8 */
-		if (!(tag->t_flags & cpu_to_be32(JFS_FLAG_SAME_UUID)))
-			tag += 2;
+		if (!(tag->t_flags & cpu_to_be32(JBD2_FLAG_SAME_UUID)))
+			tagp += 16;
 	}
 
 	*nr_ret = nr;
@@ -288,14 +285,16 @@ static errcode_t read_journal_block(ocfs2_filesys *fs,
 static errcode_t replay_blocks(ocfs2_filesys *fs, struct journal_info *ji,
 			       char *buf, uint64_t seq, uint64_t *next_block)
 {
-	journal_block_tag_t tag, *tagp;
+	journal_block_tag_t tag;
+	char *tagp;
 	size_t i, num;
 	char *io_buf = NULL;
 	errcode_t err, ret = 0;
+	int tag_bytes = journal_tag_bytes(ji->ji_jsb);
 		
-	tagp = (journal_block_tag_t *)(buf + sizeof(journal_header_t));
+	tagp = buf + sizeof(journal_header_t);
 	num = (ji->ji_jsb->s_blocksize - sizeof(journal_header_t)) / 
-	      sizeof(tag);
+		tag_bytes;
 
 	ret = ocfs2_malloc_blocks(fs->fs_io, 1, &io_buf);
 	if (ret) {
@@ -303,8 +302,8 @@ static errcode_t replay_blocks(ocfs2_filesys *fs, struct journal_info *ji,
 		goto out;
 	}
 
-	for(i = 0; i < num; i++, tagp++, (*next_block)++) {
-		memcpy(&tag, tagp, sizeof(tag));
+	for(i = 0; i < num; i++, tagp += tag_bytes, (*next_block)++) {
+		memcpy(&tag, tagp, tag_bytes);
 		tag.t_flags = be32_to_cpu(tag.t_flags);
 		tag.t_blocknr = be32_to_cpu(tag.t_blocknr);
 
@@ -322,8 +321,8 @@ static errcode_t replay_blocks(ocfs2_filesys *fs, struct journal_info *ji,
 			goto skip_io;
 		}
 
-		if (tag.t_flags & JFS_FLAG_ESCAPE) {
-			uint32_t magic = cpu_to_be32(JFS_MAGIC_NUMBER);
+		if (tag.t_flags & JBD2_FLAG_ESCAPE) {
+			uint32_t magic = cpu_to_be32(JBD2_MAGIC_NUMBER);
 			memcpy(io_buf, &magic, sizeof(magic));
 		}
 
@@ -333,11 +332,10 @@ static errcode_t replay_blocks(ocfs2_filesys *fs, struct journal_info *ji,
 			ret = err;
 
 	skip_io:
-		if (tag.t_flags & JFS_FLAG_LAST_TAG)
+		if (tag.t_flags & JBD2_FLAG_LAST_TAG)
 			i = num; /* be sure to increment next_block */
-		/* inline uuids are 16 bytes, tags are 8 */
-		if (!(tag.t_flags & JFS_FLAG_SAME_UUID))
-			tagp += 2;
+		if (!(tag.t_flags & JBD2_FLAG_SAME_UUID))
+			tagp += 16;
 	}
 	
 out:
@@ -389,7 +387,7 @@ static errcode_t walk_journal(ocfs2_filesys *fs, int slot,
 
 		verbosef("jh magic %x\n", jh.h_magic);
 
-		if (jh.h_magic != JFS_MAGIC_NUMBER)
+		if (jh.h_magic != JBD2_MAGIC_NUMBER)
 			break;
 
 		verbosef("jh block %x\n", jh.h_blocktype);
@@ -399,7 +397,7 @@ static errcode_t walk_journal(ocfs2_filesys *fs, int slot,
 			break;
 
 		switch(jh.h_blocktype) {
-		case JFS_DESCRIPTOR_BLOCK:
+		case JBD2_DESCRIPTOR_BLOCK:
 			verbosef("found a desc type %x\n", jh.h_blocktype);
 			/* replay the blocks described in the desc block */
 			if (recover) {
@@ -411,19 +409,19 @@ static errcode_t walk_journal(ocfs2_filesys *fs, int slot,
 			}
 
 			/* just record the blocks as used and carry on */ 
-			err = count_tags(fs, buf, jsb->s_blocksize, &nr);
+			err = count_tags(fs, jsb, buf, &nr);
 			if (err)
 				ret = err;
 			else
 				next_block = jwrap(jsb, next_block + nr);
 			break;
 
-		case JFS_COMMIT_BLOCK:
+		case JBD2_COMMIT_BLOCK:
 			verbosef("found a commit type %x\n", jh.h_blocktype);
 			next_seq++;
 			break;
 
-		case JFS_REVOKE_BLOCK:
+		case JBD2_REVOKE_BLOCK:
 			verbosef("found a revoke type %x\n", jh.h_blocktype);
 			add_revoke_records(ji, buf, jsb->s_blocksize,
 					   next_seq);
diff --git a/include/ocfs2/jbd.h b/include/ocfs2/jbd.h
deleted file mode 100644
index 29493fb..0000000
--- a/include/ocfs2/jbd.h
+++ /dev/null
@@ -1,124 +0,0 @@
-/*
- * 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_ */
diff --git a/include/ocfs2/jbd2.h b/include/ocfs2/jbd2.h
new file mode 100644
index 0000000..bc31218
--- /dev/null
+++ b/include/ocfs2/jbd2.h
@@ -0,0 +1,185 @@
+/*
+ * jbd2.h
+ *
+ * header file extracted from linux/include/linux/jbd2.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 as published by
+ * the Free Software Foundation.
+ *
+ * Definitions for transaction data structures for the buffer cache
+ * filesystem journaling support.
+ */
+
+#ifndef _JBD2_H_
+#define _JBD2_H_
+
+/*
+ * Internal structures used by the logging mechanism:
+ */
+
+#define JBD2_MAGIC_NUMBER 0xc03b3998U /* The first 4 bytes of /dev/random! */
+
+/*
+ * On-disk structures
+ */
+
+/* 
+ * Descriptor block types:
+ */
+
+#define JBD2_DESCRIPTOR_BLOCK	1
+#define JBD2_COMMIT_BLOCK	2
+#define JBD2_SUPERBLOCK_V1	3
+#define JBD2_SUPERBLOCK_V2	4
+#define JBD2_REVOKE_BLOCK	5
+
+/*
+ * Standard header for all descriptor blocks:
+ */
+typedef struct journal_header_s
+{
+	__be32		h_magic;
+	__be32		h_blocktype;
+	__be32		h_sequence;
+} journal_header_t;
+
+/*
+ * Checksum types.
+ */
+#define JBD2_CRC32_CHKSUM       1
+#define JBD2_MD5_CHKSUM         2
+#define JBD2_SHA2_CHKSUM        3
+
+#define JBD2_CRC32_CHKSUM_SIZE  4
+
+#define JBD2_CHECKSUM_BYTES (32 / sizeof(uint32_t))
+/*
+ * Commit block header for storing transactional checksums:
+ */
+struct commit_header {
+	__be32		h_magic;
+	__be32          h_blocktype;
+	__be32          h_sequence;
+	unsigned char   h_chksum_type;
+	unsigned char   h_chksum_size;
+	unsigned char 	h_padding[2];
+	__be32 		h_chksum[JBD2_CHECKSUM_BYTES];
+	__be64		h_commit_sec;
+	__be32		h_commit_nsec;
+};
+
+/*
+ * The block tag: used to describe a single buffer in the journal.
+ * t_blocknr_high is only used if INCOMPAT_64BIT is set, so this
+ * raw struct shouldn't be used for pointer math or sizeof() - use
+ * journal_tag_bytes(journal) instead to compute this.
+ */
+typedef struct journal_block_tag_s
+{
+	__be32		t_blocknr;	/* The on-disk block number */
+	__be32		t_flags;	/* See below */
+	__be32		t_blocknr_high; /* most-significant high 32bits. */
+} journal_block_tag_t;
+
+#define JBD2_TAG_SIZE32 (offsetof(journal_block_tag_t, t_blocknr_high))
+#define JBD2_TAG_SIZE64 (sizeof(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 JBD2_FLAG_ESCAPE	1	/* on-disk block is escaped */
+#define JBD2_FLAG_SAME_UUID	2	/* block has same uuid as previous */
+#define JBD2_FLAG_DELETED	4	/* block deleted by this transaction */
+#define JBD2_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 */
+	__be32	s_blocksize;		/* journal device blocksize */
+	__be32	s_maxlen;		/* total blocks in journal file */
+	__be32	s_first;		/* first block of log information */
+	
+/* 0x0018 */
+	/* Dynamic information describing the current state of the log */
+	__be32	s_sequence;		/* first commit ID expected in log */
+	__be32	s_start;		/* blocknr of start of log */
+
+/* 0x0020 */
+	/* Error value, as set by jbd2_journal_abort(). */
+	__be32	s_errno;
+
+/* 0x0024 */
+	/* Remaining fields are only valid in a version-2 superblock */
+	__be32	s_feature_compat; 	/* compatible feature set */
+	__be32	s_feature_incompat; 	/* incompatible feature set */
+	__be32	s_feature_ro_compat; 	/* readonly-compatible feature set */
+/* 0x0030 */
+	__u8	s_uuid[16];		/* 128-bit uuid for journal */
+
+/* 0x0040 */
+	__be32	s_nr_users;		/* Nr of filesystems sharing log */
+	
+	__be32	s_dynsuper;		/* Blocknr of dynamic superblock copy*/
+	
+/* 0x0048 */
+	__be32	s_max_transaction;	/* Limit of journal blocks per trans.*/
+	__be32	s_max_trans_data;	/* Limit of data blocks per trans. */
+
+/* 0x0050 */
+	__be32	s_padding[44];
+
+/* 0x0100 */
+	__u8	s_users[16*48];		/* ids of all fs'es sharing the log */
+/* 0x0400 */
+} journal_superblock_t;
+
+#define JBD2_HAS_COMPAT_FEATURE(jsb,mask)				\
+	(((jsb)->s_header.h_blocktype == JBD2_SUPERBLOCK_V2) &&		\
+	 ((jsb)->s_feature_compat & mask))
+#define JBD2_HAS_RO_COMPAT_FEATURE(jsb,mask)				\
+	(((jsb)->s_header.h_blocktype == JBD2_SUPERBLOCK_V2) &&		\
+	 ((jsb)->s_feature_ro_compat & mask))
+#define JBD2_HAS_INCOMPAT_FEATURE(jsb,mask)				\
+	(((jsb)->s_header.h_blocktype == JBD2_SUPERBLOCK_V2) &&		\
+	 ((jsb)->s_feature_incompat & mask))
+
+#define JBD2_FEATURE_COMPAT_CHECKSUM	        0x00000001
+
+#define JBD2_FEATURE_INCOMPAT_REVOKE		0x00000001
+#define JBD2_FEATURE_INCOMPAT_64BIT		0x00000002
+#define JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT	0x00000004
+
+/* Features known to this kernel version: */
+#define JBD2_KNOWN_COMPAT_FEATURES	0
+#define JBD2_KNOWN_ROCOMPAT_FEATURES	0
+#define JBD2_KNOWN_INCOMPAT_FEATURES	0
+
+static inline size_t journal_tag_bytes(journal_superblock_t *jsb)
+{
+	if (JBD2_HAS_INCOMPAT_FEATURE(jsb, JBD2_FEATURE_INCOMPAT_64BIT))
+		return JBD2_TAG_SIZE64;
+	else
+		return JBD2_TAG_SIZE32;
+}
+
+#endif		/* _JBD2_H_ */
diff --git a/include/ocfs2/ocfs2.h b/include/ocfs2/ocfs2.h
index fbc3146..c184e5c 100644
--- a/include/ocfs2/ocfs2.h
+++ b/include/ocfs2/ocfs2.h
@@ -53,7 +53,7 @@
 #include <o2dlm/o2dlm.h>
 #include <o2cb/o2cb.h>
 #include <ocfs2/ocfs2_err.h>
-#include <ocfs2/jbd.h>
+#include <ocfs2/jbd2.h>
 #include <ocfs2-kernel/ocfs2_lockid.h>
 
 #define OCFS2_LIB_FEATURE_INCOMPAT_SUPP		(OCFS2_FEATURE_INCOMPAT_SUPP | \
diff --git a/libocfs2/mkjournal.c b/libocfs2/mkjournal.c
index 94d1a43..3812690 100644
--- a/libocfs2/mkjournal.c
+++ b/libocfs2/mkjournal.c
@@ -70,8 +70,8 @@ errcode_t ocfs2_init_journal_superblock(ocfs2_filesys *fs, char *buf,
 		return OCFS2_ET_JOURNAL_TOO_SMALL;
 
 	memset(buf, 0, buflen);
-	jsb->s_header.h_magic     = JFS_MAGIC_NUMBER;
-	jsb->s_header.h_blocktype = JFS_SUPERBLOCK_V2;
+	jsb->s_header.h_magic     = JBD2_MAGIC_NUMBER;
+	jsb->s_header.h_blocktype = JBD2_SUPERBLOCK_V2;
 
 	jsb->s_blocksize = fs->fs_blocksize;
 	jsb->s_maxlen    = jrnl_size_in_blks;
@@ -157,7 +157,7 @@ errcode_t ocfs2_read_journal_superblock(ocfs2_filesys *fs, uint64_t blkno,
 	disk = (journal_superblock_t *)blk;
 	jsb = (journal_superblock_t *)jsb_buf;
 
-	if (disk->s_header.h_magic != htonl(JFS_MAGIC_NUMBER)) {
+	if (disk->s_header.h_magic != htonl(JBD2_MAGIC_NUMBER)) {
 		ret = OCFS2_ET_BAD_JOURNAL_SUPERBLOCK_MAGIC;
 		goto out;
 	}
-- 
1.5.6.3




More information about the Ocfs2-tools-devel mailing list