1 /* $NetBSD: ninepuffs.h,v 1.11 2007/09/06 16:09:10 pooka Exp $ */
4 * Copyright (c) 2007 Antti Kantee. All Rights Reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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.
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
31 #include <sys/queue.h>
35 PUFFSOP_PROTOS(puffs9p
);
37 /* Qid structure. optimized for in-mem. different order on-wire */
44 typedef uint16_t p9ptag_t
;
45 typedef uint32_t p9pfid_t
;
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
52 #define P9P_MINREQLEN 512
54 #define P9P_DEFREQLEN (16*1024)
55 #define P9P_INVALFID 0
58 #define NEXTTAG(p9p) \
59 ((++(p9p->nexttag)) == P9PROTO_NOTAG ? p9p->nexttag = 0 : p9p->nexttag)
61 #define NEXTFID(p9p) \
62 ((++(p9p->nextfid)) == P9P_INVALFID ? p9p->nextfid = 2 : p9p->nextfid)
65 struct puffs_cc *pcc = puffs_cc_getcc(pu); \
66 struct puffs9p *p9p = puffs_getspecific(pu); \
67 uint16_t tag = NEXTTAG(p9p); \
68 struct puffs_framebuf *pb = p9pbuf_makeout(); \
72 puffs_framebuf_destroy(pb); \
75 #define GETRESPONSE(pb) \
77 if (puffs_framev_enqueue_cc(pcc, p9p->servsock, pb, 0) == -1) { \
81 } while (/*CONSTCOND*/0)
83 #define JUSTSEND(pb) \
85 if (puffs_framev_enqueue_justsend(pu,p9p->servsock,pb,1,0)==-1){\
89 } while (/*CONSTCOND*/0)
91 #define SENDCB(pb, f, a) \
93 if (puffs_framev_enqueue_cb(pu, p9p->servsock,pb,f,a,0) == -1) {\
97 } while (/*CONSTCOND*/0)
105 size_t maxreq
; /* negotiated with server */
111 LIST_ENTRY(dirfid
) entries
;
119 LIST_HEAD(,dirfid
) dir_openlist
;
122 struct puffs_framebuf
*p9pbuf_makeout(void);
123 void p9pbuf_recycleout(struct puffs_framebuf
*);
125 int p9pbuf_read(struct puffs_usermount
*, struct puffs_framebuf
*,int,int*);
126 int p9pbuf_write(struct puffs_usermount
*, struct puffs_framebuf
*,int,int*);
127 int p9pbuf_cmp(struct puffs_usermount
*,
128 struct puffs_framebuf
*, struct puffs_framebuf
*, int *);
130 void p9pbuf_put_1(struct puffs_framebuf
*, uint8_t);
131 void p9pbuf_put_2(struct puffs_framebuf
*, uint16_t);
132 void p9pbuf_put_4(struct puffs_framebuf
*, uint32_t);
133 void p9pbuf_put_8(struct puffs_framebuf
*, uint64_t);
134 void p9pbuf_put_str(struct puffs_framebuf
*, const char *);
135 void p9pbuf_put_data(struct puffs_framebuf
*, const void *, uint16_t);
136 void p9pbuf_write_data(struct puffs_framebuf
*, uint8_t *, uint32_t);
138 int p9pbuf_get_1(struct puffs_framebuf
*, uint8_t *);
139 int p9pbuf_get_2(struct puffs_framebuf
*, uint16_t *);
140 int p9pbuf_get_4(struct puffs_framebuf
*, uint32_t *);
141 int p9pbuf_get_8(struct puffs_framebuf
*, uint64_t *);
142 int p9pbuf_get_str(struct puffs_framebuf
*, char **, uint16_t *);
143 int p9pbuf_get_data(struct puffs_framebuf
*, uint8_t **, uint16_t *);
144 int p9pbuf_read_data(struct puffs_framebuf
*, uint8_t *, uint32_t);
146 uint8_t p9pbuf_get_type(struct puffs_framebuf
*);
147 uint16_t p9pbuf_get_tag(struct puffs_framebuf
*);
149 int proto_getqid(struct puffs_framebuf
*, struct qid9p
*);
150 int proto_getstat(struct puffs_framebuf
*, struct vattr
*,
151 char **, uint16_t *);
152 int proto_expect_walk_nqids(struct puffs_framebuf
*, uint16_t *);
153 int proto_expect_stat(struct puffs_framebuf
*, struct vattr
*);
154 int proto_expect_qid(struct puffs_framebuf
*, uint8_t, struct qid9p
*);
156 int proto_cc_dupfid(struct puffs_usermount
*, p9pfid_t
, p9pfid_t
);
157 int proto_cc_clunkfid(struct puffs_usermount
*, p9pfid_t
, int);
158 int proto_cc_open(struct puffs_usermount
*, p9pfid_t
, p9pfid_t
, int);
160 void proto_make_stat(struct puffs_framebuf
*, const struct vattr
*,
161 const char *, enum vtype
);
163 struct puffs_node
*p9p_handshake(struct puffs_usermount
*,
164 const char *, const char *);
166 void qid2vattr(struct vattr
*, const struct qid9p
*);
167 struct puffs_node
*newp9pnode_va(struct puffs_usermount
*,
168 const struct vattr
*, p9pfid_t
);
169 struct puffs_node
*newp9pnode_qid(struct puffs_usermount
*,
170 const struct qid9p
*, p9pfid_t
);
172 int getdfwithoffset(struct puffs_usermount
*, struct p9pnode
*, off_t
,
174 void storedf(struct p9pnode
*, struct dirfid
*);
175 void releasedf(struct puffs_usermount
*, struct dirfid
*);
176 void nukealldf(struct puffs_usermount
*, struct p9pnode
*);
178 #endif /* PUFFS9P_H_ */