Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Zilin Guan and committed by
Viacheslav Dubeyko
d47059dc 90c500e4

+32 -12
+32 -12
fs/hfsplus/super.c
··· 424 424 vhdr->attributes |= cpu_to_be32(HFSPLUS_VOL_INCNSTNT); 425 425 } 426 426 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 + 427 451 static int hfsplus_fill_super(struct super_block *sb, struct fs_context *fc) 428 452 { 429 453 struct hfsplus_vh *vhdr; 430 454 struct hfsplus_sb_info *sbi = HFSPLUS_SB(sb); 431 455 hfsplus_cat_entry entry; 432 - struct hfs_find_data fd; 433 456 struct inode *root, *inode; 434 457 struct qstr str; 435 458 struct nls_table *nls; ··· 588 565 589 566 str.len = sizeof(HFSP_HIDDENDIR_NAME) - 1; 590 567 str.name = HFSP_HIDDENDIR_NAME; 591 - err = hfs_find_init(sbi->cat_tree, &fd); 592 - if (err) 568 + err = hfsplus_get_hidden_dir_entry(sb, &str, &entry); 569 + if (err == -ENOENT) { 570 + /* 571 + * Hidden directory is absent or it cannot be read. 572 + */ 573 + } else if (unlikely(err)) { 593 574 goto out_put_root; 594 - err = hfsplus_cat_build_key(sb, fd.search_key, HFSPLUS_ROOT_CNID, &str); 595 - if (unlikely(err < 0)) { 596 - hfs_find_exit(&fd); 597 - goto out_put_root; 598 - } 599 - if (!hfsplus_brec_read_cat(&fd, &entry)) { 600 - hfs_find_exit(&fd); 575 + } else { 601 576 if (entry.type != cpu_to_be16(HFSPLUS_FOLDER)) { 602 577 err = -EIO; 603 578 goto out_put_root; ··· 606 585 goto out_put_root; 607 586 } 608 587 sbi->hidden_dir = inode; 609 - } else 610 - hfs_find_exit(&fd); 588 + } 611 589 612 590 if (!sb_rdonly(sb)) { 613 591 /*