]>
wirehaze git hosting - BOS.git/blob - kernel/fat12/fat12.asm
a96178245aba6e52c2d00cc61c1c300f730e0705
1 ;----------------------------------------------------------;
2 ; BOS kernel Christoffer Bubach, 2012-2015. ;
3 ;----------------------------------------------------------;
7 ;----------------------------------------------------------;
9 ;---------------------------------------------;
10 ; main FAT12 info structure ;
11 ;---------------------------------------------;
14 .disk_number db 0 ; which VFS disk number
15 .root_dir dw 0 ; position of rootdir
16 .fat_1 dd 0 ; position of fat1
17 .fat_2 dd 0 ; position of fat2
18 .data_area dw 0 ; position of dataarea
19 .disk_size dd 0 ; total storage size
20 .free_space dd 0 ; free space available
23 times 16 * sizeof
.dir_entry
db 0 ; 512b dir entry buffer
24 .fat_buffer: times 512 db 0 ; 512b FAT cluster info buffer
27 ;---------------------------------------------;
28 ; FAT12 bootsector structure ;
29 ;---------------------------------------------;
30 struc bootsector
; 512 bytes
33 .oem db 0,0,0,0,0,0,0,0
36 .reserved_sect dw 0 ; reserved sectors, 1 for bootsector.
39 .small_sectors dw 0 ; total sectors on small disk
40 .media_describtor db 0 ; 240 / 0xF0 = 1.44MB, 3.5"
41 .sectors_per_fat dw 0 ; 9 on 1.44MB, 3,5"
42 .sect_per_track dw 0 ; 18 on 1.44MB, 3,5"
43 .heads dw 0 ; 2 on 1.44MB, 3,5"
44 .hidden_sectors dd 0 ; sectors before bootsector
45 .large_sectors dd 0 ; total sectors if large disk
48 .bpb_signature db 0 ; 41=3 more (win NT req.), 0=end.
49 .disk_id dd 0 ; random ident number on format.
50 .volume_label db 0,0,0,0,0,0,0,0,0,0,0
51 .filesystem db 0,0,0,0,0,0,0,0 ; "FAT12 " or "FAT16 "
53 .boot_signature db 0,0 ; 0x55,0xAA
56 ;---------------------------------------------;
57 ; FAT12 directory entry structure ;
58 ;---------------------------------------------;
61 .filename db 0,0,0,0,0,0,0,0
63 .attributes db 0 ; 0x10 = dir for example.
64 .reserved db 0,0,0,0,0,0,0,0,0,0
71 ;---------------------------------------------;
72 ; FAT12 directory entry for LFN ;
73 ;---------------------------------------------;
76 .order db 0 ; LFN entry in sequence, never 0x00 or 0xE5.
77 .namefirst dw 0,0,0,0,0 ; 5 first unicode (2byte) chars
78 .attribute db 0 ; 0x0F for Long File Name identification.
80 .checksum db 0 ; 8.3 name checksum
81 .namemiddle dw 0,0,0,0,0,0 ; middle 6 unicode (2byte) chars
82 .zero_cluster dw 0 ; always zero on LNF entries
83 .namelast dw 0,0 ; last 2 unicode (2byte) characters.
106 ;------------------------------------------;
107 ; FAT cluster constants used ;
108 ;------------------------------------------;
109 cluster_free
= 0x000 ; up for grabs.
110 cluster_reserved
= 0xFF0 ; 0xFF0-0xFF6. 0xFF7=bad.
111 cluster_last
= 0xFF8 ; 0xFF8-0xFFF last cluster.
113 ;------------------------------------------;
114 ; Directory entry first char constants ;
115 ;------------------------------------------;
116 entry_free
= 0xE5 ; up for grabs.
117 entry_last
= 0x00 ; this and remaining is free
118 entry_japan_kludge
= 0x0E ; should be outputed as 0xE5.
119 entry_dot
= 0x2E ; ASCII dot, check for "." or ".." dirs
121 ;------------------------------------------;
122 ; Directory entry attribute masks ;
123 ;------------------------------------------;
127 mask_volume_label
= 0x08
128 mask_subdirectory
= 0x10
131 ;------------------------------------------;
132 ; Long File Name entry constants ;
133 ;------------------------------------------;
134 lfn_last_entry_mask
= 0x40 ; LFN sequence-order mask for last
135 attribute_lfn
= 0x0F ; attrb. byte value for LFN dir entry
141 fd0: fat12
; define fd0 data.. tmp example.
143 ; TODO, alloc memory for struct and keep pointer only.
146 ;mov edi, drive+fat12into.boot
148 ;--------------------------------------------------------------;
149 ; init_fat12 - detect if drive fs is fat12 and init ;
150 ;--------------------------------------------------------------;
152 ; in: reg = pointer to VFS drive info ;
154 ; out: reg = pointer to struct(s) if FAT12 found ;
156 ;--------------------------------------------------------------;
161 ;-----------------------------;
162 ; calculate root location ;
163 ;-----------------------------;
165 mov al, byte [fd0
.boot
.fats_per_drive
]
166 mul word [fd0
.boot
.sectors_per_fat
]
167 add ax, word [fd0
.boot
.reserved_sect
]
168 mov [fd0
.root_dir
], ax
172 ;mov ax, [si+fat12.boot.sectorssize]
174 ; a bit more code here
178 ;--------------------------------------------------------------;
179 ; calc_lfn_chksum - get long file name checksum ;
180 ;--------------------------------------------------------------;
182 ; in: esi = pointer to 11 byte 8.3 filename ;
184 ; out: ax = checksum ;
186 ;--------------------------------------------------------------;
192 xor ax, ax ; return value start with null
194 add ax, byte [esi] ; add next char to sum
195 shr ax, 1 ; shift sum right by 1
196 inc esi ; prepare for next character
203 ;--------------------------------------------------------------;
204 ; get_dir_entry - get a directory entry or amount ;
205 ;--------------------------------------------------------------;
207 ; in: esi = pointer to prev dir entry or 0 for root ;
208 ; cx = entry no. to extract or 0 for none ;
210 ; out: cx = number of entries or unchanged if set ;
211 ; edi = pointer to dir entry or unchanged if cx=0 ;
212 ;--------------------------------------------------------------;
217 ;--------------------------------------------------------------;
218 ; get_fat_entry - get a fat entry/cluster number ;
219 ;--------------------------------------------------------------;
221 ; in: cx = fat entry/cluster number ;
223 ; out: cx = next fat entry/cluster no. or 0 if none ;
224 ;--------------------------------------------------------------;
229 ;--------------------------------------------------------------;
230 ; get_cluster - get a cluster ;
231 ;--------------------------------------------------------------;
233 ; in: cx = fat entry/cluster number ;
235 ; out: edi = pointer to cluster or zero if none ;
236 ;--------------------------------------------------------------;