summaryrefslogtreecommitdiff
path: root/fs/sysfs.c
blob: 57a56c81a98ec98ab809d2de3b23c17614062241 (plain)
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
#include "mount.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,kmalloc_sysfs,mount_sysfs};
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[i]);
    }
    return fd_from_sysfs(map[0]);
}

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);
    *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);
}