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
|
#include "mount.h"
#include <stdlib.h>
#include "sysfs.h"
#include "mem.h"
#include "kmalloc.h"
#include "mount.h"
#include "log.h"
#include "lib/string/string.h"
static const char* names[] = {"/mem","/kmalloc","/mount"};
static uint32_t map[]={mem_sysfs,mem_sysfs_set,
kmalloc_sysfs,NULL,
mount_sysfs,NULL,
};
static uint32_t count=3;
/* mount interface */
fd sysfs_file_open(mount *m,char *path)
{
klog("sysfs file open: %s",path);
for (int i=0;i<count;i++)
{
if(!strcmp(path,names[i]))
return fd_from_sysfs(map[2*i],map[2*i+1]);
}
return fd_from_sysfs(map[0],map[1]);
}
int sysfs_read_dir(mount *m,char *path, fs_dirent *dirs, uint32_t *pos)
{
if(*pos>=count)return 0;
memcpy(dirs->name,names[*pos],strlen(names[*pos])+1);
dirs->inode=0;
*pos+=1;
return 1;
}
void sysfs_mount(char* path)
{
mount m;
m.type=MOUNT_TYPE_SYS;
memcpy(m.path,path,strlen(path)+1);
m.mount_file_open=sysfs_file_open;
m.mount_read_dir=sysfs_read_dir;
mount_add(m);
}
|