Index: /trunk/src/VBox/Additions/solaris/SharedFolders/vboxfs_vnode.c
===================================================================
--- /trunk/src/VBox/Additions/solaris/SharedFolders/vboxfs_vnode.c	(revision 38900)
+++ /trunk/src/VBox/Additions/solaris/SharedFolders/vboxfs_vnode.c	(revision 38901)
@@ -97,4 +97,6 @@
 #include "vboxfs_vfs.h"
 
+#define VBOXVFS_WITH_MMAP
+
 static struct vnodeops *sffs_ops = NULL;
 
@@ -212,5 +214,8 @@
 		vp->v_vfsp = node->sf_sffs->sf_vfsp;
 		vn_setops(vp, sffs_ops);
-		vp->v_flag = VNOSWAP | VNOMAP;	/* @todo -XXX- remove VNOMAP when ro-mmap is working*/
+		vp->v_flag = VNOSWAP;
+#ifndef VBOXVFS_WITH_MMAP
+		vp->v_flag |= VNOMAP;
+#endif
 		vn_exists(vp);
 		vp->v_data = node;
@@ -1405,5 +1410,5 @@
 	}
 
-#if 0
+#ifdef VBOXVFS_WITH_MMAP
 	if (vn_vfswlock(vp)) {
 		VN_RELE(vp);
@@ -1457,5 +1462,5 @@
 
 
-#if 0
+#ifdef VBOXVFS_WITH_MMAP
 static caddr_t
 sffs_page_map(
@@ -1487,5 +1492,5 @@
  * the file data into it.
  */
-int
+static int
 sffs_readpages(
 	vnode_t		*dvp,
@@ -1509,12 +1514,8 @@
 	ASSERT(node->sf_file);
 
-	cmn_err(CE_NOTE, "sffs_readpages\n");
 	if (pagelistsize == PAGESIZE)
 	{
 		io_off = off;
 		io_len = PAGESIZE;
-
-		cmn_err(CE_NOTE, "sffs_readpages io_off=%lld io_len=%lld\n", (u_longlong_t)io_off, (u_longlong_t)io_len);
-
 		ppages = page_create_va(dvp, io_off, io_len, PG_WAIT | PG_EXCL, segp, addr);
 	}
@@ -1525,5 +1526,4 @@
 	if (!ppages)
 	{
-		cmn_err(CE_NOTE, "sffs_readpages nothing done\n");
 		*pagelist = NULL;
 		return (0);
@@ -1539,11 +1539,11 @@
 		ASSERT3U(io_off, ==, pcur->p_offset);
 
-		cmn_err(CE_NOTE, "sffs_readpages page-by-page reading io_off=%lld\n", (u_longlong_t)io_off);
 		caddr_t virtaddr = sffs_page_map(pcur, segaccess);
 		uint32_t bytes = PAGESIZE;
 		error = sfprov_read(node->sf_file, virtaddr, io_off, &bytes);
 		sffs_page_unmap(pcur, virtaddr);
-		if (error != 0 || bytes < PAGESIZE)
+		if (error != 0)
 		{
+			cmn_err(CE_WARN, "sffs_readpages: sfprov_read() failed. error=%d bytes=%ld\n", error, bytes);
 			/* Get rid of all kluster pages read & bail.  */
 			pvn_read_done(ppages,  B_ERROR);
@@ -1559,6 +1559,4 @@
 	pvn_plist_init(ppages, pagelist, pagelistsize, off, io_len, segaccess);
 	ASSERT(pagelist == NULL || (*pagelist)->p_offset == off);
-	cmn_err(CE_NOTE, "sffs_readpages done\n");
-
 	return (0);
 }
@@ -1631,5 +1629,4 @@
 		}
 
-		cmn_err(CE_NOTE, "sffs_getpage addr=%p len=%lld off=%lld\n", addr, (u_longlong_t)len, (u_longlong_t)off);
 		while (*pagelist)
 		{
@@ -1661,5 +1658,4 @@
 	*pagelist = NULL;
 	mutex_exit(&sffs_lock);
-	cmn_err(CE_NOTE,  "sffs_getpage done\n");
 	return (error);
 }
@@ -1684,4 +1680,23 @@
 	 */
 	return (ENOSYS);
+}
+
+
+/*ARGSUSED*/
+static int
+sffs_discardpage(
+	vnode_t		*dvp,
+	page_t		*ppage,
+	u_offset_t	*poff,
+	size_t		*plen,
+	int			flags,
+	cred_t		*pcred)
+{
+	/*
+	 * We don't support PROT_WRITE mmaps. Just pretend we're done writing back
+	 * to the disk while unmounting/closing the node and discarding the mapped pages.
+	 */
+	pvn_write_done(ppage, B_INVAL | B_ERROR | B_FORCE);
+	return (0);
 }
 
@@ -1795,5 +1810,4 @@
 
 	ASSERT(node);
-	ASMAtomicAddU64(&node->sf_mapcnt, npages);
 	return (0);
 }
@@ -1823,9 +1837,7 @@
 		return (ENOSYS);
 
-	ASSERT(node->sf_mapcnt >= npages);
-	ASMAtomicSubU64(&node->sf_mapcnt, npages);
 	return (0);
 }
-#endif
+#endif /* VBOXVFS_WITH_MMAP */
 
 
@@ -2004,9 +2016,14 @@
 	}
 
-	/*
-	 * There should never be cached data, since we don't support mmap().
-	 */
-	if (vn_has_cached_data(vp))
+	if (vn_has_cached_data(vp)) {
+#ifdef VBOXVFS_WITH_MMAP
+		/* We're fine with releasing the vnode lock here as we should be covered by the sffs_lock */
+		mutex_exit(&vp->v_lock);
+		pvn_vplist_dirty(vp, 0 /* offset */, sffs_discardpage, B_INVAL, cr);
+		mutex_enter(&vp->v_lock);
+#else
 		panic("sffs_inactive() found cached data");
+#endif
+	}
 
 	/*
@@ -2137,5 +2154,5 @@
 	VOPNAME_WRITE,		sffs_write,
 
-# if 0
+# ifdef VBOXVFS_WITH_MMAP
 	VOPNAME_MAP,		sffs_map,
 	VOPNAME_ADDMAP,		sffs_addmap,
@@ -2168,5 +2185,5 @@
 	VOPNAME_WRITE,		{ .vop_write = sffs_write },
 
-# if 0
+# ifdef VBOXVFS_WITH_MMAP
 	VOPNAME_MAP,		{ .vop_map = sffs_map },
 	VOPNAME_ADDMAP,		{ .vop_addmap = sffs_addmap },
Index: /trunk/src/VBox/Additions/solaris/SharedFolders/vboxfs_vnode.h
===================================================================
--- /trunk/src/VBox/Additions/solaris/SharedFolders/vboxfs_vnode.h	(revision 38900)
+++ /trunk/src/VBox/Additions/solaris/SharedFolders/vboxfs_vnode.h	(revision 38901)
@@ -61,7 +61,4 @@
 	sffs_dirents_t	*sf_dir_list;	/* list of entries for this directory */
 	sffs_stats_t	*sf_dir_stats;	/* file attrs for the above entries */
-#if 0
-    volatile uint64_t	sf_mapcnt;  /* number of mapped pages */
-#endif
 } sfnode_t;
 
