From 041b3c6020e847d29af9a7f74f61400779ded397 Mon Sep 17 00:00:00 2001
From: Christoph Hellwig <hch@cloudius-systems.com>
Date: Tue, 12 Feb 2013 19:52:35 +0100
Subject: [PATCH] add support for device backed filesystems to the VFS

---
 fs/vfs/vfs_mount.c  | 11 +++--------
 include/osv/mount.h |  2 +-
 include/osv/prex.h  |  2 ++
 3 files changed, 6 insertions(+), 9 deletions(-)

diff --git a/fs/vfs/vfs_mount.c b/fs/vfs/vfs_mount.c
index bcbd0967c..63cf5243f 100755
--- a/fs/vfs/vfs_mount.c
+++ b/fs/vfs/vfs_mount.c
@@ -44,6 +44,7 @@
 
 #include <osv/prex.h>
 #include <osv/vnode.h>
+#include <osv/device.h>
 #include "vfs.h"
 
 /*
@@ -98,14 +99,12 @@ sys_mount(char *dev, char *dir, char *fsname, int flags, void *data)
 
 	/* Open device. NULL can be specified as a device. */
 	device = 0;
-#if HAVE_DEVICES
 	if (*dev != '\0') {
 		if (strncmp(dev, "/dev/", 5))
 			return ENOTBLK;
 		if ((error = device_open(dev + 5, DO_RDWR, &device)) != 0)
 			return error;
 	}
-#endif
 
 	MOUNT_LOCK();
 
@@ -114,7 +113,7 @@ sys_mount(char *dev, char *dir, char *fsname, int flags, void *data)
 	for (n = list_first(head); n != head; n = list_next(n)) {
 		mp = list_entry(n, struct mount, m_link);
 		if (!strcmp(mp->m_path, dir) ||
-		    (device && mp->m_dev == (dev_t)device)) {
+		    (device && mp->m_dev == device)) {
 			error = EBUSY;	/* Already mounted */
 			goto err1;
 		}
@@ -129,7 +128,7 @@ sys_mount(char *dev, char *dir, char *fsname, int flags, void *data)
 	mp->m_count = 0;
 	mp->m_op = fs->vs_op;
 	mp->m_flags = flags;
-	mp->m_dev = (dev_t)device;
+	mp->m_dev = device;
 	strlcpy(mp->m_path, dir, sizeof(mp->m_path));
 
 	/*
@@ -194,9 +193,7 @@ sys_mount(char *dev, char *dir, char *fsname, int flags, void *data)
  err2:
 	free(mp);
  err1:
-#if HAVE_DEVICES
 	device_close(device);
-#endif
 
 	MOUNT_UNLOCK();
 	return error;
@@ -246,10 +243,8 @@ sys_umount(char *path)
 	binval(mp->m_dev);
 #endif
 
-#if HAVE_DEVICES
 	if (mp->m_dev)
 		device_close(mp->m_dev);
-#endif
 	free(mp);
  out:
 	MOUNT_UNLOCK();
diff --git a/include/osv/mount.h b/include/osv/mount.h
index ba7364bee..b9583cf66 100755
--- a/include/osv/mount.h
+++ b/include/osv/mount.h
@@ -47,7 +47,7 @@ struct mount {
 	int		m_flags;	/* mount flag */
 	int		m_count;	/* reference count */
 	char		m_path[PATH_MAX]; /* mounted path */
-	dev_t		m_dev;		/* mounted device */
+	struct device	*m_dev;		/* mounted device */
 	struct vnode	*m_root;	/* root vnode */
 	struct vnode	*m_covered;	/* vnode covered on parent fs */
 	void		*m_data;	/* private data for fs */
diff --git a/include/osv/prex.h b/include/osv/prex.h
index 3e7b1af4f..273eea02c 100644
--- a/include/osv/prex.h
+++ b/include/osv/prex.h
@@ -16,6 +16,8 @@ __BEGIN_DECLS
 #define FREAD           0x00000001
 #define FWRITE          0x00000002
 
+#define DO_RDWR		0x2
+
 /* convert from open() flags to/from fflags; convert O_RD/WR to FREAD/FWRITE */
 #define FFLAGS(oflags)  ((oflags) + 1)
 #define OFLAGS(fflags)  ((fflags) - 1)
-- 
GitLab