Disk_manager_utility added, currently not compileing
This commit is contained in:
1 parent
00bd8e2c1a
commit
86d6126fca
5 files changed
+304
-5
No files matched your search
@@ -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;
|
||||
}
|
||||
+37
-5
@@ -1,6 +1,7 @@
|
||||
#ifndef LSFS_DISK_CONTROLLER_H
|
||||
#define LSFS_DISK_CONTROLLER_H
|
||||
|
||||
#include <errno.h>
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
@@ -29,7 +30,7 @@ typedef lsfs_sector_offset lsfs_file_id;
|
||||
static FILE* disk;
|
||||
static partition_control p_control;
|
||||
|
||||
int create_file_system();
|
||||
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);
|
||||
Directory_Table* lsfs_find_directory(const char* path, bool drop_filename);
|
||||
int lsfs_disk_getattr(lsfs_file* find_file, const char *path);
|
||||
@@ -45,7 +46,10 @@ int read_data_from_disk(lsfs_sector_offset index, uint32_t file_block_size, void
|
||||
int write_data_to_disk_off(lsfs_sector_offset index, void* data_to_write, int offset);
|
||||
int save_modified_file_information(lsfs_file* file);
|
||||
|
||||
#define SECTOR_SIZE 512
|
||||
#define SPACE_MBR_RECORD 2048; // Sectors
|
||||
#define SPACE_VBR_RECORD 2048; // Sectors
|
||||
#define SIZE_FSCI_RECORD 1; // Sectors
|
||||
#define SECTOR_SIZE 512 // BYTES
|
||||
#define NUMBER_OF_MBR_PARTITIONS 4
|
||||
#define DEFAULT_FILE_SIZE 4 // This is in sectors
|
||||
#define DEFAULT_TABLE_SIZE 10
|
||||
@@ -99,7 +103,7 @@ typedef struct Directory_Table
|
||||
|
||||
typedef struct File_System_Control_Information
|
||||
{
|
||||
char filesyste_information[256];
|
||||
char filesystem_information[256];
|
||||
uint64_t master_table_index;
|
||||
uint64_t this_partition_offset_on_disk;
|
||||
uint64_t next_free_sector;
|
||||
@@ -385,7 +389,7 @@ int get_free_sectors(int num_sectors_needed, lsfs_sector_offset* output_array) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int create_file_system() {
|
||||
int create_file_system(char* disk_name, char* hdd_or_partition, uint64_t filesystem_size_in_MB) {
|
||||
//char* sector_to_write;
|
||||
// make default File System Control information (FSCI)
|
||||
// first integer says how many pointers we got
|
||||
@@ -394,10 +398,38 @@ int create_file_system() {
|
||||
// we need the first number to allocate memory at one go.
|
||||
int* zero_buffer;
|
||||
FSCI fsci;
|
||||
fsci.this_partition_offset_on_disk = 1;
|
||||
if (hdd_or_partition[0] == '1')
|
||||
{
|
||||
// This is the create hdd case
|
||||
// This means that we setup the partition table.
|
||||
;
|
||||
}
|
||||
else if (hdd_or_partition[0] == '2')
|
||||
{
|
||||
// This is just a single partition
|
||||
// And then the file system is the only thing in the system.
|
||||
fsci.filesystem_information = "LSFS v0.2.0-exp\n(LessSimpelFileSystem)(Generated by the disk_manager_utility.c)\nDeveloped to SingOS\nby Jorn Guldberg\n";
|
||||
fsci.this_partition_offset_on_disk = SPACE_VBR_RECORD;
|
||||
fsci.master_table_index = fsci.this_partition_offset_on_disk + SIZE_FSCI_RECORD;
|
||||
fsci.next_free_sector = fsci.master_table_index + DEFAULT_TABLE_SIZE;
|
||||
fsci.next_uniqe_id = 1;
|
||||
fsci.next_sector_reuse_pointer = 0;
|
||||
fsci.last_sector_index_on_partition = filesystem_size_in_MB * 2048; // Todo, this is the ssectors pr MB, this should not be hardcoded.
|
||||
}
|
||||
else
|
||||
{
|
||||
// This is an error case, and we should not hit this case.
|
||||
assert(NULL);
|
||||
}
|
||||
|
||||
|
||||
//fsci.maximum_sectors_on_partition = 1048576; // Max 4GiB
|
||||
fsci.next_free_sector = 257;
|
||||
|
||||
// Create disk on host system:
|
||||
disk = fopen ( disk_name , "wb" );
|
||||
|
||||
// Start writing data to the disk
|
||||
fseek ( disk , 0, SEEK_SET );
|
||||
fwrite(&fsci, 1, sizeof(fsci), disk);
|
||||
zero_buffer = calloc(1, (4096 - sizeof(fsci)));
|
||||
|
||||
BIN
Binary file not shown.
Reference in new issue
Block a user