Implement fallback from vesacon to ansicon
authorH. Peter Anvin <hpa@zytor.com>
Wed, 13 Sep 2006 00:06:16 +0000 (17:06 -0700)
committerH. Peter Anvin <hpa@zytor.com>
Wed, 13 Sep 2006 00:06:16 +0000 (17:06 -0700)
com32/lib/sys/file.h
com32/lib/sys/opendev.c
com32/lib/sys/vesacon_write.c
com32/lib/sys/vesaserial_write.c

index 84ce7be..3b73848 100644 (file)
@@ -68,6 +68,7 @@ struct output_dev {
   ssize_t (*write)(struct file_info *, const void *, size_t);
   int (*close)(struct file_info *);
   int (*open)(struct file_info *);
+  const struct output_dev *fallback; /* Fallback option for certain consoles */
 };
 
 /* File structure */
index 5928b36..1bcc101 100644 (file)
@@ -75,12 +75,21 @@ int opendev(const struct input_dev *idev,
     fp->iop = idev;
   }
 
-  if (odev) {
+  while (odev) {
     if (odev->open && (e = odev->open(fp))) {
+      if (e == EAGAIN) {
+       if (odev->fallback) {
+         odev = odev->fallback;
+         continue;
+       } else {
+         e = EIO;
+       }
+      }
       errno = e;
       goto puke;
     }
     fp->oop = odev;
+    break;
   }
 
   return fd;
index bcdf6a1..da94006 100644 (file)
@@ -37,6 +37,7 @@
 #include <com32.h>
 #include <minmax.h>
 #include <colortbl.h>
+#include <console.h>
 #include <klibc/compiler.h>
 #include "ansi.h"
 #include "file.h"
@@ -85,7 +86,7 @@ int __vesacon_open(struct file_info *fp)
     } else {
       /* Switch mode */
       if (__vesacon_init())
-       return EIO;
+       return EAGAIN;
 
       /* Initial state */
       __ansi_init(&ti);
@@ -162,4 +163,5 @@ const struct output_dev dev_vesacon_w = {
   .write      = __vesacon_write,
   .close      = __vesacon_close,
   .open       = __vesacon_open,
+  .fallback   = &dev_ansicon_w,
 };
index fa434c3..e9696cb 100644 (file)
@@ -35,6 +35,7 @@
 #include <string.h>
 #include <com32.h>
 #include <minmax.h>
+#include <console.h>
 #include "file.h"
 
 extern int __vesacon_open(void);
@@ -55,4 +56,5 @@ const struct output_dev dev_vesaserial_w = {
   .write      = __vesaserial_write,
   .close      = __vesacon_close,
   .open       = __vesacon_open,
+  .fallback   = &dev_ansiserial_w,
 };