-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclient_functions.py
103 lines (78 loc) · 2.95 KB
/
client_functions.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/python
from fuse import Fuse
from time import time
import errno
import fuse
import stat # for file properties
import os # for filesystem modes (O_RDONLY, etc)
import errno # for error number codes (ENOENT, etc)
# - note: these must be returned as negatives
fuse.fuse_python_api = fuse.FUSE_PYTHON_API_VERSION
class MyStat(fuse.Stat):
def __init__(self, posix_st):
self.st_mode = posix_st.st_mode
self.st_ino = posix_st.st_ino
self.st_dev = posix_st.st_dev
self.st_nlink = posix_st.st_nlink
self.st_uid = os.getuid() # posix_st.st_uid
self.st_gid = os.getgid() # posix_st.st_gid
self.st_size = posix_st.st_size
self.st_atime = posix_st.st_atime
self.st_mtime = posix_st.st_mtime
self.st_ctime = posix_st.st_ctime
HANDLERS = None
class MoshFS(Fuse):
def __init__(self, *args, **kwargs):
if 'handlers' in kwargs:
global HANDLERS
self.handlers = kwargs['handlers']
HANDLERS = self.handlers
del kwargs['handlers']
self.file_class = self.MoshFile
Fuse.__init__(self, *args, **kwargs)
def getattr(self, path):
posix_st = self.handlers['getattr'](path)
if posix_st == -errno.ENOENT:
return posix_st
fuse_st = MyStat(posix_st)
return fuse_st
def readdir(self, path, offset):
for e in self.handlers['readdir'](path):
yield fuse.Direntry(e)
def unlink(self, path):
self.handlers['unlink'](path)
def rmdir(self, path):
self.handlers['rmdir'](path)
def mkdir(self, path, mode):
self.handlers['mkdir'](path, mode)
def readlink(self, path):
return self.handlers['readlink'](path)
def symlink(self, path, path1):
self.handlers['symlink'](path, path1)
def link(self, path, path1):
self.handlers['link'](path, path1)
def rename(self, path, path1):
self.handlers['rename'](path, path1)
def utime(self, path, times):
self.handlers['utime'](path, times)
class MoshFile(object):
def __init__(self, path, flags, mode=0777):
global HANDLERS
self.handlers = HANDLERS
self.file = self.handlers['open'](path, flags, mode)
def read(self, length, offset):
return self.handlers['read'](self.file, length, offset)
def write(self, buf, offset):
return self.handlers['write'](self.file, buf, offset)
def release(self, flags):
self.handlers['release'](self.file)
def fsync(self, isfsyncfile):
self.handlers['fsync'](self.file, isfsyncfile)
def flush(self):
self.handlers['flush'](self.file)
def fgetattr(self):
return self.handlers['fgetattr'](self.file)
def ftruncate(self, len):
self.handlers['ftruncate'](self.file)
def main(self, *args, **kwargs):
return Fuse.main(self, *args, **kwargs)