inode: add a helper for opening devices
authorAlan Cox <alan@linux.intel.com>
Fri, 22 May 2015 10:34:42 +0000 (11:34 +0100)
committerAlan Cox <alan@linux.intel.com>
Fri, 22 May 2015 10:34:42 +0000 (11:34 +0100)
We keep the inode stuff clear of devices (might be very size costly otherwise)
but do the fixups here. Not perfect... may need to size a few options and
see what the payoffs are

Kernel/inode.c

index c0c7a79..c7c3b57 100644 (file)
@@ -1,6 +1,7 @@
 #include <kernel.h>
 #include <kdata.h>
 #include <printf.h>
+#include <tty.h>
 
 #if defined(CONFIG_LARGE_IO_DIRECT)
 #define read_direct(flag)              (!udata.u_sysio)
@@ -275,3 +276,39 @@ inoptr rwsetup(bool is_read, uint8_t * flag)
            file size here in the r/w inode code */
        return (ino);
 }
+
+/*
+ *     FIXME: could we rewrite this so we just passed the oft slot and
+ *     did the work in that then picked it up in open. That would feel
+ *     less like ugly layering violations and is probably shorter and
+ *     much cleaner, and gets rid of the itmp ugly.
+ *
+ *     FIXME. Need so IS_TTY(dev) defines too and minor(x) etc
+ */
+int dev_openi(inoptr *ino, uint8_t flag)
+{
+        int ret;
+        uint16_t da = (*ino)->c_node.i_addr[0];
+        /* Handle the special casing where we need to know about inodes */
+
+        /* /dev/tty processing */
+        if (da == 0x0200) {
+                if (!udata.u_ctty) {
+                        udata.u_error = ENODEV;
+                        return -1;
+                }
+                i_deref(*ino);
+                *ino = udata.u_ctty;
+                da = (*ino)->c_node.i_addr[0];
+                i_ref(*ino);
+                /* fall through opening the real device */
+        }
+        /* normal device opening */
+        ret = d_open((int)da, flag);
+        /* errors and non tty opens */
+        if (ret != 0 || (da & 0xFF00) != 0x0200)
+                return ret;
+        /* tty post processing */
+        tty_post(*ino, da & 0xFF, flag);
+        return 0;
+}