devnull

devnull - } /* For ioctl() */ static int nullioctl(struct...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
/* * Implementation of the null device, "null:", which generates an * immediate EOF on read and throws away anything written to it. */ #include <types.h> #include <kern/errno.h> #include <lib.h> #include <vfs.h> #include <dev.h> #include <uio.h> /* For open() */ static int nullopen(struct device *dev, int openflags) { (void)dev; (void)openflags; return 0; } /* For close() */ static int nullclose(struct device *dev) { (void)dev; return 0; } /* For d_io() */ static int nullio(struct device *dev, struct uio *uio) { /* * On write, discard everything without looking at it. * On read, do nothing, generating an immediate EOF. */ (void)dev; // unused if (uio->uio_rw == UIO_WRITE) { uio->uio_resid = 0; } return 0;
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: } /* For ioctl() */ static int nullioctl(struct device *dev, int op, userptr_t data) { /* * No ioctls. */ (void)dev; (void)op; (void)data; return EINVAL; } /* * Function to create and attach null: */ void devnull_create(void) { int result; struct device *dev; dev = kmalloc(sizeof(*dev)); if (dev==NULL) { panic(&quot;Could not add null device: out of memory\n&quot;); } dev-&gt;d_open = nullopen; dev-&gt;d_close = nullclose; dev-&gt;d_io = nullio; dev-&gt;d_ioctl = nullioctl; dev-&gt;d_blocks = 0; dev-&gt;d_blocksize = 1; dev-&gt;d_data = NULL; result = vfs_adddev(&quot;null&quot;, dev, 0); if (result) { panic(&quot;Could not add null device: %s\n&quot;, strerror(result)); } }...
View Full Document

Page1 / 2

devnull - } /* For ioctl() */ static int nullioctl(struct...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online