Annotation of src/sys/miscfs/kernfs/kernfs.h, Revision 1.25
1.25 ! xtraeme 1: /* $NetBSD: kernfs.h,v 1.24 2005/05/20 13:16:54 chs 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>
41:
42: /*
43: * The different types of node in a kernfs filesystem
44: */
45: typedef enum {
1.20 darcy 46: KFSkern, /* the filesystem itself (.) */
47: KFSroot, /* the filesystem root (..) */
48: KFSnull, /* none aplicable */
49: KFStime, /* boottime */
50: KFSint, /* integer */
51: KFSstring, /* string */
52: KFShostname, /* hostname */
53: KFSavenrun, /* loadavg */
54: KFSdevice, /* device file (rootdev/rrootdev) */
55: KFSmsgbuf, /* msgbuf */
56: KFSipsecsadir, /* ipsec security association (top dir) */
57: KFSipsecspdir, /* ipsec security policy (top dir) */
58: KFSipsecsa, /* ipsec security association entry */
59: KFSipsecsp, /* ipsec security policy entry */
1.22 cl 60: KFSsubdir, /* directory */
61: KFSlasttype, /* last used type */
62: KFSmaxtype = (1<<6) - 1 /* last possible type */
1.18 itojun 63: } kfstype;
1.11 pk 64:
1.18 itojun 65: /*
1.22 cl 66: * Control data for the kern file system.
1.18 itojun 67: */
1.11 pk 68: struct kern_target {
1.18 itojun 69: u_char kt_type;
70: u_char kt_namlen;
71: const char *kt_name;
72: void *kt_data;
73: kfstype kt_tag;
74: u_char kt_vtype;
75: mode_t kt_mode;
1.1 cgd 76: };
77:
1.22 cl 78: struct dyn_kern_target {
79: struct kern_target dkt_kt;
80: SIMPLEQ_ENTRY(dyn_kern_target) dkt_queue;
81: };
82:
83: struct kernfs_subdir {
84: SIMPLEQ_HEAD(,dyn_kern_target) ks_entries;
85: unsigned int ks_nentries;
86: unsigned int ks_dirs;
87: const struct kern_target *ks_parent;
88: };
89:
1.1 cgd 90: struct kernfs_node {
1.18 itojun 91: LIST_ENTRY(kernfs_node) kfs_hash; /* hash chain */
92: TAILQ_ENTRY(kernfs_node) kfs_list; /* flat list */
93: struct vnode *kfs_vnode; /* vnode associated with this pfsnode */
94: kfstype kfs_type; /* type of procfs node */
95: mode_t kfs_mode; /* mode bits for stat() */
96: long kfs_fileno; /* unique file id */
1.20 darcy 97: u_int32_t kfs_value; /* SA id or SP id (KFSint) */
1.18 itojun 98: const struct kern_target *kfs_kt;
99: void *kfs_v; /* pointer to secasvar/secpolicy/mbuf */
100: long kfs_cookie; /* fileno cookie */
101: };
102:
103: struct kernfs_mount {
104: TAILQ_HEAD(, kernfs_node) nodelist;
105: long fileno_cookie;
1.1 cgd 106: };
107:
1.18 itojun 108: #define UIO_MX 32
109:
110: #define KERNFS_FILENO(kt, typ, cookie) \
1.22 cl 111: ((kt >= &kern_targets[0] && kt < &kern_targets[static_nkern_targets]) \
112: ? 2 + ((kt) - &kern_targets[0]) \
1.21 cl 113: : (((cookie + 1) << 6) | (typ)))
1.22 cl 114: #define KERNFS_TYPE_FILENO(typ, cookie) \
115: (((cookie + 1) << 6) | (typ))
1.18 itojun 116:
1.1 cgd 117: #define VFSTOKERNFS(mp) ((struct kernfs_mount *)((mp)->mnt_data))
1.18 itojun 118: #define VTOKERN(vp) ((struct kernfs_node *)(vp)->v_data)
119: #define KERNFSTOV(kfs) ((kfs)->kfs_vnode)
1.1 cgd 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.18 itojun 127:
128: struct secasvar;
129: struct secpolicy;
130:
1.25 ! xtraeme 131: int kernfs_root(struct mount *, struct vnode **);
1.18 itojun 132:
1.25 ! xtraeme 133: void kernfs_hashinit(void);
! 134: void kernfs_hashreinit(void);
! 135: void kernfs_hashdone(void);
! 136: int kernfs_freevp(struct vnode *);
! 137: int kernfs_allocvp(struct mount *, struct vnode **, kfstype,
! 138: const struct kern_target *, u_int32_t);
1.18 itojun 139:
1.25 ! xtraeme 140: void kernfs_revoke_sa(struct secasvar *);
! 141: void kernfs_revoke_sp(struct secpolicy *);
1.22 cl 142:
143: /*
144: * Data types for the kernfs file operations.
145: */
146: typedef enum {
147: KERNFS_XWRITE,
148: KERNFS_FILEOP_CLOSE,
149: KERNFS_FILEOP_GETATTR,
150: KERNFS_FILEOP_IOCTL,
151: KERNFS_FILEOP_OPEN,
152: KERNFS_FILEOP_WRITE,
153: } kfsfileop;
154:
155: struct kernfs_fileop {
156: kfstype kf_type;
157: kfsfileop kf_fileop;
158: union {
159: void *_kf_genop;
160: int (*_kf_vop)(void *);
161: int (*_kf_xwrite)
162: (const struct kernfs_node *, char *, size_t);
163: } _kf_opfn;
164: SPLAY_ENTRY(kernfs_fileop) kf_node;
165: };
166: #define kf_genop _kf_opfn
167: #define kf_vop _kf_opfn._kf_vop
168: #define kf_xwrite _kf_opfn._kf_xwrite
169:
170: typedef struct kern_target kernfs_parentdir_t;
171: typedef struct dyn_kern_target kernfs_entry_t;
172:
173: /*
174: * Functions for adding kernfs datatypes and nodes.
175: */
176: kfstype kernfs_alloctype(int, const struct kernfs_fileop *);
177: #define KERNFS_ALLOCTYPE(kf) kernfs_alloctype(sizeof((kf)) / \
178: sizeof((kf)[0]), (kf))
179: #define KERNFS_ALLOCENTRY(dkt, m_type, m_flags) \
180: dkt = (struct dyn_kern_target *)malloc( \
181: sizeof(struct dyn_kern_target), (m_type), (m_flags))
182: #define KERNFS_INITENTRY(dkt, type, name, data, tag, vtype, mode) do { \
183: (dkt)->dkt_kt.kt_type = (type); \
184: (dkt)->dkt_kt.kt_namlen = strlen((name)); \
185: (dkt)->dkt_kt.kt_name = (name); \
186: (dkt)->dkt_kt.kt_data = (data); \
187: (dkt)->dkt_kt.kt_tag = (tag); \
188: (dkt)->dkt_kt.kt_vtype = (vtype); \
189: (dkt)->dkt_kt.kt_mode = (mode); \
190: } while (/*CONSTCOND*/0)
191: #define KERNFS_ENTOPARENTDIR(dkt) &(dkt)->dkt_kt
1.25 ! xtraeme 192: int kernfs_addentry(kernfs_parentdir_t *, kernfs_entry_t *);
1.22 cl 193:
1.23 atatat 194: #ifdef SYSCTL_SETUP_PROTO
195: SYSCTL_SETUP_PROTO(sysctl_vfs_kernfs_setup);
196: #endif /* SYSCTL_SETUP_PROTO */
197:
1.9 briggs 198: #endif /* _KERNEL */
CVSweb <webmaster@jp.NetBSD.org>