Rev 6876 | Rev 6939 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 6876 | Rev 6917 | ||
---|---|---|---|
Line 3... | Line 3... | ||
3 | ;; Copyright (C) KolibriOS team 2004-2016. All rights reserved. ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2016. All rights reserved. ;; |
4 | ;; Distributed under terms of the GNU General Public License. ;; |
4 | ;; Distributed under terms of the GNU General Public License. ;; |
5 | ;; ;; |
5 | ;; ;; |
6 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
6 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
Line 7... | Line 7... | ||
7 | 7 | ||
Line 8... | Line 8... | ||
8 | $Revision: 6876 $ |
8 | $Revision: 6917 $ |
9 | 9 | ||
10 | ; FAT external functions |
10 | ; FAT external functions |
11 | ; in: |
11 | ; in: |
Line 27... | Line 27... | ||
27 | dd fat_GetFileInfo |
27 | dd fat_GetFileInfo |
28 | dd fat_SetFileInfo |
28 | dd fat_SetFileInfo |
29 | dd 0 |
29 | dd 0 |
30 | dd fat_Delete |
30 | dd fat_Delete |
31 | dd fat_CreateFolder |
31 | dd fat_CreateFolder |
- | 32 | dd fat_Rename |
|
32 | fat_user_functions_end: |
33 | fat_user_functions_end: |
33 | endg |
34 | endg |
Line 34... | Line 35... | ||
34 | 35 | ||
Line 44... | Line 45... | ||
44 | 45 | ||
45 | ; Internal data for every FAT partition. |
46 | ; Internal data for every FAT partition. |
46 | struct FAT PARTITION |
47 | struct FAT PARTITION |
47 | fs_type db ? |
48 | fs_type db ? |
- | 49 | fat_change db ? ; 1=fat has changed |
|
48 | fat_change db ? ; 1=fat has changed |
50 | createOption db ? |
49 | rb 2 |
51 | rb 1 |
50 | Lock MUTEX ; currently operations with one partition |
52 | Lock MUTEX ; currently operations with one partition |
51 | ; can not be executed in parallel since the legacy code is not ready |
53 | ; can not be executed in parallel since the legacy code is not ready |
52 | SECTORS_PER_FAT dd ? |
54 | SECTORS_PER_FAT dd ? |
53 | NUMBER_OF_FATS dd ? |
55 | NUMBER_OF_FATS dd ? |
Line 1839... | Line 1841... | ||
1839 | pop ecx |
1841 | pop ecx |
1840 | ret |
1842 | ret |
Line 1841... | Line 1843... | ||
1841 | 1843 | ||
1842 | ;---------------------------------------------------------------- |
1844 | ;---------------------------------------------------------------- |
1843 | fat_CreateFolder: |
1845 | fat_CreateFolder: |
1844 | push 1 |
1846 | mov [ebp+FAT.createOption], 0 |
Line 1845... | Line 1847... | ||
1845 | jmp @f |
1847 | jmp @f |
1846 | 1848 | ||
1847 | fat_CreateFile: |
1849 | fat_CreateFile: |
1848 | push 0 |
1850 | mov [ebp+FAT.createOption], 1 |
1849 | @@: |
- | |
1850 | call fat_lock |
1851 | @@: |
1851 | pop eax |
1852 | call fat_lock |
- | 1853 | mov ecx, [ebx+12] |
|
1852 | mov ecx, [ebx+12] |
1854 | mov edx, [ebx+16] |
1853 | mov edx, [ebx+16] |
1855 | .rename: |
1854 | pushad |
1856 | pushad |
1855 | xor edi, edi |
1857 | xor edi, edi |
1856 | push esi |
1858 | push esi |
Line 1934... | Line 1936... | ||
1934 | jz .exists_file |
1936 | jz .exists_file |
1935 | ; found directory |
1937 | ; found directory |
1936 | add esp, 36 |
1938 | add esp, 36 |
1937 | call fat_unlock |
1939 | call fat_unlock |
1938 | popad |
1940 | popad |
1939 | test al, al |
1941 | xor eax, eax |
1940 | mov eax, ERROR_ACCESS_DENIED |
1942 | cmp [ebp+FAT.createOption], 0 |
1941 | jz @f |
1943 | jz @f |
1942 | mov al, 0 |
1944 | mov al, ERROR_ACCESS_DENIED |
1943 | @@: |
1945 | @@: |
1944 | xor ebx, ebx |
1946 | xor ebx, ebx |
1945 | ret |
1947 | ret |
Line 1946... | Line 1948... | ||
1946 | 1948 | ||
1947 | .exists_file: |
1949 | .exists_file: |
1948 | cmp byte [esp+36+28], 0 |
1950 | cmp [ebp+FAT.createOption], 1 |
1949 | jz @f |
1951 | jz @f |
1950 | add esp, 36 |
1952 | add esp, 36 |
Line 1951... | Line 1953... | ||
1951 | jmp .noAccess |
1953 | jmp .noAccess |
Line 2089... | Line 2091... | ||
2089 | inc ecx |
2091 | inc ecx |
2090 | cmp ecx, eax |
2092 | cmp ecx, eax |
2091 | jb .scan_cont |
2093 | jb .scan_cont |
2092 | ; found! |
2094 | ; found! |
2093 | push esi ecx |
2095 | push esi ecx |
2094 | ; If creating a directory, allocate one data cluster now and fail immediately |
2096 | ; If creating a directory, allocate one data cluster or fail immediately if this is impossible. |
2095 | ; if this is impossible. This prevents from creating an invalid directory entry |
2097 | ; This prevents from creating an invalid directory entry on a full disk. |
2096 | ; on a full disk. |
- | |
2097 | ; yup, the argument is quite non-intuitive... but what should I do if |
- | |
2098 | ; the entire function uses such arguments? BTW, it refers to al from pushad, |
- | |
2099 | ; which in turn is filled with 0 in fat_CreateFile and 1 in fat_CreateFolder. |
- | |
2100 | cmp byte [esp+8+12+8+12+36+28], 0 |
2098 | cmp [ebp+FAT.createOption], 0 |
2101 | jz .no.preallocate.folder.data |
2099 | jnz .notFolder |
2102 | call get_free_FAT |
2100 | call get_free_FAT |
2103 | jnc @f |
2101 | jnc @f |
2104 | add esp, 8+12+8 |
2102 | add esp, 8+12+8 |
2105 | jmp .disk_full |
2103 | jmp .disk_full |
Line 2106... | Line 2104... | ||
2106 | 2104 | ||
2107 | @@: |
2105 | @@: |
2108 | mov [esp+8+12+8+12+36+20], eax ; store the cluster somewhere |
2106 | mov [esp+8+12+8+12+36+20], eax ; store the cluster somewhere |
2109 | .no.preallocate.folder.data: ; calculate name checksum |
2107 | .notFolder: ; calculate name checksum |
2110 | mov esi, [esp+8+12] |
2108 | mov esi, [esp+8+12] |
2111 | mov ecx, 11 |
2109 | mov ecx, 11 |
2112 | xor eax, eax |
2110 | xor eax, eax |
2113 | @@: |
2111 | @@: |
Line 2154... | Line 2152... | ||
2154 | call dword [eax+12] ; next write |
2152 | call dword [eax+12] ; next write |
2155 | xor eax, eax |
2153 | xor eax, eax |
2156 | loop .writelfn |
2154 | loop .writelfn |
2157 | pop eax esi |
2155 | pop eax esi |
2158 | .nolfn: |
2156 | .nolfn: |
- | 2157 | pop esi |
|
2159 | xchg esi, [esp] |
2158 | add esp, 16 |
2160 | mov ecx, 11 |
2159 | mov ecx, 11 |
2161 | rep movsb |
2160 | rep movsb |
- | 2161 | cmp [ebp+FAT.createOption], 2 |
|
- | 2162 | jz .copy |
|
2162 | mov word [edi], 20h ; attributes |
2163 | mov word [edi], 20h ; attributes |
2163 | sub edi, 11 |
2164 | sub edi, 11 |
2164 | pop esi ecx |
- | |
2165 | add esp, 12 |
- | |
2166 | mov byte [edi+13], 0 ; tenths of a second at file creation time |
2165 | mov byte [edi+13], 0 ; tenths of a second at file creation time |
2167 | call get_time_for_file |
2166 | call get_time_for_file |
2168 | mov [edi+14], ax ; creation time |
2167 | mov [edi+14], ax ; creation time |
2169 | mov [edi+22], ax ; last write time |
2168 | mov [edi+22], ax ; last write time |
2170 | call get_date_for_file |
2169 | call get_date_for_file |
2171 | mov [edi+16], ax ; creation date |
2170 | mov [edi+16], ax ; creation date |
2172 | mov [edi+24], ax ; last write date |
2171 | mov [edi+24], ax ; last write date |
2173 | mov [edi+18], ax ; last access date |
2172 | mov [edi+18], ax ; last access date |
2174 | xor ecx, ecx |
- | |
2175 | mov word [edi+20], cx ; high word of cluster |
2173 | mov word [edi+20], cx ; high word of cluster |
2176 | mov word [edi+26], cx ; low word of cluster - to be filled |
2174 | mov word [edi+26], cx ; low word of cluster - to be filled |
2177 | mov dword [edi+28], ecx ; file size - to be filled |
2175 | mov dword [edi+28], ecx ; file size - to be filled |
2178 | cmp byte [esp+36+28], cl |
2176 | cmp [ebp+FAT.createOption], 0 |
2179 | jz .doit |
2177 | jnz .doit |
2180 | ; create directory |
2178 | ; create directory |
2181 | mov byte [edi+11], 10h ; attributes: folder |
2179 | mov byte [edi+11], 10h ; attributes: folder |
2182 | mov esi, edi |
2180 | mov esi, edi |
2183 | lea eax, [esp+8] |
- | |
2184 | call dword [eax+16] ; flush directory |
- | |
2185 | mov eax, [esp+36+20] ; extract saved cluster |
2181 | mov eax, [esp+36+20] ; extract saved cluster |
2186 | mov [esp+36+20], edi ; this is needed for calculating arg of add_disk_free_space! |
2182 | mov [esp+36+20], edi ; this is needed for calculating arg of add_disk_free_space! |
2187 | push ecx |
2183 | push ecx |
2188 | mov ecx, [ebp+FAT.SECTORS_PER_CLUSTER] |
2184 | mov ecx, [ebp+FAT.SECTORS_PER_CLUSTER] |
2189 | shl ecx, 9 |
2185 | shl ecx, 9 |
2190 | push ecx |
2186 | push ecx |
2191 | push edi |
2187 | push edi |
2192 | jmp .doit2 |
2188 | jmp .doit2 |
Line -... | Line 2189... | ||
- | 2189 | ||
- | 2190 | .copy: |
|
- | 2191 | lea esi, [esp+72+11] |
|
- | 2192 | mov cl, 21 |
|
- | 2193 | rep movsb |
|
- | 2194 | sub edi, 32 |
|
- | 2195 | jmp .doit |
|
2193 | 2196 | ||
2194 | .done1: |
2197 | .done1: |
2195 | pop edi |
2198 | pop edi |
2196 | call get_time_for_file |
2199 | call get_time_for_file |
2197 | mov [edi+22], ax |
2200 | mov [edi+22], ax |
Line 2203... | Line 2206... | ||
2203 | mov esi, [esp+36+20] |
2206 | mov esi, [esp+36+20] |
2204 | lea eax, [esp+8] |
2207 | lea eax, [esp+8] |
2205 | call dword [eax+16] ; flush directory |
2208 | call dword [eax+16] ; flush directory |
2206 | push ecx |
2209 | push ecx |
2207 | mov ecx, [esp+4+36+24] |
2210 | mov ecx, [esp+4+36+24] |
2208 | push ecx |
2211 | xor eax, eax |
2209 | push edi |
- | |
2210 | test ecx, ecx |
2212 | test ecx, ecx |
2211 | jz .done |
2213 | jz .done |
- | 2214 | push ecx edi |
|
2212 | call get_free_FAT |
2215 | call get_free_FAT |
2213 | jc .diskfull |
2216 | jc .diskfull |
2214 | .doit2: |
2217 | .doit2: |
2215 | push eax |
2218 | push eax |
2216 | mov [edi+26], ax |
2219 | mov [edi+26], ax |
Line 2227... | Line 2230... | ||
2227 | dec eax |
2230 | dec eax |
2228 | imul eax, [ebp+FAT.SECTORS_PER_CLUSTER] |
2231 | imul eax, [ebp+FAT.SECTORS_PER_CLUSTER] |
2229 | add eax, [ebp+FAT.DATA_START] |
2232 | add eax, [ebp+FAT.DATA_START] |
2230 | push [ebp+FAT.SECTORS_PER_CLUSTER] |
2233 | push [ebp+FAT.SECTORS_PER_CLUSTER] |
2231 | .write_sector: |
2234 | .write_sector: |
2232 | cmp byte [esp+20+36+28], 0 |
2235 | cmp [ebp+FAT.createOption], 0 |
2233 | jnz .writedir |
2236 | jz .writedir |
2234 | mov ecx, 512 |
2237 | mov ecx, 512 |
2235 | cmp dword [esp+12], ecx |
2238 | cmp dword [esp+12], ecx |
2236 | jb .writeshort |
2239 | jb .writeshort |
2237 | ; we can write directly from given buffer |
2240 | ; we can write directly from given buffer |
2238 | mov ebx, esi |
2241 | mov ebx, esi |
Line 2323... | Line 2326... | ||
2323 | mov eax, ERROR_DEVICE |
2326 | mov eax, ERROR_DEVICE |
2324 | jmp .ret |
2327 | jmp .ret |
Line 2325... | Line 2328... | ||
2325 | 2328 | ||
2326 | .writedone: |
2329 | .writedone: |
2327 | pop eax eax |
- | |
2328 | .done: |
2330 | pop eax eax |
2329 | xor eax, eax |
2331 | xor eax, eax |
2330 | .ret: |
2332 | .ret: |
- | 2333 | pop edi ecx |
|
- | 2334 | inc ecx |
|
2331 | pop edi ecx |
2335 | .done: |
2332 | sub esi, [esp+4+36+20] |
2336 | sub esi, [esp+4+36+20] |
2333 | mov [esp+4+36+28], eax |
2337 | mov [esp+4+36+28], eax |
- | 2338 | mov [esp+4+36+16], esi |
|
2334 | mov [esp+4+36+16], esi |
2339 | jecxz @f |
2335 | lea eax, [esp+12] |
2340 | lea eax, [esp+12] |
2336 | call dword [eax+8] |
2341 | call dword [eax+8] |
2337 | mov [edi+28], esi |
2342 | mov [edi+28], esi |
2338 | call dword [eax+16] |
- | |
- | 2343 | call dword [eax+16] |
|
2339 | mov [esp+36+16], ebx |
2344 | @@: |
2340 | lea eax, [esi+511] |
2345 | lea eax, [esi+511] |
2341 | shr eax, 9 |
2346 | shr eax, 9 |
2342 | mov ecx, [ebp+FAT.SECTORS_PER_CLUSTER] |
2347 | mov ecx, [ebp+FAT.SECTORS_PER_CLUSTER] |
2343 | lea eax, [eax+ecx-1] |
2348 | lea eax, [eax+ecx-1] |
2344 | xor edx, edx |
2349 | xor edx, edx |
2345 | div ecx |
2350 | div ecx |
2346 | pop ecx |
2351 | pop ecx |
2347 | sub ecx, eax |
2352 | sub ecx, eax |
2348 | call add_disk_free_space |
2353 | call add_disk_free_space |
- | 2354 | add esp, 36 |
|
- | 2355 | cmp [ebp+FAT.createOption], 2 |
|
2349 | add esp, 36 |
2356 | jz @f |
2350 | call update_disk |
2357 | call update_disk |
- | 2358 | call fat_unlock |
|
2351 | call fat_unlock |
2359 | @@: |
2352 | popad |
2360 | popad |
Line 2353... | Line 2361... | ||
2353 | ret |
2361 | ret |
2354 | 2362 | ||
Line 3112... | Line 3120... | ||
3112 | call clear_cluster_chain |
3120 | call clear_cluster_chain |
3113 | call update_disk |
3121 | call update_disk |
3114 | call fat_unlock |
3122 | call fat_unlock |
3115 | xor eax, eax |
3123 | xor eax, eax |
3116 | ret=>=>>65536 |
3124 | ret |
- | 3125 | ||
- | 3126 | ;---------------------------------------------------------------- |
|
- | 3127 | fat_Rename: |
|
- | 3128 | ; in: edi -> new path string in UTF-8 |
|
- | 3129 | push esi edi |
|
- | 3130 | call fat_lock |
|
- | 3131 | call hd_find_lfn |
|
- | 3132 | pop ebx |
|
- | 3133 | jc .error |
|
- | 3134 | sub esp, 32 |
|
- | 3135 | mov esi, edi |
|
- | 3136 | mov edi, esp |
|
- | 3137 | mov ecx, 8 |
|
- | 3138 | rep movsd |
|
- | 3139 | mov [ebp+FAT.createOption], 2 |
|
- | 3140 | mov esi, ebx |
|
- | 3141 | call fat_CreateFile.rename |
|
- | 3142 | add esp, 32 |
|
- | 3143 | pop esi |
|
- | 3144 | test eax, eax |
|
- | 3145 | jnz .ret |
|
- | 3146 | push eax |
|
- | 3147 | mov [ebp+FAT.longname_sec1], eax |
|
- | 3148 | mov [ebp+FAT.longname_sec2], eax |
|
- | 3149 | call hd_find_lfn |
|
- | 3150 | jc .error |
|
- | 3151 | mov byte [edi], 0xE5 |
|
- | 3152 | jmp fat_Delete.lfndel |
|
- | 3153 | ||
- | 3154 | .error: |
|
- | 3155 | push eax |
|
- | 3156 | call fat_unlock |
|
- | 3157 | pop eax ebx |
|
- | 3158 | .ret: |
|
- | 3159 | ret=>=>>65536 |