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