-
Notifications
You must be signed in to change notification settings - Fork 0
/
tosfs.py
executable file
·204 lines (163 loc) · 5.4 KB
/
tosfs.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
Program do montowania obrazów dysku .DSK z system TOS.
Użycie, np.
mkdir disk
./tosfs.py MUSIC.DSK disk
cd disk
ls
cd -
Odmontowanie:
fusermount -u disk
"""
import array
import errno # for error number codes (ENOENT, etc)
# - note: these must be returned as negatives
import fuse
import os
import stat # for file properties
import sys
from TOSDSK import *
fuse.fuse_python_api = (0, 2)
class TOSFS(fuse.Fuse):
"""
"""
def __init__(self, *args, **kw):
fuse.Fuse.__init__(self, *args, **kw)
self.dsk = DSK(sys.argv[-2])
self.dsk.show_header()
self.tos = TOS(self.dsk)
print 'Init complete.'
def getattr(self, path):
"""
- st_mode (protection bits)
- st_ino (inode number)
- st_dev (device)
- st_nlink (number of hard links)
- st_uid (user ID of owner)
- st_gid (group ID of owner)
- st_size (size of file, in bytes)
- st_atime (time of most recent access)
- st_mtime (time of most recent content modification)
- st_ctime (platform dependent; time of most recent metadata change on Unix,
or the time of creation on Windows).
"""
st = fuse.Stat()
st.st_mode = stat.S_IFDIR | 0755
st.st_nlink = 2
st.st_atime = 0
st.st_mtime = st.st_atime
st.st_ctime = st.st_atime
st.st_uid = st.st_gid = 501
st.st_ino = 0
st.st_size = 0
c = path.count("/")
if c == 1:
nr_of_dir = 0
filename = path[1:]
else:
dd = path.split("/")
ff = "/".join(dd[1:-1])
i = self.tos.names[ff]
nr_of_dir = self.tos.entries[i][-1][0]
filename = dd[-1]
for i in self.tos.entries:
if i[NR_OF_DIR] == nr_of_dir and filename == i[NAME]:
if not i[NAME].endswith("DIR"):
st.st_mode = stat.S_IFREG | 0644
st.st_ino = i[0]
st.st_size = self.tos.get_size(i)
return st
print '*** getattr', path
#print 'self.dupa', self.dupa
#depth = getDepth(path) # depth of path, zero-based from root
#pathparts = getParts(path) # the actual parts of the path
if path == "/":
pass
else:
return -errno.ENOENT
return st
def readdir(self, path, offset):
print "readdir: path =",path,"offset =",offset
if path == "/":
nr_of_dir = 0
else:
i = self.tos.names[path[1:]]
nr_of_dir = self.tos.entries[i][-1][0]
print nr_of_dir
entries = [fuse.Direntry("."), fuse.Direntry("..")]
ee = filter(lambda x: x[NR_OF_DIR] == nr_of_dir and x[NO] == 0, self.tos.entries)
e = map(lambda x: fuse.Direntry(x[NAME]), ee)
#print ee
return entries + e
# def getdir(self, path):
# """
# return: [[('file1', 0), ('file2', 0), ... ]]
# """
# print '*** getdir', path
# return -errno.ENOSYS
# def mythread ( self ):
# print '*** mythread'
# return -errno.ENOSYS
# def chmod ( self, path, mode ):
# print '*** chmod', path, oct(mode)
# return -errno.ENOSYS
# def chown ( self, path, uid, gid ):
# print '*** chown', path, uid, gid
# return -errno.ENOSYS
# def fsync ( self, path, isFsyncFile ):
# print '*** fsync', path, isFsyncFile
# return -errno.ENOSYS
# def link ( self, targetPath, linkPath ):
# print '*** link', targetPath, linkPath
# return -errno.ENOSYS
# def mkdir ( self, path, mode ):
# print '*** mkdir', path, oct(mode)
# return -errno.ENOSYS
# def mknod ( self, path, mode, dev ):
# print '*** mknod', path, oct(mode), dev
# return -errno.ENOSYS
def open ( self, path, flags ):
log('*** open path=%s flags=%d' % (path, flags))
return None
def read ( self, path, length, offset ):
log('*** read %s %d %d' % (path, length, offset))
data = self.tos.read_file(path[1:])
log("length = %d" % len(data))
return data[offset:offset+length].tostring()
#return -errno.ENOENT
# def readlink ( self, path ):
# print '*** readlink', path
# return -errno.ENOSYS
# def release ( self, path, flags ):
# print '*** release', path, flags
# return -errno.ENOSYS
# def rename ( self, oldPath, newPath ):
# print '*** rename', oldPath, newPath
# return -errno.ENOSYS
# def rmdir ( self, path ):
# print '*** rmdir', path
# return -errno.ENOSYS
# def statfs ( self ):
# print '*** statfs'
# return -errno.ENOSYS
# def symlink ( self, targetPath, linkPath ):
# print '*** symlink', targetPath, linkPath
# return -errno.ENOSYS
# def truncate ( self, path, size ):
# print '*** truncate', path, size
# return -errno.ENOSYS
# def unlink ( self, path ):
# print '*** unlink', path
# return -errno.ENOSYS
# def utime ( self, path, times ):
# print '*** utime', path, times
# return -errno.ENOSYS
# def write ( self, path, buf, offset ):
# print '*** write', path, buf, offset
# return -errno.ENOSYS
if __name__ == "__main__":
fs = TOSFS()
fs.parse(errex = 1)
fs.main()