Skip to content

Commit 6352539

Browse files
dhowellsLinus Torvalds
authored andcommitted
iget: stop HFSPLUS from using iget() and read_inode()
Stop the HFSPLUS filesystem from using iget() and read_inode(). Replace hfsplus_read_inode() with hfsplus_iget(), and call that instead of iget(). hfsplus_iget() then uses iget_locked() directly and returns a proper error code instead of an inode in the event of an error. hfsplus_fill_super() returns any error incurred when getting the root inode. Signed-off-by: David Howells <[email protected]> Cc: Roman Zippel <[email protected]> Acked-by: Christoph Hellwig <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent fa300b1 commit 6352539

File tree

4 files changed

+43
-19
lines changed

4 files changed

+43
-19
lines changed

fs/hfsplus/btree.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ struct hfs_btree *hfs_btree_open(struct super_block *sb, u32 id)
2222
struct hfs_btree *tree;
2323
struct hfs_btree_header_rec *head;
2424
struct address_space *mapping;
25+
struct inode *inode;
2526
struct page *page;
2627
unsigned int size;
2728

@@ -33,9 +34,10 @@ struct hfs_btree *hfs_btree_open(struct super_block *sb, u32 id)
3334
spin_lock_init(&tree->hash_lock);
3435
tree->sb = sb;
3536
tree->cnid = id;
36-
tree->inode = iget(sb, id);
37-
if (!tree->inode)
37+
inode = hfsplus_iget(sb, id);
38+
if (IS_ERR(inode))
3839
goto free_tree;
40+
tree->inode = inode;
3941

4042
mapping = tree->inode->i_mapping;
4143
page = read_mapping_page(mapping, 0, NULL);

fs/hfsplus/dir.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@ static struct dentry *hfsplus_lookup(struct inode *dir, struct dentry *dentry,
9797
goto fail;
9898
}
9999
hfs_find_exit(&fd);
100-
inode = iget(dir->i_sb, cnid);
101-
if (!inode)
102-
return ERR_PTR(-EACCES);
100+
inode = hfsplus_iget(dir->i_sb, cnid);
101+
if (IS_ERR(inode))
102+
return ERR_CAST(inode);
103103
if (S_ISREG(inode->i_mode))
104104
HFSPLUS_I(inode).dev = linkid;
105105
out:

fs/hfsplus/hfsplus_fs.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,9 @@ int hfsplus_parse_options(char *, struct hfsplus_sb_info *);
345345
void hfsplus_fill_defaults(struct hfsplus_sb_info *);
346346
int hfsplus_show_options(struct seq_file *, struct vfsmount *);
347347

348+
/* super.c */
349+
struct inode *hfsplus_iget(struct super_block *, unsigned long);
350+
348351
/* tables.c */
349352
extern u16 hfsplus_case_fold_table[];
350353
extern u16 hfsplus_decompose_table[];

fs/hfsplus/super.c

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,18 @@ static void hfsplus_destroy_inode(struct inode *inode);
2020

2121
#include "hfsplus_fs.h"
2222

23-
static void hfsplus_read_inode(struct inode *inode)
23+
struct inode *hfsplus_iget(struct super_block *sb, unsigned long ino)
2424
{
2525
struct hfs_find_data fd;
2626
struct hfsplus_vh *vhdr;
27-
int err;
27+
struct inode *inode;
28+
long err = -EIO;
29+
30+
inode = iget_locked(sb, ino);
31+
if (!inode)
32+
return ERR_PTR(-ENOMEM);
33+
if (!(inode->i_state & I_NEW))
34+
return inode;
2835

2936
INIT_LIST_HEAD(&HFSPLUS_I(inode).open_dir_list);
3037
init_MUTEX(&HFSPLUS_I(inode).extents_lock);
@@ -41,7 +48,7 @@ static void hfsplus_read_inode(struct inode *inode)
4148
hfs_find_exit(&fd);
4249
if (err)
4350
goto bad_inode;
44-
return;
51+
goto done;
4552
}
4653
vhdr = HFSPLUS_SB(inode->i_sb).s_vhdr;
4754
switch(inode->i_ino) {
@@ -70,10 +77,13 @@ static void hfsplus_read_inode(struct inode *inode)
7077
goto bad_inode;
7178
}
7279

73-
return;
80+
done:
81+
unlock_new_inode(inode);
82+
return inode;
7483

75-
bad_inode:
76-
make_bad_inode(inode);
84+
bad_inode:
85+
iget_failed(inode);
86+
return ERR_PTR(err);
7787
}
7888

7989
static int hfsplus_write_inode(struct inode *inode, int unused)
@@ -262,7 +272,6 @@ static int hfsplus_remount(struct super_block *sb, int *flags, char *data)
262272
static const struct super_operations hfsplus_sops = {
263273
.alloc_inode = hfsplus_alloc_inode,
264274
.destroy_inode = hfsplus_destroy_inode,
265-
.read_inode = hfsplus_read_inode,
266275
.write_inode = hfsplus_write_inode,
267276
.clear_inode = hfsplus_clear_inode,
268277
.put_super = hfsplus_put_super,
@@ -278,7 +287,7 @@ static int hfsplus_fill_super(struct super_block *sb, void *data, int silent)
278287
struct hfsplus_sb_info *sbi;
279288
hfsplus_cat_entry entry;
280289
struct hfs_find_data fd;
281-
struct inode *root;
290+
struct inode *root, *inode;
282291
struct qstr str;
283292
struct nls_table *nls = NULL;
284293
int err = -EINVAL;
@@ -366,18 +375,25 @@ static int hfsplus_fill_super(struct super_block *sb, void *data, int silent)
366375
goto cleanup;
367376
}
368377

369-
HFSPLUS_SB(sb).alloc_file = iget(sb, HFSPLUS_ALLOC_CNID);
370-
if (!HFSPLUS_SB(sb).alloc_file) {
378+
inode = hfsplus_iget(sb, HFSPLUS_ALLOC_CNID);
379+
if (IS_ERR(inode)) {
371380
printk(KERN_ERR "hfs: failed to load allocation file\n");
381+
err = PTR_ERR(inode);
372382
goto cleanup;
373383
}
384+
HFSPLUS_SB(sb).alloc_file = inode;
374385

375386
/* Load the root directory */
376-
root = iget(sb, HFSPLUS_ROOT_CNID);
387+
root = hfsplus_iget(sb, HFSPLUS_ROOT_CNID);
388+
if (IS_ERR(root)) {
389+
printk(KERN_ERR "hfs: failed to load root directory\n");
390+
err = PTR_ERR(root);
391+
goto cleanup;
392+
}
377393
sb->s_root = d_alloc_root(root);
378394
if (!sb->s_root) {
379-
printk(KERN_ERR "hfs: failed to load root directory\n");
380395
iput(root);
396+
err = -ENOMEM;
381397
goto cleanup;
382398
}
383399
sb->s_root->d_op = &hfsplus_dentry_operations;
@@ -390,9 +406,12 @@ static int hfsplus_fill_super(struct super_block *sb, void *data, int silent)
390406
hfs_find_exit(&fd);
391407
if (entry.type != cpu_to_be16(HFSPLUS_FOLDER))
392408
goto cleanup;
393-
HFSPLUS_SB(sb).hidden_dir = iget(sb, be32_to_cpu(entry.folder.id));
394-
if (!HFSPLUS_SB(sb).hidden_dir)
409+
inode = hfsplus_iget(sb, be32_to_cpu(entry.folder.id));
410+
if (IS_ERR(inode)) {
411+
err = PTR_ERR(inode);
395412
goto cleanup;
413+
}
414+
HFSPLUS_SB(sb).hidden_dir = inode;
396415
} else
397416
hfs_find_exit(&fd);
398417

0 commit comments

Comments
 (0)