Skip to contentSkip to conversation

hfsplus journal detection

PATCH New Warren Turkal 3 participants 13 messages Nov 5, 2008 – Nov 9, 2008

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

These small changes change the hfsplus filesystem so that a 0 in the journal info block of the volume header indicates that there is no journal. This change allows the such an HFS+ volume to mount in rw mode without needing the force mount option.

Are there any tips you can give me so that I can make sure I am doing the right thing to get this into the Linux kernel?

Thanks,
wt

#1 lore raw

PATCH 1/1 Identify journal info block in volume header.

---
 fs/hfsplus/hfsplus_raw.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
fs/hfsplus/hfsplus_raw.h +1 -1
index fe99fe8..14f1dd8 100644
@@ -94,7 +94,7 @@ struct hfsplus_vh {
 	__be16 version;
 	__be32 attributes;
 	__be32 last_mount_vers;
-	u32 reserved;
+	__be32 journal_info_block;
 
 	__be32 create_date;
 	__be32 modify_date;
Signature · 1 line
1.5.6.3
#2 lore raw

PATCH 1/1 Fix journal detection on HFS+.

The code was unconditionally assumming that the volume had a jounal if the jounal attribute was set in the volume header. However, the volume also has to have a non-zero journal info block to actually have a journal.

---
 fs/hfsplus/super.c |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)
fs/hfsplus/super.c +5 -2
index eb74531..b12e767 100644
@@ -260,7 +260,8 @@ static int hfsplus_remount(struct super_block *sb, int *flags, char *data)
 			printk(KERN_WARNING "hfs: filesystem is marked locked, leaving read-only.\n");
 			sb->s_flags |= MS_RDONLY;
 			*flags |= MS_RDONLY;
-		} else if (vhdr->attributes & cpu_to_be32(HFSPLUS_VOL_JOURNALED)) {
+		} else if (vhdr->attributes & cpu_to_be32(HFSPLUS_VOL_JOURNALED) &&
+				vhdr->journal_info_block != cpu_to_be32(0)) {
 			printk(KERN_WARNING "hfs: filesystem is marked journaled, leaving read-only.\n");
 			sb->s_flags |= MS_RDONLY;
 			*flags |= MS_RDONLY;
@@ -356,7 +357,9 @@ static int hfsplus_fill_super(struct super_block *sb, void *data, int silent)
 	} else if (vhdr->attributes & cpu_to_be32(HFSPLUS_VOL_SOFTLOCK)) {
 		printk(KERN_WARNING "hfs: Filesystem is marked locked, mounting read-only.\n");
 		sb->s_flags |= MS_RDONLY;
-	} else if ((vhdr->attributes & cpu_to_be32(HFSPLUS_VOL_JOURNALED)) && !(sb->s_flags & MS_RDONLY)) {
+	} else if ((vhdr->attributes & cpu_to_be32(HFSPLUS_VOL_JOURNALED)) &&
+			(be32_to_cpu(vhdr->journal_info_block) != 0) &&
+			!(sb->s_flags & MS_RDONLY)) {
 		printk(KERN_WARNING "hfs: write access to a journaled filesystem is not supported, "
 		       "use the force option at your own risk, mounting read-only.\n");
 		sb->s_flags |= MS_RDONLY;
Signature · 1 line
1.5.6.3
#3 lore raw

Re: [PATCH] Fix journal detection on HFS+.

fs/hfsplus/super.c static int hfsplus_remount(struct super_block *sb, int *flags, char *data) · line 264

Quoted 2 lines · Warren Turkal
fs/hfsplus/super.c +1 -0
+				vhdr->journal_info_block != cpu_to_be32(0)) {

0 doesn't need explicit cpu_to_be32(). You can drop the whole != cpu_to_be32(0)

fs/hfsplus/super.c static int hfsplus_fill_super(struct super_block *sb, void *data, int silent) · line 361

Quoted 1 line
fs/hfsplus/super.c +1 -0
+			(be32_to_cpu(vhdr->journal_info_block) != 0) &&

Same here.

Jörn

Signature · 6 lines
This above all: to thine own self be true.
-- Shakespeare
--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#4 lore raw

Re: [PATCH] Fix journal detection on HFS+.

Quoted 10 lines · J??rn Engel

fs/hfsplus/super.c static int hfsplus_remount(struct super_block *sb, int *flags, char *data) · line 264

Quoted 2 lines · Warren Turkal
fs/hfsplus/super.c +1 -0
+				vhdr->journal_info_block != cpu_to_be32(0)) {

0 doesn't need explicit cpu_to_be32(). You can drop the whole != cpu_to_be32(0)

fs/hfsplus/super.c static int hfsplus_fill_super(struct super_block *sb, void *data, int silent) · line 361

Quoted 1 line
fs/hfsplus/super.c +1 -0
+			(be32_to_cpu(vhdr->journal_info_block) != 0) &&

Same here.

Yeah. In addition adding a little helper that checks both the journal flag and the non-zeroness of journal_info_block would be useful so that everyone adding more checks like this in the future get it right.

#5 lore raw

hfsplus journal detection - next try

Here is my next stab at this issue. I refactored the logic into a function and took out the != 0 like you all suggested. Please let me know if there is anything else I can do to improve it.

Also, I am just getting used to git. Is the best workflow to create a branch that I cherrypick seemingly acceptable patches into and just createa a different branch for each patchset attempt?

Thanks,
wt

#6 lore raw

PATCH 1/1 Identify journal info block in volume header.

---
 fs/hfsplus/hfsplus_raw.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
fs/hfsplus/hfsplus_raw.h +1 -1
index fe99fe8..14f1dd8 100644
@@ -94,7 +94,7 @@ struct hfsplus_vh {
 	__be16 version;
 	__be32 attributes;
 	__be32 last_mount_vers;
-	u32 reserved;
+	__be32 journal_info_block;
 
 	__be32 create_date;
 	__be32 modify_date;
Signature · 1 line
1.5.6.3
#7 lore raw

PATCH 1/1 Fix journal detection on HFS+.

The code was unconditionally assumming that the volume had a jounal if the jounal attribute was set in the volume header. However, the volume also has to have a non-zero journal info block to actually have a journal.

---
 fs/hfsplus/Makefile     |    5 +++--
 fs/hfsplus/hfsplus_fs.h |    2 ++
 fs/hfsplus/journal.c    |   14 ++++++++++++++
 fs/hfsplus/super.c      |    4 ++--
 4 files changed, 21 insertions(+), 4 deletions(-)
 create mode 100644 fs/hfsplus/journal.c
fs/hfsplus/Makefile +3 -2
index 3cc0df7..a90cdcb 100644
@@ -4,6 +4,7 @@
 
 obj-$(CONFIG_HFSPLUS_FS) += hfsplus.o
 
-hfsplus-objs := super.o options.o inode.o ioctl.o extents.o catalog.o dir.o btree.o \
-		bnode.o brec.o bfind.o tables.o unicode.o wrapper.o bitmap.o part_tbl.o
+hfsplus-objs := super.o options.o inode.o ioctl.o extents.o catalog.o dir.o \
+		btree.o bnode.o brec.o bfind.o tables.o unicode.o wrapper.o \
+		bitmap.o part_tbl.o journal.o
 
fs/hfsplus/hfsplus_fs.h +2 -0
index f027a90..9018d2d 100644
@@ -421,4 +421,6 @@ static inline struct hfsplus_inode_info *HFSPLUS_I(struct inode *inode)
 
 #define kdev_t_to_nr(x)		(x)
 
+bool hfsp_vol_has_journal(struct hfsplus_vh *vhdr);
+
 #endif
fs/hfsplus/journal.c new file +14 -0
new file mode 100644
index 0000000..7a5ef2a
@@ -0,0 +1,14 @@
+/*
+ * linux/fs/hfsplus/journal.c
+ * Copyright (c) 2008 Warren Turkal
+ *
+ * Journal related routines
+ */
+
+#include "hfsplus_fs.h"
+
+bool hfsp_vol_has_journal(struct hfsplus_vh *vhdr)
+{
+	return (vhdr->attributes & cpu_to_be32(HFSPLUS_VOL_JOURNALED) &&
+				vhdr->journal_info_block);
+}
fs/hfsplus/super.c +2 -2
index eb74531..9293c9a 100644
@@ -260,7 +260,7 @@ static int hfsplus_remount(struct super_block *sb, int *flags, char *data)
 			printk(KERN_WARNING "hfs: filesystem is marked locked, leaving read-only.\n");
 			sb->s_flags |= MS_RDONLY;
 			*flags |= MS_RDONLY;
-		} else if (vhdr->attributes & cpu_to_be32(HFSPLUS_VOL_JOURNALED)) {
+		} else if (hfsp_vol_has_journal(vhdr)) {
 			printk(KERN_WARNING "hfs: filesystem is marked journaled, leaving read-only.\n");
 			sb->s_flags |= MS_RDONLY;
 			*flags |= MS_RDONLY;
@@ -356,7 +356,7 @@ static int hfsplus_fill_super(struct super_block *sb, void *data, int silent)
 	} else if (vhdr->attributes & cpu_to_be32(HFSPLUS_VOL_SOFTLOCK)) {
 		printk(KERN_WARNING "hfs: Filesystem is marked locked, mounting read-only.\n");
 		sb->s_flags |= MS_RDONLY;
-	} else if ((vhdr->attributes & cpu_to_be32(HFSPLUS_VOL_JOURNALED)) && !(sb->s_flags & MS_RDONLY)) {
+	} else if (hfsp_vol_has_journal(vhdr) && !(sb->s_flags & MS_RDONLY)) {
 		printk(KERN_WARNING "hfs: write access to a journaled filesystem is not supported, "
 		       "use the force option at your own risk, mounting read-only.\n");
 		sb->s_flags |= MS_RDONLY;
Signature · 1 line
1.5.6.3
#8 lore raw

Re: [PATCH] Fix journal detection on HFS+.

fs/hfsplus/Makefile line 9

Quoted 6 lines · Warren Turkal
fs/hfsplus/Makefile +3 -2
-hfsplus-objs := super.o options.o inode.o ioctl.o extents.o catalog.o dir.o btree.o \
-		bnode.o brec.o bfind.o tables.o unicode.o wrapper.o bitmap.o part_tbl.o
+hfsplus-objs := super.o options.o inode.o ioctl.o extents.o catalog.o dir.o \
+		btree.o bnode.o brec.o bfind.o tables.o unicode.o wrapper.o \
+		bitmap.o part_tbl.o journal.o

Didn't check-read your patch? Remove, please.

fs/hfsplus/hfsplus_fs.h static inline struct hfsplus_inode_info *HFSPLUS_I(struct inode *inode) · line 425

Quoted 10 lines
fs/hfsplus/hfsplus_fs.h +2 -0
index f027a90..9018d2d 100644
@@ -421,4 +421,6 @@ static inline struct hfsplus_inode_info *HFSPLUS_I(struct inode *inode)
 
 #define kdev_t_to_nr(x)		(x)
 
+bool hfsp_vol_has_journal(struct hfsplus_vh *vhdr);
+

The function is only ever used in super.c. Just leave it in the same file and make it static.

Jörn

Signature · 6 lines
Premature optimization is the root of all evil.
-- Donald Knuth
--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#9 lore raw

Re: [PATCH] Fix journal detection on HFS+.

Quoted 9 lines · Jörn Engel

fs/hfsplus/Makefile line 9

Quoted 6 lines · Warren Turkal
fs/hfsplus/Makefile +3 -2
-hfsplus-objs := super.o options.o inode.o ioctl.o extents.o catalog.o dir.o btree.o \
-             bnode.o brec.o bfind.o tables.o unicode.o wrapper.o bitmap.o part_tbl.o
+hfsplus-objs := super.o options.o inode.o ioctl.o extents.o catalog.o dir.o \
+             btree.o bnode.o brec.o bfind.o tables.o unicode.o wrapper.o \
+             bitmap.o part_tbl.o journal.o

Didn't check-read your patch? Remove, please.

I am sorry, but I don't understand this comment. What is check-read? Do you want me to remove the journal.o from the hfsplus-objs line?

Quoted 6 lines
Quoted 6 lines
fs/hfsplus/hfsplus_fs.h +0 -0
index f027a90..9018d2d 100644
@@ -421,4 +421,6 @@ static inline struct hfsplus_inode_info *HFSPLUS_I(struct inode *inode)
 
Quoted 7 lines

fs/hfsplus/hfsplus_fs.h static inline struct hfsplus_inode_info *HFSPLUS_I(struct inode *inode) · line 425

Quoted 4 lines
fs/hfsplus/hfsplus_fs.h +2 -0
 #define kdev_t_to_nr(x)              (x)
 
+bool hfsp_vol_has_journal(struct hfsplus_vh *vhdr);
+

The function is only ever used in super.c. Just leave it in the same file and make it static.

Okay...will do.

wt
--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#10 lore raw

Re: [PATCH] Fix journal detection on HFS+.

Quoted 3 lines · Warren Turkal

I am sorry, but I don't understand this comment. What is check-read? Do you want me to remove the journal.o from the hfsplus-objs line?

Honestly, I didn't even notice you created a new file for that one function. This hunk looked like something completely unrelated - reformatting can hide functional changes.

/me whistles innocently

Jörn

Signature · 7 lines
Measure. Don't tune for speed until you've measured, and even then
don't unless one part of the code overwhelms the rest.
-- Rob Pike
--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#11 lore raw

Re: [PATCH] Fix journal detection on HFS+.

Is everything looking ok at this point?

wt

Quoted 9 lines · Jörn Engel
Quoted 3 lines · Warren Turkal

I am sorry, but I don't understand this comment. What is check-read? Do you want me to remove the journal.o from the hfsplus-objs line?

Honestly, I didn't even notice you created a new file for that one function. This hunk looked like something completely unrelated - reformatting can hide functional changes.

Quoted 9 lines

/me whistles innocently

Jörn

--
Measure. Don't tune for speed until you've measured, and even then don't unless one part of the code overwhelms the rest. -- Rob Pike

--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#12 lore raw

Re: [PATCH] Fix journal detection on HFS+.

Quoted 2 lines · Warren Turkal

Is everything looking ok at this point?

Yes.

Jörn

Signature · 6 lines
And spam is a useful source of entropy for /dev/random too!
-- Jasmine Strong
--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html