12 #error Only kernel should use this file!
24 #define FILENAME_MAX 16
30 #define SECTORS_PER_TRACK 37
51 size_t numberOfFiles = 0;
53 static void saveFATable() {
58 ::
"a"(0x0301),
"d"(0),
"c"(2),
"b"(0),
"S"(KERNEL_ADDRESS));
64 void __strncpy (
char * destination,
const char * source,
size_t num ) {
66 " mov al, byte ptr ss:[si+bx]\n"
67 " mov byte ptr cs:[di+bx], al\n"
73 ::
"D"(destination),
"S"(source),
"b"(0),
"c"(num));
83 if(*(Byte *)0 != 0xcf || *(Byte *)1 != 0xaa || *(Byte *)2 != 0x55)
86 for(; (*(
int *)(numberOfFiles * 19 + 3) != 0) && numberOfFiles * 19 + 3 < 512; numberOfFiles++)
87 for(
int i = 0; i < files[numberOfFiles].size; i++) {
89 map[files[numberOfFiles].track][files[numberOfFiles].beginSector + i] = 1;
102 for(
size_t id = 0;
id < numberOfFiles;
id++) {
103 if(
strcmp(files[
id].name, filename)) {
104 return files[id].size << 8 | id;
131 Byte beginSector = 0;
138 if(
map[track][j + i]) {
153 for(
size_t i = beginSector; i < size + beginSector; i++)
156 files[numberOfFiles].beginSector = beginSector;
157 files[numberOfFiles].size = size;
158 files[numberOfFiles].track = track;
162 return numberOfFiles - 1;
177 int track = files[id].track;
180 for(
int j = files[
id].beginSector; j < files[id].beginSector + files[id].size; j++)
181 map[files[
id].track][j] = 0;
184 for(
int i =
id; files[i].track == track; i++) {
185 files[i].beginSector = files[i + 1].beginSector;
186 files[i].size = files[i + 1].size;
187 files[i].track = files[i + 1].track;
188 strcpy(files[i].name, files[i + 1].name);
203 int sys_read(
const Byte
id,
int ptr,
size_t size) {
204 if(
id > numberOfFiles)
207 int sectors = (size - (size % 512)) / 512;
209 if(files[
id].size < (size % 512 == 0 ? sectors : sectors + 1)) {
210 size = files[id].size * 512;
211 sectors = files[id].size;
217 ::
"a"(0x0200|sectors),
"b"(ptr),
"c"(files[id].track<<8|files[id].beginSector),
"d"(0));
220 if(size % 512 != 0) {
227 ::
"a"(0x0201),
"b"(readed),
"c"((files[id].track<<8|files[id].beginSector)+sectors),
"d"(0),
"S"(KERNEL_ADDRESS));
231 " mov al, byte ptr cs:[si+bx]\n"
232 " mov byte ptr ss:[di+bx], al\n"
235 ::
"D"(ptr+(sectors*512)),
"S"(readed),
"b"(0),
"c"(size%512));
250 if(
id > numberOfFiles)
253 int sectors = (size - (size % 512)) / 512;
255 if(files[
id].size < sectors + (size % 512 != 0 ? 1 : 0)) {
257 strcpy(filename, files[
id].name);
259 if(ret < 0)
return ret;
261 ret =
sys_create(filename, sectors + (size % 512 != 0 ? 1 : 0));
262 if(ret < 0)
return ret;
269 ::
"a"(0x0300|sectors),
"b"(ptr),
"c"(files[id].track<<8|files[id].beginSector),
"d"(0));
272 if(size % 512 != 0) {
278 " mov al, byte ptr ss:[si+bx]\n"
279 " mov byte ptr cs:[di+bx], al\n"
282 ::
"D"(toSave),
"S"(ptr + (size - (size % 512))),
"b"(0),
"c"(size % 512));
288 ::
"a"(0x0301),
"b"(toSave),
"c"(files[id].track<<8|(files[id].beginSector+sectors)),
"d"(0),
"S"(KERNEL_ADDRESS));
293 #pragma GCC diagnostic push
294 #pragma GCC diagnostic ignored "-Wunused-parameter"
312 asm(
"pushw ds\nmov ds, ax"::
"a"(KERNEL_ADDRESS));
315 int ax = 0, bx = 0, cx = 0, dx = 0, di = 0, si = 0;
316 asm(
"mov ax,[ebp-24]":
"=a"(ax));
317 asm(
"mov dx,[ebp-20]":
"=d"(dx));
318 asm(
"mov cx,[ebp-16]":
"=c"(cx));
319 asm(
"mov bx,[ebp-12]":
"=b"(bx));
320 asm(
"mov si,[ebp-8]":
"=S"(si));
321 asm(
"mov di,[ebp-4]":
"=D"(di));
326 asm(
"mov [ebp-24], eax"::
"a"(
sys_setup()));
330 asm(
"mov [ebp-24], eax"::
"a"(
sys_open(fileName)));
333 asm(
"mov [ebp-24], eax"::
"a"(
sys_read(bx, cx, dx)));
336 asm(
"mov [ebp-24], eax"::
"a"(
sys_write(bx, cx, dx)));
340 asm(
"mov [ebp-24], eax"::
"a"(
sys_create(fileName, cx)));
344 asm(
"mov [ebp-24], eax"::
"a"(
sys_remove(fileName)));
348 asm(
"mov [ebp-24],eax"::
"a"(ENOSYS));
353 #pragma GCC diagnostic pop
__int void int0x21(interruptFrame *frame)
interruption for file system
void __strncpy(char *destination, const char *source, size_t num)
Copy from ss:source to cs:destination.
int sys_setup()
load file system
int sys_create(const int filename, size_t size)
Create file.
bool map[TRACKS_MAX][SECTORS_PER_TRACK]
Map of used sectors in tracks.
int sys_open(const int filename)
Open file.
#define SECTORS_PER_TRACK
Number of sectors per track.
int sys_remove(const int filename)
Remove file.
#define FILENAME_MAX
Maximal size of file name.
int sys_write(Byte id, int ptr, size_t size)
Write to file.
#define TRACKS_MAX
Maximal number of tracks in OS.
int sys_read(const Byte id, int ptr, size_t size)
Read from file.
Setting system interruptions, see interrupts.asm.
Standard input output library.
void printf(const int str,...)
C-like printf function.
int strncpy(int destination, int source, size_t num)
Copy num Bytes from source to destination until \0 appears.
bool strcmp(int str1, int str2)
Compares two string until \0 appears.
int memset(int ptr, int value, size_t count)
Set count Bytes of *ptr to value.
char * strcpy(char *destination, const char *source)
Copy from source to destination until \0 appears.
frame for interruption, required by gcc for __int
useful macros, definitions, enums etc.