Skip to content

Commit 1ff2e95

Browse files
fs/ntfs3: Redesign legacy ntfs support
1) Make is_legacy_ntfs static inline. 2) Put legacy file_operations under #if IS_ENABLED(CONFIG_NTFS_FS). Cc: Matthew Wilcox (Oracle) <[email protected]> Cc: Christian Brauner <[email protected]> Signed-off-by: Konstantin Komarov <[email protected]>
1 parent b9906f8 commit 1ff2e95

File tree

5 files changed

+23
-18
lines changed

5 files changed

+23
-18
lines changed

fs/ntfs3/dir.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,10 +631,12 @@ const struct file_operations ntfs_dir_operations = {
631631
#endif
632632
};
633633

634+
#if IS_ENABLED(CONFIG_NTFS_FS)
634635
const struct file_operations ntfs_legacy_dir_operations = {
635636
.llseek = generic_file_llseek,
636637
.read = generic_read_dir,
637638
.iterate_shared = ntfs_readdir,
638639
.open = ntfs_file_open,
639640
};
641+
#endif
640642
// clang-format on

fs/ntfs3/file.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,11 +1242,13 @@ const struct file_operations ntfs_file_operations = {
12421242
.release = ntfs_file_release,
12431243
};
12441244

1245+
#if IS_ENABLED(CONFIG_NTFS_FS)
12451246
const struct file_operations ntfs_legacy_file_operations = {
12461247
.llseek = generic_file_llseek,
12471248
.read_iter = ntfs_file_read_iter,
12481249
.splice_read = ntfs_file_splice_read,
12491250
.open = ntfs_file_open,
12501251
.release = ntfs_file_release,
12511252
};
1253+
#endif
12521254
// clang-format on

fs/ntfs3/inode.c

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -441,10 +441,9 @@ static struct inode *ntfs_read_mft(struct inode *inode,
441441
* Usually a hard links to directories are disabled.
442442
*/
443443
inode->i_op = &ntfs_dir_inode_operations;
444-
if (is_legacy_ntfs(inode->i_sb))
445-
inode->i_fop = &ntfs_legacy_dir_operations;
446-
else
447-
inode->i_fop = &ntfs_dir_operations;
444+
inode->i_fop = unlikely(is_legacy_ntfs(sb)) ?
445+
&ntfs_legacy_dir_operations :
446+
&ntfs_dir_operations;
448447
ni->i_valid = 0;
449448
} else if (S_ISLNK(mode)) {
450449
ni->std_fa &= ~FILE_ATTRIBUTE_DIRECTORY;
@@ -454,10 +453,9 @@ static struct inode *ntfs_read_mft(struct inode *inode,
454453
} else if (S_ISREG(mode)) {
455454
ni->std_fa &= ~FILE_ATTRIBUTE_DIRECTORY;
456455
inode->i_op = &ntfs_file_inode_operations;
457-
if (is_legacy_ntfs(inode->i_sb))
458-
inode->i_fop = &ntfs_legacy_file_operations;
459-
else
460-
inode->i_fop = &ntfs_file_operations;
456+
inode->i_fop = unlikely(is_legacy_ntfs(sb)) ?
457+
&ntfs_legacy_file_operations :
458+
&ntfs_file_operations;
461459
inode->i_mapping->a_ops = is_compressed(ni) ? &ntfs_aops_cmpr :
462460
&ntfs_aops;
463461
if (ino != MFT_REC_MFT)
@@ -1627,10 +1625,9 @@ int ntfs_create_inode(struct mnt_idmap *idmap, struct inode *dir,
16271625

16281626
if (S_ISDIR(mode)) {
16291627
inode->i_op = &ntfs_dir_inode_operations;
1630-
if (is_legacy_ntfs(inode->i_sb))
1631-
inode->i_fop = &ntfs_legacy_dir_operations;
1632-
else
1633-
inode->i_fop = &ntfs_dir_operations;
1628+
inode->i_fop = unlikely(is_legacy_ntfs(sb)) ?
1629+
&ntfs_legacy_dir_operations :
1630+
&ntfs_dir_operations;
16341631
} else if (S_ISLNK(mode)) {
16351632
inode->i_op = &ntfs_link_inode_operations;
16361633
inode->i_fop = NULL;
@@ -1639,10 +1636,9 @@ int ntfs_create_inode(struct mnt_idmap *idmap, struct inode *dir,
16391636
inode_nohighmem(inode);
16401637
} else if (S_ISREG(mode)) {
16411638
inode->i_op = &ntfs_file_inode_operations;
1642-
if (is_legacy_ntfs(inode->i_sb))
1643-
inode->i_fop = &ntfs_legacy_file_operations;
1644-
else
1645-
inode->i_fop = &ntfs_file_operations;
1639+
inode->i_fop = unlikely(is_legacy_ntfs(sb)) ?
1640+
&ntfs_legacy_file_operations :
1641+
&ntfs_file_operations;
16461642
inode->i_mapping->a_ops = is_compressed(ni) ? &ntfs_aops_cmpr :
16471643
&ntfs_aops;
16481644
init_rwsem(&ni->file.run_lock);

fs/ntfs3/ntfs_fs.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,6 +1140,13 @@ static inline void le64_sub_cpu(__le64 *var, u64 val)
11401140
*var = cpu_to_le64(le64_to_cpu(*var) - val);
11411141
}
11421142

1143+
#if IS_ENABLED(CONFIG_NTFS_FS)
11431144
bool is_legacy_ntfs(struct super_block *sb);
1145+
#else
1146+
static inline bool is_legacy_ntfs(struct super_block *sb)
1147+
{
1148+
return false;
1149+
}
1150+
#endif
11441151

11451152
#endif /* _LINUX_NTFS3_NTFS_FS_H */

fs/ntfs3/super.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1837,10 +1837,8 @@ bool is_legacy_ntfs(struct super_block *sb)
18371837
#else
18381838
static inline void register_as_ntfs_legacy(void) {}
18391839
static inline void unregister_as_ntfs_legacy(void) {}
1840-
bool is_legacy_ntfs(struct super_block *sb) { return false; }
18411840
#endif
18421841

1843-
18441842
// clang-format on
18451843

18461844
static int __init init_ntfs_fs(void)

0 commit comments

Comments
 (0)