-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfuse.cpp
More file actions
366 lines (303 loc) · 7.45 KB
/
fuse.cpp
File metadata and controls
366 lines (303 loc) · 7.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
/*
This file is part of CassFS.
Copyright 2010 Jeff Darcy <jeff@pl.atyp.us>
CassFS is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
CassFS is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with CassFS. If not, see <http://www.gnu.org/licenses/>.
*/
#include <errno.h>
#include <stdio.h>
#include <iostream>
#include <boost/shared_ptr.hpp>
#include <protocol/TBinaryProtocol.h>
#include <transport/TSocket.h>
#include <transport/TTransportUtils.h>
#include "Cassandra.h"
#include "base64.h"
#include "cfs_types.h"
using namespace std;
using namespace boost;
using namespace apache::thrift;
using namespace apache::thrift::protocol;
using namespace apache::thrift::transport;
using namespace org::apache::cassandra;
#include "cassfs.h"
extern "C" {
/*
* Based in part on fusexmp.c, part of FUSE
* Copyright (C) 2001-2007 Miklos Szeredi <miklos@szeredi.hu>
* See http://fuse.sourceforge.net/ for original code and license.
*/
#define FUSE_USE_VERSION 26
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#ifdef linux
/* For pread()/pwrite() */
//#define _XOPEN_SOURCE 500
#endif
#include <fuse.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <dirent.h>
#include <errno.h>
#include <sys/time.h>
#ifdef HAVE_SETXATTR
#include <sys/xattr.h>
#endif
struct my_opts {
char * host;
char * port;
char * name;
};
struct my_opts opts = { (char *)"localhost", (char *)"7777" };
struct fuse_opt my_opt_descs[] = {
{ "host=%s", offsetof(struct my_opts,host) },
{ "port=%s", offsetof(struct my_opts,port) },
{ "name=%s", offsetof(struct my_opts,name) },
{ NULL }
};
static int cfs_getattr(const char *path, struct stat *stbuf)
{
CassFs * cfs;
int rc;
CfsInode tmp;
CfsInode * my_inode = &tmp;
printf("in %s(%s)\n",__func__,path);
cfs = (CassFs *)fuse_get_context()->private_data;
rc = cfs->LookupAll((char *)path,&my_inode);
if (rc) {
return -rc;
}
cout << path << " => type " << hex << my_inode->type << ", size "
<< dec << my_inode->size << endl;
stbuf->st_mode = my_inode->type | 0644;
stbuf->st_size = my_inode->size;
return 0;
}
static int cfs_access(const char *path, int mask)
{
printf("in %s\n",__func__);
return 0;
}
static int cfs_readlink(const char *path, char *buf, size_t size)
{
printf("in %s(%s,%p,%u)\n",__func__,path,buf,size);
return 0;
}
// TBD: Blech. Pass this as an arg through CassFs::List and back.
void * rd_buf;
fuse_fill_dir_t rd_fnc;
void
cfs_list_cb (char * name, int inum, int mode)
{
struct stat st;
if (rd_fnc) {
cout << "returning " << name << endl;
st.st_ino = inum;
st.st_mode = mode >> 12;
if (rd_fnc(rd_buf,name,&st,0)) {
rd_fnc = NULL;
}
}
else {
cout << "skipping " << name << endl;
}
}
static int cfs_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
off_t offset, struct fuse_file_info *fi)
{
CassFs * cfs;
(void) offset;
(void) fi;
printf("in %s(%s,%p,%d)\n",__func__,path,buf,offset);
cfs = (CassFs *)fuse_get_context()->private_data;
rd_buf = buf;
rd_fnc = filler;
cfs->List((char *)path,cfs_list_cb);
return 0;
}
static int cfs_mknod(const char *path, mode_t mode, dev_t rdev)
{
CassFs * cfs;
int rc;
printf("in %s(%s)\n",__func__,path);
if (!S_ISREG(mode)) {
return -EOPNOTSUPP;
}
cfs = (CassFs *)fuse_get_context()->private_data;
// TBD: fix the interface to CassFs::OpenFile, because this way is
// cheesy as hell.
rc = cfs->Write((char *)path,0,NULL,0);
cout << __func__ << " got " << rc << " back from Write(0) for "
<< path << endl;
return -rc;
}
static int cfs_mkdir(const char *path, mode_t mode)
{
CassFs * cfs;
int rc;
printf("in %s\n",__func__);
cfs = (CassFs *)fuse_get_context()->private_data;
rc = cfs->Mkdir((char *)path);
return rc ? -rc : 0;
}
static int cfs_unlink(const char *path)
{
printf("in %s\n",__func__);
return 0;
}
static int cfs_rmdir(const char *path)
{
printf("in %s\n",__func__);
return 0;
}
static int cfs_symlink(const char *from, const char *to)
{
printf("in %s\n",__func__);
return 0;
}
static int cfs_rename(const char *from, const char *to)
{
printf("in %s\n",__func__);
return 0;
}
static int cfs_link(const char *from, const char *to)
{
printf("in %s\n",__func__);
return 0;
}
static int cfs_chmod(const char *path, mode_t mode)
{
printf("in %s\n",__func__);
return 0;
}
static int cfs_chown(const char *path, uid_t uid, gid_t gid)
{
printf("in %s\n",__func__);
return 0;
}
static int cfs_truncate(const char *path, off_t size)
{
printf("in %s\n",__func__);
return 0;
}
static int cfs_utimens(const char *path, const struct timespec ts[2])
{
printf("in %s\n",__func__);
return 0;
}
static int cfs_open(const char *path, struct fuse_file_info *fi)
{
printf("in %s\n",__func__);
return 0;
}
static int cfs_read(const char *path, char *buf, size_t size, off_t offset,
struct fuse_file_info *fi)
{
CassFs * cfs;
int rc;
cfs_size_t len;
printf("in %s(%s,%d,%u)\n",__func__,path,offset,size);
cfs = (CassFs *)fuse_get_context()->private_data;
len = size;
rc = cfs->Read((char *)path,(cfs_offset_t)offset,buf,len);
return rc ? -rc : len;
}
static int cfs_write(const char *path, const char *buf, size_t size,
off_t offset, struct fuse_file_info *fi)
{
CassFs * cfs;
int rc;
printf("in %s\n",__func__);
cfs = (CassFs *)fuse_get_context()->private_data;
rc = cfs->Write((char *)path,(cfs_offset_t)offset,(char *)buf,size);
cout << __func__ << "got " << rc << " back from Write" << endl;
return rc ? -rc : size;
}
static int cfs_statfs(const char *path, struct statvfs *stbuf)
{
int res;
printf("in %s\n",__func__);
res = statvfs(path, stbuf);
if (res == -1)
return -errno;
return 0;
}
void *
cfs_init (struct fuse_conn_info * not_used)
{
CassFs * cfs;
(void)not_used;
printf("in %s\n",__func__);
cfs = new CassFs();
cfs->MountFs(opts.name);
return cfs;
}
// Apparently g++ doesn't like ".getattr = cfs_getattr" style initializers
// even within an "extern C" block. Would it be too much to ask that they
// support *their own language extensions* consistently?
static struct fuse_operations cfs_oper = {
cfs_getattr,
cfs_readlink,
NULL, /* getdir */
cfs_mknod,
cfs_mkdir,
cfs_unlink,
cfs_rmdir,
cfs_symlink,
cfs_rename,
cfs_link,
cfs_chmod,
cfs_chown,
cfs_truncate,
NULL, /* utime */
cfs_open,
cfs_read,
cfs_write,
cfs_statfs,
NULL, /* flush */
NULL, /* release */
NULL, /* fsync */
#ifdef HAVE_SETXATTR
NULL,
NULL,
NULL,
NULL,
#endif
NULL, /* opendir */
cfs_readdir,
NULL, /* releasedir */
NULL, /* fsyncdir */
cfs_init,
NULL, /* destroy */
cfs_access,
NULL, /* create */
NULL, /* ftruncate */
NULL, /* fgetattr */
NULL, /* lock */
cfs_utimens,
};
int
myfs_opt_proc(void *data, const char *arg, int key, struct fuse_args *outargs)
{
return 1;
}
int main(int argc, char *argv[])
{
struct fuse_args args = FUSE_ARGS_INIT(argc, argv);
umask(0);
fuse_opt_parse(&args, &opts, my_opt_descs, myfs_opt_proc);
printf("using %s:%s\n",opts.host,opts.port);
return fuse_main(args.argc, args.argv, &cfs_oper, NULL);
}
} // extern "C"