Rev 5363 | Rev 5840 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5363 | Rev 5578 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
2 | ;; ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2015. All rights reserved. ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2015. 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 | ;; FAT32.INC ;; |
- | |
7 | ;; ;; |
- | |
8 | ;; FAT functions for KolibriOS ;; |
6 | ;; FAT functions for KolibriOS ;; |
9 | ;; ;; |
7 | ;; ;; |
10 | ;; Copyright 2002 Paolo Minazzi, paolo.minazzi@inwind.it ;; |
8 | ;; Copyright 2002 Paolo Minazzi, paolo.minazzi@inwind.it ;; |
11 | ;; ;; |
9 | ;; ;; |
12 | ;; See file COPYING for details ;; |
10 | ;; See file COPYING for details ;; |
- | 11 | ;; 06.2015 fs_read64 - pathoswithin ;; |
|
13 | ;; 04.02.2007 LFN create folder - diamond ;; |
12 | ;; 04.02.2007 LFN create folder - diamond ;; |
14 | ;; 08.10.2006 LFN delete file/folder - diamond ;; |
13 | ;; 08.10.2006 LFN delete file/folder - diamond ;; |
15 | ;; 20.08.2006 LFN set file size (truncate/extend) - diamond ;; |
14 | ;; 20.08.2006 LFN set file size (truncate/extend) - diamond ;; |
16 | ;; 17.08.2006 LFN write/append to file - diamond ;; |
15 | ;; 17.08.2006 LFN write/append to file - diamond ;; |
17 | ;; 23.06.2006 LFN start application - diamond ;; |
16 | ;; 23.06.2006 LFN start application - diamond ;; |
Line 32... | Line 31... | ||
32 | ;; 10.11.2004 removedir clear whole directory structure - ATV ;; |
31 | ;; 10.11.2004 removedir clear whole directory structure - ATV ;; |
33 | ;; 08.11.2004 rename - ATV ;; |
32 | ;; 08.11.2004 rename - ATV ;; |
34 | ;; 30.10.2004 file_read return also dirsize in bytes - ATV ;; |
33 | ;; 30.10.2004 file_read return also dirsize in bytes - ATV ;; |
35 | ;; 20.10.2004 Makedir/Removedir - ATV ;; |
34 | ;; 20.10.2004 Makedir/Removedir - ATV ;; |
36 | ;; 14.10.2004 Partition chain/Fat16 - ATV (thanks drh3xx) ;; |
35 | ;; 14.10.2004 Partition chain/Fat16 - ATV (thanks drh3xx) ;; |
37 | ;; 06.9.2004 Fix free space by Mario79 added - MH ;; |
36 | ;; 06.09.2004 Fix free space - Mario79 ;; |
38 | ;; 24.5.2004 Write back buffer for File_write -VT ;; |
37 | ;; 24.05.2004 Write back buffer for File_write - VT ;; |
39 | ;; 20.5.2004 File_read function to work with syscall 58 - VT ;; |
38 | ;; 20.05.2004 File_read function to work with syscall 58 - VT ;; |
40 | ;; 30.3.2004 Error parameters at function return - VT ;; |
39 | ;; 30.03.2004 Error parameters at function return - VT ;; |
41 | ;; 01.5.2002 Bugfix in device write - VT ;; |
40 | ;; 29.06.2002 Improved fat32 verification - VT ;; |
42 | ;; 20.5.2002 Hd status check - VT ;; |
41 | ;; 20.05.2002 Hd status check - VT ;; |
43 | ;; 29.6.2002 Improved fat32 verification - VT ;; |
42 | ;; 01.05.2002 Bugfix in device write - VT ;; |
44 | ;; ;; |
43 | ;; ;; |
45 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
44 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
46 | - | ||
47 | $Revision: 5363 $ |
- | |
Line -... | Line 45... | ||
- | 45 | ||
Line 48... | Line 46... | ||
48 | 46 | $Revision: 5578 $ |
|
Line 49... | Line 47... | ||
49 | 47 | ||
50 | cache_max equ 1919 ; max. is 1919*512+0x610000=0x6ffe00 |
48 | cache_max equ 1919 ; max. is 1919*512+0x610000=0x6ffe00 |
Line 60... | Line 58... | ||
60 | ; Internal data for every FAT partition. |
58 | ; Internal data for every FAT partition. |
61 | struct FAT PARTITION |
59 | struct FAT PARTITION |
62 | fs_type db ? |
60 | fs_type db ? |
63 | fat16_root db 0 ; flag for fat16 rootdir |
61 | fat16_root db 0 ; flag for fat16 rootdir |
64 | fat_change db 0 ; 1=fat has changed |
62 | fat_change db 0 ; 1=fat has changed |
65 | db ? ; alignment |
63 | rb 1 |
66 | Lock MUTEX ? ; currently operations with one partition |
64 | Lock MUTEX ? ; currently operations with one partition |
67 | ; can not be executed in parallel since the |
- | |
68 | ; legacy code is not ready; this mutex guards |
65 | ; can not be executed in parallel since the legacy code is not ready |
69 | ; all operations |
- | |
70 | SECTORS_PER_FAT dd 0x1f3a |
66 | SECTORS_PER_FAT dd 0x1f3a |
71 | NUMBER_OF_FATS dd 0x2 |
67 | NUMBER_OF_FATS dd 0x2 |
72 | SECTORS_PER_CLUSTER dd 0x8 |
68 | SECTORS_PER_CLUSTER dd 0x8 |
73 | BYTES_PER_SECTOR dd 0x200 ; Note: if BPS <> 512 need lots of changes |
69 | BYTES_PER_SECTOR dd 0x200 ; Note: if BPS <> 512 need lots of changes |
74 | ROOT_CLUSTER dd 2 ; first rootdir cluster |
70 | ROOT_CLUSTER dd 2 ; first rootdir cluster |
Line 83... | Line 79... | ||
83 | fatBAD dd 0x0FFFFFF7 |
79 | fatBAD dd 0x0FFFFFF7 |
84 | fatEND dd 0x0FFFFFF8 |
80 | fatEND dd 0x0FFFFFF8 |
85 | fatMASK dd 0x0FFFFFFF |
81 | fatMASK dd 0x0FFFFFFF |
Line 86... | Line 82... | ||
86 | 82 | ||
87 | fatStartScan dd 2 |
- | |
88 | 83 | fatStartScan dd 2 |
|
89 | cluster_tmp dd 0 ; used by analyze_directory |
84 | cluster_tmp dd 0 ; used by analyze_directory |
90 | ; and analyze_directory_to_write |
- | |
91 | 85 | ; and analyze_directory_to_write |
|
92 | longname_sec1 dd 0 ; used by analyze_directory to save 2 previous |
86 | longname_sec1 dd 0 ; used by analyze_directory to save 2 previous |
93 | longname_sec2 dd 0 ; directory sectors for delete long filename |
- | |
94 | 87 | longname_sec2 dd 0 ; directory sectors for delete long filename |
|
Line 95... | Line 88... | ||
95 | fat_in_cache dd -1 |
88 | fat_in_cache dd -1 |
96 | 89 | ||
97 | ; For FAT16/FAT32, this points to 512-byte buffer for the current sector of FAT. |
90 | ; For FAT16/FAT32, this points to 512-byte buffer for the current sector of FAT. |
98 | ; For FAT12, the entire FAT structure is read |
91 | ; For FAT12, the entire FAT structure is read |
99 | ; and unpacked from 12bit per cluster to word per cluster. |
92 | ; and unpacked from 12bit per cluster to word per cluster. |
100 | ; |
93 | |
101 | ; Note: work with unpacked copy of FAT12 means |
94 | ; Note: work with unpacked copy of FAT12 means |
102 | ; additional memory and additional code for packing/unpacking. |
95 | ; additional memory and additional code for packing/unpacking. |
103 | ; I'm not sure that the economy justifies the cost, but anyway, |
96 | ; I'm not sure that the economy justifies the cost, but anyway, |
Line 109... | Line 102... | ||
109 | ends |
102 | ends |
Line 110... | Line 103... | ||
110 | 103 | ||
111 | uglobal |
104 | uglobal |
112 | align 4 |
105 | align 4 |
113 | partition_count dd 0 ; partitions found by set_FAT32_variables |
- | |
114 | 106 | partition_count dd 0 ; partitions found by set_FAT32_variables |
|
115 | hd_error dd 0 ; set by wait_for_sector_buffer |
107 | hd_error dd 0 |
116 | hd_setup dd 0 |
108 | hd_setup dd 0 |
117 | hd_wait_timeout dd 0 |
- | |
118 | 109 | hd_wait_timeout dd 0 |
|
119 | cache_search_start dd 0 ; used by find_empty_slot |
110 | cache_search_start dd 0 ; used by find_empty_slot |
Line 120... | Line 111... | ||
120 | endg |
111 | endg |
121 | 112 | ||
122 | uglobal |
113 | uglobal |
123 | align 4 |
114 | align 4 |
124 | Sector512: ; label for dev_hdcd.inc |
115 | Sector512: ; label for dev_hdcd.inc |
125 | buffer: |
116 | buffer: |
Line 126... | Line 117... | ||
126 | times 512 db 0 |
117 | rb 512 |
127 | endg |
118 | endg |
128 | 119 | ||
Line 1786... | Line 1777... | ||
1786 | push edi |
1777 | push edi |
1787 | cmp byte [esi], 0 |
1778 | cmp byte [esi], 0 |
1788 | jnz @f |
1779 | jnz @f |
1789 | .noaccess: |
1780 | .noaccess: |
1790 | pop edi |
1781 | pop edi |
1791 | .noaccess_2: |
- | |
1792 | call fat_unlock |
1782 | call fat_unlock |
1793 | or ebx, -1 |
1783 | or ebx, -1 |
1794 | mov eax, ERROR_ACCESS_DENIED |
1784 | mov eax, ERROR_ACCESS_DENIED |
1795 | ret |
1785 | ret |
1796 | - | ||
1797 | @@: |
1786 | @@: |
1798 | stdcall hd_find_lfn, [esp+4+4] |
1787 | stdcall hd_find_lfn, [esp+8] |
1799 | jnc .found |
1788 | jnc .found |
1800 | pop edi |
1789 | pop edi |
1801 | push eax |
1790 | push eax |
1802 | call fat_unlock |
1791 | call fat_unlock |
1803 | pop eax |
1792 | pop eax |
1804 | or ebx, -1 |
1793 | or ebx, -1 |
1805 | ret |
1794 | ret |
1806 | - | ||
1807 | .found: |
1795 | .found: |
1808 | test byte [edi+11], 0x10; do not allow read directories |
1796 | test byte [edi+11], 0x10 ; do not allow read directories |
1809 | jnz .noaccess |
1797 | jnz .noaccess |
1810 | cmp dword [ebx+8], 0 |
1798 | cmp dword [ebx+8], 0 |
1811 | jz @f |
1799 | jz @f |
1812 | xor ebx, ebx |
1800 | xor ebx, ebx |
1813 | .reteof: |
- | |
1814 | call fat_unlock |
1801 | call fat_unlock |
1815 | mov eax, ERROR_END_OF_FILE |
1802 | mov eax, ERROR_END_OF_FILE |
1816 | pop edi |
1803 | pop edi |
1817 | ret |
1804 | ret |
1818 | @@: |
1805 | @@: |
- | 1806 | mov edx, [ebx+4] ; file offset |
|
1819 | mov ecx, [ebx+12] ; size |
1807 | mov ecx, [ebx+12] ; size |
1820 | mov edx, [ebx+16] ; pointer |
1808 | mov ebx, [ebx+16] ; buffer |
1821 | mov ebx, [ebx+4] ; file offset |
- | |
1822 | push edx |
1809 | push ebx |
1823 | push 0 |
1810 | push 0 |
1824 | mov eax, [edi+28] |
1811 | mov eax, [edi+28] |
1825 | sub eax, ebx |
1812 | sub eax, edx |
1826 | jb .eof |
1813 | jb .fileEnd |
1827 | cmp eax, ecx |
1814 | cmp eax, ecx |
1828 | jae @f |
1815 | jae @f |
1829 | mov ecx, eax |
1816 | mov ecx, eax |
1830 | mov byte [esp], 6 |
1817 | mov byte [esp], 6 |
1831 | @@: |
1818 | @@: |
1832 | mov eax, [edi+20-2] |
1819 | mov eax, [edi+20-2] |
1833 | mov ax, [edi+26] |
1820 | mov ax, [edi+26] |
1834 | ; now eax=cluster, ebx=position, ecx=count, edx=buffer for data |
1821 | ; now eax=cluster, ebx=buffer for data, ecx=count, edx=position |
1835 | .new_cluster: |
1822 | mov edi, [ebp+FAT.SECTORS_PER_CLUSTER] |
1836 | jecxz .new_sector |
1823 | shl edi, 9 |
- | 1824 | @@: |
|
1837 | cmp eax, 2 |
1825 | cmp eax, 2 |
1838 | jb .eof |
1826 | jb .fileEnd |
1839 | cmp eax, [ebp+FAT.fatRESERVED] |
1827 | cmp eax, [ebp+FAT.fatRESERVED] |
- | 1828 | jae .fileEnd |
|
- | 1829 | sub edx, edi |
|
1840 | jae .eof |
1830 | jc @f |
- | 1831 | call get_FAT |
|
- | 1832 | jc .noaccess2 |
|
- | 1833 | jmp @b |
|
- | 1834 | @@: |
|
1841 | mov [ebp+FAT.cluster_tmp], eax |
1835 | mov esi, eax |
1842 | dec eax |
1836 | dec eax |
1843 | dec eax |
1837 | dec eax |
1844 | mov edi, [ebp+FAT.SECTORS_PER_CLUSTER] |
1838 | imul eax, [ebp+FAT.SECTORS_PER_CLUSTER] |
1845 | imul eax, edi |
- | |
1846 | add eax, [ebp+FAT.DATA_START] |
1839 | add eax, [ebp+FAT.DATA_START] |
1847 | .new_sector: |
- | |
1848 | test ecx, ecx |
- | |
1849 | jz .done |
- | |
1850 | sub ebx, 512 |
- | |
1851 | jae .skip |
- | |
1852 | add ebx, 512 |
1840 | add edx, edi |
1853 | jnz .force_buf |
- | |
1854 | cmp ecx, 512 |
- | |
1855 | jb .force_buf |
1841 | jz .alignedCluster |
1856 | ; we may read directly to given buffer |
- | |
1857 | push eax ebx |
- | |
1858 | mov ebx, edx |
1842 | mov edi, edx |
1859 | call fs_read32_app |
- | |
1860 | test eax, eax |
1843 | shr edi, 9 |
1861 | pop ebx eax |
- | |
1862 | jne .noaccess_1 |
- | |
1863 | add edx, 512 |
1844 | add eax, edi |
1864 | sub ecx, 512 |
1845 | and edx, 511 |
1865 | jmp .skip |
1846 | jz .alignedSector |
1866 | .force_buf: |
1847 | .sectorPiece: |
1867 | ; we must read sector to temporary buffer and then copy it to destination |
- | |
1868 | push eax ebx |
1848 | push eax ebx |
1869 | lea ebx, [ebp+FAT.buffer] |
1849 | lea ebx, [ebp+FAT.buffer] |
1870 | call fs_read32_app |
1850 | call fs_read32_app |
1871 | test eax, eax |
1851 | test eax, eax |
1872 | mov eax, ebx |
1852 | mov eax, ebx |
1873 | pop ebx |
1853 | pop ebx |
1874 | jne .noaccess_3 |
1854 | jne .noaccess3 |
1875 | add eax, ebx |
1855 | add eax, edx |
1876 | push ecx |
1856 | push ecx |
1877 | add ecx, ebx |
1857 | add ecx, edx |
1878 | cmp ecx, 512 |
1858 | cmp ecx, 512 |
1879 | jbe @f |
1859 | jbe @f |
1880 | mov ecx, 512 |
1860 | mov ecx, 512 |
1881 | @@: |
1861 | @@: |
1882 | sub ecx, ebx |
1862 | sub ecx, edx |
1883 | mov ebx, edx |
- | |
1884 | call memmove |
1863 | call memmove |
1885 | add edx, ecx |
- | |
1886 | sub [esp], ecx |
1864 | sub [esp], ecx |
1887 | pop ecx |
1865 | add ebx, ecx |
1888 | pop eax |
1866 | pop ecx eax |
1889 | xor ebx, ebx |
1867 | xor edx, edx |
1890 | .skip: |
1868 | inc edi |
1891 | inc eax |
1869 | inc eax |
- | 1870 | test ecx, ecx |
|
1892 | dec edi |
1871 | jz .done |
- | 1872 | .alignedSector: |
|
- | 1873 | cmp ecx, 512 |
|
1893 | jnz .new_sector |
1874 | jc .sectorPiece |
- | 1875 | shl edi, 9 |
|
- | 1876 | add ecx, edi |
|
1894 | mov eax, [ebp+FAT.cluster_tmp] |
1877 | mov edi, [ebp+FAT.SECTORS_PER_CLUSTER] |
- | 1878 | shl edi, 9 |
|
- | 1879 | .alignedCluster: |
|
- | 1880 | cmp ecx, 512 |
|
- | 1881 | jc .sectorPiece |
|
- | 1882 | mov edx, eax |
|
- | 1883 | mov eax, esi |
|
- | 1884 | @@: |
|
- | 1885 | sub ecx, edi |
|
- | 1886 | jbe .readEnd |
|
1895 | call get_FAT |
1887 | call get_FAT |
1896 | jc .noaccess_1 |
1888 | jc .noaccess4 |
1897 | - | ||
- | 1889 | cmp eax, 2 |
|
- | 1890 | jb .fileEnd2 |
|
- | 1891 | cmp eax, [ebp+FAT.fatRESERVED] |
|
- | 1892 | jae .fileEnd2 |
|
- | 1893 | inc esi |
|
1898 | jmp .new_cluster |
1894 | cmp eax, esi |
- | 1895 | jz @b |
|
1899 | .noaccess_3: |
1896 | .fragmentEnd: |
- | 1897 | xchg eax, esi |
|
- | 1898 | dec eax |
|
- | 1899 | dec eax |
|
- | 1900 | imul eax, [ebp+FAT.SECTORS_PER_CLUSTER] |
|
- | 1901 | add eax, [ebp+FAT.DATA_START] |
|
- | 1902 | sub eax, edx |
|
- | 1903 | .readFragment: |
|
- | 1904 | push ecx |
|
- | 1905 | mov ecx, eax |
|
- | 1906 | mov eax, edx |
|
- | 1907 | xor edx, edx |
|
- | 1908 | push eax |
|
- | 1909 | call fs_read64_app |
|
- | 1910 | add [esp], ecx |
|
- | 1911 | shl ecx, 9 |
|
- | 1912 | add ebx, ecx |
|
- | 1913 | test eax, eax |
|
1900 | pop eax |
1914 | pop eax |
- | 1915 | jnz .noaccess3 |
|
- | 1916 | pop ecx |
|
- | 1917 | xor edx, edx |
|
- | 1918 | jcxz .done |
|
- | 1919 | cmp ecx, 512 |
|
- | 1920 | jc .sectorPiece |
|
- | 1921 | mov eax, esi |
|
- | 1922 | dec eax |
|
- | 1923 | dec eax |
|
- | 1924 | imul eax, [ebp+FAT.SECTORS_PER_CLUSTER] |
|
- | 1925 | add eax, [ebp+FAT.DATA_START] |
|
- | 1926 | jmp .alignedCluster |
|
- | 1927 | .readEnd: |
|
- | 1928 | add ecx, edi |
|
- | 1929 | mov edi, ecx |
|
- | 1930 | and ecx, 511 |
|
- | 1931 | shr edi, 9 |
|
- | 1932 | dec eax |
|
- | 1933 | dec eax |
|
- | 1934 | imul eax, [ebp+FAT.SECTORS_PER_CLUSTER] |
|
- | 1935 | add eax, [ebp+FAT.DATA_START] |
|
- | 1936 | sub eax, edx |
|
- | 1937 | add eax, edi |
|
- | 1938 | jmp .readFragment |
|
1901 | .noaccess_1: |
1939 | .noaccess3: |
1902 | pop eax |
1940 | pop eax |
- | 1941 | .noaccess2: |
|
1903 | push ERROR_DEVICE |
1942 | mov byte [esp], ERROR_DEVICE |
1904 | .done: |
1943 | .done: |
1905 | mov ebx, edx |
- | |
1906 | call fat_unlock |
1944 | call fat_unlock |
1907 | pop eax edx edi |
1945 | pop eax edx edi |
1908 | sub ebx, edx |
1946 | sub ebx, edx |
1909 | ret |
1947 | ret |
1910 | .eof: |
1948 | .fileEnd: |
- | 1949 | mov byte [esp], ERROR_END_OF_FILE |
|
1911 | mov ebx, edx |
1950 | jmp .done |
- | 1951 | .noaccess4: |
|
- | 1952 | mov byte [esp], ERROR_DEVICE |
|
- | 1953 | jmp @f |
|
- | 1954 | .fileEnd2: |
|
- | 1955 | mov byte [esp], ERROR_END_OF_FILE |
|
- | 1956 | @@: |
|
1912 | pop eax edx |
1957 | inc esi |
1913 | sub ebx, edx |
1958 | xor ecx, ecx |
1914 | jmp .reteof |
1959 | jmp .fragmentEnd |
Line 1915... | Line 1960... | ||
1915 | 1960 | ||
1916 | ;---------------------------------------------------------------- |
1961 | ;---------------------------------------------------------------- |
1917 | ; fat_ReadFolder - FAT implementation of reading a folder |
1962 | ; fat_ReadFolder - FAT implementation of reading a folder |
1918 | ; in: ebp = pointer to FAT structure |
1963 | ; in: ebp = pointer to FAT structure |