1 1.16 uwe /* $NetBSD: ninepuffs.h,v 1.16 2020/05/26 22:54:43 uwe 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.12 pooka #define AUTOVAR(pu) \ 65 1.12 pooka struct puffs_cc *pcc = puffs_cc_getcc(pu); \ 66 1.12 pooka struct puffs9p *p9p = puffs_getspecific(pu); \ 67 1.16 uwe p9ptag_t tag; \ 68 1.3 pooka struct puffs_framebuf *pb = p9pbuf_makeout(); \ 69 1.1 pooka int rv = 0 70 1.1 pooka 71 1.1 pooka #define RETURN(rv) \ 72 1.3 pooka puffs_framebuf_destroy(pb); \ 73 1.1 pooka return (rv) 74 1.1 pooka 75 1.8 pooka #define GETRESPONSE(pb) \ 76 1.8 pooka do { \ 77 1.9 pooka if (puffs_framev_enqueue_cc(pcc, p9p->servsock, pb, 0) == -1) { \ 78 1.8 pooka rv = errno; \ 79 1.8 pooka goto out; \ 80 1.8 pooka } \ 81 1.8 pooka } while (/*CONSTCOND*/0) 82 1.8 pooka 83 1.8 pooka #define JUSTSEND(pb) \ 84 1.8 pooka do { \ 85 1.9 pooka if (puffs_framev_enqueue_justsend(pu,p9p->servsock,pb,1,0)==-1){\ 86 1.8 pooka rv = errno; \ 87 1.8 pooka goto out; \ 88 1.8 pooka } \ 89 1.8 pooka } while (/*CONSTCOND*/0) 90 1.8 pooka 91 1.8 pooka #define SENDCB(pb, f, a) \ 92 1.8 pooka do { \ 93 1.9 pooka if (puffs_framev_enqueue_cb(pu, p9p->servsock,pb,f,a,0) == -1) {\ 94 1.8 pooka rv = errno; \ 95 1.8 pooka goto out; \ 96 1.8 pooka } \ 97 1.8 pooka } while (/*CONSTCOND*/0) 98 1.6 pooka 99 1.1 pooka struct puffs9p { 100 1.1 pooka int servsock; 101 1.1 pooka 102 1.1 pooka p9ptag_t nexttag; 103 1.1 pooka p9pfid_t nextfid; 104 1.1 pooka 105 1.1 pooka size_t maxreq; /* negotiated with server */ 106 1.13 ozaki 107 1.13 ozaki int protover; 108 1.15 ozaki int server; 109 1.15 ozaki #define P9P_SERVER_TCP 0 110 1.15 ozaki #define P9P_SERVER_CDEV 1 111 1.1 pooka }; 112 1.1 pooka 113 1.1 pooka struct dirfid { 114 1.1 pooka p9pfid_t fid; 115 1.1 pooka off_t seekoff; 116 1.1 pooka LIST_ENTRY(dirfid) entries; 117 1.1 pooka }; 118 1.1 pooka 119 1.1 pooka struct p9pnode { 120 1.1 pooka p9pfid_t fid_base; 121 1.2 pooka p9pfid_t fid_read; 122 1.2 pooka p9pfid_t fid_write; 123 1.1 pooka 124 1.1 pooka LIST_HEAD(,dirfid) dir_openlist; 125 1.1 pooka }; 126 1.1 pooka 127 1.3 pooka struct puffs_framebuf *p9pbuf_makeout(void); 128 1.3 pooka void p9pbuf_recycleout(struct puffs_framebuf *); 129 1.3 pooka 130 1.3 pooka int p9pbuf_read(struct puffs_usermount *, struct puffs_framebuf *,int,int*); 131 1.3 pooka int p9pbuf_write(struct puffs_usermount *, struct puffs_framebuf*,int,int*); 132 1.3 pooka int p9pbuf_cmp(struct puffs_usermount *, 133 1.11 pooka struct puffs_framebuf *, struct puffs_framebuf *, int *); 134 1.3 pooka 135 1.3 pooka void p9pbuf_put_1(struct puffs_framebuf *, uint8_t); 136 1.3 pooka void p9pbuf_put_2(struct puffs_framebuf *, uint16_t); 137 1.3 pooka void p9pbuf_put_4(struct puffs_framebuf *, uint32_t); 138 1.3 pooka void p9pbuf_put_8(struct puffs_framebuf *, uint64_t); 139 1.3 pooka void p9pbuf_put_str(struct puffs_framebuf *, const char *); 140 1.3 pooka void p9pbuf_put_data(struct puffs_framebuf *, const void *, uint16_t); 141 1.3 pooka void p9pbuf_write_data(struct puffs_framebuf *, uint8_t *, uint32_t); 142 1.3 pooka 143 1.3 pooka int p9pbuf_get_1(struct puffs_framebuf *, uint8_t *); 144 1.3 pooka int p9pbuf_get_2(struct puffs_framebuf *, uint16_t *); 145 1.3 pooka int p9pbuf_get_4(struct puffs_framebuf *, uint32_t *); 146 1.3 pooka int p9pbuf_get_8(struct puffs_framebuf *, uint64_t *); 147 1.3 pooka int p9pbuf_get_str(struct puffs_framebuf *, char **, uint16_t *); 148 1.3 pooka int p9pbuf_get_data(struct puffs_framebuf *, uint8_t **, uint16_t *); 149 1.3 pooka int p9pbuf_read_data(struct puffs_framebuf *, uint8_t *, uint32_t); 150 1.3 pooka 151 1.3 pooka uint8_t p9pbuf_get_type(struct puffs_framebuf *); 152 1.3 pooka uint16_t p9pbuf_get_tag(struct puffs_framebuf *); 153 1.3 pooka 154 1.3 pooka int proto_getqid(struct puffs_framebuf *, struct qid9p *); 155 1.13 ozaki int proto_getstat(struct puffs_usermount *, struct puffs_framebuf *, struct vattr *, 156 1.3 pooka char **, uint16_t *); 157 1.14 ozaki int proto_expect_walk_nqids(struct puffs_usermount *, 158 1.14 ozaki struct puffs_framebuf *, uint16_t *); 159 1.13 ozaki int proto_expect_stat(struct puffs_usermount *, struct puffs_framebuf *, 160 1.13 ozaki struct vattr *); 161 1.14 ozaki int proto_expect_qid(struct puffs_usermount *, struct puffs_framebuf *, 162 1.14 ozaki uint8_t, struct qid9p *); 163 1.14 ozaki int proto_handle_rerror(struct puffs_usermount *, struct puffs_framebuf *); 164 1.1 pooka 165 1.12 pooka int proto_cc_dupfid(struct puffs_usermount *, p9pfid_t, p9pfid_t); 166 1.12 pooka int proto_cc_clunkfid(struct puffs_usermount *, p9pfid_t, int); 167 1.12 pooka int proto_cc_open(struct puffs_usermount *, p9pfid_t, p9pfid_t, int); 168 1.1 pooka 169 1.13 ozaki void proto_make_stat(struct puffs_usermount *, struct puffs_framebuf *, 170 1.13 ozaki const struct vattr *, const char *, enum vtype); 171 1.1 pooka 172 1.10 pooka struct puffs_node *p9p_handshake(struct puffs_usermount *, 173 1.10 pooka const char *, const char *); 174 1.1 pooka 175 1.1 pooka void qid2vattr(struct vattr *, const struct qid9p *); 176 1.1 pooka struct puffs_node *newp9pnode_va(struct puffs_usermount *, 177 1.1 pooka const struct vattr *, p9pfid_t); 178 1.1 pooka struct puffs_node *newp9pnode_qid(struct puffs_usermount *, 179 1.1 pooka const struct qid9p *, p9pfid_t); 180 1.1 pooka 181 1.12 pooka int getdfwithoffset(struct puffs_usermount *, struct p9pnode *, off_t, 182 1.1 pooka struct dirfid **); 183 1.1 pooka void storedf(struct p9pnode *, struct dirfid *); 184 1.12 pooka void releasedf(struct puffs_usermount *, struct dirfid *); 185 1.12 pooka void nukealldf(struct puffs_usermount *, struct p9pnode *); 186 1.1 pooka 187 1.1 pooka #endif /* PUFFS9P_H_ */ 188