Browse Source

version 1.0.0-BETA-b1: rm dir works, fix for multiple data pointers

master
Jørn Guldberg 5 years ago
parent
commit
2e68d085e9
6 changed files with 50 additions and 20 deletions
  1. BIN
      SingOS.img
  2. BIN
      a.out
  3. +44
    -19
      lsfs_disk_controller.h
  4. BIN
      lsfs_fuse
  5. +6
    -1
      lsfs_fuse.c
  6. BIN
      lsfs_fuse.o

BIN
SingOS.img View File


BIN
a.out View File


+ 44
- 19
lsfs_disk_controller.h View File

@ -241,9 +241,9 @@ int lsfs_disk_read_data_from_file(lsfs_file *file, int buffer_size, char *data,
int data_length = file->size;
int amount_read = 0;
int amount_to_read = 0;
printf("READ: buffer_size: %d\n", buffer_size);
printf("READ: Data length: %d\n", data_length);
printf("READ: Offset length: %d\n", offset_to_next_entry);
//printf("READ: buffer_size: %d\n", buffer_size);
//printf("READ: Data length: %d\n", data_length);
//printf("READ: Offset length: %d\n", offset_to_next_entry);
int data_pointer_index = 0; // start at first data pointer.
@ -264,7 +264,7 @@ int lsfs_disk_read_data_from_file(lsfs_file *file, int buffer_size, char *data,
}
//read_data_from_disk(lsfs_sector_offset index, uint32_t file_block_size, void* data_buffer)
read_data_from_disk(file->data_pointer[data_pointer_index], DEFAULT_DATA_POINTER_SIZE, tmp_buffer);
memcpy(data, tmp_buffer, amount_to_read);
memcpy((data + amount_read), tmp_buffer, amount_to_read);
data_length -= amount_to_read;
amount_read += amount_to_read;
data_pointer_index++;
@ -286,7 +286,7 @@ int lsfs_disk_read_data_from_file(lsfs_file *file, int buffer_size, char *data,
read_data_from_disk_off(file->data_pointer[data_pointer_index], DEFAULT_DATA_POINTER_SIZE, tmp_buffer, offset_to_next_entry);
memcpy(data, tmp_buffer, amount_to_read);
memcpy((data + amount_read), tmp_buffer, amount_to_read);
data_length -= amount_to_read;
amount_read += amount_to_read;
@ -321,8 +321,8 @@ int lsfs_disk_write_data_to_file(lsfs_file *file, int data_length, char *data, s
int new_filesize = data_length + offset_to_next_entry;
int amount_written = 0;
int amount_to_write = 0;
printf("Data length: %d\n", data_length);
printf("Offset length: %d\n", offset_to_next_entry);
//printf("Data length: %d\n", data_length);
//printf("Offset length: %d\n", offset_to_next_entry);
int data_pointer_index = 0; // start at first data pointer.
@ -331,13 +331,11 @@ int lsfs_disk_write_data_to_file(lsfs_file *file, int data_length, char *data, s
while (file->data_pointer[data_pointer_index] == 0)
{
// we have to assign a free sector
printf("line 279:\n");
if (get_free_sectors(1, file->data_pointer))
{
// This is a fail case, we cannot assign a new sector:
return amount_written;
}
printf("line 280:\n");
}
if (offset_to_next_entry == 0)
@ -354,17 +352,13 @@ int lsfs_disk_write_data_to_file(lsfs_file *file, int data_length, char *data, s
amount_to_write = (DEFAULT_DATA_POINTER_SIZE * SECTOR_SIZE);
}
printf("line 296: %d \n", amount_to_write);
memcpy(tmp_buffer, data, amount_to_write);
memcpy(tmp_buffer, (data + amount_written), amount_to_write);
data_length -= amount_to_write;
amount_written += amount_to_write;
printf("line 300, write data to sector: %d\n", file->data_pointer[data_pointer_index]);
write_data_to_disk(file->data_pointer[data_pointer_index], DEFAULT_DATA_POINTER_SIZE, tmp_buffer);
printf("line 303:\n");
data_pointer_index++;
free(tmp_buffer);
printf("line 305:\n");
}
else if (offset_to_next_entry <= (DEFAULT_DATA_POINTER_SIZE * SECTOR_SIZE))
{
@ -381,7 +375,7 @@ int lsfs_disk_write_data_to_file(lsfs_file *file, int data_length, char *data, s
}
memcpy(tmp_buffer, data, amount_to_write);
memcpy(tmp_buffer, (data + amount_written), amount_to_write);
data_length -= amount_to_write;
amount_written += amount_to_write;
@ -393,7 +387,6 @@ int lsfs_disk_write_data_to_file(lsfs_file *file, int data_length, char *data, s
else
{
// We have to skip a whole data pointer:
printf("WRONG\n");
offset_to_next_entry -= (DEFAULT_DATA_POINTER_SIZE * SECTOR_SIZE);
data_pointer_index++;
}
@ -448,6 +441,7 @@ int lsfs_disk_rename_file(const char* old_filename, const char* new_filename) {
}
int lsfs_disk_delete_file(lsfs_file *file) {
//printf("file: %s - has been deleted \n", file->filename);
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_ENTRY_SIZE, zero_buffer);
@ -456,6 +450,38 @@ int lsfs_disk_delete_file(lsfs_file *file) {
return 1;
}
int lsfs_disk_delete_directory(const char *path) {
// Find the directory and check if this is empty for entries:
Directory_Table *directory_table = calloc(1, (DEFAULT_ENTRY_SIZE * SECTOR_SIZE));
directory_table = lsfs_find_directory(path, false);
bool empty = true;
for (int i = 0; i < DEFAULT_TABLE_SIZE; ++i)
{
if (directory_table->entries[i].entry_kind != 0)
{
empty = false;
}
}
free(directory_table);
if (!empty)
{
return 1;
}
lsfs_file *file = calloc(1, sizeof(lsfs_file));
lsfs_disk_getattr(file, path);
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_ENTRY_SIZE, zero_buffer);
free(zero_buffer);
return 0;
}
int get_free_sectors_table() {
// We need DEFAULT_TABLE_SIZE sectors straight contigious for a table
// Otherwise the file system cannot make a new table.
@ -473,7 +499,7 @@ int get_free_sectors_table() {
fseek ( disk , ((p_control.fsci.this_partition_offset_on_disk) * SECTOR_SIZE), SEEK_SET );
fwrite(&p_control.fsci, 1, SECTOR_SIZE, disk);
printf("Table has got assigned Sector: %d\n", return_index);
//printf("Table has got assigned Sector: %d\n", return_index);
return return_index;
}
@ -536,7 +562,6 @@ int create_file_system(char* disk_name, char* hdd_or_partition, uint64_t filesys
if ((hdd_or_partition[0] == '1') || (hdd_or_partition[0] == '2'))
{
printf("HEY YUP\n");
// This is just a single partition
// And then the file system is the only thing in the system.
sprintf(fsci->filesystem_information, "LSFS v1.0.0-a1\n(LessSimpelFileSystem)(Generated by the disk_manager_utility.c)\nDeveloped to SingOS\nby Jorn Guldberg\n");
@ -679,7 +704,7 @@ int lsfs_disk_create_entry(const char* path, Table_Entry_Kind entry_kind)
// if not -1, we have found a better index.
if (free_index == -1)
{
printf("Index found for file: %d\n", table_index);
//printf("Index found for file: %d\n", table_index);
table_disk_position += table_index; // Abselout index in file system
free_index = table_index;
}

BIN
lsfs_fuse View File


+ 6
- 1
lsfs_fuse.c View File

@ -53,7 +53,12 @@ int lsfs_mkdir(const char *path, mode_t mode) {
int lsfs_rmdir(const char *path) {
// call to the disk controller to remove a dir
if (lsfs_disk_delete_directory(path))
{
// error case:
// directory is not empty
return -EINVAL;
}
return 0;
}

BIN
lsfs_fuse.o View File


Loading…
Cancel
Save