-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtoyrw.py
48 lines (42 loc) · 1.57 KB
/
toyrw.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import fuse
import stat
import errno
import time
class ToyStat(fuse.Stat):
def __init__(self):
"""
The following stat structure members are implemented.
"""
self.st_mode = 0 # (protection bits)
self.st_ino = 0 # (inode number)
self.st_dev = 0 # (device)
self.st_nlink = 0 # (number of hard links)
self.st_uid = 500 # (user ID of owner)
self.st_gid = 500 # (group ID of owner)
self.st_size = 0 # (size of file, in bytes)
self.st_atime = 0 # (time of most recent access)
self.st_mtime = 0 # (time of most recent content modification)
self.st_ctime = 0 # (time of most recent metadata change)
# Helper for Toy filesystem
class Toy():
def __init__(self):
self.data = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. In augue sapien, congue fermentum tortor ut, consequat maximus posuere.\n'
def getattr(self, path):
st = ToyStat()
if path.endswith('.txt'):
st.st_mode = stat.S_IFREG | 0644
st.st_size = len(self.data)
else:
st.st_mode = stat.S_IFDIR | 0755
return st
def readdir(self, path):
contents = {
'/': ['hello', 'world', 'docs'],
'/hello': ['welt'],
'/hello/welt': ['last_level'],
'/docs': ['readme.txt']
}
res = ['.','..'] + contents.get(path)
return res
def read(self, path, length, offset):
return self.data