Skip to content

Commit d47059d

Browse files
GoodLuck612dubeyko
authored andcommitted
hfsplus: extract hidden directory search into a helper function
In hfsplus_fill_super(), the process of looking up the hidden directory involves initializing a catalog search, building a search key, reading the b-tree record, and releasing the search data. Currently, this logic is open-coded directly within the main superblock initialization routine. This makes hfsplus_fill_super() quite lengthy and its error handling paths less straightforward. Extract the hidden directory search sequence into a new helper function, hfsplus_get_hidden_dir_entry(). This improves overall code readability, cleanly encapsulates the hfs_find_data lifecycle, and simplifies the error exits in hfsplus_fill_super(). Signed-off-by: Zilin Guan <[email protected]> Reviewed-by: Viacheslav Dubeyko <[email protected]> Tested-by: Viacheslav Dubeyko <[email protected]> Signed-off-by: Viacheslav Dubeyko <[email protected]>
1 parent 90c500e commit d47059d

1 file changed

Lines changed: 32 additions & 12 deletions

File tree

fs/hfsplus/super.c

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -424,12 +424,35 @@ void hfsplus_prepare_volume_header_for_commit(struct hfsplus_vh *vhdr)
424424
vhdr->attributes |= cpu_to_be32(HFSPLUS_VOL_INCNSTNT);
425425
}
426426

427+
static inline int hfsplus_get_hidden_dir_entry(struct super_block *sb,
428+
const struct qstr *str,
429+
hfsplus_cat_entry *entry)
430+
{
431+
struct hfs_find_data fd;
432+
int err;
433+
434+
err = hfs_find_init(HFSPLUS_SB(sb)->cat_tree, &fd);
435+
if (unlikely(err))
436+
return err;
437+
438+
err = hfsplus_cat_build_key(sb, fd.search_key, HFSPLUS_ROOT_CNID, str);
439+
if (unlikely(err))
440+
goto free_fd;
441+
442+
err = hfsplus_brec_read_cat(&fd, entry);
443+
if (err)
444+
err = -ENOENT;
445+
446+
free_fd:
447+
hfs_find_exit(&fd);
448+
return err;
449+
}
450+
427451
static int hfsplus_fill_super(struct super_block *sb, struct fs_context *fc)
428452
{
429453
struct hfsplus_vh *vhdr;
430454
struct hfsplus_sb_info *sbi = HFSPLUS_SB(sb);
431455
hfsplus_cat_entry entry;
432-
struct hfs_find_data fd;
433456
struct inode *root, *inode;
434457
struct qstr str;
435458
struct nls_table *nls;
@@ -565,16 +588,14 @@ static int hfsplus_fill_super(struct super_block *sb, struct fs_context *fc)
565588

566589
str.len = sizeof(HFSP_HIDDENDIR_NAME) - 1;
567590
str.name = HFSP_HIDDENDIR_NAME;
568-
err = hfs_find_init(sbi->cat_tree, &fd);
569-
if (err)
570-
goto out_put_root;
571-
err = hfsplus_cat_build_key(sb, fd.search_key, HFSPLUS_ROOT_CNID, &str);
572-
if (unlikely(err < 0)) {
573-
hfs_find_exit(&fd);
591+
err = hfsplus_get_hidden_dir_entry(sb, &str, &entry);
592+
if (err == -ENOENT) {
593+
/*
594+
* Hidden directory is absent or it cannot be read.
595+
*/
596+
} else if (unlikely(err)) {
574597
goto out_put_root;
575-
}
576-
if (!hfsplus_brec_read_cat(&fd, &entry)) {
577-
hfs_find_exit(&fd);
598+
} else {
578599
if (entry.type != cpu_to_be16(HFSPLUS_FOLDER)) {
579600
err = -EIO;
580601
goto out_put_root;
@@ -585,8 +606,7 @@ static int hfsplus_fill_super(struct super_block *sb, struct fs_context *fc)
585606
goto out_put_root;
586607
}
587608
sbi->hidden_dir = inode;
588-
} else
589-
hfs_find_exit(&fd);
609+
}
590610

591611
if (!sb_rdonly(sb)) {
592612
/*

0 commit comments

Comments
 (0)