Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
72 diamond 1
; System function 70 - files with long names (LFN)
71 diamond 2
; diamond, 2006
3
 
4
iglobal
5
; in this table names must be in lowercase
6
rootdirs:
75 diamond 7
        db      2,'rd'
8
        dd      fs_OnRamdisk
9
        dd      fs_NextRamdisk
10
        db      7,'ramdisk'
11
        dd      fs_OnRamdisk
12
        dd      fs_NextRamdisk
13
        db      2,'fd'
14
        dd      fs_OnFloppy
15
        dd      fs_NextFloppy
16
        db      10,'floppydisk'
17
        dd      fs_OnFloppy
18
        dd      fs_NextFloppy
19
        db      3,'hd0'
20
        dd      fs_OnHd0
21
        dd      fs_NextHd0
22
        db      3,'hd1'
23
        dd      fs_OnHd1
24
        dd      fs_NextHd1
25
        db      3,'hd2'
26
        dd      fs_OnHd2
27
        dd      fs_NextHd2
28
        db      3,'hd3'
29
        dd      fs_OnHd3
30
        dd      fs_NextHd3
31
        db      0
32
 
33
virtual_root_query:
34
        dd      fs_HasRamdisk
35
        du      'rd',0
36
        dd      fs_HasFloppy
37
        du      'fd',0
38
        dd      fs_HasHd0
39
        du      'hd0',0
40
        dd      fs_HasHd1
41
        du      'hd1',0
42
        dd      fs_HasHd2
43
        du      'hd2',0
44
        dd      fs_HasHd3
45
        du      'hd3',0
46
        dd      0
71 diamond 47
endg
48
 
49
file_system_lfn:
50
; in: eax->fileinfo block
51
; operation codes:
72 diamond 52
; 0 : read file
75 diamond 53
; 1 : read folder
54
; 2 : rewrite file - not implemented yet
72 diamond 55
; 3 : write/append to file - not implemented yet
75 diamond 56
; 4 : start application - not implemented yet
57
; 5 : delete file - not implemented yet
58
; 6 : create directory - not implemented yet
59
; 7 : rename file/directory - not implemented yet
60
; 8 : get file attributes structure - not implemented yet
71 diamond 61
 
75 diamond 62
        add     eax, std_application_base_address
71 diamond 63
; parse file name
75 diamond 64
        xchg    ebx, eax
65
        lea     esi, [ebx+20]
66
        lodsb
67
        cmp     al, '/'
68
        jz      @f
71 diamond 69
.notfound:
75 diamond 70
        mov     dword [esp+36], 5       ; file not found
71
        ret
71 diamond 72
@@:
75 diamond 73
        cmp     byte [esi], 0
74
        jz      .rootdir
75
        mov     edi, rootdirs-8
76
        xor     ecx, ecx
77
        push    esi
71 diamond 78
.scan1:
75 diamond 79
        pop     esi
80
        add     edi, ecx
81
        scasd
82
        scasd
83
        mov     cl, byte [edi]
84
        jecxz   .notfound
85
        inc     edi
86
        push    esi
71 diamond 87
@@:
75 diamond 88
        lodsb
89
        or      al, 20h
90
        scasb
91
        loopz   @b
92
        jnz     .scan1
93
        lodsb
94
        cmp     al, '/'
95
        jz      .found1
96
        test    al, al
97
        jnz     .scan1
98
        pop     eax
71 diamond 99
; directory /xxx
100
.maindir:
75 diamond 101
        cmp     dword [ebx], 1
102
        jnz     .access_denied
103
        xor     eax, eax
104
        mov     ebp, [ebx+12]
105
        mov     edx, [ebx+16]
106
        add     edx, std_application_base_address
107
        mov     ebx, [ebx+4]
108
        mov     esi, [edi+4]
109
; ebx=first block, ebp=number of blocks, edx=return area, esi='Next' handler
110
        mov     edi, edx
111
        mov     ecx, 32/4
112
        rep     stosd
113
        mov     byte [edx], 1   ; version
114
.maindir_loop:
115
        call    esi
116
        jc      .maindir_done
117
        inc     dword [edx+8]
118
        dec     ebx
119
        jns     .maindir_loop
120
        dec     ebp
121
        js      .maindir_loop
122
        inc     dword [edx+4]
123
        mov     dword [edi], 0x10       ; attributes: folder
124
        mov     dword [edi+4], 1        ; name type: UNICODE
125
        push    eax
126
        xor     eax, eax
127
        add     edi, 8
128
        mov     ecx, 40/4-2
129
        rep     stosd
130
        pop     eax
131
        push    eax edx
132
; convert number in eax to decimal UNICODE string
133
        push    edi
134
        push    -'0'
135
        mov     cl, 10
136
@@:
137
        xor     edx, edx
138
        div     ecx
139
        push    edx
140
        test    eax, eax
141
        jnz     @b
142
@@:
143
        pop     eax
144
        add     al, '0'
145
        stosw
146
        jnz     @b
147
        mov     byte [edi-1], 0
148
        pop     edi
149
        add     edi, 520
150
        pop     edx eax
151
        jmp     .maindir_loop
152
.maindir_done:
153
        mov     ebx, [edx+8]
154
        xor     eax, eax
155
        dec     ebp
156
        js      @f
157
        mov     al, ERROR_END_OF_FILE
158
@@:
159
        mov     [esp+36], eax
160
        mov     [esp+24], ebx
161
        ret
71 diamond 162
; directory /
163
.rootdir:
75 diamond 164
        cmp     dword [ebx], 1  ; read folder?
165
        jz      .readroot
166
.access_denied:
167
        mov     dword [esp+36], 10      ; access denied
168
        ret
71 diamond 169
 
75 diamond 170
.readroot:
171
; virtual root folder - special handler
172
        mov     esi, virtual_root_query
173
        mov     ebp, [ebx+12]
174
        mov     edx, [ebx+16]
175
        add     edx, std_application_base_address
176
        mov     ebx, [ebx+4]
177
        xor     eax, eax
178
; eax=0, ebx=first block, ebp=number of blocks, edx=return area
179
        mov     edi, edx
180
        mov     ecx, 32/4
181
        rep     stosd
182
        mov     byte [edx], 1   ; version
183
.readroot_loop:
184
        cmp     dword [esi], eax
185
        jz      .readroot_done
186
        call    dword [esi]
187
        add     esi, 4
188
        test    eax, eax
189
        jnz     @f
190
.readroot_next:
191
        or      ecx, -1
192
        xchg    esi, edi
193
        repnz   scasw
194
        xchg    esi, edi
195
        jmp     .readroot_loop
196
@@:
197
        xor     eax, eax
198
        inc     dword [edx+8]
199
        dec     ebx
200
        jns     .readroot_next
201
        dec     ebp
202
        js      .readroot_next
203
        inc     dword [edx+4]
204
        mov     dword [edi], 0x10       ; attributes: folder
205
        mov     dword [edi+4], 1        ; name type: UNICODE
206
        add     edi, 8
207
        mov     ecx, 40/4-2
208
        rep     stosd
209
        push    edi
210
@@:
211
        lodsw
212
        stosw
213
        test    eax, eax
214
        jnz     @b
215
        pop     edi
216
        add     edi, 520
217
        jmp     .readroot_loop
218
.readroot_done:
219
        mov     ebx, [edx+8]
220
        xor     eax, eax
221
        dec     ebp
222
        js      @f
223
        mov     al, ERROR_END_OF_FILE
224
@@:
225
        mov     [esp+36], eax
226
        mov     [esp+24], ebx
227
        ret
228
 
71 diamond 229
.found1:
75 diamond 230
        pop     eax
231
        cmp     byte [esi], 0
232
        jz      .maindir
71 diamond 233
; read partition number
75 diamond 234
        xor     ecx, ecx
235
        xor     eax, eax
71 diamond 236
@@:
75 diamond 237
        lodsb
238
        cmp     al, '/'
239
        jz      .done1
240
        test    al, al
241
        jz      .done1
242
        sub     al, '0'
243
        cmp     al, 9
244
        ja      .notfound
245
        imul    ecx, 10
246
        add     ecx, eax
247
        jmp     @b
71 diamond 248
.done1:
75 diamond 249
        test    ecx, ecx
250
        jz      .notfound
251
        test    al, al
252
        jnz     @f
253
        dec     esi
71 diamond 254
@@:
75 diamond 255
; now [edi] contains handler address, ecx - partition number,
256
; esi points to ASCIIZ string - rest of name
257
        jmp     dword [edi]
71 diamond 258
 
259
; handlers for devices
75 diamond 260
; in: ecx = 0 => query virtual directory /xxx
71 diamond 261
; in: ecx = partition number
262
;     esi -> relative (for device) name
263
;     ebx -> fileinfo
264
; out: [esp+36]=image of eax, [esp+24]=image of ebx
265
 
266
fs_OnRamdisk:
75 diamond 267
        cmp     ecx, 1
268
        jnz     file_system_lfn.notfound
269
        mov     eax, [ebx]
270
        cmp     eax, 1
271
        ja      .not_impl
272
        mov     ecx, [ebx+12]
273
        mov     edx, [ebx+16]
274
        add     edx, std_application_base_address
275
        add     ebx, 4
276
        call    dword [fs_RamdiskServices + eax*4]
277
        mov     [esp+36], eax
278
        mov     [esp+24], ebx
279
        ret
71 diamond 280
.not_impl:
75 diamond 281
        mov     dword [esp+36], 2       ; not implemented
282
        ret
71 diamond 283
 
284
fs_RamdiskServices:
75 diamond 285
        dd      fs_RamdiskRead
286
        dd      fs_RamdiskReadFolder
71 diamond 287
 
288
fs_OnFloppy:
75 diamond 289
        cmp     ecx, 2
290
        ja      file_system_lfn.notfound
291
        mov     eax, [ebx]
292
        cmp     eax, 1
293
        ja      fs_OnRamdisk.not_impl
294
        call    reserve_flp
295
        mov     [flp_number], cl
296
        mov     ecx, [ebx+12]
297
        mov     edx, [ebx+16]
298
        add     edx, std_application_base_address
299
        add     ebx, 4
300
        call    dword [fs_FloppyServices + eax*4]
301
        and     [flp_status], 0
302
        mov     [esp+36], eax
303
        mov     [esp+24], ebx
304
        ret
71 diamond 305
 
306
fs_FloppyServices:
75 diamond 307
        dd      fs_FloppyRead
308
        dd      fs_FloppyReadFolder
71 diamond 309
 
310
fs_OnHd0:
75 diamond 311
        call    reserve_hd1
312
        mov     [hdbase], 0x1F0
313
        mov     [hdid], 0
314
        push    1
315
        jmp     fs_OnHd
71 diamond 316
fs_OnHd1:
75 diamond 317
        call    reserve_hd1
318
        mov     [hdbase], 0x1F0
319
        mov     [hdid], 0x10
320
        push    2
321
        jmp     fs_OnHd
71 diamond 322
fs_OnHd2:
75 diamond 323
        call    reserve_hd1
324
        mov     [hdbase], 0x170
325
        mov     [hdid], 0
326
        push    3
327
        jmp     fs_OnHd
71 diamond 328
fs_OnHd3:
75 diamond 329
        call    reserve_hd1
330
        mov     [hdbase], 0x170
331
        mov     [hdid], 0x10
332
        push    4
71 diamond 333
fs_OnHd:
75 diamond 334
        pop     eax
335
        mov     [hdpos], eax
336
        cmp     ecx, 0x100
337
        jae     .nf
338
        cmp     cl, [0x40001+eax]
339
        jbe     @f
340
.nf:
341
        and     [hd1_status], 0
342
        mov     dword [esp+36], 5       ; not found
343
        ret
71 diamond 344
@@:
75 diamond 345
        mov     [fat32part], ecx
346
        push    ebx esi
347
        call    choice_necessity_partition_1
348
        pop     esi ebx
349
        mov     ecx, [ebx+12]
350
        mov     edx, [ebx+16]
351
        add     edx, std_application_base_address
352
        mov     eax, [ebx]
353
        cmp     eax, 1
354
        ja      .not_impl
355
        add     ebx, 4
356
        call    dword [fs_HdServices + eax*4]
357
        and     [hd1_status], 0
358
        mov     [esp+36], eax
359
        mov     [esp+24], ebx
360
        ret
361
.not_impl:
362
        and     [hd1_status], 0
363
        mov     dword [esp+36], 2       ; not implemented
364
        ret
71 diamond 365
 
366
fs_HdServices:
75 diamond 367
        dd      fs_HdRead
368
        dd      fs_HdReadFolder
369
 
370
fs_HasRamdisk:
371
        mov     al, 1   ; we always have ramdisk
372
        ret
373
 
374
fs_HasFloppy:
375
        cmp     byte [0x40000], 0
376
        setnz   al
377
        ret
378
 
379
fs_HasHd0:
380
        mov     al, [0x40001]
381
        and     al, 11000000b
382
        cmp     al, 01000000b
383
        setz    al
384
        ret
385
fs_HasHd1:
386
        mov     al, [0x40001]
387
        and     al, 00110000b
388
        cmp     al, 00010000b
389
        setz    al
390
        ret
391
fs_HasHd2:
392
        mov     al, [0x40001]
393
        and     al, 00001100b
394
        cmp     al, 00000100b
395
        setz    al
396
        ret
397
fs_HasHd3:
398
        mov     al, [0x40001]
399
        and     al, 00000011b
400
        cmp     al, 00000001b
401
        setz    al
402
        ret
403
 
404
; fs_NextXXX functions:
405
; in: eax = partition number, from which start to scan
406
; out: CF=1 => no more partitions
407
;      CF=0 => eax=next partition number
408
 
409
fs_NextRamdisk:
410
; we always have /rd/1
411
        test    eax, eax
412
        stc
413
        jnz     @f
414
        mov     al, 1
415
        clc
416
@@:
417
        ret
418
 
419
fs_NextFloppy:
420
; we have /fd/1 iff (([0x40000] and 0xF0) != 0) and /fd/2 iff (([0x40000] and 0x0F) != 0)
421
        test    byte [0x40000], 0xF0
422
        jz      .no1
423
        test    eax, eax
424
        jnz     .no1
425
        inc     eax
426
        ret     ; CF cleared
427
.no1:
428
        test    byte [0x40000], 0x0F
429
        jz      .no2
430
        cmp     al, 2
431
        jae     .no2
432
        mov     al, 2
433
        clc
434
        ret
435
.no2:
436
        stc
437
        ret
438
 
439
; on hdx, we have partitions from 1 to [0x40002+x]
440
fs_NextHd0:
441
        push    0
442
        jmp     fs_NextHd
443
fs_NextHd1:
444
        push    1
445
        jmp     fs_NextHd
446
fs_NextHd2:
447
        push    2
448
        jmp     fs_NextHd
449
fs_NextHd3:
450
        push    3
451
fs_NextHd:
452
        pop     ecx
453
        movzx   ecx, byte [0x40002+ecx]
454
        cmp     eax, ecx
455
        jae     fs_NextFloppy.no2
456
        inc     eax
457
        clc
458
        ret