33#include <fuse.h>
44#include <stdio.h>
55#include <unistd.h>
6+ #include <limits.h>
67#include <sys/types.h>
78#include <sys/stat.h>
89#include <sys/file.h>
1213
1314#define DEFAULT_FILE_DISK "persistence_file.fisopfs"
1415
15- char * filedisk = DEFAULT_FILE_DISK ;
16+ // absolute path for persistence file used in
17+ // `.init` and `.destroy` FUSE operations
18+ static char filedisk_path [2 * PATH_MAX ];
1619
1720static int
1821fisopfs_getattr (const char * path , struct stat * st )
@@ -24,6 +27,7 @@ fisopfs_getattr(const char *path, struct stat *st)
2427 st -> st_mode = __S_IFDIR | 0755 ;
2528 st -> st_nlink = 2 ;
2629 } else if (strcmp (path , "/fisop" ) == 0 ) {
30+ // TODO: remove hardcoded file
2731 st -> st_uid = 1818 ;
2832 st -> st_mode = __S_IFREG | 0644 ;
2933 st -> st_size = 2048 ;
@@ -44,11 +48,11 @@ fisopfs_readdir(const char *path,
4448{
4549 printf ("[debug] fisopfs_readdir - path: %s\n" , path );
4650
47- // Los directorios '.' y '..'
51+ // pseudo directories '.' y '..'
4852 filler (buffer , "." , NULL , 0 );
4953 filler (buffer , ".." , NULL , 0 );
5054
51- // Si nos preguntan por el directorio raiz, solo tenemos un archivo
55+ // TODO: remove hardcoded file
5256 if (strcmp (path , "/" ) == 0 ) {
5357 filler (buffer , "fisop" , NULL , 0 );
5458 return 0 ;
@@ -57,9 +61,6 @@ fisopfs_readdir(const char *path,
5761 return - ENOENT ;
5862}
5963
60- #define MAX_CONTENIDO 100
61- static char fisop_file_contenidos [MAX_CONTENIDO ] = "hola fisopfs!\n" ;
62-
6364static int
6465fisopfs_read (const char * path ,
6566 char * buffer ,
@@ -72,7 +73,10 @@ fisopfs_read(const char *path,
7273 offset ,
7374 size );
7475
75- // Solo tenemos un archivo hardcodeado!
76+ // TODO: remove hardcoded file
77+ static char fisop_file_contenidos [100 ] = "hola fisopfs!\n" ;
78+
79+ // TODO: remove hardcoded file
7680 if (strcmp (path , "/fisop" ) != 0 )
7781 return - ENOENT ;
7882
@@ -95,13 +99,16 @@ static struct fuse_operations operations = {
9599int
96100main (int argc , char * argv [])
97101{
102+ char * filedisk_name = DEFAULT_FILE_DISK ;
103+
98104 for (int i = 1 ; i < argc - 1 ; i ++ ) {
99105 if (strcmp (argv [i ], "--filedisk" ) == 0 ) {
100- filedisk = argv [i + 1 ];
106+ filedisk_name = argv [i + 1 ];
101107
102- // We remove the argument so that fuse doesn't use our
108+ // we remove the argument so that FUSE doesn't use our
103109 // argument or name as folder.
104- // Equivalent to a pop.
110+ //
111+ // equivalent to a pop.
105112 for (int j = i ; j < argc - 1 ; j ++ ) {
106113 argv [j ] = argv [j + 2 ];
107114 }
@@ -111,5 +118,13 @@ main(int argc, char *argv[])
111118 }
112119 }
113120
121+ // handle absolute path for persistence file
122+ // so background executions can work properly
123+ //
124+ // Hint: use `getcwd(3)` before `fuse_main`
125+ //
126+ // TODO: build absolute path in `filedisk_path`
127+ strcpy (filedisk_path , filedisk_name );
128+
114129 return fuse_main (argc , argv , & operations , NULL );
115130}
0 commit comments