#include <lunaix/fs/twifs.h>
void
-__blk_rd_serial(struct twimap* map)
+__twimap_read_serial(struct twimap* map)
{
struct hba_device* hbadev = twimap_data(map, struct hba_device*);
twimap_printf(map, "%s", hbadev->serial_num);
}
void
-__blk_rd_last_status(struct twimap* map)
+__twimap_read_last_status(struct twimap* map)
{
struct hba_device* hbadev = twimap_data(map, struct hba_device*);
twimap_printf(map,
}
void
-__blk_rd_capabilities(struct twimap* map)
+__twimap_read_capabilities(struct twimap* map)
{
struct hba_device* hbadev = twimap_data(map, struct hba_device*);
twimap_printf(map, "%p", hbadev->capabilities);
}
void
-__blk_rd_aoffset(struct twimap* map)
+__twimap_read_alignment(struct twimap* map)
{
struct hba_device* hbadev = twimap_data(map, struct hba_device*);
twimap_printf(map, "%d", hbadev->alignment_offset);
}
void
-__blk_rd_wwid(struct twimap* map)
+__twimap_read_wwid(struct twimap* map)
{
struct hba_device* hbadev = twimap_data(map, struct hba_device*);
u32_t h = hbadev->wwn >> 32;
struct twifs_node* dev_root = (struct twifs_node*)fs_node;
struct twimap* map;
- map = twifs_mapping(dev_root, bdev->driver, "serial");
- map->read = __blk_rd_serial;
-
- map = twifs_mapping(dev_root, bdev->driver, "last_status");
- map->read = __blk_rd_last_status;
-
- map = twifs_mapping(dev_root, bdev->driver, "wwid");
- map->read = __blk_rd_wwid;
-
- map = twifs_mapping(dev_root, bdev->driver, "capabilities");
- map->read = __blk_rd_capabilities;
-
- map = twifs_mapping(dev_root, bdev->driver, "alignment_offset");
- map->read = __blk_rd_aoffset;
+ twimap_export_value(dev_root, serial, FSACL_aR, bdev->driver);
+ twimap_export_value(dev_root, last_status, FSACL_aR, bdev->driver);
+ twimap_export_value(dev_root, wwid, FSACL_aR, bdev->driver);
+ twimap_export_value(dev_root, capabilities, FSACL_aR, bdev->driver);
+ twimap_export_value(dev_root, alignment, FSACL_aR, bdev->driver);
}
\ No newline at end of file
}
static void
-__pci_read_cspace(struct twimap* map)
+__twimap_read_config(struct twimap* map)
{
struct pci_probe* probe;
/*---------- TwiFS interface definition ----------*/
static void
-__pci_read_revid(struct twimap* map)
+__twimap_read_revision(struct twimap* map)
{
struct pci_probe* probe;
}
static void
-__pci_read_class(struct twimap* map)
+__twimap_read_class(struct twimap* map)
{
struct pci_probe* probe;
}
static void
-__pci_read_devinfo(struct twimap* map)
+__twimap_read_pci_devinfo(struct twimap* map)
{
struct pci_probe* probe;
}
static void
-__pci_bar_read(struct twimap* map)
+__twimap_read_io_bases(struct twimap* map)
{
struct pci_probe* probe;
int bar_index;
}
static int
-__pci_bar_gonext(struct twimap* map)
+__twimap_gonext_io_bases(struct twimap* map)
{
if (twimap_index(map, int) >= 5) {
return 0;
}
static void
-__pci_read_binding(struct twimap* map)
+__twimap_reset_io_bases(struct twimap* map)
+{
+ map->index = 0;
+}
+
+static void
+__twimap_read_binding(struct twimap* map)
{
struct pci_probe* probe;
struct devident* devid;
probe = changeling_reveal(pos, pci_probe_morpher);
pci_dev = twifs_dir_node(pci_class, "%x", probe->loc);
- map = twifs_mapping(pci_dev, probe, "config");
- map->read = __pci_read_cspace;
-
- map = twifs_mapping(pci_dev, probe, "revision");
- map->read = __pci_read_revid;
-
- map = twifs_mapping(pci_dev, probe, "class");
- map->read = __pci_read_class;
-
- map = twifs_mapping(pci_dev, probe, "binding");
- map->read = __pci_read_binding;
-
- map = twifs_mapping(pci_dev, probe, "io_bases");
- map->read = __pci_bar_read;
- map->go_next = __pci_bar_gonext;
+ twimap_export_value(pci_dev, config, FSACL_aR, probe);
+ twimap_export_value(pci_dev, revision, FSACL_aR, probe);
+ twimap_export_value(pci_dev, class, FSACL_aR, probe);
+ twimap_export_value(pci_dev, binding, FSACL_aR, probe);
+ twimap_export_list (pci_dev, io_bases, FSACL_aR, probe);
}
}
EXPORT_TWIFS_PLUGIN(pci_devs, pci_build_fsmapping);
hwrtc_twifs_export(struct hwrtc_potens* pot)
{
const char* name = pot->rtc_proxy->name_val;
- struct twimap* rtc_mapping = twifs_mapping(NULL, pot, name);
+ struct twimap* rtc_mapping;
+
+ rtc_mapping = twifs_mapping(NULL, pot, FSACL_aR, name);
rtc_mapping->read = __hwrtc_readinfo;
}
#include <lunaix/fs/twimap.h>
#include <lunaix/spike.h>
+struct twifs_ops
+{
+ int (*write)(struct v_inode* inode,
+ void* buffer,
+ size_t len,
+ size_t fpos);
+ int (*read)(struct v_inode* inode,
+ void* buffer,
+ size_t len,
+ size_t fpos);
+};
+
struct twifs_node
{
struct hstr name;
inode_t ino_id;
void* data;
u32_t itype;
+ int acl;
+
char name_val[VFS_NAME_MAXLEN];
struct llist_header children;
struct llist_header siblings;
- struct
- {
- int (*write)(struct v_inode* inode,
- void* buffer,
- size_t len,
- size_t fpos);
- int (*read)(struct v_inode* inode,
- void* buffer,
- size_t len,
- size_t fpos);
- } ops;
+ struct twifs_ops ops;
+};
+
+struct twifs_export
+{
+ char* name;
+ int acl;
+ struct twifs_ops ops;
+};
+
+struct twimap_export
+{
+ char* name;
+ int acl;
+ struct twimap_ops ops;
};
#define twinode_getdata(inode, type) \
#define EXPORT_TWIFS_PLUGIN(label, plg_init) \
export_ldga_el(twiplugin_inits, label, ptr_t, plg_init)
-void
-twifs_register_plugins();
+#define __twifs_export_base(name_, acl_) \
+ .name=stringify(name_), .acl=(acl_)
+
+#define twifs_node_ro(name_, acl_) \
+ struct twifs_export __twifs_exp_##name_ = \
+ { __twifs_export_base(name_, acl_), \
+ .ops = { .read = __twifs_read_##name_ }}
+
+#define twifs_node_rw(name_, acl_) \
+ struct twifs_export __twifs_exp_##name_ = \
+ { __twifs_export_base(name_, acl_), \
+ .ops = { .read = __twifs_read_##name_, \
+ .write = __twifs_write_##name_ }}
+
+#define twimap_value_export(name_, acl_) \
+ struct twimap_export __twimap_exp_##name_ = \
+ { __twifs_export_base(name_, acl_), \
+ .ops = { .read = __twimap_read_##name_ }}
+
+#define twimap_list_export(name_, acl_) \
+ struct twimap_export __twimap_exp_##name_ = \
+ { __twifs_export_base(name_, acl_), \
+ .ops = { .read = __twimap_read_##name_, \
+ .go_next = __twimap_gonext_##name_, \
+ .reset = __twimap_reset_##name_, }}
+
+#define twifs_export(parent, name_, data_) \
+ twifs_basic_node_from(parent, &__twifs_exp_##name_, data_)
+
+#define twimap_export(parent, name_, data_) \
+ twifs_mapped_node_from(parent, &__twimap_exp_##name_, data_)
+
+#define twifs_export_ro(parent, name_, acl_, data_) \
+ ({ \
+ twifs_node_ro(name_, acl_); \
+ twifs_export(parent, name_, data_); \
+ })
+
+#define twimap_export_value(parent, name_, acl_, data_) \
+ ({ \
+ twimap_value_export(name_, acl_); \
+ twimap_export(parent, name_, data_); \
+ })
+
+#define twimap_export_list(parent, name_, acl_, data_) \
+ ({ \
+ twimap_list_export(name_, acl_); \
+ twimap_export(parent, name_, data_); \
+ })
void
-twifs_init();
+twifs_register_plugins();
struct twifs_node*
twifs_file_node_vargs(struct twifs_node* parent, const char* fmt, va_list args);
-struct twifs_node*
-twifs_file_node(struct twifs_node* parent, const char* fmt, ...);
-
struct twifs_node*
twifs_dir_node(struct twifs_node* parent, const char* fmt, ...);
int
twifs_rm_node(struct twifs_node* node);
-struct twimap*
-twifs_mapping(struct twifs_node* parent, void* data, const char* fmt, ...);
+struct twifs_node*
+twifs_basic_node_from(struct twifs_node* parent,
+ struct twifs_export* exp_def, void* data);
-#define twimap_entry_simple(parent, name, data, read_cb) \
- ({ \
- struct twimap* map = twifs_mapping((parent), (data), (name)); \
- map->read = (read_cb); \
- map; \
- })
+struct twifs_node*
+twifs_mapped_node_from(struct twifs_node* parent,
+ struct twimap_export* exp_def, void* data);
+
+struct twimap*
+twifs_mapping(struct twifs_node* parent,
+ void* data, int acl, const char* fmt, ...);
#endif /* __LUNAIX_TWIFS_H */
extern struct v_file_ops twimap_file_ops;
+#define __TWIMAP_OPS \
+ void (*read)(struct twimap* mapping); \
+ int (*go_next)(struct twimap* mapping); \
+ void (*reset)(struct twimap* mapping);
+
+struct twimap;
+struct twimap_ops
+{
+ __TWIMAP_OPS
+};
+
struct twimap
{
void* index;
void* buffer;
void* data;
size_t size_acc;
- void (*read)(struct twimap* mapping);
- int (*go_next)(struct twimap* mapping);
- void (*reset)(struct twimap* mapping);
+ union
+ {
+ struct twimap_ops ops;
+ struct { __TWIMAP_OPS };
+ };
+
};
int
#define FSACL_g_ 0
#define FSACL_o_ 0
-// any read
+// any
#define FSACL_aR (FSACL_uR | FSACL_gR | FSACL_oR)
-// any write
#define FSACL_aW (FSACL_uW | FSACL_gW | FSACL_oW)
-// any execute
#define FSACL_aX (FSACL_uX | FSACL_gX | FSACL_oX)
+// user/group
+#define FSACL_ugR (FSACL_uR | FSACL_gR)
+#define FSACL_ugW (FSACL_uW | FSACL_gW)
+#define FSACL_ugX (FSACL_uX | FSACL_gX)
+
+
#define __fsacl_sel(scope, type) (FSACL_##scope##type)
#define FSACL_u(r, w, x) \
(v__(__fsacl_sel(u, r)) | v__(__fsacl_sel(u, w)) | v__(__fsacl_sel(u, x)))
blk_root = twifs_dir_node(NULL, "block");
}
-void
-__blk_rd_lblksz(struct twimap* map)
+static void
+__twimap_read_lblk_size(struct twimap* map)
{
struct block_dev* bdev = twimap_data(map, struct block_dev*);
size_t lblksz = bdev->blk_size;
twimap_printf(map, "%u", lblksz);
}
-void
-__blk_rd_name(struct twimap* map)
+static void
+__twimap_read_name(struct twimap* map)
{
struct block_dev* bdev = twimap_data(map, struct block_dev*);
twimap_printf(map, "%s", bdev->name);
}
-void
-__blk_rd_start_lba(struct twimap* map)
+static void
+__twimap_read_lba_begin(struct twimap* map)
{
struct block_dev* bdev = twimap_data(map, struct block_dev*);
twimap_printf(map, "%d", bdev->start_lba);
}
-void
-__blk_rd_end_lba(struct twimap* map)
+static void
+__twimap_read_lba_end(struct twimap* map)
{
struct block_dev* bdev = twimap_data(map, struct block_dev*);
twimap_printf(map, "%d", bdev->end_lba);
}
-void
-__blk_rd_size(struct twimap* map)
+static void
+__twimap_read_size(struct twimap* map)
{
struct block_dev* bdev = twimap_data(map, struct block_dev*);
twimap_printf(
void
__map_internal(struct block_dev* bdev, void* fsnode)
{
- struct twifs_node* dev_root = (struct twifs_node*)fsnode;
-
- struct twimap* map = twifs_mapping(dev_root, bdev, "size");
- map->read = __blk_rd_size;
-
- map = twifs_mapping(dev_root, bdev, "lblk_size");
- map->read = __blk_rd_lblksz;
-
- map = twifs_mapping(dev_root, bdev, "name");
- map->read = __blk_rd_name;
-
- map = twifs_mapping(dev_root, bdev, "begin");
- map->read = __blk_rd_start_lba;
-
- map = twifs_mapping(dev_root, bdev, "end");
- map->read = __blk_rd_end_lba;
+ struct twifs_node* dev_root;
+
+ dev_root = (struct twifs_node*)fsnode;
+
+ twimap_export_value(dev_root, size, FSACL_aR, bdev);
+ twimap_export_value(dev_root, lblk_size, FSACL_aR, bdev);
+ twimap_export_value(dev_root, name, FSACL_aR, bdev);
+ twimap_export_value(dev_root, lba_begin, FSACL_aR, bdev);
+ twimap_export_value(dev_root, lba_end, FSACL_aR, bdev);
}
void
}
static int
-__devdb_db_gonext(struct twimap* mapping)
+__twimap_gonext_devtab(struct twimap* mapping)
{
struct device_def* current = twimap_index(mapping, struct device_def*);
if (current->dev_list.next == &dev_registry_flat) {
}
static void
-__devdb_twifs_lsdb(struct twimap* mapping)
+__twimap_read_devtab(struct twimap* mapping)
{
char flags[64];
struct device_def* def = twimap_index(mapping, struct device_def*);
flags);
}
-void
-__devdb_reset(struct twimap* map)
+static void
+__twimap_reset_devtab(struct twimap* map)
{
map->index =
container_of(dev_registry_flat.next, struct device_def, dev_list);
static void
devdb_twifs_plugin()
{
- struct twimap* map = twifs_mapping(NULL, NULL, "devtab");
- map->reset = __devdb_reset;
- map->read = __devdb_twifs_lsdb;
- map->go_next = __devdb_db_gonext;
+ twimap_export_list(NULL, devtab, FSACL_aR, NULL);
}
EXPORT_TWIFS_PLUGIN(devdb, devdb_twifs_plugin);
\ No newline at end of file
if (waitq_empty(current_wq)) {
return;
}
-
+
block_current_thread();
if (!check_stall) {
void
pwake_one(waitq_t* queue)
{
- if (llist_empty(&queue->waiters)) {
+ if (waitq_empty(queue)) {
return;
}
void
pwake_all(waitq_t* queue)
{
- if (llist_empty(&queue->waiters)) {
+ if (waitq_empty(queue)) {
return;
}
return errno;
}
-__DEFINE_LXSYSCALL3(int,
- execve,
- const char*,
- filename,
- const char*,
- argv[],
- const char*,
- envp[])
+__DEFINE_LXSYSCALL3(int, execve, const char*, filename,
+ const char*, argv[], const char*, envp[])
{
int errno = 0;
int acl;
// Always yield the process that want execve!
schedule();
- // this will never get executed!
- return -1;
+ unreachable;
}
\ No newline at end of file
extern struct llist_header all_mnts;
-void
-__mount_read(struct twimap* map)
+static void
+__twimap_read_mounts(struct twimap* map)
{
char path[512];
struct v_mount* mnt = twimap_index(map, struct v_mount*);
twimap_printf(map, "\n");
}
-int
-__mount_next(struct twimap* map)
+static int
+__twimap_gonext_mounts(struct twimap* map)
{
struct v_mount* mnt = twimap_index(map, struct v_mount*);
if (mnt->list.next == &all_mnts) {
return 1;
}
-void
-__mount_reset(struct twimap* map)
+static void
+__twimap_reset_mounts(struct twimap* map)
{
map->index = container_of(all_mnts.next, struct v_mount, list);
}
void
-__version_rd(struct twimap* map)
+__twimap_read_version(struct twimap* map)
{
twimap_printf(map,
"Lunaix "
void
vfs_export_attributes()
{
- struct twimap* map = twifs_mapping(NULL, NULL, "mounts");
- map->read = __mount_read;
- map->go_next = __mount_next;
- map->reset = __mount_reset;
-
- map = twifs_mapping(NULL, NULL, "version");
- map->read = __version_rd;
+ twimap_export_list (NULL, mounts, FSACL_ugR, NULL);
+ twimap_export_value(NULL, version, FSACL_ugR, NULL);
}
EXPORT_TWIFS_PLUGIN(vfs_general, vfs_export_attributes);
\ No newline at end of file
}
static void
-read_fslist(struct twimap *mapping)
+__twimap_read_fstab(struct twimap *mapping)
{
struct filesystem *pos, *n;
llist_for_each(pos, n, &fs_flatlist, fs_flat)
static void
fstab_twifs_plugin()
{
- struct twimap* map = twifs_mapping(NULL, NULL, "fstab");
- map->read = read_fslist;
+ twimap_export_value(NULL, fstab, FSACL_ugR, NULL);
}
EXPORT_TWIFS_PLUGIN(fstab, fstab_twifs_plugin);
\ No newline at end of file
#include <asm/pagetable.h>
static struct twifs_node* fs_root;
-
static struct cake_pile* twi_pile;
-
static volatile u32_t inode_id = 0;
extern const struct v_file_ops twifs_file_ops;
extern const struct v_inode_ops twifs_inode_ops;
-struct twifs_node*
+static struct twifs_node*
__twifs_new_node(struct twifs_node* parent,
- const char* name,
- int name_len,
- u32_t itype)
+ const char* name, int name_len, u32_t itype)
{
struct twifs_node* node = cake_grab(twi_pile);
memset(node, 0, sizeof(*node));
return node;
}
-void
+static void
__twifs_init_inode(struct v_superblock* vsb, struct v_inode* inode)
{
inode->ops = (struct v_inode_ops*)&twifs_inode_ops;
fsapi_inode_setowner(inode, 0, 0);
}
-int
+static int
__twifs_mount(struct v_superblock* vsb, struct v_dnode* mount_point)
{
vsb->ops.init_inode = __twifs_init_inode;
return 0;
}
-int
+static int
__twifs_unmount(struct v_superblock* vsb)
{
return 0;
}
-int
+static int
__twifs_fwrite(struct v_inode* inode, void* buffer, size_t len, size_t fpos)
{
struct twifs_node* twi_node = (struct twifs_node*)inode->data;
return twi_node->ops.write(inode, buffer, len, fpos);
}
-int
+static int
__twifs_fwrite_pg(struct v_inode* inode, void* buffer, size_t fpos)
{
return __twifs_fwrite(inode, buffer, PAGE_SIZE, fpos);
}
-int
+static int
__twifs_fread(struct v_inode* inode, void* buffer, size_t len, size_t fpos)
{
struct twifs_node* twi_node = (struct twifs_node*)inode->data;
return twi_node->ops.read(inode, buffer, len, fpos);
}
-int
+static int
__twifs_fread_pg(struct v_inode* inode, void* buffer, size_t fpos)
{
return __twifs_fread(inode, buffer, PAGE_SIZE, fpos);
}
-struct twifs_node*
+static struct twifs_node*
__twifs_get_node(struct twifs_node* parent, struct hstr* name)
{
if (!parent)
return NULL;
}
-int
+static int
__twifs_dirlookup(struct v_inode* inode, struct v_dnode* dnode)
{
struct twifs_node* twi_node = (struct twifs_node*)inode->data;
return ENOTDIR;
}
- struct twifs_node* child_node = __twifs_get_node(twi_node, &dnode->name);
- if (child_node) {
- struct v_inode* child_inode = vfs_i_find(inode->sb, child_node->ino_id);
+ struct twifs_node* twinode = __twifs_get_node(twi_node, &dnode->name);
+ if (twinode) {
+ struct v_inode* child_inode = vfs_i_find(inode->sb, twinode->ino_id);
if (child_inode) {
goto done;
}
return ENOENT;
}
- child_inode->id = child_node->ino_id;
- child_inode->itype = child_node->itype;
- child_inode->data = child_node;
+ child_inode->id = twinode->ino_id;
+ child_inode->itype = twinode->itype;
+ child_inode->data = twinode;
+
+ if (twinode->acl != -1) {
+ fsapi_inode_setaccess(child_inode, twinode->acl);
+ }
vfs_i_addhash(child_inode);
done:
- dnode->data = child_node->data;
+ dnode->data = twinode->data;
vfs_assign_inode(dnode, child_inode);
return 0;
}
return ENOENT;
}
-int
+static int
__twifs_iterate_dir(struct v_file* file, struct dir_context* dctx)
{
struct twifs_node* twi_node = (struct twifs_node*)(file->inode->data);
return 0;
}
-int
+static int
__twifs_openfile(struct v_inode* inode, struct v_file* file)
{
struct twifs_node* twi_node = (struct twifs_node*)inode->data;
return ENOTSUP;
}
+static inline struct twifs_node*
+__twifs_create_node(struct twifs_node* parent,
+ const char* name, int acl)
+{
+ struct twifs_node* twi_node;
+ unsigned int size;
+
+ size = strlen(name);
+ parent = parent ?: fs_root;
+ twi_node = __twifs_new_node(parent, name, size, F_FILE);
+ twi_node->acl = acl;
+
+ return twi_node;
+}
+
+static int
+__twifs_twimap_file_read(struct v_inode* inode,
+ void* buf, size_t len, size_t fpos)
+{
+ struct twimap* map = twinode_getdata(inode, struct twimap*);
+ return twimap_read(map, buf, len, fpos);
+}
+
+
int
twifs_rm_node(struct twifs_node* node)
{
}
struct twifs_node*
-twifs_file_node(struct twifs_node* parent, const char* fmt, ...)
+twifs_dir_node(struct twifs_node* parent, const char* fmt, ...)
{
+ size_t len;
+ char buf[VFS_NAME_MAXLEN];
+ struct twifs_node* twi_node;
+
va_list args;
va_start(args, fmt);
- struct twifs_node* twi_node = twifs_file_node_vargs(parent, fmt, args);
+ len = ksnprintfv(buf, fmt, VFS_NAME_MAXLEN, args);
+ twi_node =
+ __twifs_new_node(parent ? parent : fs_root, buf, len, VFS_IFDIR);
+
+ twi_node->acl = FSACL_aR | FSACL_aX;
va_end(args);
return twi_node;
}
+
struct twifs_node*
-twifs_dir_node(struct twifs_node* parent, const char* fmt, ...)
+twifs_basic_node_from(struct twifs_node* parent,
+ struct twifs_export* def, void* data)
{
- va_list args;
- va_start(args, fmt);
-
- char buf[VFS_NAME_MAXLEN];
- size_t len = ksnprintfv(buf, fmt, VFS_NAME_MAXLEN, args);
- struct twifs_node* twi_node =
- __twifs_new_node(parent ? parent : fs_root, buf, len, VFS_IFDIR);
-
- va_end(args);
+ struct twifs_node* twi_node;
+
+ twi_node = __twifs_create_node(parent, def->name, def->acl);
+ twi_node->ops = def->ops;
+ twi_node->data = data;
return twi_node;
}
-void
-twifs_init()
+struct twifs_node*
+twifs_mapped_node_from(struct twifs_node* parent,
+ struct twimap_export* def, void* data)
{
- struct filesystem* fs;
- fs = fsapi_fs_declare("twifs", FSTYPE_PSEUDO | FSTYPE_ROFS);
+ struct twifs_node* twi_node;
+ struct twimap* map_;
- fsapi_fs_set_mntops(fs, __twifs_mount, __twifs_unmount);
- fsapi_fs_finalise(fs);
+ map_ = twimap_create(data);
+ twi_node = __twifs_create_node(parent, def->name, def->acl);
- twi_pile = cake_new_pile("twifs_node", sizeof(struct twifs_node), 1, 0);
- fs_root = twifs_dir_node(NULL, NULL, 0, 0);
-}
-EXPORT_FILE_SYSTEM(twifs, twifs_init);
+ twi_node->data = map_;
+ twi_node->ops.read = __twifs_twimap_file_read;
+ // twi_node->ops.write = __twifs_twimap_file_write;
-void
-twifs_register_plugins()
-{
- ldga_invoke_fn0(twiplugin_inits);
-}
+ if (def->ops.go_next) {
+ map_->ops.go_next = def->ops.go_next;
+ }
-int
-__twifs_twimap_file_read(struct v_inode* inode,
- void* buf,
- size_t len,
- size_t fpos)
-{
- struct twimap* map = twinode_getdata(inode, struct twimap*);
- return twimap_read(map, buf, len, fpos);
+ if (def->ops.reset) {
+ map_->ops.reset = def->ops.reset;
+ }
+
+ map_->ops.read = def->ops.read;
+
+ return twi_node;
}
struct twimap*
-twifs_mapping(struct twifs_node* parent, void* data, const char* fmt, ...)
+twifs_mapping(struct twifs_node* parent,
+ void* data, int acl, const char* fmt, ...)
{
va_list args;
va_start(args, fmt);
struct twimap* map = twimap_create(data);
struct twifs_node* node = twifs_file_node_vargs(parent, fmt, args);
+
node->ops.read = __twifs_twimap_file_read;
node->data = map;
+ node->acl = acl;
return map;
}
+void
+twifs_register_plugins()
+{
+ ldga_invoke_fn0(twiplugin_inits);
+}
+
const struct v_file_ops twifs_file_ops = { .close = default_file_close,
.read = __twifs_fread,
.read_page = __twifs_fread_pg,
const struct v_inode_ops twifs_inode_ops = { .dir_lookup = __twifs_dirlookup,
.mkdir = default_inode_mkdir,
.rmdir = default_inode_rmdir,
- .open = __twifs_openfile };
\ No newline at end of file
+ .open = __twifs_openfile };
+
+
+static void
+twifs_init()
+{
+ struct filesystem* fs;
+ fs = fsapi_fs_declare("twifs", FSTYPE_PSEUDO | FSTYPE_ROFS);
+
+ fsapi_fs_set_mntops(fs, __twifs_mount, __twifs_unmount);
+ fsapi_fs_finalise(fs);
+
+ twi_pile = cake_new_pile("twifs_node", sizeof(struct twifs_node), 1, 0);
+ fs_root = twifs_dir_node(NULL, NULL, 0, 0);
+}
+EXPORT_FILE_SYSTEM(twifs, twifs_init);
\ No newline at end of file
}
static void
-__twimap_kprintf_read(struct twimap* map)
+__twimap_read_kmsg(struct twimap* map)
{
struct kp_records* __kprecs = twimap_data(map, struct kp_records*);
static void
kprintf_mapping_init()
{
- twimap_entry_simple(NULL, "kmsg", &kprecs, __twimap_kprintf_read);
+ twimap_export_value(NULL, kmsg, FSACL_ugR, &kprecs);
}
EXPORT_TWIFS_PLUGIN(kprintf, kprintf_mapping_init);
}
static void
-read_lrulist_entry(struct twimap* map)
+__twimap_read_lru_pool(struct twimap* map)
{
struct lru_zone* zone;
}
static void
-read_lrulist_reset(struct twimap* map)
+__twimap_reset_lru_pool(struct twimap* map)
{
map->index = container_of(&zone_lead, struct lru_zone, zones);
twimap_printf(map, "name, n_objs, hot, n_evt, n_half, n_full, status\n");
}
static int
-read_lrulist_next(struct twimap* map)
+__twimap_gonext_lru_pool(struct twimap* map)
{
struct lru_zone* zone;
struct llist_header* next;
static void
lru_pool_twimappable()
{
- struct twimap* map;
-
- map = twifs_mapping(NULL, NULL, "lru_pool");
- map->read = read_lrulist_entry;
- map->reset = read_lrulist_reset;
- map->go_next = read_lrulist_next;
+ twimap_export_list(NULL, lru_pool, FSACL_aR, NULL);
}
EXPORT_TWIFS_PLUGIN(__lru_twimap, lru_pool_twimappable);
\ No newline at end of file
if (!pos)
return NULL;
-
+
void* piece;
piece_t found_index, *fl_slot;
cake_release(struct cake_pile* pile, void* area)
{
piece_t piece_index;
- size_t dsize = 0;
+ size_t dsize = 0, maybe_index;
+
+ piece_t *fl_slot;
struct cake_s *pos, *n;
struct llist_header* hdrs[2] = { &pile->full, &pile->partial };
if (pos->first_piece > area) {
continue;
}
- dsize = (ptr_t)(area - pos->first_piece);
- piece_index = dsize / pile->piece_size;
- if (piece_index < pile->pieces_per_cake) {
+
+ dsize = __ptr(area - pos->first_piece);
+ maybe_index = dsize / pile->piece_size;
+
+ if (maybe_index < pile->pieces_per_cake) {
+ piece_index = (piece_t)maybe_index;
goto found;
}
}
found:
assert(!(dsize % pile->piece_size));
- piece_t *fl_slot;
+ assert_msg(piece_index != pos->next_free, "double free");
fl_slot = __fl_slot(pos, piece_index);
*fl_slot = pos->next_free;
pos->next_free = piece_index;
- assert_msg(*fl_slot != pos->next_free, "double free");
-
pos->used_pieces--;
pile->alloced_pieces--;
extern struct llist_header piles;
-int
-__cake_stat_gonext(struct twimap* map)
+static int
+__twimap_gonext_pinkiepie(struct twimap* map)
{
struct cake_pile* pile = twimap_index(map, struct cake_pile*);
if (pile->piles.next == &piles) {
return 1;
}
-void
-__cake_stat_reset(struct twimap* map)
+static void
+__twimap_reset_pinkiepie(struct twimap* map)
{
map->index = container_of(&piles, struct cake_pile, piles);
twimap_printf(map, "name cakes pages size slices actives\n");
}
-void
-__cake_rd_stat(struct twimap* map)
+static void
+__twimap_read_pinkiepie(struct twimap* map)
{
struct cake_pile* pos = twimap_index(map, struct cake_pile*);
twimap_printf(map,
pos->alloced_pieces);
}
-void
-__cake_rd_psize(struct twimap* map)
+static void
+__twimap_read_piece_size(struct twimap* map)
{
struct cake_pile* pile = twimap_data(map, struct cake_pile*);
twimap_printf(map, "%u", pile->piece_size);
}
-void
-__cake_rd_ccount(struct twimap* map)
+static void
+__twimap_read_cake_count(struct twimap* map)
{
struct cake_pile* pile = twimap_data(map, struct cake_pile*);
twimap_printf(map, "%u", pile->cakes_count);
}
-void
-__cake_rd_alloced(struct twimap* map)
+static void
+__twimap_read_grabbed(struct twimap* map)
{
struct cake_pile* pile = twimap_data(map, struct cake_pile*);
twimap_printf(map, "%u", pile->alloced_pieces);
}
-void
-__cake_rd_ppc(struct twimap* map)
+static void
+__twimap_read_pieces_per_cake(struct twimap* map)
{
struct cake_pile* pile = twimap_data(map, struct cake_pile*);
twimap_printf(map, "%u", pile->pieces_per_cake);
}
-void
-__cake_rd_ppg(struct twimap* map)
+static void
+__twimap_read_page_per_cake(struct twimap* map)
{
struct cake_pile* pile = twimap_data(map, struct cake_pile*);
twimap_printf(map, "%u", pile->pg_per_cake);
void
cake_export_pile(struct twifs_node* root, struct cake_pile* pile)
{
- struct twifs_node* pile_rt = twifs_dir_node(root, pile->pile_name);
-
- struct twimap* map = twifs_mapping(pile_rt, pile, "piece_size");
- map->read = __cake_rd_psize;
-
- map = twifs_mapping(pile_rt, pile, "cake_count");
- map->read = __cake_rd_ccount;
-
- map = twifs_mapping(pile_rt, pile, "grabbed");
- map->read = __cake_rd_alloced;
-
- map = twifs_mapping(pile_rt, pile, "pieces_per_cake");
- map->read = __cake_rd_ppc;
-
- map = twifs_mapping(pile_rt, pile, "page_per_cake");
- map->read = __cake_rd_ppg;
+ struct twifs_node* pile_rt;
+
+ pile_rt = twifs_dir_node(root, pile->pile_name);
+
+ twimap_export_value(pile_rt, piece_size, FSACL_ugR, pile);
+ twimap_export_value(pile_rt, cake_count, FSACL_ugR, pile);
+ twimap_export_value(pile_rt, grabbed, FSACL_ugR, pile);
+ twimap_export_value(pile_rt, pieces_per_cake, FSACL_ugR, pile);
+ twimap_export_value(pile_rt, page_per_cake, FSACL_ugR, pile);
}
void
cake_export()
{
- struct twifs_node* cake_root = twifs_dir_node(NULL, "cake");
+ struct cake_pile *pos, *n;
+ struct twifs_node* cake_root;
+
+ cake_root = twifs_dir_node(NULL, "cake");
- struct twimap* map = twifs_mapping(cake_root, NULL, "pinkiepie");
- map->reset = __cake_stat_reset;
- map->go_next = __cake_stat_gonext;
- map->read = __cake_rd_stat;
+ twimap_export_list(cake_root, pinkiepie, FSACL_ugR, NULL);
- struct cake_pile *pos, *n;
- llist_for_each(pos, n, &piles, piles)
- {
+ llist_for_each(pos, n, &piles, piles) {
cake_export_pile(cake_root, pos);
}
}
#include <klibc/string.h>
-void
-__clock_read_systime(struct twimap* map)
+static void
+__twimap_read_systime(struct twimap* map)
{
ticks_t sys_time = clock_systime();
twimap_printf(map, "%u", sys_time);
}
-void
-__clock_read_datetime(struct twimap* map)
+static void
+__twimap_read_datetime(struct twimap* map)
{
datetime_t dt;
clock_walltime(&dt);
dt.hour, dt.minute, dt.second);
}
-void
-__clock_read_unix(struct twimap* map)
+static void
+__twimap_read_unixtime(struct twimap* map)
{
twimap_printf(map, "%u", clock_unixtime());
}
-void
-clock_build_mapping()
-{
- struct twifs_node* root = twifs_dir_node(NULL, "clock");
- struct twimap* map;
-
- map = twifs_mapping(root, NULL, "systime");
- map->read = __clock_read_systime;
-
- map = twifs_mapping(root, NULL, "unix");
- map->read = __clock_read_unix;
-
- map = twifs_mapping(root, NULL, "datetime");
- map->read = __clock_read_datetime;
-}
-EXPORT_TWIFS_PLUGIN(sys_clock, clock_build_mapping);
-
time_t
clock_unixtime()
{
clock_walltime(datetime_t* datetime)
{
sysrtc->ops->get_walltime(sysrtc, datetime);
-}
\ No newline at end of file
+}
+
+static void
+clock_build_mapping()
+{
+ struct twifs_node* root;
+ struct twimap* map;
+
+ root = twifs_dir_node(NULL, "clock");
+
+ twimap_export_value(root, systime, FSACL_ugR, NULL);
+ twimap_export_value(root, unixtime, FSACL_ugR, NULL);
+ twimap_export_value(root, datetime, FSACL_ugR, NULL);
+}
+EXPORT_TWIFS_PLUGIN(sys_clock, clock_build_mapping);