SayoriOS 0.3.3

natfs.c
1
10 #include <kernel.h>
11 #include <io/ports.h>
12 #include <fs/fsm.h>
13 #include <fs/natfs.h>
14
15 #include <lib/php/pathinfo.h>
16
17 size_t fs_natfs_read(const char Disk,const char* Path, size_t Offset, size_t Size,void* Buffer){
18 char* buf = __milla_getFile(Path);
19 qemu_log("NatSuki:\n\t Path: %s\n\tSize: %d | %d\n\tContent: %s", Path, Size, strlen(buf), buf);
20
21 memcpy(Buffer, buf, Size);
22 //substr(Buffer, (void*)__milla_getFile(Path), Offset, Size);
23 kfree(buf);
24 return Size;
25 }
26
27 size_t fs_natfs_write(const char Disk,const char* Path,size_t Offset,size_t Size,void* Buffer){
28 return 0;
29 }
30
31 FSM_FILE fs_natfs_info(const char Disk,const char* Path){
32 FSM_FILE file = {};
33 file.Size = __milla_getSizeFile(Path);
34 if (__milla_isFile(__milla_findID(Path,"file")) != 1){
35 qemu_warn("[NatFS] File no found???");
36 return file;
37 }
38 file.Ready = 1;
39 //fsm_convertUnix(atoi(_m_s[3]), &file.LastTime);
40
41 char* zpath = pathinfo(Path, PATHINFO_DIRNAME);
42 char* zname = pathinfo(Path, PATHINFO_BASENAME);
43
44 file.Mode = 'r';
45 //file.Type = ((strcmpn(_m_s[0], "file")?0:5));
46 file.Type = 0;
47 file.Ready = 1;
48
49 memcpy(file.Path, Path, strlen(Path));
50 memcpy(file.Name, zname, strlen(zname));
51 return file;
52 }
53
54 FSM_DIR* fs_natfs_dir(const char Disk,const char* Path){
55 size_t inxDir = __milla_findID(Path,"DIR");
56 if (inxDir < 0){
57 qemu_warn("[NatSuki] When searching for a folder, the error %d was returned, perhaps the folder was not found or the device is not ready to work.", inxDir);
58 return 0;
59 }
60
61 qemu_log("[NatSuki] Get path: %s",Path);
62 FSM_DIR *Dir = kcalloc(sizeof(FSM_DIR), 1);
63 size_t CA = 0, CF = 0, CD = 0, CO = 0;
64
65 char* listt = __milla_getList(Path);
66 char* _m_d[256] = {0};
67 char* _m_s[256] = {0};
68 uint32_t _m_d2 = 0;
69
70 uint32_t _m_d1 = str_cdsp(listt,"\n");
71
72 str_split(listt,_m_d,"\n");
73
74 //tty_printf("Найдено файлов и папок: %d\n",_m_d1-1);
75
76
77 FSM_FILE *Files = kcalloc(sizeof(FSM_FILE), _m_d1);
78 //struct dirent* testFS = kcalloc(_m_d1, sizeof(struct dirent));
79 if (_m_d1 == 0){
80 Dir->Ready = 1;
81 Dir->Count = CA;
82 Dir->CountFiles = CF;
83 Dir->CountDir = CD;
84 Dir->CountOther = CO;
85 Dir->Files = Files;
86
87 return Dir;
88 }
89 for(size_t ind = 0; ind < _m_d1; ind++){
90 _m_d2 = str_cdsp(_m_d[ind],"::");
91 if (_m_d2 < 1) continue;
92 memset(_m_s,0,256);
93 str_split(_m_d[ind],_m_s,"::");
94
95 fsm_convertUnix(atoi(_m_s[3]), &Files[CA].LastTime);
96
97 // Files[CA].Mode = 'rw'; // INVALID!
98 Files[CA].Mode = 'r';
99 Files[CA].Size = (atoi(_m_s[4]));
100 Files[CA].Type = ((strcmpn(_m_s[0], "file")?0:5));
101 Files[CA].Ready = 1;
102
103 memcpy(Files[CA].Path, Path, strlen(Path));
104 memcpy(Files[CA].Name, _m_s[1], strlen(_m_s[1]));
105
106
107 if (Files[CA].Type == 0) {
109 CF++;
110 } else if (Files[CA].Type == 5){
112 CD++;
113 } else {
115 CO++;
116 }
117 CA++;
118
119 //testFS[inxFile].type = ((strcmpn(_m_s[0], "file")?FS_FILE:FS_DIRECTORY));
120 //testFS[inxFile].ino = inxFile;
121 //testFS[inxFile].next = inxFile+1;
122 //testFS[inxFile].length = (atoi(_m_s[4]));
123 //strcpy(testFS[inxFile].name, _m_s[1]);
124 qemu_log("[Milla] [%s] %s (%d b.) Date: %s Owner: %s",_m_s[0],_m_s[1],(atoi(_m_s[4])),_m_s[3],_m_s[5]);
125 }
126 kfree(listt);
127
128 Dir->Ready = 1;
129 Dir->Count = CA;
130 Dir->CountFiles = CF;
131 Dir->CountDir = CD;
132 Dir->CountOther = CO;
133 Dir->Files = Files;
134
135 return Dir;
136 }
137
138 int fs_natfs_create(const char Disk,const char* Path,int Mode){
139 return 0;
140 }
141
142 int fs_natfs_delete(const char Disk,const char* Path,int Mode){
143 return 0;
144 }
145
146 void fs_natfs_label(const char Disk, char* Label){
147 memcpy(Label,"NatFS",strlen("NatFS"));
148 }
149
150 int fs_natfs_detect(const char Disk){
151 return (0);
152 }
153
154 char* __milla_getDiskInfo_Name();
155 int __milla_getDiskInfo_All();
156
157 int fs_natfs_init(){
158 int _m = __milla_init();
159 if (_m != 0){
160 qemu_warn("[NatFS] An error occurred during initialization, the server returned a response: %d",_m);
161 return 0;
162 }
163 int dsize = __milla_getDiskInfo_All();
164 char* dname = __milla_getDiskInfo_Name();
165 int dpm = dpm_reg('N', dname, "NatFS", 2, dsize, 0, 0, 3, "NAT0-SUKI", (void *) _m);
166 if (dpm != 1){
167 qemu_warn("[NatFS] An error occurred while initializing the disk in the operating system! DPM returned the code: %d", dpm);
168 return 0;
169 }
170 return 1;
171 }
__milla_init
int __milla_init()
Инициализация проекта Милла
Definition: NatSuki.c:327
dpm_reg
int dpm_reg(char Letter, char *Name, char *FS, int Status, size_t Size, size_t Sectors, size_t SectorSize, int AddrMode, char *Serial, void *Point)
[DPM] Регистрация дискового раздела
Definition: dpm.c:187
strlen
size_t strlen(const char *str)
Возращает длину строки
Definition: string.c:88
atoi
uint32_t atoi(const char s[])
Превращает строку в число
Definition: string.c:565
strcmpn
bool strcmpn(const char *str1, const char *str2)
Сравнение строк
Definition: string.c:270
memset
void * memset(void *ptr, char value, size_t num)
Заполнение массива указанными символами
Definition: string.c:203
memcpy
void * memcpy(void *restrict destination, const void *restrict source, size_t n)
Копирование непересекающихся массивов используя SSE.
Definition: string.c:173
str_cdsp
uint32_t str_cdsp(const char *a_str, const char *del)
Функция отладки
Definition: split.c:22
str_split
void str_split(const char a_str[], char *out[], char *del)
Функция для деления строк
Definition: split.c:40