From: acevest Date: Tue, 3 Sep 2024 12:37:28 +0000 (+0800) Subject: 添加ramfs_create X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/doc/man.7.ps?a=commitdiff_plain;h=272ddbf348e122a02896b93f0a41677ae61b9e0a;p=kernel.git 添加ramfs_create --- diff --git a/fs/dentry.c b/fs/dentry.c index 33cb782..ab3d8df 100644 --- a/fs/dentry.c +++ b/fs/dentry.c @@ -92,7 +92,9 @@ dentry_t *dentry_alloc_root(inode_t *root_inode) { dentry->d_sb = root_inode->i_sb; dentry->d_parent = dentry; } - dentry->d_inode = root_inode; + + // dentry->d_inode = root_inode; + dentry_add(dentry, root_inode); return dentry; } diff --git a/fs/ramfs.c b/fs/ramfs.c index a1df565..f4b15e4 100644 --- a/fs/ramfs.c +++ b/fs/ramfs.c @@ -52,12 +52,12 @@ static const file_operations_t ramfs_dir_operations = { }; -int ramfs_mkdir(inode_t *dir, dentry_t *dentry, int mode) { +static int ramfs_mknod(inode_t *dir, dentry_t *dentry, umode_t mode) { int ret = 0; inode_t *inode = NULL; - inode = ramfs_get_inode(dir->i_sb, mode | S_IFDIR, 0); + inode = ramfs_get_inode(dir->i_sb, mode, 0); if (inode == NULL) { return -ENOSPC; } @@ -69,15 +69,24 @@ int ramfs_mkdir(inode_t *dir, dentry_t *dentry, int mode) { return ret; } -dentry_t *ramfs_lookup(inode_t *dir, dentry_t *dentry) { +static int ramfs_create(inode_t *dir, dentry_t *dentry, umode_t mode, namei_t *ni) { + return ramfs_mknod(dir, dentry, mode | S_IFREG); +} + +static int ramfs_mkdir(inode_t *dir, dentry_t *dentry, umode_t mode) { + return ramfs_mknod(dir, dentry, mode | S_IFDIR); +} + +static dentry_t *ramfs_lookup(inode_t *dir, dentry_t *dentry) { dentry_add(dentry, NULL); return NULL; } static const inode_operations_t ramfs_dir_inode_operations = { - .mkdir = ramfs_mkdir, .lookup = ramfs_lookup, + .create = ramfs_create, + .mkdir = ramfs_mkdir, }; inode_t *ramfs_get_inode(superblock_t *sb, umode_t mode, dev_t dev) { diff --git a/fs/vfs.h b/fs/vfs.h index b4936be..40f60ff 100644 --- a/fs/vfs.h +++ b/fs/vfs.h @@ -182,10 +182,10 @@ struct inode_operations { dentry_t *(*lookup)(inode_t *, dentry_t *); // 在inode下创建一个dentry->d_small_name的文件 - int (*create)(inode_t *, dentry_t *, int, namei_t *); + int (*create)(inode_t *, dentry_t *, umode_t, namei_t *); // 创建文件夹 - int (*mkdir)(inode_t *, dentry_t *, int); + int (*mkdir)(inode_t *, dentry_t *, umode_t); // link // unlink