kernfs.h revision 1.37.12.1 1 1.37.12.1 tls /* $NetBSD: kernfs.h,v 1.37.12.1 2014/08/10 06:56:05 tls Exp $ */
2 1.8 cgd
3 1.1 cgd /*
4 1.6 mycroft * Copyright (c) 1992, 1993
5 1.6 mycroft * The Regents of the University of California. All rights reserved.
6 1.1 cgd *
7 1.5 cgd * This code is derived from software donated to Berkeley by
8 1.1 cgd * Jan-Simon Pendry.
9 1.1 cgd *
10 1.2 cgd * Redistribution and use in source and binary forms, with or without
11 1.2 cgd * modification, are permitted provided that the following conditions
12 1.2 cgd * are met:
13 1.2 cgd * 1. Redistributions of source code must retain the above copyright
14 1.2 cgd * notice, this list of conditions and the following disclaimer.
15 1.2 cgd * 2. Redistributions in binary form must reproduce the above copyright
16 1.2 cgd * notice, this list of conditions and the following disclaimer in the
17 1.2 cgd * documentation and/or other materials provided with the distribution.
18 1.17 agc * 3. Neither the name of the University nor the names of its contributors
19 1.2 cgd * may be used to endorse or promote products derived from this software
20 1.2 cgd * without specific prior written permission.
21 1.1 cgd *
22 1.2 cgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 1.2 cgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 1.2 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 1.2 cgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 1.2 cgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 1.2 cgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 1.2 cgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 1.2 cgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 1.2 cgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 1.2 cgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 1.2 cgd * SUCH DAMAGE.
33 1.1 cgd *
34 1.12 fvdl * @(#)kernfs.h 8.6 (Berkeley) 3/29/95
35 1.1 cgd */
36 1.1 cgd
37 1.6 mycroft #define _PATH_KERNFS "/kern" /* Default mountpoint */
38 1.6 mycroft
39 1.9 briggs #ifdef _KERNEL
40 1.18 itojun #include <sys/queue.h>
41 1.34 apb #include <sys/tree.h>
42 1.37.12.1 tls #include <sys/mutex.h>
43 1.18 itojun
44 1.18 itojun /*
45 1.18 itojun * The different types of node in a kernfs filesystem
46 1.18 itojun */
47 1.18 itojun typedef enum {
48 1.20 darcy KFSkern, /* the filesystem itself (.) */
49 1.20 darcy KFSroot, /* the filesystem root (..) */
50 1.20 darcy KFSnull, /* none aplicable */
51 1.20 darcy KFStime, /* boottime */
52 1.20 darcy KFSint, /* integer */
53 1.20 darcy KFSstring, /* string */
54 1.20 darcy KFShostname, /* hostname */
55 1.20 darcy KFSavenrun, /* loadavg */
56 1.20 darcy KFSdevice, /* device file (rootdev/rrootdev) */
57 1.20 darcy KFSmsgbuf, /* msgbuf */
58 1.22 cl KFSsubdir, /* directory */
59 1.22 cl KFSlasttype, /* last used type */
60 1.22 cl KFSmaxtype = (1<<6) - 1 /* last possible type */
61 1.18 itojun } kfstype;
62 1.11 pk
63 1.18 itojun /*
64 1.22 cl * Control data for the kern file system.
65 1.18 itojun */
66 1.11 pk struct kern_target {
67 1.18 itojun u_char kt_type;
68 1.18 itojun u_char kt_namlen;
69 1.18 itojun const char *kt_name;
70 1.18 itojun void *kt_data;
71 1.18 itojun kfstype kt_tag;
72 1.18 itojun u_char kt_vtype;
73 1.18 itojun mode_t kt_mode;
74 1.1 cgd };
75 1.1 cgd
76 1.22 cl struct dyn_kern_target {
77 1.22 cl struct kern_target dkt_kt;
78 1.22 cl SIMPLEQ_ENTRY(dyn_kern_target) dkt_queue;
79 1.22 cl };
80 1.22 cl
81 1.22 cl struct kernfs_subdir {
82 1.22 cl SIMPLEQ_HEAD(,dyn_kern_target) ks_entries;
83 1.22 cl unsigned int ks_nentries;
84 1.22 cl unsigned int ks_dirs;
85 1.22 cl const struct kern_target *ks_parent;
86 1.22 cl };
87 1.22 cl
88 1.1 cgd struct kernfs_node {
89 1.18 itojun LIST_ENTRY(kernfs_node) kfs_hash; /* hash chain */
90 1.18 itojun TAILQ_ENTRY(kernfs_node) kfs_list; /* flat list */
91 1.32 alc struct vnode *kfs_vnode; /* vnode associated with this kernfs_node */
92 1.32 alc kfstype kfs_type; /* type of kernfs node */
93 1.18 itojun mode_t kfs_mode; /* mode bits for stat() */
94 1.18 itojun long kfs_fileno; /* unique file id */
95 1.18 itojun const struct kern_target *kfs_kt;
96 1.37.12.1 tls void *kfs_v; /* dynamic node private data */
97 1.18 itojun long kfs_cookie; /* fileno cookie */
98 1.18 itojun };
99 1.18 itojun
100 1.18 itojun struct kernfs_mount {
101 1.18 itojun TAILQ_HEAD(, kernfs_node) nodelist;
102 1.18 itojun long fileno_cookie;
103 1.1 cgd };
104 1.1 cgd
105 1.18 itojun #define UIO_MX 32
106 1.18 itojun
107 1.18 itojun #define KERNFS_FILENO(kt, typ, cookie) \
108 1.22 cl ((kt >= &kern_targets[0] && kt < &kern_targets[static_nkern_targets]) \
109 1.22 cl ? 2 + ((kt) - &kern_targets[0]) \
110 1.21 cl : (((cookie + 1) << 6) | (typ)))
111 1.22 cl #define KERNFS_TYPE_FILENO(typ, cookie) \
112 1.22 cl (((cookie + 1) << 6) | (typ))
113 1.18 itojun
114 1.1 cgd #define VFSTOKERNFS(mp) ((struct kernfs_mount *)((mp)->mnt_data))
115 1.18 itojun #define VTOKERN(vp) ((struct kernfs_node *)(vp)->v_data)
116 1.18 itojun #define KERNFSTOV(kfs) ((kfs)->kfs_vnode)
117 1.1 cgd
118 1.36 christos #define KERNFS_MAXNAMLEN 255
119 1.36 christos
120 1.18 itojun extern const struct kern_target kern_targets[];
121 1.18 itojun extern int nkern_targets;
122 1.22 cl extern const int static_nkern_targets;
123 1.25 xtraeme extern int (**kernfs_vnodeop_p)(void *);
124 1.1 cgd extern struct vfsops kernfs_vfsops;
125 1.6 mycroft extern dev_t rrootdev;
126 1.37.12.1 tls extern kmutex_t kfs_lock;
127 1.18 itojun
128 1.25 xtraeme int kernfs_root(struct mount *, struct vnode **);
129 1.18 itojun
130 1.22 cl /*
131 1.22 cl * Data types for the kernfs file operations.
132 1.22 cl */
133 1.22 cl typedef enum {
134 1.29 bouyer KERNFS_XREAD,
135 1.22 cl KERNFS_XWRITE,
136 1.22 cl KERNFS_FILEOP_CLOSE,
137 1.22 cl KERNFS_FILEOP_GETATTR,
138 1.22 cl KERNFS_FILEOP_IOCTL,
139 1.22 cl KERNFS_FILEOP_OPEN,
140 1.29 bouyer KERNFS_FILEOP_READ,
141 1.22 cl KERNFS_FILEOP_WRITE,
142 1.22 cl } kfsfileop;
143 1.22 cl
144 1.22 cl struct kernfs_fileop {
145 1.22 cl kfstype kf_type;
146 1.22 cl kfsfileop kf_fileop;
147 1.22 cl union {
148 1.22 cl int (*_kf_vop)(void *);
149 1.29 bouyer int (*_kf_xread)
150 1.30 bouyer (const struct kernfs_node *, char **, size_t);
151 1.22 cl int (*_kf_xwrite)
152 1.22 cl (const struct kernfs_node *, char *, size_t);
153 1.22 cl } _kf_opfn;
154 1.22 cl SPLAY_ENTRY(kernfs_fileop) kf_node;
155 1.22 cl };
156 1.31 christos
157 1.22 cl #define kf_vop _kf_opfn._kf_vop
158 1.29 bouyer #define kf_xread _kf_opfn._kf_xread
159 1.22 cl #define kf_xwrite _kf_opfn._kf_xwrite
160 1.22 cl
161 1.22 cl typedef struct kern_target kernfs_parentdir_t;
162 1.22 cl typedef struct dyn_kern_target kernfs_entry_t;
163 1.22 cl
164 1.22 cl /*
165 1.22 cl * Functions for adding kernfs datatypes and nodes.
166 1.22 cl */
167 1.22 cl kfstype kernfs_alloctype(int, const struct kernfs_fileop *);
168 1.22 cl #define KERNFS_ALLOCTYPE(kf) kernfs_alloctype(sizeof((kf)) / \
169 1.22 cl sizeof((kf)[0]), (kf))
170 1.22 cl #define KERNFS_ALLOCENTRY(dkt, m_type, m_flags) \
171 1.22 cl dkt = (struct dyn_kern_target *)malloc( \
172 1.22 cl sizeof(struct dyn_kern_target), (m_type), (m_flags))
173 1.22 cl #define KERNFS_INITENTRY(dkt, type, name, data, tag, vtype, mode) do { \
174 1.22 cl (dkt)->dkt_kt.kt_type = (type); \
175 1.22 cl (dkt)->dkt_kt.kt_namlen = strlen((name)); \
176 1.22 cl (dkt)->dkt_kt.kt_name = (name); \
177 1.22 cl (dkt)->dkt_kt.kt_data = (data); \
178 1.22 cl (dkt)->dkt_kt.kt_tag = (tag); \
179 1.22 cl (dkt)->dkt_kt.kt_vtype = (vtype); \
180 1.22 cl (dkt)->dkt_kt.kt_mode = (mode); \
181 1.22 cl } while (/*CONSTCOND*/0)
182 1.22 cl #define KERNFS_ENTOPARENTDIR(dkt) &(dkt)->dkt_kt
183 1.25 xtraeme int kernfs_addentry(kernfs_parentdir_t *, kernfs_entry_t *);
184 1.22 cl
185 1.35 christos #ifdef IPSEC
186 1.35 christos __weak_extern(key_freesp)
187 1.35 christos __weak_extern(key_getspbyid)
188 1.35 christos __weak_extern(key_setdumpsa_spi)
189 1.35 christos __weak_extern(key_setdumpsp)
190 1.35 christos __weak_extern(satailq)
191 1.35 christos __weak_extern(sptailq)
192 1.35 christos #endif
193 1.35 christos
194 1.9 briggs #endif /* _KERNEL */
195