Module: RFuse

Defined in:
lib/rfuse.rb,
lib/rfuse/version.rb,
ext/rfuse/filler.c,
ext/rfuse/context.c,
ext/rfuse/file_info.c,
ext/rfuse/rfuse_mod.c

Overview

Ruby FUSE (Filesystem in USErspace) binding

Defined Under Namespace

Classes: Context, Error, FileInfo, Filler, Fuse, FuseDelegator, Stat, StatVfs

Constant Summary collapse

VERSION =
"1.0.5"

Class Method Summary collapse

Class Method Details

.packxattr(xattrs) ⇒ Object

Used by listxattr



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/rfuse.rb', line 10

def self.packxattr(xattrs)
    case xattrs
    when Array
        xattrs.join("\000").concat("\000")
    when String
        #assume already \0 separated list of keys
        xattrs
    else
        raise RFuse::Error, ":listxattr must return Array or String, got #{xattrs.inspect}"
    end
end

.parse_options(argv, *local_opts) ⇒ Hash{Symbol => String,Boolean}

Parse mount arguments and options

Fuse itself will normalise arguments

mount -t fuse </path/to/fs>#<device> mountpoint [options...]
mount.fuse </path/to/fs>#<device> mountpoint [options...]

both result in a call to /path/to/fs with arguments…

[device] mountpoint [-h] [-o [opt,optkey=value,...]]

which this method will parse into a Hash with the following special keys

:device - the optional mount device, removed from argv if present
:mountpoint - required mountpoint
:help - true if -h was supplied

and any other supplied options.

Examples:

ARGV = [ "some/device", "/mnt/point", "-h", "-o", "debug,myfs=aValue" ]
options = RFuse.parse_options(ARGV,:myfs)

# options == 
{ :device => "some/device",
  :mountpoint => "/mnt/point",
  :help => true,
  :debug => true,
  :myfs => "aValue"
}
# and ARGV == 
[ "/mnt/point","-h","-o","debug" ]

fs = create_filesystem(options)
fuse = RFuse::FuseDelegator.new(fs,*ARGV)

Parameters:

  • argv (Array<String>)

    normalised fuse options

  • local_opts (Array<Symbol>)

    local options if these are found in the argv entry following “-o” they are removed from argv, ie so argv is a clean set of options that can be passed to Fuse or FuseDelegator

Returns:

  • (Hash{Symbol => String,Boolean})

    the extracted options

Since:

  • 1.0.3



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/rfuse.rb', line 72

def self.parse_options(argv,*local_opts)
    result = Hash.new(nil)
    
    first_opt_index = (argv.find_index() { |opt| opt =~ /-.*/ } || argv.length ) 

    result[:device] = argv.shift if first_opt_index > 1
    result[:mountpoint] = argv[0] if argv.length > 0
    
    if argv.include?("-h")
        result[:help]  =  true
    end

    if argv.include?("-d")
        result[:debug] = true
    end

    opt_index = ( argv.find_index("-o") || -1 ) + 1

    if opt_index > 1 && opt_index < argv.length
        options = argv[opt_index].split(",")

        options.delete_if() do |opt| 
            opt.strip!

            opt,value = opt.split("=",2)
            value = true unless value
            opt_sym = opt.to_sym
            result[opt_sym] = value

            #result of delete if
            local_opts.include?(opt_sym)
        end

        if options.empty?
            argv.slice!(opt_index - 1,2)
        else
            argv[opt_index] = options.join(",")
        end
    end

    result
end

.usage(device = nil, exec = File.basename($0)) ⇒ String

Generate a usage string

Parameters:

  • device (String) (defaults to: nil)

    a description of how the device field should be used

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

    the executable

Returns:

  • (String)

    the usage string



120
121
122
# File 'lib/rfuse.rb', line 120

def self.usage(device=nil,exec=File.basename($0))
    "Usage:\n\t #{exec} #{device} mountpoint [-h] [-o [opt,optkey=value,...]]\n"
end