[ANN] FuseFS-0.5

G

Greg Millam

Lo, another travesty was visited upon the ruby-talk community ... and
this one was named ... FuseFS 0.5!

--------------

FuseFS is a ruby module that lets you define Filesystems in ruby, so you
can navigate a database. Browse virtual filesystems with ls and cd! Or
even, with _why_the_lucky_stiff's railsfs.rb (included in FuseFS 0.5!)
view your Ruby On Rails data on your filesystem! Do you want to know more?

http://redhanded.hobix.com/inspect/railsfsAfterACoupleMinutesOfToolingWithFuseWhoa.html

Aside from the awesome railsfs.rb and the FUSE-2.4 change, what else is
included?

Well, remember how you couldn't get some apps to recognize a file as
being anything other than empty? Well now you can correct that assumption!

fuseroot#size will be called on files, so when xmms tries to load your
ruby-offered mp3, it'll be able to!

And a treat for those working with big (and I mean BIG) files that they
don't want all loaded into ram:

"raw_open" and associated methods will allow fuseroot to receive the
actual, individual read and write requests for each file, so that you
can return portions of a file at a time!

http://rubyforge.org/projects/fusefs/

Happy coding!

- Greg
 
K

Kent Sibilev

Thank you.

I've been playing with new raw API and I've found it somewhat broken.
Please consider this diff:

RCS file: /var/cvs/fusefs/fusefs/ext/fusefs_lib.c,v
retrieving revision 1.9
diff -u -r1.9 fusefs_lib.c
--- fusefs_lib.c 15 Oct 2005 21:48:03 -0000 1.9
+++ fusefs_lib.c 29 Oct 2005 20:07:03 -0000
@@ -637,7 +637,7 @@

newfile->next = opened_head;
opened_head = newfile;
- return 1;
+ return 0;
}
debug(" no.\n");

@@ -845,7 +845,7 @@
/* raw read */
debug(" yes.\n");
rf_call(path,id_raw_close,Qnil);
- return 0;
+ goto out;
}
debug(" no.\n");

@@ -867,6 +867,8 @@
}
}

+out:
+
/* Free the file contents. */
if (!is_editor) {
if (prev == NULL) {
@@ -1246,7 +1248,13 @@
VALUE args = rb_ary_new();
rb_ary_push(args,INT2NUM(offset));
rb_ary_push(args,INT2NUM(size));
- rf_call(path,id_raw_read,args);
+ VALUE ret = rf_call(path,id_raw_read,args);
+ if(ret == Qnil)
+ return 0;
+ StringValue(ret);
+ if(RSTRING(ret)->len < size)
+ size = RSTRING(ret)->len;
+ memcpy(buf, RSTRING(ret)->ptr, size);
return size;
}

Cheers,
Kent.
 
K

Kent Sibilev

Sorry for replying to my previous email. With this patch applied, here
is the simple implementation (less than 100 lines of code) of Ruby
remote filesystem using DRb.

server.rb:
#!/usr/bin/env ruby

require 'drb'

class RemoteDirectory
def initialize(dir)
@dir = dir
@files = {}
end

def contents(path)
Dir[File.join(@dir, path,'*')].map{|fn| File.basename fn}
end

%w|file? directory? executable? size delete|.each do |name|
define_method(name) do |path|
File.send name, File.join(@dir, path)
end
end

%w|mkdir rmdir|.each do |name|
define_method(name) do |path|
Dir.send name, File.join(@dir, path)
end
end

%w|can_write? can_delete? can_mkdir? can_rmdir?|.each do |name|
define_method(name) do |path|
true
end
end

def raw_open(path, mode)
return true if @files.has_key? path
@files[path] = File.open(File.join(@dir, path), mode)
return true
rescue
puts $!
false
end

def raw_read(path, off, size)
file = @files[path]
return unless file
file.seek(off, File::SEEK_SET)
file.read(size)
rescue
puts $!
nil
end

def raw_write(path, off, sz, buf)
file = @files[path]
return unless file
file.seek(off, File::SEEK_SET)
file.write(buf[0, sz])
rescue
puts $!
end

def raw_close(path)
file = @files[path]
return unless file
file.close
@files.delete path
rescue
puts $!
end
end

if $0 == __FILE__
dir = RemoteDirectory.new ARGV.shift || '.'
uri = ARGV.shift || 'druby://0.0.0.0:7777'
DRb.start_service uri, dir
puts DRb.uri
DRb.thread.join
end

rubyfs.rb:
#!/usr/bin/env ruby

require 'drb'
require 'fusefs'

unless (1..2).include? ARGV.size
puts "Usage: #$0 <directory> <uri>"
exit(1)
end

dir = ARGV.shift
uri = ARGV.shift || 'druby://0.0.0.0:7777'

DRb.start_service(nil, nil)
root = DRbObject.new_with_uri(uri)

FuseFS.set_root(root)
FuseFS.mount_under(dir)
FuseFS.run

Now I don't have to use samba in order to access files on my Windows
workstation! :)

Cool.
Kent.
 
R

Ryan Leavengood

Sorry for replying to my previous email. With this patch applied, here
is the simple implementation (less than 100 lines of code) of Ruby
remote filesystem using DRb.

That is massively cool. Thanks for this, and thanks to Greg for
providing FuseFS which allows such cool code to be written!

Regards,
Ryan
 
G

Greg Millam

This is very neat!

I've also applied the bugfixes from Kent, and released 0.5.1 on
rubyforge. 0.5.1 lets Kent's drb filesystem be used.

http://rubyforge.org/projects/fusefs/

Thanks, Kent!

- Greg

Kent said:
Sorry for replying to my previous email. With this patch applied, here
is the simple implementation (less than 100 lines of code) of Ruby
remote filesystem using DRb.

server.rb:
#!/usr/bin/env ruby

require 'drb'

class RemoteDirectory
def initialize(dir)
@dir = dir
@files = {}
end

def contents(path)
Dir[File.join(@dir, path,'*')].map{|fn| File.basename fn}
end

%w|file? directory? executable? size delete|.each do |name|
define_method(name) do |path|
File.send name, File.join(@dir, path)
end
end

%w|mkdir rmdir|.each do |name|
define_method(name) do |path|
Dir.send name, File.join(@dir, path)
end
end

%w|can_write? can_delete? can_mkdir? can_rmdir?|.each do |name|
define_method(name) do |path|
true
end
end

def raw_open(path, mode)
return true if @files.has_key? path
@files[path] = File.open(File.join(@dir, path), mode)
return true
rescue
puts $!
false
end

def raw_read(path, off, size)
file = @files[path]
return unless file
file.seek(off, File::SEEK_SET)
file.read(size)
rescue
puts $!
nil
end

def raw_write(path, off, sz, buf)
file = @files[path]
return unless file
file.seek(off, File::SEEK_SET)
file.write(buf[0, sz])
rescue
puts $!
end

def raw_close(path)
file = @files[path]
return unless file
file.close
@files.delete path
rescue
puts $!
end
end

if $0 == __FILE__
dir = RemoteDirectory.new ARGV.shift || '.'
uri = ARGV.shift || 'druby://0.0.0.0:7777'
DRb.start_service uri, dir
puts DRb.uri
DRb.thread.join
end

rubyfs.rb:
#!/usr/bin/env ruby

require 'drb'
require 'fusefs'

unless (1..2).include? ARGV.size
puts "Usage: #$0 <directory> <uri>"
exit(1)
end

dir = ARGV.shift
uri = ARGV.shift || 'druby://0.0.0.0:7777'

DRb.start_service(nil, nil)
root = DRbObject.new_with_uri(uri)

FuseFS.set_root(root)
FuseFS.mount_under(dir)
FuseFS.run

Now I don't have to use samba in order to access files on my Windows
workstation! :)

Cool.
Kent.

Thank you.
I've been playing with new raw API and I've found it somewhat broken.
Please consider this diff:

RCS file: /var/cvs/fusefs/fusefs/ext/fusefs_lib.c,v
retrieving revision 1.9
diff -u -r1.9 fusefs_lib.c
--- fusefs_lib.c 15 Oct 2005 21:48:03 -0000 1.9
+++ fusefs_lib.c 29 Oct 2005 20:07:03 -0000
@@ -637,7 +637,7 @@

newfile->next = opened_head;
opened_head = newfile;
- return 1;
+ return 0;
}
debug(" no.\n");

@@ -845,7 +845,7 @@
/* raw read */
debug(" yes.\n");
rf_call(path,id_raw_close,Qnil);
- return 0;
+ goto out;
}
debug(" no.\n");

@@ -867,6 +867,8 @@
}
}

+out:
+
/* Free the file contents. */
if (!is_editor) {
if (prev == NULL) {
@@ -1246,7 +1248,13 @@
VALUE args = rb_ary_new();
rb_ary_push(args,INT2NUM(offset));
rb_ary_push(args,INT2NUM(size));
- rf_call(path,id_raw_read,args);
+ VALUE ret = rf_call(path,id_raw_read,args);
+ if(ret == Qnil)
+ return 0;
+ StringValue(ret);
+ if(RSTRING(ret)->len < size)
+ size = RSTRING(ret)->len;
+ memcpy(buf, RSTRING(ret)->ptr, size);
return size;
}

Cheers,
Kent.
so you can navigate a database. Browse virtual filesystems with ls and
cd! Or even, with _why_the_lucky_stiff's railsfs.rb (included in FuseFS
0.5!) view your Ruby On Rails data on your filesystem! Do you want to
know more?as being anything other than empty? Well now you can correct that
assumption!the actual, individual read and write requests for each file, so that
you can return portions of a file at a time!
 
D

Dick Davies

Thanks Greg!

I hear linux 2.6.14 now has FUSE in the base, so this is great timing.

Dick
(who's even more glad he didn't get a powerbook)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

[ANN] FuseFS-0.4 0
[ANN] FuseFS-0.1 6
[ANN] FuseFS 0.6.0 2
[ANN] FuseFS-0.3 1
FuseFS, and ruby threading issues 1
[ANN] Metadata 0.5 17
[ANN] Reiserfs for ruby initial announcement 3
[ANN] Monkeybars 0.5 released 0

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top