mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-09 07:06:47 +00:00
vfs_alloc_dentry (#54)
* vfs_alloc_dentry * vfs_alloc_dentry * 修正dentry被错误清空的问题 Co-authored-by: fslongjin <longjin@RinGoTek.cn>
This commit is contained in:
parent
e62bbf13e5
commit
1b0c901ab2
@ -297,15 +297,12 @@ int64_t vfs_mkdir(const char *path, mode_t mode, bool from_userland)
|
||||
return -EEXIST;
|
||||
}
|
||||
|
||||
struct vfs_dir_entry_t *subdir_dentry = (struct vfs_dir_entry_t *)kzalloc(sizeof(struct vfs_dir_entry_t), 0);
|
||||
struct vfs_dir_entry_t *subdir_dentry = vfs_alloc_dentry(pathlen - last_slash);
|
||||
|
||||
list_init(&subdir_dentry->subdirs_list);
|
||||
list_init(&subdir_dentry->child_node_list);
|
||||
if (path[pathlen - 1] == '/')
|
||||
subdir_dentry->name_length = pathlen - last_slash - 2;
|
||||
else
|
||||
subdir_dentry->name_length = pathlen - last_slash - 1;
|
||||
subdir_dentry->name = (char *)kmalloc(subdir_dentry->name_length + 1, 0);
|
||||
memset((void *)subdir_dentry->name, 0, subdir_dentry->name_length + 1);
|
||||
|
||||
for (int i = last_slash + 1, cnt = 0; i < pathlen && cnt < subdir_dentry->name_length; ++i, ++cnt)
|
||||
@ -409,10 +406,9 @@ uint64_t do_open(const char *filename, int flags)
|
||||
parent_dentry = vfs_root_sb->root;
|
||||
|
||||
// 创建新的文件
|
||||
dentry = (struct vfs_dir_entry_t *)kzalloc(sizeof(struct vfs_dir_entry_t), 0);
|
||||
dentry = vfs_alloc_dentry(path_len - tmp_index);
|
||||
|
||||
dentry->name_length = path_len - tmp_index - 1;
|
||||
dentry->name = (char *)kzalloc(dentry->name_length + 1, 0);
|
||||
strncpy(dentry->name, path + tmp_index + 1, dentry->name_length);
|
||||
// kdebug("to create new file:%s namelen=%d", dentry->name, dentry->name_length)
|
||||
dentry->parent = parent_dentry;
|
||||
@ -513,7 +509,8 @@ struct vfs_dir_entry_t *vfs_alloc_dentry(const int name_size)
|
||||
struct vfs_dir_entry_t *dentry = (struct vfs_dir_entry_t *)kzalloc(sizeof(struct vfs_dir_entry_t), 0);
|
||||
if (unlikely(dentry == NULL))
|
||||
return NULL;
|
||||
dentry->name = (char *)kzalloc(name_size, 0);
|
||||
if (name_size != 0)
|
||||
dentry->name = (char *)kzalloc(name_size, 0);
|
||||
|
||||
// 初始化lockref
|
||||
spin_init(&dentry->lockref.lock);
|
||||
|
@ -205,9 +205,7 @@ static __always_inline void __devfs_init_root_inode()
|
||||
*/
|
||||
static __always_inline void __devfs_init_root_dentry()
|
||||
{
|
||||
devfs_root_dentry = (struct vfs_dir_entry_t *)kzalloc(sizeof(struct vfs_dir_entry_t), 0);
|
||||
list_init(&devfs_root_dentry->child_node_list);
|
||||
list_init(&devfs_root_dentry->subdirs_list);
|
||||
devfs_root_dentry = vfs_alloc_dentry(0);
|
||||
devfs_root_dentry->dir_ops = &devfs_dentry_ops;
|
||||
|
||||
__devfs_init_root_inode();
|
||||
|
@ -369,16 +369,11 @@ struct vfs_superblock_t *fat32_read_superblock(struct block_device *blk)
|
||||
printk_color(BLUE, BLACK, "FAT32 FSInfo\n\tFSI_LeadSig:%#018lx\n\tFSI_StrucSig:%#018lx\n\tFSI_Free_Count:%#018lx\n", fsbi->fsinfo.FSI_LeadSig, fsbi->fsinfo.FSI_StrucSig, fsbi->fsinfo.FSI_Free_Count);
|
||||
|
||||
// 初始化超级块的dir entry
|
||||
sb_ptr->root = (struct vfs_dir_entry_t *)kmalloc(sizeof(struct vfs_dir_entry_t), 0);
|
||||
memset(sb_ptr->root, 0, sizeof(struct vfs_dir_entry_t));
|
||||
|
||||
list_init(&sb_ptr->root->child_node_list);
|
||||
list_init(&sb_ptr->root->subdirs_list);
|
||||
sb_ptr->root = vfs_alloc_dentry(2);
|
||||
|
||||
sb_ptr->root->parent = sb_ptr->root;
|
||||
sb_ptr->root->dir_ops = &fat32_dEntry_ops;
|
||||
// 分配2个字节的name
|
||||
sb_ptr->root->name = (char *)(kmalloc(2, 0));
|
||||
sb_ptr->root->name[0] = '/';
|
||||
sb_ptr->root->name_length = 1;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user