Home | History | Annotate | Line # | Download | only in mount_9p
ninepuffs.h revision 1.6
      1 /*	$NetBSD: ninepuffs.h,v 1.6 2007/05/11 16:23:00 pooka Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 2007  Antti Kantee.  All Rights Reserved.
      5  *
      6  * Redistribution and use in source and binary forms, with or without
      7  * modification, are permitted provided that the following conditions
      8  * are met:
      9  * 1. Redistributions of source code must retain the above copyright
     10  *    notice, this list of conditions and the following disclaimer.
     11  * 2. Redistributions in binary form must reproduce the above copyright
     12  *    notice, this list of conditions and the following disclaimer in the
     13  *    documentation and/or other materials provided with the distribution.
     14  *
     15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
     16  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     17  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     18  * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     21  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     25  * SUCH DAMAGE.
     26  */
     27 
     28 #ifndef PUFFS9P_H_
     29 #define PUFFS9P_H_
     30 
     31 #include <sys/queue.h>
     32 
     33 #include <puffs.h>
     34 
     35 PUFFSOP_PROTOS(puffs9p);
     36 
     37 /* Qid structure.  optimized for in-mem.  different order on-wire */
     38 struct qid9p {
     39 	uint64_t	qidpath;
     40 	uint32_t	qidvers;
     41 	uint8_t		qidtype;
     42 };
     43 
     44 typedef uint16_t p9ptag_t;
     45 typedef uint32_t p9pfid_t;
     46 
     47 /*
     48  * refuse (no, not *that* refuse) to play if the server doesn't
     49  * support requests of at least the following size.  It would only
     50  * make life difficult
     51  */
     52 #define P9P_MINREQLEN	512
     53 
     54 #define P9P_DEFREQLEN	(16*1024)
     55 #define P9P_INVALFID	0
     56 #define P9P_ROOTFID	1
     57 
     58 #define NEXTTAG(p9p)	\
     59     ((++(p9p->nexttag)) == P9PROTO_NOTAG ? p9p->nexttag = 0 : p9p->nexttag)
     60 
     61 #define NEXTFID(p9p)	\
     62     ((++(p9p->nextfid)) == P9P_INVALFID ? p9p->nextfid = 2 : p9p->nextfid)
     63 
     64 #define AUTOVAR(pcc)							\
     65 	struct puffs9p *p9p = puffs_cc_getspecific(pcc);		\
     66 	uint16_t tag = NEXTTAG(p9p);					\
     67 	struct puffs_framebuf *pb = p9pbuf_makeout();			\
     68 	int rv = 0
     69 
     70 #define RETURN(rv)							\
     71 	puffs_framebuf_destroy(pb);					\
     72 	return (rv)
     73 
     74 #define GETRESPONSE(pb) puffs_framebuf_enqueue_cc(pcc,p9p->servsock,pb)
     75 #define JUSTSEND(pb) puffs_framebuf_enqueue_justsend(pu,p9p->servsock,pb,1)
     76 #define SENDCB(pb, f, a) puffs_framebuf_enqueue_cb(pu,p9p->servsock pb,f,a)
     77 
     78 struct puffs9p {
     79 	int servsock;
     80 
     81 	p9ptag_t nexttag;
     82 	p9pfid_t nextfid;
     83 
     84 	size_t maxreq;		/* negotiated with server */
     85 };
     86 
     87 struct dirfid {
     88 	p9pfid_t	fid;
     89 	off_t		seekoff;
     90 	LIST_ENTRY(dirfid) entries;
     91 };
     92 
     93 struct p9pnode {
     94 	p9pfid_t	fid_base;
     95 	p9pfid_t	fid_read;
     96 	p9pfid_t	fid_write;
     97 
     98 	LIST_HEAD(,dirfid) dir_openlist;
     99 };
    100 
    101 struct puffs_framebuf	*p9pbuf_makeout(void);
    102 void			p9pbuf_recycleout(struct puffs_framebuf *);
    103 
    104 int	p9pbuf_read(struct puffs_usermount *, struct puffs_framebuf *,int,int*);
    105 int	p9pbuf_write(struct puffs_usermount *, struct puffs_framebuf*,int,int*);
    106 int	p9pbuf_cmp(struct puffs_usermount *,
    107 		   struct puffs_framebuf *, struct puffs_framebuf *);
    108 
    109 void	p9pbuf_put_1(struct puffs_framebuf *, uint8_t);
    110 void	p9pbuf_put_2(struct puffs_framebuf *, uint16_t);
    111 void	p9pbuf_put_4(struct puffs_framebuf *, uint32_t);
    112 void	p9pbuf_put_8(struct puffs_framebuf *, uint64_t);
    113 void	p9pbuf_put_str(struct puffs_framebuf *, const char *);
    114 void	p9pbuf_put_data(struct puffs_framebuf *, const void *, uint16_t);
    115 void	p9pbuf_write_data(struct puffs_framebuf *, uint8_t *, uint32_t);
    116 
    117 int	p9pbuf_get_1(struct puffs_framebuf *, uint8_t *);
    118 int	p9pbuf_get_2(struct puffs_framebuf *, uint16_t *);
    119 int	p9pbuf_get_4(struct puffs_framebuf *, uint32_t *);
    120 int	p9pbuf_get_8(struct puffs_framebuf *, uint64_t *);
    121 int	p9pbuf_get_str(struct puffs_framebuf *, char **, uint16_t *);
    122 int	p9pbuf_get_data(struct puffs_framebuf *, uint8_t **, uint16_t *);
    123 int	p9pbuf_read_data(struct puffs_framebuf *, uint8_t *, uint32_t);
    124 
    125 uint8_t		p9pbuf_get_type(struct puffs_framebuf *);
    126 uint16_t	p9pbuf_get_tag(struct puffs_framebuf *);
    127 
    128 int	proto_getqid(struct puffs_framebuf *, struct qid9p *);
    129 int	proto_getstat(struct puffs_framebuf *, struct vattr *,
    130 		      char **, uint16_t *);
    131 int	proto_expect_walk_nqids(struct puffs_framebuf *, uint16_t *);
    132 int	proto_expect_stat(struct puffs_framebuf *, struct vattr *);
    133 int	proto_expect_qid(struct puffs_framebuf *, uint8_t, struct qid9p *);
    134 
    135 int	proto_cc_dupfid(struct puffs_cc *, p9pfid_t, p9pfid_t);
    136 int	proto_cc_clunkfid(struct puffs_cc *, p9pfid_t, int);
    137 int	proto_cc_open(struct puffs_cc *, p9pfid_t, p9pfid_t, int);
    138 
    139 void	proto_make_stat(struct puffs_framebuf *, const struct vattr *,
    140 			const char *, enum vtype);
    141 
    142 struct puffs_node	*p9p_handshake(struct puffs_usermount *, const char *);
    143 
    144 void			qid2vattr(struct vattr *, const struct qid9p *);
    145 struct puffs_node	*newp9pnode_va(struct puffs_usermount *,
    146 				       const struct vattr *, p9pfid_t);
    147 struct puffs_node	*newp9pnode_qid(struct puffs_usermount *,
    148 					const struct qid9p *, p9pfid_t);
    149 
    150 int	getdfwithoffset(struct puffs_cc *, struct p9pnode *, off_t,
    151 			 struct dirfid **);
    152 void	storedf(struct p9pnode *, struct dirfid *);
    153 void	releasedf(struct puffs_cc *, struct dirfid *);
    154 void	nukealldf(struct puffs_cc *, struct p9pnode *);
    155 
    156 #endif /* PUFFS9P_H_ */
    157