All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4 01/15] hfsplus: add necessary declarations for journal replay
@ 2014-02-23 15:31 Vyacheslav Dubeyko
  0 siblings, 0 replies; only message in thread
From: Vyacheslav Dubeyko @ 2014-02-23 15:31 UTC (permalink / raw)
  To: Linux FS devel list
  Cc: Al Viro, ChristophHellwig, Hin-Tak Leung, Andrew Morton

From: Vyacheslav Dubeyko <slava@dubeyko.com>
Subject: [PATCH v4 01/15] hfsplus: add necessary declarations for journal replay

The patch adds necessary declarations of HFS+ journal's
on-disk structures, declaration of structure for journal's
object in memory and different journal related flags.

If HFSPLUS_VOL_JOURNALED is set in the volume header's attributes field,
the volume has a journal. The journal data structures consist of a journal
info block, journal header, and journal buffer. The journal info block
indicates the location and size of the journal header and journal buffer.
The journal buffer is the space set aside to hold transactions. The journal
header describes which part of the journal buffer is active and contains
transactions waiting to be committed.

A single transaction consists of several blocks, including both the data
to be written, and the location where that data is to be written. This is
represented on disk by a block list header, which describes the number and
sizes of the blocks, immediately followed by the contents of those blocks.

The journal info block (struct hfsplus_journal_info_block) is big-endian
structure. The rest structures of HFS+ journal (struct hfsplus_journal_header,
struct hfsplus_blhdr, struct hfsplus_block_info) can be as little-endian as
big-endian. The endian field of struct hfsplus_journal_header defines
what endianness has a journal.

Signed-off-by: Vyacheslav Dubeyko <slava@dubeyko.com>
CC: Al Viro <viro@zeniv.linux.org.uk>
CC: Christoph Hellwig <hch@infradead.org>
Tested-by: Hin-Tak Leung <htl10@users.sourceforge.net>
---
 fs/hfsplus/hfsplus_fs.h  |   35 +++++++++++++++++++++
 fs/hfsplus/hfsplus_raw.h |   77 +++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 111 insertions(+), 1 deletion(-)

diff --git a/fs/hfsplus/hfsplus_fs.h b/fs/hfsplus/hfsplus_fs.h
index 08846425b..2353eaa 100644
--- a/fs/hfsplus/hfsplus_fs.h
+++ b/fs/hfsplus/hfsplus_fs.h
@@ -31,6 +31,11 @@
 #define DBG_BITMAP	0x00000040
 #define DBG_ATTR_MOD	0x00000080
 #define DBG_ACL_MOD	0x00000100
+#define DBG_JOURNAL	0x00000200
+#define DBG_JREPLAY	0x00000400
+#define DBG_JTRANS	0x00000800
+#define DBG_JCOMMIT	0x00001000
+#define DBG_JCHKPT	0x00002000
 
 #if 0
 #define DBG_MASK	(DBG_EXTENT|DBG_INODE|DBG_BNODE_MOD)
@@ -126,6 +131,35 @@ struct hfs_bnode {
 #define HFS_BNODE_DIRTY		3
 #define HFS_BNODE_DELETED	4
 
+/* An HFS+ Journal held in memory */
+struct hfsplus_journal {
+	struct mutex jnl_lock;
+
+	/* Journal info block specific */
+	void *jib_buf;
+	struct hfsplus_journal_info_block *jib;
+
+	/* Journal header specific */
+	void *jh_buf;
+	struct hfsplus_journal_header *jh;
+#define HFSPLUS_JOURNAL_CORRUPTED	0
+#define HFSPLUS_BE_JOURNAL		1
+#define HFSPLUS_LE_JOURNAL		2
+	u8 endianness;
+
+	/* TODO: Pointer of JBD */
+
+	struct super_block *sbp;
+};
+
+#define HFSPLUS_JOURNAL_PTR(ptr) \
+	((struct hfsplus_journal *)(ptr))
+
+#define IS_BE_JOURNAL(jnl) \
+	(HFSPLUS_JOURNAL_PTR(jnl)->endianness == HFSPLUS_BE_JOURNAL)
+#define IS_LE_JOURNAL(jnl) \
+	(HFSPLUS_JOURNAL_PTR(jnl)->endianness == HFSPLUS_LE_JOURNAL)
+
 /*
  * Attributes file states
  */
@@ -146,6 +180,7 @@ struct hfsplus_sb_info {
 	struct hfsplus_vh *s_vhdr;
 	void *s_backup_vhdr_buf;
 	struct hfsplus_vh *s_backup_vhdr;
+	struct hfsplus_journal *jnl;
 	struct hfs_btree *ext_tree;
 	struct hfs_btree *cat_tree;
 	struct hfs_btree *attr_tree;
diff --git a/fs/hfsplus/hfsplus_raw.h b/fs/hfsplus/hfsplus_raw.h
index 8ffb3a8..8d178ab 100644
--- a/fs/hfsplus/hfsplus_raw.h
+++ b/fs/hfsplus/hfsplus_raw.h
@@ -46,6 +46,7 @@
 #define HFSP_SYMLINK_CREATOR	0x72686170	/* 'rhap' */
 
 #define HFSP_MOUNT_VERSION	0x482b4c78	/* 'H+Lx' */
+#define HFSP_MOUNT_JOURNALED_VERSION 0x4846534A	/* 'HFSJ' */
 
 /* Structures used on disk */
 
@@ -105,7 +106,7 @@ struct hfsplus_vh {
 	__be16 version;
 	__be32 attributes;
 	__be32 last_mount_vers;
-	u32 reserved;
+	__be32 journal_info_block;
 
 	__be32 create_date;
 	__be32 modify_date;
@@ -401,4 +402,78 @@ typedef union {
 	struct hfsplus_attr_key attr;
 } __packed hfsplus_btree_key;
 
+/* HFS+ on-disk journal structures */
+
+/*
+ * Describes placement of the journal header
+ * and journal buffer
+ */
+struct hfsplus_journal_info_block {
+#define HFSPLUS_JOURNAL_IN_FS		0x01
+#define HFSPLUS_JOURNAL_ON_OTHER_DEVICE	0x02
+#define HFSPLUS_JOURNAL_NEED_INIT	0x04
+	__be32 flags;
+	__be32 device_signature[8];
+	__be64 offset;
+	__be64 size;
+	u32 reserved[32];
+} __packed;
+
+/* Valid magic and endian value */
+#define HFSPLUS_JOURNAL_HEADER_MAGIC	0x4A4E4C78
+#define HFSPLUS_JOURNAL_HEADER_ENDIAN	0x12345678
+
+/*
+ * Describe the location of transactions in
+ * the journal buffer
+ *
+ * This structure can be as big-endian as little-endian.
+ * But now little-endian is more frequent case.
+ */
+struct hfsplus_journal_header {
+	__le32 magic;
+	__le32 endian;
+	__le64 start;
+	__le64 end;
+	__le64 size; /* Includes the header and the buffer */
+	__le32 blhdr_size;
+	__le32 checksum;
+	__le32 jhdr_size;
+} __packed;
+
+/*
+ * Represent a single block of data in the journal
+ * buffer which must be copied to its correct
+ * location on disk
+ *
+ * This structure can be as big-endian as little-endian.
+ * But now little-endian is more frequent case.
+ */
+struct hfsplus_block_info {
+	__le64 bnum;
+	__le32 bsize;
+	union {
+		__le32 checksum;
+		__le32 seq_num; /* only used in binfo[0] */
+	} block;
+} __packed;
+
+/*
+ * Describe a list of blocks included in
+ * a transaction
+ *
+ * This structure can be as big-endian as little-endian.
+ * But now little-endian is more frequent case.
+ */
+struct hfsplus_blhdr {
+	__le16 max_blocks;
+	__le16 num_blocks;
+	__le32 bytes_used;
+	__le32 checksum;
+#define HFSPLUS_BLHDR_CHECK_CHECKSUMS	0x0001
+#define HFSPLUS_BLHDR_FIRST_HEADER	0x0002
+	__le32 flags;
+	struct hfsplus_block_info binfo[1];
+} __packed;
+
 #endif
-- 
1.7.9.5




^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2014-02-23 15:32 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-02-23 15:31 [PATCH v4 01/15] hfsplus: add necessary declarations for journal replay Vyacheslav Dubeyko

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.