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;
}
};
-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;
}
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) {
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