Subversion Repositories Kolibri OS

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
5936 pavelyakov 1
#ifndef FS_C_INCLUDE
2
#define FS_C_INCLUDE
3
 
4
#include "stdlib.c"
5
 
6
#pragma pack(push,1)
7
typedef struct
8
{
9
unsigned	p00;
10
unsigned	p04;
11
unsigned	p08;
12
unsigned	p12;
13
unsigned	p16;
14
char		p20;
15
char		*p21;
16
} FS_struct70;
17
#pragma pack(pop)
18
 
19
#pragma pack(push,1)
20
typedef struct
21
{
22
unsigned	p00;
23
char		p04;
24
char		p05[3];
25
unsigned	p08;
26
unsigned	p12;
27
unsigned	p16;
28
unsigned	p20;
29
unsigned	p24;
30
unsigned	p28;
31
//unsigned	p32[2];
32
long long p32;
33
unsigned	p40;
34
} FS_struct_BDVK;
35
#pragma pack(pop)
36
 
37
#define FS_COPY_BUFFER_SET 0x100000
38
static inline char BUF_COPY[FS_COPY_BUFFER_SET] = {0};
39
 
40
static inline char *string_error_code(char code)
41
{
42
	if(!code)return "Successfully!";
43
	if(code==1)return "Not defined basis and / or hard disk partition (sub-functions 7, 8 function 21)!";
44
	if(code==2)return "Function is not supported for this file system!";
45
	if(code==3)return "Unknown file system!";
46
	if(code==4)return "Reserved, never returned to the current implementation!";
47
	if(code==5)return "File not found!";
48
	if(code==6)return "The file is ended!";
49
	if(code==7)return "Pointer out the application memory!";
50
	if(code==8)return "Disk is full!";
51
	if(code==9)return "FAT table is destroyed!";
52
	if(code==10)return "Access is denied!";
53
	if(code==11)return "Device error!";
54
	return "An unexpected error!";
55
}
56
 
57
static inline dword sprintf(char *mstr,const char *fmt,...)
58
{
59
 
60
	dword *arg = &fmt;
61
	char *tmp = 0;
62
	char *pos = mstr;
63
	--pos;
64
	--fmt;
65
	while(*++fmt)
66
	{
67
		char s = *fmt;
68
		if(s=='%')
69
		{
70
			s = *++fmt;
71
			if(s=='s')
72
			{
73
				tmp = *++arg;
74
				while(*tmp)*++pos = *tmp++;
75
			}
76
			else
77
			{
78
				*++pos='%';
79
				--fmt;
80
			}
81
		}
82
		else *++pos=s;
83
	}
84
	*++pos = 0;
85
	return pos-mstr;
86
}
87
 
88
static inline int FS_file_70(FS_struct70 *k)
89
{
90
	asm volatile ("int $0x40"::"a"(70), "b"(k));
91
}
92
 
93
FS_struct_BDVK ret_struct;
94
static inline FS_struct_BDVK* get_bdvk(char *path)
95
{
96
	FS_struct70 file_read_struct;
97
	file_read_struct.p00 = 5;
98
	file_read_struct.p04 = 0;
99
	file_read_struct.p08 = 0;
100
	file_read_struct.p12 = 0;
101
	file_read_struct.p16 = (unsigned)&ret_struct;
102
	file_read_struct.p20 = 0;
103
	file_read_struct.p21 = path;
104
	FS_file_70(&file_read_struct);
105
	return (FS_struct_BDVK*)&ret_struct;
106
}
107
 
108
static inline long long file_size(char *path)
109
{
110
	FS_struct_BDVK *data =  get_bdvk(path);
111
	return data->p32;
112
}
113
 
114
static inline byte file_isdir(char *path)
115
{
116
	FS_struct_BDVK *data =  get_bdvk(path);
117
	if(data->p00&0b10000)return 1;
118
	return 0;
119
}
120
 
121
static inline byte file_ismetka(char *path)
122
{
123
	FS_struct_BDVK *data =  get_bdvk(path);
124
	if(data->p00&0b1000)return 1;
125
	return 0;
126
}
127
 
128
static inline byte file_isfile()
129
{
130
	//FS_struct_BDVK *data =  get_bdvk(path);
131
	if(ret_struct.p00&0b11000)return 0;
132
	return 1;
133
}
134
 
135
static inline int file_run(char *path,char *arg)
136
{
137
	FS_struct70 file_read_struct;
138
	file_read_struct.p00 = 7;
139
	file_read_struct.p04 = 0;
140
	file_read_struct.p08 = arg;
141
	file_read_struct.p12 = 0;
142
	file_read_struct.p16 = 0;
143
	file_read_struct.p20 = 0;
144
	file_read_struct.p21 = path;
145
	return FS_file_70(&file_read_struct);
146
 
147
}
148
 
149
static inline int file_read_binary(char *path,unsigned pos,unsigned size,void *adr)
150
{
151
	FS_struct70 file_read_struct;
152
	file_read_struct.p00 = 0;
153
	file_read_struct.p04 = pos;
154
	file_read_struct.p08 = 0;
155
	file_read_struct.p12 = size;
156
	file_read_struct.p16 = (unsigned)adr;
157
	file_read_struct.p20 = 0;
158
	file_read_struct.p21 = path;
159
	char c = FS_file_70(&file_read_struct);
160
	if(c)
161
	{
162
		sprintf(&BUF_COPY,"'Error read file (%s) file: %s.'E",string_error_code(c),path);
163
		file_run("/sys/@notify",&BUF_COPY);
164
	}
165
	return c;
166
}
167
 
168
static inline int file_delete(char *path)
169
{
170
	FS_struct70 file_read_struct;
171
	file_read_struct.p00 = 8;
172
	file_read_struct.p04 = 0;
173
	file_read_struct.p08 = 0;
174
	file_read_struct.p12 = 0;
175
	file_read_struct.p16 = 0;
176
	file_read_struct.p20 = 0;
177
	file_read_struct.p21 = path;
178
	char c = FS_file_70(&file_read_struct);
179
	if(c)
180
	{
181
		sprintf(&BUF_COPY,"'Error delete file: %s. Info: %s'E",string_error_code(c),path);
182
		file_run("/sys/@notify",&BUF_COPY);
183
	}
184
	return c;
185
}
186
 
187
static inline int file_mkdir(char *path)
188
{
189
	FS_struct70 file_read_struct;
190
	file_read_struct.p00 = 9;
191
	file_read_struct.p04 = 0;
192
	file_read_struct.p08 = 0;
193
	file_read_struct.p12 = 0;
194
	file_read_struct.p16 = 0;
195
	file_read_struct.p20 = 0;
196
	file_read_struct.p21 = path;
197
	char c = FS_file_70(&file_read_struct);
198
	if(c)
199
	{
200
		sprintf(&BUF_COPY,"'Error make dir: %s. Info: %s.'E",string_error_code(c),path);
201
		file_run("/sys/@notify",&BUF_COPY);
202
	}
203
	return c;
204
}
205
 
206
static inline int file_write(char *path,void *ukaz,dword size)
207
{
208
	FS_struct70 file_read_struct;
209
	file_read_struct.p00 = 2;
210
	file_read_struct.p04 = 0;
211
	file_read_struct.p08 = 0;
212
	file_read_struct.p12 = size;
213
	file_read_struct.p16 = ukaz;
214
	file_read_struct.p20 = 0;
215
	file_read_struct.p21 = path;
216
	char c = FS_file_70(&file_read_struct);
217
	if(c)
218
	{
219
		sprintf(&BUF_COPY,"'Error write file: %s. Info: %s.'E",string_error_code(c),path);
220
		file_run("/sys/@notify",&BUF_COPY);
221
	}
222
	return c;
223
}
224
 
225
static inline int file_rewrite(char *path,dword pos1,dword pos2,void *ukaz,dword size)
226
{
227
	FS_struct70 file_read_struct;
228
	file_read_struct.p00 = 3;
229
	file_read_struct.p04 = pos1;
230
	file_read_struct.p08 = pos2;
231
	file_read_struct.p12 = size;
232
	file_read_struct.p16 = ukaz;
233
	file_read_struct.p20 = 0;
234
	file_read_struct.p21 = path;
235
	char c = FS_file_70(&file_read_struct);
236
	if(c)
237
	{
238
		sprintf(&BUF_COPY,"'Error rewrite file (%s) file: %s.'E",string_error_code(c),path);
239
		file_run("/sys/@notify",&BUF_COPY);
240
	}
241
	return c;
242
}
243
 
244
 
245
static inline char file_copy(char *path1,char *path2)
246
{
247
	long long size = file_size(path1);
248
	if(!size)file_write(path2,&BUF_COPY,0);
249
	long long cel = size;
250
	cel /= FS_COPY_BUFFER_SET;
251
	dword ost = size-cel*FS_COPY_BUFFER_SET;
252
	long long i = 0;
253
	char err=0;
254
	if(cel)
255
	{
256
		if(file_read_binary(path1,0,FS_COPY_BUFFER_SET,&BUF_COPY))goto ERROR;
257
		if(file_write(path2,&BUF_COPY,FS_COPY_BUFFER_SET))goto ERROR;
258
		++i;
259
	}
260
	else
261
	{
262
		if(file_read_binary(path1,0,ost,&BUF_COPY))goto ERROR;
263
		if(file_write(path2,&BUF_COPY,ost))goto ERROR;
264
		return 1;
265
	}
266
	while(i
267
	{
268
		if(file_read_binary(path1,FS_COPY_BUFFER_SET*i,FS_COPY_BUFFER_SET,&BUF_COPY))goto ERROR;
269
		if(file_rewrite(path2,FS_COPY_BUFFER_SET*i,0,&BUF_COPY,FS_COPY_BUFFER_SET))goto ERROR;
270
		++i;
271
	}
272
	if(file_read_binary(path1,FS_COPY_BUFFER_SET*i,ost,&BUF_COPY))goto ERROR;
273
	if(file_rewrite(path2,FS_COPY_BUFFER_SET*i,0,&BUF_COPY,ost))goto ERROR;
274
	return 1;
275
	ERROR:
276
 
277
	//asm("":"=a"(err));
278
	//sprintf(&BUF_COPY,"Error %s file: %s.",string_error_code(err),path1);
279
	//file_run("/sys/@notify",&BUF_COPY);
280
	return 0;
281
}
282
 
283
/*
284
dword FS_COPY_BUFFER_SET_POINT = 0x100000;
285
dword BUF_COPY_POINT = 0;
286
static inline char file_copy(char *path1,char *path2)
287
{
288
	long long size = file_size(path1);
289
	if(!size)file_write(path2,BUF_COPY_POINT,0);
290
	long long cel = size;
291
	cel /= FS_COPY_BUFFER_SET_POINT;
292
	dword ost = size-cel*FS_COPY_BUFFER_SET_POINT;
293
	long long i = 0;
294
	char err=0;
295
	if(cel)
296
	{
297
		if(file_read_binary(path1,0,FS_COPY_BUFFER_SET_POINT,BUF_COPY_POINT))goto ERROR;
298
		if(file_write(path2,BUF_COPY_POINT,FS_COPY_BUFFER_SET_POINT))goto ERROR;
299
		++i;
300
	}
301
	else
302
	{
303
		if(file_read_binary(path1,0,ost,BUF_COPY_POINT))goto ERROR;
304
		if(file_write(path2,BUF_COPY_POINT,ost))goto ERROR;
305
		return 1;
306
	}
307
	while(i
308
	{
309
		if(file_read_binary(path1,FS_COPY_BUFFER_SET_POINT*i,FS_COPY_BUFFER_SET_POINT,BUF_COPY_POINT))goto ERROR;
310
		if(file_rewrite(path2,FS_COPY_BUFFER_SET_POINT*i,0,BUF_COPY_POINT,FS_COPY_BUFFER_SET_POINT))goto ERROR;
311
		++i;
312
	}
313
	if(file_read_binary(path1,FS_COPY_BUFFER_SET_POINT*i,ost,BUF_COPY_POINT))goto ERROR;
314
	if(file_rewrite(path2,FS_COPY_BUFFER_SET_POINT*i,0,BUF_COPY_POINT,ost))goto ERROR;
315
	return 1;
316
	ERROR:
317
 
318
	//asm("":"=a"(err));
319
	//sprintf(BUF_COPY_POINT,"Error %s file: %s.",string_error_code(err),path1);
320
	//file_run("/sys/@notify",BUF_COPY_POINT);
321
	return 0;
322
}
323
*/
324
/*
325
#define FS_COPY_BUFFER_SET 0x100000
326
char BUF_COPY[FS_COPY_BUFFER_SET] = {0};
327
static inline char file_copy(char *path1,char *path2)
328
{
329
	long long size = file_size(path1);
330
	if(!size)file_write(path2,&BUF_COPY,0);
331
	long long cel = size;
332
	cel /= FS_COPY_BUFFER_SET;
333
	dword ost = size-cel*FS_COPY_BUFFER_SET;
334
	long long i = 0;
335
 
336
	if(cel)
337
	{
338
		file_read_binary(path1,0,FS_COPY_BUFFER_SET,&BUF_COPY);
339
		file_write(path2,&BUF_COPY,FS_COPY_BUFFER_SET);
340
		++i;
341
	}
342
	else
343
	{
344
		file_read_binary(path1,0,ost,&BUF_COPY);
345
		file_write(path2,&BUF_COPY,ost);
346
		return 1;
347
	}
348
	while(i
349
	{
350
		file_read_binary(path1,FS_COPY_BUFFER_SET*i,FS_COPY_BUFFER_SET,&BUF_COPY);
351
		file_rewrite(path2,FS_COPY_BUFFER_SET*i,0,&BUF_COPY,FS_COPY_BUFFER_SET);
352
		++i;
353
	}
354
	file_read_binary(path1,FS_COPY_BUFFER_SET*i,ost,&BUF_COPY);
355
	file_rewrite(path2,FS_COPY_BUFFER_SET*i,0,&BUF_COPY,ost);
356
	return 1;
357
}
358
*/
359
long long size_long_file=0;
360
 
361
static inline void *file_read(char *path)
362
{
363
	size_long_file = file_size(path);
364
	void *data = malloc(size_long_file+1);
365
 
366
	if(file_read_binary(path,0,size_long_file,data))return 0;
367
 
368
	return data;
369
}
370
 
371
static inline void *file_readKPACK(char *path)
372
{
373
	void *data = 0;
374
	dword size=0;
375
	asm ("int $0x40":"=a"(data),"=d"(size):"a"(68), "b"(27), "c"(path));
376
	size_long_file = size;
377
	asm volatile(""::"c"(size));
378
	return data;
379
}
380
 
381
static inline int file_read_dir(dword begin,dword file_count,dword read_buffer,char *dir_path)
382
{
383
	FS_struct70 file_read_struct;
384
	file_read_struct.p00 = 1;
385
	file_read_struct.p04 = begin;
386
	file_read_struct.p08 = 0;
387
	file_read_struct.p12 = file_count;
388
	file_read_struct.p16 = read_buffer;
389
	file_read_struct.p20 = 0;
390
	file_read_struct.p21 = dir_path;
391
	return FS_file_70(&file_read_struct);
392
}
393
 
394
#endif