Skip to contentSkip to conversation

HFS+ journal improvement - take 6

PATCH In review Warren Turkal 2 participants 9 messages Nov 21, 2008 – Dec 1, 2008

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

cover HFS+ journal improvement - take 6

This is a patchset to change the way that the HFS+ filesystem detects whether a volume has a journal or not.

The code currently mounts an HFS+ volume read-only by default when a journal is detected. One can force a read/write mount by giving the "force" mount option. The current code has this behavior since there is no support for the HFS+ journal.

My problem is that the detection of the journal could be better. The current code tests the attribute bit in the volume header that indicates there is a journal. If that bit is set, the code assumes that there is a journal.

Unfortunately, this is not enough to really determine if there is a journal or not. When that bit is set, one must also examine the journal info block field of the volume header. If this field is 0, there is no journal, and the volume can be mounted read/write.

Thanks,
wt

Warren Turkal (2):
Identify journal info block in volume header.
Fix journal detection on HFS+.

 fs/hfsplus/hfsplus_raw.h |    2 +-
 fs/hfsplus/super.c       |   10 ++++++++--
 2 files changed, 9 insertions(+), 3 deletions(-)
#1 lore raw

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

The HFS+ support in the kernel currently will mount an HFS+ volume read-only if the volume header has the attribute bit set that indicates there is a journal. The kernel does this because there is no support for a journalled HFS+ volume.

The problem is that this is only half of what needs to be checked to see if there really is a journal. There is also an entry in the volume header that tells you where to find the journal info block. In the kernel version of the kernel, this 4 byte block is labeled reserved. This patch identifies the journal info block in the 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 2/2 Fix journal detection on HFS+.

The code currently mounts an HFS+ volume read-only (unless given the "force" mount option) if it detects that the HFS+ volume has a journal. The code was unconditionally assuming that the volume had a jounal if the journal 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.

In this patch, I refactored the journal detection into a function since the logic is used twice. The journal detection also uses the better logic to determine if there is a journal.

---
 fs/hfsplus/super.c |   10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)
fs/hfsplus/super.c +8 -2
index eb74531..dcbcc24 100644
@@ -20,6 +20,12 @@ static void hfsplus_destroy_inode(struct inode *inode);
 
 #include "hfsplus_fs.h"
 
+static bool hfsplus_vol_has_journal(struct hfsplus_vh *vhdr)
+{
+	return (vhdr->attributes & cpu_to_be32(HFSPLUS_VOL_JOURNALED) &&
+				vhdr->journal_info_block);
+}
+
 struct inode *hfsplus_iget(struct super_block *sb, unsigned long ino)
 {
 	struct hfs_find_data fd;
@@ -260,7 +266,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 (hfsplus_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 +362,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 (hfsplus_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
#3 lore raw

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

Hi,

On Friday 21. November 2008, Warren Turkal wrote:

(Sorry for taking so long to get to this.)

fs/hfsplus/super.c static void hfsplus_destroy_inode(struct inode *inode); · line 27

Quoted 5 lines
fs/hfsplus/super.c +5 -0
+static bool hfsplus_vol_has_journal(struct hfsplus_vh *vhdr)
+{
+	return (vhdr->attributes & cpu_to_be32(HFSPLUS_VOL_JOURNALED) &&
+				vhdr->journal_info_block);
+}

I'm curious how common it is to have the journal bit set but no journal block, I haven't seen this case so far.
IMO more useful would be to read the journal block and check if there is anything that needs to be replayed.
If you're interested in a second step you could replay the journal, it's not that difficult to do, it's pretty much just copying blocks around.

bye, Roman

#4 lore raw

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

Quoted 2 lines · Roman Zippel

I'm curious how common it is to have the journal bit set but no journal block, I haven't seen this case so far.

It's so uncommon that the technote for HFS+ doesn't mention it. However, I did find [1], and it's (c) by Apple. Look at the comment at
[2] to see what tipped me off.

Quoted 4 lines

IMO more useful would be to read the journal block and check if there is anything that needs to be replayed.
If you're interested in a second step you could replay the journal, it's not that difficult to do, it's pretty much just copying blocks around.

I am actually looking into doing the journal replaying, but i haven't gotten around to it yet.

[1]http://fxr.watson.org/fxr/source/bsd/hfs/hfs_format.h?v=xnu-1228#L626 [2]http://fxr.watson.org/fxr/source/bsd/hfs/hfs_format.h?v=xnu-1228#L633

wt

#5 lore raw

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

Hi,

Quoted 7 lines · Warren Turkal
Quoted 2 lines · Roman Zippel

I'm curious how common it is to have the journal bit set but no journal block, I haven't seen this case so far.

It's so uncommon that the technote for HFS+ doesn't mention it. However, I did find [1], and it's (c) by Apple. Look at the comment at
[2] to see what tipped me off.

That likely also means the journal bit is cleared. If you want to verify this, you should check the actual kernel source and there I can't find anywhere, that they handle a zero journal block specially, thus it will result in a failure to replay the journal, so I don't see why we should allow write access to the volume in this case.

Quoted 7 lines
Quoted 4 lines

IMO more useful would be to read the journal block and check if there is anything that needs to be replayed.
If you're interested in a second step you could replay the journal, it's not that difficult to do, it's pretty much just copying blocks around.

I am actually looking into doing the journal replaying, but i haven't gotten around to it yet.

That's why I suggested to do the replay check first, as it's relatively simple to do.

bye, Roman

#6 lore raw

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

I have a drive that has the property of having the journal bit set and having 0 in the journal_info_block field that mounts in rw on MacOS X. That's how I discovered the problem.

wt

Quoted 31 lines · Roman Zippel

Hi,

Quoted 7 lines · Warren Turkal
Quoted 2 lines · Roman Zippel

I'm curious how common it is to have the journal bit set but no journal block, I haven't seen this case so far.

It's so uncommon that the technote for HFS+ doesn't mention it. However, I did find [1], and it's (c) by Apple. Look at the comment at
[2] to see what tipped me off.

That likely also means the journal bit is cleared. If you want to verify this, you should check the actual kernel source and there I can't find anywhere, that they handle a zero journal block specially, thus it will result in a failure to replay the journal, so I don't see why we should allow write access to the volume in this case.

Quoted 7 lines
Quoted 4 lines

IMO more useful would be to read the journal block and check if there is anything that needs to be replayed.
If you're interested in a second step you could replay the journal, it's not that difficult to do, it's pretty much just copying blocks around.

I am actually looking into doing the journal replaying, but i haven't gotten around to it yet.

That's why I suggested to do the replay check first, as it's relatively simple to do.

bye, Roman

#7 lore raw

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

Hi,

Quoted 3 lines · Warren Turkal

I have a drive that has the property of having the journal bit set and having 0 in the journal_info_block field that mounts in rw on MacOS X. That's how I discovered the problem.

Which OS X version? How was that drive created?
Is the journal info block still zero after being mounted in OS X? Does Disk Utility report the drive as journaled?

The main point I don't understand is how it became zero in first place. OS X will certainly mount such a drive, but I'd expect it'll simply reinitialize the journal.

bye, Roman

#8 lore raw

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

In reply to Warren Turkal

Hi,

Quoted 3 lines · Warren Turkal

I have a drive that has the property of having the journal bit set and having 0 in the journal_info_block field that mounts in rw on MacOS X. That's how I discovered the problem.

Another possibility: Was the drive mounted under any other OS? Maybe some other OS cleared that block while mounting and continued without journal, so that OS X would be forced to reinitialize the journal.

bye, Roman