#include <mini-os/xmalloc.h>
#include <mini-os/fbfront.h>
#include <mini-os/lib.h>
+#ifdef HAVE_LIBC
+#include <errno.h>
+#endif
DECLARE_WAIT_QUEUE_HEAD(kbdfront_queue);
{
#ifdef HAVE_LIBC
struct kbdfront_dev *dev = data;
- int fd = dev->fd;
+ struct file *file = get_file_from_fd(dev->fd);
- if (fd != -1)
- files[fd].read = true;
+ if ( file )
+ file->read = true;
#endif
wake_up(&kbdfront_queue);
}
struct xenkbd_page *page = dev->page;
uint32_t prod, cons;
int i;
-
#ifdef HAVE_LIBC
- if (dev->fd != -1) {
- files[dev->fd].read = false;
+ struct file *file = get_file_from_fd(dev->fd);
+
+ if ( file )
+ {
+ file->read = false;
mb(); /* Make sure to let the handler set read to 1 before we start looking at the ring */
}
#endif
notify_remote_via_evtchn(dev->evtchn);
#ifdef HAVE_LIBC
- if (cons != prod && dev->fd != -1)
+ if ( cons != prod && file )
/* still some events to read */
- files[dev->fd].read = true;
+ file->read = true;
#endif
return i;
}
#ifdef HAVE_LIBC
+static int kbd_read(struct file *file, void *buf, size_t nbytes)
+{
+ int ret, n;
+
+ n = nbytes / sizeof(union xenkbd_in_event);
+ ret = kbdfront_receive(file->dev, buf, n);
+ if ( ret <= 0 )
+ {
+ errno = EAGAIN;
+ return -1;
+ }
+
+ return ret * sizeof(union xenkbd_in_event);
+}
+
+static int kbd_close_fd(struct file *file)
+{
+ shutdown_kbdfront(file->dev);
+
+ return 0;
+}
+
+static struct file_ops kbd_ops = {
+ .name = "kbd",
+ .read = kbd_read,
+ .close = kbd_close_fd,
+ .select_rd = select_read_flag,
+};
+
+static unsigned int ftype_kbd;
+
+__attribute__((constructor))
+static void kbdfront_initialize(void)
+{
+ ftype_kbd = alloc_file_type(&kbd_ops);
+}
+
int kbdfront_open(struct kbdfront_dev *dev)
{
- dev->fd = alloc_fd(FTYPE_KBD);
+ struct file *file;
+
+ dev->fd = alloc_fd(ftype_kbd);
printk("kbd_open(%s) -> %d\n", dev->nodename, dev->fd);
- files[dev->fd].dev = dev;
+ file = get_file_from_fd(dev->fd);
+ file->dev = dev;
+
return dev->fd;
}
#endif
{
#ifdef HAVE_LIBC
struct fbfront_dev *dev = data;
- int fd = dev->fd;
+ struct file *file = get_file_from_fd(dev->fd);
- if (fd != -1)
- files[fd].read = true;
+ if ( file )
+ file->read = true;
#endif
wake_up(&fbfront_queue);
}
struct xenfb_page *page = dev->page;
uint32_t prod, cons;
int i;
-
#ifdef HAVE_LIBC
- if (dev->fd != -1) {
- files[dev->fd].read = false;
+ struct file *file = get_file_from_fd(dev->fd);
+
+ if ( file )
+ {
+ file->read = false;
mb(); /* Make sure to let the handler set read to 1 before we start looking at the ring */
}
#endif
notify_remote_via_evtchn(dev->evtchn);
#ifdef HAVE_LIBC
- if (cons != prod && dev->fd != -1)
+ if ( cons != prod && file )
/* still some events to read */
- files[dev->fd].read = true;
+ file->read = true;
#endif
return i;
}
#ifdef HAVE_LIBC
+static int fbfront_read(struct file *file, void *buf, size_t nbytes)
+{
+ int ret, n;
+
+ n = nbytes / sizeof(union xenfb_in_event);
+ ret = fbfront_receive(file->dev, buf, n);
+ if ( ret <= 0 )
+ {
+ errno = EAGAIN;
+ return -1;
+ }
+
+ return ret * sizeof(union xenfb_in_event);
+}
+
+static int fbfront_close_fd(struct file *file)
+{
+ shutdown_fbfront(file->dev);
+
+ return 0;
+}
+
+static const struct file_ops fb_ops = {
+ .name = "fb",
+ .read = fbfront_read,
+ .close = fbfront_close_fd,
+ .select_rd = select_read_flag,
+};
+
+static unsigned int ftype_fb;
+
+__attribute__((constructor))
+static void fbfront_initialize(void)
+{
+ ftype_fb = alloc_file_type(&fb_ops);
+}
+
int fbfront_open(struct fbfront_dev *dev)
{
- dev->fd = alloc_fd(FTYPE_FB);
+ struct file *file;
+
+ dev->fd = alloc_fd(ftype_fb);
printk("fb_open(%s) -> %d\n", dev->nodename, dev->fd);
- files[dev->fd].dev = dev;
+ file = get_file_from_fd(dev->fd);
+ file->dev = dev;
return dev->fd;
}
#endif
#ifdef HAVE_LWIP
case FTYPE_SOCKET:
return lwip_read(files[fd].fd, buf, nbytes);
-#endif
-#ifdef CONFIG_KBDFRONT
- case FTYPE_KBD: {
- int ret, n;
- n = nbytes / sizeof(union xenkbd_in_event);
- ret = kbdfront_receive(files[fd].dev, buf, n);
- if (ret <= 0) {
- errno = EAGAIN;
- return -1;
- }
- return ret * sizeof(union xenkbd_in_event);
- }
-#endif
-#ifdef CONFIG_FBFRONT
- case FTYPE_FB: {
- int ret, n;
- n = nbytes / sizeof(union xenfb_in_event);
- ret = fbfront_receive(files[fd].dev, buf, n);
- if (ret <= 0) {
- errno = EAGAIN;
- return -1;
- }
- return ret * sizeof(union xenfb_in_event);
- }
#endif
default:
break;
res = lwip_close(files[fd].fd);
break;
#endif
-#ifdef CONFIG_KBDFRONT
- case FTYPE_KBD:
- shutdown_kbdfront(files[fd].dev);
- break;
-#endif
-#ifdef CONFIG_FBFRONT
- case FTYPE_FB:
- shutdown_fbfront(files[fd].dev);
- break;
-#endif
#ifdef CONFIG_CONSFRONT
case FTYPE_SAVEFILE:
case FTYPE_CONSOLE:
[FTYPE_NONE] = "none",
[FTYPE_CONSOLE] = "console",
[FTYPE_SOCKET] = "socket",
- [FTYPE_KBD] = "kbd",
- [FTYPE_FB] = "fb",
};
static const char *get_type_name(unsigned int type)
n++;
FD_CLR(i, exceptfds);
break;
- case FTYPE_KBD:
- case FTYPE_FB:
- if (FD_ISSET(i, readfds)) {
- if (files[i].read)
- n++;
- else
- FD_CLR(i, readfds);
- }
- FD_CLR(i, writefds);
- FD_CLR(i, exceptfds);
- break;
#ifdef HAVE_LWIP
case FTYPE_SOCKET:
if (FD_ISSET(i, readfds)) {