14 #include <lib/php/pathinfo.h>
17 size_t fs_smfs_read(
const char Disk,
const char* Path,
size_t Offset,
size_t Size,
void* Buffer){
21 size_t fs_smfs_write(
const char Disk,
const char* Path,
size_t Offset,
size_t Size,
void* Buffer){
25 FSM_FILE fs_smfs_info(
const char Disk,
const char* Path){
29 FSM_DIR* fs_smfs_dir(
const char Disk,
const char* Path){
33 int fs_smfs_create(
const char Disk,
const char* Path,
int Mode){
37 int fs_smfs_delete(
const char Disk,
const char* Path,
int Mode){
41 void fs_smfs_label(
const char Disk,
char* Label){
45 int fs_smfs_format(
const char Disk){
47 DPM_Disk IDisk = dpm_info(Disk);
48 size_t MaxFiles = (((IDisk.Size) - (
sizeof(SMFS_BOOT_SECTOR))) / 2048);
50 qemu_log(
"FATAL FORMAT!");
53 qemu_log(
"FORMAT IS STARTING...");
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)));
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");
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};
72 SMFS_BOOT_SECTOR *boot = kmalloc(
sizeof(SMFS_BOOT_SECTOR));
74 boot[0].magic1 = 0x7246;
75 boot[0].magic2 = 0xCAFE;
76 boot[0].MaximumElems = MaxFiles;
77 boot[0].MaxPackage = allPkg;
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);
83 read =
dpm_write(Disk, seek,
sizeof(SMFS_BOOT_SECTOR), &boot[0]);
87 qemu_log(
"[SMFS] FDA WRITE:%d\n",read);
90 qemu_log(
"[SMFS] FATAL FORMAT!");
94 seek =
sizeof(SMFS_BOOT_SECTOR);
95 qemu_log(
"[SMFS] Create markup structures for files and folders");
97 SMFS_Elements *elements = kmalloc(
sizeof(SMFS_Elements));
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;
106 elements[0].Point = 0;
108 memcpy((
void*) elements[0].Name, eName, 32);
110 for (
int i = 0; i < MaxFiles; i++) {
111 elements[0].Index = i;
113 read =
dpm_write(Disk, seek,
sizeof(SMFS_Elements), &elements[0]);
115 qemu_log(
"[SMFS] DISK WRITE:%d | I: %d | In: %x\n",read,i,seek);
116 seek +=
sizeof(SMFS_Elements);
119 qemu_log(
"[SMFS] Now we write packages");
121 SMFS_PACKAGE *pkg = kmalloc(
sizeof(SMFS_PACKAGE));
123 memcpy((
void*) pkg[0].Data, eData, 8);
126 pkg[0].Status = SMFS_PACKAGE_FREE;
128 for (
int i = 0; i < allPkg; i++){
130 read =
dpm_write(Disk, seek,
sizeof(SMFS_PACKAGE), &pkg[0]);
133 qemu_log(
"[SMFS] DISK WRITE:%d | I: %d | In: %x\n",read,i,seek);
134 seek +=
sizeof(SMFS_PACKAGE);
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);
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);
size_t dpm_write(char Letter, uint64_t high_offset, uint64_t low_offset, size_t Size, char *Buffer)
[DPM] Запись данных на диск
size_t dpm_read(char Letter, uint64_t high_offset, uint64_t low_offset, size_t Size, void *Buffer)
[DPM] Считывание данных с диска
size_t strlen(const char *str)
Возращает длину строки
void * memcpy(void *restrict destination, const void *restrict source, size_t n)
Копирование непересекающихся массивов используя SSE.