Deleted Added
full compact
cdev.c (48275) cdev.c (66549)
1/* 08 Nov 1998*/
2/*
3 * cdev.c
4 *
5 * 08 Nov 1998 Rajesh Vaidheeswarran
6 *
7 * Copyright (c) 1998 Rajesh Vaidheeswarran
8 * All rights reserved.

--- 50 unchanged lines hidden (view full) ---

59 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
60 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
61 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
62 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
63 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
64 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
65 * SUCH DAMAGE.
66 *
1/* 08 Nov 1998*/
2/*
3 * cdev.c
4 *
5 * 08 Nov 1998 Rajesh Vaidheeswarran
6 *
7 * Copyright (c) 1998 Rajesh Vaidheeswarran
8 * All rights reserved.

--- 50 unchanged lines hidden (view full) ---

59 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
60 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
61 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
62 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
63 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
64 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
65 * SUCH DAMAGE.
66 *
67 *
68 * $FreeBSD: head/share/examples/kld/cdev/module/cdev.c 66549 2000-10-02 14:14:07Z sobomax $
67 */
69 */
70#include <sys/types.h>
71#include <sys/uio.h>
68#include <sys/param.h>
69#include <sys/systm.h>
70#include <sys/ioccom.h>
71#include <sys/systm.h>
72#include <sys/conf.h>
73
74#include "cdev.h"
75

--- 9 unchanged lines hidden (view full) ---

85 *
86 * You would have to use the "-R" option of "ld" to ensure a linkable file
87 * if you were to do this, since you would need to combine multiple ".o"
88 * files into a single ".o" file for use by "modload".
89 */
90
91#define CDEV_IOCTL1 _IOR('C', 1, u_int)
92
72#include <sys/param.h>
73#include <sys/systm.h>
74#include <sys/ioccom.h>
75#include <sys/systm.h>
76#include <sys/conf.h>
77
78#include "cdev.h"
79

--- 9 unchanged lines hidden (view full) ---

89 *
90 * You would have to use the "-R" option of "ld" to ensure a linkable file
91 * if you were to do this, since you would need to combine multiple ".o"
92 * files into a single ".o" file for use by "modload".
93 */
94
95#define CDEV_IOCTL1 _IOR('C', 1, u_int)
96
97/* Stores string recv'd by _write() */
98static char buf[512+1];
99static int len;
100
93int
94mydev_open(dev_t dev, int flag, int otyp, struct proc *procp)
95{
96 printf("mydev_open: dev_t=%d, flag=%x, otyp=%x, procp=%p\n",
97 dev2udev(dev), flag, otyp, procp);
101int
102mydev_open(dev_t dev, int flag, int otyp, struct proc *procp)
103{
104 printf("mydev_open: dev_t=%d, flag=%x, otyp=%x, procp=%p\n",
105 dev2udev(dev), flag, otyp, procp);
106 memset(&buf, '\0', 513);
107 len = 0;
98 return (0);
99}
100
101int
102mydev_close(dev_t dev, int flag, int otyp, struct proc *procp)
103{
104 printf("mydev_close: dev_t=%d, flag=%x, otyp=%x, procp=%p\n",
105 dev2udev(dev), flag, otyp, procp);

--- 14 unchanged lines hidden (view full) ---

120 break;
121 default:
122 printf("No such ioctl for me!\n");
123 error = EINVAL;
124 break;
125 }
126 return error;
127}
108 return (0);
109}
110
111int
112mydev_close(dev_t dev, int flag, int otyp, struct proc *procp)
113{
114 printf("mydev_close: dev_t=%d, flag=%x, otyp=%x, procp=%p\n",
115 dev2udev(dev), flag, otyp, procp);

--- 14 unchanged lines hidden (view full) ---

130 break;
131 default:
132 printf("No such ioctl for me!\n");
133 error = EINVAL;
134 break;
135 }
136 return error;
137}
138
139/*
140 * mydev_write takes in a character string and saves it
141 * to buf for later accessing.
142 */
143int
144mydev_write(dev_t dev, struct uio *uio, int ioflag)
145{
146 int err = 0;
147
148 printf("mydev_write: dev_t=%d, uio=%p, ioflag=%d\n",
149 dev2udev(dev), uio, ioflag);
150
151 err = copyinstr(uio->uio_iov->iov_base, &buf, 512, &len);
152 if (err != 0) {
153 printf("Write to \"cdev\" failed.\n");
154 }
155 return(err);
156}
157
158/*
159 * The mydev_read function just takes the buf that was saved
160 * via mydev_write() and returns it to userland for
161 * accessing.
162 */
163int
164mydev_read(dev_t dev, struct uio *uio, int ioflag)
165{
166 int err = 0;
167
168 printf("mydev_read: dev_t=%d, uio=%p, ioflag=%d\n",
169 dev2udev(dev), uio, ioflag);
170
171 if (len <= 0) {
172 err = -1;
173 } else { /* copy buf to userland */
174 copystr(&buf, uio->uio_iov->iov_base, 513, &len);
175 }
176 return(err);
177}