Home | History | Annotate | Line # | Download | only in libpuffs
puffs.h revision 1.11
      1  1.11  pooka /*	$NetBSD: puffs.h,v 1.11 2006/11/23 16:44:28 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.3  pooka 	struct vattr	pn_va;			/* XXX: doesn't belong here*/
     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.5  pooka 	int (*puffs_mount)(struct puffs_usermount *, void **);
     77   1.1  pooka 	int (*puffs_unmount)(struct puffs_usermount *, int, pid_t);
     78   1.1  pooka 	int (*puffs_statvfs)(struct puffs_usermount *,
     79   1.1  pooka 	    struct statvfs *, pid_t);
     80   1.1  pooka 	int (*puffs_sync)(struct puffs_usermount *, int,
     81   1.1  pooka 	    const struct puffs_cred *, pid_t);
     82   1.1  pooka };
     83   1.1  pooka 
     84   1.1  pooka struct puffs_vnops {
     85   1.1  pooka 	int (*puffs_lookup)(struct puffs_usermount *,
     86   1.4  pooka 	    void *, void **, enum vtype *, voff_t *, dev_t *,
     87   1.3  pooka 	    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_getextattr)(struct puffs_usermount *,
    141   1.1  pooka 	    void *, struct puffs_vnreq_getextattr *);
    142   1.1  pooka 	int (*puffs_setextattr)(struct puffs_usermount *,
    143   1.1  pooka 	    void *, struct puffs_vnreq_setextattr *);
    144   1.1  pooka 	int (*puffs_listextattr)(struct puffs_usermount *,
    145   1.1  pooka 	    void *, struct puffs_vnreq_listextattr *);
    146   1.1  pooka 	int (*puffs_read)(struct puffs_usermount *, void *,
    147   1.1  pooka 	    uint8_t *, off_t, size_t *, const struct puffs_cred *, int);
    148   1.1  pooka 	int (*puffs_write)(struct puffs_usermount *, void *,
    149   1.1  pooka 	    uint8_t *, off_t, size_t *, const struct puffs_cred *, int);
    150   1.1  pooka 
    151   1.1  pooka 	int (*puffs_ioctl1)(struct puffs_usermount *, void *,
    152   1.1  pooka 	    struct puffs_vnreq_fcnioctl *, struct puffs_sizeop *);
    153   1.1  pooka 	int (*puffs_ioctl2)(struct puffs_usermount *, void *,
    154   1.1  pooka 	    struct puffs_vnreq_fcnioctl *, struct puffs_sizeop *);
    155   1.1  pooka 	int (*puffs_fcntl1)(struct puffs_usermount *, void *,
    156   1.1  pooka 	    struct puffs_vnreq_fcnioctl *, struct puffs_sizeop *);
    157   1.1  pooka 	int (*puffs_fcntl2)(struct puffs_usermount *, void *,
    158   1.1  pooka 	    struct puffs_vnreq_fcnioctl *, struct puffs_sizeop *);
    159   1.1  pooka };
    160   1.1  pooka 
    161   1.1  pooka struct puffs_usermount {
    162   1.1  pooka 	struct puffs_vfsops	pu_pvfs;
    163   1.1  pooka 	struct puffs_vnops	pu_pvn;
    164   1.1  pooka 
    165   1.1  pooka 	int			pu_fd;
    166   1.1  pooka 	uint32_t		pu_flags;
    167   1.1  pooka 	size_t			pu_maxreqlen;
    168   1.1  pooka 
    169   1.1  pooka 	struct puffs_node	*pu_rootnode;
    170   1.1  pooka 	const char *		pu_rootpath;
    171   1.5  pooka 	fsid_t			pu_fsidx;
    172   1.1  pooka 	LIST_HEAD(, puffs_node)	pu_pnodelst;
    173   1.1  pooka 
    174   1.1  pooka 	int	pu_wcnt;
    175   1.1  pooka 	void	*pu_privdata;
    176   1.1  pooka };
    177   1.1  pooka 
    178   1.8  pooka #define PUFFSFLAG_KERN(a)	((a) & 0xffff)
    179   1.8  pooka #define PUFFSFLAG_OPDUMP	0x10000		/* dump all operations */
    180   1.1  pooka 
    181   1.1  pooka struct puffs_usermount *puffs_mount(struct puffs_vfsops *, struct puffs_vnops *,
    182   1.1  pooka 		    		    const char *, int, const char *,
    183   1.1  pooka 				    uint32_t, size_t);
    184   1.1  pooka int		puffs_mainloop(struct puffs_usermount *);
    185   1.1  pooka int		puffs_oneop(struct puffs_usermount *, uint8_t *, size_t);
    186   1.1  pooka int		puffs_getselectable(struct puffs_usermount *);
    187   1.1  pooka int		puffs_setblockingmode(struct puffs_usermount *, int);
    188   1.1  pooka void		puffs_dummyops(struct puffs_vnops *);
    189   1.1  pooka 
    190   1.5  pooka #define PUFFSDEV_BLOCK 0
    191   1.5  pooka #define PUFFSDEV_NONBLOCK 1
    192   1.5  pooka 
    193   1.1  pooka struct puffs_node *	puffs_newpnode(struct puffs_usermount *, void *,
    194   1.1  pooka 				       enum vtype);
    195   1.1  pooka void		puffs_putpnode(struct puffs_node *);
    196   1.1  pooka void		puffs_setvattr(struct vattr *, const struct vattr *);
    197   1.1  pooka 
    198   1.7  pooka int puffs_vfsnop_unmount(struct puffs_usermount *, int, pid_t);
    199   1.7  pooka int puffs_vfsnop_statvfs(struct puffs_usermount *, struct statvfs *, pid_t);
    200   1.7  pooka int puffs_vfsnop_sync(struct puffs_usermount *, int waitfor,
    201   1.7  pooka 		      const struct puffs_cred *, pid_t);
    202   1.6  pooka 
    203   1.1  pooka #define		DENT_DOT	0
    204   1.1  pooka #define		DENT_DOTDOT	1
    205   1.1  pooka #define		DENT_ADJ(a)	((a)-2)	/* nth request means dir's n-2th */
    206   1.1  pooka int		puffs_gendotdent(struct dirent **, ino_t, int, size_t *);
    207   1.1  pooka int		puffs_nextdent(struct dirent **, const char *, ino_t,
    208   1.1  pooka 			       uint8_t, size_t *);
    209   1.1  pooka int		puffs_vtype2dt(enum vtype);
    210  1.10  pooka enum vtype	puffs_mode2vt(mode_t);
    211   1.1  pooka 
    212   1.1  pooka 
    213   1.1  pooka /*
    214   1.1  pooka  * Operation credentials
    215   1.1  pooka  */
    216   1.1  pooka 
    217   1.1  pooka /* Credential fetch */
    218   1.1  pooka int	puffs_cred_getuid(const struct puffs_cred *pcr, uid_t *);
    219   1.1  pooka int	puffs_cred_getgid(const struct puffs_cred *pcr, gid_t *);
    220   1.1  pooka int	puffs_cred_getgroups(const struct puffs_cred *pcr, gid_t *, short *);
    221   1.1  pooka 
    222   1.1  pooka /* Credential check */
    223   1.1  pooka int	puffs_cred_isuid(const struct puffs_cred *pcr, uid_t);
    224   1.1  pooka int	puffs_cred_hasgroup(const struct puffs_cred *pcr, gid_t);
    225   1.1  pooka /* kernel internal NOCRED */
    226   1.1  pooka int	puffs_cred_iskernel(const struct puffs_cred *pcr);
    227   1.1  pooka /* kernel internal FSCRED */
    228   1.1  pooka int	puffs_cred_isfs(const struct puffs_cred *pcr);
    229   1.1  pooka /* root || NOCRED || FSCRED */
    230   1.1  pooka int	puffs_cred_isjuggernaut(const struct puffs_cred *pcr);
    231   1.1  pooka 
    232   1.1  pooka 
    233   1.1  pooka #define PUFFSVFS_PROTOS(fsname)						\
    234   1.5  pooka 	int fsname##_mount(struct puffs_usermount *, void **);		\
    235   1.1  pooka 	int fsname##_unmount(struct puffs_usermount *, int, pid_t);	\
    236   1.1  pooka 	int fsname##_statvfs(struct puffs_usermount *,			\
    237   1.1  pooka 	    struct statvfs *, pid_t);					\
    238   1.1  pooka 	int fsname##_sync(struct puffs_usermount *, int,		\
    239   1.1  pooka 	    const struct puffs_cred *cred, pid_t);
    240   1.1  pooka 
    241   1.1  pooka #define PUFFSVN_PROTOS(fsname)						\
    242   1.1  pooka 	int fsname##_lookup(struct puffs_usermount *,			\
    243   1.4  pooka 	    void *, void **, enum vtype *, voff_t *, dev_t *,		\
    244   1.3  pooka 	    const struct puffs_cn *);					\
    245   1.1  pooka 	int fsname##_create(struct puffs_usermount *,			\
    246   1.1  pooka 	    void *, void **, const struct puffs_cn *,			\
    247   1.1  pooka 	    const struct vattr *);					\
    248   1.1  pooka 	int fsname##_mknod(struct puffs_usermount *,			\
    249   1.1  pooka 	    void *, void **, const struct puffs_cn *,			\
    250   1.1  pooka 	    const struct vattr *);					\
    251   1.1  pooka 	int fsname##_open(struct puffs_usermount *,			\
    252   1.1  pooka 	    void *, int, const struct puffs_cred *, pid_t);		\
    253   1.1  pooka 	int fsname##_close(struct puffs_usermount *,			\
    254  1.11  pooka 	    void *, int, const struct puffs_cred *, pid_t);		\
    255   1.1  pooka 	int fsname##_access(struct puffs_usermount *,			\
    256  1.11  pooka 	    void *, int, const struct puffs_cred *, pid_t);		\
    257   1.1  pooka 	int fsname##_getattr(struct puffs_usermount *,			\
    258   1.1  pooka 	    void *, struct vattr *, const struct puffs_cred *, pid_t);	\
    259   1.1  pooka 	int fsname##_setattr(struct puffs_usermount *,			\
    260   1.1  pooka 	    void *, const struct vattr *, const struct puffs_cred *,	\
    261   1.1  pooka 	    pid_t);							\
    262   1.1  pooka 	int fsname##_poll(struct puffs_usermount *,			\
    263   1.1  pooka 	    void *, struct puffs_vnreq_poll *);				\
    264   1.1  pooka 	int fsname##_revoke(struct puffs_usermount *, void *, int);	\
    265   1.1  pooka 	int fsname##_mmap(struct puffs_usermount *,			\
    266   1.1  pooka 	    void *, struct puffs_vnreq_mmap *);				\
    267   1.1  pooka 	int fsname##_fsync(struct puffs_usermount *,			\
    268   1.1  pooka 	    void *, const struct puffs_cred *, int, off_t, off_t,	\
    269   1.1  pooka 	    pid_t);							\
    270   1.1  pooka 	int fsname##_seek(struct puffs_usermount *,			\
    271   1.1  pooka 	    void *, off_t, off_t, const struct puffs_cred *);		\
    272   1.1  pooka 	int fsname##_remove(struct puffs_usermount *,			\
    273   1.1  pooka 	    void *, void *, const struct puffs_cn *);			\
    274   1.1  pooka 	int fsname##_link(struct puffs_usermount *,			\
    275   1.1  pooka 	    void *, void *, const struct puffs_cn *);			\
    276   1.1  pooka 	int fsname##_rename(struct puffs_usermount *,			\
    277   1.1  pooka 	    void *, void *, const struct puffs_cn *, void *, void *,	\
    278   1.1  pooka 	    const struct puffs_cn *);					\
    279   1.1  pooka 	int fsname##_mkdir(struct puffs_usermount *,			\
    280   1.1  pooka 	    void *, void **, const struct puffs_cn *,			\
    281   1.1  pooka 	    const struct vattr *);					\
    282   1.1  pooka 	int fsname##_rmdir(struct puffs_usermount *,			\
    283   1.1  pooka 	    void *, void *, const struct puffs_cn *);			\
    284   1.1  pooka 	int fsname##_symlink(struct puffs_usermount *,			\
    285   1.1  pooka 	    void *, void **, const struct puffs_cn *,			\
    286   1.1  pooka 	    const struct vattr *, const char *);			\
    287   1.1  pooka 	int fsname##_readdir(struct puffs_usermount *,			\
    288   1.1  pooka 	    void *, struct dirent *, const struct puffs_cred *,		\
    289   1.1  pooka 	    off_t *, size_t *);						\
    290   1.1  pooka 	int fsname##_readlink(struct puffs_usermount *,			\
    291   1.1  pooka 	    void *, const struct puffs_cred *, char *, size_t *);	\
    292   1.1  pooka 	int fsname##_reclaim(struct puffs_usermount *,			\
    293   1.1  pooka 	    void *, pid_t);						\
    294   1.2  pooka 	int fsname##_inactive(struct puffs_usermount *,			\
    295   1.2  pooka 	    void *, pid_t, int *);					\
    296   1.1  pooka 	int fsname##_print(struct puffs_usermount *,			\
    297   1.1  pooka 	    void *);							\
    298   1.1  pooka 	int fsname##_pathconf(struct puffs_usermount *,			\
    299   1.1  pooka 	    void *, int, int *);					\
    300   1.1  pooka 	int fsname##_advlock(struct puffs_usermount *,			\
    301   1.1  pooka 	    void *, void *, int, struct flock *, int);			\
    302   1.1  pooka 	int fsname##_getextattr(struct puffs_usermount *,		\
    303   1.1  pooka 	    void *, struct puffs_vnreq_getextattr *);			\
    304   1.1  pooka 	int fsname##_setextattr(struct puffs_usermount *,		\
    305   1.1  pooka 	    void *, struct puffs_vnreq_setextattr *);			\
    306   1.1  pooka 	int fsname##_listextattr(struct puffs_usermount *,		\
    307   1.1  pooka 	    void *, struct puffs_vnreq_listextattr *);			\
    308   1.1  pooka 	int fsname##_read(struct puffs_usermount *, void *,		\
    309   1.1  pooka 	    uint8_t *, off_t, size_t *, const struct puffs_cred *, int);\
    310   1.1  pooka 	int fsname##_write(struct puffs_usermount *, void *,		\
    311   1.1  pooka 	    uint8_t *, off_t, size_t *, const struct puffs_cred *, int);
    312   1.1  pooka 
    313   1.1  pooka #endif /* _PUFFS_USER_H_ */
    314