I'm attempting to create a FAT file system I understand the basic principle of how its supposed to set up and I'm using a struct like this for each FAT entry
struct FATEntry
{
char name[20]; /* Name of file */
uint32_t pos; /* Position of file on disk (sector, block, something else) */
uint32_t size; /* Size in bytes of file */
uint32_t mtime; /* Time of last modification */
};
I'm essentially creating a 2 MB file to act as my file system. From there I will write and read files into blocks of 512 bytes each. My question how I can write a struct to a file? Does fwrite allow me to do this? For example:
struct FATEntry entry1;
strcpy(entry1.name, "abc");
entry1.pos = 3;
entry1.size = 10;
entry1.mtime = 100;
cout << entry1.name;
file = fopen("filesys", "w");
fwrite(&entry1,sizeof(entry1),1,file);
fclose(file);
Will that store the struct in bytes? How do I read from this? I'm having trouble understanding what I will get back when I use fread