Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dummm committed Dec 27, 2018
1 parent c19a97a commit 29f083a
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 13 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*.ko
*.obj
*.elf
sifs

# Linker output
*.ilk
Expand Down Expand Up @@ -56,3 +57,4 @@ dkms.conf
*.tar.*
=======
*.tar

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions lib/getattr.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
#ifndef getattr_h
#define getattr_h
#include "../lib/tree.h"
#include "../lib/logger.h"

#include <sys/stat.h>
#include <string.h>
#include <stdlib.h>
#include <fuse.h>
#include "tree.h"
#include "logger.h"
int sifs_getattr(const char*, struct stat*);

#endif
1 change: 1 addition & 0 deletions lib/logger.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#ifndef LOGGING_HEADERS
#define LOGGING_HEADERS

#include <stdio.h>
enum log_level_t { DEBUG, WARN, ERROR, OFF };
typedef enum log_level_t log_level;
Expand Down
5 changes: 4 additions & 1 deletion lib/tar_structure.h
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -50,4 +52,5 @@ struct tar_header {// byte offset
char ctime[12]; // 488
char mfill[8]; // 500
char xmagic[4]; // 508 "tar"
};
};
#endif
8 changes: 7 additions & 1 deletion lib/tree.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#ifndef tree_h
#define tree_h

#include "tar_structure.h"

struct node {
struct tar_header *header;
struct node *parent;
Expand All @@ -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 *);
int tree_remove_node(struct node *);
#endif
8 changes: 4 additions & 4 deletions sifs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <fuse.h>

Expand Down Expand Up @@ -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
Expand Down
60 changes: 56 additions & 4 deletions src/getattr.c
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit 29f083a

Please sign in to comment.