device - Vnode operations for VFS devices These hand off to...

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

View Full Document Right Arrow Icon
/* * Vnode operations for VFS devices. * * These hand off to the functions in the VFS device structure (see dev.h) * but take care of a bunch of common tasks in a uniform fashion. */ #include <types.h> #include <lib.h> #include <synch.h> #include <kern/errno.h> #include <kern/unistd.h> #include <kern/stat.h> #include <vnode.h> #include <uio.h> #include <dev.h> /* * Called for each open(). * * We reject O_APPEND. */ static int dev_open(struct vnode *v, int flags) { struct device *d = v->vn_data; return EINVAL; } return d->d_open(d, flags); } /* * Called on the last close(). * Just pass through. */ static int dev_close(struct vnode *v) { struct device *d = v->vn_data; return d->d_close(d); } /* * Called when the vnode refcount reaches zero. * Do nothing; devices are permanent. */ static int dev_reclaim(struct vnode *v) { (void)v; /* nothing - device continues to exist even when not in use */ return 0; }
Background image of page 1

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

View Full Document Right Arrow Icon
/* * Called for read. Hand off to d_io. */ static int dev_read(struct vnode *v, struct uio *uio) { struct device *d = v->vn_data; assert(uio->uio_rw == UIO_READ); return d->d_io(d, uio); } /* * Used for several functions with the same type signature that are * not meaningful on devices. */ static int null_io(struct vnode *v, struct uio *uio) { (void)v; (void)uio; return EINVAL; } /* * Called for write. Hand off to d_io. */ static int dev_write(struct vnode *v, struct uio *uio) { struct device *d = v->vn_data; assert(uio->uio_rw == UIO_WRITE); return d->d_io(d, uio); } /* * Called for ioctl(). Just pass through. */ static
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 8

device - Vnode operations for VFS devices These hand off to...

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

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