Tools like clear_console rely on the fact that scrollback history is
flushed when switching back and forth between consoles.
Persistent scrollback buffers for each console breaks this, so this
patch adds a ioctl() callf for flushing the scrollback history.

Signed-off-by: Manuel Schölling <manuel.schoell...@gmx.de>
---
 drivers/tty/vt/vt_ioctl.c               | 20 ++++++++++++++++++++
 drivers/usb/misc/sisusbvga/sisusb_con.c |  1 +
 drivers/video/console/dummycon.c        |  1 +
 drivers/video/console/mdacon.c          |  6 ++++++
 drivers/video/console/newport_con.c     |  1 +
 drivers/video/console/sticon.c          |  7 +++++++
 drivers/video/console/vgacon.c          | 23 +++++++++++++++++++++++
 include/linux/console.h                 |  1 +
 include/uapi/linux/vt.h                 |  1 +
 9 files changed, 61 insertions(+)

diff --git a/drivers/tty/vt/vt_ioctl.c b/drivers/tty/vt/vt_ioctl.c
index 97d5a74..18adc23 100644
--- a/drivers/tty/vt/vt_ioctl.c
+++ b/drivers/tty/vt/vt_ioctl.c
@@ -903,6 +903,26 @@ int vt_ioctl(struct tty_struct *tty,
                break;
        }
 
+       /*
+        * flush the specified VT's scollback buffer
+        */
+       case VT_FLUSH_SCROLLBACK: {
+               if (!perm)
+                       return -EPERM;
+               if (arg == 0 || arg > MAX_NR_CONSOLES)
+                       ret = -ENXIO;
+               else {
+                       struct vc_data *data = vc_cons[arg-1].d;
+
+                       if (!data)
+                               ret = -ENXIO;
+                       else
+                               ret = data->vc_sw->con_flush_scrollback(data);
+               }
+
+               break;
+       }
+
        case PIO_FONT: {
                if (!perm)
                        return -EPERM;
diff --git a/drivers/usb/misc/sisusbvga/sisusb_con.c 
b/drivers/usb/misc/sisusbvga/sisusb_con.c
index ace3430..cc5fc10 100644
--- a/drivers/usb/misc/sisusbvga/sisusb_con.c
+++ b/drivers/usb/misc/sisusbvga/sisusb_con.c
@@ -1442,6 +1442,7 @@ static const struct consw sisusb_dummy_con = {
        .con_font_copy =        SISUSBCONDUMMY,
        .con_set_palette =      SISUSBCONDUMMY,
        .con_scrolldelta =      SISUSBCONDUMMY,
+       .con_flush_scrollback = SISUSBCONDUMMY,
 };
 
 int
diff --git a/drivers/video/console/dummycon.c b/drivers/video/console/dummycon.c
index 0efc52f..d2888e5 100644
--- a/drivers/video/console/dummycon.c
+++ b/drivers/video/console/dummycon.c
@@ -73,5 +73,6 @@ const struct consw dummy_con = {
     .con_font_copy =   DUMMY,
     .con_set_palette = DUMMY,
     .con_scrolldelta = DUMMY,
+    .con_flush_scrollback = DUMMY,
 };
 EXPORT_SYMBOL_GPL(dummy_con);
diff --git a/drivers/video/console/mdacon.c b/drivers/video/console/mdacon.c
index 296e945..10ebcbe 100644
--- a/drivers/video/console/mdacon.c
+++ b/drivers/video/console/mdacon.c
@@ -510,6 +510,11 @@ static int mdacon_scrolldelta(struct vc_data *c, int lines)
        return 0;
 }
 
+static int mdacon_flush_scrollback(struct vc_data *c)
+{
+       return 0;
+}
+
 static void mdacon_cursor(struct vc_data *c, int mode)
 {
        if (mode == CM_ERASE) {
@@ -579,6 +584,7 @@ static const struct consw mda_con = {
        .con_blank =            mdacon_blank,
        .con_set_palette =      mdacon_set_palette,
        .con_scrolldelta =      mdacon_scrolldelta,
+       .con_flush_scrollback = mdacon_flush_scrollback,
        .con_build_attr =       mdacon_build_attr,
        .con_invert_region =    mdacon_invert_region,
 };
diff --git a/drivers/video/console/newport_con.c 
b/drivers/video/console/newport_con.c
index bb4e962..d04183c 100644
--- a/drivers/video/console/newport_con.c
+++ b/drivers/video/console/newport_con.c
@@ -738,6 +738,7 @@ const struct consw newport_con = {
        .con_scrolldelta  = newport_scrolldelta,
        .con_set_origin   = DUMMY,
        .con_save_screen  = DUMMY
+       .con_flush_scrollback = DUMMY,
 };
 
 static int newport_probe(struct gio_device *dev,
diff --git a/drivers/video/console/sticon.c b/drivers/video/console/sticon.c
index 026fd12..46046d6 100644
--- a/drivers/video/console/sticon.c
+++ b/drivers/video/console/sticon.c
@@ -345,6 +345,12 @@ static void sticon_save_screen(struct vc_data *conp)
 {
 }
 
+static int sticon_flush_scrollback(struct vc_data *c)
+{
+       return 0;
+}
+
+
 static const struct consw sti_con = {
        .owner                  = THIS_MODULE,
        .con_startup            = sticon_startup,
@@ -360,6 +366,7 @@ static const struct consw sti_con = {
        .con_blank              = sticon_blank,
        .con_set_palette        = sticon_set_palette,
        .con_scrolldelta        = sticon_scrolldelta,
+       .con_flush_scrollback   = sticon_flush_scrollback,
        .con_set_origin         = sticon_set_origin,
        .con_save_screen        = sticon_save_screen, 
        .con_build_attr         = sticon_build_attr,
diff --git a/drivers/video/console/vgacon.c b/drivers/video/console/vgacon.c
index 6c0b9ba..b5ea94f 100644
--- a/drivers/video/console/vgacon.c
+++ b/drivers/video/console/vgacon.c
@@ -379,12 +379,34 @@ static int vgacon_scrolldelta(struct vc_data *c, int 
lines)
 
        return 1;
 }
+
+/* flush the scrollback buffer of a console */
+static int vgacon_flush_scrollback(struct vc_data *c)
+{
+       size_t size = CONFIG_VGACON_SOFT_SCROLLBACK_SIZE * 1024;
+       struct vgacon_scrollback_info *vgacon_scrollback_prev;
+
+       vgacon_scrollback_prev = vgacon_scrollback_cur;
+       vgacon_scrollback_cur = &vgacon_scrollbacks[c->vc_num];
+
+       if (vgacon_scrollback_cur != NULL)
+               vgacon_scrollback_reset(size);
+
+       vgacon_scrollback_cur = vgacon_scrollback_prev;
+
+       return 0;
+}
 #else
 #define vgacon_scrollback_startup(...) do { } while (0)
 #define vgacon_scrollback_init(...)    do { } while (0)
 #define vgacon_scrollback_update(...)  do { } while (0)
 #define vgacon_switch_scrollback(...)  do { } while (0)
 
+static int vgacon_flush_scrollback(struct vc_data *c)
+{
+       return 0;
+}
+
 static void vgacon_restore_screen(struct vc_data *c)
 {
        if (c->vc_origin != c->vc_visible_origin)
@@ -1492,6 +1514,7 @@ const struct consw vga_con = {
        .con_resize = vgacon_resize,
        .con_set_palette = vgacon_set_palette,
        .con_scrolldelta = vgacon_scrolldelta,
+       .con_flush_scrollback = vgacon_flush_scrollback,
        .con_set_origin = vgacon_set_origin,
        .con_save_screen = vgacon_save_screen,
        .con_build_attr = vgacon_build_attr,
diff --git a/include/linux/console.h b/include/linux/console.h
index e49cc1e..946ff20 100644
--- a/include/linux/console.h
+++ b/include/linux/console.h
@@ -49,6 +49,7 @@ struct consw {
                               unsigned int);
        int     (*con_set_palette)(struct vc_data *, unsigned char *);
        int     (*con_scrolldelta)(struct vc_data *, int);
+       int     (*con_flush_scrollback)(struct vc_data *);
        int     (*con_set_origin)(struct vc_data *);
        void    (*con_save_screen)(struct vc_data *);
        u8      (*con_build_attr)(struct vc_data *, u8, u8, u8, u8, u8, u8);
diff --git a/include/uapi/linux/vt.h b/include/uapi/linux/vt.h
index 978578b..b799541 100644
--- a/include/uapi/linux/vt.h
+++ b/include/uapi/linux/vt.h
@@ -83,5 +83,6 @@ struct vt_setactivate {
 };
 
 #define VT_SETACTIVATE 0x560F  /* Activate and set the mode of a console */
+#define VT_FLUSH_SCROLLBACK    0x5610  /* Flush the scrollback buffer */
 
 #endif /* _UAPI_LINUX_VT_H */
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to