Rev 7202 | Rev 7213 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
5598 | pavelyakov | 1 | #ifndef INCLUDE_FILESYSTEM_H |
2 | #define INCLUDE_FILESYSTEM_H |
||
5676 | pavelyakov | 3 | #print "[include |
5598 | pavelyakov | 4 | |
5640 | pavelyakov | 5 | #ifndef INCLUDE_DATE_H |
6 | #include "../lib/date.h" |
||
5598 | pavelyakov | 7 | #endif |
8 | |||
5487 | leency | 9 | :struct f70{ |
3067 | leency | 10 | dword func; |
11 | dword param1; |
||
12 | dword param2; |
||
13 | dword param3; |
||
14 | dword param4; |
||
15 | char rezerv; |
||
16 | dword name; |
||
17 | }; |
||
18 | |||
5487 | leency | 19 | :struct BDVK { |
20 | dword readonly:1, hidden:1, system:1, volume_label:1, isfolder:1, notarchived:1, :0; |
||
3067 | leency | 21 | byte type_name; |
4898 | leency | 22 | byte rez1, rez2, selected; |
5487 | leency | 23 | dword timecreate; |
24 | date datecreate; |
||
3067 | leency | 25 | dword timelastaccess; |
5487 | leency | 26 | date datelastaccess; |
3067 | leency | 27 | dword timelastedit; |
5487 | leency | 28 | date datelastedit; |
3067 | leency | 29 | dword sizelo; |
30 | dword sizehi; |
||
31 | char name[518]; |
||
32 | }; |
||
33 | |||
34 | |||
5487 | leency | 35 | |
36 | |||
5640 | pavelyakov | 37 | |
38 | /////////////////////////// |
||
39 | // Параметры файла // |
||
3067 | leency | 40 | /////////////////////////// |
5472 | leency | 41 | :f70 getinfo_file_70; |
3440 | leency | 42 | :dword GetFileInfo(dword file_path, bdvk_struct) |
43 | { |
||
44 | getinfo_file_70.func = 5; |
||
45 | getinfo_file_70.param1 = |
||
46 | getinfo_file_70.param2 = |
||
47 | getinfo_file_70.param3 = 0; |
||
48 | getinfo_file_70.param4 = bdvk_struct; |
||
49 | getinfo_file_70.rezerv = 0; |
||
50 | getinfo_file_70.name = file_path; |
||
51 | $mov eax,70 |
||
52 | $mov ebx,#getinfo_file_70.func |
||
3444 | leency | 53 | $int 0x40 |
3440 | leency | 54 | } |
55 | |||
5640 | pavelyakov | 56 | ///////////////////////////////////// |
57 | // Изменение параметров файла // |
||
58 | ///////////////////////////////////// |
||
5554 | punk_joker | 59 | :f70 setinfo_file_70; |
60 | :dword SetFileInfo(dword file_path, bdvk_struct) |
||
61 | { |
||
62 | setinfo_file_70.func = 6; |
||
63 | setinfo_file_70.param1 = |
||
64 | setinfo_file_70.param2 = |
||
65 | setinfo_file_70.param3 = 0; |
||
66 | setinfo_file_70.param4 = bdvk_struct; |
||
67 | setinfo_file_70.rezerv = 0; |
||
68 | setinfo_file_70.name = file_path; |
||
69 | $mov eax,70 |
||
70 | $mov ebx,#setinfo_file_70.func |
||
71 | $int 0x40 |
||
72 | } |
||
73 | |||
5640 | pavelyakov | 74 | /////////////////////////// |
75 | // Запуск программы // |
||
5554 | punk_joker | 76 | /////////////////////////// |
5472 | leency | 77 | :f70 run_file_70; |
78 | :signed int RunProgram(dword run_path, run_param) |
||
3067 | leency | 79 | { |
80 | run_file_70.func = 7; |
||
81 | run_file_70.param1 = |
||
82 | run_file_70.param3 = |
||
83 | run_file_70.param4 = |
||
84 | run_file_70.rezerv = 0; |
||
85 | run_file_70.param2 = run_param; |
||
86 | run_file_70.name = run_path; |
||
87 | $mov eax,70 |
||
88 | $mov ebx,#run_file_70.func |
||
89 | $int 0x40 |
||
90 | } |
||
91 | |||
5640 | pavelyakov | 92 | /////////////////////////// |
93 | // Создание папки // |
||
3067 | leency | 94 | /////////////////////////// |
5472 | leency | 95 | :f70 create_dir_70; |
3067 | leency | 96 | :int CreateDir(dword new_folder_path) |
97 | { |
||
98 | create_dir_70.func = 9; |
||
99 | create_dir_70.param1 = |
||
100 | create_dir_70.param2 = |
||
101 | create_dir_70.param3 = |
||
102 | create_dir_70.param4 = |
||
103 | create_dir_70.rezerv = 0; |
||
104 | create_dir_70.name = new_folder_path; |
||
105 | $mov eax,70 |
||
106 | $mov ebx,#create_dir_70.func |
||
107 | $int 0x40 |
||
108 | } |
||
109 | |||
5640 | pavelyakov | 110 | //////////////////////////// |
111 | // Удаление файла/папки // |
||
3067 | leency | 112 | //////////////////////////// |
5472 | leency | 113 | :f70 del_file_70; |
3067 | leency | 114 | :int DeleteFile(dword del_file_path) |
115 | { |
||
116 | del_file_70.func = 8; |
||
117 | del_file_70.param1 = |
||
118 | del_file_70.param2 = |
||
119 | del_file_70.param3 = |
||
120 | del_file_70.param4 = |
||
121 | del_file_70.rezerv = 0; |
||
122 | del_file_70.name = del_file_path; |
||
123 | $mov eax,70 |
||
124 | $mov ebx,#del_file_70.func |
||
125 | $int 0x40 |
||
126 | } |
||
127 | |||
5640 | pavelyakov | 128 | //////////////////////////// |
129 | // Прочитать файл // |
||
3067 | leency | 130 | //////////////////////////// |
5472 | leency | 131 | :f70 read_file_70; |
7210 | leency | 132 | :int ReadFile(dword offset, data_size, buffer, file_path) |
3067 | leency | 133 | { |
134 | read_file_70.func = 0; |
||
7210 | leency | 135 | read_file_70.param1 = offset; |
3067 | leency | 136 | read_file_70.param2 = 0; |
7210 | leency | 137 | read_file_70.param3 = data_size; |
138 | read_file_70.param4 = buffer; |
||
3067 | leency | 139 | read_file_70.rezerv = 0; |
7210 | leency | 140 | read_file_70.name = file_path; |
3067 | leency | 141 | $mov eax,70 |
142 | $mov ebx,#read_file_70.func |
||
143 | $int 0x40 |
||
144 | } |
||
145 | |||
5472 | leency | 146 | :f70 write_file_70; |
7210 | leency | 147 | :int WriteFile(dword data_size, buffer, file_path) |
3067 | leency | 148 | { |
149 | write_file_70.func = 2; |
||
150 | write_file_70.param1 = 0; |
||
151 | write_file_70.param2 = 0; |
||
7210 | leency | 152 | write_file_70.param3 = data_size; |
153 | write_file_70.param4 = buffer; |
||
3067 | leency | 154 | write_file_70.rezerv = 0; |
7210 | leency | 155 | write_file_70.name = file_path; |
3067 | leency | 156 | $mov eax,70 |
157 | $mov ebx,#write_file_70.func |
||
158 | $int 0x40 |
||
5542 | leency | 159 | } |
3067 | leency | 160 | |
5640 | pavelyakov | 161 | //////////////////////////////////////// |
162 | // WriteInFileThatAlredyExists // |
||
163 | //////////////////////////////////////// |
||
5542 | leency | 164 | :f70 write_file_offset_70; |
7210 | leency | 165 | :int WriteFileWithOffset(dword offset, data_size, buffer, file_path) |
5542 | leency | 166 | { |
167 | write_file_offset_70.func = 3; |
||
168 | write_file_offset_70.param1 = offset; |
||
169 | write_file_offset_70.param2 = 0; |
||
7210 | leency | 170 | write_file_offset_70.param3 = data_size; |
171 | write_file_offset_70.param4 = buffer; |
||
5542 | leency | 172 | write_file_offset_70.rezerv = 0; |
7210 | leency | 173 | write_file_offset_70.name = file_path; |
5542 | leency | 174 | $mov eax,70 |
175 | $mov ebx,#write_file_offset_70.func |
||
176 | $int 0x40 |
||
7210 | leency | 177 | } |
5542 | leency | 178 | |
7210 | leency | 179 | |
5640 | pavelyakov | 180 | /////////////////////////// |
181 | // Прочитать папку // |
||
3067 | leency | 182 | /////////////////////////// |
5472 | leency | 183 | :f70 read_dir_70; |
3067 | leency | 184 | :int ReadDir(dword file_count, read_buffer, dir_path) |
3363 | leency | 185 | { |
3067 | leency | 186 | read_dir_70.func = 1; |
187 | read_dir_70.param1 = |
||
188 | read_dir_70.param2 = |
||
189 | read_dir_70.rezerv = 0; |
||
190 | read_dir_70.param3 = file_count; |
||
191 | read_dir_70.param4 = read_buffer; |
||
192 | read_dir_70.name = dir_path; |
||
193 | $mov eax,70 |
||
194 | $mov ebx,#read_dir_70.func |
||
195 | $int 0x40 |
||
196 | } |
||
197 | |||
7202 | leency | 198 | :bool dir_exists(dword fpath) |
3440 | leency | 199 | { |
200 | BDVK fpath_atr; |
||
6930 | leency | 201 | if (GetFileInfo(fpath, #fpath_atr) != 0) return false; |
5487 | leency | 202 | return fpath_atr.isfolder; |
3440 | leency | 203 | } |
7202 | leency | 204 | :bool file_exists(dword fpath) |
6251 | leency | 205 | { |
206 | BDVK ReadFile_atr; |
||
207 | if (! GetFileInfo(fpath, #ReadFile_atr)) return true; |
||
208 | return false; |
||
209 | } |
||
3877 | leency | 210 | |
6251 | leency | 211 | |
3440 | leency | 212 | :int GetFile(dword buf, filesize, read_path) |
213 | { |
||
6251 | leency | 214 | int return_val = 0; |
3440 | leency | 215 | BDVK ReadFile_atr; |
216 | dword rBuf; |
||
217 | if (! GetFileInfo(read_path, #ReadFile_atr)) |
||
218 | { |
||
219 | rBuf = malloc(ReadFile_atr.sizelo); |
||
220 | if (! ReadFile(0, ReadFile_atr.sizelo, rBuf, read_path)) |
||
221 | { |
||
222 | ESDWORD[buf] = rBuf; |
||
223 | ESDWORD[filesize] = ReadFile_atr.sizelo; |
||
6251 | leency | 224 | return_val = 1; |
3440 | leency | 225 | } |
226 | } |
||
227 | free(rBuf); |
||
6251 | leency | 228 | return return_val; |
3440 | leency | 229 | } |
3067 | leency | 230 | |
3444 | leency | 231 | enum |
3363 | leency | 232 | { |
3444 | leency | 233 | DIRS_ALL, |
234 | DIRS_NOROOT, |
||
235 | DIRS_ONLYREAL |
||
236 | }; |
||
237 | :int GetDir(dword dir_buf, file_count, path, doptions) |
||
238 | { |
||
3363 | leency | 239 | dword buf, fcount, error; |
240 | buf = malloc(32); |
||
241 | error = ReadDir(0, buf, path); |
||
242 | if (!error) |
||
243 | { |
||
244 | fcount = ESDWORD[buf+8]; |
||
245 | buf = realloc(buf, fcount+1*304+32); |
||
246 | ReadDir(fcount, buf, path); |
||
3440 | leency | 247 | //fcount=EBX; |
3444 | leency | 248 | |
249 | if (doptions == DIRS_ONLYREAL) |
||
250 | { |
||
251 | if (!strcmp(".",buf+72)) {fcount--; memmov(buf,buf+304,fcount*304);} |
||
252 | if (!strcmp("..",buf+72)) {fcount--; memmov(buf,buf+304,fcount*304);} |
||
253 | } |
||
254 | if (doptions == DIRS_NOROOT) |
||
255 | { |
||
256 | if (!strcmp(".",buf+72)) {fcount--; memmov(buf,buf+304,fcount*304);} |
||
257 | } |
||
258 | |||
3363 | leency | 259 | ESDWORD[dir_buf] = buf; |
260 | ESDWORD[file_count] = fcount; |
||
261 | } |
||
3440 | leency | 262 | else |
3067 | leency | 263 | { |
3440 | leency | 264 | ESDWORD[file_count] = 0; |
265 | ESDWORD[dir_buf] = free(buf); |
||
3067 | leency | 266 | } |
3440 | leency | 267 | return error; |
3067 | leency | 268 | } |
269 | |||
3432 | leency | 270 | :dword abspath(dword relative_path) //GetAbsolutePathFromRelative() |
271 | { |
||
272 | char absolute_path[4096]; |
||
4137 | leency | 273 | if (ESBYTE[relative_path]=='/') |
274 | { |
||
275 | strcpy(#absolute_path, relative_path); |
||
276 | } |
||
277 | else |
||
278 | { |
||
6735 | leency | 279 | strcpy(#absolute_path, I_Path); |
4137 | leency | 280 | absolute_path[strrchr(#absolute_path, '/')] = '\0'; |
281 | strcat(#absolute_path, relative_path); |
||
282 | } |
||
3432 | leency | 283 | return #absolute_path; |
284 | } |
||
5483 | leency | 285 | |
7202 | leency | 286 | :dword GetIni(dword ini_path, ini_name) //search it on /kolibrios/ then on /sys/ |
7197 | leency | 287 | { |
7202 | leency | 288 | strcpy(ini_path, "/kolibrios/settings/"); |
289 | strcat(ini_path, ini_name); |
||
290 | if (!file_exists(ini_path)) { |
||
291 | strcpy(ini_path, "/sys/settings/"); |
||
292 | strcat(ini_path, ini_name); |
||
7197 | leency | 293 | } |
7202 | leency | 294 | return ini_path; |
7197 | leency | 295 | } |
296 | |||
5591 | pavelyakov | 297 | :byte ConvertSize_size_prefix[8]; |
5576 | pavelyakov | 298 | :dword ConvertSize(dword bytes) |
5483 | leency | 299 | { |
5591 | pavelyakov | 300 | byte size_nm[4]; |
5803 | leency | 301 | if (bytes>=1073741824) strlcpy(#size_nm, "Gb",2); |
302 | else if (bytes>=1048576) strlcpy(#size_nm, "Mb",2); |
||
303 | else if (bytes>=1024) strlcpy(#size_nm, "Kb",2); |
||
304 | else strlcpy(#size_nm, "b ",2); |
||
6989 | leency | 305 | while (bytes>1023) bytes >>= 10; |
5591 | pavelyakov | 306 | sprintf(#ConvertSize_size_prefix,"%d %s",bytes,#size_nm); |
307 | return #ConvertSize_size_prefix; |
||
5493 | leency | 308 | } |
6988 | leency | 309 | :dword ConvertSize64(dword bytes_lo, bytes_hi) |
310 | { |
||
311 | if (bytes_hi > 0) { |
||
6989 | leency | 312 | if (bytes_lo>=1073741824) bytes_lo >>= 30; else bytes_lo = 0; |
313 | sprintf(#ConvertSize_size_prefix,"%d Gb",bytes_hi<<2 + bytes_lo); |
||
6988 | leency | 314 | return #ConvertSize_size_prefix; |
315 | } |
||
316 | else return ConvertSize(bytes_lo); |
||
317 | } |
||
5631 | pavelyakov | 318 | :dword notify(dword notify_param) |
319 | { |
||
6563 | leency | 320 | return RunProgram("/sys/@notify", notify_param); |
5631 | pavelyakov | 321 | } |
6698 | leency | 322 | :void die(dword _last_msg) |
323 | { |
||
324 | notify(_last_msg); |
||
325 | ExitProcess(); |
||
326 | } |
||
6969 | leency | 327 | :unsigned char size[25]=0; |
5493 | leency | 328 | :dword ConvertSizeToKb(unsigned int bytes) |
329 | { |
||
330 | unsigned int kb; |
||
331 | dword kb_line; |
||
332 | |||
6568 | leency | 333 | if (bytes >= 1024) |
334 | { |
||
335 | kb_line = itoa(bytes / 1024); |
||
336 | strcpy(#size, kb_line); |
||
337 | strcat(#size, " Kb"); |
||
338 | } |
||
339 | else { |
||
340 | kb_line = itoa(bytes); |
||
341 | strcpy(#size, kb_line); |
||
342 | strcat(#size, " b"); |
||
343 | } |
||
5493 | leency | 344 | |
345 | return #size; |
||
5598 | pavelyakov | 346 | } |
7210 | leency | 347 | |
348 | :int CopyFileAtOnce(dword size, copyFrom, copyTo) |
||
349 | dword cbuf; |
||
350 | int error; |
||
351 | { |
||
352 | cbuf = malloc(size); |
||
353 | if (error = ReadFile(0, size, cbuf, copyFrom)) |
||
354 | { |
||
355 | debugln("Error: CopyFileAtOnce->ReadFile"); |
||
356 | } |
||
357 | else |
||
358 | { |
||
359 | if (error = WriteFile(size, cbuf, copyTo)) debugln("Error: CopyFileAtOnce->WriteFile"); |
||
360 | } |
||
361 | free(cbuf); |
||
362 | return error; |
||
363 | } |
||
364 | |||
365 | :int CopyFileByBlocks(dword size, copyFrom, copyTo) |
||
366 | dword cbuf; |
||
367 | int error=-1; |
||
368 | dword offpos=0; |
||
369 | int block_size=1024*4024; //copy by 4 MiBs |
||
370 | { |
||
371 | cbuf = malloc(block_size); |
||
372 | WriteFile(0, 0, copyTo); //create file |
||
373 | while(offpos < size) |
||
374 | { |
||
375 | error = ReadFile(offpos, block_size, cbuf, copyFrom); |
||
376 | if (error = 6) { //File ended before last byte was readed |
||
377 | block_size = EBX; |
||
378 | error=0; |
||
379 | } |
||
380 | else |
||
381 | if (error!=0) break; |
||
382 | if (error = WriteFileWithOffset(offpos, block_size, cbuf, copyTo)) break; |
||
383 | offpos += block_size; |
||
384 | } |
||
385 | free(cbuf); |
||
386 | return error; |
||
387 | } |
||
388 | |||
389 | |||
5598 | pavelyakov | 390 | #endif>2><2> |