Subversion Repositories Kolibri OS

Rev

Rev 3742 | Rev 4277 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2288 clevermous 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                              ;;
2455 mario79 3
;; Copyright (C) KolibriOS team 2004-2011. All rights reserved. ;;
2288 clevermous 4
;; Distributed under terms of the GNU General Public License    ;;
5
;;                                                              ;;
6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7
 
8
$Revision: 4273 $
9
 
2889 turbanoff 10
ERROR_SUCCESS        = 0
11
ERROR_DISK_BASE      = 1
12
ERROR_UNSUPPORTED_FS = 2
13
ERROR_UNKNOWN_FS     = 3
14
ERROR_PARTITION      = 4
15
ERROR_FILE_NOT_FOUND = 5
16
ERROR_END_OF_FILE    = 6
17
ERROR_MEMORY_POINTER = 7
18
ERROR_DISK_FULL      = 8
19
ERROR_FAT_TABLE      = 9 ;deprecated
20
ERROR_FS_FAIL        = 9
21
ERROR_ACCESS_DENIED  = 10
22
ERROR_DEVICE         = 11
2288 clevermous 23
 
24
image_of_eax EQU esp+32
25
image_of_ebx EQU esp+20
26
 
27
; System function 70 - files with long names (LFN)
28
; diamond, 2006
29
 
30
iglobal
31
; in this table names must be in lowercase
32
rootdirs:
33
;**********************************************
34
        db      3,'cd0'
35
        dd      fs_OnCd0
36
        dd      fs_NextCd
37
        db      3,'cd1'
38
        dd      fs_OnCd1
39
        dd      fs_NextCd
40
        db      3,'cd2'
41
        dd      fs_OnCd2
42
        dd      fs_NextCd
43
        db      3,'cd3'
44
        dd      fs_OnCd3
45
        dd      fs_NextCd
46
;***********************************************
47
        db      0
48
 
49
 
50
virtual_root_query:
51
;**********************************************
52
        dd      fs_HasCd0
53
        db      'cd0',0
54
        dd      fs_HasCd1
55
        db      'cd1',0
56
        dd      fs_HasCd2
57
        db      'cd2',0
58
        dd      fs_HasCd3
59
        db      'cd3',0
60
;**********************************************
61
        dd      0
62
 
63
fs_additional_handlers:
64
        dd      dyndisk_handler, dyndisk_enum_root
65
; add new handlers here
66
        dd      0
67
 
68
endg
3296 clevermous 69
 
70
file_system_lfn_protected:
71
        pushad
72
        call    protect_from_terminate
73
        call    file_system_lfn
74
        call    unprotect_from_terminate
75
        popad
76
        mov     [image_of_eax], eax
77
        mov     [image_of_ebx], ebx
78
        ret
79
 
2288 clevermous 80
file_system_lfn:
81
; in: ebx->fileinfo block
82
; operation codes:
83
; 0 : read file
84
; 1 : read folder
85
; 2 : create/rewrite file
86
; 3 : write/append to file
87
; 4 : set end of file
88
; 5 : get file/directory attributes structure
89
; 6 : set file/directory attributes structure
90
; 7 : start application
91
; 8 : delete file
92
; 9 : create directory
93
 
94
; parse file name
95
        lea     esi, [ebx+20]
96
        lodsb
97
        test    al, al
98
        jnz     @f
99
        mov     esi, [esi]
100
        lodsb
101
@@:
102
        cmp     al, '/'
103
        jz      .notcurdir
104
        dec     esi
105
        mov     ebp, esi
106
        test    al, al
107
        jnz     @f
108
        xor     ebp, ebp
109
@@:
110
        mov     esi, [current_slot]
111
        mov     esi, [esi+APPDATA.cur_dir]
112
        jmp     .parse_normal
113
.notcurdir:
114
        cmp     byte [esi], 0
115
        jz      .rootdir
116
        call    process_replace_file_name
117
.parse_normal:
118
        cmp     dword [ebx], 7
119
        jne     @F
120
        mov     edx, [ebx+4]
121
        mov     ebx, [ebx+8]
122
        call    fs_execute; esi+ebp, ebx, edx
123
        mov     [image_of_eax], eax
124
        ret
125
@@:
126
        mov     edi, rootdirs-8
127
        xor     ecx, ecx
128
        push    esi
129
.scan1:
130
        pop     esi
131
        add     edi, ecx
132
        scasd
133
        scasd
134
        mov     cl, byte [edi]
135
        test    cl, cl
136
        jz      .notfound_try
137
        inc     edi
138
        push    esi
139
@@:
140
        lodsb
141
        or      al, 20h
142
        scasb
143
        loopz   @b
144
        jnz     .scan1
145
        lodsb
146
        cmp     al, '/'
147
        jz      .found1
148
        test    al, al
149
        jnz     .scan1
150
        pop     eax
151
; directory /xxx
152
.maindir:
153
        mov     esi, [edi+4]
154
.maindir_noesi:
155
        cmp     dword [ebx], 1
156
        jnz     .access_denied
157
        xor     eax, eax
158
        mov     ebp, [ebx+12]                   ;количество блоков для считывания
159
        mov     edx, [ebx+16]                   ;куда записывать рузельтат
160
    ;    add     edx, std_application_base_address
161
        push    dword [ebx+4]   ; first block
162
        mov     ebx, [ebx+8]    ; flags
163
; ebx=flags, [esp]=first block, ebp=number of blocks, edx=return area, esi='Next' handler
164
        mov     edi, edx
165
        push    ecx
166
        mov     ecx, 32/4
167
        rep stosd
168
        pop     ecx
169
        mov     byte [edx], 1   ; version
170
.maindir_loop:
171
        call    esi
172
        jc      .maindir_done
173
        inc     dword [edx+8]
174
        dec     dword [esp]
175
        jns     .maindir_loop
176
        dec     ebp
177
        js      .maindir_loop
178
        inc     dword [edx+4]
179
        mov     dword [edi], 0x10       ; attributes: folder
180
        mov     dword [edi+4], 1        ; name type: UNICODE
181
        push    eax
182
        xor     eax, eax
183
        add     edi, 8
184
        push    ecx
185
        mov     ecx, 40/4-2
186
        rep stosd
187
        pop     ecx
188
        pop     eax
189
        push    eax edx
190
; convert number in eax to decimal UNICODE string
191
        push    edi
192
        push    ecx
193
        push    -'0'
194
        mov     ecx, 10
195
@@:
196
        xor     edx, edx
197
        div     ecx
198
        push    edx
199
        test    eax, eax
200
        jnz     @b
201
@@:
202
        pop     eax
203
        add     al, '0'
204
        stosb
205
        test    bl, 1           ; UNICODE name?
206
        jz      .ansi2
207
        mov     byte [edi], 0
208
        inc     edi
209
.ansi2:
210
        test    al, al
211
        jnz     @b
212
        mov     byte [edi-1], 0
213
        pop     ecx
214
        pop     edi
215
; UNICODE name length is 520 bytes, ANSI - 264
216
        add     edi, 520
217
        test    bl, 1
218
        jnz     @f
219
        sub     edi, 520-264
220
@@:
221
        pop     edx eax
222
        jmp     .maindir_loop
223
.maindir_done:
224
        pop     eax
225
        mov     ebx, [edx+4]
226
        xor     eax, eax
227
        dec     ebp
228
        js      @f
229
        mov     al, ERROR_END_OF_FILE
230
@@:
231
        mov     [image_of_eax], eax
232
        mov     [image_of_ebx], ebx
233
        ret
234
; directory /
235
.rootdir:
236
        cmp     dword [ebx], 1  ; read folder?
237
        jz      .readroot
238
.access_denied:
239
        mov     dword [image_of_eax], 10      ; access denied
240
        ret
241
 
242
.readroot:
243
; virtual root folder - special handler
244
        mov     esi, virtual_root_query
245
        mov     ebp, [ebx+12]
246
        mov     edx, [ebx+16]
247
    ;    add     edx, std_application_base_address
248
        push    dword [ebx+4]   ; first block
249
        mov     ebx, [ebx+8]    ; flags
250
        xor     eax, eax
251
; eax=0, [esp]=first block, ebx=flags, ebp=number of blocks, edx=return area
252
        mov     edi, edx
253
        mov     ecx, 32/4
254
        rep stosd
255
        mov     byte [edx], 1   ; version
256
.readroot_loop:
257
        cmp     dword [esi], eax
258
        jz      .readroot_done_static
259
        call    dword [esi]
260
        add     esi, 4
261
        test    eax, eax
262
        jnz     @f
263
.readroot_next:
264
        or      ecx, -1
265
        xchg    esi, edi
266
        repnz scasb
267
        xchg    esi, edi
268
        jmp     .readroot_loop