41void Mkfile(
const char *filename,
const char *ext) {
43 int sector_to_write = -1;
44 u32 entries_per_sector =
fat16.bytes_per_sector / 32;
45 u32 root_dir_sectors =
46 ((
fat16.root_entry_count * 32) + (
fat16.bytes_per_sector - 1)) /
47 fat16.bytes_per_sector;
53 for (
u32 i = 0; i < root_dir_sectors; i++) {
55 for (
u32 j = 0; j < entries_per_sector; j++) {
57 if (entry[0] == 0x00 || entry[0] == 0xE5) {
60 goto found_free_entry;
66 if (free == -1 || sector_to_write == -1) {
67 Kprintf(
"No free root directory entry found!\n");
72 for (
u16 c = 2; c <
fat16.total_cluster; c++) {
73 u32 fat_offset = c * 2;
74 u32 fat_sector =
fat16.fat_start_lba + (fat_offset / 512);
75 u32 fat_index = fat_offset % 512;
80 if (fatbuf[fat_index] == 0x00 && fatbuf[fat_index + 1] == 0x00) {
82 fatbuf[fat_index] = 0xFF;
83 fatbuf[fat_index + 1] = 0xFF;
90 Kprintf(
"No free cluster found!\n");
100 for (
int i = 0; i < 32; i++) {
106 Padname(filename, name_pad, 8);
107 Padname(ext, ext_pad, 3);
108 Kmemcpy(entry + 0x00, name_pad, 8);
109 Kmemcpy(entry + 0x08, ext_pad, 3);
119 entry[0x1A] = clust & 0xFF;
120 entry[0x1B] = (clust >> 8) & 0xFF;
129 Kprintf(
"File entry written successfully.\n");