12 #include <lib/php/pathinfo.h>
13 #include "lib/php/str_contains.h"
14 #include "lib/php/explode.h"
15 #include "lib/sprintf.h"
18 #include "drv/disk/dpm.h"
22 bool fsm_debug =
false;
24 size_t fsm_DateConvertToUnix(FSM_TIME time) {
25 uint32_t seconds_per_day = 24 * 60 * 60;
29 for (uint32_t year = 1970; year < time.year; year++) {
30 uint32_t days_in_year = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)) ? 366 : 365;
31 unix_time += days_in_year * seconds_per_day;
34 int8_t month_days[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
35 if (time.year % 4 == 0 && (time.year % 100 != 0 || time.year % 400 == 0)) {
40 for (uint32_t month = 0; month < time.month - 1; month++) {
41 unix_time += month_days[month] * seconds_per_day;
45 unix_time += (time.day - 1) * seconds_per_day;
48 unix_time += time.hour * 3600 + time.minute * 60 + time.second;
54 void fsm_convertUnix(uint32_t unix_time, FSM_TIME* time) {
55 if (fsm_debug) qemu_log(
"[FSM] Convert unix: %d",unix_time);
56 uint32_t seconds_per_day = 24 * 60 * 60;
57 uint32_t days = unix_time / seconds_per_day;
59 uint32_t years = 1970;
62 uint32_t days_in_year = (years % 4 == 0 && (years % 100 != 0 || years % 400 == 0)) ? 366 : 365;
63 if (days < days_in_year) {
70 int8_t month_days[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
71 if (years % 4 == 0 && (years % 100 != 0 || years % 400 == 0)) {
75 uint32_t year_day = days;
76 for (month = 0; month < 12; month++) {
77 if (year_day < month_days[month]) {
80 year_day -= month_days[month];
85 uint32_t seconds = unix_time % seconds_per_day;
86 uint32_t hour = seconds / 3600;
87 uint32_t minute = (seconds % 3600) / 60;
88 uint32_t second = seconds % 60;
95 time->minute = minute;
96 time->second = second;
101 char* fsm_timePrintable(FSM_TIME time){
104 asprintf(&btime,
"%04d.%02d.%02d %02d:%02d:%02d",
115 int fsm_isPathToFile(
const char* Path,
const char* Name){
116 char* zpath = pathinfo(Name, PATHINFO_DIRNAME);
117 char* bpath = pathinfo(Name, PATHINFO_BASENAME);
118 bool isCheck1 =
strcmpn(zpath,Path);
119 bool isCheck2 =
strlen(bpath) == 0;
120 bool isCheck3 = str_contains(Name, Path);
126 bool isCheck4 = ((c2 - c1) == 1) && (c4 == c3);
127 bool isCheck5 = ((c4 - c3) == 1) && (c2 == c1);
132 bool isPassed = ((isCheck1 && !isCheck2 && isCheck3) || (!isCheck1 && isCheck2 && isCheck3 && (isCheck4 || isCheck5)));
140 int fsm_getIDbyName(
const char* Name){
141 for (
int i = 0; i < C_FSM; i++){
142 if (!
strcmpn(G_FSM[i].Name,Name))
continue;
148 void fsm_dump(FSM_FILE file){
149 qemu_log(
" |--- Ready : %d",file.Ready);
150 qemu_log(
" |--- Name : %s",file.Name);
151 qemu_log(
" |--- Path : %s",file.Path);
152 qemu_log(
" |--- Mode : %d",file.Mode);
153 qemu_log(
" |--- Size : %d",file.Size);
154 qemu_log(
" |--- Type : %d",file.Type);
155 qemu_log(
" |--- Date : %d",file.LastTime.year);
158 size_t fsm_read(
int FIndex,
char DIndex,
const char* Name,
size_t Offset,
size_t Count,
void* Buffer){
159 if (fsm_debug) qemu_log(
"[FSM] [READ] F:%d | D:%d | N:%d | O:%d | C:%d",FIndex,DIndex,Name,Offset,Count);
160 if (G_FSM[FIndex].Ready == 0)
return 0;
161 if (fsm_debug) qemu_log(
"[FSM] [READ] GO TO DRIVER");
162 return G_FSM[FIndex].Read(DIndex,Name,Offset, Count, Buffer);
166 int fsm_create(
int FIndex,
char DIndex,
const char* Name,
int Mode){
167 if (G_FSM[FIndex].Ready == 0)
return 0;
168 return G_FSM[FIndex].Create(DIndex,Name,Mode);
172 int fsm_delete(
int FIndex,
const char DIndex,
const char* Name,
int Mode){
173 if (G_FSM[FIndex].Ready == 0)
176 return G_FSM[FIndex].Delete(DIndex,Name,Mode);
179 size_t fsm_write(
int FIndex,
const char DIndex,
const char* Name,
size_t Offset,
size_t Count,
void* Buffer){
180 if (G_FSM[FIndex].Ready == 0)
183 return G_FSM[FIndex].Write(DIndex,Name,Offset, Count, Buffer);
186 FSM_FILE fsm_info(
int FIndex,
const char DIndex,
const char* Name){
187 if (fsm_debug) qemu_log(
"[FSM] [INFO] F:%d | D:%d | N:%s",FIndex,DIndex,Name);
188 if (G_FSM[FIndex].Ready == 0){
189 if (fsm_debug) qemu_log(
"[FSM] [INFO] READY == 0");
192 if (fsm_debug) qemu_log(
"[FSM] [INFO] GO TO GFSM");
193 return G_FSM[FIndex].Info(DIndex,Name);
196 FSM_DIR* fsm_dir(
int FIndex,
const char DIndex,
const char* Name){
197 if (fsm_debug) qemu_log(
"[FSM] [DIR] F:%d | D:%d | N:%s",FIndex,DIndex,Name);
199 if (G_FSM[FIndex].Ready == 0){
200 if (fsm_debug) qemu_log(
"[FSM] [INFO] READY == 0");
201 FSM_DIR* dir = kmalloc(
sizeof(FSM_DIR));
205 return G_FSM[FIndex].Dir(DIndex, Name);
208 void fsm_reg(
const char* Name,
int Splash,fsm_cmd_read_t Read, fsm_cmd_write_t Write, fsm_cmd_info_t Info, fsm_cmd_create_t Create, fsm_cmd_delete_t Delete, fsm_cmd_dir_t Dir, fsm_cmd_label_t Label, fsm_cmd_detect_t Detect){
209 G_FSM[C_FSM].Ready = 1;
210 G_FSM[C_FSM].Splash = Splash;
211 G_FSM[C_FSM].Read = Read;
212 G_FSM[C_FSM].Write = Write;
213 G_FSM[C_FSM].Info = Info;
214 G_FSM[C_FSM].Create = Create;
215 G_FSM[C_FSM].Delete = Delete;
216 G_FSM[C_FSM].Dir = Dir;
217 G_FSM[C_FSM].Label = Label;
218 G_FSM[C_FSM].Detect = Detect;
220 qemu_log(
"[FSM] Registration of the '%s' file system driver is complete.",Name);
224 int fsm_getMode(
int FIndex){
225 if (G_FSM[FIndex].Ready == 0)
return 0;
227 return G_FSM[FIndex].Splash;
231 void fsm_dpm_update(
char Letter){
232 char BLANK[128] = {
'U',
'n',
'k',
'n',
'o',
'w',
'n',0};
235 for(
int i = 0; i < 26; i++){
239 DPM_Disk dpm = dpm_info(DISKID);
241 if (dpm.Ready != 1) {
245 qemu_note(
"SCANNING PARTITIONS ON: %c", DISKID);
246 mbr_dump_all(DISKID);
248 for(
int f = 0; f < C_FSM; f++){
249 qemu_note(
"[FSM] [DPM] >>> Disk %c | Test %s", DISKID, G_FSM[f].Name);
251 int detect = G_FSM[f].Detect(DISKID);
256 char* lab_test = kcalloc(1,129);
258 G_FSM[f].Label(DISKID,lab_test);
263 qemu_note(
" | Label: %s", lab_test);
275 for(
int f = 0; f < C_FSM; f++){
276 qemu_note(
"[FSM] [DPM] >>> Disk %c | Test %s", DISKID, G_FSM[f].Name);
277 int detect = G_FSM[f].Detect(DISKID);
282 char* lab_test = kcalloc(1,129);
284 G_FSM[f].Label(DISKID, lab_test);
287 qemu_note(
"[FSM] [DPM] ^^^ Disk %c | Label: %s", DISKID, lab_test);
void dpm_LabelUpdate(char Letter, char *Label)
void dpm_FileSystemUpdate(char Letter, char *FileSystem)
uint32_t str_cdsp2(const char *a_str, char del)
Функция отладки
size_t strlen(const char *str)
Возращает длину строки
bool strcmpn(const char *str1, const char *str2)
Сравнение строк
void * memcpy(void *restrict destination, const void *restrict source, size_t n)
Копирование непересекающихся массивов используя SSE.