Rev 5565 | Rev 5596 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5565 | Rev 5594 | ||
---|---|---|---|
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: 4273 $ |
- | |
Line 48... | Line 45... | ||
48 | 45 | ||
Line 49... | Line 46... | ||
49 | 46 | ||
Line 60... | Line 57... | ||
60 | ; Internal data for every FAT partition. |
57 | ; Internal data for every FAT partition. |
61 | struct FAT PARTITION |
58 | struct FAT PARTITION |
62 | fs_type db ? |
59 | fs_type db ? |
63 | fat16_root db 0 ; flag for fat16 rootdir |
60 | fat16_root db 0 ; flag for fat16 rootdir |
64 | fat_change db 0 ; 1=fat has changed |
61 | fat_change db 0 ; 1=fat has changed |
65 | db ? ; alignment |
62 | rb 1 |
66 | Lock MUTEX ? ; currently operations with one partition |
63 | 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 |
64 | ; can not be executed in parallel since the legacy code is not ready |
69 | ; all operations |
- | |
70 | SECTORS_PER_FAT dd 0x1f3a |
65 | SECTORS_PER_FAT dd 0x1f3a |
71 | NUMBER_OF_FATS dd 0x2 |
66 | NUMBER_OF_FATS dd 0x2 |
72 | SECTORS_PER_CLUSTER dd 0x8 |
67 | SECTORS_PER_CLUSTER dd 0x8 |
73 | BYTES_PER_SECTOR dd 0x200 ; Note: if BPS <> 512 need lots of changes |
68 | BYTES_PER_SECTOR dd 0x200 ; Note: if BPS <> 512 need lots of changes |
74 | ROOT_CLUSTER dd 2 ; first rootdir cluster |
69 | ROOT_CLUSTER dd 2 ; first rootdir cluster |
Line 83... | Line 78... | ||
83 | fatBAD dd 0x0FFFFFF7 |
78 | fatBAD dd 0x0FFFFFF7 |
84 | fatEND dd 0x0FFFFFF8 |
79 | fatEND dd 0x0FFFFFF8 |
85 | fatMASK dd 0x0FFFFFFF |
80 | fatMASK dd 0x0FFFFFFF |
Line 86... | Line 81... | ||
86 | 81 | ||
87 | fatStartScan dd 2 |
- | |
88 | 82 | fatStartScan dd 2 |
|
89 | cluster_tmp dd 0 ; used by analyze_directory |
83 | cluster_tmp dd 0 ; used by analyze_directory |
90 | ; and analyze_directory_to_write |
- | |
91 | 84 | ; and analyze_directory_to_write |
|
92 | longname_sec1 dd 0 ; used by analyze_directory to save 2 previous |
85 | longname_sec1 dd 0 ; used by analyze_directory to save 2 previous |
93 | longname_sec2 dd 0 ; directory sectors for delete long filename |
- | |
94 | 86 | longname_sec2 dd 0 ; directory sectors for delete long filename |
|
Line 95... | Line 87... | ||
95 | fat_in_cache dd -1 |
87 | fat_in_cache dd -1 |
96 | 88 | ||
97 | ; For FAT16/FAT32, this points to 512-byte buffer for the current sector of FAT. |
89 | ; For FAT16/FAT32, this points to 512-byte buffer for the current sector of FAT. |
98 | ; For FAT12, the entire FAT structure is read |
90 | ; For FAT12, the entire FAT structure is read |
99 | ; and unpacked from 12bit per cluster to word per cluster. |
91 | ; and unpacked from 12bit per cluster to word per cluster. |
100 | ; |
92 | |
101 | ; Note: work with unpacked copy of FAT12 means |
93 | ; Note: work with unpacked copy of FAT12 means |
102 | ; additional memory and additional code for packing/unpacking. |
94 | ; additional memory and additional code for packing/unpacking. |
103 | ; I'm not sure that the economy justifies the cost, but anyway, |
95 | ; I'm not sure that the economy justifies the cost, but anyway, |
Line 109... | Line 101... | ||
109 | ends |
101 | ends |
Line 110... | Line 102... | ||
110 | 102 | ||
111 | uglobal |
103 | uglobal |
112 | align 4 |
104 | align 4 |
113 | partition_count dd 0 ; partitions found by set_FAT32_variables |
- | |
114 | 105 | partition_count dd 0 ; partitions found by set_FAT32_variables |
|
115 | hd_error dd 0 ; set by wait_for_sector_buffer |
106 | hd_error dd 0 |
116 | hd_setup dd 0 |
107 | hd_setup dd 0 |
117 | hd_wait_timeout dd 0 |
- | |
118 | 108 | hd_wait_timeout dd 0 |
|
119 | cache_search_start dd 0 ; used by find_empty_slot |
109 | cache_search_start dd 0 ; used by find_empty_slot |
Line 120... | Line 110... | ||
120 | endg |
110 | endg |
121 | 111 | ||
122 | uglobal |
112 | uglobal |
123 | align 4 |
113 | align 4 |
124 | Sector512: ; label for dev_hdcd.inc |
114 | Sector512: ; label for dev_hdcd.inc |
125 | buffer: |
115 | buffer: |
Line 126... | Line 116... | ||
126 | times 512 db 0 |
116 | rb 512 |
127 | endg |
117 | endg |
128 | 118 | ||
Line 1786... | Line 1776... | ||
1786 | push edi |
1776 | push edi |
1787 | cmp byte [esi], 0 |
1777 | cmp byte [esi], 0 |
1788 | jnz @f |
1778 | jnz @f |
1789 | .noaccess: |
1779 | .noaccess: |
1790 | pop edi |
1780 | pop edi |
1791 | .noaccess_2: |
- | |
1792 | call fat_unlock |
1781 | call fat_unlock |
1793 | or ebx, -1 |
1782 | or ebx, -1 |
1794 | mov eax, ERROR_ACCESS_DENIED |
1783 | mov eax, ERROR_ACCESS_DENIED |
1795 | ret |
1784 | ret |
1796 | - | ||
1797 | @@: |
1785 | @@: |
1798 | stdcall hd_find_lfn, [esp+4+4] |
1786 | stdcall hd_find_lfn, [esp+8] |
1799 | jnc .found |
1787 | jnc .found |
1800 | pop edi |
1788 | pop edi |
1801 | push eax |
1789 | push eax |
1802 | call fat_unlock |
1790 | call fat_unlock |
1803 | pop eax |
1791 | pop eax |
1804 | or ebx, -1 |
1792 | or ebx, -1 |
1805 | ret |
1793 | ret |
1806 | - | ||
1807 | .found: |
1794 | .found: |
1808 | test byte [edi+11], 0x10; do not allow read directories |
1795 | test byte [edi+11], 0x10 ; do not allow read directories |
1809 | jnz .noaccess |
1796 | jnz .noaccess |
1810 | cmp dword [ebx+8], 0 |
1797 | cmp dword [ebx+8], 0 |
1811 | jz @f |
1798 | jz @f |
1812 | xor ebx, ebx |
1799 | xor ebx, ebx |
1813 | .reteof: |
- | |
1814 | call fat_unlock |
1800 | call fat_unlock |
1815 | mov eax, ERROR_END_OF_FILE |
1801 | mov eax, ERROR_END_OF_FILE |
1816 | pop edi |
1802 | pop edi |
1817 | ret |
1803 | ret |
1818 | @@: |
1804 | @@: |
- | 1805 | mov edx, [ebx+4] ; file offset |
|
1819 | mov ecx, [ebx+12] ; size |
1806 | mov ecx, [ebx+12] ; size |
1820 | mov edx, [ebx+16] ; pointer |
1807 | mov ebx, [ebx+16] ; buffer |
1821 | mov ebx, [ebx+4] ; file offset |
- | |
1822 | push edx |
1808 | push ebx |
1823 | push 0 |
1809 | push 0 |
1824 | mov eax, [edi+28] |
1810 | mov eax, [edi+28] |
1825 | sub eax, ebx |
1811 | sub eax, edx |
1826 | jb .eof |
1812 | jb .fileEnd |
1827 | cmp eax, ecx |
1813 | cmp eax, ecx |
1828 | jae @f |
1814 | jae @f |
1829 | mov ecx, eax |
1815 | mov ecx, eax |
1830 | mov byte [esp], 6 |
1816 | mov byte [esp], 6 |
1831 | @@: |
1817 | @@: |
1832 | mov eax, [edi+20-2] |
1818 | mov eax, [edi+20-2] |
1833 | mov ax, [edi+26] |
1819 | mov ax, [edi+26] |
1834 | ; now eax=cluster, ebx=position, ecx=count, edx=buffer for data |
1820 | ; now eax=cluster, ebx=buffer for data, ecx=count, edx=position |
1835 | .new_cluster: |
1821 | mov edi, [ebp+FAT.SECTORS_PER_CLUSTER] |
1836 | jecxz .new_sector |
1822 | shl edi, 9 |
- | 1823 | @@: |
|
1837 | cmp eax, 2 |
1824 | cmp eax, 2 |
1838 | jb .eof |
1825 | jb .fileEnd |
1839 | cmp eax, [ebp+FAT.fatRESERVED] |
1826 | cmp eax, [ebp+FAT.fatRESERVED] |
- | 1827 | jae .fileEnd |
|
- | 1828 | sub edx, edi |
|
1840 | jae .eof |
1829 | jc @f |
- | 1830 | call get_FAT |
|
- | 1831 | jc .noaccess2 |
|
- | 1832 | jmp @b |
|
- | 1833 | @@: |
|
1841 | mov [ebp+FAT.cluster_tmp], eax |
1834 | mov esi, eax |
1842 | dec eax |
1835 | dec eax |
1843 | dec eax |
1836 | dec eax |
1844 | mov edi, [ebp+FAT.SECTORS_PER_CLUSTER] |
1837 | imul eax, [ebp+FAT.SECTORS_PER_CLUSTER] |
1845 | imul eax, edi |
- | |
1846 | add eax, [ebp+FAT.DATA_START] |
1838 | 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 |
1839 | add edx, edi |
1853 | jnz .force_buf |
- | |
1854 | cmp ecx, 512 |
- | |
1855 | jb .force_buf |
1840 | jz .alignedCluster |
1856 | ; we may read directly to given buffer |
- | |
1857 | push eax ebx |
- | |
1858 | mov ebx, edx |
1841 | mov edi, edx |
1859 | call fs_read32_app |
- | |
1860 | test eax, eax |
1842 | shr edi, 9 |
1861 | pop ebx eax |
- | |
1862 | jne .noaccess_1 |
- | |
1863 | add edx, 512 |
1843 | add eax, edi |
1864 | sub ecx, 512 |
1844 | and edx, 511 |
1865 | jmp .skip |
1845 | jz .alignedSector |
1866 | .force_buf: |
1846 | .sectorPiece: |
1867 | ; we must read sector to temporary buffer and then copy it to destination |
- | |
1868 | push eax ebx |
1847 | push eax ebx |
1869 | lea ebx, [ebp+FAT.buffer] |
1848 | lea ebx, [ebp+FAT.buffer] |
1870 | call fs_read32_app |
1849 | call fs_read32_app |
1871 | test eax, eax |
1850 | test eax, eax |
1872 | mov eax, ebx |
1851 | mov eax, ebx |
1873 | pop ebx |
1852 | pop ebx |
1874 | jne .noaccess_3 |
1853 | jne .noaccess3 |
1875 | add eax, ebx |
1854 | add eax, edx |
1876 | push ecx |
1855 | push ecx |
1877 | add ecx, ebx |
1856 | add ecx, edx |
1878 | cmp ecx, 512 |
1857 | cmp ecx, 512 |
1879 | jbe @f |
1858 | jbe @f |
1880 | mov ecx, 512 |
1859 | mov ecx, 512 |
1881 | @@: |
1860 | @@: |
1882 | sub ecx, ebx |
1861 | sub ecx, edx |
1883 | mov ebx, edx |
- | |
1884 | call memmove |
1862 | call memmove |
1885 | add edx, ecx |
- | |
1886 | sub [esp], ecx |
1863 | sub [esp], ecx |
1887 | pop ecx |
1864 | add ebx, ecx |
1888 | pop eax |
1865 | pop ecx eax |
1889 | xor ebx, ebx |
1866 | xor edx, edx |
1890 | .skip: |
1867 | inc edi |
1891 | inc eax |
1868 | inc eax |
- | 1869 | test ecx, ecx |
|
1892 | dec edi |
1870 | jz .done |
- | 1871 | .alignedSector: |
|
- | 1872 | cmp ecx, 512 |
|
1893 | jnz .new_sector |
1873 | jc .sectorPiece |
- | 1874 | shl edi, 9 |
|
- | 1875 | add ecx, edi |
|
1894 | mov eax, [ebp+FAT.cluster_tmp] |
1876 | mov edi, [ebp+FAT.SECTORS_PER_CLUSTER] |
- | 1877 | shl edi, 9 |
|
- | 1878 | .alignedCluster: |
|
- | 1879 | cmp ecx, 512 |
|
- | 1880 | jc .sectorPiece |
|
- | 1881 | mov edx, eax |
|
- | 1882 | mov eax, esi |
|
- | 1883 | @@: |
|
- | 1884 | sub ecx, edi |
|
- | 1885 | jbe .readEnd |
|
1895 | call get_FAT |
1886 | call get_FAT |
1896 | jc .noaccess_1 |
1887 | jc .noaccess4 |
1897 | - | ||
- | 1888 | cmp eax, 2 |
|
- | 1889 | jb .fileEnd2 |
|
- | 1890 | cmp eax, [ebp+FAT.fatRESERVED] |
|
- | 1891 | jae .fileEnd2 |
|
- | 1892 | inc esi |
|
1898 | jmp .new_cluster |
1893 | cmp eax, esi |
- | 1894 | jz @b |
|
1899 | .noaccess_3: |
1895 | .fragmentEnd: |
- | 1896 | xchg eax, esi |
|
- | 1897 | dec eax |
|
- | 1898 | dec eax |
|
- | 1899 | imul eax, [ebp+FAT.SECTORS_PER_CLUSTER] |
|
- | 1900 | add eax, [ebp+FAT.DATA_START] |
|
- | 1901 | sub eax, edx |
|
- | 1902 | .readFragment: |
|
- | 1903 | push ecx |
|
- | 1904 | mov ecx, eax |
|
- | 1905 | mov eax, edx |
|
- | 1906 | xor edx, edx |
|
- | 1907 | push eax |
|
- | 1908 | call fs_read64_app |
|
- | 1909 | add [esp], ecx |
|
- | 1910 | shl ecx, 9 |
|
- | 1911 | add ebx, ecx |
|
- | 1912 | test eax, eax |
|
1900 | pop eax |
1913 | pop eax |
- | 1914 | jnz .noaccess3 |
|
- | 1915 | pop ecx |
|
- | 1916 | xor edx, edx |
|
- | 1917 | jcxz .done |
|
- | 1918 | cmp ecx, 512 |
|
- | 1919 | jc .sectorPiece |
|
- | 1920 | mov eax, esi |
|
- | 1921 | dec eax |
|
- | 1922 | dec eax |
|
- | 1923 | imul eax, [ebp+FAT.SECTORS_PER_CLUSTER] |
|
- | 1924 | add eax, [ebp+FAT.DATA_START] |
|
- | 1925 | jmp .alignedCluster |
|
- | 1926 | .readEnd: |
|
- | 1927 | add ecx, edi |
|
- | 1928 | mov edi, ecx |
|
- | 1929 | and ecx, 511 |
|
- | 1930 | shr edi, 9 |
|
- | 1931 | dec eax |
|
- | 1932 | dec eax |
|
- | 1933 | imul eax, [ebp+FAT.SECTORS_PER_CLUSTER] |
|
- | 1934 | add eax, [ebp+FAT.DATA_START] |
|
- | 1935 | sub eax, edx |
|
- | 1936 | add eax, edi |
|
- | 1937 | jmp .readFragment |
|
1901 | .noaccess_1: |
1938 | .noaccess3: |
1902 | pop eax |
1939 | pop eax |
- | 1940 | .noaccess2: |
|
1903 | push ERROR_DEVICE |
1941 | mov byte [esp], ERROR_DEVICE |
1904 | .done: |
1942 | .done: |
1905 | mov ebx, edx |
- | |
1906 | call fat_unlock |
1943 | call fat_unlock |
1907 | pop eax edx edi |
1944 | pop eax edx edi |
1908 | sub ebx, edx |
1945 | sub ebx, edx |
1909 | ret |
1946 | ret |
1910 | .eof: |
1947 | .fileEnd: |
- | 1948 | mov byte [esp], ERROR_END_OF_FILE |
|
1911 | mov ebx, edx |
1949 | jmp .done |
- | 1950 | .noaccess4: |
|
- | 1951 | mov byte [esp], ERROR_DEVICE |
|
- | 1952 | jmp @f |
|
- | 1953 | .fileEnd2: |
|
- | 1954 | mov byte [esp], ERROR_END_OF_FILE |
|
- | 1955 | @@: |
|
1912 | pop eax edx |
1956 | inc esi |
1913 | sub ebx, edx |
1957 | xor ecx, ecx |
1914 | jmp .reteof |
1958 | jmp .fragmentEnd |
Line 1915... | Line 1959... | ||
1915 | 1959 | ||
1916 | ;---------------------------------------------------------------- |
1960 | ;---------------------------------------------------------------- |
1917 | ; fat_ReadFolder - FAT implementation of reading a folder |
1961 | ; fat_ReadFolder - FAT implementation of reading a folder |
1918 | ; in: ebp = pointer to FAT structure |
1962 | ; in: ebp = pointer to FAT structure |