rfuse-ng 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.txt CHANGED
@@ -1,3 +1,20 @@
1
+ 2010-06-20
2
+
3
+ Only poll() and ioctl() are missing. Fixed compilation error
4
+ on 64 bit systems and random segfault because of uninicialized
5
+ memory
6
+
7
+ 2010-05-03: 0.3.0
8
+
9
+ Fixed read() and write() bugs, updated example. Implemented
10
+ truncate() in the example.
11
+
12
+ Fuse operation fields are filled only, when the class respond_to the
13
+ particular method.
14
+
15
+ The example filesystem was tested with several hundred big files and
16
+ all came back intact.
17
+
1
18
  2010-05-01: 0.2.0
2
19
 
3
20
  Switched to Fuse API 26 from 22. Fixed incompatibilities.
@@ -7,4 +24,4 @@ functions.
7
24
 
8
25
  2010-05-01: 0.1
9
26
 
10
- Froked from rfuse, fixed compile warnings, gemified.
27
+ Forked from rfuse, fixed compile warnings, gemified.
data/README.ng CHANGED
@@ -17,6 +17,34 @@ DEPENDENCIES
17
17
  ruby 1.8
18
18
  fuse 2.8
19
19
 
20
+ INSTALLING
21
+ ==========
22
+
23
+ To install it with rubygems:
24
+
25
+ $ sudo gem install rfuse-ng
26
+
27
+ To build from the source, install libfuse-dev, and:
28
+
29
+ $ ruby ext/extconf.rb
30
+ $ make
31
+
32
+ ...and there should be a rfuse_ng.so in the project root directory.
33
+
34
+ USING
35
+ =====
36
+
37
+ Sorry, no docs here, see sample/test-ruby.rb
38
+
39
+ To run the example:
40
+
41
+ $ sudo mkdir /tmp/fuse
42
+ $ sudo sample/test-ruby.rb
43
+
44
+ ..and there should be a filesystem mounted at /tmp/fuse.
45
+
46
+ Umount should stop the example example filesystem program.
47
+
20
48
  AUTHOR
21
49
  ======
22
50
 
data/Rakefile CHANGED
@@ -5,7 +5,7 @@ begin
5
5
  require 'jeweler'
6
6
  Jeweler::Tasks.new do |gem|
7
7
  gem.name = "rfuse-ng"
8
- gem.version = "0.3.0"
8
+ gem.version = "0.4.0"
9
9
  gem.summary = 'Ruby language binding for FUSE'
10
10
  gem.description = 'Ruby language binding for FUSE. It was forked from rfuse'
11
11
  gem.rubyforge_project = 'rfuse-ng'
data/THANKS CHANGED
@@ -1 +1,3 @@
1
1
  Many thanks to Peter Schrammel for the parent project rfuse.
2
+
3
+ Thanks to Roland Pallai for providing valueable feedback.
data/ext/helper.c CHANGED
@@ -1,23 +1,48 @@
1
1
  #include "helper.h"
2
2
 
3
- void rstat2stat(VALUE rstat, struct stat *statbuf){
4
- statbuf->st_dev=FIX2ULONG(rb_funcall(rstat,rb_intern("dev"),0));
5
- statbuf->st_ino=FIX2ULONG(rb_funcall(rstat,rb_intern("ino"),0));
6
- statbuf->st_mode=FIX2UINT(rb_funcall(rstat,rb_intern("mode"),0));
7
- statbuf->st_nlink=FIX2UINT(rb_funcall(rstat,rb_intern("nlink"),0));
8
- statbuf->st_uid=FIX2UINT(rb_funcall(rstat,rb_intern("uid"),0));
9
- statbuf->st_gid=FIX2UINT(rb_funcall(rstat,rb_intern("gid"),0));
10
- statbuf->st_rdev=FIX2ULONG(rb_funcall(rstat,rb_intern("rdev"),0));
11
- statbuf->st_size=FIX2ULONG(rb_funcall(rstat,rb_intern("size"),0));
12
- statbuf->st_blksize=NUM2ULONG(rb_funcall(rstat,rb_intern("blksize"),0));
13
- statbuf->st_blocks=NUM2ULONG(rb_funcall(rstat,rb_intern("blocks"),0));
14
- statbuf->st_atime=NUM2ULONG(rb_funcall(rb_funcall(rstat,
15
- rb_intern("atime"),0),rb_intern("to_i"),0));
16
- statbuf->st_mtime=NUM2ULONG(rb_funcall(rb_funcall(rstat,
17
- rb_intern("mtime"),0),rb_intern("to_i"),0));
18
- statbuf->st_ctime=NUM2ULONG(rb_funcall(rb_funcall(rstat,
19
- rb_intern("ctime"),0),rb_intern("to_i"),0));
20
- };
3
+ void rstat2stat(VALUE rstat, struct stat *statbuf)
4
+ {
5
+ statbuf->st_dev = FIX2ULONG(rb_funcall(rstat,rb_intern("dev"),0));
6
+ statbuf->st_ino = FIX2ULONG(rb_funcall(rstat,rb_intern("ino"),0));
7
+ statbuf->st_mode = FIX2UINT(rb_funcall(rstat,rb_intern("mode"),0));
8
+ statbuf->st_nlink = FIX2UINT(rb_funcall(rstat,rb_intern("nlink"),0));
9
+ statbuf->st_uid = FIX2UINT(rb_funcall(rstat,rb_intern("uid"),0));
10
+ statbuf->st_gid = FIX2UINT(rb_funcall(rstat,rb_intern("gid"),0));
11
+ statbuf->st_rdev = FIX2ULONG(rb_funcall(rstat,rb_intern("rdev"),0));
12
+ statbuf->st_size = FIX2ULONG(rb_funcall(rstat,rb_intern("size"),0));
13
+ statbuf->st_blksize = NUM2ULONG(rb_funcall(rstat,rb_intern("blksize"),0));
14
+ statbuf->st_blocks = NUM2ULONG(rb_funcall(rstat,rb_intern("blocks"),0));
15
+ statbuf->st_atime =
16
+ NUM2ULONG(rb_funcall(rb_funcall(rstat,rb_intern("atime"),0),rb_intern("to_i"),0));
17
+ statbuf->st_mtime =
18
+ NUM2ULONG(rb_funcall(rb_funcall(rstat,rb_intern("mtime"),0),rb_intern("to_i"),0));
19
+ statbuf->st_ctime =
20
+ NUM2ULONG(rb_funcall(rb_funcall(rstat,rb_intern("ctime"),0),rb_intern("to_i"),0));
21
+ }
22
+
23
+ void rstatvfs2statvfs(VALUE rstatvfs,struct statvfs *statvfsbuf) {
24
+ statvfsbuf->f_bsize = FIX2ULONG(rb_funcall(rstatvfs,rb_intern("f_bsize"),0));
25
+ statvfsbuf->f_frsize = FIX2ULONG(rb_funcall(rstatvfs,rb_intern("f_frsize"),0));
26
+ statvfsbuf->f_blocks = FIX2ULONG(rb_funcall(rstatvfs,rb_intern("f_blocks"),0));
27
+ statvfsbuf->f_bfree = FIX2ULONG(rb_funcall(rstatvfs,rb_intern("f_bfree"),0));
28
+ statvfsbuf->f_bavail = FIX2ULONG(rb_funcall(rstatvfs,rb_intern("f_bavail"),0));
29
+ statvfsbuf->f_files = FIX2ULONG(rb_funcall(rstatvfs,rb_intern("f_files"),0));
30
+ statvfsbuf->f_ffree = FIX2ULONG(rb_funcall(rstatvfs,rb_intern("f_ffree"),0));
31
+ statvfsbuf->f_favail = FIX2ULONG(rb_funcall(rstatvfs,rb_intern("f_favail"),0));
32
+ statvfsbuf->f_fsid = FIX2ULONG(rb_funcall(rstatvfs,rb_intern("f_fsid"),0));
33
+ statvfsbuf->f_flag = FIX2ULONG(rb_funcall(rstatvfs,rb_intern("f_flag"),0));
34
+ statvfsbuf->f_namemax = FIX2ULONG(rb_funcall(rstatvfs,rb_intern("f_namemax"),0));
35
+ }
36
+
37
+ void rfuseconninfo2fuseconninfo(VALUE rfuseconninfo,struct fuse_conn_info *fuseconninfo) {
38
+ fuseconninfo->proto_major = FIX2UINT(rb_funcall(rfuseconninfo,rb_intern("proto_major"),0));
39
+ fuseconninfo->proto_minor = FIX2UINT(rb_funcall(rfuseconninfo,rb_intern("proto_minor"),0));
40
+ fuseconninfo->async_read = FIX2UINT(rb_funcall(rfuseconninfo,rb_intern("async_read"),0));
41
+ fuseconninfo->max_write = FIX2UINT(rb_funcall(rfuseconninfo,rb_intern("max_write"),0));
42
+ fuseconninfo->max_readahead = FIX2UINT(rb_funcall(rfuseconninfo,rb_intern("max_readahead"),0));
43
+ fuseconninfo->capable = FIX2UINT(rb_funcall(rfuseconninfo,rb_intern("capable"),0));
44
+ fuseconninfo->want = FIX2UINT(rb_funcall(rfuseconninfo,rb_intern("want"),0));
45
+ }
21
46
 
22
47
  struct fuse_args * rarray2fuseargs(VALUE rarray){
23
48
 
data/ext/helper.h CHANGED
@@ -1,4 +1,5 @@
1
1
  #include <sys/stat.h>
2
+ #include <sys/statvfs.h>
2
3
  #include <ruby.h>
3
4
  #include <fuse.h>
4
5
 
@@ -6,6 +7,8 @@
6
7
  #define _RHUSE_HELPER_H
7
8
 
8
9
  void rstat2stat(VALUE rstat,struct stat *statbuf);
10
+ void rstatvfs2statvfs(VALUE rstatvfs,struct statvfs *statvfsbuf);
11
+ void rfuseconninfo2fuseconninfo(VALUE rfuseconninfo,struct fuse_conn_info *fuseconninfo);
9
12
  struct fuse_args * rarray2fuseargs(VALUE rarray);
10
13
 
11
14
  #endif
data/ext/intern_rfuse.c CHANGED
@@ -6,6 +6,7 @@
6
6
  struct intern_fuse *intern_fuse_new() {
7
7
  struct intern_fuse *inf;
8
8
  inf = (struct intern_fuse *) malloc(sizeof(struct intern_fuse));
9
+ memset(&inf->fuse_op, 0, sizeof(struct fuse_operations));
9
10
  return inf;
10
11
  };
11
12
 
data/ext/rfuse.c CHANGED
@@ -201,7 +201,6 @@ static VALUE unsafe_mknod(VALUE *args)
201
201
  return rb_funcall(fuse_object,rb_intern("mknod"),4,wrap_context(ctx),path,mode,dev);
202
202
  }
203
203
 
204
- //calls getattr with path and expects something like FuseStat back
205
204
  static int rf_mknod(const char *path, mode_t mode,dev_t dev)
206
205
  {
207
206
  VALUE args[3];
@@ -345,10 +344,37 @@ static int rf_release(const char *path, struct fuse_file_info *ffi)
345
344
  }
346
345
 
347
346
  //----------------------FSYNC
347
+ static VALUE unsafe_fsync(VALUE *args) {
348
+ VALUE path = args[0];
349
+ VALUE datasync = args[1];
350
+ VALUE ffi = args[2];
351
+
352
+ struct fuse_context *ctx=fuse_get_context();
353
+
354
+ return rb_funcall(fuse_object,rb_intern("fsync"), 4, wrap_context(ctx),
355
+ path, datasync, ffi);
356
+ }
357
+
348
358
  static int rf_fsync(const char *path, int datasync, struct fuse_file_info *ffi)
349
359
  {
350
- //TODO
351
- return 0;
360
+ VALUE args[3];
361
+ VALUE res;
362
+ int error = 0;
363
+
364
+ args[0] = rb_str_new2(path);
365
+ args[1] = INT2NUM(datasync);
366
+ args[2] = wrap_file_info(ffi);
367
+
368
+ res = rb_protect((VALUE (*)())unsafe_fsync,(VALUE) args,&error);
369
+
370
+ if (error)
371
+ {
372
+ return -(return_error(ENOENT));
373
+ }
374
+ else
375
+ {
376
+ return 0;
377
+ }
352
378
  }
353
379
 
354
380
  //----------------------FLUSH
@@ -751,10 +777,35 @@ static int rf_write(const char *path,const char *buf,size_t size,
751
777
  }
752
778
 
753
779
  //----------------------STATFS
780
+ static VALUE unsafe_statfs(VALUE *args)
781
+ {
782
+ VALUE path = args[0];
783
+
784
+ struct fuse_context *ctx = fuse_get_context();
785
+
786
+ return rb_funcall(fuse_object,rb_intern("statfs"),2,
787
+ wrap_context(ctx),path);
788
+ }
789
+
754
790
  static int rf_statfs(const char * path, struct statvfs * vfsinfo)
755
791
  {
756
- // TODO
757
- return 0;
792
+ VALUE args[1];
793
+ VALUE res;
794
+ int error = 0;
795
+
796
+ args[0] = rb_str_new2(path);
797
+
798
+ res = rb_protect((VALUE (*)())unsafe_statfs,(VALUE) args,&error);
799
+
800
+ if (error || (res == Qnil))
801
+ {
802
+ return -(return_error(ENOENT));
803
+ }
804
+ else
805
+ {
806
+ rstatvfs2statvfs(res,vfsinfo);
807
+ return 0;
808
+ }
758
809
  }
759
810
 
760
811
  //----------------------SETXATTR
@@ -784,7 +835,7 @@ static int rf_setxattr(const char *path,const char *name,
784
835
  args[0]=rb_str_new2(path);
785
836
  args[1]=rb_str_new2(name);
786
837
  args[2]=rb_str_new(value,size);
787
- args[3]=INT2NUM(size); //TODO:FIX would be faster
838
+ args[3]=INT2NUM(size);
788
839
  args[4]=INT2NUM(flags);
789
840
 
790
841
  res=rb_protect((VALUE (*)())unsafe_setxattr,(VALUE) args,&error);
@@ -882,14 +933,14 @@ static int rf_listxattr(const char *path,char *buf,
882
933
  } else {
883
934
  return -ERANGE;
884
935
  }
885
- printf("destination: %s,%d\n",buf,size);
886
- printf("source: %s,%d\n",rbuf,length);
936
+ printf("destination: %s,%zd\n",buf,size);
937
+ printf("source: %s,%zd\n",rbuf,length);
887
938
  return length;
888
939
  //TODO optimize,check lenght
889
940
  }
890
941
  else
891
942
  {
892
- printf ("not copied: %s, %d\n",buf,length);
943
+ printf ("not copied: %s, %zd\n",buf,length);
893
944
  return length;
894
945
  }
895
946
  }
@@ -999,7 +1050,7 @@ static VALUE unsafe_fsyncdir(VALUE *args)
999
1050
 
1000
1051
  struct fuse_context *ctx=fuse_get_context();
1001
1052
 
1002
- return rb_funcall(fuse_object,rb_intern("fsyncdir"),3,wrap_context(ctx),path,
1053
+ return rb_funcall(fuse_object,rb_intern("fsyncdir"),4,wrap_context(ctx),path,
1003
1054
  meta,ffi);
1004
1055
  }
1005
1056
 
@@ -1024,62 +1075,278 @@ static int rf_fsyncdir(const char *path,int meta,struct fuse_file_info *ffi)
1024
1075
  }
1025
1076
 
1026
1077
  //----------------------INIT
1078
+ static VALUE unsafe_init(VALUE* args)
1079
+ {
1080
+ VALUE rfuseconninfo = args[0];
1081
+
1082
+ struct fuse_context *ctx = fuse_get_context();
1083
+
1084
+ return rb_funcall(fuse_object,rb_intern("init"),2,wrap_context(ctx),
1085
+ rfuseconninfo);
1086
+ }
1027
1087
 
1028
1088
  static void *rf_init(struct fuse_conn_info *conn)
1029
1089
  {
1030
- // TODO
1031
- return NULL;
1090
+ VALUE args[1];
1091
+ VALUE res;
1092
+ int error = 0;
1093
+
1094
+ //Create a struct for the conn_info
1095
+ VALUE s = rb_const_get(rb_cObject,rb_intern("Struct"));
1096
+ VALUE fci = rb_funcall(s,rb_intern("new"),7,
1097
+ ID2SYM(rb_intern("proto_major")),
1098
+ ID2SYM(rb_intern("proto_minor")),
1099
+ ID2SYM(rb_intern("async_read")),
1100
+ ID2SYM(rb_intern("max_write")),
1101
+ ID2SYM(rb_intern("max_readahead")),
1102
+ ID2SYM(rb_intern("capable")),
1103
+ ID2SYM(rb_intern("want"))
1104
+ );
1105
+
1106
+ VALUE fcio = rb_funcall(fci,rb_intern("new"),7,
1107
+ UINT2NUM(conn->proto_major),
1108
+ UINT2NUM(conn->proto_minor),
1109
+ UINT2NUM(conn->async_read),
1110
+ UINT2NUM(conn->max_write),
1111
+ UINT2NUM(conn->max_readahead),
1112
+ UINT2NUM(conn->capable),
1113
+ UINT2NUM(conn->want)
1114
+ );
1115
+
1116
+ args[0] = fcio;
1117
+
1118
+ res = rb_protect((VALUE (*)())unsafe_init,(VALUE) args,&error);
1119
+
1120
+ if (error)
1121
+ {
1122
+ return NULL;
1123
+ }
1124
+ else
1125
+ {
1126
+ return (void *)res;
1127
+ }
1032
1128
  }
1033
1129
 
1034
1130
  //----------------------DESTROY
1035
1131
 
1132
+ static VALUE unsafe_destroy(VALUE* args)
1133
+ {
1134
+ VALUE user_data = args[0];
1135
+
1136
+ struct fuse_context *ctx = fuse_get_context();
1137
+
1138
+ return rb_funcall(fuse_object,rb_intern("destroy"),2,wrap_context(ctx),
1139
+ user_data);
1140
+ }
1141
+
1036
1142
  static void rf_destroy(void *user_data)
1037
1143
  {
1038
- // TODO
1144
+ VALUE args[1];
1145
+ int error = 0;
1146
+
1147
+ args[0] = (VALUE)user_data;
1148
+
1149
+ rb_protect((VALUE (*)())unsafe_destroy,(VALUE) args,&error);
1150
+ // TODO: some kind of logging would be nice here.
1039
1151
  }
1040
1152
 
1041
1153
  //----------------------ACCESS
1042
1154
 
1155
+ static VALUE unsafe_access(VALUE* args)
1156
+ {
1157
+ VALUE path = args[0];
1158
+ VALUE mask = args[1];
1159
+
1160
+ struct fuse_context *ctx = fuse_get_context();
1161
+
1162
+ return rb_funcall(fuse_object,rb_intern("access"),3,wrap_context(ctx),
1163
+ path, mask);
1164
+ }
1165
+
1043
1166
  static int rf_access(const char *path, int mask)
1044
1167
  {
1045
- // TODO
1046
- return 0;
1168
+ VALUE args[2];
1169
+ VALUE res;
1170
+ int error = 0;
1171
+ args[0] = rb_str_new2(path);
1172
+ args[1] = INT2NUM(mask);
1173
+ res = rb_protect((VALUE (*)())unsafe_access,(VALUE) args,&error);
1174
+
1175
+ if (error)
1176
+ {
1177
+ return -(return_error(ENOENT));
1178
+ }
1179
+ else
1180
+ {
1181
+ return 0;
1182
+ }
1047
1183
  }
1048
1184
 
1049
1185
  //----------------------CREATE
1050
1186
 
1187
+ static VALUE unsafe_create(VALUE* args)
1188
+ {
1189
+ VALUE path = args[0];
1190
+ VALUE mode = args[1];
1191
+ VALUE ffi = args[2];
1192
+
1193
+ struct fuse_context *ctx = fuse_get_context();
1194
+
1195
+ return rb_funcall(fuse_object,rb_intern("create"),4,wrap_context(ctx),
1196
+ path, mode, ffi);
1197
+ }
1198
+
1051
1199
  static int rf_create(const char *path, mode_t mode,
1052
1200
  struct fuse_file_info *ffi)
1053
1201
  {
1054
- // TODO
1055
- return 0;
1202
+ VALUE args[3];
1203
+ VALUE res;
1204
+ int error = 0;
1205
+
1206
+ args[0] = rb_str_new2(path);
1207
+ args[1] = INT2NUM(mode);
1208
+ args[2] = wrap_file_info(ffi);
1209
+
1210
+ res = rb_protect((VALUE (*)())unsafe_create,(VALUE) args,&error);
1211
+
1212
+ if (error)
1213
+ {
1214
+ return -(return_error(ENOENT));
1215
+ }
1216
+ else
1217
+ {
1218
+ return 0;
1219
+ }
1056
1220
  }
1057
1221
 
1058
1222
  //----------------------FTRUNCATE
1059
1223
 
1224
+ static VALUE unsafe_ftruncate(VALUE* args)
1225
+ {
1226
+ VALUE path = args[0];
1227
+ VALUE size = args[1];
1228
+ VALUE ffi = args[2];
1229
+
1230
+ struct fuse_context *ctx = fuse_get_context();
1231
+
1232
+ return rb_funcall(fuse_object,rb_intern("ftruncate"),4,wrap_context(ctx),
1233
+ path, size, ffi);
1234
+ }
1235
+
1060
1236
  static int rf_ftruncate(const char *path, off_t size,
1061
1237
  struct fuse_file_info *ffi)
1062
1238
  {
1063
- // TODO
1064
- return 0;
1239
+ VALUE args[3];
1240
+ VALUE res;
1241
+ int error = 0;
1242
+
1243
+ args[0] = rb_str_new2(path);
1244
+ args[1] = INT2NUM(size);
1245
+ args[2] = wrap_file_info(ffi);
1246
+
1247
+ res = rb_protect((VALUE (*)())unsafe_ftruncate,(VALUE) args,&error);
1248
+
1249
+ if (error)
1250
+ {
1251
+ return -(return_error(ENOENT));
1252
+ }
1253
+ else
1254
+ {
1255
+ return 0;
1256
+ }
1065
1257
  }
1066
1258
 
1067
1259
  //----------------------FGETATTR
1068
1260
 
1261
+ static VALUE unsafe_fgetattr(VALUE *args)
1262
+ {
1263
+ VALUE path = args[0];
1264
+ VALUE ffi = args[1];
1265
+
1266
+ struct fuse_context *ctx = fuse_get_context();
1267
+
1268
+ return rb_funcall(fuse_object,rb_intern("fgetattr"),3,wrap_context(ctx),
1269
+ path,ffi);
1270
+ }
1271
+
1069
1272
  static int rf_fgetattr(const char *path, struct stat *stbuf,
1070
1273
  struct fuse_file_info *ffi)
1071
1274
  {
1072
- // TODO
1073
- return 0;
1275
+ VALUE args[2];
1276
+ VALUE res;
1277
+ int error = 0;
1278
+
1279
+ args[0] = rb_str_new2(path);
1280
+ args[1] = wrap_file_info(ffi);
1281
+
1282
+ res=rb_protect((VALUE (*)())unsafe_fgetattr,(VALUE) args,&error);
1283
+
1284
+ if (error || (res == Qnil))
1285
+ {
1286
+ return -(return_error(ENOENT));
1287
+ }
1288
+ else
1289
+ {
1290
+ rstat2stat(res,stbuf);
1291
+ return 0;
1292
+ }
1074
1293
  }
1075
1294
 
1076
1295
  //----------------------LOCK
1077
1296
 
1297
+ static VALUE unsafe_lock(VALUE *args)
1298
+ {
1299
+ VALUE path = args[0];
1300
+ VALUE ffi = args[1];
1301
+ VALUE cmd = args[2];
1302
+ VALUE lock = args[3];
1303
+
1304
+ struct fuse_context *ctx = fuse_get_context();
1305
+
1306
+ return rb_funcall(fuse_object,rb_intern("lock"),5,wrap_context(ctx),
1307
+ path,ffi,cmd,lock);
1308
+ }
1309
+
1078
1310
  static int rf_lock(const char *path, struct fuse_file_info *ffi,
1079
1311
  int cmd, struct flock *lock)
1080
1312
  {
1081
- // TODO
1082
- return 0;
1313
+ VALUE args[4];
1314
+ VALUE res;
1315
+ int error = 0;
1316
+
1317
+ //Create a struct for the lock structure
1318
+ VALUE s = rb_const_get(rb_cObject,rb_intern("Struct"));
1319
+ VALUE lockc = rb_funcall(s,rb_intern("new"),5,
1320
+ ID2SYM(rb_intern("l_type")),
1321
+ ID2SYM(rb_intern("l_whence")),
1322
+ ID2SYM(rb_intern("l_start")),
1323
+ ID2SYM(rb_intern("l_len")),
1324
+ ID2SYM(rb_intern("l_pid"))
1325
+ );
1326
+
1327
+ VALUE locko = rb_funcall(lockc,rb_intern("new"),5,
1328
+ UINT2NUM(lock->l_type),
1329
+ UINT2NUM(lock->l_whence),
1330
+ UINT2NUM(lock->l_start),
1331
+ UINT2NUM(lock->l_len),
1332
+ UINT2NUM(lock->l_pid)
1333
+ );
1334
+
1335
+ args[0] = rb_str_new2(path);
1336
+ args[1] = wrap_file_info(ffi);
1337
+ args[2] = INT2NUM(cmd);
1338
+ args[3] = locko;
1339
+
1340
+ res = rb_protect((VALUE (*)())unsafe_lock,(VALUE) args,&error);
1341
+
1342
+ if (error)
1343
+ {
1344
+ return -(return_error(ENOENT));
1345
+ }
1346
+ else
1347
+ {
1348
+ return 0;
1349
+ }
1083
1350
  }
1084
1351
 
1085
1352
  //----------------------UTIMENS
@@ -1138,10 +1405,39 @@ static int rf_utimens(const char * path, const struct timespec tv[2])
1138
1405
 
1139
1406
  //----------------------BMAP
1140
1407
 
1408
+ static VALUE unsafe_bmap(VALUE *args)
1409
+ {
1410
+ VALUE path = args[0];
1411
+ VALUE blocksize = args[1];
1412
+ VALUE idx = args[2];
1413
+
1414
+ struct fuse_context *ctx = fuse_get_context();
1415
+
1416
+ return rb_funcall( fuse_object, rb_intern("bmap"), 4, wrap_context(ctx),
1417
+ path, blocksize, idx);
1418
+ }
1419
+
1141
1420
  static int rf_bmap(const char *path, size_t blocksize, uint64_t *idx)
1142
1421
  {
1143
- //TODO
1144
- return 0;
1422
+ VALUE args[3];
1423
+ VALUE res;
1424
+ int error = 0;
1425
+
1426
+ args[0] = rb_str_new2(path);
1427
+ args[1] = INT2NUM(blocksize);
1428
+ args[2] = LL2NUM(*idx);
1429
+
1430
+ res = rb_protect((VALUE (*)())unsafe_bmap,(VALUE) args, &error);
1431
+
1432
+ if (error)
1433
+ {
1434
+ return -(return_error(ENOENT));
1435
+ }
1436
+ else
1437
+ {
1438
+ *idx = NUM2LL(args[2]);
1439
+ return 0;
1440
+ }
1145
1441
  }
1146
1442
 
1147
1443
  //----------------------IOCTL
@@ -1275,13 +1571,13 @@ static VALUE rf_initialize(
1275
1571
  if (RESPOND_TO(self,"write"))
1276
1572
  inf->fuse_op.write = rf_write;
1277
1573
  if (RESPOND_TO(self,"statfs"))
1278
- inf->fuse_op.statfs = rf_statfs; //TODO
1574
+ inf->fuse_op.statfs = rf_statfs;
1279
1575
  if (RESPOND_TO(self,"flush"))
1280
1576
  inf->fuse_op.flush = rf_flush;
1281
1577
  if (RESPOND_TO(self,"release"))
1282
1578
  inf->fuse_op.release = rf_release;
1283
1579
  if (RESPOND_TO(self,"fsync"))
1284
- inf->fuse_op.fsync = rf_fsync; // TODO
1580
+ inf->fuse_op.fsync = rf_fsync;
1285
1581
  if (RESPOND_TO(self,"setxattr"))
1286
1582
  inf->fuse_op.setxattr = rf_setxattr;
1287
1583
  if (RESPOND_TO(self,"getxattr"))
@@ -1299,23 +1595,23 @@ static VALUE rf_initialize(
1299
1595
  if (RESPOND_TO(self,"fsyncdir"))
1300
1596
  inf->fuse_op.fsyncdir = rf_fsyncdir;
1301
1597
  if (RESPOND_TO(self,"init"))
1302
- inf->fuse_op.init = rf_init; // TODO
1598
+ inf->fuse_op.init = rf_init;
1303
1599
  if (RESPOND_TO(self,"destroy"))
1304
- inf->fuse_op.destroy = rf_destroy; // TODO
1600
+ inf->fuse_op.destroy = rf_destroy;
1305
1601
  if (RESPOND_TO(self,"access"))
1306
- inf->fuse_op.access = rf_access; // TODO
1602
+ inf->fuse_op.access = rf_access;
1307
1603
  if (RESPOND_TO(self,"create"))
1308
- inf->fuse_op.create = rf_create; // TODO
1604
+ inf->fuse_op.create = rf_create;
1309
1605
  if (RESPOND_TO(self,"ftruncate"))
1310
- inf->fuse_op.ftruncate = rf_ftruncate; // TODO
1606
+ inf->fuse_op.ftruncate = rf_ftruncate;
1311
1607
  if (RESPOND_TO(self,"fgetattr"))
1312
- inf->fuse_op.fgetattr = rf_fgetattr; // TODO
1608
+ inf->fuse_op.fgetattr = rf_fgetattr;
1313
1609
  if (RESPOND_TO(self,"lock"))
1314
- inf->fuse_op.lock = rf_lock; // TODO
1610
+ inf->fuse_op.lock = rf_lock;
1315
1611
  if (RESPOND_TO(self,"utimens"))
1316
1612
  inf->fuse_op.utimens = rf_utimens;
1317
1613
  if (RESPOND_TO(self,"bmap"))
1318
- inf->fuse_op.bmap = rf_bmap; // TODO
1614
+ inf->fuse_op.bmap = rf_bmap;
1319
1615
  if (RESPOND_TO(self,"ioctl"))
1320
1616
  inf->fuse_op.ioctl = rf_ioctl; // TODO
1321
1617
  if (RESPOND_TO(self,"poll"))
data/sample/test-ruby.rb CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/ruby -rubygems
1
+ #!/usr/bin/ruby
2
2
 
3
3
  # TestFS for RFuse-ng
4
4
 
@@ -122,26 +122,43 @@ class MyFile
122
122
  end
123
123
  end
124
124
 
125
- #TODO: atime,mtime,ctime...nicer classes not only fixnums
126
125
  class Stat
127
126
  attr_accessor :uid,:gid,:mode,:size,:atime,:mtime,:ctime
128
127
  attr_accessor :dev,:ino,:nlink,:rdev,:blksize,:blocks
129
- def initialize(uid,gid,mode,size,atime,mtime,ctime,rdev,blocks,nlink,dev,ino,blksize)
130
- @uid=uid
131
- @gid=gid
132
- @mode=mode
133
- @size=size
134
- @atime=atime
135
- @mtime=mtime
136
- @ctime=ctime
137
- @dev=dev
138
- @ino=ino
139
- @nlink=nlink
140
- @rdev=rdev
141
- @blksize=blksize
142
- @blocks=blocks
143
- end
144
- end #class Stat
128
+ def initialize
129
+ @uid = 0
130
+ @gid = 0
131
+ @mode = 0
132
+ @size = 0
133
+ @atime = 0
134
+ @mtime = 0
135
+ @ctime = 0
136
+ @dev = 0
137
+ @ino = 0
138
+ @nlink = 0
139
+ @rdev = 0
140
+ @blksize = 0
141
+ @blocks = 0
142
+ end
143
+ end
144
+
145
+ class StatVfs
146
+ attr_accessor :f_bsize,:f_frsize,:f_blocks,:f_bfree,:f_bavail
147
+ attr_accessor :f_files,:f_ffree,:f_favail,:f_fsid,:f_flag,:f_namemax
148
+ def initialize
149
+ @f_bsize = 0
150
+ @f_frsize = 0
151
+ @f_blocks = 0
152
+ @f_bfree = 0
153
+ @f_bavail = 0
154
+ @f_files = 0
155
+ @f_ffree = 0
156
+ @f_favail = 0
157
+ @f_fsid = 0
158
+ @f_flag = 0
159
+ @f_namemax = 0
160
+ end
161
+ end
145
162
 
146
163
  class MyFuse < RFuse::Fuse
147
164
 
@@ -168,8 +185,13 @@ class MyFuse < RFuse::Fuse
168
185
  d=@root.search(path)
169
186
  if d.isdir then
170
187
  d.each {|name,obj|
171
- stat=Stat.new(obj.uid,obj.gid,obj.mode,obj.size,obj.actime,obj.modtime,
172
- 0,0,0,0,0,0,0)
188
+ stat = Stat.new
189
+ stat.uid = obj.uid
190
+ stat.gid = obj.gid
191
+ stat.mode = obj.mode
192
+ stat.size = obj.size
193
+ stat.atime = obj.actime
194
+ stat.mtime = obj.modtime
173
195
  filler.push(name,stat,0)
174
196
  }
175
197
  else
@@ -178,9 +200,14 @@ class MyFuse < RFuse::Fuse
178
200
  end
179
201
 
180
202
  def getattr(ctx,path)
181
- d=@root.search(path)
182
- stat=Stat.new(d.uid,d.gid,d.mode,d.size,d.actime,d.modtime,
183
- 0,0,0,0,0,0,0)
203
+ d = @root.search(path)
204
+ stat = Stat.new
205
+ stat.uid = d.uid
206
+ stat.gid = d.gid
207
+ stat.mode = d.mode
208
+ stat.size = d.size
209
+ stat.atime = d.actime
210
+ stat.mtime = d.modtime
184
211
  return stat
185
212
  end #getattr
186
213
 
@@ -192,8 +219,8 @@ class MyFuse < RFuse::Fuse
192
219
  @root.insert_obj(MyFile.new(File.basename(path),mode,ctx.uid,ctx.gid),path)
193
220
  end #mknod
194
221
 
195
- #def open(ctx,path,ffi)
196
- #end
222
+ def open(ctx,path,ffi)
223
+ end
197
224
 
198
225
  #def release(ctx,path,fi)
199
226
  #end
@@ -303,6 +330,31 @@ class MyFuse < RFuse::Fuse
303
330
  #def fsyncdir(ctx,path,meta,ffi)
304
331
  #end
305
332
 
333
+ # Some random numbers to show with df command
334
+ def statfs(ctx,path)
335
+ s = StatVfs.new
336
+ s.f_bsize = 1024
337
+ s.f_frsize = 1024
338
+ s.f_blocks = 1000000
339
+ s.f_bfree = 500000
340
+ s.f_bavail = 990000
341
+ s.f_files = 10000
342
+ s.f_ffree = 9900
343
+ s.f_favail = 9900
344
+ s.f_fsid = 23423
345
+ s.f_flag = 0
346
+ s.f_namemax = 10000
347
+ return s
348
+ end
349
+
350
+ def init(ctx,rfuseconninfo)
351
+ print "init called\n"
352
+ print "proto_major: "
353
+ print rfuseconninfo.proto_major
354
+ print "\n"
355
+ return nil
356
+ end
357
+
306
358
  end #class Fuse
307
359
 
308
360
  fo = MyFuse.new("/tmp/fuse",["allow_other"],["debug"], MyDir.new("",493));
@@ -318,7 +370,5 @@ end
318
370
  begin
319
371
  fo.loop
320
372
  rescue
321
- f=File.new("/tmp/error","w+")
322
- f.puts "Error:" + $!
323
- f.close
373
+ print "Error:" + $!
324
374
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rfuse-ng
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - !binary |
@@ -11,7 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2010-05-03 00:00:00 +02:00
14
+ date: 2010-06-20 00:00:00 +02:00
15
15
  default_executable:
16
16
  dependencies: []
17
17