diff --git a/fat16.c b/fat16.c index 757f0bb..a16f005 100644 --- a/fat16.c +++ b/fat16.c @@ -57,6 +57,20 @@ bool find_empty_file_slot(FAT16_FILE* file); // =========== INTERNAL FUNCTION IMPLEMENTATIONS ========= + +uint16_t read16(const BLOCKDEV* dev) +{ + uint16_t a; + dev->load(&a, 2); + return a; +} + + +void write16(const BLOCKDEV* dev, const uint16_t val) +{ + dev->store(&val, 2); +} + /** Find absolute address of first boot sector. Returns 0 on failure. */ uint32_t find_bs(const BLOCKDEV* dev) { @@ -139,14 +153,14 @@ void read_bs(const BLOCKDEV* dev, Fat16BootSector* info, const uint32_t addr) void write_fat(const FAT16* fat, const uint16_t cluster, const uint16_t value) { fat->dev->seek(fat->fat_addr + (cluster * 2)); - fat->dev->write16(value); + write16(fat->dev, value); } uint16_t read_fat(const FAT16* fat, const uint16_t cluster) { fat->dev->seek(fat->fat_addr + (cluster * 2)); - return fat->dev->read16(); + return read16(fat->dev); } @@ -418,11 +432,11 @@ void write_file_header(FAT16_FILE* file, const char* fname_raw, const uint8_t at } // addr of the first file cluster - dev->write16(clu_start); + write16(dev, clu_start); // file size (uint32_t) - dev->write16(0); - dev->write16(0); + write16(dev, 0); + write16(dev, 0); // reopen file - load & parse the information just written open_file(file->fat, file, file->clu, file->num); diff --git a/fat16.h b/fat16.h index e11dbee..ff34d92 100644 --- a/fat16.h +++ b/fat16.h @@ -9,12 +9,8 @@ typedef struct void (*store)(const void* src, const uint16_t len); // Sequential byte write void (*write)(const uint8_t b); - // Sequential 2-byte write - void (*write16)(const uint16_t b); // Sequential byte read uint8_t (*read)(void); - // Sequential 2-byte read - uint16_t (*read16)(void); // Absolute seek void (*seek)(const uint32_t); // Relative seek diff --git a/main.c b/main.c index 58afa67..5cb6680 100644 --- a/main.c +++ b/main.c @@ -45,11 +45,6 @@ void test_write(const uint8_t b) fwrite(&b, 1, 1, testf); } -void test_write16(const uint16_t b) -{ - fwrite(&b, 2, 1, testf); -} - uint8_t test_read() { uint8_t a; @@ -57,21 +52,11 @@ uint8_t test_read() return a; } -uint16_t test_read16() -{ - uint16_t a; - fread(&a, 2, 1, testf); - return a; -} - void test_open() { test.read = &test_read; test.write = &test_write; - test.read16 = &test_read16; - test.write16 = &test_write16; - test.load = &test_load; test.store = &test_store; diff --git a/test b/test new file mode 100755 index 0000000..8484a1b Binary files /dev/null and b/test differ