Rev 115 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 115 | Rev 131 | ||
---|---|---|---|
Line 1263... | Line 1263... | ||
1263 | pop edi esi |
1263 | pop edi esi |
1264 | stc |
1264 | stc |
1265 | ret |
1265 | ret |
1266 | .found: |
1266 | .found: |
1267 | mov eax, [esp+8] |
1267 | mov eax, [esp+8] |
- | 1268 | add eax, 31 |
|
- | 1269 | cmp dword [esp], flp_root_next |
|
- | 1270 | jnz @f |
|
- | 1271 | add eax, -31+19 |
|
- | 1272 | @@: |
|
1268 | add esp, 16 ; CF=0 |
1273 | add esp, 16 ; CF=0 |
1269 | pop esi |
1274 | pop esi |
1270 | ret |
1275 | ret |
Line 1271... | Line 1276... | ||
1271 | 1276 | ||
Line 1913... | Line 1918... | ||
1913 | sub esi, ecx |
1918 | sub esi, ecx |
1914 | mov eax, 11 |
1919 | mov eax, 11 |
1915 | pop edi ecx |
1920 | pop edi ecx |
1916 | jmp .ret |
1921 | jmp .ret |
Line -... | Line 1922... | ||
- | 1922 | ||
- | 1923 | ;---------------------------------------------------------------- |
|
- | 1924 | ; |
|
- | 1925 | ; fs_FloppyWrite - LFN variant for writing to floppy |
|
- | 1926 | ; |
|
- | 1927 | ; esi points to filename |
|
- | 1928 | ; ebx pointer to 64-bit number = first wanted byte, 0+ |
|
- | 1929 | ; may be ebx=0 - start from first byte |
|
- | 1930 | ; ecx number of bytes to write, 0+ |
|
- | 1931 | ; edx mem location to data |
|
- | 1932 | ; |
|
- | 1933 | ; ret ebx = bytes written (maybe 0) |
|
- | 1934 | ; eax = 0 ok write or other = errormsg |
|
- | 1935 | ; |
|
- | 1936 | ;-------------------------------------------------------------- |
|
- | 1937 | ||
- | 1938 | @@: |
|
- | 1939 | push ERROR_ACCESS_DENIED |
|
- | 1940 | fs_FloppyWrite.ret0: |
|
- | 1941 | pop eax |
|
- | 1942 | xor ebx, ebx |
|
- | 1943 | ret |
|
- | 1944 | ||
- | 1945 | fs_FloppyWrite.ret11: |
|
- | 1946 | push 11 |
|
- | 1947 | jmp fs_FloppyWrite.ret0 |
|
- | 1948 | ||
- | 1949 | fs_FloppyWrite: |
|
- | 1950 | cmp byte [esi], 0 |
|
- | 1951 | jz @b |
|
- | 1952 | call read_flp_fat |
|
- | 1953 | cmp [FDC_Status], 0 |
|
- | 1954 | jnz .ret11 |
|
- | 1955 | pushad |
|
- | 1956 | call fd_find_lfn |
|
- | 1957 | jnc .found |
|
- | 1958 | popad |
|
- | 1959 | push ERROR_FILE_NOT_FOUND |
|
- | 1960 | jmp .ret0 |
|
- | 1961 | .found: |
|
- | 1962 | ; FAT does not support files larger than 4GB |
|
- | 1963 | test ebx, ebx |
|
- | 1964 | jz .l1 |
|
- | 1965 | cmp dword [ebx+4], 0 |
|
- | 1966 | jz @f |
|
- | 1967 | .eof: |
|
- | 1968 | popad |
|
- | 1969 | push ERROR_END_OF_FILE |
|
- | 1970 | jmp .ret0 |
|
- | 1971 | @@: |
|
- | 1972 | mov ebx, [ebx] |
|
- | 1973 | .l1: |
|
- | 1974 | ; now edi points to direntry, ebx=start byte to write, |
|
- | 1975 | ; ecx=number of bytes to write, edx=data pointer |
|
- | 1976 | ||
- | 1977 | ; extend file if needed |
|
- | 1978 | add ecx, ebx |
|
- | 1979 | jc .eof ; FAT does not support files larger than 4GB |
|
- | 1980 | push eax ; save directory cluster |
|
- | 1981 | push 0 ; return value=0 |
|
- | 1982 | ||
- | 1983 | call get_time_for_file |
|
- | 1984 | mov [edi+22], ax ; last write time |
|
- | 1985 | call get_date_for_file |
|
- | 1986 | mov [edi+24], ax ; last write date |
|
- | 1987 | mov [edi+18], ax ; last access date |
|
- | 1988 | ||
- | 1989 | push dword [edi+28] ; save current file size |
|
- | 1990 | cmp ecx, [edi+28] |
|
- | 1991 | jbe .length_ok |
|
- | 1992 | cmp ecx, ebx |
|
- | 1993 | jz .length_ok |
|
- | 1994 | call floppy_extend_file |
|
- | 1995 | jnc .length_ok |
|
- | 1996 | mov [esp+4], eax |
|
- | 1997 | ; floppy_extend_file can return two error codes: FAT table error or disk full. |
|
- | 1998 | ; First case is fatal error, in second case we may write some data |
|
- | 1999 | cmp al, ERROR_DISK_FULL |
|
- | 2000 | jz .disk_full |
|
- | 2001 | pop eax |
|
- | 2002 | pop eax |
|
- | 2003 | mov [esp+4+28], eax |
|
- | 2004 | pop eax |
|
- | 2005 | popad |
|
- | 2006 | xor ebx, ebx |
|
- | 2007 | ret |
|
- | 2008 | .disk_full: |
|
- | 2009 | ; correct number of bytes to write |
|
- | 2010 | mov ecx, [edi+28] |
|
- | 2011 | cmp ecx, ebx |
|
- | 2012 | ja .length_ok |
|
- | 2013 | .ret: |
|
- | 2014 | pop eax |
|
- | 2015 | pop eax |
|
- | 2016 | mov [esp+4+28], eax ; eax=return value |
|
- | 2017 | pop eax |
|
- | 2018 | sub edx, [esp+20] |
|
- | 2019 | mov [esp+16], edx ; ebx=number of written bytes |
|
- | 2020 | popad |
|
- | 2021 | ret |
|
- | 2022 | .length_ok: |
|
- | 2023 | ; save FAT & directory |
|
- | 2024 | ; note that directory must be saved first because save_flp_fat uses buffer at 0xD000 |
|
- | 2025 | mov esi, [edi+28] |
|
- | 2026 | movzx edi, word [edi+26] ; starting cluster |
|
- | 2027 | mov eax, [esp+8] |
|
- | 2028 | pusha |
|
- | 2029 | call save_chs_sector |
|
- | 2030 | popa |
|
- | 2031 | cmp [FDC_Status], 0 |
|
- | 2032 | jnz .device_err |
|
- | 2033 | call save_flp_fat |
|
- | 2034 | cmp [FDC_Status], 0 |
|
- | 2035 | jz @f |
|
- | 2036 | .device_err: |
|
- | 2037 | mov byte [esp+4], 11 |
|
- | 2038 | jmp .ret |
|
- | 2039 | @@: |
|
- | 2040 | ||
- | 2041 | ; now ebx=start pos, ecx=end pos, both lie inside file |
|
- | 2042 | sub ecx, ebx |
|
- | 2043 | jz .ret |
|
- | 2044 | call SetUserInterrupts |
|
- | 2045 | .write_loop: |
|
- | 2046 | lea eax, [edi+31] ; current sector |
|
- | 2047 | ; get length of data in current sector |
|
- | 2048 | push ecx |
|
- | 2049 | sub ebx, 0x200 |
|
- | 2050 | jb .hasdata |
|
- | 2051 | neg ebx |
|
- | 2052 | xor ecx, ecx |
|
- | 2053 | jmp @f |
|
- | 2054 | .hasdata: |
|
- | 2055 | neg ebx |
|
- | 2056 | cmp ecx, ebx |
|
- | 2057 | jbe @f |
|
- | 2058 | mov ecx, ebx |
|
- | 2059 | @@: |
|
- | 2060 | ; load sector if needed |
|
- | 2061 | cmp dword [esp+4], 0 ; we don't need to read uninitialized data |
|
- | 2062 | jz .noread |
|
- | 2063 | cmp ecx, 0x200 ; we don't need to read sector if it is fully rewritten |
|
- | 2064 | jz .noread |
|
- | 2065 | cmp ecx, esi ; (same for the last sector) |
|
- | 2066 | jz .noread |
|
- | 2067 | pusha |
|
- | 2068 | call read_chs_sector |
|
- | 2069 | popa |
|
- | 2070 | cmp [FDC_Status], 0 |
|
- | 2071 | jz @f |
|
- | 2072 | .device_err2: |
|
- | 2073 | pop ecx |
|
- | 2074 | jmp .device_err |
|
- | 2075 | @@: |
|
- | 2076 | .noread: |
|
- | 2077 | ; zero uninitialized data if file was extended (because floppy_extend_file does not this) |
|
- | 2078 | push eax ecx edi |
|
- | 2079 | xor eax, eax |
|
- | 2080 | mov ecx, 0x200 |
|
- | 2081 | sub ecx, [esp+4+12] |
|
- | 2082 | jbe @f |
|
- | 2083 | mov edi, 0xD000 |
|
- | 2084 | add edi, [esp+4+12] |
|
- | 2085 | rep stosb |
|
- | 2086 | @@: |
|
- | 2087 | ; zero uninitialized data in the last sector |
|
- | 2088 | mov ecx, 0x200 |
|
- | 2089 | sub ecx, esi |
|
- | 2090 | jbe @f |
|
- | 2091 | mov edi, 0xD000 |
|
- | 2092 | add edi, esi |
|
- | 2093 | rep stosb |
|
- | 2094 | @@: |
|
- | 2095 | pop edi ecx eax |
|
- | 2096 | ; copy new data |
|
- | 2097 | push eax |
|
- | 2098 | mov eax, edx |
|
- | 2099 | neg ebx |
|
- | 2100 | jecxz @f |
|
- | 2101 | add ebx, 0xD000+0x200 |
|
- | 2102 | call memmove |
|
- | 2103 | xor ebx, ebx |
|
- | 2104 | @@: |
|
- | 2105 | pop eax |
|
- | 2106 | ; save sector |
|
- | 2107 | pusha |
|
- | 2108 | call save_chs_sector |
|
- | 2109 | popa |
|
- | 2110 | cmp [FDC_Status], 0 |
|
- | 2111 | jnz .device_err2 |
|
- | 2112 | add edx, ecx |
|
- | 2113 | sub [esp], ecx |
|
- | 2114 | pop ecx |
|
- | 2115 | jz .done |
|
- | 2116 | .next_cluster: |
|
- | 2117 | movzx edi, word [edi*2+0x282000] |
|
- | 2118 | sub esi, 0x200 |
|
- | 2119 | jae @f |
|
- | 2120 | xor esi, esi |
|
- | 2121 | @@: |
|
- | 2122 | sub dword [esp], 0x200 |
|
- | 2123 | jae .write_loop |
|
- | 2124 | and dword [esp], 0 |
|
- | 2125 | jmp .write_loop |
|
- | 2126 | .done: |
|
- | 2127 | mov [fdc_irq_func], fdc_null |
|
- | 2128 | jmp .ret |
|
- | 2129 | ||
- | 2130 | floppy_extend_file.zero_size: |
|
- | 2131 | xor eax, eax |
|
- | 2132 | jmp floppy_extend_file.start_extend |
|
- | 2133 | ||
- | 2134 | ; extends file on floppy to given size (new data area is undefined) |
|
- | 2135 | ; in: edi->direntry, ecx=new size |
|
- | 2136 | ; out: CF=0 => OK, eax destroyed |
|
- | 2137 | ; CF=1 => error, eax=code (ERROR_FAT_TABLE or ERROR_DISK_FULL) |
|
- | 2138 | floppy_extend_file: |
|
- | 2139 | push ecx |
|
- | 2140 | ; find the last cluster of file |
|
- | 2141 | movzx eax, word [edi+26] ; first cluster |
|
- | 2142 | mov ecx, [edi+28] |
|
- | 2143 | jecxz .zero_size |
|
- | 2144 | @@: |
|
- | 2145 | sub ecx, 0x200 |
|
- | 2146 | jbe @f |
|
- | 2147 | mov eax, [eax*2+0x282000] |
|
- | 2148 | and eax, 0xFFF |
|
- | 2149 | jz .fat_err |
|
- | 2150 | cmp eax, 0xFF8 |
|
- | 2151 | jb @b |
|
- | 2152 | .fat_err: |
|
- | 2153 | pop ecx |
|
- | 2154 | push ERROR_FAT_TABLE |
|
- | 2155 | pop eax |
|
- | 2156 | stc |
|
- | 2157 | ret |
|
- | 2158 | @@: |
|
- | 2159 | push eax |
|
- | 2160 | mov eax, [eax*2+0x282000] |
|
- | 2161 | and eax, 0xFFF |
|
- | 2162 | cmp eax, 0xFF8 |
|
- | 2163 | pop eax |
|
- | 2164 | jb .fat_err |
|
- | 2165 | ; set length to full number of sectors |
|
- | 2166 | sub [edi+28], ecx |
|
- | 2167 | .start_extend: |
|
- | 2168 | pop ecx |
|
- | 2169 | ; now do extend |
|
- | 2170 | push edx esi |
|
- | 2171 | mov esi, 0x282000+2*2 ; start scan from cluster 2 |
|
- | 2172 | mov edx, 2847 ; number of clusters to scan |
|
- | 2173 | .extend_loop: |
|
- | 2174 | cmp [edi+28], ecx |
|
- | 2175 | jae .extend_done |
|
- | 2176 | ; add new sector |
|
- | 2177 | push ecx |
|
- | 2178 | push edi |
|
- | 2179 | .scan: |
|
- | 2180 | mov ecx, edx |
|
- | 2181 | mov edi, esi |
|
- | 2182 | jecxz .disk_full |
|
- | 2183 | push eax |
|
- | 2184 | xor eax, eax |
|
- | 2185 | repnz scasw |
|
- | 2186 | pop eax |
|
- | 2187 | jnz .disk_full |
|
- | 2188 | mov word [edi-2], 0xFFF |
|
- | 2189 | mov esi, edi |
|
- | 2190 | mov edx, ecx |
|
- | 2191 | sub edi, 0x282000 |
|
- | 2192 | shr edi, 1 |
|
- | 2193 | dec edi ; now edi=new cluster |
|
- | 2194 | test eax, eax |
|
- | 2195 | jz .first_cluster |
|
- | 2196 | mov [0x282000+eax*2], di |
|
- | 2197 | jmp @f |
|
- | 2198 | .first_cluster: |
|
- | 2199 | pop eax ; eax->direntry |
|
- | 2200 | push eax |
|
- | 2201 | mov [eax+26], di |
|
- | 2202 | @@: |
|
- | 2203 | mov eax, edi ; eax=new cluster |
|
- | 2204 | pop edi ; edi->direntry |
|
- | 2205 | pop ecx ; ecx=required size |
|
- | 2206 | add dword [edi+28], 0x200 |
|
- | 2207 | jmp .extend_loop |
|
- | 2208 | .extend_done: |
|
- | 2209 | mov [edi+28], ecx |
|
- | 2210 | pop esi edx |
|
- | 2211 | clc |
|
- | 2212 | ret |
|
- | 2213 | .disk_full: |
|
- | 2214 | pop edi ecx |
|
- | 2215 | pop esi edx |
|
- | 2216 | stc |
|
- | 2217 | push ERROR_DISK_FULL |
|
- | 2218 | pop eax |
|
- | 2219 | ret |
|
1917 | 2220 | ||
1918 | fs_FloppyGetFileInfo: |
2221 | fs_FloppyGetFileInfo: |
1919 | call read_flp_fat |
2222 | call read_flp_fat |
1920 | cmp [FDC_Status], 0 |
2223 | cmp [FDC_Status], 0 |
1921 | jnz ret11 |
2224 | jnz ret11 |
Line 1949... | Line 2252... | ||
1949 | ret |
2252 | ret |
1950 | @@: |
2253 | @@: |
1951 | push eax |
2254 | push eax |
1952 | call bdfe_to_fat_entry |
2255 | call bdfe_to_fat_entry |
1953 | pop eax |
2256 | pop eax |
1954 | test eax, eax |
- | |
1955 | jz .root |
- | |
1956 | add eax, 31 |
- | |
1957 | pusha |
2257 | pusha |
1958 | call save_chs_sector |
2258 | call save_chs_sector |
1959 | popa |
2259 | popa |
1960 | jmp .cmn |
- | |
1961 | .root: |
- | |
1962 | call save_flp_root |
- | |
1963 | .cmn: |
- | |
1964 | pop edi |
2260 | pop edi |
1965 | xor eax, eax |
2261 | xor eax, eax |
1966 | cmp [FDC_Status], 0 |
2262 | cmp [FDC_Status], 0 |
1967 | jz @f |
2263 | jz @f |
1968 | mov al, 11 |
2264 | mov al, 11 |