|
|
@ -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);
|
|
|
|