Skip to content

Commit

Permalink
添加touch创建文件功能
Browse files Browse the repository at this point in the history
  • Loading branch information
qcloud committed Jul 10, 2024
1 parent 5619f4e commit 051481b
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 16 deletions.
Binary file not shown.
62 changes: 46 additions & 16 deletions eBPF_Supermarket/Filesystem_Subsystem/fast_fuse/difuse/src/difuse.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,19 @@ struct dfs_dentry *lookup_or_create_dentry(const char *path, struct dfs_dentry *

/*功能函数*/

static int di_utimens(const char *path, const struct timespec ts[2], struct fuse_file_info *fi)
{
(void)fi;
struct dfs_dentry *dentry = look_up(root, path);
if (dentry == NULL)
{
return -ENOENT;
}

return 0;
}


static int di_mkdir(const char *path, mode_t mode)
{
(void)mode;
Expand All @@ -141,6 +154,11 @@ static int dfs_create(const char *path, mode_t mode, struct fuse_file_info *fi)
{
(void)mode;
(void)fi;
struct dfs_dentry *existing = look_up(root, path);
if (existing != NULL)
{
return -EEXIST; // 文件已存在,返回错误
}
struct dfs_dentry *dentry = lookup_or_create_dentry(path, root, FILE_TYPE);
if (dentry == NULL)
{
Expand Down Expand Up @@ -180,10 +198,11 @@ static int di_getattr(const char *path, struct stat *di_stat,

/*遍历目录项*/
static int di_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
off_t offset, struct fuse_file_info *fi)
off_t offset, struct fuse_file_info *fi, enum fuse_readdir_flags flags)
{
(void)fi;
(void)offset;
(void)flags;
struct dfs_dentry *dentry = look_up(root, path);

if (dentry == NULL)
Expand Down Expand Up @@ -245,22 +264,11 @@ static int di_read(const char *path, char *buf, size_t size, off_t offset,
return size;
}






static struct fuse_operations difs_ops = {
.readdir = di_readdir,
.getattr = di_getattr,
.open = di_open,
.read = di_read,
.mkdir = di_mkdir,
.create = dfs_create,
};

int main(int argc, char *argv[])
static void *di_init(struct fuse_conn_info *conn, struct fuse_config *cfg)
{
(void)conn; // 如果不使用这个参数,可以忽略它

// 创建并初始化根目录的 inode 和 dentry
struct dfs_inode *root_inode = new_inode(0, 0);
root = new_dentry("/", DIRECTORY_TYPE, NULL, root_inode);

Expand Down Expand Up @@ -289,5 +297,27 @@ int main(int argc, char *argv[])
struct dfs_dentry *file3 = new_dentry("file3", FILE_TYPE, dir2, file3_inode);
add_child_dentry(dir2, file3);

// 可以在此进行其他初始化操作

return 0; // 可以返回一个自定义的结构体,如果不需要则返回 NULL
}


static struct fuse_operations difs_ops = {
.init = di_init,
.readdir = di_readdir,
.getattr = di_getattr,
.open = di_open,
.read = di_read,
.mkdir = di_mkdir,
.create = dfs_create,
.utimens = di_utimens,
};

int main(int argc, char *argv[])
{



return fuse_main(argc, argv, &difs_ops, NULL);
}

0 comments on commit 051481b

Please sign in to comment.