Merge from vendor branch SENDMAIL:
[games.git] / sys / sys / conf.h
1 /*-
2  * Copyright (c) 1990, 1993
3  *      The Regents of the University of California.  All rights reserved.
4  * (c) UNIX System Laboratories, Inc.
5  * All or some portions of this file are derived from material licensed
6  * to the University of California by American Telephone and Telegraph
7  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8  * the permission of UNIX System Laboratories, Inc.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *      This product includes software developed by the University of
21  *      California, Berkeley and its contributors.
22  * 4. Neither the name of the University nor the names of its contributors
23  *    may be used to endorse or promote products derived from this software
24  *    without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36  * SUCH DAMAGE.
37  *
38  *      @(#)conf.h      8.5 (Berkeley) 1/9/95
39  * $FreeBSD: src/sys/sys/conf.h,v 1.103.2.6 2002/03/11 01:14:55 dd Exp $
40  * $DragonFly: src/sys/sys/conf.h,v 1.10 2006/02/17 19:18:07 dillon Exp $
41  */
42
43 #ifndef _SYS_CONF_H_
44 #define _SYS_CONF_H_
45
46 #include <sys/queue.h>
47 #include <sys/time.h>
48 #include <sys/biotrack.h>
49
50 #define SPECNAMELEN     15
51
52 struct tty;
53 struct disk;
54 struct vnode;
55 struct lwkt_port;
56
57 struct specinfo {
58         u_int           si_flags;
59         udev_t          si_udev;
60         LIST_ENTRY(specinfo)    si_hash;
61         SLIST_HEAD(, vnode) si_hlist;
62         char            si_name[SPECNAMELEN + 1];
63         void            *si_drv1;
64         void            *si_drv2;
65         struct cdevsw   *si_devsw;      /* direct device switch */
66         struct lwkt_port *si_port;      /* direct port dispatch */
67         int             si_iosize_max;  /* maximum I/O size (for physio &al) */
68         int             si_refs;
69         union {
70                 struct {
71                         struct tty *__sit_tty;
72                 } __si_tty;
73                 struct {
74                         struct disk *__sid_disk;
75                         struct mount *__sid_mountpoint;
76                         int __sid_bsize_phys; /* min physical block size */
77                         int __sid_bsize_best; /* optimal block size */
78                 } __si_disk;
79         } __si_u;
80         struct bio_track si_track_read;
81         struct bio_track si_track_write;
82         time_t          si_lastread;            /* time_second */
83         time_t          si_lastwrite;           /* time_second */
84 };
85
86 #define SI_STASHED      0x0001  /* created in stashed storage */
87 #define SI_HASHED       0x0002  /* in (maj,min) hash table */
88 #define SI_ADHOC        0x0004  /* created via make_adhoc_dev() or udev2dev() */
89
90 #define si_tty          __si_u.__si_tty.__sit_tty
91 #define si_disk         __si_u.__si_disk.__sid_disk
92 #define si_mountpoint   __si_u.__si_disk.__sid_mountpoint
93 #define si_bsize_phys   __si_u.__si_disk.__sid_bsize_phys
94 #define si_bsize_best   __si_u.__si_disk.__sid_bsize_best
95
96 #define CDEVSW_ALL_MINORS       0       /* mask of 0 always matches 0 */
97
98 /*
99  * Special device management
100  */
101 #define SPECHSZ 64
102 #define SPECHASH(rdev)  (((unsigned)(minor(rdev)))%SPECHSZ)
103
104 /*
105  * Definitions of device driver entry switches
106  */
107
108 struct buf;
109 struct bio;
110 struct proc;
111 struct uio;
112 struct knote;
113
114 /*
115  * Note: d_thread_t is provided as a transition aid for those drivers
116  * that treat struct proc/struct thread as an opaque data type and
117  * exist in substantially the same form in both 4.x and 5.x.  Writers
118  * of drivers that dips into the d_thread_t structure should use
119  * struct thread or struct proc as appropriate for the version of the
120  * OS they are using.  It is provided in lieu of each device driver
121  * inventing its own way of doing this.  While it does violate style(9)
122  * in a number of ways, this violation is deemed to be less
123  * important than the benefits that a uniform API between releases
124  * gives.
125  *
126  * Users of struct thread/struct proc that aren't device drivers should
127  * not use d_thread_t.
128  */
129
130 struct thread;
131 struct lwkt_port;
132
133 typedef struct thread d_thread_t;
134 typedef int d_clone_t (dev_t dev);
135 typedef int d_open_t (dev_t dev, int oflags, int devtype, d_thread_t *td);
136 typedef int d_close_t (dev_t dev, int fflag, int devtype, d_thread_t *td);
137 typedef void d_strategy_t (dev_t dev, struct bio *bio);
138 typedef int d_ioctl_t (dev_t dev, u_long cmd, caddr_t data,
139                            int fflag, d_thread_t *td);
140 typedef int d_dump_t (dev_t dev, u_int count, u_int blkno, u_int secsize);
141 typedef int d_psize_t (dev_t dev);
142
143 typedef int d_read_t (dev_t dev, struct uio *uio, int ioflag);
144 typedef int d_write_t (dev_t dev, struct uio *uio, int ioflag);
145 typedef int d_poll_t (dev_t dev, int events, d_thread_t *td);
146 typedef int d_kqfilter_t (dev_t dev, struct knote *kn);
147 typedef int d_mmap_t (dev_t dev, vm_offset_t offset, int nprot);
148
149 typedef int l_open_t (dev_t dev, struct tty *tp);
150 typedef int l_close_t (struct tty *tp, int flag);
151 typedef int l_read_t (struct tty *tp, struct uio *uio, int flag);
152 typedef int l_write_t (struct tty *tp, struct uio *uio, int flag);
153 typedef int l_ioctl_t (struct tty *tp, u_long cmd, caddr_t data,
154                            int flag, d_thread_t *td);
155 typedef int l_rint_t (int c, struct tty *tp);
156 typedef int l_start_t (struct tty *tp);
157 typedef int l_modem_t (struct tty *tp, int flag);
158
159 /*
160  * Types for d_flags.
161  */
162 #define D_TAPE  0x0001
163 #define D_DISK  0x0002
164 #define D_TTY   0x0004
165 #define D_MEM   0x0008
166
167 #define D_TYPEMASK      0xffff
168
169 /*
170  * Flags for d_flags.
171  */
172 #define D_MEMDISK       0x00010000      /* memory type disk */
173 #define D_NAGGED        0x00020000      /* nagged about missing make_dev() */
174 #define D_CANFREE       0x00040000      /* can free blocks */
175 #define D_TRACKCLOSE    0x00080000      /* track all closes */
176 #define D_MASTER        0x00100000      /* used by pty/tty code */
177 #define D_KQFILTER      0x00200000      /* has kqfilter entry */
178
179 /*
180  * Character device switch table.
181  *
182  * NOTE: positions are hard coded for static structure initialization.
183  */
184 struct cdevsw {
185         const char      *d_name;        /* base device name, e.g. 'vn' */
186         int             d_maj;          /* major (char) device number */
187         u_int           d_flags;        /* D_ flags */
188         struct lwkt_port *d_port;       /* port (template only) */
189         d_clone_t       *d_clone;       /* clone from base cdevsw */
190
191         /*
192          * Old style vectors are used only if d_port is NULL when the cdevsw
193          * is added to the system.   They have been renamed to prevent misuse.
194          */
195         d_open_t        *old_open;
196         d_close_t       *old_close;
197         d_read_t        *old_read;
198         d_write_t       *old_write;
199         d_ioctl_t       *old_ioctl;
200         d_poll_t        *old_poll;
201         d_mmap_t        *old_mmap;
202         d_strategy_t    *old_strategy;
203         d_dump_t        *old_dump;
204         d_psize_t       *old_psize;
205         d_kqfilter_t    *old_kqfilter;
206         void            (*old_dummy1)(void);    /* expansion space */
207         void            (*old_dummy2)(void);
208         void            (*old_dummy3)(void);
209         void            (*old_dummy4)(void);
210         int             d_refs;                 /* ref count */
211         void            *d_data;                /* custom driver data */
212 };
213
214 struct cdevlink {
215         struct cdevlink *next;
216         u_int           mask;
217         u_int           match;
218         struct cdevsw   *devsw;
219 };
220
221 /*
222  * Line discipline switch table
223  */
224 struct linesw {
225         l_open_t        *l_open;
226         l_close_t       *l_close;
227         l_read_t        *l_read;
228         l_write_t       *l_write;
229         l_ioctl_t       *l_ioctl;
230         l_rint_t        *l_rint;
231         l_start_t       *l_start;
232         l_modem_t       *l_modem;
233         u_char          l_hotchar;
234 };
235
236 #ifdef _KERNEL
237 extern struct linesw linesw[];
238 extern int nlinesw;
239
240 int ldisc_register (int , struct linesw *);
241 void ldisc_deregister (int);
242 #define LDISC_LOAD      -1              /* Loadable line discipline */
243 #endif
244
245 /*
246  * Swap device table
247  */
248 struct swdevt {
249         udev_t  sw_dev;                 /* For quasibogus swapdev reporting */
250         int     sw_flags;
251         int     sw_nblks;
252         struct  vnode *sw_vp;
253         dev_t   sw_device;
254 };
255 #define SW_FREED        0x01
256 #define SW_SEQUENTIAL   0x02
257 #define sw_freed        sw_flags        /* XXX compat */
258
259 #ifdef _KERNEL
260 d_open_t        noopen;
261 d_close_t       noclose;
262 d_read_t        noread;
263 d_write_t       nowrite;
264 d_ioctl_t       noioctl;
265 d_clone_t       noclone;
266 d_mmap_t        nommap;
267 d_kqfilter_t    nokqfilter;
268 d_strategy_t    nostrategy;
269 d_poll_t        nopoll;
270 d_psize_t       nopsize;
271 d_dump_t        nodump;
272
273 #define NUMCDEVSW 256
274
275 d_open_t        nullopen;
276 d_close_t       nullclose;
277
278 l_ioctl_t       l_nullioctl;
279 l_read_t        l_noread;
280 l_write_t       l_nowrite;
281
282 struct module;
283
284 struct devsw_module_data {
285         int     (*chainevh)(struct module *, int, void *); /* next handler */
286         void    *chainarg;      /* arg for next event handler */
287         /* Do not initialize fields hereafter */
288 };
289
290 #define DEV_MODULE(name, evh, arg)                                      \
291 static moduledata_t name##_mod = {                                      \
292     #name,                                                              \
293     evh,                                                                \
294     arg                                                                 \
295 };                                                                      \
296 DECLARE_MODULE(name, name##_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE)
297
298 extern struct cdevsw dead_cdevsw;
299
300 void    compile_devsw(struct cdevsw *);
301 int     cdevsw_add (struct cdevsw *, u_int mask, u_int match);
302 struct cdevsw *cdevsw_add_override (dev_t, u_int mask, u_int match);
303 struct lwkt_port *cdevsw_dev_override(dev_t dev, struct lwkt_port *port);
304
305 int     cdevsw_remove (struct cdevsw *, u_int mask, u_int match);
306 struct cdevsw *cdevsw_get (int x, int y);
307 void    cdevsw_release (struct cdevsw *);
308 int     count_dev (dev_t dev);
309 int     count_udev (udev_t dev);
310 void    destroy_dev (dev_t dev);
311 void    destroy_all_dev (struct cdevsw *, u_int mask, u_int match);
312 void    release_dev (dev_t dev);
313 dev_t   reference_dev (dev_t dev);
314 struct cdevsw *devsw (dev_t dev);
315 const char *devtoname (dev_t dev);
316 void    freedev (dev_t dev);
317 int     iszerodev (dev_t dev);
318 dev_t   make_dev (struct cdevsw *devsw, int minor, uid_t uid, gid_t gid, int perms, const char *fmt, ...) __printflike(6, 7);
319 dev_t   make_adhoc_dev (struct cdevsw *devsw, int minor);
320 dev_t   make_sub_dev (dev_t dev, int minor);
321 int     lminor (dev_t dev);
322 void    setconf (void);
323 dev_t   getdiskbyname(const char *name);
324 int     dev_is_good(dev_t dev);
325
326 /*
327  * XXX: This included for when DEVFS resurfaces 
328  */
329
330 #define         UID_ROOT        0
331 #define         UID_BIN         3
332 #define         UID_UUCP        66
333
334 #define         GID_WHEEL       0
335 #define         GID_KMEM        2
336 #define         GID_OPERATOR    5
337 #define         GID_BIN         7
338 #define         GID_GAMES       13
339 #define         GID_DIALER      68
340
341 #endif /* _KERNEL */
342
343 #endif /* !_SYS_CONF_H_ */