blob: 10495747ce8ed932c7b65066ccfe46120490b7fd [file] [log] [blame]
Jeff Dikecb8fa612007-10-16 01:27:34 -07001/*
Jeff Dikee99525f2007-10-16 01:26:41 -07002 * Copyright (C) 2002 - 2007 Jeff Dike (jdike@{linux.intel,addtoit}.com)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 * Licensed under the GPL
4 */
5
Jeff Dikee99525f2007-10-16 01:26:41 -07006#include <stddef.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07007#include <errno.h>
Jeff Dikee99525f2007-10-16 01:26:41 -07008#include <fcntl.h>
Jeff Dikee99525f2007-10-16 01:26:41 -07009#include "chan_user.h"
Al Viro37185b32012-10-08 03:27:32 +010010#include <os.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011
Simon Arlottb60745b2007-10-20 01:23:03 +020012/* This address is used only as a unique identifier */
Linus Torvalds1da177e2005-04-16 15:20:36 -070013static int null_chan;
14
Jeff Dike5e7672e2006-09-27 01:50:33 -070015static void *null_init(char *str, int device, const struct chan_opts *opts)
Linus Torvalds1da177e2005-04-16 15:20:36 -070016{
Jeff Dikee99525f2007-10-16 01:26:41 -070017 return &null_chan;
Linus Torvalds1da177e2005-04-16 15:20:36 -070018}
19
20static int null_open(int input, int output, int primary, void *d,
21 char **dev_out)
22{
Jeff Dikee99525f2007-10-16 01:26:41 -070023 int fd;
24
Linus Torvalds1da177e2005-04-16 15:20:36 -070025 *dev_out = NULL;
Jeff Dikee99525f2007-10-16 01:26:41 -070026
27 fd = open(DEV_NULL, O_RDWR);
28 return (fd < 0) ? -errno : fd;
Linus Torvalds1da177e2005-04-16 15:20:36 -070029}
30
31static int null_read(int fd, char *c_out, void *unused)
32{
Jeff Dikee99525f2007-10-16 01:26:41 -070033 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -070034}
35
36static void null_free(void *data)
37{
38}
39
Jeff Dike5e7672e2006-09-27 01:50:33 -070040const struct chan_ops null_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 .type = "null",
42 .init = null_init,
43 .open = null_open,
44 .close = generic_close,
45 .read = null_read,
46 .write = generic_write,
47 .console_write = generic_console_write,
48 .window_size = generic_window_size,
49 .free = null_free,
50 .winch = 0,
51};