0
I need to write a program that creates a floppy image of FAT12. The instructions include creating a boot sector, making sure I set aside space for two FAT tables, setting up space for root directory and finally for data. However the instructions don't mention anything about handling new files/directories.
For example, let's say I have a ready floopy image called "floppy". Then I can mount the floppy in Ubuntu terminal:
sudo mount -o loop,uid=user, gid=user floppy mntpoint/
mkdir mntpoint/test
echo "Hello World" > mntpoint/test/foo
Does mount automatically recognize the information contained in the boot sector and understands that it's FAT12? If yes how does mount
know where to put foo
file within the floppy image? I assume I must somehow handle this. But how can I handle this line for example, what kind of functions would I have to have:
echo "Hello World" > mntpoint/test/foo
I'm writing in C. I'm not adding the code because my question is not code specific but rather conceptual. Just in case I'm adding the code for boot sector struct:
typedef struct {
uint8_t bootjmp[3]; /* 0 Jump to boot code */
uint8_t oem_id[8]; /* 3 OEM name & version */
uint16_t sector_size; /* 11 Bytes per sector hopefully 512 */
uint8_t sectors_per_cluster; /* 13 Cluster size in sectors */
uint16_t reserved_sector_count; /* 14 Number of reserved (boot) sectors */
uint8_t number_of_fats; /* 16 Number of FAT tables hopefully 2 */
uint16_t number_of_dirents; /* 17 Number of directory slots */
/*
* If 0, look in sector_count_large
*/
uint16_t sector_count; /* 19 Total sectors on disk */
uint8_t media_type; /* 21 Media descriptor=first byte of FAT */
/*
* Set for FAT12/16 only.
*
* The number of blocks occupied by one copy of the File Allocation Table.
*/
uint16_t fat_size_sectors; /* 22 Sectors in FAT */
uint16_t sectors_per_track; /* 24 Sectors/track */
uint16_t nheads; /* 26 Heads */
uint32_t sectors_hidden; /* 28 number of hidden sectors */
uint32_t sector_count_large; /* 32 big total sectors */
} __attribute__ ((packed)) boot_record_t;
1Do you just need to create the filesystem or do you need to include files? A filesystem is dumb and in most cases doesn't know anything about how to add files as that logic get implemented in the OS and filesystem driver. – Seth – 2018-01-09T10:15:57.173
@Seth I need to create the system but them I need to support adding files like in the echo example. – Yos – 2018-01-09T10:16:55.963
Would this be more suited to StackOverflow, since it's essentially programming related? A user (even a "superuser" ;-) would just mount & echo. And have you looked through the fat driver's source code yet, all the "how" answers should be in there somewhere. – Xen2050 – 2018-01-09T11:02:45.783
@Xen2050 I actually posted this question in the beginning to StackOverflow but they said it doesn't belong to SO and suggested I post it here. In any case my fundamental question has now been answered. – Yos – 2018-01-09T11:09:49.187