Module: FFI::Libfuse::Filesystem::Ruby::VirtualFile
- Includes:
- VirtualNode
- Included in:
- VirtualFile
- Defined in:
- lib/ffi/libfuse/filesystem/virtual_file.rb
Overview
Filesystem methods representing a single synthetic file at the root and satisfying Satisfies the contract of Adapter::Ruby
Instance Attribute Summary collapse
-
#content ⇒ String
readonly
The (binary) content of the synthetic file.
-
#nlink ⇒ Integer
readonly
The number of links to this file.
Attributes included from VirtualNode
#accounting, #virtual_stat, #virtual_xattr
FUSE Callbacks collapse
-
#create(_path, mode, ffi = nil) ⇒ Object
A file handled (captured by Adapter::Ruby::Prepend).
- #getattr(path, stat = nil, ffi = nil) ⇒ Object
- #link(_target, path) ⇒ Object
- #open(_path, ffi) ⇒ Object
- #truncate(path, size, ffi = nil) ⇒ Object
- #unlink(path) ⇒ Object
-
#write(path, data, offset = 0, _ffi = nil) ⇒ Object
write(const char* path, char buf, size_t size, off_t offset, struct fuse_file_info fi).
Instance Method Summary collapse
-
#initialize(accounting: nil) ⇒ Object
Create an empty synthetic file.
Methods included from VirtualNode
#chmod, #chown, #getxattr, #init_node, #listxattr, #statfs, #utimens
Instance Attribute Details
#content ⇒ String (readonly)
Returns the (binary) content of the synthetic file.
16 17 18 |
# File 'lib/ffi/libfuse/filesystem/virtual_file.rb', line 16 def content @content end |
#nlink ⇒ Integer (readonly)
Returns the number of links to this file.
19 20 21 |
# File 'lib/ffi/libfuse/filesystem/virtual_file.rb', line 19 def nlink @nlink end |
Instance Method Details
#create(_path, mode, ffi = nil) ⇒ Object
Returns a file handled (captured by Adapter::Ruby::Prepend).
40 41 42 43 44 45 |
# File 'lib/ffi/libfuse/filesystem/virtual_file.rb', line 40 def create(_path, mode, ffi = nil) init_node(mode) @content = String.new(encoding: 'binary') @nlink = 1 sio(ffi) if ffi end |
#getattr(path, stat = nil, ffi = nil) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/ffi/libfuse/filesystem/virtual_file.rb', line 28 def getattr(path, stat = nil, ffi = nil) # We don't exist until create or otherwise or virtual stat exists raise Errno::ENOENT unless root?(path) && virtual_stat stat&.file(size: (ffi&.fh || content).size, nlink: nlink, **virtual_stat) self end |
#initialize(accounting: nil) ⇒ Object
Create an empty synthetic file
22 23 24 |
# File 'lib/ffi/libfuse/filesystem/virtual_file.rb', line 22 def initialize(accounting: nil) super end |
#link(_target, path) ⇒ Object
69 70 71 72 73 74 75 |
# File 'lib/ffi/libfuse/filesystem/virtual_file.rb', line 69 def link(_target, path) raise Errno::ENOENT unless root?(path) accounting&.adjust(content.size, 1) if @nlink.zero? @nlink += 1 self end |
#open(_path, ffi) ⇒ Object
47 48 49 50 |
# File 'lib/ffi/libfuse/filesystem/virtual_file.rb', line 47 def open(_path, ffi) virtual_stat[:atime] = Time.now.utc sio(ffi) end |
#truncate(path, size, ffi = nil) ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/ffi/libfuse/filesystem/virtual_file.rb', line 61 def truncate(path, size, ffi = nil) raise Errno::ENOENT unless root?(path) accounting&.truncate(content.size, size) sio(ffi).truncate(size) virtual_stat[:mtime] = Time.now.utc end |
#unlink(path) ⇒ Object
77 78 79 80 81 82 |
# File 'lib/ffi/libfuse/filesystem/virtual_file.rb', line 77 def unlink(path) raise Errno::ENOENT unless root?(path) @nlink -= 1 accounting&.adjust(-content.size, -1) if @nlink.zero? end |
#write(path, data, offset = 0, _ffi = nil) ⇒ Object
write(const char* path, char buf, size_t size, off_t offset, struct fuse_file_info fi)
53 54 55 56 57 58 59 |
# File 'lib/ffi/libfuse/filesystem/virtual_file.rb', line 53 def write(path, data, offset = 0, _ffi = nil) raise Errno::ENOENT unless root?(path) accounting&.write(content.size, data.size, offset) virtual_stat[:mtime] = Time.now.utc nil # just let the sio in ffi handle it end |