Commit 1ff2e956 authored by Konstantin Komarov's avatar Konstantin Komarov

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) <willy@infradead.org>
Cc: Christian Brauner <brauner@kernel.org>
Signed-off-by: default avatarKonstantin Komarov <almaz.alexandrovich@paragon-software.com>
parent b9906f81
......@@ -631,10 +631,12 @@ const struct file_operations ntfs_dir_operations = {
#endif
};
#if IS_ENABLED(CONFIG_NTFS_FS)
const struct file_operations ntfs_legacy_dir_operations = {
.llseek = generic_file_llseek,
.read = generic_read_dir,
.iterate_shared = ntfs_readdir,
.open = ntfs_file_open,
};
#endif
// clang-format on
......@@ -1242,6 +1242,7 @@ const struct file_operations ntfs_file_operations = {
.release = ntfs_file_release,
};
#if IS_ENABLED(CONFIG_NTFS_FS)
const struct file_operations ntfs_legacy_file_operations = {
.llseek = generic_file_llseek,
.read_iter = ntfs_file_read_iter,
......@@ -1249,4 +1250,5 @@ const struct file_operations ntfs_legacy_file_operations = {
.open = ntfs_file_open,
.release = ntfs_file_release,
};
#endif
// clang-format on
......@@ -441,10 +441,9 @@ static struct inode *ntfs_read_mft(struct inode *inode,
* Usually a hard links to directories are disabled.
*/
inode->i_op = &ntfs_dir_inode_operations;
if (is_legacy_ntfs(inode->i_sb))
inode->i_fop = &ntfs_legacy_dir_operations;
else
inode->i_fop = &ntfs_dir_operations;
inode->i_fop = unlikely(is_legacy_ntfs(sb)) ?
&ntfs_legacy_dir_operations :
&ntfs_dir_operations;
ni->i_valid = 0;
} else if (S_ISLNK(mode)) {
ni->std_fa &= ~FILE_ATTRIBUTE_DIRECTORY;
......@@ -454,10 +453,9 @@ static struct inode *ntfs_read_mft(struct inode *inode,
} else if (S_ISREG(mode)) {
ni->std_fa &= ~FILE_ATTRIBUTE_DIRECTORY;
inode->i_op = &ntfs_file_inode_operations;
if (is_legacy_ntfs(inode->i_sb))
inode->i_fop = &ntfs_legacy_file_operations;
else
inode->i_fop = &ntfs_file_operations;
inode->i_fop = unlikely(is_legacy_ntfs(sb)) ?
&ntfs_legacy_file_operations :
&ntfs_file_operations;
inode->i_mapping->a_ops = is_compressed(ni) ? &ntfs_aops_cmpr :
&ntfs_aops;
if (ino != MFT_REC_MFT)
......@@ -1627,10 +1625,9 @@ int ntfs_create_inode(struct mnt_idmap *idmap, struct inode *dir,
if (S_ISDIR(mode)) {
inode->i_op = &ntfs_dir_inode_operations;
if (is_legacy_ntfs(inode->i_sb))
inode->i_fop = &ntfs_legacy_dir_operations;
else
inode->i_fop = &ntfs_dir_operations;
inode->i_fop = unlikely(is_legacy_ntfs(sb)) ?
&ntfs_legacy_dir_operations :
&ntfs_dir_operations;
} else if (S_ISLNK(mode)) {
inode->i_op = &ntfs_link_inode_operations;
inode->i_fop = NULL;
......@@ -1639,10 +1636,9 @@ int ntfs_create_inode(struct mnt_idmap *idmap, struct inode *dir,
inode_nohighmem(inode);
} else if (S_ISREG(mode)) {
inode->i_op = &ntfs_file_inode_operations;
if (is_legacy_ntfs(inode->i_sb))
inode->i_fop = &ntfs_legacy_file_operations;
else
inode->i_fop = &ntfs_file_operations;
inode->i_fop = unlikely(is_legacy_ntfs(sb)) ?
&ntfs_legacy_file_operations :
&ntfs_file_operations;
inode->i_mapping->a_ops = is_compressed(ni) ? &ntfs_aops_cmpr :
&ntfs_aops;
init_rwsem(&ni->file.run_lock);
......
......@@ -1140,6 +1140,13 @@ static inline void le64_sub_cpu(__le64 *var, u64 val)
*var = cpu_to_le64(le64_to_cpu(*var) - val);
}
#if IS_ENABLED(CONFIG_NTFS_FS)
bool is_legacy_ntfs(struct super_block *sb);
#else
static inline bool is_legacy_ntfs(struct super_block *sb)
{
return false;
}
#endif
#endif /* _LINUX_NTFS3_NTFS_FS_H */
......@@ -1837,10 +1837,8 @@ bool is_legacy_ntfs(struct super_block *sb)
#else
static inline void register_as_ntfs_legacy(void) {}
static inline void unregister_as_ntfs_legacy(void) {}
bool is_legacy_ntfs(struct super_block *sb) { return false; }
#endif
// clang-format on
static int __init init_ntfs_fs(void)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment