Class: FuseFS::FileHandle

Inherits:
Object
  • Object
show all
Defined in:
lib/fuse/rfusefs-fuse.rb

Constant Summary collapse

@@fh =
0

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#contentsObject

Returns the value of attribute contents.



13
14
15
# File 'lib/fuse/rfusefs-fuse.rb', line 13

def contents
  @contents
end

#flagsObject (readonly)

Returns the value of attribute flags.



12
13
14
# File 'lib/fuse/rfusefs-fuse.rb', line 12

def flags
  @flags
end

#idObject (readonly)

Returns the value of attribute id.



12
13
14
# File 'lib/fuse/rfusefs-fuse.rb', line 12

def id
  @id
end

#pathObject (readonly)

Returns the value of attribute path.



12
13
14
# File 'lib/fuse/rfusefs-fuse.rb', line 12

def path
  @path
end

#rawObject

Returns the value of attribute raw.



13
14
15
# File 'lib/fuse/rfusefs-fuse.rb', line 13

def raw
  @raw
end

Instance Method Details

#accmodeObject



54
55
56
# File 'lib/fuse/rfusefs-fuse.rb', line 54

def accmode
  flags & Fcntl::O_ACCMODE
end

#append?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/fuse/rfusefs-fuse.rb', line 70

def append?
  writing? && (flags & Fcntl::O_APPEND != 0)
end

#createObject



27
28
29
30
# File 'lib/fuse/rfusefs-fuse.rb', line 27

def create
  @contents = ""
  @modified = true
end

#flushObject



45
46
47
48
# File 'lib/fuse/rfusefs-fuse.rb', line 45

def flush
  @modified = false
  contents
end

#modified?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/fuse/rfusefs-fuse.rb', line 50

def modified?
  @modified
end

#raw_modeObject



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

Returns:

  • (Boolean)


66
67
68
# File 'lib/fuse/rfusefs-fuse.rb', line 66

def rdonly?
  accmode == Fcntl::O_RDONLY
end

#rdwr?Boolean

Returns:

  • (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

Returns:

  • (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

Returns:

  • (Boolean)


78
79
80
# File 'lib/fuse/rfusefs-fuse.rb', line 78

def writing?
  wronly? || rdwr?
end

#wronly?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/fuse/rfusefs-fuse.rb', line 62

def wronly?
  accmode == Fcntl::O_WRONLY
end