@@ -408,6 +408,12 @@ static int ntfs_fs_reconfigure(struct fs_context *fc)
408408 struct ntfs_mount_options * new_opts = fc -> fs_private ;
409409 int ro_rw ;
410410
411+ /* If ntfs3 is used as legacy ntfs enforce read-only mode. */
412+ if (is_legacy_ntfs (sb )) {
413+ fc -> sb_flags |= SB_RDONLY ;
414+ goto out ;
415+ }
416+
411417 ro_rw = sb_rdonly (sb ) && !(fc -> sb_flags & SB_RDONLY );
412418 if (ro_rw && (sbi -> flags & NTFS_FLAGS_NEED_REPLAY )) {
413419 errorf (fc ,
@@ -427,15 +433,15 @@ static int ntfs_fs_reconfigure(struct fs_context *fc)
427433 fc ,
428434 "ntfs3: Cannot use different iocharset when remounting!" );
429435
430- sync_filesystem (sb );
431-
432436 if (ro_rw && (sbi -> volume .flags & VOLUME_FLAG_DIRTY ) &&
433437 !new_opts -> force ) {
434438 errorf (fc ,
435439 "ntfs3: Volume is dirty and \"force\" flag is not set!" );
436440 return - EINVAL ;
437441 }
438442
443+ out :
444+ sync_filesystem (sb );
439445 swap (sbi -> options , fc -> fs_private );
440446
441447 return 0 ;
@@ -1613,6 +1619,8 @@ static int ntfs_fill_super(struct super_block *sb, struct fs_context *fc)
16131619 }
16141620#endif
16151621
1622+ if (is_legacy_ntfs (sb ))
1623+ sb -> s_flags |= SB_RDONLY ;
16161624 return 0 ;
16171625
16181626put_inode_out :
@@ -1730,7 +1738,7 @@ static const struct fs_context_operations ntfs_context_ops = {
17301738 * This will called when mount/remount. We will first initialize
17311739 * options so that if remount we can use just that.
17321740 */
1733- static int ntfs_init_fs_context (struct fs_context * fc )
1741+ static int __ntfs_init_fs_context (struct fs_context * fc )
17341742{
17351743 struct ntfs_mount_options * opts ;
17361744 struct ntfs_sb_info * sbi ;
@@ -1778,6 +1786,11 @@ static int ntfs_init_fs_context(struct fs_context *fc)
17781786 return - ENOMEM ;
17791787}
17801788
1789+ static int ntfs_init_fs_context (struct fs_context * fc )
1790+ {
1791+ return __ntfs_init_fs_context (fc );
1792+ }
1793+
17811794static void ntfs3_kill_sb (struct super_block * sb )
17821795{
17831796 struct ntfs_sb_info * sbi = sb -> s_fs_info ;
@@ -1800,10 +1813,20 @@ static struct file_system_type ntfs_fs_type = {
18001813};
18011814
18021815#if IS_ENABLED (CONFIG_NTFS_FS )
1816+ static int ntfs_legacy_init_fs_context (struct fs_context * fc )
1817+ {
1818+ int ret ;
1819+
1820+ ret = __ntfs_init_fs_context (fc );
1821+ /* If ntfs3 is used as legacy ntfs enforce read-only mode. */
1822+ fc -> sb_flags |= SB_RDONLY ;
1823+ return ret ;
1824+ }
1825+
18031826static struct file_system_type ntfs_legacy_fs_type = {
18041827 .owner = THIS_MODULE ,
18051828 .name = "ntfs" ,
1806- .init_fs_context = ntfs_init_fs_context ,
1829+ .init_fs_context = ntfs_legacy_init_fs_context ,
18071830 .parameters = ntfs_fs_parameters ,
18081831 .kill_sb = ntfs3_kill_sb ,
18091832 .fs_flags = FS_REQUIRES_DEV | FS_ALLOW_IDMAP ,
@@ -1821,9 +1844,14 @@ static inline void unregister_as_ntfs_legacy(void)
18211844{
18221845 unregister_filesystem (& ntfs_legacy_fs_type );
18231846}
1847+ bool is_legacy_ntfs (struct super_block * sb )
1848+ {
1849+ return sb -> s_type == & ntfs_legacy_fs_type ;
1850+ }
18241851#else
18251852static inline void register_as_ntfs_legacy (void ) {}
18261853static inline void unregister_as_ntfs_legacy (void ) {}
1854+ bool is_legacy_ntfs (struct super_block * sb ) { return false; }
18271855#endif
18281856
18291857
0 commit comments