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



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

#contentsObject

Returns the value of attribute contents.



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

def contents
  @contents
end

#flagsObject (readonly)

Returns the value of attribute flags.



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

def flags
  @flags
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

#rawObject

Returns the value of attribute raw.



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

def raw
  @raw
end

Instance Method Details

#accmodeObject



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

#createObject



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

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

#flushObject



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_modeObject



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