Ver a proveniência

Working on use of all datapoitners.

master
Jørn Guldberg há 5 anos
ascendente
cometimento
788485fcae
6 ficheiros alterados com 137 adições e 33 eliminações
  1. BIN
      SingOS.img
  2. BIN
      a.out
  3. +132
    -28
      lsfs_disk_controller.h
  4. BIN
      lsfs_fuse
  5. +5
    -5
      lsfs_fuse.c
  6. BIN
      lsfs_fuse.o

BIN
SingOS.img Ver ficheiro


BIN
a.out Ver ficheiro


+ 132
- 28
lsfs_disk_controller.h Ver ficheiro

@ -38,13 +38,14 @@ int lsfs_disk_getattr(lsfs_file* find_file, const char *path);
int lsfs_disk_delete_file(lsfs_file *file);
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_read_data_from_file(lsfs_file *file, int data_length, char *data, size_t offset_to_next_entry);
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(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);
int write_data_to_disk_off(lsfs_sector_offset index, uint32_t file_block_size, void* data_to_write, int offset);
int read_data_from_disk(lsfs_sector_offset index, uint32_t file_block_size, void* data_buffer);
int read_data_from_disk_off(lsfs_sector_offset index, uint32_t file_block_size, void* data_to_write, int offset);
int save_modified_file_information(lsfs_file* file);
#define SPACE_MBR_RECORD 2048 // Sectors
@ -235,25 +236,78 @@ int lsfs_disk_getattr(lsfs_file* find_file, const char* path) {
int lsfs_disk_read_data_from_file(lsfs_file *file, int buffer_size, void* buffer_for_data) {
// TODO some offset, to tell where in the file we want to write
int lsfs_disk_read_data_from_file(lsfs_file *file, int buffer_size, char *data, size_t offset_to_next_entry)
{
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);
int data_pointer_index = 0; // start at first data pointer.
while(data_length > 0) // We have more to write
{
if (offset_to_next_entry == 0)
{
char *tmp_buffer = calloc(DEFAULT_DATA_POINTER_SIZE, SECTOR_SIZE);
assert(tmp_buffer);
if (data_length < (DEFAULT_DATA_POINTER_SIZE * SECTOR_SIZE))
{
amount_to_read = data_length;
}
else
{
amount_to_read = (DEFAULT_DATA_POINTER_SIZE * SECTOR_SIZE);
}
//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);
data_length -= amount_to_read;
amount_read += amount_to_read;
data_pointer_index++;
free(tmp_buffer);
}
else if (offset_to_next_entry <= (DEFAULT_DATA_POINTER_SIZE * SECTOR_SIZE))
{
char *tmp_buffer = calloc(1, ((DEFAULT_DATA_POINTER_SIZE * SECTOR_SIZE) - offset_to_next_entry));
assert(tmp_buffer);
if (data_length < ((DEFAULT_DATA_POINTER_SIZE * SECTOR_SIZE) - offset_to_next_entry) )
{
amount_to_read = data_length;
}
else
{
amount_to_read = ((DEFAULT_DATA_POINTER_SIZE * SECTOR_SIZE) - offset_to_next_entry);
}
read_data_from_disk_off(file->data_pointer[data_pointer_index], DEFAULT_DATA_POINTER_SIZE, tmp_buffer, offset_to_next_entry);
int return_val = 0;
memcpy(data, tmp_buffer, amount_to_read);
data_length -= amount_to_read;
amount_read += amount_to_read;
for (int i = 0; i < NUM_DATA_POINTERS; ++i) {
if(file->data_pointer[i] == 0) {
break;
data_pointer_index++;
free(tmp_buffer);
}
return_val += read_data_from_disk(file->data_pointer[i], file->file_block_size, buffer_for_data + (SECTOR_SIZE * i));
else
{
// We have to skip a whole data pointer:
offset_to_next_entry -= (DEFAULT_DATA_POINTER_SIZE * SECTOR_SIZE);
data_pointer_index++;
}
}
//time_t current_time;
//time ( &current_time );
time_t current_time;
time ( &current_time );
file->access_time = current_time;
return amount_read;
//mif_record->last_access_date = (uint64_t) current_time;
//write_data_to_disk(file_id, mif_record);
//free(mif_record);
return return_val;
}
static inline time_t lsfs_disk_update_timestamps(lsfs_file *file) {
@ -262,20 +316,28 @@ static inline time_t lsfs_disk_update_timestamps(lsfs_file *file) {
#define lsfs_num_sectors_for_size(x) (((x)+SECTOR_SIZE-1)&~(SECTOR_SIZE-1))
int lsfs_disk_write_data_to_file(lsfs_file *file, int data_length, char *data, size_t offset_to_next_entry) {
int lsfs_disk_write_data_to_file(lsfs_file *file, int data_length, char *data, size_t offset_to_next_entry)
{
int new_filesize = data_length + offset_to_next_entry;
int amount_written = data_length;
//printf("Data length: %d\n", data_length);
//printf("Offset length: %d\n", 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);
int data_pointer_index = 0; // start at first data pointer.
while(data_length > 0) // We have more to write
{
if (file->data_pointer[data_pointer_index] == 0)
while (file->data_pointer[data_pointer_index] == 0)
{
// we have to assign a free sector
get_free_sectors(1, (lsfs_sector_offset*) file->data_pointer[data_pointer_index]);
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)
@ -283,21 +345,45 @@ int lsfs_disk_write_data_to_file(lsfs_file *file, int data_length, char *data, s
char *tmp_buffer = calloc(DEFAULT_DATA_POINTER_SIZE, SECTOR_SIZE);
assert(tmp_buffer);
memcpy(tmp_buffer, data, data_length);
data_length -= (DEFAULT_DATA_POINTER_SIZE * SECTOR_SIZE);
if (data_length < (DEFAULT_DATA_POINTER_SIZE * SECTOR_SIZE))
{
amount_to_write = data_length;
}
else
{
amount_to_write = (DEFAULT_DATA_POINTER_SIZE * SECTOR_SIZE);
}
printf("line 296: %d \n", amount_to_write);
memcpy(tmp_buffer, data, 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))
{
char *tmp_buffer = calloc(1, ((DEFAULT_DATA_POINTER_SIZE * SECTOR_SIZE) - offset_to_next_entry));
assert(tmp_buffer);
memcpy(tmp_buffer, data, data_length);
data_length -= ((DEFAULT_DATA_POINTER_SIZE * SECTOR_SIZE) - offset_to_next_entry);
if (data_length < ((DEFAULT_DATA_POINTER_SIZE * SECTOR_SIZE) - offset_to_next_entry) )
{
amount_to_write = data_length;
}
else
{
amount_to_write = ((DEFAULT_DATA_POINTER_SIZE * SECTOR_SIZE) - offset_to_next_entry);
}
memcpy(tmp_buffer, data, amount_to_write);
data_length -= amount_to_write;
amount_written += amount_to_write;
write_data_to_disk_off(file->data_pointer[data_pointer_index], DEFAULT_DATA_POINTER_SIZE, tmp_buffer, offset_to_next_entry);
@ -307,6 +393,7 @@ 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++;
}
@ -397,10 +484,22 @@ int get_free_sectors(int num_sectors_needed, lsfs_sector_offset* output_array) {
// We cannot assign what we want.
return -EINVAL;
}
for (int i = 0; i < num_sectors_needed; ++i)
int i = 0;
while (num_sectors_needed > 0)
{
output_array[i] = p_control.fsci.next_free_sector;
p_control.fsci.next_free_sector += DEFAULT_FILE_SIZE;
if (i > NUM_DATA_POINTERS)
{
return -EINVAL; // We don't have any more data pointers.
}
if (output_array[i] == 0)
{
// If free we can assign:
output_array[i] = p_control.fsci.next_free_sector;
p_control.fsci.next_free_sector += DEFAULT_FILE_SIZE;
num_sectors_needed--;
}
i++;
}
fseek ( disk , (p_control.fsci.this_partition_offset_on_disk) * SECTOR_SIZE, SEEK_SET );
@ -666,4 +765,9 @@ int read_data_from_disk(lsfs_sector_offset index, uint32_t file_block_size, void
return read;
}
int read_data_from_disk_off(lsfs_sector_offset index, uint32_t file_block_size, void* data_to_write, int offset) {
fseek ( disk, ((index * SECTOR_SIZE) + offset), SEEK_SET ); // SEEK_SET start offset at index 0 and move 1 * SECTOR_SIZE, and write here.
int written = fread(data_to_write, 1, ((file_block_size * SECTOR_SIZE) - offset), disk);
return written;
}
#endif

BIN
lsfs_fuse Ver ficheiro


+ 5
- 5
lsfs_fuse.c Ver ficheiro

@ -184,11 +184,11 @@ int lsfs_open( const char *path, struct fuse_file_info *fi ) {
int lsfs_read( const char *path, char *buf, size_t size, off_t offset_to_next_entry, struct fuse_file_info *fi ) {
// printf("read: (path=%s)\n", path);
time_t current_time;
time ( &current_time );
int res = lsfs_disk_read_data_from_file( ((lsfs_file*) fi->fh), size, buf);
((lsfs_file*) fi->fh)->access_time = current_time;
int res = lsfs_disk_read_data_from_file(
((lsfs_file*) fi->fh),
size,
buf,
offset_to_next_entry);
return res;
}

BIN
lsfs_fuse.o Ver ficheiro


Carregando…
Cancelar
Guardar