mirror of
https://github.com/torvalds/linux.git
synced 2026-06-04 04:23:35 +02:00
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 <zilin@seu.edu.cn> Reviewed-by: Viacheslav Dubeyko <slava@dubeyko.com> Tested-by: Viacheslav Dubeyko <slava@dubeyko.com> Signed-off-by: Viacheslav Dubeyko <slava@dubeyko.com>
This commit is contained in:
parent
90c500e4fd
commit
d47059dcc4
|
|
@ -424,12 +424,35 @@ void hfsplus_prepare_volume_header_for_commit(struct hfsplus_vh *vhdr)
|
|||
vhdr->attributes |= cpu_to_be32(HFSPLUS_VOL_INCNSTNT);
|
||||
}
|
||||
|
||||
static inline int hfsplus_get_hidden_dir_entry(struct super_block *sb,
|
||||
const struct qstr *str,
|
||||
hfsplus_cat_entry *entry)
|
||||
{
|
||||
struct hfs_find_data fd;
|
||||
int err;
|
||||
|
||||
err = hfs_find_init(HFSPLUS_SB(sb)->cat_tree, &fd);
|
||||
if (unlikely(err))
|
||||
return err;
|
||||
|
||||
err = hfsplus_cat_build_key(sb, fd.search_key, HFSPLUS_ROOT_CNID, str);
|
||||
if (unlikely(err))
|
||||
goto free_fd;
|
||||
|
||||
err = hfsplus_brec_read_cat(&fd, entry);
|
||||
if (err)
|
||||
err = -ENOENT;
|
||||
|
||||
free_fd:
|
||||
hfs_find_exit(&fd);
|
||||
return err;
|
||||
}
|
||||
|
||||
static int hfsplus_fill_super(struct super_block *sb, struct fs_context *fc)
|
||||
{
|
||||
struct hfsplus_vh *vhdr;
|
||||
struct hfsplus_sb_info *sbi = HFSPLUS_SB(sb);
|
||||
hfsplus_cat_entry entry;
|
||||
struct hfs_find_data fd;
|
||||
struct inode *root, *inode;
|
||||
struct qstr str;
|
||||
struct nls_table *nls;
|
||||
|
|
@ -565,16 +588,14 @@ static int hfsplus_fill_super(struct super_block *sb, struct fs_context *fc)
|
|||
|
||||
str.len = sizeof(HFSP_HIDDENDIR_NAME) - 1;
|
||||
str.name = HFSP_HIDDENDIR_NAME;
|
||||
err = hfs_find_init(sbi->cat_tree, &fd);
|
||||
if (err)
|
||||
err = hfsplus_get_hidden_dir_entry(sb, &str, &entry);
|
||||
if (err == -ENOENT) {
|
||||
/*
|
||||
* Hidden directory is absent or it cannot be read.
|
||||
*/
|
||||
} else if (unlikely(err)) {
|
||||
goto out_put_root;
|
||||
err = hfsplus_cat_build_key(sb, fd.search_key, HFSPLUS_ROOT_CNID, &str);
|
||||
if (unlikely(err < 0)) {
|
||||
hfs_find_exit(&fd);
|
||||
goto out_put_root;
|
||||
}
|
||||
if (!hfsplus_brec_read_cat(&fd, &entry)) {
|
||||
hfs_find_exit(&fd);
|
||||
} else {
|
||||
if (entry.type != cpu_to_be16(HFSPLUS_FOLDER)) {
|
||||
err = -EIO;
|
||||
goto out_put_root;
|
||||
|
|
@ -585,8 +606,7 @@ static int hfsplus_fill_super(struct super_block *sb, struct fs_context *fc)
|
|||
goto out_put_root;
|
||||
}
|
||||
sbi->hidden_dir = inode;
|
||||
} else
|
||||
hfs_find_exit(&fd);
|
||||
}
|
||||
|
||||
if (!sb_rdonly(sb)) {
|
||||
/*
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user