diff --git a/.gitignore b/.gitignore index 1278ecc..93f5120 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ *.ko *.obj *.elf +sifs # Linker output *.ilk @@ -56,3 +57,4 @@ dkms.conf *.tar.* ======= *.tar + diff --git a/Makefile b/Makefile index 4120f42..e03c4b4 100644 --- a/Makefile +++ b/Makefile @@ -41,7 +41,7 @@ tree.o: src/tree.c lib/tree.h $(CC) $(CFLAGS) -c tree.c getattr.o: src/getattr.c lib/getattr.h - $(CC) $(CFLAGS) -c sifs.c + $(CC) $(CFLAGS) -c getattr.c sifs.o: sifs.c lib/tar_structure.h $(CC) $(CFLAGS) -c sifs.c diff --git a/lib/getattr.h b/lib/getattr.h index b1e9756..dd307b9 100644 --- a/lib/getattr.h +++ b/lib/getattr.h @@ -1,7 +1,12 @@ #ifndef getattr_h #define getattr_h -#include "../lib/tree.h" -#include "../lib/logger.h" + #include +#include +#include +#include +#include "tree.h" +#include "logger.h" int sifs_getattr(const char*, struct stat*); + #endif diff --git a/lib/logger.h b/lib/logger.h index 526b3a9..b8fd99a 100644 --- a/lib/logger.h +++ b/lib/logger.h @@ -1,5 +1,6 @@ #ifndef LOGGING_HEADERS #define LOGGING_HEADERS + #include enum log_level_t { DEBUG, WARN, ERROR, OFF }; typedef enum log_level_t log_level; diff --git a/lib/tar_structure.h b/lib/tar_structure.h index cccc678..9a5aef1 100644 --- a/lib/tar_structure.h +++ b/lib/tar_structure.h @@ -5,6 +5,8 @@ * * https://www.gnu.org/software/tar/manual/html_node/Standard.html */ +#ifndef tar_structure_h +#define tar_structure_h struct tar_archive{ char archive_name[50]; @@ -50,4 +52,5 @@ struct tar_header {// byte offset char ctime[12]; // 488 char mfill[8]; // 500 char xmagic[4]; // 508 "tar" -}; \ No newline at end of file +}; +#endif \ No newline at end of file diff --git a/lib/tree.h b/lib/tree.h index dafc38b..99a7189 100644 --- a/lib/tree.h +++ b/lib/tree.h @@ -1,3 +1,8 @@ +#ifndef tree_h +#define tree_h + +#include "tar_structure.h" + struct node { struct tar_header *header; struct node *parent; @@ -8,4 +13,5 @@ struct node { int node_init(struct node *node); int tree_add_child(struct node *node, struct node *new_node); -int tree_remove_node(struct node *); \ No newline at end of file +int tree_remove_node(struct node *); +#endif \ No newline at end of file diff --git a/sifs.c b/sifs.c index fb11686..07e4403 100644 --- a/sifs.c +++ b/sifs.c @@ -49,7 +49,7 @@ // #include "lib/lock.h" #include "lib/logger.h" -//#include "lib/tree.h" +#include "lib/tree.h" #include "lib/tar_structure.h" #include @@ -222,12 +222,12 @@ int main(int argc, char **argv) { set_log_output(stdout); // Opening file - if ((fd = open(argv[3], O_RDONLY)) == -1) { - logger(DEBUG, "[main] File open error(%s): %d\n", argv[1], errno); + if ((fd = open(argv[argc - 1], O_RDONLY)) == -1) { + logger(DEBUG, "[main] File open error(%s): %d\n", argv[argc - 1], errno); return -1; } else { - logger(DEBUG, "[main] Opened file: %s\n", argv[3]); + logger(DEBUG, "[main] Opened file: %s\n", argv[argc - 1]); } // Moving reading head to beginning of file diff --git a/src/getattr.c b/src/getattr.c index 7e4f448..85ddf4f 100644 --- a/src/getattr.c +++ b/src/getattr.c @@ -1,17 +1,69 @@ #include "../lib/getattr.h" +/* + ./sifs -f -d -o default_permissions ./f ../Tars/testTar.tar + ./sifs -f -d -o default_permissions ../tests/testFolder ../tests/tars/testTar.tar + +*/ +struct node* get_node_from_path(struct node* n, const char* path) { + // +1 to remove . from filename + + // Node has the same path + if (strcmp(n->header->name + 1, path) == 0) + return n; + // Path contains the node + else if (strncmp(n->header->name + 1, path, strlen(n->header->name + 1) == 0) == 0) { +; + } + return NULL; +} int _sifs_getattr(const char* path, struct stat* sbuf) { - return 0; + return -1; } int sifs_getattr(const char* path, struct stat* sbuf) { - logger(DEBUG, "[getattr] Started\n"); - printf("caca\n"); + //logger(DEBUG, "[getattr] Started on path: %s\n", path); + + char *aux; + aux = malloc(strlen(path) + 2); + aux[0] = '.'; aux[1] = '\0'; + strcpy(aux, path); + stat(aux, sbuf); + return 0; + + if (strcmp(path, "/") == 0) { + stat("./", sbuf); + return -1; + } + + struct fuse_context* context; + context = fuse_get_context(); + + struct node* root; + root = (struct node*)context->private_data; + logger(DEBUG, "[getattr] %s\n", root->header->name); + + struct node* n; + n = get_node_from_path(root, path); + + // The 'st_dev' and 'st_blksize' fields are ignored. + // The 'st_ino' field is ignored except if the 'use_ino' mount option is given + sbuf->st_mode = strtoul(n->header->mode, NULL, 10);/* protection */ + sbuf->st_nlink = n->children_size;/* number of hard links */ + sbuf->st_uid = strtoul(n->header->uid, NULL, 10); /* user ID of owner */ + sbuf->st_gid = strtoul(n->header->gid, NULL, 10); /* group ID of owner */ + //sbuf->st_rdev = n->header->; /* device ID (if special file) */ + sbuf->st_size = strtol(n->header->size, NULL, 8); /* total size, in bytes */ + //sbuf->st_blksize = n->header->; /* blocksize for file system I/O */ + //sbuf->st_blocks = n->header->; /* number of 512B blocks allocated */ + sbuf->st_atime = strtol(n->header->atime, NULL, 10); /* time of last access */ + sbuf->st_mtime = strtol(n->header->mtime, NULL, 10); /* time of last modification */ + sbuf->st_ctime = strtol(n->header->ctime, NULL, 10); /* time of last status change */ int ret; ret = _sifs_getattr(path, sbuf); logger(DEBUG, "[getattr] Ended\n"); - return ret; + return 0; }