summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libcons/ChangeLog7
-rw-r--r--libcons/Makefile37
-rw-r--r--libcons/cons-lookup.c134
-rw-r--r--libcons/cons-switch.c95
-rw-r--r--libcons/cons.h202
-rw-r--r--libcons/demuxer.c30
-rw-r--r--libcons/dir-changed.c130
-rw-r--r--libcons/extra-version.c24
-rw-r--r--libcons/file-changed.c266
-rw-r--r--libcons/init-init.c99
-rw-r--r--libcons/init-loop.c32
-rw-r--r--libcons/mutations.h27
-rw-r--r--libcons/opts-std-startup.c91
-rw-r--r--libcons/opts-version.c44
-rw-r--r--libcons/priv.h50
-rw-r--r--libcons/vcons-add.c43
-rw-r--r--libcons/vcons-close.c51
-rw-r--r--libcons/vcons-open.c162
-rw-r--r--libcons/vcons-refresh.c60
-rw-r--r--libcons/vcons-remove.c32
20 files changed, 1616 insertions, 0 deletions
diff --git a/libcons/ChangeLog b/libcons/ChangeLog
new file mode 100644
index 00000000..2913619d
--- /dev/null
+++ b/libcons/ChangeLog
@@ -0,0 +1,7 @@
+2002-08-22 Marcus Brinkmann <marcus@gnu.org>
+
+ * demuxer.c, init-init.c, init-loop.c, opts-version.c,
+ extra-version.c, dir-changed.c, file-changed.c,
+ opts-std-startup.c, cons-lookup.c, cons-switch.c, vcons-remove.c,
+ vcons-add.c, vcons-open.c, vcons-close.c, vcons-refresh.c, priv.h,
+ mutations.h, cons.h: New files.
diff --git a/libcons/Makefile b/libcons/Makefile
new file mode 100644
index 00000000..a6d60419
--- /dev/null
+++ b/libcons/Makefile
@@ -0,0 +1,37 @@
+#
+# Copyright (C) 1994,95,96,97,98,99,2000,01,02 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 2, or (at
+# your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+dir := libcons
+makemode := library
+
+libname = libcons
+SRCS= demuxer.c init-init.c init-loop.c opts-version.c extra-version.c \
+ dir-changed.c file-changed.c opts-std-startup.c cons-lookup.c \
+ cons-switch.c vcons-remove.c vcons-add.c vcons-open.c \
+ vcons-close.c vcons-refresh.c
+LCLHDRS = priv.h mutations.h
+installhdrs = cons.h
+
+fs_notify-MIGSFLAGS = -imacros $(srcdir)/mutations.h
+MIGSTUBS = fs_notifyServer.o
+OBJS = $(sort $(SRCS:.c=.o) $(MIGSTUBS))
+
+HURDLIBS = threads ports
+
+MIGCOMSFLAGS = -prefix cons_
+
+include ../Makeconf
diff --git a/libcons/cons-lookup.c b/libcons/cons-lookup.c
new file mode 100644
index 00000000..f3bdabef
--- /dev/null
+++ b/libcons/cons-lookup.c
@@ -0,0 +1,134 @@
+/* cons-lookup.c - Looking up virtual consoles.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ Written by Marcus Brinkmann.
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */
+
+#include <errno.h>
+#include <malloc.h>
+#include <sys/mman.h>
+
+#include "cons.h"
+
+/* Lookup the virtual console with number ID in the console CONS,
+ acquire a reference for it, and return it in R_VCONS. If CREATE is
+ true, the virtual console will be created if it doesn't exist yet.
+ If CREATE is true, and ID 0, the first free virtual console id is
+ used. CONS must be locked. */
+error_t
+cons_lookup (cons_t cons, int id, int create, vcons_t *r_vcons)
+{
+ vcons_t previous_vcons = 0;
+ vcons_t vcons;
+
+ if (!id && !create)
+ return EINVAL;
+
+ if (id)
+ {
+ if (cons->vcons_list && cons->vcons_list->id <= id)
+ {
+ previous_vcons = cons->vcons_list;
+ while (previous_vcons->next && previous_vcons->next->id <= id)
+ previous_vcons = previous_vcons->next;
+ if (previous_vcons->id == id)
+ {
+ /* previous_vcons->refcnt++; */
+ *r_vcons = previous_vcons;
+ return 0;
+ }
+ }
+ else if (!create)
+ return ESRCH;
+ }
+ else
+ {
+ id = 1;
+ if (cons->vcons_list && cons->vcons_list->id == 1)
+ {
+ previous_vcons = cons->vcons_list;
+ while (previous_vcons && previous_vcons->id == id)
+ {
+ id++;
+ previous_vcons = previous_vcons->next;
+ }
+ }
+ }
+
+ vcons = calloc (1, sizeof (struct vcons));
+ if (!vcons)
+ {
+ mutex_unlock (&vcons->cons->lock);
+ return ENOMEM;
+ }
+ vcons->cons = cons;
+ /* vcons->refcnt = 1; */
+ vcons->id = id;
+ mutex_init (&vcons->lock);
+ vcons->input = -1;
+ vcons->display = MAP_FAILED;
+ vcons->notify = NULL;
+
+#if 0
+ err = display_create (&vcons->display, cons->encoding ?: DEFAULT_ENCODING,
+ cons->foreground, cons->background);
+ if (err)
+ {
+ free (vcons->name);
+ free (vcons);
+ return err;
+ }
+
+ err = input_create (&vcons->input, cons->encoding ?: DEFAULT_ENCODING);
+ if (err)
+ {
+ display_destroy (vcons->display);
+ free (vcons->name);
+ free (vcons);
+ return err;
+ }
+#endif
+
+ cons_vcons_add (vcons);
+
+ /* Insert the virtual console into the doubly linked list. */
+ if (previous_vcons)
+ {
+ vcons->prev = previous_vcons;
+ if (previous_vcons->next)
+ {
+ previous_vcons->next->prev = vcons;
+ vcons->next = previous_vcons->next;
+ }
+ else
+ cons->vcons_last = vcons;
+ previous_vcons->next = vcons;
+ }
+ else
+ {
+ if (cons->vcons_list)
+ {
+ cons->vcons_list->prev = vcons;
+ vcons->next = cons->vcons_list;
+ }
+ else
+ cons->vcons_last = vcons;
+ cons->vcons_list = vcons;
+ }
+ *r_vcons = vcons;
+ return 0;
+}
diff --git a/libcons/cons-switch.c b/libcons/cons-switch.c
new file mode 100644
index 00000000..f2b72daf
--- /dev/null
+++ b/libcons/cons-switch.c
@@ -0,0 +1,95 @@
+/* cons-switch.c - Switch to another virtual console.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ Written by Marcus Brinkmann.
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */
+
+#include <errno.h>
+#include <error.h>
+#include <assert.h>
+
+#include "cons.h"
+
+/* Switch the active console in CONS to ID or the current one plus
+ DELTA. This will call back into the user code by doing a
+ cons_vcons_activate. */
+error_t
+cons_switch (cons_t cons, int id, int delta)
+{
+ vcons_t vcons = NULL;
+ vcons_t active;
+
+ if (!id && !delta)
+ return 0;
+
+ mutex_lock (&cons->lock);
+ active = cons->active;
+
+ if (!id && !active)
+ {
+ mutex_unlock (&cons->lock);
+ return EINVAL;
+ }
+
+ if (id)
+ {
+ vcons = cons->vcons_list;
+ while (vcons && vcons->id != id)
+ vcons = vcons->next;
+ }
+ else if (delta > 0)
+ {
+ vcons = cons->active;
+ while (delta-- > 0)
+ {
+ vcons = vcons->next;
+ if (!vcons)
+ vcons = cons->vcons_list;
+ }
+ }
+ else
+ {
+ assert (delta < 0);
+ while (delta++ < 0)
+ {
+ vcons = vcons->prev;
+ if (!vcons)
+ vcons = cons->vcons_last;
+ }
+ }
+
+ if (!vcons)
+ {
+ mutex_unlock (&cons->lock);
+ return ESRCH;
+ }
+
+ if (vcons != active)
+ {
+ error_t err = cons_vcons_activate (vcons);
+ if (err)
+ {
+ mutex_unlock (&cons->lock);
+ return err;
+ }
+
+ cons->active = vcons;
+ cons_vcons_refresh (vcons);
+ }
+ mutex_unlock (&cons->lock);
+ return 0;
+}
diff --git a/libcons/cons.h b/libcons/cons.h
new file mode 100644
index 00000000..7966657b
--- /dev/null
+++ b/libcons/cons.h
@@ -0,0 +1,202 @@
+/* cons.h - Definitions for cons helper and callback functions.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ Written by Marcus Brinkmann.
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */
+
+#ifndef _HURD_CONS_H
+#define _HURD_CONS_H
+
+#include <dirent.h>
+
+#include <hurd/ports.h>
+#include <mach.h>
+
+#include <hurd/console.h>
+
+typedef struct vcons *vcons_t;
+typedef struct cons *cons_t;
+typedef struct cons_notify *cons_notify_t;
+
+struct vcons
+{
+ vcons_t next;
+ vcons_t prev;
+ cons_t cons;
+ int id;
+
+ struct mutex lock;
+ /* The FD of the input node. */
+ int input;
+ struct cons_display *display;
+ size_t display_size;
+ cons_notify_t notify;
+
+ struct
+ {
+ struct
+ {
+ uint32_t col;
+ uint32_t row;
+ uint32_t status;
+ } cursor;
+ struct
+ {
+ uint32_t width;
+ uint32_t height;
+ uint32_t lines;
+ uint32_t cur_line;
+ uint32_t scr_lines;
+ conchar_t *matrix;
+ } screen;
+ struct
+ {
+ uint32_t audible;
+ uint32_t visible;
+ } bell;
+ struct
+ {
+ uint32_t written;
+ uint32_t length;
+ cons_change_t *buffer;
+ } changes;
+ } state;
+};
+
+struct cons
+{
+ /* Protects the cons structure and the linked list in
+ VCONS_LIST. */
+ struct mutex lock;
+ vcons_t vcons_list;
+ vcons_t vcons_last;
+ vcons_t active;
+
+ struct port_class *port_class;
+ struct port_bucket *port_bucket;
+ DIR *dir;
+ io_t dirport;
+ int slack;
+};
+
+struct cons_notify
+{
+ struct port_info pi;
+
+ /* This is set for the dir notification port. */
+ cons_t cons;
+
+ /* This is set for the file notification ports. */
+ vcons_t vcons;
+};
+
+
+/* The user must define this variable. Set this to the name of the
+ console client. */
+extern const char *cons_client_name;
+
+/* The user must define this variables. Set this to be the client
+ version number. */
+extern const char *cons_client_version;
+
+/* The user may define this variable. Set this to be any additional
+ version specification that should be printed for --version. */
+extern char *cons_extra_version;
+
+/* The user must define this function. Write LENGTH characters
+ starting from STR on the virtual console VCONS, which is locked,
+ starting from position COL and ROW. */
+void cons_vcons_write (vcons_t vcons, conchar_t *str, size_t length,
+ uint32_t col, uint32_t row);
+
+/* The user must define this function. Set the cursor on virtual
+ console VCONS, which is locked, to position COL and ROW. */
+void cons_vcons_set_cursor_pos (vcons_t vcons, uint32_t col, uint32_t row);
+
+/* The user must define this function. Set the cursor status of
+ virtual console VCONS, which is locked, to STATUS. */
+void cons_vcons_set_cursor_status (vcons_t vcons, uint32_t status);
+
+/* The user must define this function. Scroll the content of virtual
+ console VCONS, which is locked, up by DELTA if DELTA is positive or
+ down by -DELTA if DELTA is negative. This call will be immediately
+ followed by corresponding cons_vcons_write calls to fill the
+ resulting gap on the screen, and VCONS will be looked throughout
+ the whole time. */
+void cons_vcons_scroll (vcons_t vcons, int delta);
+
+/* The user may define this function. Make the changes from
+ cons_vcons_write, cons_vcons_set_cursor_pos,
+ cons_vcons_set_cursor_status and cons_vcons_scroll active. VCONS
+ is locked and will have been continuously locked from the first
+ change since the last update on. This is the latest possible point
+ the user must make the changes visible from. The user can always
+ make the changes visible at a more convenient, earlier time. */
+void cons_vcons_update (vcons_t vcons);
+
+/* The user must define this function. Make the virtual console
+ VCONS, which is locked, beep audible. */
+void cons_vcons_beep (vcons_t vcons);
+
+/* The user must define this function. Make the virtual console
+ VCONS, which is locked, flash visibly. */
+void cons_vcons_flash (vcons_t vcons);
+
+/* The user must define this function. It is called whenever a
+ virtual console is selected to be the active one. */
+error_t cons_vcons_activate (vcons_t vcons);
+
+/* The user may define this function. It is called whenever a
+ virtual console is added. VCONS->cons is locked. */
+void cons_vcons_add (vcons_t vcons);
+
+/* The user may define this function. It is called whenever a
+ virtual console is removed. VCONS->cons is locked. */
+void cons_vcons_remove (vcons_t vcons);
+
+/* Switch the active console in CONS to ID or the current one plus
+ DELTA. This will call back into the user code by doing a
+ cons_vcons_activate. */
+error_t cons_switch (cons_t cons, int id, int delta);
+
+
+extern const struct argp cons_startup_argp;
+
+extern struct port_bucket *cons_port_bucket;
+extern struct port_class *cons_port_class;
+
+error_t cons_init (void);
+void cons_server_loop (void);
+int cons_demuxer (mach_msg_header_t *inp, mach_msg_header_t *outp);
+
+/* Lookup the virtual console with number ID in the console CONS,
+ acquire a reference for it, and return it in R_VCONS. If CREATE is
+ true, the virtual console will be created if it doesn't exist yet.
+ If CREATE is true, and ID 0, the first free virtual console id is
+ used. CONS must be locked. */
+error_t cons_lookup (cons_t cons, int id, int create, vcons_t *r_vcons);
+
+/* Open the virtual console VCONS. VCONS->cons is locked. */
+error_t cons_vcons_open (vcons_t vcons);
+
+/* Close the virtual console VCONS. VCONS->cons is locked. */
+void cons_vcons_close (vcons_t vcons);
+
+/* Redraw the virtual console VCONS, which is locked. */
+void cons_vcons_refresh (vcons_t vcons);
+
+#endif /* hurd/cons.h */
diff --git a/libcons/demuxer.c b/libcons/demuxer.c
new file mode 100644
index 00000000..8982bfa9
--- /dev/null
+++ b/libcons/demuxer.c
@@ -0,0 +1,30 @@
+/* demuxer.c - Message demuxer for console client library.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ Written by Marcus Brinkmann.
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */
+
+#include "cons.h"
+
+int
+cons_demuxer (mach_msg_header_t *inp, mach_msg_header_t *outp)
+{
+ int cons_fs_notify_server (mach_msg_header_t *inp, mach_msg_header_t *outp);
+
+ return (cons_fs_notify_server (inp, outp));
+}
+
diff --git a/libcons/dir-changed.c b/libcons/dir-changed.c
new file mode 100644
index 00000000..15b466a6
--- /dev/null
+++ b/libcons/dir-changed.c
@@ -0,0 +1,130 @@
+/* dir-changed.c - Handling dir changed notifications.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ Written by Marcus Brinkmann.
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */
+
+#include <errno.h>
+#include <dirent.h>
+#include <assert.h>
+#include <mach.h>
+#include <cthreads.h>
+
+#include "cons.h"
+#include "fs_notify_S.h"
+
+
+static error_t
+add_one (cons_t cons, char *name)
+{
+ unsigned long int nr;
+ char *tail;
+
+ errno = 0;
+ nr = strtoul (name, &tail, 10);
+ if (!errno && *tail == '\0' && nr > 0)
+ {
+ vcons_t vcons;
+ return cons_lookup (cons, nr, 1, &vcons);
+ }
+ return 0;
+}
+
+static error_t
+lookup_one (cons_t cons, char *name, vcons_t *vcons)
+{
+ unsigned long int nr;
+ char *tail;
+
+ errno = 0;
+ nr = strtoul (name, &tail, 10);
+ if (!errno && *tail == '\0' && nr > 0)
+ return cons_lookup (cons, nr, 0, vcons);
+ return 0;
+}
+
+
+kern_return_t
+cons_S_dir_changed (cons_notify_t notify, natural_t tickno,
+ dir_changed_type_t change, string_t name)
+{
+ error_t err;
+ cons_t cons;
+
+ if (!notify || !notify->cons)
+ return EOPNOTSUPP;
+ cons = notify->cons;
+
+ mutex_lock (&cons->lock);
+
+ switch (change)
+ {
+ case DIR_CHANGED_NULL:
+ {
+ DIR *dir = cons->dir;
+ struct dirent *dent;
+ do
+ {
+ errno = 0;
+ dent = readdir (dir);
+ if (!dent && errno)
+ err = errno;
+ else if (dent)
+ err = add_one (cons, dent->d_name);
+ }
+ while (dent && !err);
+ if (err)
+ assert ("Unexpected error"); /* XXX */
+ }
+ break;
+ case DIR_CHANGED_NEW:
+ {
+ err = add_one (cons, name);
+ if (err)
+ assert ("Unexpected error"); /* XXX */
+ }
+ break;
+ case DIR_CHANGED_UNLINK:
+ {
+ vcons_t vcons;
+ err = lookup_one (cons, name, &vcons);
+ if (!err)
+ {
+ cons_vcons_remove (vcons);
+ if (vcons->prev)
+ vcons->prev->next = vcons->next;
+ else
+ cons->vcons_list = vcons->next;
+ if (vcons->next)
+ vcons->next->prev = vcons->prev;
+ else
+ cons->vcons_last = vcons->prev;
+
+ /* XXX Destroy the state. */
+ free (vcons);
+ }
+ }
+ break;
+ case DIR_CHANGED_RENUMBER:
+ default:
+ assert ("Unexpected dir-changed type.");
+ mutex_unlock (&cons->lock);
+ return EINVAL;
+ }
+ mutex_unlock (&cons->lock);
+ return 0;
+}
diff --git a/libcons/extra-version.c b/libcons/extra-version.c
new file mode 100644
index 00000000..4ff54d85
--- /dev/null
+++ b/libcons/extra-version.c
@@ -0,0 +1,24 @@
+/* Default value for cons_extra_version
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ Written by Marcus Brinkmann.
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */
+
+
+#include "priv.h"
+
+char *cons_extra_version = "";
diff --git a/libcons/file-changed.c b/libcons/file-changed.c
new file mode 100644
index 00000000..ff51fa29
--- /dev/null
+++ b/libcons/file-changed.c
@@ -0,0 +1,266 @@
+/* file-changed.c - Handling file changed notifications.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ Written by Marcus Brinkmann.
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */
+
+#include <mach.h>
+#include <errno.h>
+
+#include "cons.h"
+#include "fs_notify_S.h"
+
+kern_return_t
+cons_S_file_changed (cons_notify_t notify, natural_t tickno,
+ file_changed_type_t change,
+ off_t start, off_t end)
+{
+ error_t err = 0;
+ vcons_t vcons;
+
+ if (!notify || !notify->vcons)
+ return EOPNOTSUPP;
+
+ vcons = notify->vcons;
+
+ mutex_lock (&vcons->lock);
+ switch (change)
+ {
+ case FILE_CHANGED_NULL:
+ /* Always sent first for sync. */
+ cons_vcons_refresh (vcons);
+ break;
+ case FILE_CHANGED_WRITE:
+ /* File data has been written. */
+ while (vcons->state.changes.written < vcons->display->changes.written)
+ {
+ cons_change_t change;
+
+ if (vcons->display->changes.written - vcons->state.changes.written
+ > vcons->cons->slack)
+ {
+ cons_vcons_refresh (vcons);
+ continue;
+ }
+ change = vcons->state.changes.buffer[vcons->state.changes.written
+ % vcons->state.changes.length];
+ if (vcons->display->changes.written - vcons->state.changes.written
+ > vcons->state.changes.length - 1)
+ {
+ /* While we were reading the entry, the server might
+ have overwritten it. */
+ cons_vcons_refresh (vcons);
+ continue;
+ }
+ vcons->state.changes.written++;
+
+ if (change.what.not_matrix)
+ {
+ if (change.what.cursor_pos)
+ {
+ vcons->state.cursor.col = vcons->display->cursor.col;
+ vcons->state.cursor.row = vcons->display->cursor.row;
+ cons_vcons_set_cursor_pos (vcons, vcons->state.cursor.col,
+ vcons->state.cursor.row);
+ cons_vcons_update (vcons);
+ }
+ if (change.what.cursor_status)
+ {
+ vcons->state.cursor.status = vcons->display->cursor.status;
+ cons_vcons_set_cursor_status (vcons,
+ vcons->state.cursor.status);
+ cons_vcons_update (vcons);
+ }
+ if (change.what.screen_cur_line)
+ {
+ off_t size = vcons->state.screen.width
+ * vcons->state.screen.lines;
+ off_t vis_start;
+ uint32_t new_cur_line;
+ int scrolling;
+ off_t start;
+ off_t end;
+
+ new_cur_line = vcons->display->screen.cur_line;
+ scrolling = new_cur_line - vcons->state.screen.cur_line;
+ if (scrolling < 0)
+ scrolling += vcons->state.screen.lines;
+ cons_vcons_scroll (vcons, scrolling);
+ vis_start = vcons->state.screen.width * new_cur_line;
+ start = ((new_cur_line + vcons->state.screen.height
+ - scrolling) * vcons->state.screen.width) % size;
+ end = start + scrolling * vcons->state.screen.width - 1;
+ cons_vcons_write (vcons, vcons->state.screen.matrix + start,
+ end < size
+ ? end - start + 1
+ : size - start,
+ (start - vis_start)
+ % vcons->state.screen.width,
+ (start - vis_start)
+ / vcons->state.screen.width);
+ if (end >= size)
+ cons_vcons_write (vcons,
+ vcons->state.screen.matrix,
+ end - size + 1,
+ (size - vis_start)
+ % vcons->state.screen.width,
+ (size - vis_start)
+ / vcons->state.screen.width);
+ cons_vcons_update (vcons);
+ vcons->state.screen.cur_line = new_cur_line;
+ }
+ if (change.what.screen_scr_lines)
+ {
+ vcons->state.screen.scr_lines
+ = vcons->display->screen.scr_lines;
+ }
+ if (change.what.bell_audible)
+ {
+ while (vcons->state.bell.audible
+ < vcons->display->bell.audible)
+ {
+ cons_vcons_beep (vcons);
+ vcons->state.bell.audible++;
+ }
+ }
+ if (change.what.bell_visible)
+ {
+ while (vcons->state.bell.visible
+ < vcons->display->bell.visible)
+ {
+ cons_vcons_flash (vcons);
+ vcons->state.bell.visible++;
+ }
+ }
+ }
+ else
+ {
+ /* For clipping. */
+ off_t size = vcons->state.screen.width*vcons->state.screen.lines;
+ off_t rotate = vcons->state.screen.width
+ * vcons->state.screen.cur_line;
+ off_t vis_end = vcons->state.screen.height
+ * vcons->state.screen.width - 1;
+ off_t end2 = -1;
+ off_t start_rel = 0; /* start relative to visible start. */
+ off_t start = change.matrix.start;
+ off_t end = change.matrix.end;
+
+ /* Rotate the buffer. */
+ start -= rotate;
+ if (start < 0)
+ start += size;
+ end -= rotate;
+ if (end < 0)
+ end += size;
+
+ /* Find the intersection. */
+ if (start > vis_end)
+ {
+ if (end < start)
+ {
+ start = 0;
+ if (vis_end < end)
+ end = vis_end;
+ }
+ else
+ start = -1;
+ }
+ else
+ {
+ if (end >= start)
+ {
+ if (end > vis_end)
+ end = vis_end;
+ }
+ else
+ {
+ end2 = end;
+ end = vis_end;
+ }
+ }
+ /* We now have three cases: No intersection if start ==
+ -1, one intersection [start;end] if end2 == -1, and
+ two intersections [start;end] and [0;end2] if end2 !=
+ -1. However, we still have to undo the buffer
+ rotation. */
+ if (start != -1)
+ {
+ start_rel = start;
+ start += rotate;
+ if (start >= size)
+ start -= size;
+ end += rotate;
+ if (end >= size)
+ end -= size;
+ if (start > end)
+ end += size;
+ }
+ if (end2 != -1)
+ /* The interval should be [vis_start:end2]. */
+ end2 += rotate;
+
+ if (start != -1)
+ {
+ cons_vcons_write (vcons, vcons->state.screen.matrix + start,
+ end < size
+ ? end - start + 1
+ : size - start,
+ start_rel % vcons->state.screen.width,
+ start_rel / vcons->state.screen.width);
+ if (end >= size)
+ cons_vcons_write (vcons, vcons->state.screen.matrix,
+ end - size + 1,
+ (size - rotate)
+ % vcons->state.screen.width,
+ (size - rotate)
+ / vcons->state.screen.width);
+ if (end2 != -1)
+ {
+ cons_vcons_write (vcons,
+ vcons->state.screen.matrix + rotate,
+ end2 < size
+ ? end2 - rotate + 1
+ : size - rotate,
+ 0, 0);
+ if (end2 >= size)
+ cons_vcons_write (vcons, vcons->state.screen.matrix,
+ end2 - size + 1,
+ (size - rotate)
+ % vcons->state.screen.width,
+ (size - rotate)
+ / vcons->state.screen.width);
+ }
+ cons_vcons_update (vcons);
+ }
+ }
+ }
+ break;
+ case FILE_CHANGED_EXTEND:
+ /* File has grown. */
+ case FILE_CHANGED_TRUNCATE:
+ /* File has been truncated. */
+ case FILE_CHANGED_META:
+ /* Stat information has changed, and none of the previous three
+ apply. Not sent for changes in node times. */
+ default:
+ err = EINVAL;
+ };
+
+ mutex_unlock (&vcons->lock);
+ return err;
+}
diff --git a/libcons/init-init.c b/libcons/init-init.c
new file mode 100644
index 00000000..e84f0e67
--- /dev/null
+++ b/libcons/init-init.c
@@ -0,0 +1,99 @@
+/* init-init.c - Initialize the console library.
+ Copyright (C) 1995, 1996, 2002 Free Software Foundation, Inc.
+ Written by Michael I. Bushnell, p/BSG and Marcus Brinkmann.
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */
+
+
+#include <errno.h>
+#include <malloc.h>
+
+#include <hurd.h>
+#include <hurd/ports.h>
+
+#include <mach.h>
+
+#include "cons.h"
+#include "priv.h"
+
+ struct port_bucket *cons_port_bucket;
+ struct port_class *cons_port_class;
+
+error_t
+cons_init (void)
+{
+ error_t err;
+ cons_t cons;
+ cons_notify_t dir_notify_port;
+ mach_port_t dir_notify;
+
+ cons_port_bucket = ports_create_bucket ();
+ if (!cons_port_bucket)
+ return errno;
+
+ cons_port_class = ports_create_class (NULL, NULL);
+ if (!cons_port_class)
+ return errno;
+
+ /* Create the console structure. */
+ cons = malloc (sizeof (*cons));
+ if (!cons)
+ return errno;
+ mutex_init (&cons->lock);
+ cons->vcons_list = NULL;
+ cons->vcons_last = NULL;
+ cons->active = NULL;
+ cons->dir = opendir (_cons_file);
+ cons->slack = _cons_slack;
+ if (!cons->dir)
+ {
+ free (cons);
+ return errno;
+ }
+ cons->dirport = getdport (dirfd (cons->dir));
+ if (cons->dirport == MACH_PORT_NULL)
+ {
+ closedir (cons->dir);
+ free (cons);
+ return errno;
+ }
+
+ /* Request directory notifications. */
+ err = ports_create_port (cons_port_class, cons_port_bucket,
+ sizeof (*dir_notify_port), &dir_notify_port);
+ if (err)
+ {
+ mach_port_deallocate (mach_task_self (), cons->dirport);
+ closedir (cons->dir);
+ free (cons);
+ return err;
+ }
+ dir_notify_port->cons = cons;
+ dir_notify_port->vcons = NULL;
+
+ dir_notify = ports_get_right (dir_notify_port);
+ err = dir_notice_changes (cons->dirport, dir_notify,
+ MACH_MSG_TYPE_MAKE_SEND);
+ if (err)
+ {
+ mach_port_deallocate (mach_task_self (), cons->dirport);
+ closedir (cons->dir);
+ free (cons);
+ return err;
+ }
+ return 0;
+}
diff --git a/libcons/init-loop.c b/libcons/init-loop.c
new file mode 100644
index 00000000..18576cb0
--- /dev/null
+++ b/libcons/init-loop.c
@@ -0,0 +1,32 @@
+/* init-loop.c - Server loop for console client library.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ Written by Marcus Brinkmann.
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */
+
+#include <hurd/ports.h>
+
+#include "cons.h"
+
+void
+cons_server_loop (void)
+{
+ ports_manage_port_operations_one_thread (cons_port_bucket,
+ cons_demuxer, 0);
+ /* Not reached. */
+}
+
diff --git a/libcons/mutations.h b/libcons/mutations.h
new file mode 100644
index 00000000..af5ab2d0
--- /dev/null
+++ b/libcons/mutations.h
@@ -0,0 +1,27 @@
+/* mutations.h - MIG mutations for the console client library.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ Written by Marcus Brinkmann.
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */
+
+/* Only CPP macro definitions should go in this file. */
+
+#define FS_NOTIFY_INTRAN cons_notify_t begin_using_notify_port (fs_notify_t)
+#define FS_NOTIFY_DESTRUCTOR end_using_notify_port (cons_notify_t)
+
+#define FS_NOTIFY_IMPORTS import "priv.h";
+
diff --git a/libcons/opts-std-startup.c b/libcons/opts-std-startup.c
new file mode 100644
index 00000000..c4a7d7bd
--- /dev/null
+++ b/libcons/opts-std-startup.c
@@ -0,0 +1,91 @@
+/* opts-std-startup.c - Standard startup-time command line parser.
+ Copyright (C) 1995,96,97,98,99,2001,02 Free Software Foundation, Inc.
+ Written by Miles Bader <miles@gnu.org> and Marcus Brinkmann.
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+
+#include <stdio.h>
+#include <argp.h>
+
+#include "priv.h"
+
+
+/* Option keys for long-only options in diskfs_common_options. */
+#define OPT_SLACK 600 /* --slack */
+
+/* Common value for diskfs_common_options and diskfs_default_sync_interval. */
+#define DEFAULT_SLACK 100
+#define DEFAULT_SLACK_STRING STRINGIFY(DEFAULT_SLACK)
+#define STRINGIFY(x) STRINGIFY_1(x)
+#define STRINGIFY_1(x) #x
+
+/* Number of records the client is allowed to lag behind the
+ server. */
+int _cons_slack = DEFAULT_SLACK;
+
+/* The filename of the console server. */
+char *_cons_file;
+
+static const struct argp_option
+startup_options[] =
+{
+ { "slack", OPT_SLACK, "RECORDS", 0, "Max number of records the client is"
+ " allowed to lag behind the server (default " DEFAULT_SLACK_STRING ")" },
+ { 0, 0 }
+};
+
+static const char args_doc[] = "CONSOLE";
+static const char doc[] = "A console client.";
+
+
+static error_t
+parse_startup_opt (int opt, char *arg, struct argp_state *state)
+{
+ switch (opt)
+ {
+ case OPT_SLACK:
+ _cons_slack = atoi (arg);
+ break;
+
+ case ARGP_KEY_ARG:
+ if (state->arg_num > 0)
+ /* Too many arguments. */
+ argp_usage (state);
+
+ _cons_file = arg;
+ break;
+
+ case ARGP_KEY_END:
+ if (state->arg_num != 1)
+ /* Not enough arguments. */
+ argp_usage (state);
+ break;
+
+ default:
+ return ARGP_ERR_UNKNOWN;
+ }
+
+ return 0;
+}
+
+/* An argp structure for the standard console client command line
+ arguments. */
+const struct argp
+cons_startup_argp =
+{
+ startup_options, parse_startup_opt, args_doc, doc
+};
diff --git a/libcons/opts-version.c b/libcons/opts-version.c
new file mode 100644
index 00000000..f8751490
--- /dev/null
+++ b/libcons/opts-version.c
@@ -0,0 +1,44 @@
+/* opts-version.c - Default hook for argp --version handling
+ Copyright (C) 1996, 2002 Free Software Foundation, Inc.
+ Written by Miles Bader <miles@gnu.ai.mit.edu> and Marcus Brinkmann.
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+
+#include <stdio.h>
+#include <argp.h>
+#include <version.h>
+
+#include "priv.h"
+
+static void
+_print_version (FILE *stream, struct argp_state *state)
+{
+ if (argp_program_version)
+ /* If this is non-zero, then the program's probably defined it, so let
+ that take precedence over the default. */
+ fputs (argp_program_version, stream);
+ else if (cons_extra_version && *cons_extra_version)
+ fprintf (stream, "%s (%s) %s\n",
+ cons_client_name, cons_extra_version, cons_client_version);
+ else
+ fprintf (stream, "%s %s\n", cons_client_name, cons_client_version);
+
+ fputs (STANDARD_HURD_VERSION (libcons) "\n", stream);
+}
+
+void (*argp_program_version_hook) (FILE *stream, struct argp_state *state)
+ = _print_version;
diff --git a/libcons/priv.h b/libcons/priv.h
new file mode 100644
index 00000000..c99a1600
--- /dev/null
+++ b/libcons/priv.h
@@ -0,0 +1,50 @@
+/* Private declarations for cons library
+ Copyright (C) 2002 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+
+#ifndef _CONS_PRIV_H
+#define _CONS_PRIV_H
+
+#include "cons.h"
+
+
+/* Number of records the client is allowed to lag behind the
+ server. */
+extern int _cons_slack;
+
+/* The filename of the console server. */
+extern char *_cons_file;
+
+
+/* Called by MiG to translate ports into cons_notify_t. mutations.h
+ arranges for this to happen for the fs_notify interfaces. */
+static inline cons_notify_t
+begin_using_notify_port (fs_notify_t port)
+{
+ return ports_lookup_port (cons_port_bucket, port, cons_port_class);
+}
+
+/* Called by MiG after server routines have been run; this balances
+ begin_using_notify_port, and is arranged for the fs_notify
+ interfaces by mutations.h. */
+static inline void
+end_using_notify_port (cons_notify_t cred)
+{
+ if (cred)
+ ports_port_deref (cred);
+}
+
+#endif /* _CONS_PRIV_H */
diff --git a/libcons/vcons-add.c b/libcons/vcons-add.c
new file mode 100644
index 00000000..cc7717f6
--- /dev/null
+++ b/libcons/vcons-add.c
@@ -0,0 +1,43 @@
+/* vcons-add.c - Add a virtual console.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ Written by Marcus Brinkmann.
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */
+
+#include <errno.h>
+
+#include "cons.h"
+
+/* The virtual console VCONS was just added. VCONS->cons is
+ locked. */
+void
+cons_vcons_add (vcons_t vcons)
+{
+ error_t err;
+
+ /* The first console added will be activated automatically. */
+ if (vcons->cons->active)
+ return;
+
+ /* Forward the activation request to the user. */
+ err = cons_vcons_activate (vcons);
+ if (!err)
+ {
+ vcons->cons->active = vcons;
+ cons_vcons_refresh (vcons);
+ }
+}
diff --git a/libcons/vcons-close.c b/libcons/vcons-close.c
new file mode 100644
index 00000000..584c3e61
--- /dev/null
+++ b/libcons/vcons-close.c
@@ -0,0 +1,51 @@
+/* vcons-close.c - Close a virtual console.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ Written by Marcus Brinkmann.
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */
+
+#include <errno.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <sys/mman.h>
+#include <sys/fcntl.h>
+
+#include <hurd.h>
+#include <mach.h>
+
+#include "cons.h"
+
+/* Close the virtual console VCONS. VCONS->cons is locked. */
+void
+cons_vcons_close (vcons_t vcons)
+{
+ if (vcons->input >= 0)
+ {
+ close (vcons->input);
+ vcons->input = -1;
+ }
+ if (vcons->display != MAP_FAILED)
+ {
+ munmap (vcons->display, vcons->display_size);
+ vcons->display = MAP_FAILED;
+ }
+ if (vcons->notify)
+ {
+ ports_destroy_right (vcons->notify);
+ vcons->notify = NULL;
+ }
+}
diff --git a/libcons/vcons-open.c b/libcons/vcons-open.c
new file mode 100644
index 00000000..7256b4c8
--- /dev/null
+++ b/libcons/vcons-open.c
@@ -0,0 +1,162 @@
+/* vcons-open.c - Open a virtual console.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ Written by Marcus Brinkmann.
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */
+
+#include <errno.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <sys/mman.h>
+#include <sys/fcntl.h>
+
+#include <hurd.h>
+#include <mach.h>
+
+#include "cons.h"
+
+/* Open the virtual console VCONS. VCONS->cons is locked. */
+error_t
+cons_vcons_open (vcons_t vcons)
+{
+ error_t err = 0;
+ char *name;
+ file_t vconsp = MACH_PORT_NULL;
+ file_t file = MACH_PORT_NULL;
+ int fd = -1;
+ struct stat statbuf;
+ mach_port_t notify = MACH_PORT_NULL;
+
+ if (asprintf (&name, "%u", vcons->id) < 0)
+ return err;
+
+ /* Open the directory port of the virtual console. */
+ vconsp = file_name_lookup_under (vcons->cons->dirport, name,
+ O_DIRECTORY | O_RDONLY, 0);
+ if (vconsp == MACH_PORT_NULL)
+ {
+ err = errno;
+ goto err;
+ }
+
+ /* Within that directory, open the input node. */
+ file = file_name_lookup_under (vconsp, "input", O_WRONLY /* | O_NONBLOCK */, 0);
+ if (file == MACH_PORT_NULL)
+ err = errno;
+ else
+ {
+ vcons->input = openport (file, O_WRONLY /* | O_NONBLOCK */);
+ if (vcons->input < 0)
+ err = errno;
+ else
+ /* openport() consumed the reference. */
+ file = MACH_PORT_NULL;
+ }
+ if (err)
+ goto err;
+
+ /* Within that directory, also open the display node. */
+ file = file_name_lookup_under (vconsp, "display", O_RDONLY, 0);
+ if (file == MACH_PORT_NULL)
+ err = errno;
+ else
+ {
+ /* Acquire an additional reference for openport(). */
+ err = mach_port_mod_refs (mach_task_self (), file,
+ MACH_PORT_RIGHT_SEND, +1);
+ if (err)
+ goto err;
+ fd = openport (file, O_RDONLY);
+ if (fd < 0)
+ err = errno;
+ }
+ if (err)
+ goto err;
+
+ /* Map the whole file. */
+ if (fstat (fd, &statbuf) < 0)
+ {
+ err = errno;
+ goto err;
+ }
+ vcons->display_size = statbuf.st_size;
+ vcons->display = mmap (0, vcons->display_size, PROT_READ, MAP_SHARED, fd, 0);
+ if (vcons->display == MAP_FAILED)
+ {
+ err = errno;
+ goto err;
+ }
+
+ if (vcons->display->magic != CONS_MAGIC
+ || vcons->display->version >> CONS_VERSION_MAJ_SHIFT != 0)
+ {
+ err = EINVAL;
+ goto err;
+ }
+ vcons->state.screen.width = vcons->display->screen.width;
+ vcons->state.screen.height = vcons->display->screen.height;
+ vcons->state.screen.lines = vcons->display->screen.lines;
+ vcons->state.screen.matrix = ((wchar_t *) vcons->display)
+ + vcons->display->screen.matrix;
+ vcons->state.changes.length = vcons->display->changes.length;
+ vcons->state.changes.buffer = ((uint32_t *) vcons->display)
+ + vcons->display->changes.buffer;
+
+ /* Set up the port we receive notification messages on. */
+ err = ports_create_port (cons_port_class, cons_port_bucket,
+ sizeof (*vcons->notify), &vcons->notify);
+ if (err)
+ goto err;
+ vcons->notify->cons = NULL;
+ vcons->notify->vcons = vcons;
+
+ /* Request notification messages. */
+ notify = ports_get_right (vcons->notify);
+ mach_port_set_qlimit (mach_task_self (), notify, 1);
+
+ /* When this succeeds, we will immediately receive notification
+ messages for this virtual console. */
+ err = file_notice_changes (file, notify, MACH_MSG_TYPE_MAKE_SEND);
+ if (!err)
+ goto out;
+
+ err:
+ if (vcons->input >= 0)
+ {
+ close (vcons->input);
+ vcons->input = -1;
+ }
+ if (vcons->display != MAP_FAILED)
+ {
+ munmap (vcons->display, vcons->display_size);
+ vcons->display = MAP_FAILED;
+ }
+ if (notify)
+ {
+ mach_port_deallocate (mach_task_self (), notify);
+ vcons->notify = MACH_PORT_NULL;
+ }
+ out:
+ if (fd > 0)
+ close (fd);
+ if (file != MACH_PORT_NULL)
+ mach_port_deallocate (mach_task_self (), file);
+ if (vconsp != MACH_PORT_NULL)
+ mach_port_deallocate (mach_task_self (), vconsp);
+ free (name);
+ return err;
+}
diff --git a/libcons/vcons-refresh.c b/libcons/vcons-refresh.c
new file mode 100644
index 00000000..34f0de88
--- /dev/null
+++ b/libcons/vcons-refresh.c
@@ -0,0 +1,60 @@
+/* vcons-refresh.c - Redraw a virtual console.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ Written by Marcus Brinkmann.
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */
+
+#include <errno.h>
+#include <assert.h>
+
+#include "cons.h"
+
+/* Redraw the virtual console VCONS, which is locked. */
+void
+cons_vcons_refresh (vcons_t vcons)
+{
+ vcons->state.screen.cur_line = vcons->display->screen.cur_line;
+ vcons->state.screen.scr_lines = vcons->display->screen.scr_lines;
+ vcons->state.cursor.col = vcons->display->cursor.col;
+ vcons->state.cursor.row = vcons->display->cursor.row;
+ vcons->state.cursor.status = vcons->display->cursor.status;
+ vcons->state.bell.audible = vcons->display->bell.audible;
+ vcons->state.bell.visible = vcons->display->bell.visible;
+ vcons->state.changes.written = vcons->display->changes.written;
+
+ cons_vcons_write (vcons, vcons->state.screen.matrix
+ + vcons->state.screen.cur_line * vcons->state.screen.width,
+ ((vcons->state.screen.lines - vcons->state.screen.cur_line
+ < vcons->state.screen.height)
+ ? vcons->state.screen.lines - vcons->state.screen.cur_line
+ : vcons->state.screen.height)
+ * vcons->state.screen.width, 0, 0);
+ if (vcons->state.screen.lines - vcons->state.screen.cur_line
+ < vcons->state.screen.height)
+ cons_vcons_write (vcons, vcons->state.screen.matrix,
+ vcons->state.screen.height * vcons->state.screen.width
+ - (vcons->state.screen.lines
+ - vcons->state.screen.cur_line)
+ * vcons->state.screen.width, 0,
+ vcons->state.screen.lines
+ - vcons->state.screen.cur_line);
+
+ cons_vcons_set_cursor_pos (vcons, vcons->state.cursor.col,
+ vcons->state.cursor.row);
+ cons_vcons_set_cursor_status (vcons, vcons->state.cursor.status);
+ cons_vcons_update (vcons);
+}
diff --git a/libcons/vcons-remove.c b/libcons/vcons-remove.c
new file mode 100644
index 00000000..56fb34ab
--- /dev/null
+++ b/libcons/vcons-remove.c
@@ -0,0 +1,32 @@
+/* vcons-remove.c - Remove a virtual console.
+ Copyright (C) 2002 Free Software Foundation, Inc.
+ Written by Marcus Brinkmann.
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */
+
+#include <errno.h>
+#include <assert.h>
+
+#include "cons.h"
+
+/* The virtual console VCONS is going to be removed. VCONS->cons is
+ locked. */
+void
+cons_vcons_remove (vcons_t vcons)
+{
+ assert (vcons != vcons->cons->active);
+}