Browse Source

move around in code

master
Jørn Guldberg 4 years ago
parent
commit
d20587798c
3 changed files with 82 additions and 70 deletions
  1. +81
    -69
      lsfs_fuse.c
  2. +1
    -1
      source_lsfs
  3. BIN
      test_disk.img.bk

+ 81
- 69
lsfs_fuse.c View File

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

+ 1
- 1
source_lsfs

@ -1 +1 @@
Subproject commit 340cacc8f5468531db857c6104eab1672defe082
Subproject commit 0858a9776d0f1f6fe66a24a09a7e92c022c18918

BIN
test_disk.img.bk View File


Loading…
Cancel
Save