-
Notifications
You must be signed in to change notification settings - Fork 9
/
system.c
106 lines (87 loc) · 2.4 KB
/
system.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include <kernel.h>
#include <fileio.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include "system.h"
extern void *_gp;
int GetBootDeviceID(void)
{
static int BootDevice = -2;
char path[256];
int result;
if (BootDevice < BOOT_DEVICE_UNKNOWN)
{
getcwd(path, sizeof(path));
if (!strncmp(path, "mc0:", 4))
result = BOOT_DEVICE_MC0;
else if (!strncmp(path, "mc1:", 4))
result = BOOT_DEVICE_MC1;
else if (!strncmp(path, "mass:", 5) || !strncmp(path, "mass0:", 6))
result = BOOT_DEVICE_MASS;
#ifdef DSNET_HOST_SUPPORT
else if (!strncmp(path, "host:", 5) || !strncmp(path, "host0:", 5))
result = BOOT_DEVICE_HOST;
#endif
else
result = BOOT_DEVICE_UNKNOWN;
BootDevice = result;
}
else
result = BootDevice;
return result;
}
int RemoveFolder(const char *path)
{
fio_dirent_t dirent;
char *fullpath;
int fd, result;
result = 0;
if ((fd = fioDopen(path)) >= 0)
{
while (fioDread(fd, &dirent) > 0 && result >= 0)
{
if (!strcmp(dirent.name, ".") || !strcmp(dirent.name, ".."))
continue;
if ((fullpath = malloc(strlen(path) + strlen(dirent.name) + 2)) != NULL)
{
sprintf(fullpath, "%s/%s", path, dirent.name);
if (FIO_S_ISDIR(dirent.stat.mode))
{
result = RemoveFolder(fullpath);
}
else
{
result = fioRemove(fullpath);
}
free(fullpath);
}
}
fioDclose(fd);
if (result >= 0)
fioRmdir(path);
}
else
result = fd;
return result;
}
int SysCreateThread(void *function, void *stack, unsigned int StackSize, void *arg, int priority)
{
ee_thread_t ThreadData;
int ThreadID;
ThreadData.func = function;
ThreadData.stack = stack;
ThreadData.stack_size = StackSize;
ThreadData.gp_reg = &_gp;
ThreadData.initial_priority = priority;
ThreadData.attr = ThreadData.option = 0;
if ((ThreadID = CreateThread(&ThreadData)) >= 0)
{
if (StartThread(ThreadID, arg) < 0)
{
DeleteThread(ThreadID);
ThreadID = -1;
}
}
return ThreadID;
}