static int sysfs_mount(char *source, char *tgt, uint32_t flags, void *args) { struct fnode *tgt_dir = NULL; /* Source must be NULL */ if (source) return -1; /* Target must be a valid dir */ if (!tgt) return -1; tgt_dir = fno_search(tgt); if (!tgt_dir || ((tgt_dir->flags & FL_DIR) == 0)) { /* Not a valid mountpoint. */ return -1; } /* TODO: check empty dir if (tgt_dir->children) { return -1; } */ tgt_dir->owner = &mod_sysfs; sysfs_register("time", "/sys", sysfs_time_read, sysfs_no_write); sysfs_register("tasks","/sys", sysfs_tasks_read, sysfs_no_write); sysfs_register("mem", "/sys", sysfs_mem_read, sysfs_no_write); sysfs_register("modules", "/sys", sysfs_modules_read, sysfs_no_write); sysfs_register("mtab", "/sys", sysfs_mtab_read, sysfs_no_write); #if defined(STM32F4) || defined(STM32F7) sysfs_register("pins", "/sys", sysfs_pins_read, sysfs_no_write); #endif return 0; }
static int klog_open(const char *path, int flags) { if (klog.used) return -EBUSY; klog.used++; return task_filedesc_add(fno_search("/dev/klog")); }
static int memfs_mount(char *source, char *tgt, uint32_t flags, void *arg) { struct fnode *tgt_dir = NULL; /* Source must be NULL */ if (source) return -1; /* Target must be a valid dir */ if (!tgt) return -1; tgt_dir = fno_search(tgt); if (!tgt_dir || ((tgt_dir->flags & FL_DIR) == 0)) { /* Not a valid mountpoint. */ return -1; } /* TODO: Check empty dir if (tgt_dir->children) { return -1; } */ tgt_dir->owner = &mod_memfs; return 0; }
void sysfs_init(void) { mod_sysfs.family = FAMILY_FILE; strcpy(mod_sysfs.name, "sysfs"); mod_sysfs.mount = sysfs_mount; mod_sysfs.ops.read = sysfs_read; mod_sysfs.ops.poll = sysfs_poll; mod_sysfs.ops.write = sysfs_write; mod_sysfs.ops.close = sysfs_close; sysfs = fno_search("/sys"); register_module(&mod_sysfs); fno_mkdir(&mod_sysfs, "net", sysfs); sysfs_mutex = mutex_init(); }
int sysfs_register(char *name, char *dir, int (*do_read)(struct sysfs_fnode *sfs, void *buf, int len), int (*do_write)(struct sysfs_fnode *sfs, const void *buf, int len) ) { struct fnode *fno = fno_create(&mod_sysfs, name, fno_search(dir)); struct sysfs_fnode *mfs; if (!fno) return -1; mfs = kalloc(sizeof(struct sysfs_fnode)); if (mfs) { mfs->fnode = fno; fno->priv = mfs; mfs->do_read = do_read; mfs->do_write = do_write; return 0; } return -1; }