Browse Source

move around in code

master
Jørn Guldberg 5 years ago
parent
commit
d20587798c
  1. 148
      lsfs_fuse.c
  2. 2
      source_lsfs
  3. BIN
      test_disk.img.bk

148
lsfs_fuse.c

@ -43,65 +43,56 @@ static struct fuse_operations lsfs_oper = {
.utime = lsfs_utime_STUB,
};
int lsfs_mkdir(const char *path, mode_t mode) {
(void)mode;
return lsfs_disk_create_entry(path, ENTRY_DIRECTORY);
}
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);
int lsfs_rmdir(const char *path) {
Directory_Table *directory_table;
directory_table = lsfs_find_directory(path, false);
// call to the disk controller to remove a dir
if (lsfs_disk_delete_directory(path))
if (directory_table != NULL)
{
// error case:
// directory is not empty
return -EINVAL;
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);
}
}
return 0;
}
int lsfs_unlink(const char *path) {
lsfs_file *found_file = calloc(1, sizeof(lsfs_file));
lsfs_disk_getattr(found_file, path);
lsfs_disk_delete_entry(found_file);
free(found_file);
return 0;
}
int lsfs_truncate(const char *path, off_t offset) {
(void)offset; // Truncate to this byte?
lsfs_file *found_file = calloc(1, sizeof(lsfs_file));
}
lsfs_disk_getattr(found_file, path);
lsfs_disk_truncate_file(found_file, offset);
free(found_file);
if (strcmp(path, "/") != 0)
{
//free(directory_table);
}
return 0;
}
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 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 ) {
if( strcmp( path, "/" ) == 0 )
{
stbuf->st_mode = S_IFDIR | 0755;
stbuf->st_nlink = 2;
} else {
if(lsfs_disk_getattr(found_file, path)) {
}
else
{
if(lsfs_disk_getattr(found_file, path))
{
if (found_file->entry_kind == ENTRY_FILE)
{
stbuf->st_mode = S_IFREG | 0777;
@ -123,7 +114,8 @@ int lsfs_getattr( const char *path, struct stat *stbuf ) {
stbuf->st_mtime = found_file->modification_time;
//free(found_file);
}
else {
else
{
res = -ENOENT;
}
}
@ -131,45 +123,65 @@ int lsfs_getattr( const char *path, struct stat *stbuf ) {
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(
((lsfs_file*) file_info->fh),
content_length,
(void*) content, offset_to_next_entry);
return res;
}
int lsfs_mkdir(const char *path, mode_t mode) {
(void)mode;
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);
return lsfs_disk_create_entry(path, ENTRY_DIRECTORY);
}
filler(buf, ".", NULL, 0);
filler(buf, "..", NULL, 0);
Directory_Table *directory_table;
directory_table = lsfs_find_directory(path, false);
int lsfs_rmdir(const char *path) {
if (directory_table != NULL)
{
for (int i = 0; i < DEFAULT_TABLE_SIZE; ++i)
{
if (strcmp( "", directory_table->entries[i].filename ) != 0)
// call to the disk controller to remove a dir
if (lsfs_disk_delete_directory(path))
{
filler(buf, directory_table->entries[i].filename, NULL, 0);
}
// error case:
// directory is not empty
return -EINVAL;
}
return 0;
}
int lsfs_unlink(const char *path) {
lsfs_file *found_file = calloc(1, sizeof(lsfs_file));
lsfs_disk_getattr(found_file, path);
lsfs_disk_delete_entry(found_file);
free(found_file);
return 0;
}
int lsfs_truncate(const char *path, off_t offset) {
(void)offset; // Truncate to this byte?
lsfs_file *found_file = calloc(1, sizeof(lsfs_file));
lsfs_disk_getattr(found_file, path);
lsfs_disk_truncate_file(found_file, offset);
free(found_file);
}
if (strcmp(path, "/") != 0)
{
//free(directory_table);
}
return 0;
}
int lsfs_rename(const char *path, const char *to) {
return lsfs_disk_rename_file(path, to);
}
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(
((lsfs_file*) file_info->fh),
content_length,
(void*) content, offset_to_next_entry);
return res;
}
//Permission
int lsfs_open( const char *path, struct fuse_file_info *fi ) {
// printf("open: (path=%s)\n", path);

2
source_lsfs

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

BIN
test_disk.img.bk

Binary file not shown.
Loading…
Cancel
Save