SayoriOS 0.3.3

smfs.c
1
10 #include <kernel.h>
11 #include <io/ports.h>
12 #include <fs/fsm.h>
13 #include <fs/smfs.h>
14 #include <lib/php/pathinfo.h>
15
16
17 size_t fs_smfs_read(const char Disk,const char* Path, size_t Offset, size_t Size,void* Buffer){
18 return 0;
19 }
20
21 size_t fs_smfs_write(const char Disk,const char* Path,size_t Offset,size_t Size,void* Buffer){
22 return 0;
23 }
24
25 FSM_FILE fs_smfs_info(const char Disk,const char* Path){
26
27 }
28
29 FSM_DIR* fs_smfs_dir(const char Disk,const char* Path){
30
31 }
32
33 int fs_smfs_create(const char Disk,const char* Path,int Mode){
34 return 0;
35 }
36
37 int fs_smfs_delete(const char Disk,const char* Path,int Mode){
38 return 0;
39 }
40
41 void fs_smfs_label(const char Disk, char* Label){
42 memcpy(Label,"SMFS",strlen("SMFS"));
43 }
44
45 int fs_smfs_format(const char Disk){
46
47 DPM_Disk IDisk = dpm_info(Disk);
48 size_t MaxFiles = (((IDisk.Size) - (sizeof(SMFS_BOOT_SECTOR))) / 2048);
49 if (MaxFiles <= 0){
50 qemu_log("FATAL FORMAT!");
51 return 0;
52 }
53 qemu_log("FORMAT IS STARTING...");
54
55 size_t read = 0,seek = 0;
56 int sizeFiles = ((sizeof(SMFS_Elements)) * MaxFiles);
57 int freeSpa = ((IDisk.Size) - (sizeFiles) - (sizeof(SMFS_BOOT_SECTOR)));
58 int allPkg = (freeSpa / (sizeof(SMFS_PACKAGE)));
59
60 qemu_log("[SMFS] Formatting FDA STARTED!");
61 qemu_log("[SMFS] DISK_SIZE = %d", (IDisk.Size));
62 qemu_log("[SMFS] BOOT_SIZE = %d", (sizeof(SMFS_BOOT_SECTOR)));
63 qemu_log("[SMFS] Max Elems = %d | %d", MaxFiles, sizeFiles);
64 qemu_log("[SMFS] FREE SPA = %d", freeSpa);
65 qemu_log("[SMFS] Max Package = %d", allPkg);
66 qemu_log("[SMFS] We overwrite on our own BOOT SECTOR");
67
68 char oem[8] = {'S','A','Y','O','R','I','O','S'};
69 char label[11] = {'S','M','F','S',' ',' ',' ',' ',' ',' ',0};
70 char fsid[8] = {'S','M','F','S','1','.','0',0};
71
72 SMFS_BOOT_SECTOR *boot = kmalloc(sizeof(SMFS_BOOT_SECTOR));
73
74 boot[0].magic1 = 0x7246;
75 boot[0].magic2 = 0xCAFE;
76 boot[0].MaximumElems = MaxFiles;
77 boot[0].MaxPackage = allPkg;
78
79 memcpy((void*) boot[0].oem_name, oem, 8);
80 memcpy((void*) boot[0].volume_label, label, 11);
81 memcpy((void*) boot[0].fsid, fsid, 8);
82
83 read = dpm_write(Disk, seek, sizeof(SMFS_BOOT_SECTOR), &boot[0]);
84
85 //read = _FloppyWrite(0,&boot[0],0,sizeof(SMFS_BOOT_SECTOR));
86
87 qemu_log("[SMFS] FDA WRITE:%d\n",read);
88
89 if (read == -1){
90 qemu_log("[SMFS] FATAL FORMAT!");
91 return 0;
92 }
93
94 seek = sizeof(SMFS_BOOT_SECTOR);
95 qemu_log("[SMFS] Create markup structures for files and folders");
96
97 SMFS_Elements *elements = kmalloc(sizeof(SMFS_Elements));
98
99 char eName[32] = {0};
100 elements[0].Attr = SMFS_TYPE_DELETE;
101 elements[0].Size = 0;
102 elements[0].TimeCreateHIS = 0;
103 elements[0].TimeCreateDate = 0;
104 elements[0].TimeAccess = 0;
105 elements[0].Dir = 0;
106 elements[0].Point = 0;
107
108 memcpy((void*) elements[0].Name, eName, 32);
109
110 for (int i = 0; i < MaxFiles; i++) {
111 elements[0].Index = i;
112
113 read = dpm_write(Disk, seek, sizeof(SMFS_Elements), &elements[0]);
114 //read = _FloppyWrite(0,&elements[0],seek,sizeof(SMFS_Elements));
115 qemu_log("[SMFS] DISK WRITE:%d | I: %d | In: %x\n",read,i,seek);
116 seek += sizeof(SMFS_Elements);
117 }
118
119 qemu_log("[SMFS] Now we write packages");
120
121 SMFS_PACKAGE *pkg = kmalloc(sizeof(SMFS_PACKAGE));
122 char eData[8] = {0};
123 memcpy((void*) pkg[0].Data, eData, 8);
124 pkg[0].Length = 0;
125 pkg[0].Next = -1;
126 pkg[0].Status = SMFS_PACKAGE_FREE;
127
128 for (int i = 0; i < allPkg; i++){
129
130 read = dpm_write(Disk, seek, sizeof(SMFS_PACKAGE), &pkg[0]);
131
132 //read = _FloppyWrite(0,&pkg[0],seek,sizeof(SMFS_PACKAGE));
133 qemu_log("[SMFS] DISK WRITE:%d | I: %d | In: %x\n",read,i,seek);
134 seek += sizeof(SMFS_PACKAGE);
135 }
136 return 1;
137 }
138
139 int fs_smfs_detect(const char Disk){
140 SMFS_BOOT_SECTOR* BOOT = kmalloc(sizeof(SMFS_BOOT_SECTOR)+1);
141 dpm_read(Disk, 0, sizeof(SMFS_BOOT_SECTOR), BOOT);
142
143
144 qemu_log("[SMFS] Check BootSector:");
145 qemu_log(" |--- magic1 | %x\n",BOOT->magic1);
146 qemu_log(" |--- magic2 | %x\n",BOOT->magic2);
147 qemu_log(" |--- MaximumElems | %d\n",BOOT->MaximumElems);
148 qemu_log(" |--- MaxPackage | %d\n",BOOT->MaxPackage);
149 qemu_log(" |--- OEM | %s\n",BOOT->oem_name);
150 qemu_log(" |--- Label | %s\n",BOOT->volume_label);
151 qemu_log(" |--- FSID | %s\n",BOOT->fsid);
152
153 kfree(BOOT);
154 return (0);
155 }
dpm_write
size_t dpm_write(char Letter, uint64_t high_offset, uint64_t low_offset, size_t Size, char *Buffer)
[DPM] Запись данных на диск
Definition: dpm.c:123
dpm_read
size_t dpm_read(char Letter, uint64_t high_offset, uint64_t low_offset, size_t Size, void *Buffer)
[DPM] Считывание данных с диска
Definition: dpm.c:82
strlen
size_t strlen(const char *str)
Возращает длину строки
Definition: string.c:88
memcpy
void * memcpy(void *restrict destination, const void *restrict source, size_t n)
Копирование непересекающихся массивов используя SSE.
Definition: string.c:173