删除文件夹时回收dentry缓存

This commit is contained in:
fslongjin
2022-09-13 16:17:35 +08:00
parent 9f2b080cda
commit 26eebaf03a
10 changed files with 132 additions and 63 deletions

View File

@ -1,5 +1,7 @@
#include "chardev.h"
#include "internal.h"
#include <filesystem/VFS/VFS.h>
#include <common/mutex.h>
#include <common/stdlib.h>
#include <common/string.h>
@ -55,7 +57,7 @@ int __devfs_chardev_register(struct devfs_private_inode_info_t *private_info, st
struct vfs_dir_entry_t *dentry = vfs_alloc_dentry(namelen + 1);
__devfs_fill_dentry(dentry, devname);
__devfs_fill_inode(dentry, __devfs_alloc_inode(), VFS_IF_DEVICE, private_info);
__devfs_fill_inode(dentry, vfs_alloc_inode(), VFS_IF_DEVICE, private_info);
// 将dentry挂载到char文件夹下
__devfs_dentry_bind_parent(chardev_folder_dentry, dentry);

View File

@ -33,11 +33,11 @@ struct vfs_superblock_t *devfs_read_superblock(struct block_device *blk)
return &devfs_sb;
}
static void devfs_write_superblock(struct vfs_superblock_t *sb) {return 0; }
static void devfs_write_superblock(struct vfs_superblock_t *sb) {return ; }
static void devfs_put_superblock(struct vfs_superblock_t *sb) {return 0; }
static void devfs_put_superblock(struct vfs_superblock_t *sb) {return ; }
static void devfs_write_inode(struct vfs_index_node_t *inode) {return 0; }
static void devfs_write_inode(struct vfs_index_node_t *inode) {return ; }
struct vfs_super_block_operations_t devfs_sb_ops =
{
.write_superblock = &devfs_write_superblock,
@ -146,7 +146,7 @@ static struct vfs_dir_entry_t *devfs_lookup(struct vfs_index_node_t *parent_inod
*/
static long devfs_mkdir(struct vfs_index_node_t *inode, struct vfs_dir_entry_t *dEntry, int mode)
{
dEntry->dir_inode = (struct vfs_index_node_t *)kzalloc(sizeof(struct vfs_index_node_t), 0);
dEntry->dir_inode = vfs_alloc_inode();
dEntry->dir_inode->file_ops = &devfs_file_ops;
dEntry->dir_inode->inode_ops = &devfs_inode_ops;
dEntry->dir_ops = &devfs_dentry_ops;
@ -181,7 +181,7 @@ struct vfs_filesystem_type_t devfs_fs_type =
static __always_inline void __devfs_init_root_inode()
{
devfs_root_dentry->dir_inode = (struct vfs_index_node_t *)kzalloc(sizeof(struct vfs_index_node_t), 0);
devfs_root_dentry->dir_inode = vfs_alloc_inode();
devfs_root_dentry->dir_inode->file_ops = &devfs_file_ops;
devfs_root_dentry->dir_inode->inode_ops = &devfs_inode_ops;

View File

@ -9,9 +9,6 @@ extern struct vfs_file_operations_t devfs_file_ops;
extern struct vfs_inode_operations_t devfs_inode_ops;
extern struct vfs_superblock_t devfs_sb;
// 分配inode
#define __devfs_alloc_inode() ((struct vfs_index_node_t *)kzalloc(sizeof(struct vfs_index_node_t), 0))
/**
* @brief 在devfs中注册字符设备该函数只应被devfs调用
*
@ -101,9 +98,7 @@ static inline void __devfs_fill_dentry(struct vfs_dir_entry_t *dentry, const cha
* @param parent 父目录项
* @param dentry 子目录项
*/
#define __devfs_dentry_bind_parent(parent_dentry, dentry) \
do \
{ \
(dentry)->parent = (parent_dentry); \
list_append(&((parent_dentry)->subdirs_list), &((dentry)->child_node_list)); \
} while (0)
#define __devfs_dentry_bind_parent(parent_dentry, dentry) ({ \
(dentry)->parent = (parent_dentry); \
list_append(&((parent_dentry)->subdirs_list), &((dentry)->child_node_list)); \
})