Subversion Repositories Kolibri OS

Rev

Rev 6262 | Rev 6471 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 6262 Rev 6468
Line 1... Line 1...
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                              ;;
2
;;                                                              ;;
3
;; Copyright (C) KolibriOS team 2004-2015. 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
;;                                                              ;;
-
 
6
;;  FAT functions for KolibriOS                                 ;;
-
 
7
;;                                                              ;;
-
 
8
;;  Copyright 2002 Paolo Minazzi, paolo.minazzi@inwind.it       ;;
-
 
9
;;                                                              ;;
-
 
10
;;  See file COPYING for details                                ;;
-
 
11
;;  06.2015 fs_read64 - pathoswithin                            ;;
-
 
12
;;  04.02.2007 LFN create folder - diamond                      ;;
-
 
13
;;  08.10.2006 LFN delete file/folder - diamond                 ;;
-
 
14
;;  20.08.2006 LFN set file size (truncate/extend) - diamond    ;;
-
 
15
;;  17.08.2006 LFN write/append to file - diamond               ;;
-
 
16
;;  23.06.2006 LFN start application - diamond                  ;;
-
 
17
;;  15.06.2006 LFN get/set file/folder info - diamond           ;;
-
 
18
;;  27.05.2006 LFN create/rewrite file - diamond                ;;
-
 
19
;;  04.05.2006 LFN read folder - diamond                        ;;
-
 
20
;;  29.04.2006 Elimination of hangup after the                  ;;
-
 
21
;;             expiration hd_wait_timeout - Mario79             ;;
-
 
22
;;  23.04.2006 LFN read file - diamond                          ;;
-
 
23
;;  28.01.2006 find all Fat16/32 partition in all input point   ;;
-
 
24
;;             to MBR, see file part_set.inc - Mario79          ;;
-
 
25
;;  15.01.2005 get file size/attr/date, file_append - ATV       ;;
-
 
26
;;  04.12.2004 skip volume label, file delete bug fixed - ATV   ;;
-
 
27
;;  29.11.2004 get_free_FAT changed, append dir bug fixed - ATV ;;
-
 
28
;;  23.11.2004 don't allow overwrite dir with file - ATV        ;;
-
 
29
;;  18.11.2004 get_disk_info and more error codes - ATV         ;;
-
 
30
;;  17.11.2004 set_FAT/get_FAT and disk cache rewritten - ATV   ;;
-
 
31
;;  10.11.2004 removedir clear whole directory structure - ATV  ;;
-
 
32
;;  08.11.2004 rename - ATV                                     ;;
-
 
33
;;  30.10.2004 file_read return also dirsize in bytes - ATV     ;;
-
 
34
;;  20.10.2004 Makedir/Removedir - ATV                          ;;
-
 
35
;;  14.10.2004 Partition chain/Fat16 - ATV (thanks drh3xx)      ;;
-
 
36
;;  06.09.2004 Fix free space - Mario79                         ;;
-
 
37
;;  24.05.2004 Write back buffer for File_write - VT            ;;
-
 
38
;;  20.05.2004 File_read function to work with syscall 58 - VT  ;;
-
 
39
;;  30.03.2004 Error parameters at function return - VT         ;;
-
 
40
;;  29.06.2002 Improved fat32 verification - VT                 ;;
-
 
41
;;  20.05.2002 Hd status check - VT                             ;;
-
 
42
;;  01.05.2002 Bugfix in device write - VT                      ;;
-
 
43
;;                                                              ;;
5
;;                                                              ;;
44
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 45... Line 7...
45
 
7
 
-
 
8
$Revision: 6468 $
-
 
9
 
-
 
10
; FAT external functions
-
 
11
;   in:
-
 
12
; ebx -> parameter structure of sysfunc 70
-
 
13
; ebp -> FAT structure
-
 
14
; esi -> path string
-
 
15
;   out:
-
 
16
; eax, ebx = return values for sysfunc 70
-
 
17
iglobal
-
 
18
align 4
-
 
19
fat_user_functions:
-
 
20
        dd      fat_free
-
 
21
        dd      (fat_user_functions_end - fat_user_functions - 4) / 4
-
 
22
        dd      fat_Read
-
 
23
        dd      fat_ReadFolder
-
 
24
        dd      fat_CreateFile
-
 
25
        dd      fat_Write
-
 
26
        dd      fat_SetFileEnd
-
 
27
        dd      fat_GetFileInfo
-
 
28
        dd      fat_SetFileInfo
-
 
29
        dd      0
-
 
30
        dd      fat_Delete
-
 
31
        dd      fat_CreateFolder
-
 
32
fat_user_functions_end:
Line 46... Line 33...
46
$Revision: 6262 $
33
endg
Line 47... Line 34...
47
 
34
 
48
cache_max equ 1919      ; max. is 1919*512+0x610000=0x6ffe00
35
cache_max equ 1919      ; max. is 1919*512+0x610000=0x6ffe00
Line 56... Line 43...
56
PUSHAD_EDI equ [esp+0]
43
PUSHAD_EDI equ [esp+0]
Line 57... Line 44...
57
 
44
 
58
; Internal data for every FAT partition.
45
; Internal data for every FAT partition.
59
struct FAT PARTITION
46
struct FAT PARTITION
60
fs_type              db ?
-
 
61
fat16_root           db 0       ; flag for fat16 rootdir
47
fs_type             db  ?
62
fat_change           db 0       ; 1=fat has changed
48
fat_change          db  ?   ; 1=fat has changed
63
                     rb 1
49
                    rb  2
64
Lock            MUTEX   ?       ; currently operations with one partition
50
Lock                MUTEX   ; currently operations with one partition
65
; can not be executed in parallel since the legacy code is not ready
51
; can not be executed in parallel since the legacy code is not ready
66
SECTORS_PER_FAT      dd 0x1f3a
52
SECTORS_PER_FAT     dd  ?
67
NUMBER_OF_FATS       dd 0x2
53
NUMBER_OF_FATS      dd  ?
68
SECTORS_PER_CLUSTER  dd 0x8
54
SECTORS_PER_CLUSTER dd  ?
69
BYTES_PER_SECTOR     dd 0x200   ; Note: if BPS <> 512 need lots of changes
55
BYTES_PER_SECTOR    dd  ?   ; Note: if BPS <> 512 need lots of changes
70
ROOT_CLUSTER         dd 2       ; first rootdir cluster
56
ROOT_CLUSTER        dd  ?   ; first rootdir cluster
71
FAT_START            dd 0       ; start of fat table
57
FAT_START           dd  ?   ; start of fat table
72
ROOT_START           dd 0       ; start of rootdir (only fat16)
58
ROOT_START          dd  ?   ; start of rootdir (only fat16)
73
ROOT_SECTORS         dd 0       ; count of rootdir sectors (only fat16)
59
ROOT_SECTORS        dd  ?   ; count of rootdir sectors (only fat16)
74
DATA_START           dd 0       ; start of data area (=first cluster 2)
60
DATA_START          dd  ?   ; start of data area (=first cluster 2)
75
LAST_CLUSTER         dd 0       ; last availabe cluster
61
LAST_CLUSTER        dd  ?   ; last availabe cluster
76
ADR_FSINFO           dd 0       ; used only by fat32
-
 
77
 
62
ADR_FSINFO          dd  ?   ; used only by fat32
78
fatRESERVED          dd 0x0FFFFFF6
63
fatRESERVED         dd  ?
79
fatBAD               dd 0x0FFFFFF7
64
fatBAD              dd  ?
80
fatEND               dd 0x0FFFFFF8
65
fatEND              dd  ?
81
fatMASK              dd 0x0FFFFFFF
-
 
82
 
66
fatMASK             dd  ?
83
fatStartScan         dd 2
67
fatStartScan        dd  ?
84
cluster_tmp          dd 0       ; used by analyze_directory
-
 
85
                                ; and analyze_directory_to_write
68
cluster_tmp         dd  ?   ; used by analyze_directory and analyze_directory_to_write
86
longname_sec1        dd 0       ; used by analyze_directory to save 2 previous
69
longname_sec1       dd  ?   ; used by analyze_directory to save 2 previous
87
longname_sec2        dd 0       ; directory sectors for delete long filename
70
longname_sec2       dd  ?   ; directory sectors for delete long filename
88
fat_in_cache         dd -1
-
 
89
 
71
fat_in_cache        dd  ?
90
; For FAT16/FAT32, this points to 512-byte buffer for the current sector of FAT.
72
; For FAT16/FAT32, this points to 512-byte buffer for the current sector of FAT.
91
; For FAT12, the entire FAT structure is read
73
; For FAT12, the entire FAT structure is read
92
; and unpacked from 12bit per cluster to word per cluster.
-
 
93
 
74
; and unpacked from 12bit per cluster to word per cluster.
94
; Note: work with unpacked copy of FAT12 means
75
; Note: work with unpacked copy of FAT12 means
95
; additional memory and additional code for packing/unpacking.
76
; additional memory and additional code for packing/unpacking.
96
; I'm not sure that the economy justifies the cost, but anyway,
77
; I'm not sure that the economy justifies the cost, but anyway,
97
; there is how work was done before my edits, and I'm just keeping the principle.
78
; there is how work was done before my edits, and I'm just keeping the principle.
Line 101... Line 82...
101
fsinfo_buffer        rb 512
82
fsinfo_buffer       rb  512
102
ends
83
ends
Line 103... Line 84...
103
 
84
 
104
uglobal
85
uglobal
105
align 4
86
align 4
106
partition_count      dd 0       ; partitions found by set_FAT32_variables
87
partition_count     dd  ?   ; partitions found by set_FAT32_variables
107
hd_error             dd 0
88
hd_error            dd  ?
108
hd_setup             dd 0
89
hd_setup            dd  ?
109
hd_wait_timeout      dd 0
90
hd_wait_timeout     dd  ?
110
cache_search_start   dd 0       ; used by find_empty_slot
-
 
111
endg
-
 
112
 
-
 
113
uglobal
-
 
114
align 4
91
cache_search_start  dd  ?   ; used by find_empty_slot
115
Sector512:      ; label for dev_hdcd.inc
92
Sector512:      ; label for dev_hdcd.inc
116
buffer:
93
buffer:
117
rb 512
94
rb 512
Line 118... Line -...
118
endg
-
 
119
 
-
 
120
iglobal
-
 
121
align 4
-
 
122
fat_user_functions:
-
 
123
        dd      fat_free
-
 
124
        dd      (fat_user_functions_end - fat_user_functions - 4) / 4
-
 
125
        dd      fat_Read
-
 
126
        dd      fat_ReadFolder
-
 
127
        dd      fat_Rewrite
-
 
128
        dd      fat_Write
-
 
129
        dd      fat_SetFileEnd
-
 
130
        dd      fat_GetFileInfo
-
 
131
        dd      fat_SetFileInfo
-
 
132
        dd      0
-
 
133
        dd      fat_Delete
-
 
134
        dd      fat_CreateFolder
-
 
135
fat_user_functions_end:
-
 
136
endg
95
endg
137
 
96
 
138
; these labels are located before the main function to make
97
; these labels are located before the main function to make
139
; most of jumps to these be short
98
; most of jumps to these be short
140
fat_create_partition.free_return0:
99
fat_create_partition.free_return0:
Line 1596... Line 1555...
1596
        call    bdfe_to_fat_date
1555
        call    bdfe_to_fat_date
1597
        mov     [edi+24], ax            ; last write date
1556
        mov     [edi+24], ax            ; last write date
1598
        ret
1557
        ret
Line 1599... Line 1558...
1599
 
1558
 
1600
hd_find_lfn:
1559
hd_find_lfn:
1601
; in: ebp -> FAT structure
-
 
1602
; in: esi+[esp+4] -> name
1560
; in: esi -> path string
1603
; out: CF=1 - file not found, eax=error code
1561
; out: CF=1 - file not found, eax=error code
1604
;      else CF=0 and edi->direntry, eax=sector
-
 
1605
; destroys eax
1562
;      else CF=0 and edi->direntry, eax=sector
1606
        push    esi edi
1563
        push    esi edi
1607
        push    0
1564
        push    0
1608
        push    0
1565
        push    0
1609
        push    fat1x_root_first
1566
        push    fat1x_root_first
Line 1616... Line 1573...
1616
        and     [ebp+FAT.longname_sec2], 0
1573
        and     [ebp+FAT.longname_sec2], 0
1617
        call    fat_find_lfn
1574
        call    fat_find_lfn
1618
        jc      .notfound
1575
        jc      .notfound
1619
        cmp     byte [esi], 0
1576
        cmp     byte [esi], 0
1620
        jz      .found
1577
        jz      .found
1621
.continue:
-
 
1622
        test    byte [edi+11], 10h
1578
        test    byte [edi+11], 10h
1623
        jz      .notfound
1579
        jz      .notfound
1624
        and     dword [esp+12], 0
1580
        and     dword [esp+12], 0
1625
        mov     eax, [edi+20-2]
1581
        mov     eax, [edi+20-2]
1626
        mov     ax, [edi+26]    ; cluster
1582
        mov     ax, [edi+26]    ; cluster
1627
.fat32:
1583
.fat32:
1628
        mov     [esp+8], eax
1584
        mov     [esp+8], eax
1629
        mov     dword [esp+4], fat_notroot_first
1585
        mov     dword [esp+4], fat_notroot_first
1630
        mov     dword [esp], fat_notroot_next
1586
        mov     dword [esp], fat_notroot_next
1631
        jmp     .loop
1587
        jmp     .loop
-
 
1588
 
1632
.notfound:
1589
.notfound:
1633
        add     esp, 16
1590
        add     esp, 16
1634
        pop     edi esi
1591
        pop     edi esi
1635
        stc
1592
        stc
1636
        ret     4
1593
        ret
-
 
1594
 
1637
.found:
1595
.found:
1638
        lea     eax, [esp+4+24]
-
 
1639
        cmp     dword [eax], 0
-
 
1640
        jz      @f
-
 
1641
        mov     esi, [eax]
-
 
1642
        and     dword [eax], 0
-
 
1643
        jmp     .continue
-
 
1644
@@:
-
 
1645
        lea     eax, [esp+8]
1596
        lea     eax, [esp+8]
1646
        cmp     dword [eax], 0
1597
        cmp     dword [eax], 0
1647
        jz      .root
1598
        jz      .root
1648
        call    fat_get_sector
1599
        call    fat_get_sector
1649
        jmp     .cmn
1600
        jmp     .cmn
-
 
1601
 
1650
.root:
1602
.root:
1651
        mov     eax, [eax+4]
1603
        mov     eax, [eax+4]
1652
        add     eax, [ebp+FAT.ROOT_START]
1604
        add     eax, [ebp+FAT.ROOT_START]
1653
.cmn:
1605
.cmn:
1654
        add     esp, 20         ; CF=0
1606
        add     esp, 20         ; CF=0
1655
        pop     esi
1607
        pop     esi
1656
        ret     4
1608
        ret
Line 1657... Line 1609...
1657
 
1609
 
1658
;----------------------------------------------------------------
-
 
1659
; fat_Read - FAT implementation of reading a file
-
 
1660
; in:  ebp = pointer to FAT structure
-
 
1661
; in:  esi+[esp+4] = name
-
 
1662
; in:  ebx = pointer to parameters from sysfunc 70
-
 
1663
; out: eax, ebx = return values for sysfunc 70
-
 
1664
;----------------------------------------------------------------
1610
;----------------------------------------------------------------
1665
fat_Read:
1611
fat_Read:
1666
        call    fat_lock
1612
        call    fat_lock
1667
        push    edi
1613
        push    edi
1668
        cmp     byte [esi], 0
1614
        cmp     byte [esi], 0
Line 1672... Line 1618...
1672
        call    fat_unlock
1618
        call    fat_unlock
1673
        or      ebx, -1
1619
        or      ebx, -1
1674
        mov     eax, ERROR_ACCESS_DENIED
1620
        mov     eax, ERROR_ACCESS_DENIED
1675
        ret
1621
        ret
1676
@@:
1622
@@:
1677
        stdcall hd_find_lfn, [esp+8]
1623
        call    hd_find_lfn
1678
        jnc     .found
1624
        jnc     .found
1679
        pop     edi
1625
        pop     edi
1680
        push    eax
1626
        push    eax
1681
        call    fat_unlock
1627
        call    fat_unlock
1682
        pop     eax
1628
        pop     eax
Line 1849... Line 1795...
1849
        inc     esi
1795
        inc     esi
1850
        xor     ecx, ecx
1796
        xor     ecx, ecx
1851
        jmp     .fragmentEnd
1797
        jmp     .fragmentEnd
Line 1852... Line 1798...
1852
 
1798
 
1853
;----------------------------------------------------------------
-
 
1854
; fat_ReadFolder - FAT implementation of reading a folder
-
 
1855
; in:  ebp = pointer to FAT structure
-
 
1856
; in:  esi+[esp+4] = name
-
 
1857
; in:  ebx = pointer to parameters from sysfunc 70
-
 
1858
; out: eax, ebx = return values for sysfunc 70
-
 
1859
;----------------------------------------------------------------
1799
;----------------------------------------------------------------
1860
fat_ReadFolder:
1800
fat_ReadFolder:
1861
        call    fat_lock
1801
        call    fat_lock
1862
        mov     eax, [ebp+FAT.ROOT_CLUSTER]
1802
        mov     eax, [ebp+FAT.ROOT_CLUSTER]
1863
        push    edi
1803
        push    edi
1864
        cmp     byte [esi], 0
1804
        cmp     byte [esi], 0
1865
        jz      .doit
1805
        jz      .doit
1866
        stdcall hd_find_lfn, [esp+4+4]
1806
        call    hd_find_lfn
1867
        jnc     .found
1807
        jnc     .found
1868
        pop     edi
1808
        pop     edi
1869
        push    eax
1809
        push    eax
1870
        call    fat_unlock
1810
        call    fat_unlock
Line 2252... Line 2192...
2252
        mov     eax, ERROR_ACCESS_DENIED
2192
        mov     eax, ERROR_ACCESS_DENIED
2253
        xor     ebx, ebx
2193
        xor     ebx, ebx
2254
        ret
2194
        ret
Line 2255... Line 2195...
2255
 
2195
 
2256
;----------------------------------------------------------------
-
 
2257
; fat_CreateFolder - FAT implementation of creating a folder
-
 
2258
; in:  ebp = pointer to FAT structure
-
 
2259
; in:  esi+[esp+4] = name
-
 
2260
; in:  ebx = pointer to parameters from sysfunc 70
-
 
2261
; out: eax, ebx = return values for sysfunc 70
-
 
2262
;----------------------------------------------------------------
2196
;----------------------------------------------------------------
2263
fat_CreateFolder:
2197
fat_CreateFolder:
2264
        push    1
2198
        push    1
Line 2265... Line -...
2265
        jmp     fat_Rewrite.common
-
 
2266
 
-
 
2267
;----------------------------------------------------------------
-
 
2268
; fat_Rewrite - FAT implementation of creating a new file
-
 
2269
; in:  ebp = pointer to FAT structure
-
 
2270
; in:  esi+[esp+4] = name
-
 
2271
; in:  ebx = pointer to parameters from sysfunc 70
-
 
2272
; out: eax, ebx = return values for sysfunc 70
2199
        jmp     @f
2273
;----------------------------------------------------------------
2200
 
2274
fat_Rewrite:
2201
fat_CreateFile:
2275
        push    0
2202
        push    0
2276
.common:
2203
@@:
2277
        call    fat_lock
2204
        call    fat_lock
2278
        pop     eax
2205
        pop     eax
2279
        cmp     byte [esi], 0
2206
        cmp     byte [esi], 0
2280
        jz      fshrad
2207
        jz      fshrad
2281
        mov     ecx, [ebx+12]
2208
        mov     ecx, [ebx+12]
2282
        mov     edx, [ebx+16]
2209
        mov     edx, [ebx+16]
2283
        pushad
-
 
2284
        xor     edi, edi
2210
        pushad
2285
        mov     edx, [esp+4+20h]
-
 
2286
        push    esi
-
 
2287
        test    edx, edx
-
 
2288
        jz      @f
2211
        xor     edi, edi
2289
        mov     esi, edx
2212
        push    esi
2290
@@:
2213
@@:
2291
        lodsb
2214
        lodsb
2292
        test    al, al
2215
        test    al, al
2293
        jz      @f
2216
        jz      @f
2294
        cmp     al, '/'
2217
        cmp     al, '/'
2295
        jnz     @b
2218
        jnz     @b
-
 
2219
        lea     edi, [esi-1]
2296
        lea     edi, [esi-1]
2220
        jmp     @b
2297
        jmp     @b
2221
 
2298
@@:
2222
@@:
2299
        pop     esi
2223
        pop     esi
2300
        test    edi, edi
-
 
2301
        jnz     .noroot
-
 
2302
        test    edx, edx
2224
        test    edi, edi
2303
        jnz     .hasebp
2225
        jnz     .noroot
2304
        mov     edx, [ebp+FAT.ROOT_CLUSTER]
2226
        mov     edx, [ebp+FAT.ROOT_CLUSTER]
2305
        cmp     [ebp+FAT.fs_type], 32
2227
        cmp     [ebp+FAT.fs_type], 32
2306
        jz      .pushnotroot
2228
        jz      .pushnotroot
Line 2313... Line 2235...
2313
        push    edx
2235
        push    edx
2314
        push    edx
2236
        push    edx
2315
        push    fat1x_root_first
2237
        push    fat1x_root_first
2316
        push    fat1x_root_next
2238
        push    fat1x_root_next
2317
        jmp     .common1
2239
        jmp     .common1
2318
.hasebp:
2240
 
2319
        mov     eax, ERROR_ACCESS_DENIED
-
 
2320
        cmp     byte [edx], 0
-
 
2321
        jz      .ret1
-
 
2322
        stdcall hd_find_lfn, 0
-
 
2323
        mov     esi, [esp+4+20h]
-
 
2324
        jc      .ret1
-
 
2325
        jmp     .common0
-
 
2326
.noroot:
2241
.noroot:
2327
        mov     eax, ERROR_ACCESS_DENIED
2242
        mov     eax, ERROR_ACCESS_DENIED
2328
        cmp     byte [edi+1], 0
2243
        cmp     byte [edi+1], 0
2329
        jz      .ret1
2244
        jz      .ret1
2330
; check existence
2245
; check existence
2331
        mov     byte [edi], 0
2246
        mov     byte [edi], 0
2332
        push    edi
2247
        push    edi
2333
        stdcall hd_find_lfn, [esp+4+24h]
2248
        call    hd_find_lfn
2334
        pop     esi
2249
        pop     esi
2335
        mov     byte [esi], '/'
2250
        mov     byte [esi], '/'
2336
        jnc     @f
2251
        jnc     @f
2337
.notfound0:
2252
.notfound0:
2338
        mov     eax, ERROR_FILE_NOT_FOUND
2253
        mov     eax, ERROR_FILE_NOT_FOUND
Line 2340... Line 2255...
2340
        mov     [esp+28], eax
2255
        mov     [esp+28], eax
2341
        call    fat_unlock
2256
        call    fat_unlock
2342
        popad
2257
        popad
2343
        xor     ebx, ebx
2258
        xor     ebx, ebx
2344
        ret
2259
        ret
-
 
2260
 
2345
@@:
2261
@@:
2346
        inc     esi
2262
        inc     esi
2347
.common0:
-
 
2348
        test    byte [edi+11], 0x10     ; must be directory
2263
        test    byte [edi+11], 0x10     ; must be directory
2349
        mov     eax, ERROR_ACCESS_DENIED
2264
        mov     eax, ERROR_ACCESS_DENIED
2350
        jz      .ret1
2265
        jz      .ret1
2351
        mov     edx, [edi+20-2]
2266
        mov     edx, [edi+20-2]
2352
        mov     dx, [edi+26]            ; ebp=cluster
2267
        mov     dx, [edi+26]            ; ebp=cluster
2353
        mov     eax, ERROR_FAT_TABLE
2268
        mov     eax, ERROR_FS_FAIL
2354
        cmp     edx, 2
2269
        cmp     edx, 2
2355
        jb      .ret1
2270
        jb      .ret1
2356
.pushnotroot:
2271
.pushnotroot:
2357
        push    edx
2272
        push    edx
2358
        push    fat_notroot_extend_dir
2273
        push    fat_notroot_extend_dir
Line 2364... Line 2279...
2364
        push    fat_notroot_first
2279
        push    fat_notroot_first
2365
        push    fat_notroot_next
2280
        push    fat_notroot_next
2366
.common1:
2281
.common1:
2367
        call    fat_find_lfn
2282
        call    fat_find_lfn
2368
        jc      .notfound
2283
        jc      .notfound
2369
; found
-
 
2370
        test    byte [edi+11], 10h
2284
        test    byte [edi+11], 10h
2371
        jz      .exists_file
2285
        jz      .exists_file
2372
; found directory; if we are creating directory, return OK,
2286
; found directory
2373
;                  if we are creating file, say "access denied"
-
 
2374
        add     esp, 36
2287
        add     esp, 36
2375
        call    fat_unlock
2288
        call    fat_unlock
2376
        popad
2289
        popad
2377
        test    al, al
2290
        test    al, al
2378
        mov     eax, ERROR_ACCESS_DENIED
2291
        mov     eax, ERROR_ACCESS_DENIED
2379
        jz      @f
2292
        jz      @f
2380
        mov     al, 0
2293
        mov     al, 0
2381
@@:
2294
@@:
2382
        xor     ebx, ebx
2295
        xor     ebx, ebx
2383
        ret
2296
        ret
-
 
2297
 
2384
.exists_file:
2298
.exists_file:
2385
; found file; if we are creating directory, return "access denied",
-
 
2386
;             if we are creating file, delete existing file and continue
-
 
2387
        cmp     byte [esp+36+28], 0
2299
        cmp     byte [esp+36+28], 0
2388
        jz      @f
2300
        jz      @f
2389
        add     esp, 36
2301
        add     esp, 36
2390
        call    fat_unlock
2302
        call    fat_unlock
2391
        popad
2303
        popad
2392
        mov     eax, ERROR_ACCESS_DENIED
2304
        mov     eax, ERROR_ACCESS_DENIED
2393
        xor     ebx, ebx
2305
        xor     ebx, ebx
2394
        ret
2306
        ret
2395
@@:
2307
 
2396
; delete FAT chain
2308
@@: ; delete FAT chain
2397
        push    edi
2309
        push    edi
2398
        xor     eax, eax
2310
        xor     eax, eax
2399
        mov     dword [edi+28], eax     ; zero size
2311
        mov     dword [edi+28], eax     ; zero size
2400
        xor     ecx, ecx
2312
        xor     ecx, ecx
2401
        mov     eax, [edi+20-2]
2313
        mov     eax, [edi+20-2]
Line 2413... Line 2325...
2413
        mov     eax, edx
2325
        mov     eax, edx
2414
        pop     edx
2326
        pop     edx
2415
        jc      .done1
2327
        jc      .done1
2416
        inc     ecx
2328
        inc     ecx
2417
        jmp     @b
2329
        jmp     @b
-
 
2330
 
2418
.done1:
2331
.short_name_found:
2419
        pop     edi
2332
        pop     ecx edi esi
2420
        call    get_time_for_file
2333
        call    fat_next_short_name
2421
        mov     [edi+22], ax
2334
        jnc     .test_short_name_loop
-
 
2335
.disk_full:
2422
        call    get_date_for_file
2336
        add     esp, 12+36
2423
        mov     [edi+24], ax
2337
        call    fat_unlock
2424
        mov     [edi+18], ax
2338
        popa
2425
        or      byte [edi+11], 20h      ; set 'archive' attribute
2339
        mov     eax, ERROR_DISK_FULL
2426
        jmp     .doit
2340
        xor     ebx, ebx
2427
.notfound:
2341
        ret
-
 
2342
 
2428
; file is not found; generate short name
2343
.notfound:  ; generate short name
2429
        call    fat_name_is_legal
2344
        call    fat_name_is_legal
2430
        jc      @f
2345
        jc      @f
2431
        add     esp, 36
2346
        add     esp, 36
2432
        call    fat_unlock
2347
        call    fat_unlock
2433
        popad
2348
        popad
2434
        mov     eax, ERROR_FILE_NOT_FOUND
2349
        mov     eax, ERROR_FILE_NOT_FOUND
2435
        xor     ebx, ebx
2350
        xor     ebx, ebx
2436
        ret
2351
        ret
-
 
2352
 
2437
@@:
2353
@@:
2438
        sub     esp, 12
2354
        sub     esp, 12
2439
        mov     edi, esp
2355
        mov     edi, esp
2440
        call    fat_gen_short_name
2356
        call    fat_gen_short_name
2441
.test_short_name_loop:
2357
.test_short_name_loop:
Line 2457... Line 2373...
2457
        jz      .short_name_found
2373
        jz      .short_name_found
2458
.test_short_name_cont:
2374
.test_short_name_cont:
2459
        lea     eax, [esp+12+12+8]
2375
        lea     eax, [esp+12+12+8]
2460
        call    dword [eax-8]
2376
        call    dword [eax-8]
2461
        jnc     .test_short_name_entry
2377
        jnc     .test_short_name_entry
2462
        jmp     .found
-
 
2463
.short_name_found:
-
 
2464
        pop     ecx edi esi
-
 
2465
        call    fat_next_short_name
-
 
2466
        jnc     .test_short_name_loop
-
 
2467
.disk_full:
-
 
2468
        add     esp, 12+36
-
 
2469
        call    fat_unlock
-
 
2470
        popa
-
 
2471
        mov     eax, ERROR_DISK_FULL
-
 
2472
        xor     ebx, ebx
-
 
2473
        ret
-
 
2474
.found:
2378
.found:
2475
        pop     ecx edi esi
2379
        pop     ecx edi esi
2476
; now find space in directory
2380
; now find space in directory
2477
; we need to save LFN <=> LFN is not equal to short name <=> generated name contains '~'
2381
; we need to save LFN <=> LFN is not equal to short name <=> generated name contains '~'
2478
        mov     al, '~'
2382
        mov     al, '~'
Line 2487... Line 2391...
2487
        cmp     byte [esi], 0
2391
        cmp     byte [esi], 0
2488
        jz      @f
2392
        jz      @f
2489
        inc     esi
2393
        inc     esi
2490
        inc     eax
2394
        inc     eax
2491
        jmp     @b
2395
        jmp     @b
-
 
2396
 
2492
@@:
2397
@@:
2493
        sub     esi, eax
2398
        sub     esi, eax
2494
        add     eax, 12+13
2399
        add     eax, 12+13
2495
        mov     ecx, 13
2400
        mov     ecx, 13
2496
        push    edx
2401
        push    edx
Line 2516... Line 2421...
2516
        call    fat_unlock
2421
        call    fat_unlock
2517
        popad
2422
        popad
2518
        mov     eax, ERROR_DEVICE
2423
        mov     eax, ERROR_DEVICE
2519
        xor     ebx, ebx
2424
        xor     ebx, ebx
2520
        ret
2425
        ret
-
 
2426
 
2521
.scan_dir:
2427
.scan_dir:
2522
        cmp     byte [edi], 0
2428
        cmp     byte [edi], 0
2523
        jz      .free
2429
        jz      .free
2524
        cmp     byte [edi], 0xE5
2430
        cmp     byte [edi], 0xE5
2525
        jz      .free
2431
        jz      .free
Line 2542... Line 2448...
2542
        call    fat_unlock
2448
        call    fat_unlock
2543
        popad
2449
        popad
2544
        mov     eax, ERROR_DISK_FULL
2450
        mov     eax, ERROR_DISK_FULL
2545
        xor     ebx, ebx
2451
        xor     ebx, ebx
2546
        ret
2452
        ret
-
 
2453
 
2547
.free:
2454
.free:
2548
        test    ecx, ecx
2455
        test    ecx, ecx
2549
        jnz     @f
2456
        jnz     @f
2550
        mov     [esp], edi
2457
        mov     [esp], edi
2551
        mov     ecx, [esp+12+8+12+8]
2458
        mov     ecx, [esp+12+8+12+8]
Line 2562... Line 2469...
2562
; If creating a directory, allocate one data cluster now and fail immediately
2469
; If creating a directory, allocate one data cluster now and fail immediately
2563
; if this is impossible. This prevents from creating an invalid directory entry
2470
; if this is impossible. This prevents from creating an invalid directory entry
2564
; on a full disk.
2471
; on a full disk.
2565
; yup, the argument is quite non-intuitive... but what should I do if
2472
; yup, the argument is quite non-intuitive... but what should I do if
2566
; the entire function uses such arguments? BTW, it refers to al from pushad,
2473
; the entire function uses such arguments? BTW, it refers to al from pushad,
2567
; which in turn is filled with 0 in fat_Rewrite and 1 in fat_CreateFolder.
2474
; which in turn is filled with 0 in fat_CreateFile and 1 in fat_CreateFolder.
2568
        cmp     byte [esp+8+12+8+12+36+28], 0
2475
        cmp     byte [esp+8+12+8+12+36+28], 0
2569
        jz      .no.preallocate.folder.data
2476
        jz      .no.preallocate.folder.data
2570
        call    get_free_FAT
2477
        call    get_free_FAT
2571
        jnc     @f
2478
        jnc     @f
2572
        add     esp, 8+12+8
2479
        add     esp, 8+12+8
2573
        jmp     .disk_full
2480
        jmp     .disk_full
-
 
2481
 
2574
@@:
2482
@@:
2575
        mov     [esp+8+12+8+12+36+20], eax ; store the cluster somewhere
2483
        mov     [esp+8+12+8+12+36+20], eax ; store the cluster somewhere
2576
.no.preallocate.folder.data:
2484
.no.preallocate.folder.data:    ; calculate name checksum
2577
; calculate name checksum
-
 
2578
        mov     esi, [esp+8+12]
2485
        mov     esi, [esp+8+12]
2579
        mov     ecx, 11
2486
        mov     ecx, 11
2580
        xor     eax, eax
2487
        xor     eax, eax
2581
@@:
2488
@@:
2582
        ror     al, 1
2489
        ror     al, 1
Line 2620... Line 2527...
2620
        call    dword [eax+12]         ; next write
2527
        call    dword [eax+12]         ; next write
2621
        xor     eax, eax
2528
        xor     eax, eax
2622
        loop    .writelfn
2529
        loop    .writelfn
2623
        pop     eax
2530
        pop     eax
2624
        pop     esi
2531
        pop     esi
2625
;        lea     eax, [esp+8+12+8]
-
 
2626
;        call    dword [eax+16]          ; end write
-
 
2627
.nolfn:
2532
.nolfn:
2628
        xchg    esi, [esp]
2533
        xchg    esi, [esp]
2629
        mov     ecx, 11
2534
        mov     ecx, 11
2630
        rep movsb
2535
        rep movsb
2631
        mov     word [edi], 20h         ; attributes
2536
        mov     word [edi], 20h         ; attributes
Line 2657... Line 2562...
2657
        mov     ecx, [ebp+FAT.SECTORS_PER_CLUSTER]
2562
        mov     ecx, [ebp+FAT.SECTORS_PER_CLUSTER]
2658
        shl     ecx, 9
2563
        shl     ecx, 9
2659
        push    ecx
2564
        push    ecx
2660
        push    edi
2565
        push    edi
2661
        jmp     .doit2
2566
        jmp     .doit2
-
 
2567
 
-
 
2568
.done1:
-
 
2569
        pop     edi
-
 
2570
        call    get_time_for_file
-
 
2571
        mov     [edi+22], ax
-
 
2572
        call    get_date_for_file
-
 
2573
        mov     [edi+24], ax
-
 
2574
        mov     [edi+18], ax
-
 
2575
        or      byte [edi+11], 20h      ; set 'archive' attribute
2662
.doit:
2576
.doit:
2663
        mov     esi, [esp+36+20]
2577
        mov     esi, [esp+36+20]
2664
        lea     eax, [esp+8]
2578
        lea     eax, [esp+8]
2665
        call    dword [eax+16]  ; flush directory
2579
        call    dword [eax+16]  ; flush directory
2666
        push    ecx
2580
        push    ecx
Line 2688... Line 2602...
2688
        dec     eax
2602
        dec     eax
2689
        dec     eax
2603
        dec     eax
2690
        imul    eax, [ebp+FAT.SECTORS_PER_CLUSTER]
2604
        imul    eax, [ebp+FAT.SECTORS_PER_CLUSTER]
2691
        add     eax, [ebp+FAT.DATA_START]
2605
        add     eax, [ebp+FAT.DATA_START]
2692
        push    [ebp+FAT.SECTORS_PER_CLUSTER]
2606
        push    [ebp+FAT.SECTORS_PER_CLUSTER]
2693
; write data
-
 
2694
.write_sector:
2607
.write_sector:
2695
        cmp     byte [esp+20+36+28], 0
2608
        cmp     byte [esp+20+36+28], 0
2696
        jnz     .writedir
2609
        jnz     .writedir
2697
        mov     ecx, 512
2610
        mov     ecx, 512
2698
        cmp     dword [esp+12], ecx
2611
        cmp     dword [esp+12], ecx
2699
        jb      .writeshort
2612
        jb      .writeshort
2700
; we can write directly from given buffer
2613
; we can write directly from given buffer
2701
        mov     ebx, esi
2614
        mov     ebx, esi
2702
        add     esi, ecx
2615
        add     esi, ecx
2703
        jmp     .writecommon
2616
        jmp     .writecommon
-
 
2617
 
2704
.writeshort:
2618
.writeshort:
2705
        mov     ecx, [esp+12]
2619
        mov     ecx, [esp+12]
2706
        push    ecx
2620
        push    ecx
2707
        lea     edi, [ebp+FAT.buffer]
2621
        lea     edi, [ebp+FAT.buffer]
2708
        mov     ebx, edi
2622
        mov     ebx, edi
Line 2739... Line 2653...
2739
        mov     edx, ecx
2653
        mov     edx, ecx
2740
        call    set_FAT
2654
        call    set_FAT
2741
        pop     edx
2655
        pop     edx
2742
        xchg    eax, ecx
2656
        xchg    eax, ecx
2743
        jmp     .write_cluster
2657
        jmp     .write_cluster
-
 
2658
 
2744
.diskfull:
2659
.diskfull:
2745
        mov     eax, ERROR_DISK_FULL
2660
        mov     eax, ERROR_DISK_FULL
2746
        jmp     .ret
2661
        jmp     .ret
-
 
2662
 
2747
.writeerr:
2663
.writeerr:
2748
        pop     eax eax
2664
        pop     eax eax
2749
        sub     esi, ecx
2665
        sub     esi, ecx
2750
        mov     eax, ERROR_DEVICE
2666
        mov     eax, ERROR_DEVICE
2751
        jmp     .ret
2667
        jmp     .ret
-
 
2668
 
2752
.writedone:
2669
.writedone:
2753
        pop     eax eax
2670
        pop     eax eax
2754
.done:
2671
.done:
2755
        xor     eax, eax
2672
        xor     eax, eax
2756
.ret:
2673
.ret:
Line 2775... Line 2692...
2775
        add     esp, 36
2692
        add     esp, 36
2776
        call    update_disk
2693
        call    update_disk
2777
        call    fat_unlock
2694
        call    fat_unlock
2778
        popad
2695
        popad
2779
        ret
2696
        ret
-
 
2697
 
2780
.writedir:
2698
.writedir:
2781
        push    512
2699
        push    512
2782
        lea     edi, [ebp+FAT.buffer]
2700
        lea     edi, [ebp+FAT.buffer]
2783
        mov     ebx, edi
2701
        mov     ebx, edi
2784
        mov     ecx, [ebp+FAT.SECTORS_PER_CLUSTER]
2702
        mov     ecx, [ebp+FAT.SECTORS_PER_CLUSTER]
Line 2828... Line 2746...
2828
        call    fat_read_symbol
2746
        call    fat_read_symbol
2829
        stosw
2747
        stosw
2830
        loop    fat_read_symbols
2748
        loop    fat_read_symbols
2831
        ret
2749
        ret
Line 2832... Line -...
2832
 
-
 
2833
 
-
 
2834
fat_Write.access_denied:
-
 
2835
        push    ERROR_ACCESS_DENIED
-
 
2836
fat_Write.ret0:
-
 
2837
        pop     eax
-
 
2838
        xor     ebx, ebx
-
 
2839
        ret
-
 
2840
 
-
 
2841
fat_Write.ret11:
-
 
2842
        push    ERROR_DEVICE
-
 
2843
        jmp     fat_Write.ret0
-
 
2844
 
-
 
2845
;----------------------------------------------------------------
-
 
2846
; fat_Write - FAT implementation of writing to file
-
 
2847
; in:  ebp = pointer to FAT structure
-
 
2848
; in:  esi+[esp+4] = name
-
 
2849
; in:  ebx = pointer to parameters from sysfunc 70
-
 
2850
; out: eax, ebx = return values for sysfunc 70
2750
 
2851
;----------------------------------------------------------------
2751
;----------------------------------------------------------------
2852
fat_Write:
2752
fat_Write:
2853
        cmp     byte [esi], 0
2753
        cmp     byte [esi], 0
2854
        jz      .access_denied
2754
        jz      .access_denied
2855
        call    fat_lock
2755
        call    fat_lock
2856
        push    edi
2756
        push    edi
2857
        stdcall hd_find_lfn, [esp+4+4]
2757
        call    hd_find_lfn
2858
        jnc     .found
2758
        jnc     .found
2859
        pop     edi
2759
        pop     edi
2860
        push    eax
2760
        push    eax
-
 
2761
        call    fat_unlock
-
 
2762
.ret0:
-
 
2763
        pop     eax
-
 
2764
        xor     ebx, ebx
-
 
2765
        ret
-
 
2766
 
-
 
2767
.access_denied:
2861
        call    fat_unlock
2768
        push    ERROR_ACCESS_DENIED
2862
        jmp     .ret0
2769
        jmp     .ret0
2863
.found:
2770
 
2864
; FAT does not support files larger than 4GB
2771
.found:     ; FAT does not support files larger than 4GB
2865
        cmp     dword [ebx+8], 0
2772
        cmp     dword [ebx+8], 0
2866
        jz      @f
2773
        jz      @f
2867
.eof:
2774
.eof:
2868
        pop     edi
2775
        pop     edi
Line 2873... Line 2780...
2873
        mov     ecx, [ebx+12]
2780
        mov     ecx, [ebx+12]
2874
        mov     edx, [ebx+16]
2781
        mov     edx, [ebx+16]
2875
        mov     ebx, [ebx+4]
2782
        mov     ebx, [ebx+4]
2876
; now edi points to direntry, ebx=start byte to write,
2783
; now edi points to direntry, ebx=start byte to write,
2877
; ecx=number of bytes to write, edx=data pointer
2784
; ecx=number of bytes to write, edx=data pointer
2878
 
-
 
2879
; extend file if needed
2785
; extend file if needed
2880
        add     ecx, ebx
2786
        add     ecx, ebx
2881
        jc      .eof    ; FAT does not support files larger than 4GB
2787
        jc      .eof    ; FAT does not support files larger than 4GB
2882
        push    edx
2788
        push    edx
2883
        push    eax     ; save directory sector
2789
        push    eax     ; save directory sector
2884
        push    0       ; return value=0
2790
        push    0       ; return value=0
2885
 
-
 
2886
        call    get_time_for_file
2791
        call    get_time_for_file
2887
        mov     [edi+22], ax            ; last write time
2792
        mov     [edi+22], ax            ; last write time
2888
        call    get_date_for_file
2793
        call    get_date_for_file
2889
        mov     [edi+24], ax            ; last write date
2794
        mov     [edi+24], ax            ; last write date
2890
        mov     [edi+18], ax            ; last access date
2795
        mov     [edi+18], ax            ; last access date
2891
 
-
 
2892
        push    dword [edi+28]          ; save current file size
2796
        push    dword [edi+28]          ; save current file size
2893
        cmp     ecx, [edi+28]
2797
        cmp     ecx, [edi+28]
2894
        jbe     .length_ok
2798
        jbe     .length_ok
2895
        cmp     ecx, ebx
2799
        cmp     ecx, ebx
2896
        jz      .length_ok
2800
        jz      .length_ok
Line 2947... Line 2851...
2947
        jz      @f
2851
        jz      @f
2948
.device_err:
2852
.device_err:
2949
        mov     byte [esp+8], ERROR_DEVICE
2853
        mov     byte [esp+8], ERROR_DEVICE
2950
        jmp     .ret
2854
        jmp     .ret
2951
.fat_err:
2855
.fat_err:
2952
        mov     byte [esp+8], ERROR_FAT_TABLE
2856
        mov     byte [esp+8], ERROR_FS_FAIL
2953
        jmp     .ret
2857
        jmp     .ret
2954
@@:
2858
@@:
Line 2955... Line 2859...
2955
 
2859
 
2956
; now ebx=start pos, ecx=end pos, both lie inside file
2860
; now ebx=start pos, ecx=end pos, both lie inside file
Line 3072... Line 2976...
3072
        jmp     hd_extend_file.start_extend
2976
        jmp     hd_extend_file.start_extend
Line 3073... Line 2977...
3073
 
2977
 
3074
; extends file on hd to given size (new data area is undefined)
2978
; extends file on hd to given size (new data area is undefined)
3075
; in: edi->direntry, ecx=new size
2979
; in: edi->direntry, ecx=new size
3076
; out: CF=0 => OK, eax=0
2980
; out: CF=0 => OK, eax=0
3077
;      CF=1 => error, eax=code (ERROR_FAT_TABLE or ERROR_DISK_FULL or ERROR_DEVICE)
2981
;      CF=1 => error, eax=code (ERROR_FS_FAIL or ERROR_DISK_FULL or ERROR_DEVICE)
3078
hd_extend_file:
2982
hd_extend_file:
3079
        push    esi
2983
        push    esi
3080
        mov     esi, [ebp+FAT.SECTORS_PER_CLUSTER]
2984
        mov     esi, [ebp+FAT.SECTORS_PER_CLUSTER]
3081
        imul    esi, [ebp+FAT.BYTES_PER_SECTOR]
2985
        imul    esi, [ebp+FAT.BYTES_PER_SECTOR]
Line 3104... Line 3008...
3104
        jb      .fat_err
3008
        jb      .fat_err
3105
        cmp     eax, [ebp+FAT.fatRESERVED]
3009
        cmp     eax, [ebp+FAT.fatRESERVED]
3106
        jb      .last_loop
3010
        jb      .last_loop
3107
.fat_err:
3011
.fat_err:
3108
        pop     ecx esi
3012
        pop     ecx esi
3109
        push    ERROR_FAT_TABLE
3013
        push    ERROR_FS_FAIL
3110
        jmp     .ret_err
3014
        jmp     .ret_err
3111
.last_found:
3015
.last_found:
3112
        push    eax
3016
        push    eax
3113
        call    get_FAT
3017
        call    get_FAT
3114
        jnc     @f
3018
        jnc     @f
Line 3175... Line 3079...
3175
        call    get_date_for_file
3079
        call    get_date_for_file
3176
        mov     [edi+24], ax            ; last write date
3080
        mov     [edi+24], ax            ; last write date
3177
        mov     [edi+18], ax            ; last access date
3081
        mov     [edi+18], ax            ; last access date
3178
        ret
3082
        ret
Line 3179... Line -...
3179
 
-
 
3180
 
-
 
3181
;----------------------------------------------------------------
-
 
3182
; fat_SetFileEnd - FAT implementation of setting end-of-file
-
 
3183
; in:  ebp = pointer to FAT structure
-
 
3184
; in:  esi+[esp+4] = name
-
 
3185
; in:  ebx = pointer to parameters from sysfunc 70
-
 
3186
; out: eax, ebx = return values for sysfunc 70
3083
 
3187
;----------------------------------------------------------------
3084
;----------------------------------------------------------------
3188
fat_SetFileEnd:
3085
fat_SetFileEnd:
3189
        call    fat_lock
3086
        call    fat_lock
3190
        push    edi
3087
        push    edi
Line 3196... Line 3093...
3196
        call    fat_unlock
3093
        call    fat_unlock
3197
        pop     eax
3094
        pop     eax
3198
        pop     edi
3095
        pop     edi
3199
        ret
3096
        ret
3200
@@:
3097
@@:
3201
        stdcall hd_find_lfn, [esp+4+4]
3098
        call    hd_find_lfn
3202
        jnc     @f
3099
        jnc     @f
3203
.reteax:
3100
.reteax:
3204
        push    eax
3101
        push    eax
3205
        jmp     .ret
3102
        jmp     .ret
3206
@@:
3103
@@:
Line 3407... Line 3304...
3407
        call    fat_unlock
3304
        call    fat_unlock
3408
        xor     eax, eax
3305
        xor     eax, eax
3409
        ret
3306
        ret
3410
.error_fat:
3307
.error_fat:
3411
        pop     eax
3308
        pop     eax
3412
        mov     byte [esp], ERROR_FAT_TABLE
3309
        mov     byte [esp], ERROR_FS_FAIL
3413
        jmp     .pop_ret
3310
        jmp     .pop_ret
3414
.error_fat2:
3311
.error_fat2:
3415
        pop     eax ecx eax edi
3312
        pop     eax ecx eax edi
3416
        call    update_disk
3313
        call    update_disk
3417
        call    fat_unlock
3314
        call    fat_unlock
3418
        movi    eax, ERROR_FAT_TABLE
3315
        movi    eax, ERROR_FS_FAIL
3419
        ret
3316
        ret
Line 3420... Line 3317...
3420
 
3317
 
3421
;----------------------------------------------------------------
-
 
3422
; fat_GetFileInfo - FAT implementation of getting file info
-
 
3423
; in:  ebp = pointer to FAT structure
-
 
3424
; in:  esi+[esp+4] = name
-
 
3425
; in:  ebx = pointer to parameters from sysfunc 70
-
 
3426
; out: eax, ebx = return values for sysfunc 70
-
 
3427
;----------------------------------------------------------------
3318
;----------------------------------------------------------------
3428
fat_GetFileInfo:
3319
fat_GetFileInfo:
3429
        cmp     byte [esi], 0
3320
        cmp     byte [esi], 0
3430
        jnz     @f
3321
        jnz     @f
3431
        mov     eax, 2
3322
        mov     eax, 2
3432
        ret
3323
        ret
3433
@@:
3324
@@:
3434
        push    edi
3325
        push    edi
3435
        call    fat_lock
3326
        call    fat_lock
3436
        stdcall hd_find_lfn, [esp+4+4]
3327
        call    hd_find_lfn
3437
        jc      .error
3328
        jc      .error
3438
        push    ebp
3329
        push    ebp
3439
        xor     ebp, ebp
3330
        xor     ebp, ebp
3440
        mov     esi, [ebx+16]
3331
        mov     esi, [ebx+16]
Line 3451... Line 3342...
3451
        pop     eax
3342
        pop     eax
3452
        pop     edi
3343
        pop     edi
3453
        ret
3344
        ret
Line 3454... Line 3345...
3454
 
3345
 
3455
;----------------------------------------------------------------
-
 
3456
; fat_SetFileInfo - FAT implementation of setting file info
-
 
3457
; in:  ebp = pointer to FAT structure
-
 
3458
; in:  esi+[esp+4] = name
-
 
3459
; in:  ebx = pointer to parameters from sysfunc 70
-
 
3460
; out: eax, ebx = return values for sysfunc 70
-
 
3461
;----------------------------------------------------------------
3346
;----------------------------------------------------------------
3462
fat_SetFileInfo:
3347
fat_SetFileInfo:
3463
        cmp     byte [esi], 0
3348
        cmp     byte [esi], 0
3464
        jnz     @f
3349
        jnz     @f
3465
        mov     eax, 2
3350
        mov     eax, 2
3466
        ret
3351
        ret
3467
@@:
3352
@@:
3468
        push    edi
3353
        push    edi
3469
        call    fat_lock
3354
        call    fat_lock
3470
        stdcall hd_find_lfn, [esp+4+4]
3355
        call    hd_find_lfn
3471
        jc      .error
3356
        jc      .error
3472
        push    eax
3357
        push    eax
3473
        mov     edx, [ebx+16]
3358
        mov     edx, [ebx+16]
3474
        call    bdfe_to_fat_entry
3359
        call    bdfe_to_fat_entry
Line 3486... Line 3371...
3486
        pop     eax
3371
        pop     eax
3487
        pop     edi
3372
        pop     edi
3488
        ret
3373
        ret
Line 3489... Line 3374...
3489
 
3374
 
3490
;----------------------------------------------------------------
-
 
3491
; fat_Delete - FAT implementation of deleting a file/folder
-
 
3492
; in:  ebp = pointer to FAT structure
-
 
3493
; in:  esi+[esp+4] = name
-
 
3494
; in:  ebx = pointer to parameters from sysfunc 70
-
 
3495
; out: eax, ebx = return values for sysfunc 70
-
 
3496
;----------------------------------------------------------------
3375
;----------------------------------------------------------------
3497
fat_Delete:
3376
fat_Delete:
3498
        call    fat_lock
3377
        call    fat_lock
3499
        cmp     byte [esi], 0
3378
        cmp     byte [esi], 0
3500
        jnz     @f
3379
        jnz     @f
Line 3508... Line 3387...
3508
        ret
3387
        ret
3509
@@:
3388
@@:
3510
        and     [ebp+FAT.longname_sec1], 0
3389
        and     [ebp+FAT.longname_sec1], 0
3511
        and     [ebp+FAT.longname_sec2], 0
3390
        and     [ebp+FAT.longname_sec2], 0
3512
        push    edi
3391
        push    edi
3513
        stdcall hd_find_lfn, [esp+4+4]
3392
        call    hd_find_lfn
3514
        jnc     .found
3393
        jnc     .found
3515
        pop     edi
3394
        pop     edi
3516
        push    ERROR_FILE_NOT_FOUND
3395
        push    ERROR_FILE_NOT_FOUND
3517
        jmp     .pop_ret
3396
        jmp     .pop_ret
3518
.found:
3397
.found:
Line 3575... Line 3454...
3575
        ret
3454
        ret
3576
.error_fat:
3455
.error_fat:
3577
        popad
3456
        popad
3578
        pop     edi
3457
        pop     edi
3579
        call    fat_unlock
3458
        call    fat_unlock
3580
        movi    eax, ERROR_FAT_TABLE
3459
        movi    eax, ERROR_FS_FAIL
3581
        ret
3460
        ret
3582
.notempty:
3461
.notempty:
3583
        popad
3462
        popad
3584
.access_denied2:
3463
.access_denied2:
3585
        pop     edi
3464
        pop     edi