[ANN] FuseFS-0.5

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

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.

On Sat, 2005-10-29 at 16:52 +0900, Greg Millam wrote:

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

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)

···

On 29/10/05, Greg Millam <ruby-talk@lethalcode.net> wrote:

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

--
Rasputin :: Jack of All Trades - Master of Nuns
http://number9.hellooperator.net/

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! :slight_smile:

Cool.
Kent.

···

On Sun, 2005-10-30 at 05:18 +0900, Kent Sibilev wrote:

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.

On Sat, 2005-10-29 at 16:52 +0900, Greg Millam wrote:
> 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
>

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

Regards,
Ryan

···

On 10/29/05, Kent Sibilev wrote:

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.

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 Sibilev wrote:

> 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! :slight_smile:
>
> 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.
>>
>>> 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!

···

On Sun, 2005-10-30 at 05:18 +0900, Kent Sibilev wrote:

>> On Sat, 2005-10-29 at 16:52 +0900, Greg Millam wrote:
>>>
>>> http://rubyforge.org/projects/fusefs/
>>>
>>> Happy coding!
>>>
>>> - Greg