ninepuffs.h revision 1.6 1 1.6 pooka /* $NetBSD: ninepuffs.h,v 1.6 2007/05/11 16:23:00 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.6 pooka #define GETRESPONSE(pb) puffs_framebuf_enqueue_cc(pcc,p9p->servsock,pb)
75 1.6 pooka #define JUSTSEND(pb) puffs_framebuf_enqueue_justsend(pu,p9p->servsock,pb,1)
76 1.6 pooka #define SENDCB(pb, f, a) puffs_framebuf_enqueue_cb(pu,p9p->servsock pb,f,a)
77 1.6 pooka
78 1.1 pooka struct puffs9p {
79 1.1 pooka int servsock;
80 1.1 pooka
81 1.1 pooka p9ptag_t nexttag;
82 1.1 pooka p9pfid_t nextfid;
83 1.1 pooka
84 1.1 pooka size_t maxreq; /* negotiated with server */
85 1.1 pooka };
86 1.1 pooka
87 1.1 pooka struct dirfid {
88 1.1 pooka p9pfid_t fid;
89 1.1 pooka off_t seekoff;
90 1.1 pooka LIST_ENTRY(dirfid) entries;
91 1.1 pooka };
92 1.1 pooka
93 1.1 pooka struct p9pnode {
94 1.1 pooka p9pfid_t fid_base;
95 1.2 pooka p9pfid_t fid_read;
96 1.2 pooka p9pfid_t fid_write;
97 1.1 pooka
98 1.1 pooka LIST_HEAD(,dirfid) dir_openlist;
99 1.1 pooka };
100 1.1 pooka
101 1.3 pooka struct puffs_framebuf *p9pbuf_makeout(void);
102 1.3 pooka void p9pbuf_recycleout(struct puffs_framebuf *);
103 1.3 pooka
104 1.3 pooka int p9pbuf_read(struct puffs_usermount *, struct puffs_framebuf *,int,int*);
105 1.3 pooka int p9pbuf_write(struct puffs_usermount *, struct puffs_framebuf*,int,int*);
106 1.3 pooka int p9pbuf_cmp(struct puffs_usermount *,
107 1.3 pooka struct puffs_framebuf *, struct puffs_framebuf *);
108 1.3 pooka
109 1.3 pooka void p9pbuf_put_1(struct puffs_framebuf *, uint8_t);
110 1.3 pooka void p9pbuf_put_2(struct puffs_framebuf *, uint16_t);
111 1.3 pooka void p9pbuf_put_4(struct puffs_framebuf *, uint32_t);
112 1.3 pooka void p9pbuf_put_8(struct puffs_framebuf *, uint64_t);
113 1.3 pooka void p9pbuf_put_str(struct puffs_framebuf *, const char *);
114 1.3 pooka void p9pbuf_put_data(struct puffs_framebuf *, const void *, uint16_t);
115 1.3 pooka void p9pbuf_write_data(struct puffs_framebuf *, uint8_t *, uint32_t);
116 1.3 pooka
117 1.3 pooka int p9pbuf_get_1(struct puffs_framebuf *, uint8_t *);
118 1.3 pooka int p9pbuf_get_2(struct puffs_framebuf *, uint16_t *);
119 1.3 pooka int p9pbuf_get_4(struct puffs_framebuf *, uint32_t *);
120 1.3 pooka int p9pbuf_get_8(struct puffs_framebuf *, uint64_t *);
121 1.3 pooka int p9pbuf_get_str(struct puffs_framebuf *, char **, uint16_t *);
122 1.3 pooka int p9pbuf_get_data(struct puffs_framebuf *, uint8_t **, uint16_t *);
123 1.3 pooka int p9pbuf_read_data(struct puffs_framebuf *, uint8_t *, uint32_t);
124 1.3 pooka
125 1.3 pooka uint8_t p9pbuf_get_type(struct puffs_framebuf *);
126 1.3 pooka uint16_t p9pbuf_get_tag(struct puffs_framebuf *);
127 1.3 pooka
128 1.3 pooka int proto_getqid(struct puffs_framebuf *, struct qid9p *);
129 1.3 pooka int proto_getstat(struct puffs_framebuf *, struct vattr *,
130 1.3 pooka char **, uint16_t *);
131 1.3 pooka int proto_expect_walk_nqids(struct puffs_framebuf *, uint16_t *);
132 1.3 pooka int proto_expect_stat(struct puffs_framebuf *, struct vattr *);
133 1.3 pooka int proto_expect_qid(struct puffs_framebuf *, uint8_t, struct qid9p *);
134 1.1 pooka
135 1.1 pooka int proto_cc_dupfid(struct puffs_cc *, p9pfid_t, p9pfid_t);
136 1.1 pooka int proto_cc_clunkfid(struct puffs_cc *, p9pfid_t, int);
137 1.1 pooka int proto_cc_open(struct puffs_cc *, p9pfid_t, p9pfid_t, int);
138 1.1 pooka
139 1.3 pooka void proto_make_stat(struct puffs_framebuf *, const struct vattr *,
140 1.5 pooka const char *, enum vtype);
141 1.1 pooka
142 1.1 pooka struct puffs_node *p9p_handshake(struct puffs_usermount *, const char *);
143 1.1 pooka
144 1.1 pooka void qid2vattr(struct vattr *, const struct qid9p *);
145 1.1 pooka struct puffs_node *newp9pnode_va(struct puffs_usermount *,
146 1.1 pooka const struct vattr *, p9pfid_t);
147 1.1 pooka struct puffs_node *newp9pnode_qid(struct puffs_usermount *,
148 1.1 pooka const struct qid9p *, p9pfid_t);
149 1.1 pooka
150 1.1 pooka int getdfwithoffset(struct puffs_cc *, struct p9pnode *, off_t,
151 1.1 pooka struct dirfid **);
152 1.1 pooka void storedf(struct p9pnode *, struct dirfid *);
153 1.1 pooka void releasedf(struct puffs_cc *, struct dirfid *);
154 1.1 pooka void nukealldf(struct puffs_cc *, struct p9pnode *);
155 1.1 pooka
156 1.1 pooka #endif /* PUFFS9P_H_ */
157