Selaa lähdekoodia

rename, delete works, new default table size = 16 entries

master
Jørn Guldberg 5 vuotta sitten
vanhempi
commit
5db0a51db0
6 muutettua tiedostoa jossa 42 lisäystä ja 63 poistoa
  1. BIN
      SingOS.img
  2. BIN
      a.out
  3. +40
    -50
      lsfs_disk_controller.h
  4. BIN
      lsfs_fuse
  5. +2
    -13
      lsfs_fuse.c
  6. BIN
      lsfs_fuse.o

BIN
SingOS.img Näytä tiedosto


BIN
a.out Näytä tiedosto


+ 40
- 50
lsfs_disk_controller.h Näytä tiedosto

@ -29,6 +29,7 @@ typedef lsfs_sector_offset lsfs_file_id;
//typedef uint64_t sector_index;
static FILE* disk;
static partition_control p_control;
static time_t timestamp_loading;
int create_file_system(char* disk_name, char* hdd_or_partition, uint64_t filesystem_size_in_MB);
int lsfs_disk_create_entry(const char* path, Table_Entry_Kind entry_kind);
@ -39,7 +40,7 @@ int get_free_sectors_table();
int get_free_sectors(int num_sectors_needed, lsfs_sector_offset* output_array);
int lsfs_disk_read_data_from_file(lsfs_file* file, int buffer_size, void* buffer_for_data);
int lsfs_disk_write_data_to_file(lsfs_file* file, int data_length, char *data, size_t offset_to_next_entry);
int lsfs_disk_rename_file(lsfs_file* file, const char* new_filename);
int lsfs_disk_rename_file(const char* old_filename_, const char* new_filename);
int lsfs_disk_load_disk();
int write_data_to_disk(lsfs_sector_offset at_sector, uint32_t file_block_size, void* data_to_write);
int read_data_from_disk(lsfs_sector_offset index, uint32_t file_block_size, void* data_buffer);
@ -54,7 +55,7 @@ int save_modified_file_information(lsfs_file* file);
#define NUMBER_OF_MBR_PARTITIONS 4
#define DEFAULT_FILE_SIZE 4 // This is in sectors
#define DEFAULT_DATA_POINTER_SIZE 4 // This is in sectors
#define DEFAULT_TABLE_SIZE 10
#define DEFAULT_TABLE_SIZE 16
#define NUM_DATA_POINTERS 27
typedef enum Table_Entry_Kind
@ -100,22 +101,22 @@ typedef struct struct_table_entry
typedef struct Directory_Table
{
struct_table_entry entries[10];
struct_table_entry entries[DEFAULT_TABLE_SIZE];
} __attribute__((packed)) Directory_Table;
typedef struct File_System_Control_Information
{
char filesystem_information[256];
uint64_t master_table_index;
uint64_t this_partition_offset_on_disk;
uint64_t next_free_sector;
uint64_t next_uniqe_id; // both files and directories gets this.
uint64_t next_sector_reuse_pointer;
uint64_t last_sector_index_on_partition;
uint64_t maximum_sectors_on_disk;
uint64_t sector_size_on_disk;
uint64_t not_used[24];
char filesystem_information[256];
lsfs_sector_offset master_table_index;
lsfs_sector_offset this_partition_offset_on_disk;
lsfs_sector_offset next_free_sector;
uint64_t next_uniqe_id; // both files and directories gets this.
lsfs_sector_offset next_sector_reuse_pointer;
lsfs_sector_offset last_sector_index_on_partition;
lsfs_sector_offset maximum_sectors_on_disk;
lsfs_sector_offset sector_size_on_disk;
uint64_t not_used[24];
} __attribute__((packed)) FSCI;
@ -177,7 +178,8 @@ typedef struct lsfs_file {
Directory_Table* lsfs_find_directory(const char *path, bool drop_filename)
{
Directory_Table *dir_table = &p_control.master_table;
Directory_Table *dir_table = calloc(1, sizeof(Directory_Table));
read_data_from_disk(p_control.fsci.master_table_index, DEFAULT_TABLE_SIZE, dir_table);
lsfs_string_array split_path = lsfs_string_split_c(path, '/', false);
int number_of_traversal = split_path.length;
@ -195,16 +197,6 @@ Directory_Table* lsfs_find_directory(const char *path, bool drop_filename)
if (strcmp(dir_table->entries[j].filename, split_path.strings[i].chars) == 0)
{
int index_sector = dir_table->entries[j].data_pointer[0];
if (i == 0)
{
// Alocate space, we refuse this further on
dir_table = calloc(1, sizeof(Directory_Table));
}
else
{
free(dir_table);
dir_table = calloc(1, sizeof(Directory_Table));
}
read_data_from_disk(index_sector, DEFAULT_TABLE_SIZE, dir_table);
break;
}
@ -223,9 +215,6 @@ int lsfs_disk_getattr(lsfs_file* find_file, const char* path) {
for (int i = 0; i < DEFAULT_TABLE_SIZE; ++i)
{
if(strcmp( filename.chars, dir_table->entries[i].filename ) == 0) {
time_t current_time;
time ( &current_time );
find_file->file_id = dir_table->entries[i].file_id;
find_file->entry_kind = dir_table->entries[i].entry_kind;
find_file->table_entry_pointer = i;
@ -233,10 +222,10 @@ int lsfs_disk_getattr(lsfs_file* find_file, const char* path) {
find_file->table_entry_sector_index = dir_table->entries[i].table_entry_sector_index;
find_file->owner_id = getuid();
find_file->size = dir_table->entries[i].file_size; // dir_table->entries[i].data_pointer[0]; //;
find_file->creation_date = (uint64_t) current_time;
find_file->access_time = (uint64_t) current_time;
find_file->modification_time = (uint64_t) current_time;
memcpy(find_file->data_pointer, dir_table->entries[i].data_pointer, DEFAULT_DATA_POINTER_SIZE * 8);
find_file->creation_date = (uint64_t) timestamp_loading;
find_file->access_time = (uint64_t) timestamp_loading;
find_file->modification_time = (uint64_t) timestamp_loading;
memcpy(find_file->data_pointer, dir_table->entries[i].data_pointer, NUM_DATA_POINTERS * 8);
find_file->file_block_size = 1; // TODO: should be loaded from disk.
return 1;
}
@ -352,18 +341,21 @@ time_t lsfs_disk_truncate_file(lsfs_file *file, off_t offset) {
return result;
}
int lsfs_disk_rename_file(lsfs_file* file, const char* new_filename) {
memset(file->filename, 0, 256);
sprintf(file->filename, "%s", new_filename);
int lsfs_disk_rename_file(const char* old_filename, const char* new_filename) {
time_t current_time;
time ( &current_time );
lsfs_file *old_file = calloc(1, sizeof(lsfs_file));
lsfs_file *new_file = calloc(1, sizeof(lsfs_file));
file->access_time = (uint64_t) current_time;
file->modification_time = (uint64_t) current_time;
lsfs_disk_getattr(old_file, old_filename);
lsfs_disk_create_entry(new_filename, ENTRY_FILE);
lsfs_disk_getattr(new_file, new_filename);
save_modified_file_information(file);
new_file->file_id = old_file->file_id;
new_file->size = old_file->size;
// TODO(Jørn) The data pointer assignt to the new file should be released.
memcpy(new_file->data_pointer, old_file->data_pointer, NUM_DATA_POINTERS * 8);
save_modified_file_information(new_file);
lsfs_disk_delete_file(old_file);
return 0;
}
@ -371,7 +363,7 @@ int lsfs_disk_rename_file(lsfs_file* file, const char* new_filename) {
int lsfs_disk_delete_file(lsfs_file *file) {
Table_Entry *zero_buffer = calloc(1, (DEFAULT_ENTRY_SIZE * SECTOR_SIZE));
//read_data_from_disk(file_id, 1, mif_record);
write_data_to_disk(file->table_entry_sector_index, DEFAULT_TABLE_SIZE, zero_buffer);
write_data_to_disk(file->table_entry_sector_index, DEFAULT_ENTRY_SIZE, zero_buffer);
free(zero_buffer);
return 1;
@ -453,6 +445,7 @@ int create_file_system(char* disk_name, char* hdd_or_partition, uint64_t filesys
// Create disk on host system:
disk = fopen ( disk_name , "wb" );
ftruncate(fileno(disk), SECTOR_SIZE * fsci->last_sector_index_on_partition);
write_data_to_disk(fsci->this_partition_offset_on_disk, 1, fsci);
@ -467,6 +460,8 @@ int lsfs_disk_load_disk() {
// Find the partition talbe:
// This makes is BIOS dependent.
// UEFI is not supported.
time(&timestamp_loading);
Master_Boot_record mbr;
fseek( disk , 0 * SECTOR_SIZE, SEEK_SET );
fread(&mbr, 1, sizeof(mbr), disk);
@ -523,7 +518,8 @@ int lsfs_disk_create_entry(const char* path, Table_Entry_Kind entry_kind)
// Start from the master table
int free_index = -1; // -1 is no index found.
Directory_Table *dir_table = &p_control.master_table;
Directory_Table *dir_table = calloc(1, sizeof(Directory_Table));
read_data_from_disk(p_control.fsci.master_table_index, DEFAULT_TABLE_SIZE, dir_table);
lsfs_sector_offset table_disk_position = p_control.fsci.master_table_index;
@ -541,11 +537,6 @@ int lsfs_disk_create_entry(const char* path, Table_Entry_Kind entry_kind)
// We have found the next directory to traverse.
//printf("Get next dir at sector: ");
table_disk_position = dir_table->entries[j].data_pointer[0];
if (i == 0)
{
// Alocate space, we refuse this further on
dir_table = malloc(sizeof(Directory_Table));
}
//printf("%d\n", table_disk_position);
read_data_from_disk(table_disk_position, DEFAULT_TABLE_SIZE, dir_table);
break;
@ -610,7 +601,7 @@ int lsfs_disk_create_entry(const char* path, Table_Entry_Kind entry_kind)
time ( &current_time );
*/
//printf("File is written to sector: %d\n", table_disk_position);
write_data_to_disk(table_disk_position, 1, &dir_table->entries[free_index]);
write_data_to_disk(table_disk_position, DEFAULT_ENTRY_SIZE, &dir_table->entries[free_index]);
return 0;
}
@ -623,9 +614,8 @@ int save_modified_file_information(lsfs_file* file) {
//entry.file_id = file->file_id;
memcpy(entry->filename, file->filename, 256);
printf("Filse size: %d\n", file->size);
entry->file_size = file->size; // p_control.master_table.entries[i].data_pointer[0]; //;
//p_control.master_table.entries[i].data_pointer = find_file->data;
memcpy(entry->data_pointer, file->data_pointer, NUM_DATA_POINTERS * 8);
write_data_to_disk(file->table_entry_sector_index, DEFAULT_ENTRY_SIZE, entry);
return 0;

BIN
lsfs_fuse Näytä tiedosto


+ 2
- 13
lsfs_fuse.c Näytä tiedosto

@ -82,12 +82,8 @@ int lsfs_truncate(const char *path, off_t offset) {
int lsfs_rename(const char *path, const char *to) {
(void)path;
(void)to;
lsfs_file *found_file = calloc(1, sizeof(lsfs_file));
lsfs_disk_getattr(found_file, path);
return lsfs_disk_rename_file(found_file, to);
return lsfs_disk_rename_file(path, to);
}
int lsfs_getattr( const char *path, struct stat *stbuf ) {
@ -149,14 +145,7 @@ int lsfs_readdir( const char *path, void *buf, fuse_fill_dir_t filler, off_t off
filler(buf, "..", NULL, 0);
Directory_Table *directory_table;
if (strcmp(path, "/") != 0)
{
directory_table = lsfs_find_directory(path, false);
}
else
{
directory_table = &p_control.master_table;
}
directory_table = lsfs_find_directory(path, false);
if (directory_table != NULL)
{

BIN
lsfs_fuse.o Näytä tiedosto


Ladataan…
Peruuta
Tallenna