Re: [PATCH 1/2] fs: btrfs: implement opendir(), readdir() and closedir()
Qu Wenruo <[email protected]>
| Newsgroups | org.kernel.vger.linux-btrfs,org.u-boot-project.lists.u-boot |
|---|---|
| Message-ID | <[email protected]> |
在 2026/6/26 18:51, Alexey Charkov 写道: > On Fri, Jun 26, 2026 at 10:38 AM Qu Wenruo <[email protected]> wrote: [...] >> >> So it looks like u-boot only supports the above 3 types, and unlike >> linux kernel the values doesn't match the btrfs internal ones. >> >> In that case, I'd still prefer a proper convertor function. > > Hmm, but the convertor function would still be the same switch > statement, and it's only used in this single place. Would factoring it > out actually improve readability? This is mostly a cross-project tendency. Inside kernel, we do not need a conversion because all the BTRFS_FT* flags matches the FT_* inside kernel. In progs we have btrfs_type_to_imode() to do the conversion to S_IF* flags. Thus I'd prefer a convertor, even if there is only a single user. > >> [...] >>> + >>> + *offset = key.offset + 1; >>> + type = btrfs_dir_type(path.nodes[0], di); >>> + >>> + /* XATTRs share the key space but are not directory entries. */ >>> + if (type == BTRFS_FT_XATTR) { >> >> This doesn't looks correct again. >> >> XATTR has their own keys, they should not show up among DIR_INDEX keys. Firstly, xattr is per-inode, not per-dentry. Thus I doubt if you can hit an XATTR type inside a DIR_INDEX. The easily way to test the theory is just create a simple XATTR for compression: # mkfs.btrfs -f test.img # mount test.img /mnt/btrfs # touch /mnt/btrfs/foobar # btrfs prop set /mnt/btrfs/foobar compression zstd # sync # btrfs ins dump-tree -t 5 test.img [...] item 6 key (257 XATTR_ITEM 550297449) itemoff 15812 itemsize 51 location key (0 UNKNOWN.0 0) type XATTR transid 10 data_len 4 name_len 17 name: btrfs.compression data zstd You can see that XATTR_ITEM key is for that inode 257, not for the parent directory inode (256). Secondly, if you check the tree-checker.c from the kernel, check_dir_item() will reject an XATTR dir type if the key is not XATTR_ITEM_KEY. So even if you really find a btrfs with XATTR dir type but with DIR_INDEX key, btrfs will refuse to reject that tree block. Thanks, Qu > > Let me double check and adjust accordingly. > > Thanks a lot for your review! > > Best regards, > Alexey