diff --git a/lsfs_fuse.c b/lsfs_fuse.c index 681bbe6..ee19b0b 100644 --- a/lsfs_fuse.c +++ b/lsfs_fuse.c @@ -43,6 +43,87 @@ static struct fuse_operations lsfs_oper = { .utime = lsfs_utime_STUB, }; + +int lsfs_readdir( const char *path, void *buf, fuse_fill_dir_t filler, off_t offset_to_next_entry, struct fuse_file_info *fi ) +{ + //(void) offset; + (void) fi; + //printf("readdir: (path=%s)\n", path); + + filler(buf, ".", NULL, 0); + filler(buf, "..", NULL, 0); + + Directory_Table *directory_table; + directory_table = lsfs_find_directory(path, false); + + if (directory_table != NULL) + { + for (int i = 0; i < DEFAULT_TABLE_SIZE; ++i) + { + if (strcmp( "", directory_table->entries[i].filename ) != 0) + { + filler(buf, directory_table->entries[i].filename, NULL, 0); + } + } + + } + + if (strcmp(path, "/") != 0) + { + //free(directory_table); + } + + return 0; +} + + +int lsfs_getattr( const char *path, struct stat *stbuf ) +{ + int res = 0; + lsfs_file *found_file = calloc(1, sizeof(lsfs_file)); + //printf("getattr: (path=%s)\n", path); + + memset(stbuf, 0, sizeof(struct stat)); + if( strcmp( path, "/" ) == 0 ) + { + stbuf->st_mode = S_IFDIR | 0755; + stbuf->st_nlink = 2; + } + else + { + if(lsfs_disk_getattr(found_file, path)) + { + if (found_file->entry_kind == ENTRY_FILE) + { + stbuf->st_mode = S_IFREG | 0777; + } + else if (found_file->entry_kind == ENTRY_DIRECTORY) + { + stbuf->st_mode = S_IFDIR | 0755; + stbuf->st_nlink = 2; + } + else + { + res = -ENOENT; + } + stbuf->st_nlink = 1; // @Hardcode + stbuf->st_size = found_file->size; + stbuf->st_uid = found_file->owner_id; + stbuf->st_gid = found_file->owner_id; + stbuf->st_atime = found_file->access_time; + stbuf->st_mtime = found_file->modification_time; + //free(found_file); + } + else + { + res = -ENOENT; + } + } + + return res; +} + + int lsfs_mkdir(const char *path, mode_t mode) { (void)mode; @@ -91,46 +172,6 @@ int lsfs_rename(const char *path, const char *to) { return lsfs_disk_rename_file(path, to); } -int lsfs_getattr( const char *path, struct stat *stbuf ) { - int res = 0; - lsfs_file *found_file = calloc(1, sizeof(lsfs_file)); - //printf("getattr: (path=%s)\n", path); - - memset(stbuf, 0, sizeof(struct stat)); - if( strcmp( path, "/" ) == 0 ) { - stbuf->st_mode = S_IFDIR | 0755; - stbuf->st_nlink = 2; - } else { - if(lsfs_disk_getattr(found_file, path)) { - if (found_file->entry_kind == ENTRY_FILE) - { - stbuf->st_mode = S_IFREG | 0777; - } - else if (found_file->entry_kind == ENTRY_DIRECTORY) - { - stbuf->st_mode = S_IFDIR | 0755; - stbuf->st_nlink = 2; - } - else - { - res = -ENOENT; - } - stbuf->st_nlink = 1; // @Hardcode - stbuf->st_size = found_file->size; - stbuf->st_uid = found_file->owner_id; - stbuf->st_gid = found_file->owner_id; - stbuf->st_atime = found_file->access_time; - stbuf->st_mtime = found_file->modification_time; - //free(found_file); - } - else { - res = -ENOENT; - } - } - - return res; -} - int lsfs_write(const char *path, const char *content, size_t content_length, off_t offset_to_next_entry, struct fuse_file_info *file_info) { int res = lsfs_disk_write_data_to_file( @@ -141,35 +182,6 @@ int lsfs_write(const char *path, const char *content, size_t content_length, off return res; } -int lsfs_readdir( const char *path, void *buf, fuse_fill_dir_t filler, off_t offset_to_next_entry, struct fuse_file_info *fi ) { - //(void) offset; - (void) fi; - //printf("readdir: (path=%s)\n", path); - - filler(buf, ".", NULL, 0); - filler(buf, "..", NULL, 0); - - Directory_Table *directory_table; - directory_table = lsfs_find_directory(path, false); - - if (directory_table != NULL) - { - for (int i = 0; i < DEFAULT_TABLE_SIZE; ++i) - { - if (strcmp( "", directory_table->entries[i].filename ) != 0) - { - filler(buf, directory_table->entries[i].filename, NULL, 0); - } - } - - } - if (strcmp(path, "/") != 0) - { - //free(directory_table); - } - return 0; -} - //Permission int lsfs_open( const char *path, struct fuse_file_info *fi ) { // printf("open: (path=%s)\n", path); diff --git a/source_lsfs b/source_lsfs index 340cacc..0858a97 160000 --- a/source_lsfs +++ b/source_lsfs @@ -1 +1 @@ -Subproject commit 340cacc8f5468531db857c6104eab1672defe082 +Subproject commit 0858a9776d0f1f6fe66a24a09a7e92c022c18918 diff --git a/test_disk.img.bk b/test_disk.img.bk index 7079fad..c98a68b 100644 Binary files a/test_disk.img.bk and b/test_disk.img.bk differ