#!/usr/bin/env ruby require '/home/jj/dev/ruby-fuse-ro/fuserofs' require 'socket' require 'timeout' class JjFS < FuseROFS def rq(r) begin @socket.puts r.length.to_s @socket.write r len = @socket.gets.to_i @socket.read len or raise rescue count ||= 0 raise if count > 3 count += 1 connect_socket retry end end def connect_socket @socket = TCPSocket.new @host, @port end def initialize(url) super() raise 'Unparsed url' unless md = %r{jjfs://([\w.-]+)(:\d+)?(/.*)}.match(url) @control_dir = '.rjjfs-ctrl/' @host, @port, @rootdir = md.captures @port ||= 10987 @port = @port.to_i @socket = nil @cache_timeout = 3600 @minreadsize = 32*1024 file_accessor_int :minreadsize file_accessor :rootdir, :host, :port connect_socket end def get_file_content(path, off) rq("read #{off} #@minreadsize #{@rootdir + path}") end def directory_listing(path) rq("dir #{@rootdir + path}").split("\n") - %w[. ..] end def get_file_size(path) rq("size #{@rootdir + path}").to_i end end if $0 == __FILE__ begin Timeout::timeout(30, RuntimeError) { JjFS.new(ARGV.shift) }.mount_under(ARGV.shift) rescue puts $! puts "Usage : #$0 [jjfs://host[:port]/[rootdir/] " end end