Class: FuseFS::FileHandle
- Inherits:
-
Object
- Object
- FuseFS::FileHandle
- Defined in:
- lib/fuse/rfusefs-fuse.rb
Constant Summary collapse
- @@fh =
0
Instance Attribute Summary collapse
-
#contents ⇒ Object
Returns the value of attribute contents.
-
#flags ⇒ Object
readonly
Returns the value of attribute flags.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#raw ⇒ Object
Returns the value of attribute raw.
Instance Method Summary collapse
- #accmode ⇒ Object
- #append? ⇒ Boolean
- #create ⇒ Object
- #flush ⇒ Object
-
#initialize(path, flags) ⇒ FileHandle
constructor
A new instance of FileHandle.
- #modified? ⇒ Boolean
- #raw_mode ⇒ Object
- #rdonly? ⇒ Boolean
- #rdwr? ⇒ Boolean
- #read(offset, size) ⇒ Object
- #reading? ⇒ Boolean
- #write(offset, data) ⇒ Object
- #writing? ⇒ Boolean
- #wronly? ⇒ Boolean
Constructor Details
#initialize(path, flags) ⇒ FileHandle
13 14 15 16 17 18 19 20 |
# File 'lib/fuse/rfusefs-fuse.rb', line 13 def initialize(path,flags) @id = (@@fh += 1) @flags = flags @path = path @modified = false @contents = "" @size = 0 end |
Instance Attribute Details
#contents ⇒ Object
Returns the value of attribute contents.
12 13 14 |
# File 'lib/fuse/rfusefs-fuse.rb', line 12 def contents @contents end |
#flags ⇒ Object (readonly)
Returns the value of attribute flags.
11 12 13 |
# File 'lib/fuse/rfusefs-fuse.rb', line 11 def flags @flags end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
11 12 13 |
# File 'lib/fuse/rfusefs-fuse.rb', line 11 def id @id end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
11 12 13 |
# File 'lib/fuse/rfusefs-fuse.rb', line 11 def path @path end |
#raw ⇒ Object
Returns the value of attribute raw.
12 13 14 |
# File 'lib/fuse/rfusefs-fuse.rb', line 12 def raw @raw end |
Instance Method Details
#accmode ⇒ Object
53 54 55 |
# File 'lib/fuse/rfusefs-fuse.rb', line 53 def accmode flags & Fcntl::O_ACCMODE end |
#append? ⇒ Boolean
69 70 71 |
# File 'lib/fuse/rfusefs-fuse.rb', line 69 def append? writing? && (flags & Fcntl::O_APPEND != 0) end |
#create ⇒ Object
26 27 28 29 |
# File 'lib/fuse/rfusefs-fuse.rb', line 26 def create @contents = "" @modified = true end |
#flush ⇒ Object
44 45 46 47 |
# File 'lib/fuse/rfusefs-fuse.rb', line 44 def flush @modified = false contents end |
#modified? ⇒ Boolean
49 50 51 |
# File 'lib/fuse/rfusefs-fuse.rb', line 49 def modified? @modified end |
#raw_mode ⇒ Object
81 82 83 84 85 86 87 88 89 90 |
# File 'lib/fuse/rfusefs-fuse.rb', line 81 def raw_mode mode_str = case accmode when Fcntl::O_RDWR; "rw" when Fcntl::O_RDONLY; "r" when Fcntl::O_WRONLY; "w" end mode_str << "a" if append? return mode_str end |
#rdonly? ⇒ Boolean
65 66 67 |
# File 'lib/fuse/rfusefs-fuse.rb', line 65 def rdonly? accmode == Fcntl::O_RDONLY end |
#rdwr? ⇒ Boolean
57 58 59 |
# File 'lib/fuse/rfusefs-fuse.rb', line 57 def rdwr? accmode == Fcntl::O_RDWR end |
#read(offset, size) ⇒ Object
22 23 24 |
# File 'lib/fuse/rfusefs-fuse.rb', line 22 def read(offset,size) contents[offset,size] end |
#reading? ⇒ Boolean
73 74 75 |
# File 'lib/fuse/rfusefs-fuse.rb', line 73 def reading? rdonly? || rdwr? end |
#write(offset, data) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/fuse/rfusefs-fuse.rb', line 31 def write(offset,data) # TODO: why append? if append? || offset >= contents.length #ignore offset #TODO: should this zero fill? contents << data else contents[offset,data.length]=data end @modified = true return data.length end |
#writing? ⇒ Boolean
77 78 79 |
# File 'lib/fuse/rfusefs-fuse.rb', line 77 def writing? wronly? || rdwr? end |
#wronly? ⇒ Boolean
61 62 63 |
# File 'lib/fuse/rfusefs-fuse.rb', line 61 def wronly? accmode == Fcntl::O_WRONLY end |