0

Im trying to have fuse create files when I mount the system using the init function. However whenever I mount my system the process never ends. Then i cant unmount it afterwards. How do i fix this.

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

Thats the code im using. I need to create multiple files but I cant even get this 1 file to work.

Bans
  • 1
  • how about checking for errors and outputing an error message on failure. I.E. if(NULL == fp) { perror(" fopen failed" ); exit( EXIT_FAILURE); }' that way a meaningful message will be output to stderr if the fopen fails – user3629249 Apr 12 '15 at 00:16

1 Answers1

1

Check the return of fopen if you want to know why it fails:

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

If data1 is in the same directory (not in the root path), change

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

to

fp=fopen("data1/fuse/file.txt","w+"); /* remove the first backslash */
David Ranieri
  • 39,972
  • 7
  • 52
  • 94