Implement SFS Superblock

This commit is contained in:
Robbe Van Herck 2020-01-03 15:14:29 +01:00
parent 07fbe8ee4c
commit bf5f6e3ea7
No known key found for this signature in database
GPG key ID: A66F76F7B81BD784
2 changed files with 54 additions and 15 deletions

View file

@ -29,13 +29,14 @@
## Hard Drive layout ## Hard Drive layout
| start | end | use | | start | end | use |
|--------|--------|--------------------------------------------| |------------|------------|--------------------------------------------|
| 0x0000 | 0x01ff | Bootloader code (including SFS superblock) | | 0x00000000 | 0x000001ff | Bootloader code (including SFS superblock) |
| 0x0200 | 0x81ff | SFS reserved area (kernel ELF file) | | 0x00000200 | 0x000081ff | SFS reserved area (kernel ELF file) |
| 0x8200 | 0x???? | SFS data area | | 0x00008200 | 0x400081ff | SFS data area (1GiB, 1048576 SFS blocks) |
| 0x???? | 0x???? | SFS free area | | 0x40008200 | 0x5fffffff | SFS free area |
| 0x???? | end | SFS index area | | 0x60000000 | 0x7fffffff | SFS index area |
| 0x80000000 | end | Unused |
## Known issues ## Known issues

View file

@ -1,27 +1,65 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdint.h> #include <stdint.h>
#include <time.h>
#define KERNEL_SECTORS 64 #define KERNEL_SECTORS 64
#define KiB 1024
#define MiB (1024 * KiB)
#define GiB (1024 * MiB)
#define DISK_SIZE (1 * GiB)
#define BLOCK_SIZE_ARG 1
#define BLOCK_SIZE (1 << (BLOCK_SIZE_ARG + 7))
#define RESERVED_SIZE (32 * KiB)
#define NUM_RESERVED_BLOCKS (RESERVED_SIZE / BLOCK_SIZE)
#define DATA_SIZE (1 * GiB)
#define NUM_DATA_BLOCKS (DATA_SIZE / BLOCK_SIZE)
#define INDEX_SIZE (128 * MiB)
int main(int argc, char** argv) { int main(int argc, char** argv) {
FILE* result_file = fopen("./target/boot.bin", "w+b"); FILE* result_file = fopen("./target/boot.bin", "w+b");
FILE* bootloader_file = fopen("./target/bootloader/bootloader.bin", "rb"); FILE* bootloader_file = fopen("./target/bootloader/bootloader.bin", "rb");
// ------- BOOTLOADER + SFS HEADER ------- // ------- BOOTLOADER + SFS HEADER -------
char* buffer = calloc(512, sizeof(char)); uint8_t* buffer = calloc(512, sizeof(uint8_t));
int i = 0; int i = 0;
int curr_char; int curr_byte;
while ((curr_char = fgetc(bootloader_file)) != EOF) { while ((curr_byte = fgetc(bootloader_file)) != EOF) {
buffer[i] = (char) curr_char; buffer[i] = (uint8_t) curr_byte;
i++; i++;
} }
// TODO edit SFS header // SFS Superblock
time_t current_time = time(NULL);
uint64_t sfs_timestamp = (uint64_t) current_time * 65536;
buffer[0x194] = 0xff; (*(uint64_t*) (buffer + 0x194)) = sfs_timestamp;
(*(uint64_t*) (buffer + 0x19C)) = NUM_DATA_BLOCKS;
(*(uint64_t*) (buffer + 0x1A4)) = INDEX_SIZE;
(*(uint32_t*) (buffer + 0x1AC)) = 0x10534653; // SFS magic + version
(*(uint64_t*) (buffer + 0x1B0)) = ((uint64_t) DISK_SIZE) / BLOCK_SIZE;
// The superblock may be bigger than one block
if (BLOCK_SIZE < 512) {
(*(uint32_t*) (buffer + 0x1B8)) = NUM_RESERVED_BLOCKS + 2;
} else {
(*(uint32_t*) (buffer + 0x1B8)) = NUM_RESERVED_BLOCKS + 1;
}
buffer[0x1BC] = BLOCK_SIZE_ARG;
uint8_t sum = 0;
for (int i = 0x1AC; i < 0x1BD; i++) {
sum += buffer[i];
}
buffer[0x1BD] = -sum;
for (int i = 0; i < 512; i++) { for (int i = 0; i < 512; i++) {
@ -37,8 +75,8 @@ int main(int argc, char** argv) {
int bytes_written = 0; int bytes_written = 0;
while ((curr_char = fgetc(kernel_file)) != EOF) { while ((curr_byte = fgetc(kernel_file)) != EOF) {
fputc((char) curr_char, result_file); fputc((char) curr_byte, result_file);
bytes_written++; bytes_written++;
} }