msdosfs & ffs: flush cache if updating mount from r/w to r/o
authorsf <sf@openbsd.org>
Mon, 29 May 2017 14:07:16 +0000 (14:07 +0000)
committersf <sf@openbsd.org>
Mon, 29 May 2017 14:07:16 +0000 (14:07 +0000)
ok deraadt@

sys/msdosfs/msdosfs_vfsops.c
sys/ufs/ffs/ffs_vfsops.c

index e13b0b1..5c426a2 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: msdosfs_vfsops.c,v 1.83 2016/10/10 00:34:50 bluhm Exp $       */
+/*     $OpenBSD: msdosfs_vfsops.c,v 1.84 2017/05/29 14:07:16 sf Exp $  */
 /*     $NetBSD: msdosfs_vfsops.c,v 1.48 1997/10/18 02:54:57 briggs Exp $       */
 
 /*-
@@ -64,6 +64,7 @@
 #include <sys/malloc.h>
 #include <sys/dirent.h>
 #include <sys/disk.h>
+#include <sys/dkio.h>
 #include <sys/stdint.h>
 
 #include <msdosfs/bpb.h>
@@ -128,8 +129,14 @@ msdosfs_mount(struct mount *mp, const char *path, void *data,
                        if (mp->mnt_flag & MNT_FORCE)
                                flags |= FORCECLOSE;
                        error = vflush(mp, NULLVP, flags);
-                       if (!error)
+                       if (!error) {
+                               int force = 0;
+
                                pmp->pm_flags |= MSDOSFSMNT_RONLY;
+                               /* may be not supported, ignore error */
+                               VOP_IOCTL(pmp->pm_devvp, DIOCCACHESYNC,
+                                   &force, FWRITE, FSCRED, p);
+                       }
                }
                if (!error && (mp->mnt_flag & MNT_RELOAD))
                        /* not yet implemented */
index 0770e9a..d0894ff 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: ffs_vfsops.c,v 1.165 2017/04/20 14:13:00 visa Exp $   */
+/*     $OpenBSD: ffs_vfsops.c,v 1.166 2017/05/29 14:07:16 sf Exp $     */
 /*     $NetBSD: ffs_vfsops.c,v 1.19 1996/02/09 22:22:26 christos Exp $ */
 
 /*
@@ -456,6 +456,16 @@ success:
                                fs->fs_flags &= ~FS_DOSOFTDEP;
                }
                ffs_sbupdate(ump, MNT_WAIT);
+               if (ronly) {
+                       int force = 0;
+
+                       /*
+                        * Updating mount to readonly. Try a cache flush.
+                        * Ignore error because the ioctl may not be supported.
+                        */
+                       VOP_IOCTL(ump->um_devvp, DIOCCACHESYNC, &force,
+                           FWRITE, FSCRED, p);
+               }
        }
        return (0);