Skip to content

Commit b8005fa

Browse files
Implemented ~80% of original FAT16. Will work more.
1 parent d76089c commit b8005fa

7 files changed

Lines changed: 356 additions & 27 deletions

File tree

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,4 @@ keys/private_key.pem
2222
*.bin
2323
*.raw
2424
*.so
25-
*.img
2625
*.img.tar.gz

Makefile

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,15 @@ QEMU_COMMON = \
6161
-vga std \
6262
-debugcon stdio \
6363
-serial file:serial.log \
64-
-boot menu=on \
6564
-audiodev pa,id=speaker \
6665
-device rtl8139,netdev=eth0 \
6766
-netdev user,hostfwd=tcp::5555-:22,id=eth0 \
68-
-device usb-ehci,id=ehci \
69-
-drive if=none,format=raw,file=$(ISO_FILE),id=usbdisk,index=0\
70-
-device usb-storage,drive=usbdisk \
71-
-drive if=none,format=raw,file=disk.txtimg,id=disk,index=1 \
67+
-cdrom $(ISO_FILE) \
68+
-drive if=none,format=raw,file=disk.img,id=disk,index=1 \
7269
-device ahci,id=ahci \
7370
-device ide-hd,drive=disk,bus=ahci.0 \
7471
-rtc base=localtime,clock=host \
72+
-boot order=d \
7573
-m 512
7674

7775
run-x86-hdd:
@@ -115,3 +113,14 @@ fonts:
115113
clean:
116114
@rm -rf ./disk_root $(ISO_FILE) $(ISO_FILE).tar.gz serial.log
117115
@cd source && make deep-clean && cd ..
116+
117+
# MISC
118+
mount-dummy-disk:
119+
sudo losetup -fP disk.img
120+
sudo mkdir -p /mnt/fat16
121+
sudo mount /dev/loop0p1 /mnt/fat16
122+
cd /mnt/fat16
123+
124+
umount-dummy-disk:
125+
sudo umount /mnt/fat16
126+
sudo losetup -d /dev/loop0
32 MB
Binary file not shown.

source/includes/filesystems/fat16.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ typedef struct {
6868
typedef struct {
6969
fat16_fs_t* fs;
7070
fat16_dir_entry_t entry;
71+
uint16_t parent_cluster;
7172
uint32_t pos;
7273
uint16_t cluster;
7374
} fat16_file_t;
@@ -94,4 +95,6 @@ void fat16_write_fat_entry(fat16_fs_t* fs, uint16_t cluster, uint16_t value);
9495
uint16_t fat16_allocate_cluster(fat16_fs_t* fs);
9596
uint16_t fat16_append_cluster(fat16_fs_t* fs, uint16_t last_cluster);
9697
void fat16_update_root_entry(fat16_fs_t* fs, fat16_dir_entry_t* entry);
98+
int fat16_update_dir_entry(fat16_fs_t* fs, uint16_t dir_cluster, fat16_dir_entry_t* entry);
99+
97100
#endif

source/kernel/C/ahci.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ void detect_ahci_devices(ahci_hba_mem_t* ahci_ctrl) {
4242

4343
handle_sata_disk(i);
4444

45-
// hcf2();
45+
hcf2();
4646
break;
4747
case satapi_disk:
4848
printf("[AHCI] SATAPI device detected on port %d", i);

source/kernel/C/disk/gpt.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,23 @@ void parse_gpt_partitions(int portno, struct GPT_PartTableHeader* hdr) {
9999
fat16_fs_t fs;
100100
fat16_dir_entry_t file;
101101

102+
//
102103
fat16_mount(portno, start, &fs);
103-
fat16_list_root(&fs);
104+
105+
fat16_create(&fs, 0, "FWLOGS.TXT", 0x20);
106+
fat16_file_t f;
107+
fat16_open(&fs, "/FWLOGS.TXT", &f);
108+
const char msg[] = "HELLO FAT16\n";
109+
fat16_write(&f, (const uint8_t*)msg, sizeof(msg));
110+
111+
// rewind
112+
f.pos = 0;
113+
f.cluster = f.entry.first_cluster;
114+
uint8_t buf[64];
115+
fat16_read(&f, buf, sizeof(buf));
116+
for(int k=0;k<64;k++)
117+
printfnoln("%c", buf[k]);
118+
print("\n");
104119
}
105120
}
106121

0 commit comments

Comments
 (0)