rfuse-ng 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/sample/test-ruby.rb CHANGED
@@ -1,4 +1,6 @@
1
- #!/usr/bin/ruby
1
+ #!/usr/bin/ruby -rubygems
2
+
3
+ # TestFS for RFuse-ng
2
4
 
3
5
  require "rfuse_ng"
4
6
 
@@ -43,27 +45,27 @@ class MyDir < Hash
43
45
  end
44
46
  return d
45
47
  end
48
+ def remove_obj(path)
49
+ d=self.search(File.dirname(path))
50
+ d.delete(File.basename(path))
51
+ end
46
52
  def search(path)
47
- puts "searching: " + path
48
53
  p=path.split('/').delete_if {|x| x==''}
49
54
  if p.length==0 then
50
- puts "found root"
51
55
  return self
52
56
  else
53
57
  return self.follow(p)
54
58
  end
55
59
  end
56
60
  def follow (path_array)
57
- puts "following: " + path_array.to_s
58
61
  if path_array.length==0 then
59
- puts "found me!" + @name
60
62
  return self
61
63
  else
62
64
  d=self[path_array.shift]
63
65
  if d then
64
- return d.follow(path_array)
66
+ return d.follow(path_array)
65
67
  else
66
- raise Errno::ENOENT.new
68
+ raise Errno::ENOENT.new
67
69
  end
68
70
  end
69
71
  end
@@ -148,12 +150,23 @@ class MyFuse < RFuse::Fuse
148
150
  @root=root
149
151
  end
150
152
 
153
+ # The old, deprecated way: getdir
154
+ #def getdir(ctx,path,filler)
155
+ # d=@root.search(path)
156
+ # if d.isdir then
157
+ # d.each {|name,obj|
158
+ # # Use push_old to add this entry, no need for Stat here
159
+ # filler.push_old(name, obj.mode, 0)
160
+ # }
161
+ # else
162
+ # raise Errno::ENOTDIR.new(path)
163
+ # end
164
+ #end
165
+
166
+ # The new readdir way, c+p-ed from getdir
151
167
  def readdir(ctx,path,filler,offset,ffi)
152
- puts "readdir:"+path
153
- puts ctx
154
168
  d=@root.search(path)
155
169
  if d.isdir then
156
- puts "getdir: listing directory"
157
170
  d.each {|name,obj|
158
171
  stat=Stat.new(obj.uid,obj.gid,obj.mode,obj.size,obj.actime,obj.modtime,
159
172
  0,0,0,0,0,0,0)
@@ -165,185 +178,130 @@ class MyFuse < RFuse::Fuse
165
178
  end
166
179
 
167
180
  def getattr(ctx,path)
168
- puts "getattr:" + path
169
- puts ctx
170
181
  d=@root.search(path)
171
182
  stat=Stat.new(d.uid,d.gid,d.mode,d.size,d.actime,d.modtime,
172
183
  0,0,0,0,0,0,0)
173
- puts d
174
184
  return stat
175
185
  end #getattr
176
186
 
177
187
  def mkdir(ctx,path,mode)
178
- puts "mkdir:" + path + " Mode:" + mode.to_s
179
- puts ctx
180
188
  @root.insert_obj(MyDir.new(File.basename(path),mode),path)
181
189
  end #mkdir
182
190
 
183
191
  def mknod(ctx,path,mode,dev)
184
- puts "mknod:" + path + " Mode:" + mode.to_s + " Device:" + dev.to_s
185
- puts ctx
186
192
  @root.insert_obj(MyFile.new(File.basename(path),mode,ctx.uid,ctx.gid),path)
187
193
  end #mknod
188
194
 
189
- def open(ctx,path,ffi)
190
- puts "open:" + path
191
- puts ctx
192
- end
195
+ #def open(ctx,path,ffi)
196
+ #end
193
197
 
194
- def release(ctx,path,fi)
195
- puts "release:" + path
196
- puts ctx
197
- end
198
+ #def release(ctx,path,fi)
199
+ #end
198
200
 
199
- def flush(ctx,path,fi)
200
- puts "flush:" + path
201
- puts ctx
202
- end
201
+ #def flush(ctx,path,fi)
202
+ #end
203
203
 
204
204
  def chmod(ctx,path,mode)
205
- puts "chmod:" + path + " Mode:" + mode.to_s
206
- puts ctx
207
205
  d=@root.search(path)
208
- d.mode=mode #TODO: check if this is ok for dir
209
- #raise Errno::EPERM.new(path)
206
+ d.mode=mode
210
207
  end
211
208
 
212
209
  def chown(ctx,path,uid,gid)
213
- puts "chown:" + path + " UID:" + uid.to_s + " GID:" + gid.to_s
214
- puts ctx
215
210
  d=@root.search(path)
216
211
  d.uid=uid
217
212
  d.gid=gid
218
213
  end
219
214
 
220
215
  def truncate(ctx,path,offset)
221
- puts "truncate:" + path + " offset: " + offset.to_s
222
- puts ctx
216
+ d=@root.search(path)
217
+ d.content = d.content[0..offset]
223
218
  end
224
219
 
225
220
  def utime(ctx,path,actime,modtime)
226
- puts "utime:" + path + " actime:" + actime.to_s +
227
- " modtime:" + modtime.to_s
228
- puts ctx
229
221
  d=@root.search(path)
230
222
  d.actime=actime
231
223
  d.modtime=modtime
232
224
  end
233
225
 
234
226
  def unlink(ctx,path)
235
- puts "utime:" + path
236
- puts ctx
227
+ @root.remove_obj(path)
237
228
  end
238
229
 
239
230
  def rmdir(ctx,path)
240
- puts "rmdir:" + path
241
- puts ctx
231
+ @root.remove_obj(path)
242
232
  end
243
233
 
244
- def symlink(ctx,path,as)
245
- puts "symlink:" + path + " as:" + as
246
- puts ctx
247
- end
234
+ #def symlink(ctx,path,as)
235
+ #end
248
236
 
249
237
  def rename(ctx,path,as)
250
- puts "rename:" + path + " as:" + as
251
- puts ctx
238
+ d = @root.search(path)
239
+ @root.remove_obj(path)
240
+ @root.insert_obj(d,path)
252
241
  end
253
242
 
254
- def link(ctx,path,as)
255
- puts "link:" + path + " as:" + as
256
- puts ctx
257
- end
243
+ #def link(ctx,path,as)
244
+ #end
258
245
 
259
246
  def read(ctx,path,size,offset,fi)
260
- puts "read:" + path + " size:" + size.to_s + " offset:" + offset.to_s
261
- puts ctx
262
- d=@root.search(path)
247
+ d = @root.search(path)
263
248
  if (d.isdir)
264
249
  raise Errno::EISDIR.new(path)
265
250
  return nil
266
251
  else
267
- return d.content
252
+ return d.content[offset..offset + size - 1]
268
253
  end
269
254
  end
270
255
 
271
- def write(ctx,path,buf,size,offset,fi)
272
- puts "write:" + path + " size:" + size.to_s + " offset:" + offset.to_s
273
- puts ctx
274
- puts "content:" + buf
256
+ def write(ctx,path,buf,offset,fi)
275
257
  d=@root.search(path)
276
258
  if (d.isdir)
277
259
  raise Errno::EISDIR.new(path)
278
260
  else
279
- d.content=buf
261
+ d.content[offset..offset+buf.length - 1] = buf
280
262
  end
281
- return nil
263
+ return buf.length
282
264
  end
283
265
 
284
266
  def setxattr(ctx,path,name,value,size,flags)
285
- puts
286
- "setxattr:" + path +
287
- " name:" + name +
288
- " value:" + value.inspect +
289
- " size:" + size.to_s +
290
- " flags:" + flags.to_s +
291
- " rubysize:" + value.size.to_s
292
- puts ctx
293
267
  d=@root.search(path)
294
268
  d.setxattr(name,value,flags)
295
269
  end
296
270
 
297
271
  def getxattr(ctx,path,name,size)
298
- puts
299
- "getxattr:" + path +
300
- " name:" + name +
301
- " size:" + size.to_s
302
- puts ctx
303
272
  d=@root.search(path)
304
273
  if (d)
305
- puts "found:" + d.name
306
274
  value=d.getxattr(name)
307
- if (value)
308
- puts "return: "+value.to_s + " size:"+value.size.to_s
309
- else
275
+ if (!value)
310
276
  value=""
311
277
  #raise Errno::ENOENT.new #TODO raise the correct error :
312
278
  #NOATTR which is not implemented in Linux/glibc
313
279
  end
314
280
  else
315
- raise Errno::ENOENT.new #TODO put this into DIR and FILE?
281
+ raise Errno::ENOENT.new
316
282
  end
317
283
  return value
318
284
  end
319
285
 
320
286
  def listxattr(ctx,path,size)
321
- puts "listxattr:" + path + " size:" + size.to_s
322
- puts ctx
323
287
  d=@root.search(path)
324
288
  value= d.listxattr()
325
- puts "listxattr return: "+ value
326
289
  return value
327
290
  end
328
291
 
329
292
  def removexattr(ctx,path,name)
330
- puts "removexattr:" + path + " name:" + name
331
- puts ctx
332
293
  d=@root.search(path)
333
294
  d.removexattr(name)
334
295
  end
335
296
 
336
- def opendir(ctx,path,ffi)
337
- puts 'opendir:'+ path
338
- end
297
+ #def opendir(ctx,path,ffi)
298
+ #end
339
299
 
340
- def releasedir(ctx,path,ffi)
341
- puts 'releasedir:'+ path
342
- end
300
+ #def releasedir(ctx,path,ffi)
301
+ #end
343
302
 
344
- def fsyncdir(ctx,path,meta,ffi)
345
- puts 'fsyncdir:'+ path
346
- end
303
+ #def fsyncdir(ctx,path,meta,ffi)
304
+ #end
347
305
 
348
306
  end #class Fuse
349
307
 
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.2.0
4
+ version: 0.3.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-01 00:00:00 +02:00
14
+ date: 2010-05-03 00:00:00 +02:00
15
15
  default_executable:
16
16
  dependencies: []
17
17