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