Subversion Repositories Kolibri OS

Rev

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