The remount read-write path marks quotas out of date after emptying the logfile, but initial read-write mount only loads $Quota and never calls ntfs_mark_quotas_out_of_date(). That leaves quota tracking metadata looking up to date even though the driver can modify the volume. Call the same helper after $Quota is loaded during initial read-write mount. If marking quotas out of date fails and the mount policy is on_errors=remount-ro, convert the mount to read-only and set the volume error state, matching the nearby $Quota load failure handling. This intentionally follows the initial mount error policy rather than the remount-rw path, where a quota marking failure rejects the remount with -EROFS. Move the load/mark/policy handling into a small helper, ntfs_init_quota_for_mount(), which captures each call result in a local, derives the failure reason, and gates the read-only downgrade on policy in one place. This avoids calling helpers inside compound if conditions and keeps ntfs_load_system_files() flat. Signed-off-by: DaeMyung Kang --- fs/ntfs/super.c | 46 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 11 deletions(-) diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c index 22dc786..8fa298f 100644 --- a/fs/ntfs/super.c +++ b/fs/ntfs/super.c @@ -1221,6 +1221,39 @@ static bool load_and_init_quota(struct ntfs_volume *vol) return true; } +/* + * ntfs_init_quota_for_mount - finish quota setup at mount time + * @sb: super block of the volume being mounted + * @vol: ntfs volume to set up + * + * Load $Quota and, on a read-write mount, mark quotas out of date so that + * Windows rescans them on next boot. On failure, downgrade the mount to + * read-only when on_errors=remount-ro, matching the volume error policy. + */ +static void ntfs_init_quota_for_mount(struct super_block *sb, + struct ntfs_volume *vol) +{ + bool quota_loaded, quota_marked = true; + const char *reason = NULL; + + quota_loaded = load_and_init_quota(vol); + if (quota_loaded && !sb_rdonly(sb)) + quota_marked = ntfs_mark_quotas_out_of_date(vol); + + if (!quota_loaded) + reason = "Failed to load $Quota"; + else if (!quota_marked) + reason = "Failed to mark quotas out of date"; + + if (!reason || vol->on_errors != ON_ERRORS_REMOUNT_RO) + return; + + sb->s_flags |= SB_RDONLY; + ntfs_error(sb, "%s. Mounting read-only. Run chkdsk.", reason); + /* This will prevent a read-write remount. */ + NVolSetErrors(vol); +} + /* * load_and_init_attrdef - load the attribute definitions table for a volume * @vol: ntfs super block describing device whose attrdef to load @@ -1638,16 +1671,7 @@ get_ctx_vol_failed: ntfs_error(sb, "Failed to load $Extend."); goto iput_sec_err_out; } - /* Find the quota file, load it if present, and set it up. */ - if (!load_and_init_quota(vol) && - vol->on_errors == ON_ERRORS_REMOUNT_RO) { - static const char *es1 = "Failed to load $Quota"; - static const char *es2 = ". Run chkdsk."; - - sb->s_flags |= SB_RDONLY; - ntfs_error(sb, "%s. Mounting read-only%s", es1, es2); - /* This will prevent a read-write remount. */ - NVolSetErrors(vol); - } + /* Find the quota file, load it if present, and set it up. */ + ntfs_init_quota_for_mount(sb, vol); return true; -- 2.43.0