gpt4 book ai didi

使用C在fuse中创建文件

转载 作者:行者123 更新时间:2023-11-30 15:21:24 24 4
gpt4 key购买 nike

当我使用 init 函数安装系统时,我试图让熔断器创建文件。然而,每当我安装系统时,该过程就永远不会结束。然后我就无法卸载它了。我该如何解决这个问题。

void file_init(struct fuse_conn_info *conn){
FILE *fp;
fp=fopen("/data1/fuse/file.txt","w+");
fclose(fp);
}

这就是我使用的代码。我需要创建多个文件,但我什至无法让这 1 个文件工作。

最佳答案

如果您想知道失败的原因,请检查 fopen 的返回:

fp = fopen("/data1/fuse/file.txt", "w+");
if (fp == NULL) {
perror("fopen");
exit(EXIT_FAILURE);
}
fclose(fp);

如果data1位于同一目录(不在根路径中),则更改

fp=fopen("/data1/fuse/file.txt","w+");

fp=fopen("data1/fuse/file.txt","w+"); /* remove the first backslash */

关于使用C在fuse中创建文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29575539/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com