xref: /freebsd/sys/fs/pseudofs/pseudofs.h (revision 9733a808399b6599b24768c5f8f225be95f1cae1)
19733a808SDag-Erling Smørgrav /*-
29733a808SDag-Erling Smørgrav  * Copyright (c) 2001 Dag-Erling Co�dan Sm�rgrav
39733a808SDag-Erling Smørgrav  * All rights reserved.
49733a808SDag-Erling Smørgrav  *
59733a808SDag-Erling Smørgrav  * Redistribution and use in source and binary forms, with or without
69733a808SDag-Erling Smørgrav  * modification, are permitted provided that the following conditions
79733a808SDag-Erling Smørgrav  * are met:
89733a808SDag-Erling Smørgrav  * 1. Redistributions of source code must retain the above copyright
99733a808SDag-Erling Smørgrav  *    notice, this list of conditions and the following disclaimer
109733a808SDag-Erling Smørgrav  *    in this position and unchanged.
119733a808SDag-Erling Smørgrav  * 2. Redistributions in binary form must reproduce the above copyright
129733a808SDag-Erling Smørgrav  *    notice, this list of conditions and the following disclaimer in the
139733a808SDag-Erling Smørgrav  *    documentation and/or other materials provided with the distribution.
149733a808SDag-Erling Smørgrav  * 3. The name of the author may not be used to endorse or promote products
159733a808SDag-Erling Smørgrav  *    derived from this software without specific prior written permission.
169733a808SDag-Erling Smørgrav  *
179733a808SDag-Erling Smørgrav  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
189733a808SDag-Erling Smørgrav  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
199733a808SDag-Erling Smørgrav  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
209733a808SDag-Erling Smørgrav  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
219733a808SDag-Erling Smørgrav  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
229733a808SDag-Erling Smørgrav  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
239733a808SDag-Erling Smørgrav  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
249733a808SDag-Erling Smørgrav  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
259733a808SDag-Erling Smørgrav  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
269733a808SDag-Erling Smørgrav  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
279733a808SDag-Erling Smørgrav  *
289733a808SDag-Erling Smørgrav  *      $FreeBSD$
299733a808SDag-Erling Smørgrav  */
309733a808SDag-Erling Smørgrav 
319733a808SDag-Erling Smørgrav #ifndef _PSEUDOFS_H_INCLUDED
329733a808SDag-Erling Smørgrav #define _PSEUDOFS_H_INCLUDED
339733a808SDag-Erling Smørgrav 
349733a808SDag-Erling Smørgrav /*
359733a808SDag-Erling Smørgrav  * Limits and constants
369733a808SDag-Erling Smørgrav  */
379733a808SDag-Erling Smørgrav #define PFS_NAMELEN		24
389733a808SDag-Erling Smørgrav #define PFS_DELEN		(8 + PFS_NAMELEN)
399733a808SDag-Erling Smørgrav 
409733a808SDag-Erling Smørgrav typedef enum {
419733a808SDag-Erling Smørgrav 	pfstype_none = 0,
429733a808SDag-Erling Smørgrav 	pfstype_root,
439733a808SDag-Erling Smørgrav 	pfstype_dir,
449733a808SDag-Erling Smørgrav 	pfstype_this,
459733a808SDag-Erling Smørgrav 	pfstype_parent,
469733a808SDag-Erling Smørgrav 	pfstype_file,
479733a808SDag-Erling Smørgrav 	pfstype_symlink,
489733a808SDag-Erling Smørgrav 	pfstype_procdep
499733a808SDag-Erling Smørgrav } pfs_type_t;
509733a808SDag-Erling Smørgrav 
519733a808SDag-Erling Smørgrav /* Flags */
529733a808SDag-Erling Smørgrav #define	PFS_DYNAMIC		1
539733a808SDag-Erling Smørgrav 
549733a808SDag-Erling Smørgrav /*
559733a808SDag-Erling Smørgrav  * Data structures
569733a808SDag-Erling Smørgrav  */
579733a808SDag-Erling Smørgrav struct pfs_info;
589733a808SDag-Erling Smørgrav struct pfs_node;
599733a808SDag-Erling Smørgrav struct pfs_bitmap;
609733a808SDag-Erling Smørgrav 
619733a808SDag-Erling Smørgrav typedef int (*pfs_fill_t)(struct pfs_node *, struct proc *, struct sbuf *);
629733a808SDag-Erling Smørgrav 
639733a808SDag-Erling Smørgrav struct pfs_bitmap;		/* opaque */
649733a808SDag-Erling Smørgrav 
659733a808SDag-Erling Smørgrav /*
669733a808SDag-Erling Smørgrav  * pfs_info: describes a pseudofs instance
679733a808SDag-Erling Smørgrav  */
689733a808SDag-Erling Smørgrav struct pfs_info {
699733a808SDag-Erling Smørgrav 	char			 pi_name[MFSNAMELEN];
709733a808SDag-Erling Smørgrav 	struct pfs_node		*pi_root;
719733a808SDag-Erling Smørgrav 	/* members below this line aren't initialized */
729733a808SDag-Erling Smørgrav 	/* currently, the mutex is only used to protect the bitmap */
739733a808SDag-Erling Smørgrav 	struct mtx		 pi_mutex;
749733a808SDag-Erling Smørgrav 	struct pfs_bitmap	*pi_bitmap;
759733a808SDag-Erling Smørgrav };
769733a808SDag-Erling Smørgrav 
779733a808SDag-Erling Smørgrav /*
789733a808SDag-Erling Smørgrav  * pfs_node: describes a  node (file or directory) within a pseudofs
799733a808SDag-Erling Smørgrav  */
809733a808SDag-Erling Smørgrav struct pfs_node {
819733a808SDag-Erling Smørgrav 	char			 pn_name[PFS_NAMELEN];
829733a808SDag-Erling Smørgrav 	pfs_type_t		 pn_type;
839733a808SDag-Erling Smørgrav 	int			 pn_flags;
849733a808SDag-Erling Smørgrav 	uid_t			 pn_uid;
859733a808SDag-Erling Smørgrav 	gid_t			 pn_gid;
869733a808SDag-Erling Smørgrav 	mode_t			 pn_mode;
879733a808SDag-Erling Smørgrav 	union {
889733a808SDag-Erling Smørgrav 		void		*_pn_data;
899733a808SDag-Erling Smørgrav 		pfs_fill_t	 _pn_func;
909733a808SDag-Erling Smørgrav 		struct pfs_node	*_pn_nodes;
919733a808SDag-Erling Smørgrav 	} u1;
929733a808SDag-Erling Smørgrav #define pn_data		u1._pn_data
939733a808SDag-Erling Smørgrav #define pn_func		u1._pn_func
949733a808SDag-Erling Smørgrav #define pn_nodes	u1._pn_nodes
959733a808SDag-Erling Smørgrav 	/* members below this line aren't initialized */
969733a808SDag-Erling Smørgrav 	struct pfs_node		*pn_parent;
979733a808SDag-Erling Smørgrav 	union {
989733a808SDag-Erling Smørgrav 		u_int32_t	 _pn_fileno;
999733a808SDag-Erling Smørgrav 		struct pfs_node	*_pn_shadow;
1009733a808SDag-Erling Smørgrav 	} u2;
1019733a808SDag-Erling Smørgrav #define pn_fileno	u2._pn_fileno
1029733a808SDag-Erling Smørgrav #define pn_shadow	u2._pn_shadow
1039733a808SDag-Erling Smørgrav };
1049733a808SDag-Erling Smørgrav 
1059733a808SDag-Erling Smørgrav #define PFS_NODE(name, type, flags, uid, gid, mode, data) \
1069733a808SDag-Erling Smørgrav         { (name), (type), (flags), (uid), (gid), (mode), { (data) } }
1079733a808SDag-Erling Smørgrav #define PFS_DIR(name, flags, uid, gid, mode, nodes) \
1089733a808SDag-Erling Smørgrav         PFS_NODE(name, pfstype_dir, flags, uid, gid, mode, nodes)
1099733a808SDag-Erling Smørgrav #define PFS_ROOT(nodes) \
1109733a808SDag-Erling Smørgrav         PFS_NODE("/", pfstype_root, 0, 0, 0, 0555, nodes)
1119733a808SDag-Erling Smørgrav #define PFS_THIS \
1129733a808SDag-Erling Smørgrav 	PFS_NODE(".", pfstype_this, 0, 0, 0, 0, NULL)
1139733a808SDag-Erling Smørgrav #define PFS_PARENT \
1149733a808SDag-Erling Smørgrav 	PFS_NODE("..", pfstype_parent, 0, 0, 0, 0, NULL)
1159733a808SDag-Erling Smørgrav #define PFS_FILE(name, flags, uid, gid, mode, func) \
1169733a808SDag-Erling Smørgrav 	PFS_NODE(name, pfstype_file, flags, uid, gid, mode, func)
1179733a808SDag-Erling Smørgrav #define PFS_SYMLINK(name, flags, uid, gid, mode, func) \
1189733a808SDag-Erling Smørgrav 	PFS_NODE(name, pfstype_symlink, flags, uid, gid, mode, func)
1199733a808SDag-Erling Smørgrav #define PFS_LASTNODE \
1209733a808SDag-Erling Smørgrav 	PFS_NODE("", pfstype_none, 0, 0, 0, 0, NULL)
1219733a808SDag-Erling Smørgrav 
1229733a808SDag-Erling Smørgrav /*
1239733a808SDag-Erling Smørgrav  * VFS interface
1249733a808SDag-Erling Smørgrav  */
1259733a808SDag-Erling Smørgrav int	 pfs_mount		(struct pfs_info *pi,
1269733a808SDag-Erling Smørgrav 				 struct mount *mp, char *path, caddr_t data,
1279733a808SDag-Erling Smørgrav 				 struct nameidata *ndp, struct proc *p);
1289733a808SDag-Erling Smørgrav int	 pfs_unmount		(struct mount *mp, int mntflags,
1299733a808SDag-Erling Smørgrav 				 struct proc *p);
1309733a808SDag-Erling Smørgrav int	 pfs_root		(struct mount *mp, struct vnode **vpp);
1319733a808SDag-Erling Smørgrav int	 pfs_statfs		(struct mount *mp, struct statfs *sbp,
1329733a808SDag-Erling Smørgrav 				 struct proc *p);
1339733a808SDag-Erling Smørgrav int	 pfs_init		(struct pfs_info *pi, struct vfsconf *vfc);
1349733a808SDag-Erling Smørgrav int	 pfs_uninit		(struct pfs_info *pi, struct vfsconf *vfc);
1359733a808SDag-Erling Smørgrav 
1369733a808SDag-Erling Smørgrav /*
1379733a808SDag-Erling Smørgrav  * Now for some initialization magic...
1389733a808SDag-Erling Smørgrav  */
1399733a808SDag-Erling Smørgrav #define PSEUDOFS(name, root)						\
1409733a808SDag-Erling Smørgrav 									\
1419733a808SDag-Erling Smørgrav static struct pfs_info name##_info = {					\
1429733a808SDag-Erling Smørgrav 	#name,								\
1439733a808SDag-Erling Smørgrav 	&(root)								\
1449733a808SDag-Erling Smørgrav };									\
1459733a808SDag-Erling Smørgrav 									\
1469733a808SDag-Erling Smørgrav static int								\
1479733a808SDag-Erling Smørgrav _##name##_mount(struct mount *mp, char *path, caddr_t data,		\
1489733a808SDag-Erling Smørgrav 	     struct nameidata *ndp, struct proc *p) {			\
1499733a808SDag-Erling Smørgrav         return pfs_mount(&name##_info, mp, path, data, ndp, p);		\
1509733a808SDag-Erling Smørgrav }									\
1519733a808SDag-Erling Smørgrav 									\
1529733a808SDag-Erling Smørgrav static int								\
1539733a808SDag-Erling Smørgrav _##name##_init(struct vfsconf *vfc) {					\
1549733a808SDag-Erling Smørgrav         return pfs_init(&name##_info, vfc);				\
1559733a808SDag-Erling Smørgrav }									\
1569733a808SDag-Erling Smørgrav 									\
1579733a808SDag-Erling Smørgrav static int								\
1589733a808SDag-Erling Smørgrav _##name##_uninit(struct vfsconf *vfc) {					\
1599733a808SDag-Erling Smørgrav         return pfs_uninit(&name##_info, vfc);				\
1609733a808SDag-Erling Smørgrav }									\
1619733a808SDag-Erling Smørgrav 									\
1629733a808SDag-Erling Smørgrav static struct vfsops testfs_vfsops = {					\
1639733a808SDag-Erling Smørgrav 	_##name##_mount,						\
1649733a808SDag-Erling Smørgrav 	vfs_stdstart,							\
1659733a808SDag-Erling Smørgrav 	pfs_unmount,							\
1669733a808SDag-Erling Smørgrav 	pfs_root,							\
1679733a808SDag-Erling Smørgrav 	vfs_stdquotactl,						\
1689733a808SDag-Erling Smørgrav 	pfs_statfs,							\
1699733a808SDag-Erling Smørgrav 	vfs_stdsync,							\
1709733a808SDag-Erling Smørgrav 	vfs_stdvget,							\
1719733a808SDag-Erling Smørgrav 	vfs_stdfhtovp,							\
1729733a808SDag-Erling Smørgrav 	vfs_stdcheckexp,						\
1739733a808SDag-Erling Smørgrav 	vfs_stdvptofh,							\
1749733a808SDag-Erling Smørgrav 	_##name##_init,							\
1759733a808SDag-Erling Smørgrav 	_##name##_uninit,						\
1769733a808SDag-Erling Smørgrav 	vfs_stdextattrctl,						\
1779733a808SDag-Erling Smørgrav };									\
1789733a808SDag-Erling Smørgrav VFS_SET(name##_vfsops, name, VFCF_SYNTHETIC);				\
1799733a808SDag-Erling Smørgrav MODULE_DEPEND(name, pseudofs, 1, 1, 1);
1809733a808SDag-Erling Smørgrav 
1819733a808SDag-Erling Smørgrav #endif
182