【问题标题】:Create files in fuse using C使用 C 在 fuse 中创建文件
【发布时间】:2015-06-17 00:07:37
【问题描述】:

当我使用 init 函数挂载系统时,我试图让 fuse 创建文件。但是,每当我安装我的系统时,这个过程就永远不会结束。然后我不能卸载它。我该如何解决这个问题。

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

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

【问题讨论】:

  • 如何检查错误并在失败时输出错误消息。 IE。 if(NULL == fp) { perror("fopen 失败");退出(EXIT_FAILURE); }' 这样,如果 fopen 失败,一条有意义的消息将输出到 stderr

标签: c filesystems mount fuse


【解决方案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 */

【讨论】:

    猜你喜欢
    • 2015-06-10
    • 1970-01-01
    • 2016-01-06
    • 2011-02-26
    • 1970-01-01
    • 2013-08-09
    • 1970-01-01
    • 2012-12-15
    • 1970-01-01
    相关资源
    最近更新 更多