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