Module: FuseFS

Defined in:
lib/rfusefs.rb,
lib/fusefs.rb,
lib/fuse/fusedir.rb,
lib/fusefs/dirlink.rb,
lib/fusefs/metadir.rb,
lib/fuse/rfusefs-fuse.rb,
lib/fusefs/pathmapper.rb,
lib/fusefs/sqlitemapper.rb

Overview

This is FuseFS compatible module built over RFuse

Defined Under Namespace

Classes: DirLink, FileHandle, Fuse, FuseDir, MetaDir, PathMapperFS, SqliteMapperFS, StatsHelper

Constant Summary collapse

RFUSEFS_COMPATIBILITY =

Which raw api should we use?

true
DEFAULT_FS =
FuseDir.new()

Class Method Summary collapse

Class Method Details

.exitObject

Exit the run loop and teardown FUSE

Most useful from Signal.trap() or Kernel.at_exit()


147
148
149
# File 'lib/rfusefs.rb', line 147

def FuseFS.exit
    @fuse.exit if @fuse
end

.handle_editor(bool) ⇒ Object

Deprecated.

Not supported in RFuseFS.

The original FuseFS had special handling for editor swap/backup files which appears to be a workaround for a bug where zero length files where never written to. This “bug” is fixed since RFuseFS 1.0.2



170
171
172
# File 'lib/rfusefs.rb', line 170

def self.handle_editor(bool)
    #do nothing
end

.main(argv = ARGV, options = [], option_usage = "", device = nil, exec = File.basename($0)) {|options| ... } ⇒ Object

Convenience method to launch a FuseFS filesystem with nice error messages

Examples:

MY_OPTIONS = [ :myfs ]
OPTION_USAGE = "  -o myfs=VAL how to use the myfs option"

# Normally from the command line...
ARGV = [ "some/device", "/mnt/point", "-h", "-o", "debug,myfs=aValue" ]

FuseFS.main(ARGV, MY_OPTIONS, OPTION_USAGE, "/path/to/somedevice", $0) do |options|

    # options ==
       { :device => "some/device",
         :mountpoint => "/mnt/point",
         :help => true,
         :debug => true,
         :myfs => "aValue"
       }

    fs = MyFS.new(options)
end

Parameters:

  • argv (Array<String>) (defaults to: ARGV)

    command line arguments

  • options (Array<Symbol>) (defaults to: [])

    list of additional options

  • option_usage (String) (defaults to: "")

    describing additional option usage

  • device (String) (defaults to: nil)

    a description of the device field

  • exec (String) (defaults to: File.basename($0))

    the executable file

Yield Parameters:

  • options (Hash<Symbol,String>)

    options parsed from ARGV including…

    * :device - the optional mount device
    * :mountpoint - required mountpoint
    * :help - true if -h was supplied
    

Yield Returns:

  • (FuseDir)

    an RFuseFS filesystem



47
48
49
50
51
52
53
# File 'lib/rfusefs.rb', line 47

def FuseFS.main(argv=ARGV,options=[],option_usage="",device=nil,exec=File.basename($0))
    RFuse.main(argv,options,option_usage,device,exec) do |options,argv|
        root = yield options
        FuseFS.set_root(root)
        FuseFS.mount_under(*argv)
    end
end

.mount(root, mountpoint, *opts) ⇒ void

Note:

This is an RFuseFS extension

This method returns an undefined value.

Forks start so you can access your filesystem with ruby File operations (eg for testing).



79
80
81
82
83
84
85
86
87
# File 'lib/rfusefs.rb', line 79

def FuseFS.mount(root,mountpoint,*opts)

    pid = Kernel.fork do
        status = FuseFS.start(root,mountpoint,*opts)
        Kernel.exit!(status)
    end
    @mounts[mountpoint] = pid
    pid
end

.mount_under(mountpoint, *args) ⇒ Fuse

This will cause FuseFS to virtually mount itself under the given path. set_root must have been called previously.

Parameters:

  • mountpoint (String)

    an existing directory where the filesystem will be virtually mounted

  • args (Array<String>)

Returns:

  • (Fuse)

    the mounted fuse filesystem These are as expected by the “mount” command. Note in particular that the first argument is expected to be the mount point. For more information, see fuse.sourceforge.net and the manual pages for “mount.fuse”



130
131
132
# File 'lib/rfusefs.rb', line 130

def FuseFS.mount_under(mountpoint, *args)
    @fuse = Fuse.new(@fs,mountpoint,*args)
end

.reader_gidFixnum

Returns the calling process gid.

Returns:

  • (Fixnum)

    the calling process gid



159
160
161
# File 'lib/rfusefs.rb', line 159

def self.reader_gid
    Thread.current[:fusefs_reader_gid]
end

.reader_uidFixnum

Returns the calling process uid You can use this in determining your permissions, or even provide different files for different users.

Returns:

  • (Fixnum)

    the calling process uid You can use this in determining your permissions, or even provide different files for different users.



154
155
156
# File 'lib/rfusefs.rb', line 154

def self.reader_uid
    Thread.current[:fusefs_reader_uid]
end

.runObject

Note:

RFuseFS extension

This is the main loop waiting on, then executing, filesystem operations from the kernel.

Note: Running in a separate thread is generally not useful. In particular

you cannot use Ruby File operations to access your filesystem from
within the ruby process that calls run.


141
142
143
# File 'lib/rfusefs.rb', line 141

def FuseFS.run
    @fuse.run()
end

.set_root(root) ⇒ void

This method returns an undefined value.

Set the root virtual directory

Parameters:

  • root (Object)

    an object implementing a subset of API



118
119
120
# File 'lib/rfusefs.rb', line 118

def FuseFS.set_root(root)
    @fs=Fuse::Root.new(root)
end

.start(root, mountpoint, *opts) ⇒ void

Note:

RFuseFS extension

This method returns an undefined value.

Start the FuseFS root at mountpoint with opts.

If not previously set, Signal traps for “TERM” and “INT” are added to exit the filesystem

Parameters:



65
66
67
68
69
70
71
72
73
# File 'lib/rfusefs.rb', line 65

def FuseFS.start(root,mountpoint,*opts)
    FuseFS.set_root(root)
    begin
        FuseFS.mount_under(mountpoint,*opts)
        FuseFS.run
    ensure
        FuseFS.unmount()
    end
end

.unmount(mountpoint = nil) ⇒ void

Note:

RFuseFS extension

This method returns an undefined value.

Unmount a filesystem

Parameters:

  • mountpoint (String) (defaults to: nil)

    If nil?, unmounts the filesystem started with start otherwise signals the forked process started with mount to exit and unmount.



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/rfusefs.rb', line 95

def FuseFS.unmount(mountpoint=nil)

    if (mountpoint)
        if @mounts.has_key?(mountpoint)
            pid = @mounts[mountpoint]
            Process.kill(:TERM,pid)
            Process.waitpid(pid)
        else
            raise "Unknown mountpoint #{mountpoint}"
        end
    else
        #Local unmount, make sure we only try to unmount once
        if @fuse && @fuse.mounted?
            print "Unmounting #{@fuse.mountname}\n"
            @fuse.unmount()
        end
        @fuse = nil
    end
end