FAT16 library written for an ATmega project with SD card
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
c-fat16/main.c

140 lines
6.5 KiB

10 years ago
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
10 years ago
#include <string.h>
10 years ago
#include "fat16.h"
// ------------- test ----------------
10 years ago
BLOCKDEV test;
FILE* testf;
void test_seek(const uint32_t pos)
{
fseek(testf, pos, SEEK_SET);
}
void test_rseek(const int16_t pos)
10 years ago
{
fseek(testf, pos, SEEK_CUR);
}
void test_load(void* dest, const uint16_t len)
10 years ago
{
fread(dest, len, 1, testf);
// for (int a = 0; a < len; a++) {
// fread(dest+a, 1, 1, testf);
// }
10 years ago
}
void test_store(const void* source, const uint16_t len)
10 years ago
{
fwrite(source, len, 1, testf);
// for (int a = 0; a < len; a++) {
// fwrite(source+a, 1, 1, testf);
// }
}
void test_write(const uint8_t b)
{
fwrite(&b, 1, 1, testf);
}
uint8_t test_read()
10 years ago
{
uint8_t a;
fread(&a, 1, 1, testf);
return a;
10 years ago
}
void test_open()
{
test.read = &test_read;
test.write = &test_write;
test.load = &test_load;
test.store = &test_store;
10 years ago
test.seek = &test_seek;
test.rseek = &test_rseek;
testf = fopen("imgs/hamlet.img", "rb+");
10 years ago
}
void test_close()
{
fflush(testf);
fclose(testf);
}
// --- testing ---
int main()
10 years ago
{
test_open();
// Initialize the FS
FAT16 fat;
fat16_init(&test, &fat);
FAT16_FILE file;
fat16_root(&fat, &file);
10 years ago
char str[12];
printf("Disk label: %s\n", fat16_disk_label(&fat, str));
10 years ago
do
{
10 years ago
if (!fat16_is_regular(&file))
continue;
10 years ago
printf("File name: %s, %c, %d B, @ 0x%x\n",
fat16_dispname(&file, str),
file.type, file.size, file.clu_start);
}
while (fat16_next(&file));
10 years ago
// fat16_root(&fat, &file);
10 years ago
// if (fat16_mkfile(&file, "slepice8.ini"))
// {
// printf("created.\n");
// char* moo = "Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of 'de Finibus Bonorum et Malorum' (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, 'Lorem ipsum dolor sit amet..', comes from a line in section 1.10.32.";
// fat16_write(&file, moo, strlen(moo));
// }
10 years ago
// if (fat16_find(&file, "slepice2.ini"))
// {
// printf("Found.\n");
10 years ago
10 years ago
// char m[1000000];
// fat16_read(&file, m, file.size);
// m[file.size] = 0;
// printf("%s\n", m);
10 years ago
10 years ago
//// char* moo = "\n\nContrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of 'de Finibus Bonorum et Malorum' (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, 'Lorem ipsum dolor sit amet..', comes from a line in section 1.10.32. Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of 'de Finibus Bonorum et Malorum' (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, 'Lorem ipsum dolor sit amet..', comes from a line in section 1.10.32.Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of 'de Finibus Bonorum et Malorum' (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, 'Lorem ipsum dolor sit amet..', comes from a line in section 1.10.32.Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of 'de Finibus Bonorum et Malorum' (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, 'Lorem ipsum dolor sit amet..', comes from a line in section 1.10.32.Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of 'de Finibus Bonorum et Malorum' (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, 'Lorem ipsum dolor sit amet..', comes from a line in section 1.10.32.";
10 years ago
10 years ago
//// fat16_seek(&file, file.size);
//// fat16_write(&file, moo, strlen(moo));
// }
10 years ago
// if (fat16_find(&file, "banana2.exe"))
// {
// printf("Found.\n");
// printf("Deleted? %d\n", fat16_delete(&file));
// }
10 years ago
test_close();
return 0;
}