@@ -53,16 +53,19 @@ static void bch2_vfs_inode_init(struct btree_trans *, subvol_inum,
5353 struct bch_subvolume * );
5454
5555/* Set VFS inode flags from bcachefs inode: */
56- static inline void bch2_inode_flags_to_vfs (struct bch_inode_info * inode )
56+ static inline void bch2_inode_flags_to_vfs (struct bch_fs * c , struct bch_inode_info * inode )
5757{
5858 static const __maybe_unused unsigned bch_flags_to_vfs [] = {
5959 [__BCH_INODE_sync ] = S_SYNC ,
6060 [__BCH_INODE_immutable ] = S_IMMUTABLE ,
6161 [__BCH_INODE_append ] = S_APPEND ,
6262 [__BCH_INODE_noatime ] = S_NOATIME ,
63- [__BCH_INODE_casefolded ] = S_CASEFOLD ,
6463 };
64+
6565 set_flags (bch_flags_to_vfs , inode -> ei_inode .bi_flags , inode -> v .i_flags );
66+
67+ if (bch2_inode_casefold (c , & inode -> ei_inode ))
68+ inode -> v .i_flags |= S_CASEFOLD ;
6669}
6770
6871void bch2_inode_update_after_write (struct btree_trans * trans ,
@@ -93,7 +96,7 @@ void bch2_inode_update_after_write(struct btree_trans *trans,
9396
9497 inode -> ei_inode = * bi ;
9598
96- bch2_inode_flags_to_vfs (inode );
99+ bch2_inode_flags_to_vfs (c , inode );
97100}
98101
99102int __must_check bch2_write_inode (struct bch_fs * c ,
@@ -1470,7 +1473,6 @@ static const __maybe_unused unsigned bch_flags_to_uflags[] = {
14701473 [__BCH_INODE_append ] = FS_APPEND_FL ,
14711474 [__BCH_INODE_nodump ] = FS_NODUMP_FL ,
14721475 [__BCH_INODE_noatime ] = FS_NOATIME_FL ,
1473- [__BCH_INODE_casefolded ] = FS_CASEFOLD_FL ,
14741476};
14751477
14761478/* bcachefs inode flags -> FS_IOC_FSGETXATTR: */
@@ -1486,13 +1488,14 @@ static int bch2_fileattr_get(struct dentry *dentry,
14861488 struct fileattr * fa )
14871489{
14881490 struct bch_inode_info * inode = to_bch_ei (d_inode (dentry ));
1491+ struct bch_fs * c = inode -> v .i_sb -> s_fs_info ;
14891492
14901493 fileattr_fill_xflags (fa , map_flags (bch_flags_to_xflags , inode -> ei_inode .bi_flags ));
14911494
14921495 if (inode -> ei_inode .bi_fields_set & (1 << Inode_opt_project ))
14931496 fa -> fsx_xflags |= FS_XFLAG_PROJINHERIT ;
14941497
1495- if (inode -> ei_inode . bi_flags & BCH_INODE_casefolded )
1498+ if (bch2_inode_casefold ( c , & inode -> ei_inode ) )
14961499 fa -> flags |= FS_CASEFOLD_FL ;
14971500
14981501 fa -> fsx_projid = inode -> ei_qid .q [QTYP_PRJ ];
@@ -1504,6 +1507,8 @@ struct flags_set {
15041507 unsigned flags ;
15051508 unsigned projid ;
15061509 bool set_project ;
1510+ bool set_casefold ;
1511+ bool casefold ;
15071512};
15081513
15091514static int fssetxattr_inode_update_fn (struct btree_trans * trans ,
@@ -1518,15 +1523,12 @@ static int fssetxattr_inode_update_fn(struct btree_trans *trans,
15181523 * We're relying on btree locking here for exclusion with other ioctl
15191524 * calls - use the flags in the btree (@bi), not inode->i_flags:
15201525 */
1521- unsigned newflags = s -> flags ;
1522- unsigned oldflags = bi -> bi_flags & s -> mask ;
1523-
15241526 if (!S_ISREG (bi -> bi_mode ) &&
15251527 !S_ISDIR (bi -> bi_mode ) &&
1526- (newflags & (BCH_INODE_nodump |BCH_INODE_noatime )) != newflags )
1528+ (s -> flags & (BCH_INODE_nodump |BCH_INODE_noatime )) != s -> flags )
15271529 return - EINVAL ;
15281530
1529- if (( newflags ^ oldflags ) & BCH_INODE_casefolded ) {
1531+ if (s -> casefold != bch2_inode_casefold ( c , bi ) ) {
15301532#ifdef CONFIG_UNICODE
15311533 int ret = 0 ;
15321534 /* Not supported on individual files. */
@@ -1546,6 +1548,10 @@ static int fssetxattr_inode_update_fn(struct btree_trans *trans,
15461548 return ret ;
15471549
15481550 bch2_check_set_feature (c , BCH_FEATURE_casefolding );
1551+
1552+ bi -> bi_casefold = s -> casefold + 1 ;
1553+ bi -> bi_fields_set |= BIT (Inode_opt_casefold );
1554+
15491555#else
15501556 printk (KERN_ERR "Cannot use casefolding on a kernel without CONFIG_UNICODE\n" );
15511557 return - EOPNOTSUPP ;
@@ -1558,7 +1564,7 @@ static int fssetxattr_inode_update_fn(struct btree_trans *trans,
15581564 }
15591565
15601566 bi -> bi_flags &= ~s -> mask ;
1561- bi -> bi_flags |= newflags ;
1567+ bi -> bi_flags |= s -> flags ;
15621568
15631569 bi -> bi_ctime = timespec_to_bch2_time (c , current_time (& inode -> v ));
15641570 return 0 ;
@@ -1598,6 +1604,11 @@ static int bch2_fileattr_set(struct mnt_idmap *idmap,
15981604
15991605 if (fa -> flags_valid ) {
16001606 s .mask = map_defined (bch_flags_to_uflags );
1607+
1608+ s .set_casefold = true;
1609+ s .casefold = (fa -> flags & FS_CASEFOLD_FL ) != 0 ;
1610+ fa -> flags &= ~FS_CASEFOLD_FL ;
1611+
16011612 s .flags |= map_flags_rev (bch_flags_to_uflags , fa -> flags );
16021613 if (fa -> flags )
16031614 return - EOPNOTSUPP ;
0 commit comments