summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sys/fs/devfs.c23
-rw-r--r--sys/include/fs/devfs.h1
2 files changed, 24 insertions, 0 deletions
diff --git a/sys/fs/devfs.c b/sys/fs/devfs.c
index 7e7fd9d..8b273db 100644
--- a/sys/fs/devfs.c
+++ b/sys/fs/devfs.c
@@ -199,6 +199,29 @@ devfs_add_dev(const char *name, const struct device *dev)
return 0;
}
+/*
+ * Fetch a device descriptor from a vnode.
+ */
+int
+devfs_get_dev(struct vnode *vp, struct device **res)
+{
+ struct device_node *n;
+ struct device *dev;
+
+ /* Is this really a device? */
+ if (vp->type != VBLK && vp->type != VCHR) {
+ return -ENODEV;
+ }
+
+ n = vp->data;
+ if ((dev = device_fetch(n->major, n->minor)) == NULL) {
+ return -ENODEV;
+ }
+
+ *res = dev;
+ return 0;
+}
+
struct vfsops g_devfs_ops = {
.init = devfs_init
};
diff --git a/sys/include/fs/devfs.h b/sys/include/fs/devfs.h
index 7f32f8c..66128ef 100644
--- a/sys/include/fs/devfs.h
+++ b/sys/include/fs/devfs.h
@@ -37,5 +37,6 @@ extern struct vfsops g_devfs_ops;
extern struct vops g_devfs_vops;
int devfs_add_dev(const char *name, const struct device *dev);
+int devfs_get_dev(struct vnode *vp, struct device **res);
#endif