diff --git a/Makefile b/Makefile index eac70ce..84152ba 100644 --- a/Makefile +++ b/Makefile @@ -35,6 +35,7 @@ sifs: \ src/open.o \ src/read.o \ src/unlink.o \ + src/rmdir.o \ src/mknod.o \ src/mkdir.o \ src/destroy.o \ @@ -52,6 +53,7 @@ sifs: \ src/open.o \ src/read.o \ src/unlink.o \ + src/rmdir.o \ src/write.o \ src/destroy.o \ sifs.o @@ -72,7 +74,6 @@ tar_structure.o: src/tar_structure.c lib/tar_structure.h tree.o: src/tree.c lib/tree.h $(CC) $(CFLAGS) -c tree.c - mkdir.o: src/mkdir.c lib/mkdir.h $(CC) $(CFLAGS) -c mkdir.c @@ -100,6 +101,9 @@ destroy.o: src/destroy.c lib/destroy.h unlink.o: src/unlink.c lib/unlink.h $(CC) $(CFLAGS) -c unlink.c +rmdir.o: src/rmdir.c lib/rmdir.h + $(CC) $(CFLAGS) -c rmdir.c + sifs.o: sifs.c lib/tar_structure.h $(CC) $(CFLAGS) -c sifs.c diff --git a/lib/rmdir.h b/lib/rmdir.h new file mode 100644 index 0000000..4f106fc --- /dev/null +++ b/lib/rmdir.h @@ -0,0 +1,15 @@ +#ifndef rmdir_h +#define rmdir_h +#include "./logger.h" /* logger */ +#include /* fuse_file_info */ +#include +#include +#include +#include +#include +#include "tree.h" +#include "logger.h" +#include "tar_structure.h" +int sifs_rmdir(const char* path); +#endif + diff --git a/sifs.c b/sifs.c index 82570b8..d708c7a 100644 --- a/sifs.c +++ b/sifs.c @@ -28,7 +28,7 @@ #include "lib/mknod.h" #include "lib/mkdir.h" #include "lib/unlink.h" -// #include "lib/rmdir.h" +#include "lib/rmdir.h" // #include "lib/symlink.h" // #include "lib/rename.h" // #include "lib/link.h" @@ -100,7 +100,7 @@ int populate_tree_directory(int fd, struct node *dir) { free(auxTar); break; } - + // Creating node //auxNode = malloc(sizeof(struct node)); auxNode = calloc(1, sizeof(struct node)); @@ -246,7 +246,7 @@ static struct fuse_operations sifs_oper = { .mknod = sifs_mknod, .mkdir = sifs_mkdir, .unlink = sifs_unlink, - // .rmdir = sifs_rmdir, + .rmdir = sifs_rmdir, // .symlink = sifs_symlink, // .rename = sifs_rename, // .link = sifs_link, @@ -279,9 +279,9 @@ int main(int argc, char **argv) { else { logger(DEBUG, "[main] Opened file: %s\n", argv[argc - 1]); } - + argument = malloc(strlen(argv[argc-1])); - strcpy(argument, argv[argc-1]); + strcpy(argument, argv[argc-1]); // Moving reading head to beginning of file lseek(fd, 0, SEEK_SET); diff --git a/src/destroy.c b/src/destroy.c index ea5b6aa..f6316c3 100644 --- a/src/destroy.c +++ b/src/destroy.c @@ -67,9 +67,9 @@ void print_tree2(struct node *n) { } void sifs_destroy(void* private_data) { - + off_t ofs = lseek(fd, 0, SEEK_END); - printf("\n\n\n\n\n\n%d\n\n\n\n\n", ofs); + printf("\n\n\n\n\n\n%ld\n\n\n\n\n", ofs); lseek(fd, 0, SEEK_SET); int crt = 0; while(crt < ofs) { @@ -85,7 +85,7 @@ void sifs_destroy(void* private_data) { lseek(fd, 0, SEEK_SET); /* move to the beginning of file */ //~ printf("FAILED!!!"); //~ } - + //struct node* parent; //parent = get_node_from_path(private_data,"/"); print_tree2((struct node*)private_data); diff --git a/src/rmdir.c b/src/rmdir.c new file mode 100644 index 0000000..0e9cd08 --- /dev/null +++ b/src/rmdir.c @@ -0,0 +1,28 @@ +#include "../lib/rmdir.h" + +int sifs_rmdir(const char* path) { + struct fuse_context* context; + context=fuse_get_context(); + + struct node* root; + root=(struct node*)context->private_data; + struct node *deleted = get_node_from_path(root, path); + + struct node* parent = deleted->parent; + printf("#######%s########\n\n\n", parent->header->name); + + int del_index; + for(int i = 0; i < parent->children_size; i++) { + if(!strcmp(parent->children[i]->header->name, deleted->header->name)){ + del_index = i; + } + } + + free(deleted); + for (int i = del_index + 1; i < parent->children_size; i++) { + parent->children[i-1] = parent->children[i]; + } + parent->children_size --; + return 0; +} +