Module: FFI::Libfuse::Adapter::Ruby
- Defined in:
- lib/ffi/libfuse/adapter/ruby.rb
Overview
This module assists with converting native C libfuse into idiomatic and duck-typed Ruby behaviour
Class Method helpers
These functions deal with the native fuse FFI::Pointers, Buffers etc
The class ReaddirFiller assists with the complexity of the readdir callback
FUSE Callbacks
Including this module in a Filesystem module changes the method signatures for callbacks to be more idiomatic ruby (via prepending Prepend). It also includes the type 1 adapters Context, Debug and Safe
Filesystems that return IO like objects from ##open need not implement other file io operations Similarly Filesystems that return Dir like objects from ##opendir need not implement ##readdir
Defined Under Namespace
Modules: Prepend Classes: ReaddirFiller
FUSE Callbacks collapse
-
#create(path, mode, fuse_file_info) ⇒ Object
abstract
File creation.
- #fsync(path, datasync, fuse_file_info) ⇒ Object abstract
-
#getxattr(path, name) ⇒ nil|String
abstract
Get extended attribute.
-
#listxattr(path) ⇒ Array<String>
abstract
List extended attributes.
-
#open(path, fuse_file_info) ⇒ Object
abstract
File open.
-
#opendir(path, fuse_file_info) ⇒ Object
abstract
Directory open.
-
#read(path, size, offset, ffi) ⇒ Array<Object,Integer>, nil|false
abstract
Read file data.
-
#read_buf(path, size, offset, info) ⇒ Array<Object,Integer>, nil|false
abstract
Read file data directly from a buffer.
-
#readdir(path, offset, fuse_file_info, readdir_plus: ) {|name, stat:, offset:, fill_dir_plus:| ... } ⇒ void
abstract
List directory entries.
-
#readlink(path, size) ⇒ String
abstract
Resolve target of a symbolic link.
-
#setxattr(path, name, data, flags) ⇒ void
abstract
Set extended attribute.
-
#utimens(path, atime, mtime, fuse_file_info = nil) ⇒ void
abstract
Change the access and/or modification times of a file with nanosecond resolution.
-
#write(path, data, offset, ffi) ⇒ Integer, ...
abstract
Write file data.
-
#write_buf(path, offset, ffi, &buffer) {|io = nil, *flags| ... } ⇒ Integer, nil|false
abstract
Write buffered data to a file via one of the following techniques.
Class Method Summary collapse
-
.getxattr(buf, size) ⇒ Object
Helper for implementing FuseOperations#getxattr.
-
.listxattr(buf, size) ⇒ Object
Helper for implementing FuseOperations#listxattr.
-
.read(buf, size, offset = nil) { ... } ⇒ Integer
Helper for implementing FuseOperations#read.
-
.read_buf(bufp, size, offset = nil) { ... } ⇒ Integer
Helper for implementing FuseOperations#read_buf.
-
.readlink(buf, size) { ... } ⇒ void
Helper for implementing FuseOperations#readlink.
-
.rescue_not_implemented ⇒ Object
Helper to rescue not implemented or not supported errors from sub-filesystems @return[Object] result of block @return[nil] if block raises NotImplementedError or Errno::ENOTSUP.
-
.write(buf, size) {|data| ... } ⇒ Integer
Helper to implement #FuseOperations#write yields the data and receives expects IO to write the data to @yield(data).
-
.write_buf(bufv) {|data| ... } ⇒ Integer
Helper to implement #FuseOperations#write_buf.
Class Method Details
.getxattr(buf, size) ⇒ Object
Helper for implementing FuseOperations#getxattr
703 704 705 706 707 708 709 710 711 712 713 714 |
# File 'lib/ffi/libfuse/adapter/ruby.rb', line 703 def getxattr(buf, size) res = yield raise Errno::ENODATA unless res res = res.to_s return res.size if size.zero? raise Errno::ERANGE if res.size > size buf.write_bytes(res) res.size end |
.listxattr(buf, size) ⇒ Object
Helper for implementing FuseOperations#listxattr
720 721 722 723 724 725 726 727 728 729 730 731 |
# File 'lib/ffi/libfuse/adapter/ruby.rb', line 720 def listxattr(buf, size) res = yield res.reduce(0) do |offset, name| name = name.to_s unless size.zero? raise Errno::ERANGE if offset + name.size >= size buf.put_string(offset, name) # put string includes the NUL terminator end offset + name.size + 1 end end |
.read(buf, size, offset = nil) { ... } ⇒ Integer
Helper for implementing FuseOperations#read
619 620 621 622 623 624 625 626 627 628 |
# File 'lib/ffi/libfuse/adapter/ruby.rb', line 619 def read(buf, size, offset = nil) io = yield raise Errno::ENOTSUP unless io data = Libfuse::IO.read(io, size, offset) raise Errno::ERANGE unless data.size <= size buf.write_bytes(data) data.size end |
.read_buf(bufp, size, offset = nil) { ... } ⇒ Integer
Helper for implementing FuseOperations#read_buf
640 641 642 643 644 645 646 647 648 |
# File 'lib/ffi/libfuse/adapter/ruby.rb', line 640 def read_buf(bufp, size, offset = nil) io = yield raise Errno::ENOTSUP unless io fbv = io.is_a?(FuseBufVec) ? io : FuseBufVec.create(io, size, offset) fbv.store_to(bufp) 0 end |
.readlink(buf, size) { ... } ⇒ void
This method returns an undefined value.
Helper for implementing FuseOperations#readlink
600 601 602 603 604 605 606 607 |
# File 'lib/ffi/libfuse/adapter/ruby.rb', line 600 def readlink(buf, size) link = yield raise Errno::ENOTSUP unless link raise Errno::ENAMETOOLONG unless link.size < size # includes terminating NUL buf.put_string(0, link) # with NULL terminator. 0 end |
.rescue_not_implemented ⇒ Object
Helper to rescue not implemented or not supported errors from sub-filesystems @return[Object] result of block @return[nil] if block raises NotImplementedError or Errno::ENOTSUP
586 587 588 589 590 |
# File 'lib/ffi/libfuse/adapter/ruby.rb', line 586 def rescue_not_implemented yield rescue NotImplementedError, Errno::ENOTSUP nil end |
.write(buf, size) {|data| ... } ⇒ Integer
Helper to implement #FuseOperations#write yields the data and receives expects IO to write the data to @yield(data)
661 662 663 664 665 666 667 668 669 670 671 |
# File 'lib/ffi/libfuse/adapter/ruby.rb', line 661 def write(buf, size) data = buf.read_bytes(size) if buf.respond_to?(:read_bytes) data ||= buf.to_s io, offset = yield data raise Errno::ENOSUP unless io return io if io.is_a?(Integer) Libfuse::IO.write(io, data, offset) end |
.write_buf(bufv) {|data| ... } ⇒ Integer
Helper to implement #FuseOperations#write_buf
Yields firstly with data = nil A returned truthy object is sent to buvf.copy_to_io Otherwise yields again with string data from bufv.copy_to_str expecting the caller to write the data and return the number of bytes written
690 691 692 693 694 695 696 |
# File 'lib/ffi/libfuse/adapter/ruby.rb', line 690 def write_buf(bufv) fh, *flags = yield nil # what kind of result do we want return bufv.copy_to_io(fh, offset, *flags) if fh data = bufv.copy_to_str(*flags) yield data || (raise Errno::ENOTSUP) end |
Instance Method Details
#create(path, mode, fuse_file_info) ⇒ Object
File creation
|
# File 'lib/ffi/libfuse/adapter/ruby.rb', line 373
|
#fsync(path, datasync, fuse_file_info) ⇒ Object
|
# File 'lib/ffi/libfuse/adapter/ruby.rb', line 567
|
#getxattr(path, name) ⇒ nil|String
Get extended attribute
|
# File 'lib/ffi/libfuse/adapter/ruby.rb', line 525
|
#listxattr(path) ⇒ Array<String>
List extended attributes
|
# File 'lib/ffi/libfuse/adapter/ruby.rb', line 533
|
#open(path, fuse_file_info) ⇒ Object
File open
|
# File 'lib/ffi/libfuse/adapter/ruby.rb', line 380
|
#opendir(path, fuse_file_info) ⇒ Object
Directory open
|
# File 'lib/ffi/libfuse/adapter/ruby.rb', line 404
|
#read(path, size, offset, ffi) ⇒ Array<Object,Integer>, nil|false
|
# File 'lib/ffi/libfuse/adapter/ruby.rb', line 456
|
#read_buf(path, size, offset, info) ⇒ Array<Object,Integer>, nil|false
|
# File 'lib/ffi/libfuse/adapter/ruby.rb', line 470
|
#readdir(path, offset, fuse_file_info, readdir_plus: ) {|name, stat:, offset:, fill_dir_plus:| ... } ⇒ void
This method returns an undefined value.
List directory entries
The filesystem may choose between three modes of operation:
1) The readdir implementation ignores the offset parameter yielding only name, and optional stat The yield will always return true so the whole directory is read in a single readdir operation.
2) The readdir implementation keeps track of the offsets of the directory entries. It uses the offset parameter to restart the iteration and yields non-zero offsets for each entry. When the buffer is full, or an error occurs, yielding to the filler function will return false. Subsequent yields will raise StopIteration
3) Return a Dir like object from #opendir and do not implement this method. The directory will be enumerated from offset via calling :seek, :read and :tell on fuse_file_info.fh
|
# File 'lib/ffi/libfuse/adapter/ruby.rb', line 493
|
#readlink(path, size) ⇒ String
Resolve target of a symbolic link
|
# File 'lib/ffi/libfuse/adapter/ruby.rb', line 485
|
#setxattr(path, name, data, flags) ⇒ void
This method returns an undefined value.
Set extended attribute
|
# File 'lib/ffi/libfuse/adapter/ruby.rb', line 540
|
#utimens(path, atime, mtime, fuse_file_info = nil) ⇒ void
Either atime or mtime can be nil corresponding to utimensat(2) receiving UTIME_OMIT. The special value UTIME_NOW passed from Fuse is automatically set to the current time
This method returns an undefined value.
Change the access and/or modification times of a file with nanosecond resolution
|
# File 'lib/ffi/libfuse/adapter/ruby.rb', line 552
|
#write(path, data, offset, ffi) ⇒ Integer, ...
|
# File 'lib/ffi/libfuse/adapter/ruby.rb', line 412
|
#write_buf(path, offset, ffi, &buffer) {|io = nil, *flags| ... } ⇒ Integer, nil|false
Write buffered data to a file via one of the following techniques
Yield object and flags to &buffer to write data directly to a FuseBufVec, File or IO and return the yield result (number of bytes written)
Yield with no params (or explicitly nil and flags) to retrieve String data (via FuseBufVec#copy_to_str) to write to path@offset, returning the number of bytes written (eg data.size)
Return nil, false or do not implement to
|
# File 'lib/ffi/libfuse/adapter/ruby.rb', line 425
|