-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtp.py
200 lines (150 loc) · 3.86 KB
/
tp.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
from typing import Optional
from vendor.fs import *
# TRAVAUX PRATIQUES INF2 : LE SYSTEME DE FICHIER
#
# Ce TP contient des fonctions qu'il vous appartient de comprendre,
# implémenter, tester. Par défaut, pour l'instant les fonctions
# affichent seulement leur nom.
#
# Pensez à regarder l'évolution du cache ...
############################################################
# INIT
############################################################
# disk_size → taille du disque en secteurs
# cache_size → taille du cache en blocs
def init(disk_name, disk_size, cache_size):
fs_make_disk(disk_name, disk_size)
fs_init_cache(cache_size)
fs_format_disk(disk_name, disk_size)
fs_init_dcache()
print("**************************************************")
print("\nTEST de init, création du votre premier disque:\n")
init("MY1stDISK", 10, 3)
fs_log_off()
# DUMP
def dump(disk_name: str) -> None:
fs_dump_disk(disk_name)
fs_dump_cache()
fs_dump_dcache()
print("**************************************************")
print("\nTEST de DUMP:\n")
dump("MY1stDISK")
# LS
def ls(param: Optional[str] = None) -> object:
if param is None:
res = []
for i in fs_list_in_dcache():
res.append(name_of_node(i))
else:
res = fs_lookup_in_dcache(param)
return res
print("**************************************************")
print("\nTEST de LS:\n")
print("ls")
print(ls())
print(ls("jenesuispasla"))
print(ls("."))
print(ls(".."))
# SYNC
def sync() -> None:
fs_sync_cache()
print("**************************************************")
print("\nTEST de SYNC:\n")
sync()
dump("MY1stDISK")
# MKDIR
def mkdir(name: str) -> bool:
if name in ls():
return False
free_block = fs_getfreeblock()
if free_block is None:
return False
fs_mkdir_in_dcache(name, free_block)
return True
print("**************************************************")
print("\nTEST de MKDIR:\n")
mkdir("my1stdir")
print(ls())
dump("MY1stDISK")
sync()
dump("MY1stDISK")
# CD
def cd(name: str) -> bool:
if name in ls() and is_DNODE(fs_lookup_in_dcache(name)):
fs_cd_in_dcache(name)
success = True
else:
success = False
return success
print("**************************************************")
print("\nTEST de CD, MKDIR et SYNC:\n")
print(cd("my1stdir"))
print(ls())
mkdir("bach")
print(ls())
mkdir("mozart")
print(ls())
mkdir("berlioz")
print(ls())
dump("MY1stDISK")
sync()
dump("MY1stDISK")
print(cd("mozart"))
print(cd("debussy"))
# TOUCH
def touch(name: str) -> bool:
fs_touch_in_dcache(name, fs_getfreeblock())
return bool(ls(name))
print("**************************************************")
print("\nTEST de TOUCH:\n")
touch("son1")
touch("toto")
touch("mon fichier")
print(ls())
dump("MY1stDISK")
sync()
dump("MY1stDISK")
# WRITE
def write(name: str, contents: str) -> bool:
if name in ls() and is_FNODE(fs_lookup_in_dcache(name)):
fs_write_in_dcache(name, contents)
success = True
else:
success = False
return success
print("**************************************************")
print("\nTEST de WRITE:\n")
write("son1", "sisidoréré")
dump("MY1stDISK")
sync()
dump("MY1stDISK")
# READ
def read(name: str) -> str:
if name in ls() and is_FNODE(fs_lookup_in_dcache(name)):
res = fs_read_in_dcache(name)
else:
res = None
return res
print("**************************************************")
print("\nTEST de READ:\n")
print(read("read"))
print(read("son1"))
print(read("fichierquinexistepas"))
# RM
def rm(name: str) -> bool:
if name in ls():
fs_rm_in_dcache(name)
success = True
else:
success = False
return success
print("**************************************************")
print("\nTEST de RM:\n")
print(ls())
rm("son1")
print(ls())
cd("..")
dump("MY1stDISK")
sync()
dump("MY1stDISK")
fs_stats()