5 changed files with 304 additions and 5 deletions
Binary file not shown.
@ -0,0 +1,267 @@ |
|||
#include "lsfs_disk_controller.h" |
|||
#include <stdio.h> |
|||
#include <string.h> |
|||
|
|||
static int disk_is_loaded = 0; |
|||
static char loaded_disk_name[256]; |
|||
static char input_buffer[256]; |
|||
|
|||
#if 0 |
|||
typedef struct sector_data |
|||
{ |
|||
char data[SECTOR_SIZE]; |
|||
} sector_data; |
|||
|
|||
int dmu_print_file(lsfs_file_id fileID) { |
|||
printf("\n|-----------------Meta Information For File-----------------|\n"); |
|||
mif* mif_data = calloc(1, SECTOR_SIZE); |
|||
read_data_from_disk(fileID, mif_data); |
|||
printf("File ID: %lu\n", fileID); |
|||
printf("Filename: %s\n", mif_data->filename); |
|||
printf("Owner id: %d\n", mif_data->owner_id); |
|||
printf("Tags (id):"); |
|||
for (int i = 0; i < MAX_TAGS_IN_TAG_TABLE; ++i) |
|||
{ |
|||
if(mif_data->tags[i] == 0) { |
|||
break; |
|||
} |
|||
printf("%lu\n", mif_data->tags[i]); |
|||
|
|||
} |
|||
printf("Control_bits: %d\n", mif_data->control_bits); |
|||
printf("Creation date: %lu\n", mif_data->creation_date); |
|||
printf("Last modified: %lu\n", mif_data->last_modification_data); |
|||
printf("Last accessed: %lu\n", mif_data->last_access_date); |
|||
printf("\nData pointers:\n"); |
|||
printf("%lu\n", mif_data->one_level_pointer_data[0]); |
|||
printf("%lu\n", mif_data->one_level_pointer_data[1]); |
|||
printf("%lu\n", mif_data->one_level_pointer_data[2]); |
|||
|
|||
printf("\n|-------------------------File Data-------------------------|\n"); |
|||
char* file_data = calloc(MAX_NUM_ONE_LEVEL_DATA, SECTOR_SIZE); |
|||
int size_of_data = 0; |
|||
|
|||
size_of_data = lsfs_disk_read_data_from_file(fileID, (256*4096), file_data); |
|||
|
|||
if (size_of_data <= 0) { |
|||
printf("|File has no data!\n"); |
|||
} |
|||
for (int i = 0; i < MAX_NUM_ONE_LEVEL_DATA; ++i) |
|||
{ |
|||
if (size_of_data <= 0) { |
|||
break; |
|||
} |
|||
printf("|%s", file_data); |
|||
size_of_data -= SECTOR_SIZE; |
|||
} |
|||
printf("\n|---------------------End File Data-------------------------|\n"); |
|||
return 1; |
|||
} |
|||
|
|||
int dmu_install_SingOS(char* disk_name) { |
|||
disk = fopen ( disk_name , "r+b" ); |
|||
p_control.fsci = malloc(sizeof(FSCI)); |
|||
p_control.mtt_tags = malloc(sizeof(global_tag) * DEFAULT_MASTER_TAG_TABLE_SIZE); |
|||
lsfs_disk_load_disk(disk, &p_control); |
|||
|
|||
lsfs_tag_id untagged = lsfs_disk_create_tag("@untagged", false); |
|||
lsfs_tag_id sy_files = lsfs_disk_create_tag("@system_files", false); |
|||
lsfs_tag_id SingOS_files = lsfs_disk_create_tag("@SingOS", false); |
|||
|
|||
/* Add files: */ |
|||
char* new_file_data_d = calloc(1, 4096); |
|||
char* rtfm_file = "If you don't know the answer\nRead the F manual\n"; |
|||
sprintf(new_file_data_d, "%s", rtfm_file); |
|||
char* l_filename = "RTFM.md"; |
|||
lsfs_sector_offset* tags = calloc(2, sizeof(lsfs_sector_offset)); |
|||
lsfs_tag_id filename_tag = lsfs_disk_create_tag(l_filename, true); |
|||
tags[0] = filename_tag; |
|||
tags[1] = sy_files; |
|||
int rtfm_file_if = lsfs_disk_create_file(l_filename, tags, new_file_data_d ); |
|||
lsfs_disk_write_data_to_file(rtfm_file_if, strlen(rtfm_file), new_file_data_d); |
|||
|
|||
char* vip_file = "Very important file\n" ; |
|||
sprintf(new_file_data_d, "%s", vip_file); |
|||
l_filename = "system_control.md"; |
|||
filename_tag = lsfs_disk_create_tag(l_filename, true); |
|||
tags[0] = filename_tag; |
|||
tags[1] = sy_files; |
|||
int vip_file_id = lsfs_disk_create_file(l_filename, tags, new_file_data_d ); |
|||
lsfs_disk_write_data_to_file(vip_file_id, strlen(vip_file), new_file_data_d); |
|||
|
|||
char* sing_os_file = "SingOS is comming\n\nWe are not ready to expose the binaries nor the source\nBut read more @ guld-berg.dk/singos\nSingOS is real\n\n- groot\n" ; |
|||
sprintf(new_file_data_d, "%s", sing_os_file); |
|||
l_filename = "README.md"; |
|||
filename_tag = lsfs_disk_create_tag(l_filename, true); |
|||
tags[0] = filename_tag; |
|||
tags[1] = SingOS_files; |
|||
int sing_id = lsfs_disk_create_file(l_filename, tags, new_file_data_d ); |
|||
lsfs_disk_write_data_to_file(sing_id, strlen(sing_os_file), new_file_data_d); |
|||
|
|||
|
|||
free(new_file_data_d); |
|||
free(tags); |
|||
|
|||
fclose (disk); |
|||
} |
|||
#endif |
|||
|
|||
int dmu_create_file_system(char* disk_name) { |
|||
uint64_t filesystem_size_in_MB = 0; |
|||
char hdd_or_partition[8]; // 1: is harddisk, 2: is partition
|
|||
char input_size_file_system[64]; // in MB
|
|||
|
|||
do { |
|||
printf("Create as 1: harddrive or 2: as a single partition (enter 1 or 2): \n"); |
|||
scanf("%s", hdd_or_partition); |
|||
|
|||
} while ((hdd_or_partition[0] != '1') && (hdd_or_partition[0] != '2')); |
|||
|
|||
printf("Enter size of file system in MB (as an integer number): \n"); |
|||
scanf("%s", input_size_file_system); |
|||
|
|||
filesystem_size_in_MB = atoi(input_size_file_system); |
|||
|
|||
printf("Create new disk img\n"); |
|||
create_file_system(disk_name, hdd_or_partition, filesystem_size_in_MB); |
|||
printf("Disk is created as: %s\n", disk_name); |
|||
fclose (disk); |
|||
|
|||
// TODO: Do you want to install SingOS:
|
|||
//dmu_install_SingOS(disk_name);
|
|||
|
|||
return 1; |
|||
} |
|||
|
|||
#if 0
|
|||
int dmu_load_file_system(char* disk_name) { |
|||
disk = fopen ( disk_name , "r+b" ); |
|||
p_control.fsci = malloc(sizeof(FSCI)); |
|||
p_control.mtt_tags = malloc(sizeof(global_tag) * DEFAULT_MASTER_TAG_TABLE_SIZE); |
|||
lsfs_disk_load_disk(disk, &p_control); |
|||
disk_is_loaded = 1; |
|||
return 1; |
|||
} |
|||
|
|||
int dmu_print_mtt() { |
|||
printf("\n|---------------------Master Tag Table----------------------|Control_bits|\n"); |
|||
|
|||
for (int i = 0; i < MAX_MASTER_TAGS; ++i) { |
|||
if (p_control.mtt_tags[i].tag_table_index == 0) { |
|||
break; |
|||
} |
|||
printf("|%-28s|%-30lu|%-12d| \n", p_control.mtt_tags[i].tagname, p_control.mtt_tags[i].tag_table_index, p_control.mtt_tags[i].control_bits.is_filename); |
|||
printf("|-----------------------------------------------------------|------------|\n"); |
|||
|
|||
} |
|||
printf("\n\n\n"); |
|||
return 1; |
|||
} |
|||
|
|||
int dmu_print_tag_table(lsfs_tag_id TagID) { |
|||
tag_record* tag_table = calloc(1, SECTOR_SIZE); |
|||
mif* mif_data = calloc(1, SECTOR_SIZE); |
|||
read_data_from_disk(TagID, tag_table); |
|||
|
|||
printf("Tag Table for: %lu\n", TagID); |
|||
printf("\n|------------------------Tag Table--------------------------|\n"); |
|||
|
|||
for (int i = 0; i < MAX_TAGS_IN_TAG_TABLE; ++i) { |
|||
if (tag_table[i].mif_record == 0) { |
|||
break; |
|||
} |
|||
read_data_from_disk(tag_table[i].mif_record, mif_data); |
|||
printf("|%-28lu|%-30s| \n", tag_table[i].mif_record, mif_data->filename); |
|||
printf("|-----------------------------------------------------------|\n"); |
|||
|
|||
} |
|||
printf("\n\n\n"); |
|||
return 1; |
|||
} |
|||
#endif |
|||
|
|||
int main (int argc, char *argv[]) |
|||
{ |
|||
|
|||
|
|||
char chose[8]; |
|||
while(strcmp(chose, "exit")) { |
|||
if(!disk_is_loaded) { |
|||
printf("Tag File System Utility\nMenu:\nc: Create new lsfs disk\nl: load disk\nEnter:"); |
|||
} |
|||
else { |
|||
printf("Tag File System Utility\nDisk loaded: %s\nMenu:\n1: Print Master Tag Table\n2: Print Tag Table\n3: Print File\n4: Create Tag\n5: Create New File\n", loaded_disk_name); |
|||
} |
|||
|
|||
scanf("%s", chose); |
|||
|
|||
if (strcmp(chose, "c") == 0) { |
|||
printf("\nCreate disk\nEnter filename:\n"); |
|||
scanf("%s", loaded_disk_name); |
|||
dmu_create_file_system(loaded_disk_name); |
|||
} |
|||
|
|||
|
|||
#if 0 |
|||
else if(strcmp(chose, "l") == 0) { |
|||
printf("\nLoad disk\nEnter filename:\n"); |
|||
scanf("%s", loaded_disk_name); |
|||
dmu_load_file_system(loaded_disk_name); |
|||
} |
|||
else if(strcmp(chose, "1") == 0) { |
|||
// Print Master Tag Table
|
|||
dmu_print_mtt(); |
|||
} |
|||
else if(strcmp(chose, "2") == 0) { |
|||
// Print Master Tag Table
|
|||
printf("Enter Tag ID:\n"); |
|||
scanf("%s", input_buffer); |
|||
|
|||
dmu_print_tag_table( (lsfs_tag_id) atoi(input_buffer) ); |
|||
} |
|||
else if(strcmp(chose, "3") == 0) { |
|||
// Print Master Tag Table
|
|||
printf("File ID:\n"); |
|||
scanf("%s", input_buffer); |
|||
|
|||
dmu_print_file( (lsfs_file_id) atoi(input_buffer) ); |
|||
} |
|||
else if(strcmp(chose, "4") == 0) { |
|||
// Print Master Tag Table
|
|||
printf("Enter Tag name:\n"); |
|||
scanf("%s", input_buffer); |
|||
lsfs_disk_create_tag(input_buffer, false); |
|||
} |
|||
else if(strcmp(chose, "5") == 0) { |
|||
// Print Master Tag Table
|
|||
printf("Enter Filename:\n"); |
|||
scanf("%s", input_buffer); |
|||
|
|||
printf("Write data:\n"); |
|||
char* new_file_data_d = calloc(1, 4096); |
|||
scanf("%s", new_file_data_d); |
|||
|
|||
printf("Enter Tag ID:\n"); |
|||
char* tags_number = calloc(16, sizeof(char)); |
|||
lsfs_sector_offset* tags = calloc(2, sizeof(lsfs_sector_offset)); |
|||
|
|||
scanf("%s", tags_number); |
|||
|
|||
int filename_tag = lsfs_disk_create_tag(input_buffer, true); |
|||
|
|||
tags[0] = filename_tag; |
|||
tags[1] = atoi(tags_number); |
|||
|
|||
|
|||
int new_id = lsfs_disk_create_file(input_buffer, tags, new_file_data_d ); |
|||
lsfs_disk_write_data_to_file(new_id, strlen(new_file_data_d), new_file_data_d); |
|||
|
|||
} |
|||
#endif |
|||
} |
|||
if(disk_is_loaded) { |
|||
fclose (disk); |
|||
} |
|||
|
|||
return 0; |
|||
} |
Binary file not shown.
Binary file not shown.
Loading…
Reference in new issue