From 87240444abfbf85f3f39a5832e6abcc0436ae31a Mon Sep 17 00:00:00 2001 From: taralesca Date: Sun, 13 Jan 2019 19:30:36 +0200 Subject: [PATCH] Unlink + save working --- sifs.c | 9 +-------- src/destroy.c | 23 +++++++++++++++++++++++ src/unlink.c | 1 + 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/sifs.c b/sifs.c index bd626e6..82570b8 100644 --- a/sifs.c +++ b/sifs.c @@ -279,14 +279,7 @@ int main(int argc, char **argv) { else { logger(DEBUG, "[main] Opened file: %s\n", argv[argc - 1]); } - if ((fdd = open("testy.tar", O_WRONLY | O_CREAT | O_TRUNC, 0644)) == -1) { - logger(DEBUG, "[main] File2 open error(%s): %d\n", "testy.tar", errno); - return -1; - } - else { - logger(DEBUG, "[main] Opened file2: %s\n", "testy.tar"); - } - + argument = malloc(strlen(argv[argc-1])); strcpy(argument, argv[argc-1]); // Moving reading head to beginning of file diff --git a/src/destroy.c b/src/destroy.c index c6cb2b4..ea5b6aa 100644 --- a/src/destroy.c +++ b/src/destroy.c @@ -1,4 +1,13 @@ #include "../lib/destroy.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include int fd; /* gets value from sifs.c */ int fdd; int enfd; @@ -58,6 +67,20 @@ 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); + lseek(fd, 0, SEEK_SET); + int crt = 0; + while(crt < ofs) { + crt += write(fd, "\0", ofs); + printf("\n\n\n\n\n\n\n%d\n\n\n\n\n\n\n", crt); + } + //~ printf("\n\n\n\n\n\n\n%d\n\n\n\n\n\n\n", write(fd, "\0", ofs)); + //~ printf("\n\n\n\n\n\n\n%d\n\n\n\n\n\n\n", write(fd, "\0", ofs)); + //~ printf("\n\n\n\n\n\n\n%d\n\n\n\n\n\n\n", write(fd, "\0", ofs)); + //~ printf("\n\n\n\n\n\n\n%d\n\n\n\n\n\n\n", write(fd, "\0", ofs)); + //printf("\n\n\n\n\n\n\n%d\n\n\n\n\n\n\n", write(fd, "\0", ofs)); lseek(fd, 0, SEEK_SET); /* move to the beginning of file */ //~ printf("FAILED!!!"); diff --git a/src/unlink.c b/src/unlink.c index fd687aa..a000716 100644 --- a/src/unlink.c +++ b/src/unlink.c @@ -17,6 +17,7 @@ int sifs_unlink(const char* path) { del_index = i; } } + free(deleted); for (int i = del_index + 1; i < parent->children_size; i++) { parent->children[i-1] = parent->children[i];