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