Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 17 Nov 2012 06:02:41 +0000 (UTC)
From:      Eitan Adler <eadler@FreeBSD.org>
To:        doc-committers@freebsd.org, svn-doc-all@freebsd.org, svn-doc-head@freebsd.org
Subject:   svn commit: r40051 - head/en_US.ISO8859-1/books/arch-handbook/driverbasics
Message-ID:  <201211170602.qAH62fGU041005@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: eadler
Date: Sat Nov 17 06:02:41 2012
New Revision: 40051
URL: http://svnweb.freebsd.org/changeset/doc/40051

Log:
  Remove ancient example code from the architecture handbook.
  
  Approved by:	bcr (mentor)

Modified:
  head/en_US.ISO8859-1/books/arch-handbook/driverbasics/chapter.xml

Modified: head/en_US.ISO8859-1/books/arch-handbook/driverbasics/chapter.xml
==============================================================================
--- head/en_US.ISO8859-1/books/arch-handbook/driverbasics/chapter.xml	Sat Nov 17 05:26:13 2012	(r40050)
+++ head/en_US.ISO8859-1/books/arch-handbook/driverbasics/chapter.xml	Sat Nov 17 06:02:41 2012	(r40051)
@@ -208,171 +208,7 @@ KMOD=skeleton
 
     <para>This simple example pseudo-device remembers whatever values
       you write to it and can then supply them back to you when you
-      read from it.  Two versions are shown, one for &os;&nbsp;4.X and
-      one for &os;&nbsp;5.X.</para>
-
-    <example>
-      <title>Example of a Sample Echo Pseudo-Device Driver for
-        &os;&nbsp;4.X</title>
-
-      <programlisting>/*
- * Simple `echo' pseudo-device KLD
- *
- * Murray Stokely
- */
-
-#define MIN(a,b) (((a) &lt; (b)) ? (a) : (b))
-
-#include &lt;sys/types.h&gt;
-#include &lt;sys/module.h&gt;
-#include &lt;sys/systm.h&gt;  /* uprintf */
-#include &lt;sys/errno.h&gt;
-#include &lt;sys/param.h&gt;  /* defines used in kernel.h */
-#include &lt;sys/kernel.h&gt; /* types used in module initialization */
-#include &lt;sys/conf.h&gt;   /* cdevsw struct */
-#include &lt;sys/uio.h&gt;    /* uio struct */
-#include &lt;sys/malloc.h&gt;
-
-#define BUFFERSIZE 256
-
-/* Function prototypes */
-d_open_t	echo_open;
-d_close_t	echo_close;
-d_read_t	echo_read;
-d_write_t	echo_write;
-
-/* Character device entry points */
-static struct cdevsw echo_cdevsw = {
-	echo_open,
-	echo_close,
-	echo_read,
-	echo_write,
-	noioctl,
-	nopoll,
-	nommap,
-	nostrategy,
-	"echo",
-	33,              /* reserved for lkms - /usr/src/sys/conf/majors */
-	nodump,
-	nopsize,
-	D_TTY,
-	-1
-};
-
-typedef struct s_echo {
-	char msg[BUFFERSIZE];
-	int len;
-} t_echo;
-
-/* vars */
-static dev_t sdev;
-static int count;
-static t_echo *echomsg;
-
-MALLOC_DECLARE(M_ECHOBUF);
-MALLOC_DEFINE(M_ECHOBUF, "echobuffer", "buffer for echo module");
-
-/*
- * This function is called by the kld[un]load(2) system calls to
- * determine what actions to take when a module is loaded or unloaded.
- */
-
-static int
-echo_loader(struct module *m, int what, void *arg)
-{
-	int err = 0;
-
-	switch (what) {
-	case MOD_LOAD:                /* kldload */
-		sdev = make_dev(<literal>&amp;</literal>echo_cdevsw,
-		    0,
-		    UID_ROOT,
-		    GID_WHEEL,
-		    0600,
-		    "echo");
-		/* kmalloc memory for use by this driver */
-		MALLOC(echomsg, t_echo *, sizeof(t_echo), M_ECHOBUF, M_WAITOK);
-		printf("Echo device loaded.\n");
-		break;
-	case MOD_UNLOAD:
-		destroy_dev(sdev);
-		FREE(echomsg,M_ECHOBUF);
-		printf("Echo device unloaded.\n");
-		break;
-	default:
-		err = EOPNOTSUPP;
-		break;
-	}
-	return(err);
-}
-
-int
-echo_open(dev_t dev, int oflags, int devtype, struct proc *p)
-{
-	int err = 0;
-
-	uprintf("Opened device \"echo\" successfully.\n");
-	return(err);
-}
-
-int
-echo_close(dev_t dev, int fflag, int devtype, struct proc *p)
-{
-	uprintf("Closing device \"echo.\"\n");
-	return(0);
-}
-
-/*
- * The read function just takes the buf that was saved via
- * echo_write() and returns it to userland for accessing.
- * uio(9)
- */
-
-int
-echo_read(dev_t dev, struct uio *uio, int ioflag)
-{
-	int err = 0;
-	int amt;
-
-	/*
-	 * How big is this read operation?  Either as big as the user wants,
-	 * or as big as the remaining data
-	 */
-	amt = MIN(uio-&gt;uio_resid, (echomsg-&gt;len - uio-&gt;uio_offset &gt; 0) ?
-	    echomsg-&gt;len - uio-&gt;uio_offset : 0);
-	if ((err = uiomove(echomsg-&gt;msg + uio-&gt;uio_offset,amt,uio)) != 0) {
-		uprintf("uiomove failed!\n");
-	}
-	return(err);
-}
-
-/*
- * echo_write takes in a character string and saves it
- * to buf for later accessing.
- */
-
-int
-echo_write(dev_t dev, struct uio *uio, int ioflag)
-{
-	int err = 0;
-
-	/* Copy the string in from user memory to kernel memory */
-	err = copyin(uio-&gt;uio_iov-&gt;iov_base, echomsg-&gt;msg,
-	    MIN(uio-&gt;uio_iov-&gt;iov_len, BUFFERSIZE - 1));
-
-	/* Now we need to null terminate, then record the length */
-	*(echomsg-&gt;msg + MIN(uio-&gt;uio_iov-&gt;iov_len, BUFFERSIZE - 1)) = 0;
-	echomsg-&gt;len = MIN(uio-&gt;uio_iov-&gt;iov_len, BUFFERSIZE);
-
-	if (err != 0) {
-		uprintf("Write failed: bad address!\n");
-	}
-	count++;
-	return(err);
-}
-
-DEV_MODULE(echo,echo_loader,NULL);</programlisting>
-    </example>
+      read from it.</para>
 
     <example>
       <title>Example of a Sample Echo Pseudo-Device Driver for



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201211170602.qAH62fGU041005>