Advertisement
Madmouse

fat.h so far

Dec 20th, 2015
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.09 KB | None | 0 0
  1. #ifndef __FAT_H__
  2. #define __FAT_H__
  3.  
  4. #include <stdint.h>
  5. #include <machine.h>
  6.  
  7. typedef struct bpb {
  8.     char jmp_code[3];
  9.     char oem[8];
  10.     uint16_t bytes_per_sector;
  11.     uint8_t sectors_per_cluster;
  12.     uint16_t reserved_sectors;
  13.     uint8_t fats;
  14.     uint16_t dir_entries;
  15.     uint16_t logical_sectors;
  16.     uint8_t media_type;
  17.     uint16_t sectors_per_fat;
  18.     uint16_t sectors_per_track;
  19.     uint16_t heads;
  20.     uint32_t hidden_sectors;
  21.     uint32_t large_sectors;
  22. } bpb_t;
  23.  
  24. typedef struct ebr {
  25.     uint8_t drive;
  26.     uint8_t rflags;
  27.     uint8_t signiture;
  28.     uint32_t serial;
  29.     char label[11];
  30.     char identifier[8];
  31.     char boot_code[448];
  32.     uint16_t boot_sign;
  33. } ebr_t;
  34.  
  35. typedef struct fat12_partition_info {
  36. // see fat12.s for an implementation
  37. // in assembly for visualization :D
  38.  
  39.     bpb_t bpb;
  40.     ebr_t ebr;
  41.     char data[];
  42. } fat12_partition_info_t;
  43.  
  44. typedef char fat_t[];
  45.  
  46. typedef struct fat_dir_entry {
  47.     char name[11];
  48.     uint8_t attributes;
  49.     uint16_t reserved;
  50.     uint16_t creation_time;
  51.     uint16_t creation_date;
  52.     uint16_t access_date;
  53.     uint16_t caddr_high;
  54.     uint16_t write_time;
  55.     uint16_t write_date;
  56.     uint16_t caddr_low;
  57.     uint32_t size;
  58. } fat_dir_entry_t;
  59.  
  60. const uint8_t fat12_format_stub[122] = {
  61.   0xEB, 0x3C, 0x90, 0x4D, 0x61, 0x64, 0x4F, 0x53, 0x76, 0x30,
  62.   0x31, 0x00, 0x02, 0x01, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
  63.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  64.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x29, 0x37,
  65.   0x13, 0x00, 0x00, 0x4D, 0x61, 0x64, 0x4F, 0x53, 0x20, 0x44,
  66.   0x69, 0x73, 0x6B, 0x20, 0x46, 0x41, 0x54, 0x31, 0x32, 0x20,
  67.   0x20, 0x20, 0x31, 0xC0, 0x8E, 0xD8, 0x8E, 0xC0, 0x8E, 0xD0,
  68.   0xBC, 0x7A, 0x8C, 0x8D, 0x36, 0x5E, 0x7C, 0xE8, 0x02, 0x00,
  69.   0xEB, 0xFE, 0xAC, 0x08, 0xC0, 0x74, 0x06, 0xB4, 0x0E, 0xCD,
  70.   0x10, 0xEB, 0xF5, 0xC3, 0x4D, 0x61, 0x64, 0x4F, 0x53, 0x20,
  71.   0x64, 0x69, 0x73, 0x6B, 0x20, 0x6E, 0x6F, 0x74, 0x20, 0x62,
  72.   0x6F, 0x6F, 0x74, 0x61, 0x62, 0x6C, 0x65, 0x2E, 0x2E, 0x2E,
  73.   0x0D, 0x0A
  74. /*
  75. [bits 16]
  76. [org 0x7C00]
  77.  
  78. ;;;;;;;;;;;;;;;;;;;;;;;;
  79. ; BIOS Parameter Block
  80. jmp short boot_code
  81. nop
  82. db "MadOSv01"          ; OEM identifier
  83. dw 512                 ; Bytes per sector:  512, 1024, 2048 or 4096.
  84.                        ;    the value 512 should be used for max compat.
  85. db 1                   ; sectors per cluster:  1, 2, 4, 8, 16, 32, 64, and 128.
  86. dw 0                   ; reserved sectors: must not be 0. For FAT12 and FAT16 volumes must be 1
  87. db 2                   ; number of fats: always contain the value 2
  88. dw 0                   ; root directory entries
  89. dw 0                   ; logical sectors
  90. db 0                   ; media descriptor type: 0xF8 -> fixed, 0xF0 -> removable
  91. dw 0                   ; sectors per fat, fat12/fat16 only, number of sectors occupied by one fat
  92. dw 0                   ; sectors per track
  93. dw 0                   ; number of heads / sides on media
  94. dd 0                   ; number of hidden sectors
  95. dd 0                   ; Large amount of sector on media. This field is set if there are more than 65535 sectors in the volume.
  96.  
  97. ; Extended Boot Record
  98. db 0                   ; drive number
  99. db 0                   ; reserved / NT flags (maybe use for MadOS, More research needed)
  100. db 0x29                ; signiture, 0x28 or 0x29 for fat12 /fat16
  101. dd 0x1337              ; volume serial number
  102. db "MadOS Disk "       ; volume label
  103. db "FAT12   "          ; identifier string
  104.  
  105. ; Boot code
  106. boot_code:
  107.     xor ax, ax
  108.     mov ds, ax
  109.     mov es, ax
  110.     mov ss, ax
  111.     mov sp, boot_code_end + (1024 * 4)
  112.  
  113.     lea si, [message]
  114.     call print_string
  115.     jmp $
  116.  
  117. print_string:
  118.     lodsb
  119.     or al, al
  120.     jz done
  121.     mov ah, 0x0E
  122.     int 0x10
  123.     jmp print_string
  124. done:
  125.    ret
  126.  
  127. message:
  128.     db "MadOS disk not bootable...", 0xd, 0xa
  129.  
  130. ;dw 0xAA55 ; bootable partition signiture, uncomment to make the floppy boot
  131. boot_code_end:
  132. times 450 - (boot_code_end - boot_code) db 0
  133.  
  134. ;;;;;;;;;;;;;;;;;;;;;
  135. ; DATA AREA START
  136. ;;;;;;;;;;;;;;;;;;;;;
  137. ; root directory
  138. ;;;;;;;;;;;;;;;;;;;;;
  139. ; END -> FIN
  140. */
  141. };
  142.  
  143.  
  144. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement