Home | History | Annotate | Line # | Download | only in libpuffs
puffs.h revision 1.1
      1 /*	$NetBSD: puffs.h,v 1.1 2006/10/22 22:52:21 pooka Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 2005, 2006  Antti Kantee.  All Rights Reserved.
      5  *
      6  * Development of this software was supported by the
      7  * Google Summer of Code program and the Ulla Tuominen Foundation.
      8  * The Google SoC project was mentored by Bill Studenmund.
      9  *
     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.
     18  * 3. The name of the company nor the name of the author may be used to
     19  *    endorse or promote products derived from this software without specific
     20  *    prior written permission.
     21  *
     22  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
     23  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     24  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     25  * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR 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 OR
     28  * 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.
     33  */
     34 
     35 #ifndef _PUFFS_USER_H_
     36 #define _PUFFS_USER_H_
     37 
     38 #include <sys/param.h>
     39 #include <sys/mount.h>
     40 #include <sys/statvfs.h>
     41 #include <sys/vnode.h>
     42 
     43 #include <fs/puffs/puffs_msgif.h>
     44 
     45 /*
     46  * megaXXX: these are values from inside _KERNEL
     47  * need to work on the translation for ALL the necessary values.
     48  */
     49 #define PUFFS_VNOVAL (-1)
     50 #define PUFFS_ISDOTDOT 0x2000
     51 #define PUFFS_IO_APPEND 0x20
     52 
     53 /*
     54  * puffs vnode, i.e. puffs_node
     55  *
     56  * This represents all the relevant fields from struct vnode.
     57  * This may some day become struct vnode, but let's keep it separate
     58  * for now.
     59  *
     60  * XXX: this is not finished
     61  */
     62 struct puffs_node {
     63 	off_t		pn_size;
     64 	int		pn_flag;		/* struct vnode	flags	*/
     65 	void		*pn_data;		/* private data		*/
     66 	enum vtype	pn_type;
     67 	struct vattr	pn_va;
     68 
     69 	struct puffs_usermount *pn_mnt;
     70 
     71 	LIST_ENTRY(puffs_node) pn_entries;
     72 };
     73 
     74 /* callbacks for operations */
     75 struct puffs_vfsops {
     76 	int (*puffs_start)(struct puffs_usermount *,
     77 	    struct puffs_vfsreq_start *);
     78 	int (*puffs_unmount)(struct puffs_usermount *, int, pid_t);
     79 	int (*puffs_statvfs)(struct puffs_usermount *,
     80 	    struct statvfs *, pid_t);
     81 	int (*puffs_sync)(struct puffs_usermount *, int,
     82 	    const struct puffs_cred *, pid_t);
     83 };
     84 
     85 struct puffs_vnops {
     86 	int (*puffs_lookup)(struct puffs_usermount *,
     87 	    void *, void **, enum vtype *, const struct puffs_cn *);
     88 	int (*puffs_create)(struct puffs_usermount *,
     89 	    void *, void **, const struct puffs_cn *, const struct vattr *);
     90 	int (*puffs_mknod)(struct puffs_usermount *,
     91 	    void *, void **, const struct puffs_cn *, const struct vattr *);
     92 	int (*puffs_open)(struct puffs_usermount *,
     93 	    void *, int, const struct puffs_cred *, pid_t);
     94 	int (*puffs_close)(struct puffs_usermount *,
     95 	    void *, int, const struct puffs_cred *, pid_t);
     96 	int (*puffs_access)(struct puffs_usermount *,
     97 	    void *, int, const struct puffs_cred *, pid_t);
     98 	int (*puffs_getattr)(struct puffs_usermount *,
     99 	    void *, struct vattr *, const struct puffs_cred *, pid_t);
    100 	int (*puffs_setattr)(struct puffs_usermount *,
    101 	    void *, const struct vattr *, const struct puffs_cred *, pid_t);
    102 	int (*puffs_poll)(struct puffs_usermount *,
    103 	    void *, struct puffs_vnreq_poll *);
    104 	int (*puffs_revoke)(struct puffs_usermount *, void *, int);
    105 	int (*puffs_mmap)(struct puffs_usermount *,
    106 	    void *, struct puffs_vnreq_mmap *);
    107 	int (*puffs_fsync)(struct puffs_usermount *,
    108 	    void *, const struct puffs_cred *, int, off_t, off_t, pid_t);
    109 	int (*puffs_seek)(struct puffs_usermount *,
    110 	    void *, off_t, off_t, const struct puffs_cred *);
    111 	int (*puffs_remove)(struct puffs_usermount *,
    112 	    void *, void *, const struct puffs_cn *);
    113 	int (*puffs_link)(struct puffs_usermount *,
    114 	    void *, void *, const struct puffs_cn *);
    115 	int (*puffs_rename)(struct puffs_usermount *,
    116 	    void *, void *, const struct puffs_cn *, void *, void *,
    117 	    const struct puffs_cn *);
    118 	int (*puffs_mkdir)(struct puffs_usermount *,
    119 	    void *, void **, const struct puffs_cn *, const struct vattr *);
    120 	int (*puffs_rmdir)(struct puffs_usermount *,
    121 	    void *, void *, const struct puffs_cn *);
    122 	int (*puffs_symlink)(struct puffs_usermount *,
    123 	    void *, void **, const struct puffs_cn *, const struct vattr *,
    124 	    const char *);
    125 	int (*puffs_readdir)(struct puffs_usermount *,
    126 	    void *, struct dirent *, const struct puffs_cred *,
    127 	    off_t *, size_t *);
    128 	int (*puffs_readlink)(struct puffs_usermount *,
    129 	    void *, const struct puffs_cred *, char *, size_t *);
    130 	int (*puffs_reclaim)(struct puffs_usermount *,
    131 	    void *, pid_t);
    132 	int (*puffs_print)(struct puffs_usermount *,
    133 	    void *);
    134 	int (*puffs_pathconf)(struct puffs_usermount *,
    135 	    void *, int, int *);
    136 	int (*puffs_advlock)(struct puffs_usermount *,
    137 	    void *, void *, int, struct flock *, int);
    138 	int (*puffs_getpages)(struct puffs_usermount *,
    139 	    void *, struct puffs_vnreq_getpages *);
    140 	int (*puffs_putpages)(struct puffs_usermount *,
    141 	    void *, struct puffs_vnreq_putpages *);
    142 	int (*puffs_getextattr)(struct puffs_usermount *,
    143 	    void *, struct puffs_vnreq_getextattr *);
    144 	int (*puffs_setextattr)(struct puffs_usermount *,
    145 	    void *, struct puffs_vnreq_setextattr *);
    146 	int (*puffs_listextattr)(struct puffs_usermount *,
    147 	    void *, struct puffs_vnreq_listextattr *);
    148 	int (*puffs_read)(struct puffs_usermount *, void *,
    149 	    uint8_t *, off_t, size_t *, const struct puffs_cred *, int);
    150 	int (*puffs_write)(struct puffs_usermount *, void *,
    151 	    uint8_t *, off_t, size_t *, const struct puffs_cred *, int);
    152 
    153 	int (*puffs_ioctl1)(struct puffs_usermount *, void *,
    154 	    struct puffs_vnreq_fcnioctl *, struct puffs_sizeop *);
    155 	int (*puffs_ioctl2)(struct puffs_usermount *, void *,
    156 	    struct puffs_vnreq_fcnioctl *, struct puffs_sizeop *);
    157 	int (*puffs_fcntl1)(struct puffs_usermount *, void *,
    158 	    struct puffs_vnreq_fcnioctl *, struct puffs_sizeop *);
    159 	int (*puffs_fcntl2)(struct puffs_usermount *, void *,
    160 	    struct puffs_vnreq_fcnioctl *, struct puffs_sizeop *);
    161 };
    162 
    163 struct puffs_usermount {
    164 	struct puffs_vfsops	pu_pvfs;
    165 	struct puffs_vnops	pu_pvn;
    166 
    167 	int			pu_fd;
    168 	uint32_t		pu_flags;
    169 	size_t			pu_maxreqlen;
    170 
    171 	struct puffs_node	*pu_rootnode;
    172 	const char *		pu_rootpath;
    173 	LIST_HEAD(, puffs_node)	pu_pnodelst;
    174 
    175 	int	pu_wcnt;
    176 	void	*pu_privdata;
    177 };
    178 
    179 #define PUFFSFLAG_OPDUMP	0x01		/* dump all operations */
    180 
    181 struct puffs_usermount *puffs_mount(struct puffs_vfsops *, struct puffs_vnops *,
    182 		    		    const char *, int, const char *,
    183 				    uint32_t, size_t);
    184 int		puffs_mainloop(struct puffs_usermount *);
    185 int		puffs_oneop(struct puffs_usermount *, uint8_t *, size_t);
    186 int		puffs_getselectable(struct puffs_usermount *);
    187 int		puffs_setblockingmode(struct puffs_usermount *, int);
    188 void		puffs_dummyops(struct puffs_vnops *);
    189 
    190 struct puffs_node *	puffs_newpnode(struct puffs_usermount *, void *,
    191 				       enum vtype);
    192 void		puffs_putpnode(struct puffs_node *);
    193 void		puffs_setvattr(struct vattr *, const struct vattr *);
    194 
    195 #define		DENT_DOT	0
    196 #define		DENT_DOTDOT	1
    197 #define		DENT_ADJ(a)	((a)-2)	/* nth request means dir's n-2th */
    198 int		puffs_gendotdent(struct dirent **, ino_t, int, size_t *);
    199 int		puffs_nextdent(struct dirent **, const char *, ino_t,
    200 			       uint8_t, size_t *);
    201 int		puffs_vtype2dt(enum vtype);
    202 
    203 
    204 /*
    205  * Operation credentials
    206  */
    207 
    208 /* Credential fetch */
    209 int	puffs_cred_getuid(const struct puffs_cred *pcr, uid_t *);
    210 int	puffs_cred_getgid(const struct puffs_cred *pcr, gid_t *);
    211 int	puffs_cred_getgroups(const struct puffs_cred *pcr, gid_t *, short *);
    212 
    213 /* Credential check */
    214 int	puffs_cred_isuid(const struct puffs_cred *pcr, uid_t);
    215 int	puffs_cred_hasgroup(const struct puffs_cred *pcr, gid_t);
    216 /* kernel internal NOCRED */
    217 int	puffs_cred_iskernel(const struct puffs_cred *pcr);
    218 /* kernel internal FSCRED */
    219 int	puffs_cred_isfs(const struct puffs_cred *pcr);
    220 /* root || NOCRED || FSCRED */
    221 int	puffs_cred_isjuggernaut(const struct puffs_cred *pcr);
    222 
    223 
    224 #define PUFFSVFS_PROTOS(fsname)						\
    225 	int fsname##_start(struct puffs_usermount *,			\
    226 	    struct puffs_vfsreq_start *);				\
    227 	int fsname##_unmount(struct puffs_usermount *, int, pid_t);	\
    228 	int fsname##_statvfs(struct puffs_usermount *,			\
    229 	    struct statvfs *, pid_t);					\
    230 	int fsname##_sync(struct puffs_usermount *, int,		\
    231 	    const struct puffs_cred *cred, pid_t);
    232 
    233 #define PUFFSVN_PROTOS(fsname)						\
    234 	int fsname##_lookup(struct puffs_usermount *,			\
    235 	    void *, void **, enum vtype *, const struct puffs_cn *);	\
    236 	int fsname##_create(struct puffs_usermount *,			\
    237 	    void *, void **, const struct puffs_cn *,			\
    238 	    const struct vattr *);					\
    239 	int fsname##_mknod(struct puffs_usermount *,			\
    240 	    void *, void **, const struct puffs_cn *,			\
    241 	    const struct vattr *);					\
    242 	int fsname##_open(struct puffs_usermount *,			\
    243 	    void *, int, const struct puffs_cred *, pid_t);		\
    244 	int fsname##_close(struct puffs_usermount *,			\
    245 	    void *, int, struct puffs_cred *, pid_t);			\
    246 	int fsname##_access(struct puffs_usermount *,			\
    247 	    void *, int, struct puffs_cred *, pid_t);			\
    248 	int fsname##_getattr(struct puffs_usermount *,			\
    249 	    void *, struct vattr *, const struct puffs_cred *, pid_t);	\
    250 	int fsname##_setattr(struct puffs_usermount *,			\
    251 	    void *, const struct vattr *, const struct puffs_cred *,	\
    252 	    pid_t);							\
    253 	int fsname##_poll(struct puffs_usermount *,			\
    254 	    void *, struct puffs_vnreq_poll *);				\
    255 	int fsname##_revoke(struct puffs_usermount *, void *, int);	\
    256 	int fsname##_mmap(struct puffs_usermount *,			\
    257 	    void *, struct puffs_vnreq_mmap *);				\
    258 	int fsname##_fsync(struct puffs_usermount *,			\
    259 	    void *, const struct puffs_cred *, int, off_t, off_t,	\
    260 	    pid_t);							\
    261 	int fsname##_seek(struct puffs_usermount *,			\
    262 	    void *, off_t, off_t, const struct puffs_cred *);		\
    263 	int fsname##_remove(struct puffs_usermount *,			\
    264 	    void *, void *, const struct puffs_cn *);			\
    265 	int fsname##_link(struct puffs_usermount *,			\
    266 	    void *, void *, const struct puffs_cn *);			\
    267 	int fsname##_rename(struct puffs_usermount *,			\
    268 	    void *, void *, const struct puffs_cn *, void *, void *,	\
    269 	    const struct puffs_cn *);					\
    270 	int fsname##_mkdir(struct puffs_usermount *,			\
    271 	    void *, void **, const struct puffs_cn *,			\
    272 	    const struct vattr *);					\
    273 	int fsname##_rmdir(struct puffs_usermount *,			\
    274 	    void *, void *, const struct puffs_cn *);			\
    275 	int fsname##_symlink(struct puffs_usermount *,			\
    276 	    void *, void **, const struct puffs_cn *,			\
    277 	    const struct vattr *, const char *);			\
    278 	int fsname##_readdir(struct puffs_usermount *,			\
    279 	    void *, struct dirent *, const struct puffs_cred *,		\
    280 	    off_t *, size_t *);						\
    281 	int fsname##_readlink(struct puffs_usermount *,			\
    282 	    void *, const struct puffs_cred *, char *, size_t *);	\
    283 	int fsname##_reclaim(struct puffs_usermount *,			\
    284 	    void *, pid_t);						\
    285 	int fsname##_print(struct puffs_usermount *,			\
    286 	    void *);							\
    287 	int fsname##_pathconf(struct puffs_usermount *,			\
    288 	    void *, int, int *);					\
    289 	int fsname##_advlock(struct puffs_usermount *,			\
    290 	    void *, void *, int, struct flock *, int);			\
    291 	int fsname##_getpages(struct puffs_usermount *,			\
    292 	    void *, struct puffs_vnreq_getpages *);			\
    293 	int fsname##_putpages(struct puffs_usermount *,			\
    294 	    void *, struct puffs_vnreq_putpages *);			\
    295 	int fsname##_getextattr(struct puffs_usermount *,		\
    296 	    void *, struct puffs_vnreq_getextattr *);			\
    297 	int fsname##_setextattr(struct puffs_usermount *,		\
    298 	    void *, struct puffs_vnreq_setextattr *);			\
    299 	int fsname##_listextattr(struct puffs_usermount *,		\
    300 	    void *, struct puffs_vnreq_listextattr *);			\
    301 	int fsname##_read(struct puffs_usermount *, void *,		\
    302 	    uint8_t *, off_t, size_t *, const struct puffs_cred *, int);\
    303 	int fsname##_write(struct puffs_usermount *, void *,		\
    304 	    uint8_t *, off_t, size_t *, const struct puffs_cred *, int);
    305 
    306 #endif /* _PUFFS_USER_H_ */
    307