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.2.3"
- FUSE_MAJOR_VERSION =
The underlying FUSE library major version
INT2FIX(FUSE_MAJOR_VERSION)
- FUSE_MINOR_VERSION =
The underlyfing FUSE library minor versoin
INT2FIX(FUSE_MINOR_VERSION)
Class Method Summary collapse
-
.main(argv = ARGV, extra_options = [], extra_options_usage = nil, device = nil, exec = File.basename($0)) {|options, argv| ... } ⇒ Object
Convenience method to launch a fuse filesystem, with nice usage messages and default signal traps.
-
.parse_options(argv, *local_opts) ⇒ Hash<Symbol,String|Boolean>
Parse mount arguments and options.
-
.usage(device = nil, exec = File.basename($0)) ⇒ String
Generate a usage string.
Class Method Details
.main(argv = ARGV, extra_options = [], extra_options_usage = nil, device = nil, exec = File.basename($0)) {|options, argv| ... } ⇒ Object
Convenience method to launch a fuse filesystem, with nice usage messages and default signal traps
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 |
# File 'lib/rfuse.rb', line 204 def self.main(argv=ARGV,=[],=nil,device=nil,exec=File.basename($0)) = (argv,*) unless [:mountpoint] $stderr.puts "rfuse: failed, no mountpoint provided" puts usage(device,exec) return nil end if [:help] puts usage(device,exec) # TODO: In Fuse 3.0 this looks like it will move to $stdout help_io = STDERR help_io.puts "Fuse options: (#{FUSE_MAJOR_VERSION}.#{FUSE_MINOR_VERSION})" help_io.puts " -h help - print this help output" help_io.puts " -d |-o debug enable internal FUSE debug output" help_io.puts "" help_io.flush() # Cause Fuse kernel Options to print, but don't actually start a filesystem Fuse.new(*argv) if help_io.puts "Filesystem options:" help_io.puts end return nil end begin fs = yield ,argv raise Error, "no filesystem provided" unless fs fuse = create(fs,argv,,) raise Error, "filesystem #{fs} not mounted" unless fuse && fuse.mounted? fuse.run rescue Error => fuse_ex # These errors are produced generally because the user passed bad arguments etc.. puts usage(device,exec) unless [:help] $stderr.puts "rfuse failed: #{fuse_ex.}" return nil rescue => ex # These are other errors related the yield block $stderr.puts ex. $stderr.puts ex.backtrace.join("\n") 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.rb>#<device> mountpoint [options...]
mount.fuse </path/to/fs.rb>#<device> mountpoint [options...]
both result in the following command execution
/path/to/fs.rb [device] mountpoint [-h] [-d] [-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
- if -h was supplied - will print help text (and not mount the filesystem!):debug
- if -d (or -o debug) was supplied - will print debug output from the underlying FUSE library
and any other supplied options.
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 114 115 |
# File 'lib/rfuse.rb', line 74 def self.(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 = argv[opt_index].split(",") .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 .empty? argv.slice!(opt_index - 1,2) else argv[opt_index] = .join(",") end end result end |
.usage(device = nil, exec = File.basename($0)) ⇒ String
Generate a usage string
122 123 124 |
# File 'lib/rfuse.rb', line 122 def self.usage(device=nil,exec=File.basename($0)) "Usage:\n #{exec} #{device} mountpoint [-h] [-d] [-o [opt,optkey=value,...]]\n" end |