Rev 131 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
129 | mikedld | 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
||
3 | ;; FAT32.INC ;; |
||
4 | ;; ;; |
||
131 | diamond | 5 | ;; FAT16/32 functions for KolibriOS ;; |
129 | mikedld | 6 | ;; ;; |
7 | ;; Copyright 2002 Paolo Minazzi, paolo.minazzi@inwind.it ;; |
||
8 | ;; ;; |
||
9 | ;; See file COPYING for details ;; |
||
131 | diamond | 10 | ;; 17.08.2006 LFN write/append to file - diamond ;; |
129 | mikedld | 11 | ;; 23.06.2006 LFN start application - diamond ;; |
12 | ;; 15.06.2006 LFN get/set file/folder info - diamond ;; |
||
13 | ;; 27.05.2006 LFN create/rewrite file - diamond ;; |
||
14 | ;; 04.05.2006 LFN read folder - diamond ;; |
||
15 | ;; 29.04.2006 Elimination of hangup after the ;; |
||
16 | ;; expiration hd_wait_timeout - Mario79 ;; |
||
17 | ;; 23.04.2006 LFN read file - diamond ;; |
||
18 | ;; 28.01.2006 find all Fat16/32 partition in all input point ;; |
||
19 | ;; to MBR, see file part_set.inc - Mario79 ;; |
||
20 | ;; 15.01.2005 get file size/attr/date, file_append - ATV ;; |
||
21 | ;; 04.12.2004 skip volume label, file delete bug fixed - ATV ;; |
||
22 | ;; 29.11.2004 get_free_FAT changed, append dir bug fixed - ATV ;; |
||
23 | ;; 23.11.2004 don't allow overwrite dir with file - ATV ;; |
||
24 | ;; 18.11.2004 get_disk_info and more error codes - ATV ;; |
||
25 | ;; 17.11.2004 set_FAT/get_FAT and disk cache rewritten - ATV ;; |
||
26 | ;; 10.11.2004 removedir clear whole directory structure - ATV ;; |
||
27 | ;; 08.11.2004 rename - ATV ;; |
||
28 | ;; 30.10.2004 file_read return also dirsize in bytes - ATV ;; |
||
29 | ;; 20.10.2004 Makedir/Removedir - ATV ;; |
||
30 | ;; 14.10.2004 Partition chain/Fat16 - ATV (thanks drh3xx) ;; |
||
31 | ;; 06.9.2004 Fix free space by Mario79 added - MH ;; |
||
32 | ;; 24.5.2004 Write back buffer for File_write -VT ;; |
||
33 | ;; 20.5.2004 File_read function to work with syscall 58 - VT ;; |
||
34 | ;; 30.3.2004 Error parameters at function return - VT ;; |
||
35 | ;; 01.5.2002 Bugfix in device write - VT ;; |
||
36 | ;; 20.5.2002 Hd status check - VT ;; |
||
37 | ;; 29.6.2002 Improved fat32 verification - VT ;; |
||
38 | ;; ;; |
||
39 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
40 | |||
41 | cache_max equ 1919 ; max. is 1919*512+0x610000=0x6ffe00 |
||
42 | |||
43 | ERROR_SUCCESS = 0 |
||
44 | ERROR_DISK_BASE = 1 |
||
45 | ERROR_UNSUPPORTED_FS = 2 |
||
46 | ERROR_UNKNOWN_FS = 3 |
||
47 | ERROR_PARTITION = 4 |
||
48 | ERROR_FILE_NOT_FOUND = 5 |
||
49 | ERROR_END_OF_FILE = 6 |
||
50 | ERROR_MEMORY_POINTER = 7 |
||
51 | ERROR_DISK_FULL = 8 |
||
52 | ERROR_FAT_TABLE = 9 |
||
53 | ERROR_ACCESS_DENIED = 10 |
||
54 | |||
55 | PUSHAD_EAX equ [esp+28] |
||
56 | PUSHAD_ECX equ [esp+24] |
||
57 | PUSHAD_EDX equ [esp+20] |
||
58 | PUSHAD_EBX equ [esp+16] |
||
59 | PUSHAD_EBP equ [esp+8] |
||
60 | PUSHAD_ESI equ [esp+4] |
||
61 | PUSHAD_EDI equ [esp+0] |
||
62 | |||
63 | cluster dd 0 ; used by file_write,makedir,append |
||
64 | partition_count dd 0 ; partitions found by set_FAT32_variables |
||
65 | longname_sec1 dd 0 ; used by analyze_directory to save 2 previous |
||
66 | longname_sec2 dd 0 ; directory sectors for delete long filename |
||
67 | |||
68 | hd_error dd 0 ; set by wait_for_sector_buffer |
||
69 | hd_setup dd 0 |
||
70 | hd_wait_timeout dd 0 |
||
71 | |||
72 | cluster_tmp dd 0 ; used by analyze_directory |
||
73 | ; and analyze_directory_to_write |
||
74 | |||
75 | file_size dd 0 ; used by file_read |
||
76 | |||
77 | sector_tmp dd 0 ; used by rename,append,file_write |
||
78 | entry_pos dd 0 ; used by rename,append,file_write |
||
79 | |||
80 | old_filesize dd 0 ; used by append |
||
81 | new_filepos dd 0 ; used by append |
||
82 | bytes2write dd 0 ; used by append |
||
83 | |||
84 | cache_search_start dd 0 ; used by find_empty_slot |
||
85 | |||
86 | fat_in_cache dd -1 |
||
87 | fat_cache: times 512 db 0 |
||
88 | |||
89 | uglobal |
||
90 | Sector512: ; label for dev_hdcd.inc |
||
91 | buffer: times 512 db 0 |
||
92 | deltree_buffer: times 512 db 0 |
||
133 | diamond | 93 | fsinfo_buffer: times 512 db 0 |
129 | mikedld | 94 | endg |
95 | |||
96 | iglobal |
||
97 | NewDirEntry1 db ". ",0x10 |
||
98 | times 20 db 0 |
||
99 | NewDirEntry2 db ".. ",0x10 |
||
100 | times 20 db 0 |
||
101 | endg |
||
102 | |||
103 | uglobal |
||
104 | dir_entry: times 32 db 0 |
||
105 | |||
106 | startpath: times 255 db 0 |
||
107 | |||
108 | fat16_root db 0 ; flag for fat16 rootdir |
||
109 | fat_change db 0 ; 1=fat has changed |
||
110 | |||
111 | endg |
||
112 | |||
113 | reserve_hd1: |
||
114 | |||
115 | cli |
||
116 | cmp [hd1_status],0 |
||
117 | je reserve_ok1 |
||
118 | |||
119 | sti |
||
120 | call change_task |
||
121 | jmp reserve_hd1 |
||
122 | |||
123 | reserve_ok1: |
||
124 | |||
125 | push eax |
||
126 | mov eax,[0x3000] |
||
127 | shl eax,5 |
||
128 | mov eax,[eax+0x3000+TASKDATA.pid] |
||
129 | mov [hd1_status],eax |
||
130 | pop eax |
||
131 | sti |
||
132 | ret |
||
133 | ;******************************************** |
||
134 | reserve_hd_channel: |
||
135 | cmp [hdbase], 0x1F0 |
||
136 | jne .IDE_Channel_2 |
||
137 | .IDE_Channel_1: |
||
138 | cli |
||
139 | cmp [IDE_Channel_1],0 |
||
140 | je .reserve_ok_1 |
||
141 | sti |
||
142 | call change_task |
||
143 | jmp .IDE_Channel_1 |
||
144 | .IDE_Channel_2: |
||
145 | cli |
||
146 | cmp [IDE_Channel_2],0 |
||
147 | je .reserve_ok_2 |
||
148 | sti |
||
149 | call change_task |
||
150 | jmp .IDE_Channel_1 |
||
151 | .reserve_ok_1: |
||
152 | mov [IDE_Channel_1],1 |
||
153 | ret |
||
154 | .reserve_ok_2: |
||
155 | mov [IDE_Channel_2],1 |
||
156 | ret |
||
157 | |||
158 | free_hd_channel: |
||
159 | cmp [hdbase], 0x1F0 |
||
160 | jne .IDE_Channel_2 |
||
161 | .IDE_Channel_1: |
||
162 | mov [IDE_Channel_1],0 |
||
163 | ret |
||
164 | .IDE_Channel_2: |
||
165 | mov [IDE_Channel_2],0 |
||
166 | ret |
||
167 | ;******************************************** |
||
168 | clear_hd_cache: |
||
169 | |||
170 | push eax ecx edi |
||
171 | mov edi,0x600000 |
||
172 | mov ecx,16384 |
||
173 | xor eax,eax |
||
174 | cld |
||
175 | rep stosd ; clear hd cache with 0 |
||
176 | mov [cache_search_start],eax |
||
177 | mov [fat_in_cache],-1 |
||
178 | mov [fat_change],0 |
||
179 | pop edi ecx eax |
||
180 | ret |
||
181 | |||
182 | problem_partition db 0 ; used for partitions search |
||
183 | |||
184 | include 'part_set.inc' |
||
185 | |||
186 | set_FAT: |
||
187 | ;-------------------------------- |
||
188 | ; input : EAX = cluster |
||
189 | ; EDX = value to save |
||
190 | ; output : EDX = old value |
||
191 | ;-------------------------------- |
||
192 | push eax ebx esi |
||
193 | |||
194 | cmp eax,2 |
||
195 | jb sfc_error |
||
196 | cmp eax,[LAST_CLUSTER] |
||
197 | ja sfc_error |
||
198 | cmp [fat_type],16 |
||
199 | je sfc_1 |
||
200 | add eax,eax |
||
201 | sfc_1: |
||
202 | add eax,eax |
||
203 | mov esi,511 |
||
204 | and esi,eax ; esi = position in fat sector |
||
205 | shr eax,9 ; eax = fat sector |
||
206 | add eax,[FAT_START] |
||
207 | mov ebx,fat_cache |
||
208 | |||
209 | cmp eax,[fat_in_cache] ; is fat sector already in memory? |
||
210 | je sfc_in_cache ; yes |
||
211 | |||
212 | cmp [fat_change],0 ; is fat changed? |
||
213 | je sfc_no_change ; no |
||
214 | call write_fat_sector ; yes. write it into disk |
||
215 | cmp [hd_error],0 |
||
216 | jne sfc_error |
||
217 | |||
218 | sfc_no_change: |
||
219 | mov [fat_in_cache],eax ; save fat sector |
||
220 | call hd_read |
||
221 | cmp [hd_error],0 |
||
222 | jne sfc_error |
||
223 | |||
224 | |||
225 | sfc_in_cache: |
||
226 | cmp [fat_type],16 |
||
227 | jne sfc_test32 |
||
228 | |||
229 | sfc_set16: |
||
230 | xchg [ebx+esi],dx ; save new value and get old value |
||
231 | jmp sfc_write |
||
232 | |||
233 | sfc_test32: |
||
234 | mov eax,[fatMASK] |
||
235 | |||
236 | sfc_set32: |
||
237 | and edx,eax |
||
238 | xor eax,-1 ; mask for high bits |
||
239 | and eax,[ebx+esi] ; get high 4 bits |
||
240 | or eax,edx |
||
241 | mov edx,[ebx+esi] ; get old value |
||
242 | mov [ebx+esi],eax ; save new value |
||
243 | |||
244 | sfc_write: |
||
245 | mov [fat_change],1 ; fat has changed |
||
246 | |||
247 | sfc_nonzero: |
||
248 | and edx,[fatMASK] |
||
249 | |||
250 | sfc_error: |
||
251 | pop esi ebx eax |
||
252 | ret |
||
253 | |||
254 | |||
255 | get_FAT: |
||
256 | ;-------------------------------- |
||
257 | ; input : EAX = cluster |
||
258 | ; output : EAX = next cluster |
||
259 | ;-------------------------------- |
||
260 | push ebx esi |
||
261 | |||
262 | cmp [fat_type],16 |
||