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
Returns a new instance of FileHandle.
14 15 16 17 18 19 20 21 |
# File 'lib/fuse/rfusefs-fuse.rb', line 14 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.
13 14 15 |
# File 'lib/fuse/rfusefs-fuse.rb', line 13 def contents @contents end |
#flags ⇒ Object (readonly)
Returns the value of attribute flags.
12 13 14 |
# File 'lib/fuse/rfusefs-fuse.rb', line 12 def flags @flags end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
12 13 14 |
# File 'lib/fuse/rfusefs-fuse.rb', line 12 def id @id end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
12 13 14 |
# File 'lib/fuse/rfusefs-fuse.rb', line 12 def path @path end |
#raw ⇒ Object
Returns the value of attribute raw.
13 14 15 |
# File 'lib/fuse/rfusefs-fuse.rb', line 13 def raw @raw end |
Instance Method Details
#accmode ⇒ Object
54 55 56 |
# File 'lib/fuse/rfusefs-fuse.rb', line 54 def accmode flags & Fcntl::O_ACCMODE end |
#append? ⇒ Boolean
70 71 72 |
# File 'lib/fuse/rfusefs-fuse.rb', line 70 def append? writing? && (flags & Fcntl::O_APPEND != 0) end |
#create ⇒ Object
27 28 29 30 |
# File 'lib/fuse/rfusefs-fuse.rb', line 27 def create @contents = "" @modified = true end |
#flush ⇒ Object
45 46 47 48 |
# File 'lib/fuse/rfusefs-fuse.rb', line 45 def flush @modified = false contents end |
#modified? ⇒ Boolean
50 51 52 |
# File 'lib/fuse/rfusefs-fuse.rb', line 50 def modified? @modified end |
#raw_mode ⇒ Object
82 83 84 85 86 87 88 89 90 91 |
# File 'lib/fuse/rfusefs-fuse.rb', line 82 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
66 67 68 |
# File 'lib/fuse/rfusefs-fuse.rb', line 66 def rdonly? accmode == Fcntl::O_RDONLY end |
#rdwr? ⇒ Boolean
58 59 60 |
# File 'lib/fuse/rfusefs-fuse.rb', line 58 def rdwr? accmode == Fcntl::O_RDWR end |
#read(offset, size) ⇒ Object
23 24 25 |
# File 'lib/fuse/rfusefs-fuse.rb', line 23 def read(offset,size) contents[offset,size] end |
#reading? ⇒ Boolean
74 75 76 |
# File 'lib/fuse/rfusefs-fuse.rb', line 74 def reading? rdonly? || rdwr? end |
#write(offset, data) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/fuse/rfusefs-fuse.rb', line 32 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
78 79 80 |
# File 'lib/fuse/rfusefs-fuse.rb', line 78 def writing? wronly? || rdwr? end |
#wronly? ⇒ Boolean
62 63 64 |
# File 'lib/fuse/rfusefs-fuse.rb', line 62 def wronly? accmode == Fcntl::O_WRONLY end |