rfuse 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/ext/rfuse/rfuse.c CHANGED
@@ -10,9 +10,9 @@
10
10
  #include <fuse.h>
11
11
  #include <errno.h>
12
12
  #include <sys/statfs.h>
13
- //#ifdef HAVE_SETXATTR
13
+ #ifdef HAVE_SETXATTR
14
14
  #include <sys/xattr.h>
15
- //#endif
15
+ #endif
16
16
 
17
17
  #include "helper.h"
18
18
  #include "intern_rfuse.h"
@@ -23,6 +23,7 @@
23
23
  #include "pollhandle.h"
24
24
  #include "bufferwrapper.h"
25
25
 
26
+ // Ruby 1.8 compatibility
26
27
  #ifdef HAVE_RUBY_ENCODING_H
27
28
  #include <ruby/encoding.h>
28
29
  #endif
@@ -34,9 +35,6 @@ static VALUE rb_errinfo()
34
35
  }
35
36
  #endif
36
37
 
37
- static VALUE mRFuse;
38
- static VALUE eRFuse_Error;
39
-
40
38
  static VALUE rb_filesystem_encode(VALUE str)
41
39
  {
42
40
  #ifdef HAVE_RUBY_ENCODING_H
@@ -45,6 +43,10 @@ static VALUE rb_filesystem_encode(VALUE str)
45
43
  return str;
46
44
  #endif
47
45
  }
46
+ //end 1.8 compat
47
+
48
+ static VALUE mRFuse;
49
+ static VALUE eRFuse_Error;
48
50
 
49
51
  static int unsafe_return_error(VALUE *args)
50
52
  {
@@ -54,13 +56,16 @@ static int unsafe_return_error(VALUE *args)
54
56
  return rb_funcall(rb_errinfo(),rb_intern("errno"),0);
55
57
  } else {
56
58
  VALUE info;
59
+ VALUE bt_ary;
60
+ int c;
61
+
57
62
  info = rb_inspect(rb_errinfo());
58
- printf ("ERROR: Exception %s not an Errno:: !respond_to?(:errno) \n",STR2CSTR(info));
63
+ printf ("ERROR: Exception %s not an Errno:: !respond_to?(:errno) \n",StringValueCStr(info));
59
64
  //We need the ruby_errinfo backtrace not fuse.loop ... rb_backtrace();
60
- VALUE bt_ary = rb_funcall(rb_errinfo(), rb_intern("backtrace"),0);
61
- int c;
65
+ bt_ary = rb_funcall(rb_errinfo(), rb_intern("backtrace"),0);
66
+
62
67
  for (c=0;c<RARRAY_LEN(bt_ary);c++) {
63
- printf("%s\n",RSTRING_PTR(RARRAY_PTR(bt_ary)[c]));
68
+ printf("%s\n",StringValueCStr(RARRAY_PTR(bt_ary)[c]));
64
69
  }
65
70
  return Qnil;
66
71
  }
@@ -88,7 +93,7 @@ static int return_error(int def_error)
88
93
  //Every call needs this stuff
89
94
  static void init_context_path_args(VALUE *args,struct fuse_context *ctx,const char *path)
90
95
  {
91
- args[0] = ctx->private_data;
96
+ args[0] = (VALUE) ctx->private_data;
92
97
  args[1] = wrap_context(ctx);
93
98
  args[2] = rb_str_new2(path);
94
99
  rb_filesystem_encode(args[2]);
@@ -107,6 +112,7 @@ static void init_context_path_args(VALUE *args,struct fuse_context *ctx,const ch
107
112
 
108
113
  @return [void]
109
114
  @raise [Errno]
115
+ @todo the API for the filler could be more ruby like - eg yield
110
116
  */
111
117
  static VALUE unsafe_readdir(VALUE *args)
112
118
  {
@@ -121,7 +127,6 @@ static int rf_readdir(const char *path, void *buf,
121
127
  VALUE rfiller_instance;
122
128
  struct filler_t *fillerc;
123
129
  VALUE args[6];
124
- VALUE res;
125
130
  int error = 0;
126
131
 
127
132
  struct fuse_context *ctx=fuse_get_context();
@@ -133,13 +138,13 @@ static int rf_readdir(const char *path, void *buf,
133
138
  rfiller_instance=rb_funcall(rfiller_class,rb_intern("new"),0);
134
139
  Data_Get_Struct(rfiller_instance,struct filler_t,fillerc);
135
140
 
136
- fillerc->filler=filler;//Init the filler by hand.... TODO: cleaner
141
+ fillerc->filler=filler;
137
142
  fillerc->buffer=buf;
138
143
  args[3]=rfiller_instance;
139
144
  args[4]=INT2NUM(offset);
140
145
  args[5]=get_file_info(ffi);
141
146
 
142
- res=rb_protect((VALUE (*)())unsafe_readdir,(VALUE)args,&error);
147
+ rb_protect((VALUE (*)())unsafe_readdir,(VALUE)args,&error);
143
148
  return error ? -(return_error(ENOENT)) : 0 ;
144
149
  }
145
150
 
@@ -164,12 +169,12 @@ static int rf_readlink(const char *path, char *buf, size_t size)
164
169
  VALUE args[4];
165
170
  VALUE res;
166
171
  int error = 0;
172
+ char *rbuf;
167
173
 
168
174
  struct fuse_context *ctx=fuse_get_context();
169
175
  init_context_path_args(args,ctx,path);
170
176
 
171
177
  args[3]=INT2NUM(size);
172
- char *rbuf;
173
178
  res=rb_protect((VALUE (*)())unsafe_readlink,(VALUE)args,&error);
174
179
  if (error)
175
180
  {
@@ -177,7 +182,7 @@ static int rf_readlink(const char *path, char *buf, size_t size)
177
182
  }
178
183
  else
179
184
  {
180
- rbuf=STR2CSTR(res);
185
+ rbuf=StringValueCStr(res);
181
186
  strncpy(buf,rbuf,size);
182
187
  return 0;
183
188
  }
@@ -199,7 +204,6 @@ static int rf_getdir(const char *path, fuse_dirh_t dh, fuse_dirfil_t df)
199
204
  VALUE rfiller_class;
200
205
  VALUE rfiller_instance;
201
206
  VALUE args[4];
202
- VALUE res;
203
207
  struct filler_t *fillerc;
204
208
  int error = 0;
205
209
 
@@ -218,7 +222,7 @@ static int rf_getdir(const char *path, fuse_dirh_t dh, fuse_dirfil_t df)
218
222
 
219
223
  args[3]=rfiller_instance;
220
224
 
221
- res = rb_protect((VALUE (*)())unsafe_getdir, (VALUE)args, &error);
225
+ rb_protect((VALUE (*)())unsafe_getdir, (VALUE)args, &error);
222
226
 
223
227
  return error ? -(return_error(ENOENT)) : 0 ;
224
228
  }
@@ -247,21 +251,20 @@ static VALUE unsafe_mknod(VALUE *args)
247
251
  static int rf_mknod(const char *path, mode_t mode,dev_t dev)
248
252
  {
249
253
  VALUE args[6];
250
- VALUE res;
251
254
  int error = 0;
252
255
  struct fuse_context *ctx=fuse_get_context();
253
- init_context_path_args(args,ctx,path);
254
-
255
256
  int major;
256
257
  int minor;
257
258
 
259
+ init_context_path_args(args,ctx,path);
260
+
258
261
  major = MAJOR(dev);
259
262
  minor = MINOR(dev);
260
263
 
261
264
  args[3]=INT2FIX(mode);
262
265
  args[4]=INT2FIX(major);
263
266
  args[5]=INT2FIX(minor);
264
- res=rb_protect((VALUE (*)())unsafe_mknod,(VALUE) args,&error);
267
+ rb_protect((VALUE (*)())unsafe_mknod,(VALUE) args,&error);
265
268
  return error ? -(return_error(ENOENT)) : 0 ;
266
269
  }
267
270
 
@@ -330,23 +333,15 @@ static VALUE unsafe_mkdir(VALUE *args)
330
333
  static int rf_mkdir(const char *path, mode_t mode)
331
334
  {
332
335
  VALUE args[4];
333
- VALUE res;
334
336
  int error = 0;
335
337
 
336
338
  struct fuse_context *ctx=fuse_get_context();
337
339
  init_context_path_args(args,ctx,path);
338
340
 
339
341
  args[3]=INT2FIX(mode);
340
- res=rb_protect((VALUE (*)())unsafe_mkdir,(VALUE) args,&error);
342
+ rb_protect((VALUE (*)())unsafe_mkdir,(VALUE) args,&error);
341
343
 
342
- if (error)
343
- {
344
- return -(return_error(ENOENT));
345
- }
346
- else
347
- {
348
- return 0;
349
- }
344
+ return error ? -(return_error(ENOENT)) : 0 ;
350
345
  }
351
346
 
352
347
  /*
@@ -373,7 +368,6 @@ static VALUE unsafe_open(VALUE *args)
373
368
  static int rf_open(const char *path,struct fuse_file_info *ffi)
374
369
  {
375
370
  VALUE args[4];
376
- VALUE res;
377
371
  int error = 0;
378
372
 
379
373
  struct fuse_context *ctx=fuse_get_context();
@@ -381,15 +375,9 @@ static int rf_open(const char *path,struct fuse_file_info *ffi)
381
375
 
382
376
  args[3]=wrap_file_info(ctx,ffi);
383
377
 
384
- res=rb_protect((VALUE (*)())unsafe_open,(VALUE) args,&error);
385
- if (error)
386
- {
387
- return -(return_error(ENOENT));
388
- }
389
- else
390
- {
391
- return 0;
392
- }
378
+ rb_protect((VALUE (*)())unsafe_open,(VALUE) args,&error);
379
+
380
+ return error ? -(return_error(ENOENT)) : 0;
393
381
  }
394
382
 
395
383
  //This method is registered as a default for release in the case when
@@ -401,6 +389,7 @@ static int rf_release_ffi(const char *path, struct fuse_file_info *ffi)
401
389
 
402
390
  release_file_info(ctx,ffi);
403
391
 
392
+ return 0;
404
393
  }
405
394
 
406
395
  /*
@@ -426,7 +415,6 @@ static VALUE unsafe_release(VALUE *args)
426
415
  static int rf_release(const char *path, struct fuse_file_info *ffi)
427
416
  {
428
417
  VALUE args[4];
429
- VALUE res;
430
418
  int error = 0;
431
419
 
432
420
  struct fuse_context *ctx=fuse_get_context();
@@ -434,16 +422,9 @@ static int rf_release(const char *path, struct fuse_file_info *ffi)
434
422
 
435
423
  args[3]=release_file_info(ctx,ffi);
436
424
 
437
- res=rb_protect((VALUE (*)())unsafe_release,(VALUE) args,&error);
438
-
439
- if (error)
440
- {
441
- return -(return_error(ENOENT));
442
- }
443
- else
444
- {
445
- return 0;
446
- }
425
+ rb_protect((VALUE (*)())unsafe_release,(VALUE) args,&error);
426
+
427
+ return error ? -(return_error(ENOENT)) : 0;
447
428
  }
448
429
 
449
430
  /*
@@ -467,7 +448,6 @@ static VALUE unsafe_fsync(VALUE *args) {
467
448
  static int rf_fsync(const char *path, int datasync, struct fuse_file_info *ffi)
468
449
  {
469
450
  VALUE args[5];
470
- VALUE res;
471
451
  int error = 0;
472
452
 
473
453
  struct fuse_context *ctx=fuse_get_context();
@@ -476,16 +456,9 @@ static int rf_fsync(const char *path, int datasync, struct fuse_file_info *ffi)
476
456
  args[3] = INT2NUM(datasync);
477
457
  args[4] = get_file_info(ffi);
478
458
 
479
- res = rb_protect((VALUE (*)())unsafe_fsync,(VALUE) args,&error);
459
+ rb_protect((VALUE (*)())unsafe_fsync,(VALUE) args,&error);
480
460
 
481
- if (error)
482
- {
483
- return -(return_error(ENOENT));
484
- }
485
- else
486
- {
487
- return 0;
488
- }
461
+ return error ? -(return_error(ENOENT)) : 0;
489
462
  }
490
463
 
491
464
 
@@ -519,12 +492,11 @@ static VALUE unsafe_flush(VALUE *args)
519
492
  static int rf_flush(const char *path,struct fuse_file_info *ffi)
520
493
  {
521
494
  VALUE args[4];
522
- VALUE res;
523
495
  int error = 0;
524
496
  struct fuse_context *ctx=fuse_get_context();
525
497
  init_context_path_args(args,ctx,path);
526
498
  args[3]=get_file_info(ffi);
527
- res=rb_protect((VALUE (*)())unsafe_flush,(VALUE) args,&error);
499
+ rb_protect((VALUE (*)())unsafe_flush,(VALUE) args,&error);
528
500
 
529
501
  return error ? -(return_error(ENOENT)) : 0;
530
502
  }
@@ -550,12 +522,11 @@ static VALUE unsafe_truncate(VALUE *args)
550
522
  static int rf_truncate(const char *path,off_t offset)
551
523
  {
552
524
  VALUE args[4];
553
- VALUE res;
554
525
  int error = 0;
555
526
  struct fuse_context *ctx=fuse_get_context();
556
527
  init_context_path_args(args,ctx,path);
557
528
  args[3]=INT2FIX(offset);
558
- res=rb_protect((VALUE (*)())unsafe_truncate,(VALUE) args,&error);
529
+ rb_protect((VALUE (*)())unsafe_truncate,(VALUE) args,&error);
559
530
 
560
531
  return error ? -(return_error(ENOENT)) : 0;
561
532
  }
@@ -584,7 +555,6 @@ static VALUE unsafe_utime(VALUE *args)
584
555
  static int rf_utime(const char *path,struct utimbuf *utim)
585
556
  {
586
557
  VALUE args[5];
587
- VALUE res;
588
558
  int error = 0;
589
559
 
590
560
  struct fuse_context *ctx=fuse_get_context();
@@ -592,7 +562,7 @@ static int rf_utime(const char *path,struct utimbuf *utim)
592
562
 
593
563
  args[3]=INT2NUM(utim->actime);
594
564
  args[4]=INT2NUM(utim->modtime);
595
- res=rb_protect((VALUE (*)())unsafe_utime,(VALUE) args,&error);
565
+ rb_protect((VALUE (*)())unsafe_utime,(VALUE) args,&error);
596
566
 
597
567
  return error ? -(return_error(ENOENT)) : 0;
598
568
  }
@@ -620,13 +590,12 @@ static VALUE unsafe_chown(VALUE *args)
620
590
  static int rf_chown(const char *path,uid_t uid,gid_t gid)
621
591
  {
622
592
  VALUE args[5];
623
- VALUE res;
624
593
  int error = 0;
625
594
  struct fuse_context *ctx=fuse_get_context();
626
595
  init_context_path_args(args,ctx,path);
627
596
  args[3]=INT2FIX(uid);
628
597
  args[4]=INT2FIX(gid);
629
- res=rb_protect((VALUE (*)())unsafe_chown,(VALUE) args,&error);
598
+ rb_protect((VALUE (*)())unsafe_chown,(VALUE) args,&error);
630
599
 
631
600
  return error ? -(return_error(ENOENT)) : 0;
632
601
  }
@@ -653,12 +622,11 @@ static VALUE unsafe_chmod(VALUE *args)
653
622
  static int rf_chmod(const char *path,mode_t mode)
654
623
  {
655
624
  VALUE args[4];
656
- VALUE res;
657
625
  int error = 0;
658
626
  struct fuse_context *ctx=fuse_get_context();
659
627
  init_context_path_args(args,ctx,path);
660
628
  args[3]=INT2FIX(mode);
661
- res=rb_protect((VALUE (*)())unsafe_chmod,(VALUE) args,&error);
629
+ rb_protect((VALUE (*)())unsafe_chmod,(VALUE) args,&error);
662
630
 
663
631
  return error ? -(return_error(ENOENT)) : 0;
664
632
  }
@@ -684,11 +652,10 @@ static VALUE unsafe_unlink(VALUE *args)
684
652
  static int rf_unlink(const char *path)
685
653
  {
686
654
  VALUE args[3];
687
- VALUE res;
688
655
  int error = 0;
689
656
  struct fuse_context *ctx=fuse_get_context();
690
657
  init_context_path_args(args,ctx,path);
691
- res=rb_protect((VALUE (*)())unsafe_unlink,(VALUE) args,&error);
658
+ rb_protect((VALUE (*)())unsafe_unlink,(VALUE) args,&error);
692
659
 
693
660
  return error ? -(return_error(ENOENT)) : 0;
694
661
  }
@@ -714,11 +681,10 @@ static VALUE unsafe_rmdir(VALUE *args)
714
681
  static int rf_rmdir(const char *path)
715
682
  {
716
683
  VALUE args[3];
717
- VALUE res;
718
684
  int error = 0;
719
685
  struct fuse_context *ctx=fuse_get_context();
720
686
  init_context_path_args(args,ctx,path);
721
- res = rb_protect((VALUE (*)())unsafe_rmdir, (VALUE) args ,&error);
687
+ rb_protect((VALUE (*)())unsafe_rmdir, (VALUE) args ,&error);
722
688
 
723
689
  return error ? -(return_error(ENOENT)) : 0;
724
690
  }
@@ -746,7 +712,6 @@ static VALUE unsafe_symlink(VALUE *args){
746
712
  static int rf_symlink(const char *path,const char *as)
747
713
  {
748
714
  VALUE args[4];
749
- VALUE res;
750
715
  int error = 0;
751
716
  struct fuse_context *ctx=fuse_get_context();
752
717
  init_context_path_args(args,ctx,path);
@@ -754,7 +719,7 @@ static int rf_symlink(const char *path,const char *as)
754
719
  args[3]=rb_str_new2(as);
755
720
  rb_filesystem_encode(args[3]);
756
721
 
757
- res=rb_protect((VALUE (*)())unsafe_symlink,(VALUE) args,&error);
722
+ rb_protect((VALUE (*)())unsafe_symlink,(VALUE) args,&error);
758
723
 
759
724
  return error ? -(return_error(ENOENT)) : 0;
760
725
  }
@@ -781,7 +746,6 @@ static VALUE unsafe_rename(VALUE *args)
781
746
  static int rf_rename(const char *path,const char *as)
782
747
  {
783
748
  VALUE args[4];
784
- VALUE res;
785
749
  int error = 0;
786
750
  struct fuse_context *ctx=fuse_get_context();
787
751
  init_context_path_args(args,ctx,path);
@@ -789,7 +753,7 @@ static int rf_rename(const char *path,const char *as)
789
753
  args[3]=rb_str_new2(as);
790
754
  rb_filesystem_encode(args[3]);
791
755
 
792
- res=rb_protect((VALUE (*)())unsafe_rename,(VALUE) args,&error);
756
+ rb_protect((VALUE (*)())unsafe_rename,(VALUE) args,&error);
793
757
 
794
758
  return error ? -(return_error(ENOENT)) : 0;
795
759
  }
@@ -816,13 +780,12 @@ static VALUE unsafe_link(VALUE *args)
816
780
  static int rf_link(const char *path,const char * as)
817
781
  {
818
782
  VALUE args[4];
819
- VALUE res;
820
783
  int error = 0;
821
784
  struct fuse_context *ctx=fuse_get_context();
822
785
  init_context_path_args(args,ctx,path);
823
786
  args[3]=rb_str_new2(as);
824
787
  rb_filesystem_encode(args[3]);
825
- res=rb_protect((VALUE (*)())unsafe_link,(VALUE) args,&error);
788
+ rb_protect((VALUE (*)())unsafe_link,(VALUE) args,&error);
826
789
 
827
790
  return error ? -(return_error(ENOENT)) : 0;
828
791
  }
@@ -873,7 +836,6 @@ static int rf_read(const char *path,char * buf, size_t size,off_t offset,struct
873
836
  VALUE res;
874
837
  int error = 0;
875
838
  long length=0;
876
- char* rbuf;
877
839
 
878
840
  struct fuse_context *ctx=fuse_get_context();
879
841
  init_context_path_args(args,ctx,path);
@@ -971,7 +933,7 @@ static VALUE unsafe_statfs(VALUE *args)
971
933
 
972
934
  static int rf_statfs(const char * path, struct statvfs * vfsinfo)
973
935
  {
974
- VALUE args[1];
936
+ VALUE args[3];
975
937
  VALUE res;
976
938
  int error = 0;
977
939
 
@@ -1016,7 +978,6 @@ static int rf_setxattr(const char *path,const char *name,
1016
978
  const char *value, size_t size, int flags)
1017
979
  {
1018
980
  VALUE args[6];
1019
- VALUE res;
1020
981
  int error = 0;
1021
982
 
1022
983
  struct fuse_context *ctx=fuse_get_context();
@@ -1026,7 +987,7 @@ static int rf_setxattr(const char *path,const char *name,
1026
987
  args[4]=rb_str_new(value,size);
1027
988
  args[5]=INT2NUM(flags);
1028
989
 
1029
- res=rb_protect((VALUE (*)())unsafe_setxattr,(VALUE) args,&error);
990
+ rb_protect((VALUE (*)())unsafe_setxattr,(VALUE) args,&error);
1030
991
 
1031
992
  return error ? -(return_error(ENOENT)) : 0;
1032
993
  }
@@ -1058,8 +1019,6 @@ static int rf_getxattr(const char *path,const char *name,char *buf,
1058
1019
  {
1059
1020
  VALUE args[4];
1060
1021
  VALUE res;
1061
- char *rbuf;
1062
- long length = 0;
1063
1022
  int error = 0;
1064
1023
 
1065
1024
  struct fuse_context *ctx=fuse_get_context();
@@ -1103,8 +1062,6 @@ static int rf_listxattr(const char *path,char *buf, size_t size)
1103
1062
  {
1104
1063
  VALUE args[3];
1105
1064
  VALUE res;
1106
- char *rbuf;
1107
- size_t length =0;
1108
1065
  int error = 0;
1109
1066
 
1110
1067
  struct fuse_context *ctx=fuse_get_context();
@@ -1112,11 +1069,9 @@ static int rf_listxattr(const char *path,char *buf, size_t size)
1112
1069
 
1113
1070
  res=rb_protect((VALUE (*)())unsafe_listxattr,(VALUE) args,&error);
1114
1071
 
1115
- if (error)
1116
- {
1072
+ if (error) {
1117
1073
  return -(return_error(ENOENT));
1118
- }
1119
- else {
1074
+ } else {
1120
1075
  return rb_strcpy(res,buf,size);
1121
1076
  }
1122
1077
  }
@@ -1142,12 +1097,11 @@ static VALUE unsafe_removexattr(VALUE *args)
1142
1097
  static int rf_removexattr(const char *path,const char *name)
1143
1098
  {
1144
1099
  VALUE args[4];
1145
- VALUE res;
1146
1100
  int error = 0;
1147
1101
  struct fuse_context *ctx=fuse_get_context();
1148
1102
  init_context_path_args(args,ctx,path);
1149
1103
  args[3]=rb_str_new2(name);
1150
- res=rb_protect((VALUE (*)())unsafe_removexattr,(VALUE) args,&error);
1104
+ rb_protect((VALUE (*)())unsafe_removexattr,(VALUE) args,&error);
1151
1105
 
1152
1106
  return error ? -(return_error(ENOENT)) : 0 ;
1153
1107
  }
@@ -1177,14 +1131,13 @@ static VALUE unsafe_opendir(VALUE *args)
1177
1131
  static int rf_opendir(const char *path,struct fuse_file_info *ffi)
1178
1132
  {
1179
1133
  VALUE args[4];
1180
- VALUE res;
1181
1134
  int error = 0;
1182
1135
  struct fuse_context *ctx=fuse_get_context();
1183
1136
  init_context_path_args(args,ctx,path);
1184
1137
 
1185
1138
  args[3]=wrap_file_info(ctx,ffi);
1186
1139
 
1187
- res=rb_protect((VALUE (*)())unsafe_opendir,(VALUE) args,&error);
1140
+ rb_protect((VALUE (*)())unsafe_opendir,(VALUE) args,&error);
1188
1141
 
1189
1142
  return error ? -(return_error(ENOENT)) : 0 ;
1190
1143
  }
@@ -1210,14 +1163,13 @@ static VALUE unsafe_releasedir(VALUE *args)
1210
1163
  static int rf_releasedir(const char *path,struct fuse_file_info *ffi)
1211
1164
  {
1212
1165
  VALUE args[4];
1213
- VALUE res;
1214
1166
  int error = 0;
1215
1167
 
1216
1168
  struct fuse_context *ctx=fuse_get_context();
1217
1169
  init_context_path_args(args,ctx,path);
1218
1170
  args[3]=release_file_info(ctx,ffi);
1219
1171
 
1220
- res=rb_protect((VALUE (*)())unsafe_releasedir,(VALUE) args,&error);
1172
+ rb_protect((VALUE (*)())unsafe_releasedir,(VALUE) args,&error);
1221
1173
 
1222
1174
  return error ? -(return_error(ENOENT)) : 0 ;
1223
1175
  }
@@ -1245,13 +1197,12 @@ static VALUE unsafe_fsyncdir(VALUE *args)
1245
1197
  static int rf_fsyncdir(const char *path,int meta,struct fuse_file_info *ffi)
1246
1198
  {
1247
1199
  VALUE args[5];
1248
- VALUE res;
1249
1200
  int error = 0;
1250
1201
  struct fuse_context *ctx=fuse_get_context();
1251
1202
  init_context_path_args(args,ctx,path);
1252
1203
  args[3]=INT2NUM(meta);
1253
1204
  args[4]=get_file_info(ffi);
1254
- res=rb_protect((VALUE (*)())unsafe_fsyncdir,(VALUE) args,&error);
1205
+ rb_protect((VALUE (*)())unsafe_fsyncdir,(VALUE) args,&error);
1255
1206
 
1256
1207
  return error ? -(return_error(ENOENT)) : 0 ;
1257
1208
  }
@@ -1275,20 +1226,22 @@ static VALUE unsafe_init(VALUE* args)
1275
1226
  static void *rf_init(struct fuse_conn_info *conn)
1276
1227
  {
1277
1228
  VALUE args[3];
1278
- VALUE res;
1279
1229
  int error = 0;
1280
-
1281
- struct fuse_context *ctx = fuse_get_context();
1230
+ struct fuse_context *ctx;
1231
+
1232
+ VALUE self, s, fci, fcio;
1233
+
1234
+ ctx = fuse_get_context();
1282
1235
 
1283
- VALUE self = ctx->private_data;
1236
+ self = (VALUE) ctx->private_data;
1284
1237
 
1285
1238
  args[0] = self;
1286
1239
  args[1] = wrap_context(ctx);
1287
1240
 
1288
1241
  //Create a struct for the conn_info
1289
1242
  //TODO - some of these are writable!
1290
- VALUE s = rb_const_get(rb_cObject,rb_intern("Struct"));
1291
- VALUE fci = rb_funcall(s,rb_intern("new"),7,
1243
+ s = rb_const_get(rb_cObject,rb_intern("Struct"));
1244
+ fci = rb_funcall(s,rb_intern("new"),7,
1292
1245
  ID2SYM(rb_intern("proto_major")),
1293
1246
  ID2SYM(rb_intern("proto_minor")),
1294
1247
  ID2SYM(rb_intern("async_read")),
@@ -1298,7 +1251,7 @@ static void *rf_init(struct fuse_conn_info *conn)
1298
1251
  ID2SYM(rb_intern("want"))
1299
1252
  );
1300
1253
 
1301
- VALUE fcio = rb_funcall(fci,rb_intern("new"),7,
1254
+ fcio = rb_funcall(fci,rb_intern("new"),7,
1302
1255
  UINT2NUM(conn->proto_major),
1303
1256
  UINT2NUM(conn->proto_minor),
1304
1257
  UINT2NUM(conn->async_read),
@@ -1310,50 +1263,13 @@ static void *rf_init(struct fuse_conn_info *conn)
1310
1263
 
1311
1264
  args[2] = fcio;
1312
1265
 
1313
- res = rb_protect((VALUE (*)())unsafe_init,(VALUE) args,&error);
1266
+ rb_protect((VALUE (*)())unsafe_init,(VALUE) args,&error);
1314
1267
 
1315
- if (error)
1316
- {
1317
- return NULL;
1318
- }
1319
- else
1320
- {
1321
- //This previously was the result of the init call (res)
1322
- //but it was never made available to any of the file operations
1323
- //and nothing was done to prevent it from being GC'd so
1324
- //filesystems would need to have stored it separately anyway
1325
- return (void *) self;
1326
- }
1327
- }
1328
-
1329
- /*
1330
- Cleanup filesystem
1331
-
1332
- @overload destroy()
1333
- @abstract Fuse Operation {http://fuse.sourceforge.net/doxygen/structfuse__operations.html#c41d37ab860204fe4bd7612f9fb036c5 destroy}
1334
-
1335
- @param [Context] context
1336
-
1337
- @return [void]
1338
-
1339
- Called at filesystem exit - which itself is triggered when this fuse object
1340
- is garbage collected, so not sure it is actually safe to call this
1341
- */
1342
- static VALUE unsafe_destroy(VALUE* args)
1343
- {
1344
- return rb_funcall3(args[0],rb_intern("destroy"),1,&args[1]);
1345
- }
1346
-
1347
- static void rf_destroy(void *user_data)
1348
- {
1349
- VALUE args[2];
1350
- int error = 0;
1351
-
1352
- struct fuse_context *ctx = fuse_get_context();
1353
- args[0] = ctx->private_data;
1354
- args[1] = wrap_context(ctx);
1355
-
1356
- rb_protect((VALUE (*)())unsafe_destroy,(VALUE) args,&error);
1268
+ //This previously was the result of the init call (res)
1269
+ //but it was never made available to any of the file operations
1270
+ //and nothing was done to prevent it from being GC'd so
1271
+ //filesystems would need to have stored it separately anyway
1272
+ return error ? NULL : (void *) self;
1357
1273
  }
1358
1274
 
1359
1275
  /*
@@ -1377,12 +1293,11 @@ static VALUE unsafe_access(VALUE* args)
1377
1293
  static int rf_access(const char *path, int mask)
1378
1294
  {
1379
1295
  VALUE args[4];
1380
- VALUE res;
1381
1296
  int error = 0;
1382
1297
  struct fuse_context *ctx=fuse_get_context();
1383
1298
  init_context_path_args(args,ctx,path);
1384
1299
  args[3] = INT2NUM(mask);
1385
- res = rb_protect((VALUE (*)())unsafe_access,(VALUE) args,&error);
1300
+ rb_protect((VALUE (*)())unsafe_access,(VALUE) args,&error);
1386
1301
 
1387
1302
  return error ? -(return_error(ENOENT)) : 0 ;
1388
1303
  }
@@ -1412,7 +1327,6 @@ static VALUE unsafe_create(VALUE* args)
1412
1327
  static int rf_create(const char *path, mode_t mode, struct fuse_file_info *ffi)
1413
1328
  {
1414
1329
  VALUE args[5];
1415
- VALUE res;
1416
1330
  int error = 0;
1417
1331
 
1418
1332
  struct fuse_context *ctx = fuse_get_context();
@@ -1420,7 +1334,7 @@ static int rf_create(const char *path, mode_t mode, struct fuse_file_info *ffi)
1420
1334
  args[3] = INT2NUM(mode);
1421
1335
  args[4] = wrap_file_info(ctx,ffi);
1422
1336
 
1423
- res = rb_protect((VALUE (*)())unsafe_create,(VALUE) args,&error);
1337
+ rb_protect((VALUE (*)())unsafe_create,(VALUE) args,&error);
1424
1338
 
1425
1339
  return error ? -(return_error(ENOENT)) : 0 ;
1426
1340
 
@@ -1450,7 +1364,6 @@ static int rf_ftruncate(const char *path, off_t size,
1450
1364
  struct fuse_file_info *ffi)
1451
1365
  {
1452
1366
  VALUE args[5];
1453
- VALUE res;
1454
1367
  int error = 0;
1455
1368
 
1456
1369
  struct fuse_context *ctx = fuse_get_context();
@@ -1458,7 +1371,7 @@ static int rf_ftruncate(const char *path, off_t size,
1458
1371
  args[3] = INT2NUM(size);
1459
1372
  args[4] = get_file_info(ffi);
1460
1373
 
1461
- res = rb_protect((VALUE (*)())unsafe_ftruncate,(VALUE) args,&error);
1374
+ rb_protect((VALUE (*)())unsafe_ftruncate,(VALUE) args,&error);
1462
1375
 
1463
1376
  return error ? -(return_error(ENOENT)) : 0 ;
1464
1377
  }
@@ -1517,7 +1430,8 @@ static int rf_fgetattr(const char *path, struct stat *stbuf, struct fuse_file_in
1517
1430
  @param [Struct] flock
1518
1431
 
1519
1432
  @return [void]
1520
- @raise [Errno]
1433
+ @raise [Errno]
1434
+ @todo Some of the attributes of the flock struct should be writable
1521
1435
 
1522
1436
  The cmd argument will be either F_GETLK, F_SETLK or F_SETLKW.
1523
1437
 
@@ -1540,17 +1454,19 @@ static int rf_lock(const char *path, struct fuse_file_info *ffi,
1540
1454
  int cmd, struct flock *lock)
1541
1455
  {
1542
1456
  VALUE args[6];
1543
- VALUE res;
1544
1457
  int error = 0;
1545
1458
 
1459
+ VALUE cStruct;
1460
+ VALUE lockc;
1461
+ VALUE locko;
1462
+
1546
1463
  struct fuse_context *ctx = fuse_get_context();
1547
1464
  init_context_path_args(args,ctx,path);
1548
1465
 
1549
- //TODO Wrap the struct flock so these attributes can be set
1550
1466
 
1551
1467
  //Create a struct for the lock structure
1552
- VALUE s = rb_const_get(rb_cObject,rb_intern("Struct"));
1553
- VALUE lockc = rb_funcall(s,rb_intern("new"),5,
1468
+ cStruct = rb_const_get(rb_cObject,rb_intern("Struct"));
1469
+ lockc = rb_funcall(cStruct,rb_intern("new"),5,
1554
1470
  ID2SYM(rb_intern("l_type")),
1555
1471
  ID2SYM(rb_intern("l_whence")),
1556
1472
  ID2SYM(rb_intern("l_start")),
@@ -1558,7 +1474,7 @@ static int rf_lock(const char *path, struct fuse_file_info *ffi,
1558
1474
  ID2SYM(rb_intern("l_pid"))
1559
1475
  );
1560
1476
 
1561
- VALUE locko = rb_funcall(lockc,rb_intern("new"),5,
1477
+ locko = rb_funcall(lockc,rb_intern("new"),5,
1562
1478
  UINT2NUM(lock->l_type),
1563
1479
  UINT2NUM(lock->l_whence),
1564
1480
  UINT2NUM(lock->l_start),
@@ -1570,7 +1486,7 @@ static int rf_lock(const char *path, struct fuse_file_info *ffi,
1570
1486
  args[4] = INT2NUM(cmd);
1571
1487
  args[5] = locko;
1572
1488
 
1573
- res = rb_protect((VALUE (*)())unsafe_lock,(VALUE) args,&error);
1489
+ rb_protect((VALUE (*)())unsafe_lock,(VALUE) args,&error);
1574
1490
 
1575
1491
  return error ? -(return_error(ENOENT)) : 0 ;
1576
1492
  }
@@ -1598,7 +1514,6 @@ static VALUE unsafe_utimens(VALUE *args)
1598
1514
  static int rf_utimens(const char * path, const struct timespec tv[2])
1599
1515
  {
1600
1516
  VALUE args[5];
1601
- VALUE res;
1602
1517
  int error = 0;
1603
1518
 
1604
1519
  struct fuse_context *ctx = fuse_get_context();
@@ -1619,7 +1534,7 @@ static int rf_utimens(const char * path, const struct timespec tv[2])
1619
1534
  rb_intern("+"), 1, INT2NUM(tv[1].tv_nsec)
1620
1535
  );
1621
1536
 
1622
- res = rb_protect((VALUE (*)())unsafe_utimens,(VALUE) args, &error);
1537
+ rb_protect((VALUE (*)())unsafe_utimens,(VALUE) args, &error);
1623
1538
  return error ? -(return_error(ENOENT)) : 0 ;
1624
1539
  }
1625
1540
 
@@ -1670,7 +1585,7 @@ static int rf_bmap(const char *path, size_t blocksize, uint64_t *idx)
1670
1585
  }
1671
1586
 
1672
1587
  //----------------------IOCTL
1673
-
1588
+ #ifdef RFUSE_BROKEN
1674
1589
  static VALUE unsafe_ioctl(VALUE *args)
1675
1590
  {
1676
1591
  VALUE path = args[0];
@@ -1682,7 +1597,7 @@ static VALUE unsafe_ioctl(VALUE *args)
1682
1597
 
1683
1598
  struct fuse_context *ctx = fuse_get_context();
1684
1599
 
1685
- return rb_funcall( ctx->private_data, rb_intern("ioctl"), 7, wrap_context(ctx),
1600
+ return rb_funcall((VALUE) ctx->private_data, rb_intern("ioctl"), 7, wrap_context(ctx),
1686
1601
  path, cmd, arg, ffi, flags, data);
1687
1602
  }
1688
1603
 
@@ -1710,9 +1625,10 @@ static int rf_ioctl(const char *path, int cmd, void *arg,
1710
1625
 
1711
1626
  return 0;
1712
1627
  }
1628
+ #endif
1713
1629
 
1714
1630
  //----------------------POLL
1715
-
1631
+ #ifdef RFUSE_BROKEN
1716
1632
  static VALUE unsafe_poll(VALUE *args)
1717
1633
  {
1718
1634
  VALUE path = args[0];
@@ -1751,6 +1667,7 @@ static int rf_poll(const char *path, struct fuse_file_info *ffi,
1751
1667
  }
1752
1668
  return 0;
1753
1669
  }
1670
+ #endif
1754
1671
 
1755
1672
  /*
1756
1673
  Is the filesystem successfully mounted
@@ -1794,8 +1711,11 @@ VALUE rf_unmount(VALUE self)
1794
1711
  VALUE rf_mountname(VALUE self)
1795
1712
  {
1796
1713
  struct intern_fuse *inf;
1714
+ VALUE result;
1715
+
1797
1716
  Data_Get_Struct(self,struct intern_fuse,inf);
1798
- VALUE result = rb_str_new2(inf->mountpoint);
1717
+
1718
+ result = rb_str_new2(inf->mountpoint);
1799
1719
  rb_filesystem_encode(result);
1800
1720
 
1801
1721
  return result;
@@ -1808,7 +1728,7 @@ VALUE rf_invalidate(VALUE self,VALUE path)
1808
1728
  {
1809
1729
  struct intern_fuse *inf;
1810
1730
  Data_Get_Struct(self,struct intern_fuse,inf);
1811
- return fuse_invalidate(inf->fuse,STR2CSTR(path));
1731
+ return fuse_invalidate(inf->fuse,StringValueCStr(path));
1812
1732
  }
1813
1733
 
1814
1734
  /*
@@ -1853,6 +1773,7 @@ VALUE rf_process(VALUE self)
1853
1773
 
1854
1774
  /*
1855
1775
  * initialize and mount the filesystem
1776
+ * @overload initialize(mountpoint,*options)
1856
1777
  * @param [String] mountpoint The mountpoint
1857
1778
  * @param [Array<String>] options fuse arguments (-h to see a list)
1858
1779
  */
@@ -1862,14 +1783,20 @@ static VALUE rf_initialize(
1862
1783
  VALUE opts)
1863
1784
  {
1864
1785
 
1786
+ VALUE mountpoint;
1787
+ struct intern_fuse *inf;
1788
+ int init_result;
1789
+ struct fuse_args *args;
1790
+
1865
1791
  //Allow things like Pathname to be sent as a mountpoint
1866
- VALUE mountpoint = rb_obj_as_string(mountpoint_obj);
1792
+ mountpoint = rb_obj_as_string(mountpoint_obj);
1867
1793
  Check_Type(opts, T_ARRAY);
1868
1794
 
1869
- struct intern_fuse *inf;
1870
1795
  Data_Get_Struct(self,struct intern_fuse,inf);
1871
1796
 
1872
1797
  inf->mountpoint = strdup(StringValueCStr(mountpoint));
1798
+
1799
+ args = rarray2fuseargs(opts);
1873
1800
 
1874
1801
  if (RESPOND_TO(self,"getattr"))
1875
1802
  inf->fuse_op.getattr = rf_getattr;
@@ -1939,8 +1866,6 @@ static VALUE rf_initialize(
1939
1866
  inf->fuse_op.fsyncdir = rf_fsyncdir;
1940
1867
  if (RESPOND_TO(self,"init"))
1941
1868
  inf->fuse_op.init = rf_init;
1942
- // if (RESPOND_TO(self,"destroy"))
1943
- // inf->fuse_op.destroy = rf_destroy;
1944
1869
  if (RESPOND_TO(self,"access"))
1945
1870
  inf->fuse_op.access = rf_access;
1946
1871
  if (RESPOND_TO(self,"ftruncate"))
@@ -1953,29 +1878,23 @@ static VALUE rf_initialize(
1953
1878
  inf->fuse_op.utimens = rf_utimens;
1954
1879
  if (RESPOND_TO(self,"bmap"))
1955
1880
  inf->fuse_op.bmap = rf_bmap;
1956
- /*
1881
+ #ifdef RFUSE_BROKEN
1957
1882
  if (RESPOND_TO(self,"ioctl"))
1958
1883
  inf->fuse_op.ioctl = rf_ioctl;
1959
1884
  if (RESPOND_TO(self,"poll"))
1960
1885
  inf->fuse_op.poll = rf_poll;
1961
- */
1962
-
1963
- struct fuse_args *args = rarray2fuseargs(opts);
1964
-
1965
- //Store our fuse object in user_data, this will be returned to use in the
1966
- //session context
1967
- void* user_data = self;
1886
+ #endif
1968
1887
 
1969
- int init_result;
1970
1888
 
1971
1889
  // init_result indicates not mounted, but so does inf->fuse == NULL
1972
1890
  // raise exceptions only if we try to use the mount
1973
1891
  // can test with mounted?
1974
- init_result = intern_fuse_init(inf, args, user_data);
1892
+ // Note we are storing this Ruby object as the FUSE user_data
1893
+ init_result = intern_fuse_init(inf, args, (void *) self);
1975
1894
 
1976
1895
  //Create the open files hash where we cache FileInfo objects
1977
- VALUE open_files_hash;
1978
1896
  if (init_result == 0) {
1897
+ VALUE open_files_hash;
1979
1898
  open_files_hash=rb_hash_new();
1980
1899
  rb_iv_set(self,"@open_files",open_files_hash);
1981
1900
  rb_funcall(self,rb_intern("ruby_initialize"),0);
@@ -2008,8 +1927,11 @@ void rfuse_init(VALUE module)
2008
1927
  //Trick Yardoc
2009
1928
  mRFuse = rb_define_mRFuse("RFuse");
2010
1929
  #endif
1930
+ VALUE cFuse;
1931
+
2011
1932
  mRFuse = module;
2012
- VALUE cFuse=rb_define_class_under(mRFuse,"Fuse",rb_cObject);
1933
+
1934
+ cFuse = rb_define_class_under(mRFuse,"Fuse",rb_cObject);
2013
1935
 
2014
1936
  rb_define_alloc_func(cFuse,rf_new);
2015
1937