Skip to contentSkip to conversation

hfsplus: Fix bless ioctl when used with hardlinks

PATCH Superseded Matthew Garrett 2 participants 2 messages Apr 13, 2012 – Apr 14, 2012

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hfsplus: Fix bless ioctl when used with hardlinks

HFS+ doesn't really implement hard links - instead, hardlinks are indicated by a magic file type which refers to an indirect node in a hidden directory. The spec indicates that stat() should return the inode number of the indirect node, but it turns out that this doesn't satisfy the firmware when it's looking for a bootloader - it wants the catalog ID of the hardlink file instead. Fix up this case.

---
 fs/hfsplus/ioctl.c |    9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
fs/hfsplus/ioctl.c +7 -2
index c640ba5..5ee0681 100644
@@ -31,6 +31,7 @@ static int hfsplus_ioctl_bless(struct file *file, int __user *user_flags)
 	struct hfsplus_sb_info *sbi = HFSPLUS_SB(inode->i_sb);
 	struct hfsplus_vh *vh = sbi->s_vhdr;
 	struct hfsplus_vh *bvh = sbi->s_backup_vhdr;
+	int cnid = (u32)(unsigned long)dentry->d_fsdata;
 
 	if (!capable(CAP_SYS_ADMIN))
 		return -EPERM;
@@ -41,8 +42,12 @@ static int hfsplus_ioctl_bless(struct file *file, int __user *user_flags)
 	vh->finder_info[0] = bvh->finder_info[0] =
 		cpu_to_be32(parent_ino(dentry));
 
-	/* Bootloader */
-	vh->finder_info[1] = bvh->finder_info[1] = cpu_to_be32(inode->i_ino);
+	/*
+	 * Bootloader. Just using the inode here breaks in the case of
+	 * hard links - the firmware wants the ID of the hard link file,
+	 * but the inode points at the indirect inode
+	 */
+	vh->finder_info[1] = bvh->finder_info[1] = cpu_to_be32(cnid);
 
 	/* Per spec, the OS X system folder - same as finder_info[0] here */
 	vh->finder_info[5] = bvh->finder_info[5] =
Signature · 1 line
1.7.10
#1 lore raw

Il 13/04/2012 16:06, Matthew Garrett ha scritto:

Quoted 17 lines

HFS+ doesn't really implement hard links - instead, hardlinks are indicated by a magic file type which refers to an indirect node in a hidden directory. The spec indicates that stat() should return the inode number of the indirect node, but it turns out that this doesn't satisfy the firmware when it's looking for a bootloader - it wants the catalog ID of the hardlink file instead. Fix up this case.

---
  fs/hfsplus/ioctl.c |    9 +++++++--
  1 file changed, 7 insertions(+), 2 deletions(-)
fs/hfsplus/ioctl.c +0 -0
index c640ba5..5ee0681 100644

fs/hfsplus/ioctl.c static int hfsplus_ioctl_bless(struct file *file, int __user *user_flags) · line 35

Quoted 5 lines
fs/hfsplus/ioctl.c +1 -0
@@ -31,6 +31,7 @@ static int hfsplus_ioctl_bless(struct file *file, int __user *user_flags)
  	struct hfsplus_sb_info *sbi = HFSPLUS_SB(inode->i_sb);
  	struct hfsplus_vh *vh = sbi->s_vhdr;
  	struct hfsplus_vh *bvh = sbi->s_backup_vhdr;
+	int cnid = (u32)(unsigned long)dentry->d_fsdata;
 

Why a double cast?

Marco