X-Git-Url: https://scm.lunaixsky.com/lunaix-os.git/blobdiff_plain/61a1daa59589212608039e2734009870818bacd3..270869139db617e29a35bb9ded41087bb702f9ac:/lunaix-os/kernel/process/taskfs.c diff --git a/lunaix-os/kernel/process/taskfs.c b/lunaix-os/kernel/process/taskfs.c index 1e4ad2d..2015aec 100644 --- a/lunaix-os/kernel/process/taskfs.c +++ b/lunaix-os/kernel/process/taskfs.c @@ -1,13 +1,15 @@ -#include #include #include +#include #include #include #include -#include +#include #include +#include + #define COUNTER_MASK ((1 << 16) - 1) static struct hbucket* attr_export_table; @@ -51,17 +53,21 @@ taskfs_readdir(struct v_file* file, struct dir_context* dctx) { struct v_inode* inode = file->inode; pid_t pid = inode->id >> 16; - int counter = 0; + unsigned int counter = 0; if ((inode->id & COUNTER_MASK)) { return ENOTDIR; } + if (fsapi_handle_pseudo_dirent(file, dctx)) { + return 1; + } + if (pid) { struct task_attribute *pos, *n; llist_for_each(pos, n, &attributes, siblings) { - if (counter == dctx->index) { + if (counter == file->f_pos) { dctx->read_complete_callback( dctx, pos->key_val, VFS_NAME_MAXLEN, DT_FILE); return 1; @@ -75,7 +81,7 @@ taskfs_readdir(struct v_file* file, struct dir_context* dctx) struct proc_info *root = get_process(pid), *pos, *n; llist_for_each(pos, n, &root->tasks, tasks) { - if (counter == dctx->index) { + if (counter == file->f_pos) { ksnprintf(name, VFS_NAME_MAXLEN, "%d", pos->pid); dctx->read_complete_callback(dctx, name, VFS_NAME_MAXLEN, DT_DIR); return 1; @@ -85,6 +91,7 @@ taskfs_readdir(struct v_file* file, struct dir_context* dctx) return 0; } +// ascii to pid pid_t taskfs_atop(const char* str) { @@ -111,7 +118,8 @@ taskfs_dirlookup(struct v_inode* this, struct v_dnode* dnode) if (!tattr || !(proc = get_process(pid))) return ENOENT; - int errno = taskfs_mknod(dnode, pid, taskfs_next_counter(), VFS_IFFILE); + int errno = + taskfs_mknod(dnode, pid, taskfs_next_counter(), VFS_IFSEQDEV); if (!errno) { tattr->map_file->data = proc; dnode->inode->data = tattr->map_file; @@ -126,12 +134,16 @@ taskfs_dirlookup(struct v_inode* this, struct v_dnode* dnode) return ENOENT; } - return taskfs_mknod(dnode, pid, 0, VFS_IFDIR); + return taskfs_mknod(dnode, pid, 0, F_DIR); } static struct v_file_ops taskfs_file_ops = { .close = default_file_close, .read = default_file_read, + .read_page = + default_file_read_page, .write = default_file_write, + .write_page = + default_file_write_page, .readdir = taskfs_readdir, .seek = default_file_seek }; static struct v_inode_ops taskfs_inode_ops = { .dir_lookup = taskfs_dirlookup, @@ -147,14 +159,41 @@ taskfs_init_inode(struct v_superblock* vsb, struct v_inode* inode) inode->ops = &taskfs_inode_ops; } +static volatile struct v_superblock* taskfs_sb; + int taskfs_mount(struct v_superblock* vsb, struct v_dnode* mount_point) { + taskfs_sb = vsb; vsb->ops.init_inode = taskfs_init_inode; return taskfs_mknod(mount_point, 0, 0, VFS_IFDIR); } +int +taskfs_unmount(struct v_superblock* vsb) +{ + return 0; +} + +void +taskfs_invalidate(pid_t pid) +{ + struct v_dnode *pos, *n; + struct v_inode* inode = vfs_i_find(taskfs_sb, taskfs_inode_id(pid, 0)); + + if (!inode) + return; + + llist_for_each(pos, n, &inode->aka_dnodes, aka_list) + { + if (pos->ref_count > 1) { + continue; + } + vfs_d_free(pos); + } +} + #define ATTR_TABLE_LEN 16 void @@ -192,12 +231,14 @@ export_task_attr(); void taskfs_init() { - struct filesystem* taskfs = fsm_new_fs("taskfs", 5); - taskfs->mount = taskfs_mount; - - fsm_register(taskfs); + struct filesystem* fs; + fs = fsapi_fs_declare("taskfs", FSTYPE_PSEUDO); + + fsapi_fs_set_mntops(fs, taskfs_mount, taskfs_unmount); + fsapi_fs_finalise(fs); attr_export_table = vcalloc(ATTR_TABLE_LEN, sizeof(struct hbucket)); export_task_attr(); -} \ No newline at end of file +} +EXPORT_FILE_SYSTEM(taskfs, taskfs_init); \ No newline at end of file