Skip to content

Commit af8c85b

Browse files
Roman ZippelLinus Torvalds
authored andcommitted
[PATCH] hfs: set correct create date for links
HFS+ also requires the correct creation date so recent version of OS X recognize it as link. Improve link handling: - if something is wrong with the link, ignore the link attribute and treat it as regular file (this also fixes a missing unlock during lookup). - check for incorrect link counts during unlink. Signed-off-by: Roman Zippel <zippel@linux-m68k.org> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
1 parent 9a4cad9 commit af8c85b

2 files changed

Lines changed: 22 additions & 12 deletions

File tree

‎fs/hfsplus/catalog.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ static int hfsplus_cat_build_record(hfsplus_cat_entry *entry, u32 cnid, struct i
127127
file->user_info.fdType = cpu_to_be32(HFSP_HARDLINK_TYPE);
128128
file->user_info.fdCreator = cpu_to_be32(HFSP_HFSPLUS_CREATOR);
129129
file->user_info.fdFlags = cpu_to_be16(0x100);
130+
file->create_date = HFSPLUS_I(HFSPLUS_SB(inode->i_sb).hidden_dir).create_date;
130131
file->permissions.dev = cpu_to_be32(HFSPLUS_I(inode).dev);
131132
}
132133
return sizeof(*file);

‎fs/hfsplus/dir.c‎

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,21 +66,28 @@ static struct dentry *hfsplus_lookup(struct inode *dir, struct dentry *dentry,
6666
}
6767
cnid = be32_to_cpu(entry.file.id);
6868
if (entry.file.user_info.fdType == cpu_to_be32(HFSP_HARDLINK_TYPE) &&
69-
entry.file.user_info.fdCreator == cpu_to_be32(HFSP_HFSPLUS_CREATOR)) {
69+
entry.file.user_info.fdCreator == cpu_to_be32(HFSP_HFSPLUS_CREATOR) &&
70+
(entry.file.create_date == HFSPLUS_I(HFSPLUS_SB(sb).hidden_dir).create_date ||
71+
entry.file.create_date == HFSPLUS_I(sb->s_root->d_inode).create_date) &&
72+
HFSPLUS_SB(sb).hidden_dir) {
7073
struct qstr str;
7174
char name[32];
7275

7376
if (dentry->d_fsdata) {
74-
err = -ENOENT;
75-
inode = NULL;
76-
goto out;
77+
/*
78+
* We found a link pointing to another link,
79+
* so ignore it and treat it as regular file.
80+
*/
81+
cnid = (unsigned long)dentry->d_fsdata;
82+
linkid = 0;
83+
} else {
84+
dentry->d_fsdata = (void *)(unsigned long)cnid;
85+
linkid = be32_to_cpu(entry.file.permissions.dev);
86+
str.len = sprintf(name, "iNode%d", linkid);
87+
str.name = name;
88+
hfsplus_cat_build_key(sb, fd.search_key, HFSPLUS_SB(sb).hidden_dir->i_ino, &str);
89+
goto again;
7790
}
78-
dentry->d_fsdata = (void *)(unsigned long)cnid;
79-
linkid = be32_to_cpu(entry.file.permissions.dev);
80-
str.len = sprintf(name, "iNode%d", linkid);
81-
str.name = name;
82-
hfsplus_cat_build_key(sb, fd.search_key, HFSPLUS_SB(sb).hidden_dir->i_ino, &str);
83-
goto again;
8491
} else if (!dentry->d_fsdata)
8592
dentry->d_fsdata = (void *)(unsigned long)cnid;
8693
} else {
@@ -330,7 +337,8 @@ static int hfsplus_unlink(struct inode *dir, struct dentry *dentry)
330337
if (res)
331338
return res;
332339

333-
inode->i_nlink--;
340+
if (inode->i_nlink > 0)
341+
inode->i_nlink--;
334342
hfsplus_delete_inode(inode);
335343
if (inode->i_ino != cnid && !inode->i_nlink) {
336344
if (!atomic_read(&HFSPLUS_I(inode).opencnt)) {
@@ -339,7 +347,8 @@ static int hfsplus_unlink(struct inode *dir, struct dentry *dentry)
339347
hfsplus_delete_inode(inode);
340348
} else
341349
inode->i_flags |= S_DEAD;
342-
}
350+
} else
351+
inode->i_nlink = 0;
343352
inode->i_ctime = CURRENT_TIME_SEC;
344353
mark_inode_dirty(inode);
345354

0 commit comments

Comments
 (0)