psshfs.h revision 1.21 1 1.21 pooka /* $NetBSD: psshfs.h,v 1.21 2007/07/07 21:14:27 pooka Exp $ */
2 1.1 pooka
3 1.1 pooka /*
4 1.11 pooka * Copyright (c) 2006, 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 PSSHFS_H_
29 1.1 pooka #define PSSHFS_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 /*
36 1.1 pooka * Later protocol versions would have some advantages (such as link count
37 1.1 pooka * supported directly as a part of stat), but since proto version 3 seems
38 1.1 pooka * to be the only widely available version, let's not try to jump through
39 1.1 pooka * too many hoops to be compatible with all versions.
40 1.1 pooka */
41 1.1 pooka #define SFTP_PROTOVERSION 3
42 1.1 pooka
43 1.1 pooka /*
44 1.1 pooka * Refresh directories every n seconds as indicated by the following macro.
45 1.1 pooka * Note that local changes will still be visible immediately.
46 1.1 pooka */
47 1.4 pooka #define PSSHFS_REFRESHIVAL 30
48 1.4 pooka
49 1.1 pooka PUFFSOP_PROTOS(psshfs);
50 1.1 pooka
51 1.1 pooka #define NEXTREQ(pctx) ((pctx->nextreq)++)
52 1.1 pooka #define PSSHFSAUTOVAR(pcc) \
53 1.10 pooka struct psshfs_ctx *pctx = puffs_cc_getspecific(pcc); \
54 1.1 pooka uint32_t reqid = NEXTREQ(pctx); \
55 1.11 pooka struct puffs_framebuf *pb = psbuf_makeout(); \
56 1.1 pooka int rv = 0
57 1.1 pooka
58 1.1 pooka #define PSSHFSRETURN(rv) \
59 1.11 pooka puffs_framebuf_destroy(pb); \
60 1.1 pooka return (rv)
61 1.1 pooka
62 1.15 pooka #define GETRESPONSE(pb) \
63 1.15 pooka do { \
64 1.21 pooka if (puffs_framev_enqueue_cc(pcc, pctx->sshfd, pb, 0) == -1) { \
65 1.15 pooka rv = errno; \
66 1.15 pooka goto out; \
67 1.15 pooka } \
68 1.15 pooka } while (/*CONSTCOND*/0)
69 1.15 pooka
70 1.15 pooka #define JUSTSEND(pb) \
71 1.15 pooka do { \
72 1.21 pooka if (puffs_framev_enqueue_justsend(pu,pctx->sshfd,pb,1,0) == -1){\
73 1.15 pooka rv = errno; \
74 1.15 pooka goto out; \
75 1.15 pooka } \
76 1.15 pooka } while (/*CONSTCOND*/0)
77 1.19 pooka
78 1.15 pooka #define SENDCB(pb, f, a) \
79 1.15 pooka do { \
80 1.21 pooka if (puffs_framev_enqueue_cb(pu, pctx->sshfd, pb,f,a,0) == -1) { \
81 1.15 pooka rv = errno; \
82 1.15 pooka goto out; \
83 1.15 pooka } \
84 1.15 pooka } while (/*CONSTCOND*/0)
85 1.13 pooka
86 1.1 pooka struct psshfs_dir {
87 1.1 pooka int valid;
88 1.1 pooka struct puffs_node *entry;
89 1.1 pooka
90 1.1 pooka char *entryname;
91 1.1 pooka struct vattr va;
92 1.4 pooka time_t attrread;
93 1.19 pooka
94 1.19 pooka struct puffs_framebuf *getattr_pb;
95 1.1 pooka };
96 1.1 pooka
97 1.9 pooka struct psshfs_fid {
98 1.9 pooka time_t mounttime;
99 1.9 pooka struct puffs_node *node;
100 1.9 pooka };
101 1.9 pooka
102 1.1 pooka struct psshfs_node {
103 1.1 pooka struct puffs_node *parent;
104 1.1 pooka
105 1.1 pooka struct psshfs_dir *dir; /* only valid if we're of type VDIR */
106 1.18 pooka struct delayattr {
107 1.18 pooka struct puffs_framebuf *pufbuf;
108 1.18 pooka struct readdirattr *rda;
109 1.18 pooka } *da;
110 1.18 pooka size_t nextda;
111 1.18 pooka
112 1.1 pooka size_t denttot;
113 1.1 pooka size_t dentnext;
114 1.1 pooka time_t dentread;
115 1.4 pooka int childcount;
116 1.16 pooka
117 1.16 pooka int stat;
118 1.1 pooka
119 1.4 pooka time_t attrread;
120 1.19 pooka struct puffs_framebuf *getattr_pb;
121 1.12 pooka
122 1.12 pooka char *fhand_r;
123 1.12 pooka char *fhand_w;
124 1.14 pooka uint32_t fhand_r_len;
125 1.14 pooka uint32_t fhand_w_len;
126 1.1 pooka };
127 1.16 pooka #define PSN_RECLAIMED 0x01
128 1.16 pooka #define PSN_HASFH 0x02
129 1.1 pooka
130 1.1 pooka struct psshfs_ctx {
131 1.1 pooka int sshfd;
132 1.1 pooka pid_t sshpid;
133 1.1 pooka const char *mountpath;
134 1.1 pooka
135 1.1 pooka int protover;
136 1.1 pooka uint32_t nextreq;
137 1.1 pooka
138 1.11 pooka struct puffs_framebuf *curpb;
139 1.1 pooka
140 1.1 pooka struct psshfs_node psn_root;
141 1.1 pooka ino_t nextino;
142 1.1 pooka
143 1.9 pooka int canexport;
144 1.9 pooka time_t mounttime;
145 1.1 pooka };
146 1.1 pooka
147 1.2 pooka int psshfs_domount(struct puffs_usermount *);
148 1.2 pooka
149 1.11 pooka int psbuf_read(struct puffs_usermount *, struct puffs_framebuf *,int,int*);
150 1.11 pooka int psbuf_write(struct puffs_usermount *, struct puffs_framebuf *,int,int*);
151 1.11 pooka int psbuf_cmp(struct puffs_usermount *,
152 1.11 pooka struct puffs_framebuf *, struct puffs_framebuf *);
153 1.11 pooka
154 1.11 pooka struct puffs_framebuf *psbuf_makeout(void);
155 1.11 pooka void psbuf_recycleout(struct puffs_framebuf *);
156 1.11 pooka
157 1.11 pooka void psbuf_put_1(struct puffs_framebuf *, uint8_t);
158 1.11 pooka void psbuf_put_2(struct puffs_framebuf *, uint16_t);
159 1.11 pooka void psbuf_put_4(struct puffs_framebuf *, uint32_t);
160 1.11 pooka void psbuf_put_8(struct puffs_framebuf *, uint64_t);
161 1.11 pooka void psbuf_put_str(struct puffs_framebuf *, const char *);
162 1.11 pooka void psbuf_put_data(struct puffs_framebuf *, const void *, uint32_t);
163 1.11 pooka void psbuf_put_vattr(struct puffs_framebuf *, const struct vattr *);
164 1.11 pooka
165 1.11 pooka uint8_t psbuf_get_type(struct puffs_framebuf *);
166 1.11 pooka uint32_t psbuf_get_len(struct puffs_framebuf *);
167 1.11 pooka uint32_t psbuf_get_reqid(struct puffs_framebuf *);
168 1.11 pooka
169 1.11 pooka int psbuf_get_1(struct puffs_framebuf *, uint8_t *);
170 1.11 pooka int psbuf_get_2(struct puffs_framebuf *, uint16_t *);
171 1.11 pooka int psbuf_get_4(struct puffs_framebuf *, uint32_t *);
172 1.11 pooka int psbuf_get_8(struct puffs_framebuf *, uint64_t *);
173 1.11 pooka int psbuf_get_str(struct puffs_framebuf *, char **, uint32_t *);
174 1.11 pooka int psbuf_get_vattr(struct puffs_framebuf *, struct vattr *);
175 1.11 pooka
176 1.11 pooka int psbuf_expect_status(struct puffs_framebuf *);
177 1.11 pooka int psbuf_expect_handle(struct puffs_framebuf *, char **, uint32_t *);
178 1.11 pooka int psbuf_expect_name(struct puffs_framebuf *, uint32_t *);
179 1.11 pooka int psbuf_expect_attrs(struct puffs_framebuf *, struct vattr *);
180 1.11 pooka
181 1.11 pooka int psbuf_do_data(struct puffs_framebuf *, uint8_t *, uint32_t *);
182 1.11 pooka
183 1.11 pooka void psbuf_req_data(struct puffs_framebuf *, int, uint32_t,
184 1.11 pooka const void *, uint32_t);
185 1.11 pooka void psbuf_req_str(struct puffs_framebuf *, int, uint32_t, const char *);
186 1.1 pooka
187 1.1 pooka int sftp_readdir(struct puffs_cc *, struct psshfs_ctx *,
188 1.1 pooka struct puffs_node *);
189 1.1 pooka
190 1.1 pooka struct psshfs_dir *lookup(struct psshfs_dir *, size_t, const char *);
191 1.1 pooka struct puffs_node *makenode(struct puffs_usermount *, struct puffs_node *,
192 1.1 pooka struct psshfs_dir *, const struct vattr *);
193 1.1 pooka struct puffs_node *allocnode(struct puffs_usermount *, struct puffs_node *,
194 1.1 pooka const char *, const struct vattr *);
195 1.1 pooka struct psshfs_dir *direnter(struct puffs_node *, const char *);
196 1.3 pooka void nukenode(struct puffs_node *, const char *, int);
197 1.5 pooka void doreclaim(struct puffs_node *);
198 1.7 pooka int getpathattr(struct puffs_cc *, const char *, struct vattr *);
199 1.7 pooka int getnodeattr(struct puffs_cc *, struct puffs_node *);
200 1.1 pooka
201 1.1 pooka #endif /* PSSHFS_H_ */
202