rfuse-ng 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/ext/rfuse.c CHANGED
@@ -19,9 +19,11 @@
19
19
  #include "context.h"
20
20
  #include "file_info.h"
21
21
 
22
- static VALUE fuse_object; //this is a global variable where we store the fuse object
22
+ //this is a global variable where we store the fuse object
23
+ static VALUE fuse_object;
23
24
 
24
- static int unsafe_return_error(VALUE *args){
25
+ static int unsafe_return_error(VALUE *args)
26
+ {
25
27
  VALUE info;
26
28
  info = rb_inspect(ruby_errinfo);
27
29
  rb_backtrace();
@@ -29,35 +31,43 @@ static int unsafe_return_error(VALUE *args){
29
31
  return rb_funcall(info,rb_intern("errno"),0);
30
32
  }
31
33
 
32
- static int return_error(int def_error){
34
+ static int return_error(int def_error)
35
+ {
33
36
  /*if the raised error has a method errno the return that value else
34
37
  return def(ault)_error */
35
38
  VALUE res;
36
39
  int error = 0;
37
40
  res=rb_protect((VALUE (*)())unsafe_return_error,Qnil,&error);
38
- if (error) { //this exception has no errno method or something else
39
- //went wrong
41
+ if (error)
42
+ { //this exception has no errno method or something else
43
+ //went wrong
40
44
  printf ("ERROR: Not an Errno::xxx error or exception in exception!\n");
41
45
  return def_error;
42
- } else {
46
+ }
47
+ else
48
+ {
43
49
  return FIX2INT(res);
44
50
  }
45
51
  }
46
52
 
47
- static VALUE unsafe_readdir(VALUE *args){
48
- VALUE *values=(VALUE*)args;
49
- VALUE path = values[0];
50
- VALUE filler = values[1];
51
- VALUE offset = values[2];
52
- VALUE ffi = values[3];
53
+ //----------------------READDIR
54
+
55
+ static VALUE unsafe_readdir(VALUE *args)
56
+ {
57
+ VALUE path = args[0];
58
+ VALUE filler = args[1];
59
+ VALUE offset = args[2];
60
+ VALUE ffi = args[3];
61
+
53
62
  struct fuse_context *ctx = fuse_get_context();
63
+
54
64
  return rb_funcall(fuse_object,rb_intern("readdir"),5,wrap_context(ctx),path,filler,
55
65
  offset,ffi);
56
66
  }
57
67
 
58
- //call readdir with an Filler object
59
- static int rf_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
60
- off_t offset,struct fuse_file_info *ffi)
68
+ //call readdir with an Filler object
69
+ static int rf_readdir(const char *path, void *buf,
70
+ fuse_fill_dir_t filler, off_t offset,struct fuse_file_info *ffi)
61
71
  {
62
72
  VALUE fuse_module;
63
73
  VALUE rfiller_class;
@@ -71,28 +81,38 @@ static int rf_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
71
81
  args[0]=rb_str_new2(path);
72
82
 
73
83
  fuse_module = rb_const_get(rb_cObject, rb_intern("RFuse"));
84
+
74
85
  rfiller_class=rb_const_get(fuse_module,rb_intern("Filler"));
75
86
  rfiller_instance=rb_funcall(rfiller_class,rb_intern("new"),0);
76
87
  Data_Get_Struct(rfiller_instance,struct filler_t,fillerc);
88
+
77
89
  fillerc->filler=filler;//Init the filler by hand.... TODO: cleaner
78
90
  fillerc->buffer=buf;
79
91
  args[1]=rfiller_instance;
80
92
  args[2]=INT2NUM(offset);
81
93
  args[3]=wrap_file_info(ffi);
94
+
82
95
  res=rb_protect((VALUE (*)())unsafe_readdir,(VALUE)args,&error);
83
- if (error) {
96
+
97
+ if (error)
98
+ {
84
99
  return -(return_error(ENOENT));
85
- } else {
100
+ }
101
+ else
102
+ {
86
103
  return 0;
87
- };
104
+ }
88
105
  }
89
- //----------------------------------------------
90
106
 
91
- static VALUE unsafe_readlink(VALUE *args){
92
- VALUE *values=(VALUE*)args;
93
- VALUE path = values[0];
94
- VALUE size = values[1];
107
+ //----------------------READLINK
108
+
109
+ static VALUE unsafe_readlink(VALUE *args)
110
+ {
111
+ VALUE path = args[0];
112
+ VALUE size = args[1];
113
+
95
114
  struct fuse_context *ctx = fuse_get_context();
115
+
96
116
  return rb_funcall(fuse_object,rb_intern("readlink"),3,wrap_context(ctx),path,size);
97
117
  }
98
118
 
@@ -105,96 +125,172 @@ static int rf_readlink(const char *path, char *buf, size_t size)
105
125
  args[1]=INT2NUM(size);
106
126
  char *rbuf;
107
127
  res=rb_protect((VALUE (*)())unsafe_readlink,(VALUE)args,&error);
108
- if (error) {
128
+ if (error)
129
+ {
109
130
  return -(return_error(ENOENT));
110
- } else {
131
+ }
132
+ else
133
+ {
111
134
  rbuf=STR2CSTR(res);
112
135
  strncpy(buf,rbuf,size);
113
136
  return 0;
114
137
  }
115
138
  }
116
- //----------------------------GETATTR
117
- static VALUE unsafe_getattr(VALUE *args){
118
- VALUE *values=(VALUE*)args;
119
- VALUE path = values[0];
139
+
140
+ //----------------------GETDIR
141
+
142
+ static VALUE unsafe_getdir(VALUE *args)
143
+ {
144
+ VALUE path = args[0];
145
+ VALUE filler = args[1];
146
+
147
+ struct fuse_context *ctx = fuse_get_context();
148
+
149
+ return rb_funcall(
150
+ fuse_object,rb_intern("getdir"),3,
151
+ wrap_context(ctx),path,filler
152
+ );
153
+ }
154
+
155
+ //call getdir with an Filler object
156
+ static int rf_getdir(const char *path, fuse_dirh_t dh, fuse_dirfil_t df)
157
+ {
158
+ VALUE fuse_module;
159
+ VALUE rfiller_class;
160
+ VALUE rfiller_instance;
161
+ VALUE args[2];
162
+ VALUE res;
163
+ struct filler_t *fillerc;
164
+ int error = 0;
165
+
166
+ //create a filler object
167
+ args[0]=rb_str_new2(path);
168
+
169
+ fuse_module = rb_const_get(rb_cObject, rb_intern("RFuse"));
170
+
171
+ rfiller_class = rb_const_get(fuse_module,rb_intern("Filler"));
172
+ rfiller_instance = rb_funcall(rfiller_class,rb_intern("new"),0);
173
+
174
+ Data_Get_Struct(rfiller_instance,struct filler_t,fillerc);
175
+
176
+ fillerc->df = df;
177
+ fillerc->dh = dh;
178
+
179
+ args[1]=rfiller_instance;
180
+
181
+ res = rb_protect((VALUE (*)())unsafe_getdir, (VALUE)args, &error);
182
+
183
+ if (error)
184
+ {
185
+ return -(return_error(ENOENT));
186
+ }
187
+ else
188
+ {
189
+ return 0;
190
+ }
191
+ }
192
+
193
+ //----------------------MKNOD
194
+
195
+ static VALUE unsafe_mknod(VALUE *args)
196
+ {
197
+ VALUE path = args[0];
198
+ VALUE mode = args[1];
199
+ VALUE dev = args[2];
120
200
  struct fuse_context *ctx=fuse_get_context();
121
- return rb_funcall(fuse_object,rb_intern("getattr"),2,wrap_context(ctx),path);
201
+ return rb_funcall(fuse_object,rb_intern("mknod"),4,wrap_context(ctx),path,mode,dev);
122
202
  }
123
203
 
124
204
  //calls getattr with path and expects something like FuseStat back
125
- static int rf_getattr(const char *path, struct stat *stbuf)
205
+ static int rf_mknod(const char *path, mode_t mode,dev_t dev)
126
206
  {
127
- VALUE args[1];
207
+ VALUE args[3];
128
208
  VALUE res;
129
209
  int error = 0;
130
210
  args[0]=rb_str_new2(path);
131
- res=rb_protect((VALUE (*)())unsafe_getattr,(VALUE) args,&error);
132
- if (error || (res == Qnil)) {
211
+ args[1]=INT2FIX(mode);
212
+ args[2]=INT2FIX(dev);
213
+ res=rb_protect((VALUE (*)())unsafe_mknod,(VALUE) args,&error);
214
+ if (error)
215
+ {
133
216
  return -(return_error(ENOENT));
134
- } else {
135
- rstat2stat(res,stbuf);
217
+ }
218
+ else
219
+ {
136
220
  return 0;
137
221
  }
138
222
  }
139
- //----------------------MKDIR
140
- static VALUE unsafe_mkdir(VALUE *args){
141
- VALUE *values=(VALUE*)args;
142
- VALUE path = values[0];
143
- VALUE mode = values[1];
223
+
224
+ //----------------------GETATTR
225
+
226
+ static VALUE unsafe_getattr(VALUE *args)
227
+ {
228
+ VALUE path = args[0];
229
+
144
230
  struct fuse_context *ctx=fuse_get_context();
145
- return rb_funcall(fuse_object,rb_intern("mkdir"),3,wrap_context(ctx),path,mode);
231
+
232
+ return rb_funcall(fuse_object,rb_intern("getattr"),2,wrap_context(ctx),path);
146
233
  }
147
234
 
148
235
  //calls getattr with path and expects something like FuseStat back
149
- static int rf_mkdir(const char *path, mode_t mode)
236
+ static int rf_getattr(const char *path, struct stat *stbuf)
150
237
  {
151
- VALUE args[2];
238
+ VALUE args[1];
152
239
  VALUE res;
153
240
  int error = 0;
154
241
  args[0]=rb_str_new2(path);
155
- args[1]=INT2FIX(mode);
156
- res=rb_protect((VALUE (*)())unsafe_mkdir,(VALUE) args,&error);
157
- if (error) {
242
+ res=rb_protect((VALUE (*)())unsafe_getattr,(VALUE) args,&error);
243
+
244
+ if (error || (res == Qnil))
245
+ {
158
246
  return -(return_error(ENOENT));
159
- } else {
247
+ }
248
+ else
249
+ {
250
+ rstat2stat(res,stbuf);
160
251
  return 0;
161
- };
252
+ }
162
253
  }
163
- //----------------------
164
254
 
165
- //----------------------MKNOD
166
- static VALUE unsafe_mknod(VALUE *args){
167
- VALUE *values=(VALUE*)args;
168
- VALUE path = values[0];
169
- VALUE mode = values[1];
170
- VALUE dev = values[2];
255
+ //----------------------MKDIR
256
+
257
+ static VALUE unsafe_mkdir(VALUE *args)
258
+ {
259
+ VALUE path = args[0];
260
+ VALUE mode = args[1];
261
+
171
262
  struct fuse_context *ctx=fuse_get_context();
172
- return rb_funcall(fuse_object,rb_intern("mknod"),4,wrap_context(ctx),path,mode,dev);
263
+
264
+ return rb_funcall(fuse_object,rb_intern("mkdir"),3,wrap_context(ctx),path,mode);
173
265
  }
174
266
 
175
267
  //calls getattr with path and expects something like FuseStat back
176
- static int rf_mknod(const char *path, mode_t mode,dev_t dev)
268
+ static int rf_mkdir(const char *path, mode_t mode)
177
269
  {
178
- VALUE args[3];
270
+ VALUE args[2];
179
271
  VALUE res;
180
272
  int error = 0;
181
273
  args[0]=rb_str_new2(path);
182
274
  args[1]=INT2FIX(mode);
183
- args[2]=INT2FIX(dev);
184
- res=rb_protect((VALUE (*)())unsafe_mknod,(VALUE) args,&error);
185
- if (error) {
275
+ res=rb_protect((VALUE (*)())unsafe_mkdir,(VALUE) args,&error);
276
+
277
+ if (error)
278
+ {
186
279
  return -(return_error(ENOENT));
187
- } else {
280
+ }
281
+ else
282
+ {
188
283
  return 0;
189
- };
284
+ }
190
285
  }
191
- //----------------------
286
+
192
287
  //----------------------OPEN
193
- static VALUE unsafe_open(VALUE *args){
194
- VALUE *values=(VALUE*)args;
195
- VALUE path = values[0];
196
- VALUE ffi = values[1];
197
- struct fuse_context *ctx=fuse_get_context();
288
+
289
+ static VALUE unsafe_open(VALUE *args)
290
+ {
291
+ VALUE path = args[0];
292
+ VALUE ffi = args[1];
293
+ struct fuse_context *ctx=fuse_get_context();
198
294
  return rb_funcall(fuse_object,rb_intern("open"),3,wrap_context(ctx),path,ffi);
199
295
  }
200
296
 
@@ -207,19 +303,25 @@ static int rf_open(const char *path,struct fuse_file_info *ffi)
207
303
  args[0]=rb_str_new2(path);
208
304
  args[1]=wrap_file_info(ffi);
209
305
  res=rb_protect((VALUE (*)())unsafe_open,(VALUE) args,&error);
210
- if (error) {
306
+ if (error)
307
+ {
211
308
  return -(return_error(ENOENT));
212
- } else {
309
+ }
310
+ else
311
+ {
213
312
  return 0;
214
- };
313
+ }
215
314
  }
216
- //----------------------
315
+
217
316
  //----------------------RELEASE
218
- static VALUE unsafe_release(VALUE *args){
219
- VALUE *values=(VALUE*)args;
220
- VALUE path = values[0];
221
- VALUE ffi = values[1];
317
+
318
+ static VALUE unsafe_release(VALUE *args)
319
+ {
320
+ VALUE path = args[0];
321
+ VALUE ffi = args[1];
322
+
222
323
  struct fuse_context *ctx=fuse_get_context();
324
+
223
325
  return rb_funcall(fuse_object,rb_intern("release"),3,wrap_context(ctx),path,ffi);
224
326
  }
225
327
 
@@ -231,19 +333,33 @@ static int rf_release(const char *path, struct fuse_file_info *ffi)
231
333
  args[0]=rb_str_new2(path);
232
334
  args[1]=wrap_file_info(ffi);
233
335
  res=rb_protect((VALUE (*)())unsafe_release,(VALUE) args,&error);
234
- if (error) {
336
+
337
+ if (error)
338
+ {
235
339
  return -(return_error(ENOENT));
236
- } else {
340
+ }
341
+ else
342
+ {
237
343
  return 0;
238
- };
344
+ }
345
+ }
346
+
347
+ //----------------------FSYNC
348
+ static int rf_fsync(const char *path, int datasync, struct fuse_file_info *ffi)
349
+ {
350
+ //TODO
351
+ return 0;
239
352
  }
240
- //----------------------
353
+
241
354
  //----------------------FLUSH
242
- static VALUE unsafe_flush(VALUE *args){
243
- VALUE *values=(VALUE*)args;
244
- VALUE path = values[0];
245
- VALUE ffi=values[1];
355
+
356
+ static VALUE unsafe_flush(VALUE *args)
357
+ {
358
+ VALUE path = args[0];
359
+ VALUE ffi = args[1];
360
+
246
361
  struct fuse_context *ctx=fuse_get_context();
362
+
247
363
  return rb_funcall(fuse_object,rb_intern("flush"),3,wrap_context(ctx),path,ffi);
248
364
  }
249
365
 
@@ -255,19 +371,26 @@ static int rf_flush(const char *path,struct fuse_file_info *ffi)
255
371
  args[0]=rb_str_new2(path);
256
372
  args[1]=wrap_file_info(ffi);
257
373
  res=rb_protect((VALUE (*)())unsafe_flush,(VALUE) args,&error);
258
- if (error) {
374
+
375
+ if (error)
376
+ {
259
377
  return -(return_error(ENOENT));
260
- } else {
378
+ }
379
+ else
380
+ {
261
381
  return 0;
262
- };
382
+ }
263
383
  }
264
- //----------------------
384
+
265
385
  //----------------------TRUNCATE
266
- static VALUE unsafe_truncate(VALUE *args){
267
- VALUE *values=(VALUE*)args;
268
- VALUE path = values[0];
269
- VALUE offset = values[1];
386
+
387
+ static VALUE unsafe_truncate(VALUE *args)
388
+ {
389
+ VALUE path = args[0];
390
+ VALUE offset = args[1];
391
+
270
392
  struct fuse_context *ctx=fuse_get_context();
393
+
271
394
  return rb_funcall(fuse_object,rb_intern("truncate"),3,wrap_context(ctx),path,offset);
272
395
  }
273
396
 
@@ -279,20 +402,27 @@ static int rf_truncate(const char *path,off_t offset)
279
402
  args[0]=rb_str_new2(path);
280
403
  args[1]=INT2FIX(offset);
281
404
  res=rb_protect((VALUE (*)())unsafe_truncate,(VALUE) args,&error);
282
- if (error) {
405
+
406
+ if (error)
407
+ {
283
408
  return -(return_error(ENOENT));
284
- } else {
409
+ }
410
+ else
411
+ {
285
412
  return 0;
286
- };
413
+ }
287
414
  }
288
- //----------------------
415
+
289
416
  //----------------------UTIME
290
- static VALUE unsafe_utime(VALUE *args){
291
- VALUE *values=(VALUE*)args;
292
- VALUE path = values[0];
293
- VALUE actime = values[1];
294
- VALUE modtime = values[2];
417
+
418
+ static VALUE unsafe_utime(VALUE *args)
419
+ {
420
+ VALUE path = args[0];
421
+ VALUE actime = args[1];
422
+ VALUE modtime = args[2];
423
+
295
424
  struct fuse_context *ctx=fuse_get_context();
425
+
296
426
  return rb_funcall(fuse_object,rb_intern("utime"),4,wrap_context(ctx),path,actime,modtime);
297
427
  }
298
428
 
@@ -305,20 +435,27 @@ static int rf_utime(const char *path,struct utimbuf *utim)
305
435
  args[1]=INT2NUM(utim->actime);
306
436
  args[2]=INT2NUM(utim->modtime);
307
437
  res=rb_protect((VALUE (*)())unsafe_utime,(VALUE) args,&error);
308
- if (error) {
438
+
439
+ if (error)
440
+ {
309
441
  return -(return_error(ENOENT));
310
- } else {
442
+ }
443
+ else
444
+ {
311
445
  return 0;
312
- };
446
+ }
313
447
  }
314
- //----------------------
448
+
315
449
  //----------------------CHOWN
316
- static VALUE unsafe_chown(VALUE *args){
317
- VALUE *values=(VALUE*)args;
318
- VALUE path = values[0];
319
- VALUE uid = values[1];
320
- VALUE gid = values[2];
450
+
451
+ static VALUE unsafe_chown(VALUE *args)
452
+ {
453
+ VALUE path = args[0];
454
+ VALUE uid = args[1];
455
+ VALUE gid = args[2];
456
+
321
457
  struct fuse_context *ctx=fuse_get_context();
458
+
322
459
  return rb_funcall(fuse_object,rb_intern("chown"),4,wrap_context(ctx),path,uid,gid);
323
460
  }
324
461
 
@@ -331,19 +468,26 @@ static int rf_chown(const char *path,uid_t uid,gid_t gid)
331
468
  args[1]=INT2FIX(uid);
332
469
  args[2]=INT2FIX(gid);
333
470
  res=rb_protect((VALUE (*)())unsafe_chown,(VALUE) args,&error);
334
- if (error) {
471
+
472
+ if (error)
473
+ {
335
474
  return -(return_error(ENOENT));
336
- } else {
475
+ }
476
+ else
477
+ {
337
478
  return 0;
338
- };
479
+ }
339
480
  }
340
- //----------------------
481
+
341
482
  //----------------------CHMOD
342
- static VALUE unsafe_chmod(VALUE *args){
343
- VALUE *values=(VALUE*)args;
344
- VALUE path = values[0];
345
- VALUE mode = values[1];
483
+
484
+ static VALUE unsafe_chmod(VALUE *args)
485
+ {
486
+ VALUE path = args[0];
487
+ VALUE mode = args[1];
488
+
346
489
  struct fuse_context *ctx=fuse_get_context();
490
+
347
491
  return rb_funcall(fuse_object,rb_intern("chmod"),3,wrap_context(ctx),path,mode);
348
492
  }
349
493
 
@@ -355,18 +499,25 @@ static int rf_chmod(const char *path,mode_t mode)
355
499
  args[0]=rb_str_new2(path);
356
500
  args[1]=INT2FIX(mode);
357
501
  res=rb_protect((VALUE (*)())unsafe_chmod,(VALUE) args,&error);
358
- if (error) {
502
+
503
+ if (error)
504
+ {
359
505
  return -(return_error(ENOENT));
360
- } else {
506
+ }
507
+ else
508
+ {
361
509
  return 0;
362
- };
510
+ }
363
511
  }
364
- //----------------------
512
+
365
513
  //----------------------UNLINK
366
- static VALUE unsafe_unlink(VALUE *args){
367
- VALUE *values=(VALUE*)args;
368
- VALUE path = values[0];
514
+
515
+ static VALUE unsafe_unlink(VALUE *args)
516
+ {
517
+ VALUE path = args[0];
518
+
369
519
  struct fuse_context *ctx=fuse_get_context();
520
+
370
521
  return rb_funcall(fuse_object,rb_intern("unlink"),2,wrap_context(ctx),path);
371
522
  }
372
523
 
@@ -377,18 +528,25 @@ static int rf_unlink(const char *path)
377
528
  int error = 0;
378
529
  args[0]=rb_str_new2(path);
379
530
  res=rb_protect((VALUE (*)())unsafe_unlink,(VALUE) args,&error);
380
- if (error) {
531
+
532
+ if (error)
533
+ {
381
534
  return -(return_error(ENOENT));
382
- } else {
535
+ }
536
+ else
537
+ {
383
538
  return 0;
384
- };
539
+ }
385
540
  }
386
- //----------------------
541
+
387
542
  //----------------------RMDIR
388
- static VALUE unsafe_rmdir(VALUE *args){
389
- VALUE *values=(VALUE*)args;
390
- VALUE path = values[0];
543
+
544
+ static VALUE unsafe_rmdir(VALUE *args)
545
+ {
546
+ VALUE path = args[0];
547
+
391
548
  struct fuse_context *ctx=fuse_get_context();
549
+
392
550
  return rb_funcall(fuse_object,rb_intern("rmdir"),2,wrap_context(ctx),path);
393
551
  }
394
552
 
@@ -397,21 +555,27 @@ static int rf_rmdir(const char *path)
397
555
  VALUE args[1];
398
556
  VALUE res;
399
557
  int error = 0;
400
- args[0]=rb_str_new2(path);
401
- res=rb_protect((VALUE (*)())unsafe_rmdir,(VALUE) args,&error);
402
- if (error) {
558
+ args[0] = rb_str_new2(path);
559
+ res = rb_protect((VALUE (*)())unsafe_rmdir, (VALUE) args ,&error);
560
+
561
+ if (error)
562
+ {
403
563
  return -(return_error(ENOENT));
404
- } else {
564
+ }
565
+ else
566
+ {
405
567
  return 0;
406
- };
568
+ }
407
569
  }
408
- //----------------------
570
+
409
571
  //----------------------SYMLINK
572
+
410
573
  static VALUE unsafe_symlink(VALUE *args){
411
- VALUE *values=(VALUE*)args;
412
- VALUE path = values[0];
413
- VALUE as = values[1];
574
+ VALUE path = args[0];
575
+ VALUE as = args[1];
576
+
414
577
  struct fuse_context *ctx=fuse_get_context();
578
+
415
579
  return rb_funcall(fuse_object,rb_intern("symlink"),3,wrap_context(ctx),path,as);
416
580
  }
417
581
 
@@ -423,19 +587,26 @@ static int rf_symlink(const char *path,const char *as)
423
587
  args[0]=rb_str_new2(path);
424
588
  args[1]=rb_str_new2(as);
425
589
  res=rb_protect((VALUE (*)())unsafe_symlink,(VALUE) args,&error);
426
- if (error) {
590
+
591
+ if (error)
592
+ {
427
593
  return -(return_error(ENOENT));
428
- } else {
594
+ }
595
+ else
596
+ {
429
597
  return 0;
430
- };
598
+ }
431
599
  }
432
- //----------------------
600
+
433
601
  //----------------------RENAME
434
- static VALUE unsafe_rename(VALUE *args){
435
- VALUE *values=(VALUE*)args;
436
- VALUE path = values[0];
437
- VALUE as = values[1];
602
+
603
+ static VALUE unsafe_rename(VALUE *args)
604
+ {
605
+ VALUE path = args[0];
606
+ VALUE as = args[1];
607
+
438
608
  struct fuse_context *ctx=fuse_get_context();
609
+
439
610
  return rb_funcall(fuse_object,rb_intern("rename"),3,wrap_context(ctx),path,as);
440
611
  }
441
612
 
@@ -447,19 +618,26 @@ static int rf_rename(const char *path,const char *as)
447
618
  args[0]=rb_str_new2(path);
448
619
  args[1]=rb_str_new2(as);
449
620
  res=rb_protect((VALUE (*)())unsafe_rename,(VALUE) args,&error);
450
- if (error) {
621
+
622
+ if (error)
623
+ {
451
624
  return -(return_error(ENOENT));
452
- } else {
625
+ }
626
+ else
627
+ {
453
628
  return 0;
454
- };
629
+ }
455
630
  }
456
- //----------------------
631
+
457
632
  //----------------------LINK
458
- static VALUE unsafe_link(VALUE *args){
459
- VALUE *values=(VALUE*)args;
460
- VALUE path = values[0];
461
- VALUE as = values[1];
633
+
634
+ static VALUE unsafe_link(VALUE *args)
635
+ {
636
+ VALUE path = args[0];
637
+ VALUE as = args[1];
638
+
462
639
  struct fuse_context *ctx=fuse_get_context();
640
+
463
641
  return rb_funcall(fuse_object,rb_intern("link"),3,wrap_context(ctx),path,as);
464
642
  }
465
643
 
@@ -471,21 +649,28 @@ static int rf_link(const char *path,const char * as)
471
649
  args[0]=rb_str_new2(path);
472
650
  args[1]=rb_str_new2(as);
473
651
  res=rb_protect((VALUE (*)())unsafe_link,(VALUE) args,&error);
474
- if (error) {
652
+
653
+ if (error)
654
+ {
475
655
  return -(return_error(ENOENT));
476
- } else {
656
+ }
657
+ else
658
+ {
477
659
  return 0;
478
- };
660
+ }
479
661
  }
480
- //----------------------
662
+
481
663
  //----------------------READ
482
- static VALUE unsafe_read(VALUE *args){
483
- VALUE *values=(VALUE*)args;
484
- VALUE path = values[0];
485
- VALUE size = values[1];
486
- VALUE offset = values[2];
487
- VALUE ffi = values[3];
664
+
665
+ static VALUE unsafe_read(VALUE *args)
666
+ {
667
+ VALUE path = args[0];
668
+ VALUE size = args[1];
669
+ VALUE offset = args[2];
670
+ VALUE ffi = args[3];
671
+
488
672
  struct fuse_context *ctx=fuse_get_context();
673
+
489
674
  return rb_funcall(fuse_object,rb_intern("read"),5,
490
675
  wrap_context(ctx),path,size,offset,ffi);
491
676
  }
@@ -497,66 +682,94 @@ static int rf_read(const char *path,char * buf, size_t size,off_t offset,struct
497
682
  int error = 0;
498
683
  long length=0;
499
684
  char* rbuf;
685
+
500
686
  args[0]=rb_str_new2(path);
501
687
  args[1]=INT2NUM(size);
502
688
  args[2]=INT2NUM(offset);
503
689
  args[3]=wrap_file_info(ffi);
690
+
504
691
  res=rb_protect((VALUE (*)())unsafe_read,(VALUE) args,&error);
505
- if (error) {
692
+
693
+ if (error)
694
+ {
506
695
  return -(return_error(ENOENT));
507
- } else {
508
- rbuf=rb_str2cstr(res,&length); //TODO protect this, too
509
- if (length<=size) {
696
+ }
697
+ else
698
+ {
699
+ length = NUM2LONG(rb_funcall(res, rb_intern("length"), 0));
700
+ rbuf = rb_str2cstr(res, &length);
701
+ if (length<=size)
702
+ {
510
703
  memcpy(buf,rbuf,length);
511
704
  return length;
512
- } else {
513
- memcpy(buf,rbuf,size); //TODO: This could be dangerous.
514
- //Perhaps raise an exception or return an error
515
- return size;
516
705
  }
517
- };
706
+ else
707
+ {
708
+ //This cannot happen => IO error.
709
+ return -(return_error(ENOENT));
710
+ }
711
+ }
518
712
  }
519
- //----------------------
713
+
520
714
  //----------------------WRITE
521
- static VALUE unsafe_write(VALUE *args){
522
- VALUE *values=(VALUE*)args;
523
- VALUE path = values[0];
524
- VALUE buffer = values[1];
525
- VALUE size = values[2];
526
- VALUE offset = values[3];
527
- VALUE ffi = values[4];
715
+
716
+ static VALUE unsafe_write(VALUE *args)
717
+ {
718
+ VALUE path = args[0];
719
+ VALUE buffer = args[1];
720
+ VALUE offset = args[2];
721
+ VALUE ffi = args[3];
722
+
528
723
  struct fuse_context *ctx=fuse_get_context();
529
- return rb_funcall(fuse_object,rb_intern("write"),6,
530
- wrap_context(ctx),path,buffer,size,offset,ffi);
724
+
725
+ return rb_funcall(fuse_object,rb_intern("write"),5,
726
+ wrap_context(ctx),path,buffer,offset,ffi);
531
727
  }
532
728
 
533
- static int rf_write(const char *path,const char *buf,size_t size, off_t offset,struct fuse_file_info *ffi)
729
+ static int rf_write(const char *path,const char *buf,size_t size,
730
+ off_t offset,struct fuse_file_info *ffi)
534
731
  {
535
- VALUE args[5];
732
+ VALUE args[4];
536
733
  VALUE res;
537
734
  int error = 0;
735
+
538
736
  args[0]=rb_str_new2(path);
539
- args[1]=rb_str_new2(buf);
540
- args[2]=INT2NUM(size);
541
- args[3]=INT2NUM(offset);
542
- args[4]=wrap_file_info(ffi);
543
- res=rb_protect((VALUE (*)())unsafe_write,(VALUE) args,&error);
544
- if (error) {
737
+ args[1]=rb_str_new(buf, size);
738
+ args[2]=INT2NUM(offset);
739
+ args[3]=wrap_file_info(ffi);
740
+
741
+ res = rb_protect((VALUE (*)())unsafe_write,(VALUE) args, &error);
742
+
743
+ if (error)
744
+ {
545
745
  return -(return_error(ENOENT));
546
- } else {
547
- return 0;
548
- };
746
+ }
747
+ else
748
+ {
749
+ return NUM2INT(res);
750
+ }
751
+ }
752
+
753
+ //----------------------STATFS
754
+ static int rf_statfs(const char * path, struct statvfs * vfsinfo)
755
+ {
756
+ // TODO
757
+ return 0;
549
758
  }
550
- //----------------------
759
+
551
760
  //----------------------SETXATTR
552
- static VALUE unsafe_setxattr(VALUE *args){
553
- VALUE *values=(VALUE*)args;
554
- VALUE path = values[0];
555
- VALUE name = values[1];
556
- VALUE value = values[2];
557
- VALUE size = values[3];
558
- VALUE flags = values[4];
761
+
762
+ static VALUE unsafe_setxattr(VALUE *args)
763
+ {
764
+
765
+ VALUE path = args[0];
766
+ VALUE name = args[1];
767
+ VALUE value = args[2];
768
+ VALUE size = args[3];
769
+ VALUE flags = args[4];
770
+
559
771
  struct fuse_context *ctx=fuse_get_context();
772
+
560
773
  return rb_funcall(fuse_object,rb_intern("setxattr"),6,
561
774
  wrap_context(ctx),path,name,value,size,flags);
562
775
  }
@@ -567,26 +780,35 @@ static int rf_setxattr(const char *path,const char *name,
567
780
  VALUE args[5];
568
781
  VALUE res;
569
782
  int error = 0;
783
+
570
784
  args[0]=rb_str_new2(path);
571
785
  args[1]=rb_str_new2(name);
572
786
  args[2]=rb_str_new(value,size);
573
787
  args[3]=INT2NUM(size); //TODO:FIX would be faster
574
788
  args[4]=INT2NUM(flags);
789
+
575
790
  res=rb_protect((VALUE (*)())unsafe_setxattr,(VALUE) args,&error);
576
- if (error) {
791
+
792
+ if (error)
793
+ {
577
794
  return -(return_error(ENOENT));
578
- } else {
795
+ }
796
+ else
797
+ {
579
798
  return 0;
580
- };
799
+ }
581
800
  }
582
- //----------------------
801
+
583
802
  //----------------------GETXATTR
584
- static VALUE unsafe_getxattr(VALUE *args){
585
- VALUE *values=(VALUE*)args;
586
- VALUE path = values[0];
587
- VALUE name = values[1];
588
- VALUE size = values[2];
803
+
804
+ static VALUE unsafe_getxattr(VALUE *args)
805
+ {
806
+ VALUE path = args[0];
807
+ VALUE name = args[1];
808
+ VALUE size = args[2];
809
+
589
810
  struct fuse_context *ctx=fuse_get_context();
811
+
590
812
  return rb_funcall(fuse_object,rb_intern("getxattr"),4,
591
813
  wrap_context(ctx),path,name,size);
592
814
  }
@@ -603,24 +825,32 @@ static int rf_getxattr(const char *path,const char *name,char *buf,
603
825
  args[1]=rb_str_new2(name);
604
826
  args[2]=INT2NUM(size);
605
827
  res=rb_protect((VALUE (*)())unsafe_getxattr,(VALUE) args,&error);
606
- if (error) {
828
+
829
+ if (error)
830
+ {
607
831
  return -(return_error(ENOENT));
608
- } else {
832
+ }
833
+ else
834
+ {
609
835
  rbuf=rb_str2cstr(res,&length); //TODO protect this, too
610
- if (buf != NULL) {
836
+ if (buf != NULL)
837
+ {
611
838
  memcpy(buf,rbuf,length); //First call is just to get the length
612
839
  //TODO optimize
613
840
  }
614
841
  return length;
615
842
  }
616
843
  }
617
- //----------------------
844
+
618
845
  //----------------------LISTXATTR
619
- static VALUE unsafe_listxattr(VALUE *args){
620
- VALUE *values=(VALUE*)args;
621
- VALUE path = values[0];
622
- VALUE size = values[1];
846
+
847
+ static VALUE unsafe_listxattr(VALUE *args)
848
+ {
849
+ VALUE path = args[0];
850
+ VALUE size = args[1];
851
+
623
852
  struct fuse_context *ctx=fuse_get_context();
853
+
624
854
  return rb_funcall(fuse_object,rb_intern("listxattr"),3,
625
855
  wrap_context(ctx),path,size);
626
856
  }
@@ -636,33 +866,44 @@ static int rf_listxattr(const char *path,char *buf,
636
866
  args[0]=rb_str_new2(path);
637
867
  args[1]=INT2NUM(size);
638
868
  res=rb_protect((VALUE (*)())unsafe_listxattr,(VALUE) args,&error);
639
- if (error) {
869
+
870
+ if (error)
871
+ {
640
872
  return -(return_error(ENOENT));
641
- } else {
873
+ }
874
+ else
875
+ {
642
876
  rbuf=rb_str2cstr(res,(long *)&length); //TODO protect this, too
643
- if (buf != NULL){
644
- if (length<=size) {
645
- memcpy(buf,rbuf,length); //check for size
877
+ if (buf != NULL)
878
+ {
879
+ if (length<=size)
880
+ {
881
+ memcpy(buf,rbuf,length); //check for size
646
882
  } else {
647
- return -ERANGE;
883
+ return -ERANGE;
648
884
  }
649
885
  printf("destination: %s,%d\n",buf,size);
650
886
  printf("source: %s,%d\n",rbuf,length);
651
887
  return length;
652
888
  //TODO optimize,check lenght
653
- } else {
889
+ }
890
+ else
891
+ {
654
892
  printf ("not copied: %s, %d\n",buf,length);
655
893
  return length;
656
894
  }
657
895
  }
658
896
  }
659
- //----------------------
897
+
660
898
  //----------------------REMOVEXATTR
661
- static VALUE unsafe_removexattr(VALUE *args){
662
- VALUE *values=(VALUE*)args;
663
- VALUE path = values[0];
664
- VALUE name = values[1];
899
+
900
+ static VALUE unsafe_removexattr(VALUE *args)
901
+ {
902
+ VALUE path = args[0];
903
+ VALUE name = args[1];
904
+
665
905
  struct fuse_context *ctx=fuse_get_context();
906
+
666
907
  return rb_funcall(fuse_object,rb_intern("removexattr"),3,
667
908
  wrap_context(ctx),path,name);
668
909
  }
@@ -675,19 +916,26 @@ static int rf_removexattr(const char *path,const char *name)
675
916
  args[0]=rb_str_new2(path);
676
917
  args[1]=rb_str_new2(name);
677
918
  res=rb_protect((VALUE (*)())unsafe_removexattr,(VALUE) args,&error);
678
- if (error) {
919
+
920
+ if (error)
921
+ {
679
922
  return -(return_error(ENOENT));
680
- } else {
923
+ }
924
+ else
925
+ {
681
926
  return 0;
682
- };
927
+ }
683
928
  }
684
- //----------------------
929
+
685
930
  //----------------------OPENDIR
686
- static VALUE unsafe_opendir(VALUE *args){
687
- VALUE *values=(VALUE*)args;
688
- VALUE path = values[0];
689
- VALUE ffi = values[1];
931
+
932
+ static VALUE unsafe_opendir(VALUE *args)
933
+ {
934
+ VALUE path = args[0];
935
+ VALUE ffi = args[1];
936
+
690
937
  struct fuse_context *ctx=fuse_get_context();
938
+
691
939
  return rb_funcall(fuse_object,rb_intern("opendir"),3,wrap_context(ctx),path,ffi);
692
940
  }
693
941
 
@@ -699,19 +947,26 @@ static int rf_opendir(const char *path,struct fuse_file_info *ffi)
699
947
  args[0]=rb_str_new2(path);
700
948
  args[1]=wrap_file_info(ffi);
701
949
  res=rb_protect((VALUE (*)())unsafe_opendir,(VALUE) args,&error);
702
- if (error) {
950
+
951
+ if (error)
952
+ {
703
953
  return -(return_error(ENOENT));
704
- } else {
954
+ }
955
+ else
956
+ {
705
957
  return 0;
706
- };
958
+ }
707
959
  }
708
- //----------------------
960
+
709
961
  //----------------------RELEASEDIR
710
- static VALUE unsafe_releasedir(VALUE *args){
711
- VALUE *values=(VALUE*)args;
712
- VALUE path = values[0];
713
- VALUE ffi = values[1];
962
+
963
+ static VALUE unsafe_releasedir(VALUE *args)
964
+ {
965
+ VALUE path = args[0];
966
+ VALUE ffi = args[1];
967
+
714
968
  struct fuse_context *ctx=fuse_get_context();
969
+
715
970
  return rb_funcall(fuse_object,rb_intern("releasedir"),3,wrap_context(ctx),path,ffi);
716
971
  }
717
972
 
@@ -723,20 +978,27 @@ static int rf_releasedir(const char *path,struct fuse_file_info *ffi)
723
978
  args[0]=rb_str_new2(path);
724
979
  args[1]=wrap_file_info(ffi);
725
980
  res=rb_protect((VALUE (*)())unsafe_releasedir,(VALUE) args,&error);
726
- if (error) {
981
+
982
+ if (error)
983
+ {
727
984
  return -(return_error(ENOENT));
728
- } else {
985
+ }
986
+ else
987
+ {
729
988
  return 0;
730
- };
989
+ }
731
990
  }
732
- //----------------------
991
+
733
992
  //----------------------FSYNCDIR
734
- static VALUE unsafe_fsyncdir(VALUE *args){
735
- VALUE *values=(VALUE*)args;
736
- VALUE path = values[0];
737
- VALUE meta = values[1];
738
- VALUE ffi = values[2];
993
+
994
+ static VALUE unsafe_fsyncdir(VALUE *args)
995
+ {
996
+ VALUE path = args[0];
997
+ VALUE meta = args[1];
998
+ VALUE ffi = args[2];
999
+
739
1000
  struct fuse_context *ctx=fuse_get_context();
1001
+
740
1002
  return rb_funcall(fuse_object,rb_intern("fsyncdir"),3,wrap_context(ctx),path,
741
1003
  meta,ffi);
742
1004
  }
@@ -750,78 +1012,221 @@ static int rf_fsyncdir(const char *path,int meta,struct fuse_file_info *ffi)
750
1012
  args[1]=INT2NUM(meta);
751
1013
  args[2]=wrap_file_info(ffi);
752
1014
  res=rb_protect((VALUE (*)())unsafe_fsyncdir,(VALUE) args,&error);
753
- if (error) {
1015
+
1016
+ if (error)
1017
+ {
754
1018
  return -(return_error(ENOENT));
755
- } else {
1019
+ }
1020
+ else
1021
+ {
1022
+ return 0;
1023
+ }
1024
+ }
1025
+
1026
+ //----------------------INIT
1027
+
1028
+ static void *rf_init(struct fuse_conn_info *conn)
1029
+ {
1030
+ // TODO
1031
+ return NULL;
1032
+ }
1033
+
1034
+ //----------------------DESTROY
1035
+
1036
+ static void rf_destroy(void *user_data)
1037
+ {
1038
+ // TODO
1039
+ }
1040
+
1041
+ //----------------------ACCESS
1042
+
1043
+ static int rf_access(const char *path, int mask)
1044
+ {
1045
+ // TODO
1046
+ return 0;
1047
+ }
1048
+
1049
+ //----------------------CREATE
1050
+
1051
+ static int rf_create(const char *path, mode_t mode,
1052
+ struct fuse_file_info *ffi)
1053
+ {
1054
+ // TODO
1055
+ return 0;
1056
+ }
1057
+
1058
+ //----------------------FTRUNCATE
1059
+
1060
+ static int rf_ftruncate(const char *path, off_t size,
1061
+ struct fuse_file_info *ffi)
1062
+ {
1063
+ // TODO
1064
+ return 0;
1065
+ }
1066
+
1067
+ //----------------------FGETATTR
1068
+
1069
+ static int rf_fgetattr(const char *path, struct stat *stbuf,
1070
+ struct fuse_file_info *ffi)
1071
+ {
1072
+ // TODO
1073
+ return 0;
1074
+ }
1075
+
1076
+ //----------------------LOCK
1077
+
1078
+ static int rf_lock(const char *path, struct fuse_file_info *ffi,
1079
+ int cmd, struct flock *lock)
1080
+ {
1081
+ // TODO
1082
+ return 0;
1083
+ }
1084
+
1085
+ //----------------------UTIMENS
1086
+
1087
+ static VALUE unsafe_utimens(VALUE *args)
1088
+ {
1089
+ VALUE path = args[0];
1090
+ VALUE actime = args[1];
1091
+ VALUE modtime = args[2];
1092
+
1093
+ struct fuse_context *ctx=fuse_get_context();
1094
+
1095
+ return rb_funcall(
1096
+ fuse_object,
1097
+ rb_intern("utimens"),
1098
+ 4,
1099
+ wrap_context(ctx),
1100
+ path,actime,modtime
1101
+ );
1102
+ }
1103
+
1104
+ static int rf_utimens(const char * path, const struct timespec tv[2])
1105
+ {
1106
+ VALUE args[3];
1107
+ VALUE res;
1108
+ int error = 0;
1109
+
1110
+ args[0] = rb_str_new2(path);
1111
+
1112
+ // tv_sec * 1000000 + tv_nsec
1113
+ args[1] = rb_funcall(
1114
+ rb_funcall(
1115
+ INT2NUM(tv[0].tv_sec), rb_intern("*"), 1, INT2NUM(1000000)
1116
+ ),
1117
+ rb_intern("+"), 1, INT2NUM(tv[0].tv_nsec)
1118
+ );
1119
+
1120
+ args[2] = rb_funcall(
1121
+ rb_funcall(
1122
+ INT2NUM(tv[1].tv_sec), rb_intern("*"), 1, INT2NUM(1000000)
1123
+ ),
1124
+ rb_intern("+"), 1, INT2NUM(tv[1].tv_nsec)
1125
+ );
1126
+
1127
+ res = rb_protect((VALUE (*)())unsafe_utimens,(VALUE) args, &error);
1128
+
1129
+ if (error)
1130
+ {
1131
+ return -(return_error(ENOENT));
1132
+ }
1133
+ else
1134
+ {
756
1135
  return 0;
757
- };
1136
+ }
1137
+ }
1138
+
1139
+ //----------------------BMAP
1140
+
1141
+ static int rf_bmap(const char *path, size_t blocksize, uint64_t *idx)
1142
+ {
1143
+ //TODO
1144
+ return 0;
1145
+ }
1146
+
1147
+ //----------------------IOCTL
1148
+
1149
+ static int rf_ioctl(const char *path, int cmd, void *arg,
1150
+ struct fuse_file_info *ffi, unsigned int flags, void *data)
1151
+ {
1152
+ //TODO
1153
+ return 0;
1154
+ }
1155
+
1156
+ //----------------------POLL
1157
+
1158
+ static int rf_poll(const char *path, struct fuse_file_info *ffi,
1159
+ struct fuse_pollhandle *ph, unsigned *reventsp)
1160
+ {
1161
+ //TODO
1162
+ return 0;
758
1163
  }
759
- //----------------------
760
1164
 
761
- static VALUE rf_loop(VALUE self){
1165
+ //----------------------LOOP
1166
+
1167
+ static VALUE rf_loop(VALUE self)
1168
+ {
762
1169
  struct intern_fuse *inf;
763
1170
  Data_Get_Struct(self,struct intern_fuse,inf);
764
1171
  fuse_loop(inf->fuse);
765
1172
  return Qnil;
766
1173
  }
767
1174
 
768
- /*static VALUE rf_loop_mt(VALUE self){
1175
+ //----------------------LOOP_MT
1176
+
1177
+ static VALUE rf_loop_mt(VALUE self)
1178
+ {
769
1179
  struct intern_fuse *inf;
770
1180
  Data_Get_Struct(self,struct intern_fuse,inf);
771
1181
  fuse_loop_mt(inf->fuse);
772
1182
  return Qnil;
773
- }*/
1183
+ }
1184
+
1185
+ //----------------------EXIT
774
1186
 
775
- VALUE rf_exit(VALUE self){
1187
+ VALUE rf_exit(VALUE self)
1188
+ {
776
1189
  struct intern_fuse *inf;
777
1190
  Data_Get_Struct(self,struct intern_fuse,inf);
778
1191
  fuse_exit(inf->fuse);
779
1192
  return Qnil;
780
1193
  }
781
1194
 
782
- VALUE rf_unmount(VALUE self){
1195
+ //----------------------UNMOUNT
1196
+
1197
+ VALUE rf_unmount(VALUE self)
1198
+ {
783
1199
  struct intern_fuse *inf;
784
1200
  Data_Get_Struct(self,struct intern_fuse,inf);
785
1201
  fuse_unmount(inf->mountname, inf->fc);
786
1202
  return Qnil;
787
1203
  }
788
1204
 
789
- VALUE rf_mountname(VALUE self){
1205
+ //----------------------MOUNTNAME
1206
+
1207
+ VALUE rf_mountname(VALUE self)
1208
+ {
790
1209
  struct intern_fuse *inf;
791
1210
  Data_Get_Struct(self,struct intern_fuse,inf);
792
1211
  return rb_str_new2(inf->mountname);
793
1212
  }
794
- VALUE rf_invalidate(VALUE self,VALUE path){
1213
+
1214
+ //----------------------INVALIDATE
1215
+
1216
+ VALUE rf_invalidate(VALUE self,VALUE path)
1217
+ {
795
1218
  struct intern_fuse *inf;
796
1219
  Data_Get_Struct(self,struct intern_fuse,inf);
797
1220
  return fuse_invalidate(inf->fuse,STR2CSTR(path)); //TODO: check if str?
798
1221
  }
799
- //-------------RUBY
800
1222
 
1223
+ #define RESPOND_TO(obj,methodname) \
1224
+ rb_funcall( \
1225
+ obj,rb_intern("respond_to?"), \
1226
+ 1, rb_str_new2(methodname) \
1227
+ ) == Qtrue
801
1228
 
802
- static struct fuse_args * rarray2fuseargs(VALUE rarray){
803
-
804
- Check_Type(rarray, T_ARRAY);
805
-
806
- struct fuse_args *args = malloc(sizeof(struct fuse_args));
807
-
808
- args->argc = RARRAY(rarray)->len;
809
- args->argv = malloc(args->argc * sizeof(char *) + 1);
810
- /* Nope, this isn't really 'allocated'. The elements
811
- * of this array shouldn't be freed */
812
- args->allocated = 0;
813
-
814
- int i;
815
- VALUE v;
816
- for(i = 0; i < args->argc; i++) {
817
- v = RARRAY(rarray)->ptr[i];
818
- Check_Type(v, T_STRING);
819
- args->argv[i] = STR2CSTR(RSTRING(v));
820
- }
821
- args->argv[args->argc] = NULL;
822
-
823
- return args;
824
- }
1229
+ //-------------RUBY
825
1230
 
826
1231
  static VALUE rf_initialize(
827
1232
  VALUE self,
@@ -830,61 +1235,106 @@ static VALUE rf_initialize(
830
1235
  VALUE libopts)
831
1236
  {
832
1237
  Check_Type(mountpoint, T_STRING);
833
-
1238
+
1239
+ // getdir is deprecated, use readdir instead
1240
+
834
1241
  struct intern_fuse *inf;
835
1242
  Data_Get_Struct(self,struct intern_fuse,inf);
836
- inf->fuse_op.getattr = rf_getattr;
837
- inf->fuse_op.readlink = rf_readlink;
838
- inf->fuse_op.mknod = rf_mknod;
839
- inf->fuse_op.mkdir = rf_mkdir;
840
- inf->fuse_op.unlink = rf_unlink;
841
- inf->fuse_op.rmdir = rf_rmdir;
842
- inf->fuse_op.symlink = rf_symlink;
843
- inf->fuse_op.rename = rf_rename;
844
- inf->fuse_op.link = rf_link;
845
- inf->fuse_op.chmod = rf_chmod;
846
- inf->fuse_op.chown = rf_chown;
847
- inf->fuse_op.truncate = rf_truncate;
848
- inf->fuse_op.utime = rf_utime; // Deprecated, use utimens instead
849
- inf->fuse_op.open = rf_open;
850
- inf->fuse_op.read = rf_read;
851
- inf->fuse_op.write = rf_write;
852
- //inf->fuse_op.statfs = rf_statfs; // TODO
853
- inf->fuse_op.flush = rf_flush;
854
- inf->fuse_op.release = rf_release;
855
- //inf->fuse_op.fsnyc = rf_fsync; // TODO
856
- inf->fuse_op.setxattr = rf_setxattr;
857
- inf->fuse_op.getxattr = rf_getxattr;
858
- inf->fuse_op.listxattr = rf_listxattr;
859
- inf->fuse_op.removexattr = rf_removexattr;
860
- inf->fuse_op.opendir = rf_opendir;
861
- inf->fuse_op.readdir = rf_readdir;
862
- inf->fuse_op.releasedir = rf_releasedir;
863
- inf->fuse_op.fsyncdir = rf_fsyncdir;
864
- //inf->fuse_op.init = rf_init;
865
- //inf->fuse_op.destroy = rf_destroy;
866
- //inf->fuse_op.access = rf_access;
867
- //inf->fuse_op.create = rf_create;
868
- //inf->fuse_op.ftruncate = rf_ftruncate;
869
- //inf->fuse_op.fgetattr = rf_fgetattr;
870
- //inf->fuse_op.lock = rf_lock;
871
- //inf->fuse_op.utimens = rf_utimens;
872
- //inf->fuse_op.bmap = rf_bmap;
873
- //inf->fuse_op.ioctl = rf_ioctl;
874
- //inf->fuse_op.poll = rf_poll;
1243
+ if (RESPOND_TO(self,"getattr"))
1244
+ inf->fuse_op.getattr = rf_getattr;
1245
+ if (RESPOND_TO(self,"readlink"))
1246
+ inf->fuse_op.readlink = rf_readlink;
1247
+ if (RESPOND_TO(self,"getdir"))
1248
+ inf->fuse_op.getdir = rf_getdir; // Deprecated
1249
+ if (RESPOND_TO(self,"mknod"))
1250
+ inf->fuse_op.mknod = rf_mknod;
1251
+ if (RESPOND_TO(self,"mkdir"))
1252
+ inf->fuse_op.mkdir = rf_mkdir;
1253
+ if (RESPOND_TO(self,"unlink"))
1254
+ inf->fuse_op.unlink = rf_unlink;
1255
+ if (RESPOND_TO(self,"rmdir"))
1256
+ inf->fuse_op.rmdir = rf_rmdir;
1257
+ if (RESPOND_TO(self,"symlink"))
1258
+ inf->fuse_op.symlink = rf_symlink;
1259
+ if (RESPOND_TO(self,"rename"))
1260
+ inf->fuse_op.rename = rf_rename;
1261
+ if (RESPOND_TO(self,"link"))
1262
+ inf->fuse_op.link = rf_link;
1263
+ if (RESPOND_TO(self,"chmod"))
1264
+ inf->fuse_op.chmod = rf_chmod;
1265
+ if (RESPOND_TO(self,"chown"))
1266
+ inf->fuse_op.chown = rf_chown;
1267
+ if (RESPOND_TO(self,"truncate"))
1268
+ inf->fuse_op.truncate = rf_truncate;
1269
+ if (RESPOND_TO(self,"utime"))
1270
+ inf->fuse_op.utime = rf_utime; // Deprecated
1271
+ if (RESPOND_TO(self,"open"))
1272
+ inf->fuse_op.open = rf_open;
1273
+ if (RESPOND_TO(self,"read"))
1274
+ inf->fuse_op.read = rf_read;
1275
+ if (RESPOND_TO(self,"write"))
1276
+ inf->fuse_op.write = rf_write;
1277
+ if (RESPOND_TO(self,"statfs"))
1278
+ inf->fuse_op.statfs = rf_statfs; //TODO
1279
+ if (RESPOND_TO(self,"flush"))
1280
+ inf->fuse_op.flush = rf_flush;
1281
+ if (RESPOND_TO(self,"release"))
1282
+ inf->fuse_op.release = rf_release;
1283
+ if (RESPOND_TO(self,"fsync"))
1284
+ inf->fuse_op.fsync = rf_fsync; // TODO
1285
+ if (RESPOND_TO(self,"setxattr"))
1286
+ inf->fuse_op.setxattr = rf_setxattr;
1287
+ if (RESPOND_TO(self,"getxattr"))
1288
+ inf->fuse_op.getxattr = rf_getxattr;
1289
+ if (RESPOND_TO(self,"listxattr"))
1290
+ inf->fuse_op.listxattr = rf_listxattr;
1291
+ if (RESPOND_TO(self,"removexattr"))
1292
+ inf->fuse_op.removexattr = rf_removexattr;
1293
+ if (RESPOND_TO(self,"opendir"))
1294
+ inf->fuse_op.opendir = rf_opendir;
1295
+ if (RESPOND_TO(self,"readdir"))
1296
+ inf->fuse_op.readdir = rf_readdir;
1297
+ if (RESPOND_TO(self,"releasedir"))
1298
+ inf->fuse_op.releasedir = rf_releasedir;
1299
+ if (RESPOND_TO(self,"fsyncdir"))
1300
+ inf->fuse_op.fsyncdir = rf_fsyncdir;
1301
+ if (RESPOND_TO(self,"init"))
1302
+ inf->fuse_op.init = rf_init; // TODO
1303
+ if (RESPOND_TO(self,"destroy"))
1304
+ inf->fuse_op.destroy = rf_destroy; // TODO
1305
+ if (RESPOND_TO(self,"access"))
1306
+ inf->fuse_op.access = rf_access; // TODO
1307
+ if (RESPOND_TO(self,"create"))
1308
+ inf->fuse_op.create = rf_create; // TODO
1309
+ if (RESPOND_TO(self,"ftruncate"))
1310
+ inf->fuse_op.ftruncate = rf_ftruncate; // TODO
1311
+ if (RESPOND_TO(self,"fgetattr"))
1312
+ inf->fuse_op.fgetattr = rf_fgetattr; // TODO
1313
+ if (RESPOND_TO(self,"lock"))
1314
+ inf->fuse_op.lock = rf_lock; // TODO
1315
+ if (RESPOND_TO(self,"utimens"))
1316
+ inf->fuse_op.utimens = rf_utimens;
1317
+ if (RESPOND_TO(self,"bmap"))
1318
+ inf->fuse_op.bmap = rf_bmap; // TODO
1319
+ if (RESPOND_TO(self,"ioctl"))
1320
+ inf->fuse_op.ioctl = rf_ioctl; // TODO
1321
+ if (RESPOND_TO(self,"poll"))
1322
+ inf->fuse_op.poll = rf_poll; // TODO
875
1323
 
876
1324
  struct fuse_args
877
1325
  *kargs = rarray2fuseargs(kernelopts),
878
1326
  *largs = rarray2fuseargs(libopts);
879
1327
 
880
1328
  intern_fuse_init(inf, STR2CSTR(mountpoint), kargs, largs);
881
-
882
- fuse_object=self; // this won't work with multithreading!!!
1329
+
1330
+ //TODO this won't work with multithreading!!!
1331
+ fuse_object=self;
883
1332
 
884
1333
  return self;
885
1334
  }
886
1335
 
887
- static VALUE rf_new(VALUE class){
1336
+ static VALUE rf_new(VALUE class)
1337
+ {
888
1338
  struct intern_fuse *inf;
889
1339
  VALUE self;
890
1340
  inf = intern_fuse_new();
@@ -892,16 +1342,19 @@ static VALUE rf_new(VALUE class){
892
1342
  return self;
893
1343
  }
894
1344
 
895
- VALUE rfuse_init(VALUE module){
1345
+ VALUE rfuse_init(VALUE module)
1346
+ {
896
1347
  VALUE cFuse=rb_define_class_under(module,"Fuse",rb_cObject);
1348
+
897
1349
  rb_define_alloc_func(cFuse,rf_new);
898
- //initialize: string mountpoint,array kernel_opts,array lib_opts
1350
+
899
1351
  rb_define_method(cFuse,"initialize",rf_initialize,3);
900
1352
  rb_define_method(cFuse,"loop",rf_loop,0);
901
- //rb_define_method(cFuse,"loop_mt",rf_loop_mt,0); TODO: not until RIKE!
1353
+ rb_define_method(cFuse,"loop_mt",rf_loop_mt,0); //TODO: not until RIKE!
902
1354
  rb_define_method(cFuse,"exit",rf_exit,0);
903
1355
  rb_define_method(cFuse,"invalidate",rf_invalidate,1);
904
1356
  rb_define_method(cFuse,"unmount",rf_unmount,0);
905
1357
  rb_define_method(cFuse,"mountname",rf_mountname,0);
1358
+
906
1359
  return cFuse;
907
1360
  }