vfs: check userland buffers before reading them.
[haiku.git] / src / add-ons / kernel / drivers / common / null.c
blob29f8cb199540050ae270fd67a7f78515666d4b20
1 /*
2 * Copyright 2002-2006, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
5 * Copyright 2001-2002, Travis Geiselbrecht. All rights reserved.
6 * Distributed under the terms of the NewOS License.
7 */
10 #include <Drivers.h>
11 #include <string.h>
14 #define DEVICE_NAME "null"
16 int32 api_version = B_CUR_DRIVER_API_VERSION;
19 static status_t
20 null_open(const char *name, uint32 flags, void **cookie)
22 *cookie = NULL;
23 return B_OK;
27 static status_t
28 null_close(void *cookie)
30 return B_OK;
34 static status_t
35 null_freecookie(void *cookie)
37 return B_OK;
41 static status_t
42 null_ioctl(void *cookie, uint32 op, void *buffer, size_t length)
44 return EPERM;
48 static status_t
49 null_read(void *cookie, off_t pos, void *buffer, size_t *_length)
51 *_length = 0;
52 return B_OK;
56 static status_t
57 null_write(void *cookie, off_t pos, const void *buffer, size_t *_length)
59 return B_OK;
63 // #pragma mark -
66 status_t
67 init_hardware()
69 return B_OK;
73 const char **
74 publish_devices(void)
76 static const char *devices[] = {
77 DEVICE_NAME,
78 NULL
81 return devices;
85 device_hooks *
86 find_device(const char *name)
88 static device_hooks hooks = {
89 &null_open,
90 &null_close,
91 &null_freecookie,
92 &null_ioctl,
93 &null_read,
94 &null_write,
95 /* Leave select/deselect/readv/writev undefined. The kernel will
96 * use its own default implementation. The basic hooks above this
97 * line MUST be defined, however. */
98 NULL,
99 NULL,
100 NULL,
101 NULL
104 if (!strcmp(name, DEVICE_NAME))
105 return &hooks;
107 return NULL;
111 status_t
112 init_driver(void)
114 return B_OK;
118 void
119 uninit_driver(void)