Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
129 mikedld 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                                      ;;
3
;; System service for filesystem call                                   ;;
4
;; (C) 2004 Ville Turjanmaa, License: GPL                               ;;
5
;; 29.04.2006 Elimination of hangup after the                           ;;
6
;;            expiration hd_wait_timeout (for LBA) -  Mario79           ;;
7
;; xx.04.2006 LFN support - diamond                                     ;;
8
;; 15.01.2005 get file size/attr/date, file_append (only for hd) - ATV  ;;
9
;; 23.11.2004 test if hd/partition is set - ATV                         ;;
10
;; 18.11.2004 get_disk_info and more error codes - ATV                  ;;
11
;; 08.11.2004 expand_pathz and rename (only for hd) - ATV               ;;
12
;; 20.10.2004 Makedir/Removedir (only for hd) - ATV                     ;;
13
;;                                                                      ;;
14
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15
 
16
iglobal
17
dir0:        db  'HARDDISK   '
18
             db  'RAMDISK    '
19
             db  'FLOPPYDISK '
20
             db  0
21
 
22
dir1:        db  'FIRST      '
23
             db  'SECOND     '
24
             db  'THIRD      '
25
             db  'FOURTH     '
26
             db  0
27
 
28
not_select_IDE db 0
29
 
30
hd_address_table:  dd  0x1f0,0x00,0x1f0,0x10
31
                   dd  0x170,0x00,0x170,0x10
32
endg
33
 
34
file_system:
35
 
36
; IN:
37
;
133 diamond 38
; eax = 0  ; read file          /RamDisk/First  6
129 mikedld 39
; eax = 1  ; write file         /RamDisk/First 33   /HardDisk/First 56
133 diamond 40
; eax = 2  ; delete file        /RamDisk/First 32
129 mikedld 41
; eax = 4  ; makedir
42
; eax = 5  ; rename file/directory
43
; eax = 8  ; lba read
44
; eax = 15 ; get_disk_info
45
; eax = 16 ; start application
46
;
47
; OUT:
48
;
49
; eax = 0  : read ok
50
; eax = 1  : no hd base and/or partition defined
51
; eax = 2  : function is unsupported for this FS
52
; eax = 3  : unknown FS
53
; eax = 4  : partition not defined at hd
54
; eax = 5  : file not found
55
; eax = 6  : end of file
56
; eax = 7  : memory pointer not in application area
57
; eax = 8  : disk full
58
; eax = 9  : fat table corrupted
59
; eax = 10 : access denied
60
; eax = 11 : disk error
61
;
62
; ebx = size
63
 
64
; \begin{diamond}[18.03.2006]
65
; for subfunction 16 (start application) error codes must be negative
66
;    because positive values are valid PIDs
67
; so possible return values are:
68
; eax > 0 : process created, eax=PID
69
 
70
; -0x10 <= eax < 0 : -eax is filesystem error code:
71
; eax = -1  = 0xFFFFFFFF : no hd base and/or partition defined
72
; eax = -3  = 0xFFFFFFFD : unknown FS
73
; eax = -5  = 0xFFFFFFFB : file not found
74
; eax = -6  = 0xFFFFFFFA : unexpected end of file (probably not executable file)
75
; eax = -9  = 0xFFFFFFF7 : fat table corrupted
76
; eax = -10 = 0xFFFFFFF6 : access denied
77
 
78
; -0x20 <= eax < -0x10: eax is process creation error code:
79
; eax = -0x20 = 0xFFFFFFE0 : too many processes
80
; eax = -0x1F = 0xFFFFFFE1 : not Menuet/Kolibri executable
81
; eax = -0x1E = 0xFFFFFFE2 : no memory
82
 
83
; ebx is not changed
84
 
85
; \end{diamond}[18.03.2006]
86
 
87
    ; Extract parameters
88
    add    eax, std_application_base_address    ; abs start of info block
89
 
90
    cmp   dword [eax+0],15      ; GET_DISK_INFO
91
    je    fs_info
92
    cmp   dword [eax+0],16      ; RUN - dont care about read&write blocks
93
    je    fs_read
94
    cmp   dword [eax+0],5       ; RENAME - dont care about read&write blocks
95
    je    fs_read
96
    cmp   dword [eax+0],4       ; MAKEDIR - dont care about read&write blocks
97
    je    fs_read
98
    cmp   dword [eax+0],2       ; DELETE - dont care about read&write blocks
99
    je    fs_read
100
 
101
    cmp   dword [0x3000],1      ; no memory checks for kernel requests
102
    jz    no_checks_for_kernel
103
    mov   edx,eax
104
    cmp   dword [eax+0],1
105
    jnz   .usual_check
106
    mov   ebx,[eax+12]
107
    add   ebx,std_application_base_address
108
    mov   ecx,[eax+8]
109
    call  check_region
110
    test  eax,eax
111
    jnz   area_in_app_mem
112
 
113
.error_output:
114
    mov   esi,buffer_failed
115
    call  sys_msg_board_str
116
;    mov   eax,7
117
    mov   dword [esp+36],7
118
    ret
119
iglobal
120
  buffer_failed db 'K : Buffer check failed',13,10,0
121
endg
122
.usual_check:
123
    cmp   dword [eax+0],0
124
    mov   ecx,512
125
    jnz   .small_size
126
    mov   ecx,[eax+8]
127
    shl   ecx,9
128
.small_size:
129
    mov   ebx,[eax+12]
130
    add   ebx,std_application_base_address
131
    call  check_region
132
    test  eax,eax
133
    jz    .error_output
134
  area_in_app_mem:
135
    mov   eax,edx
136
  no_checks_for_kernel:
137
 
138
  fs_read:
139
 
140
    mov   ebx,[eax+20]          ; program wants root directory ?
141
    test  bl,bl
142
    je    fs_getroot
143
    test  bh,bh
144
    jne   fs_noroot
145
  fs_getroot:
146
; \begin{diamond}[18.03.2006]
147
; root - only read is allowed
148
; other operations return "access denied", eax=10
149
; (execute operation returns eax=-10)
150
    cmp    dword [eax], 0
151
    jz    .read_root
152
    mov    ecx, 10
153
    cmp    dword [eax], 16
154
    jnz    @f
155
    neg    ecx
156
@@:    mov    [esp+36], ecx
157
    ret
158
.read_root:
159
; \end{diamond}[18.03.2006]
160
    mov   esi,dir0
161
    mov   edi,[eax+12]
162
    add   edi,std_application_base_address
163
    mov   ecx,11
164
    push  ecx
165
;    cld    ; already is
166
    rep   movsb
167
    mov   al,0x10
168
    stosb
169
    add   edi,32-11-1
170
    pop   ecx
171
    rep   movsb
172
    stosb
173
    and   dword [esp+36],0      ; ok read
174
    mov   dword [esp+24],32*2   ; size of root
175
    ret
176
 
177
  fs_info:                      ;start of code - Mihasik
178
    push  eax
179
    cmp   [eax+21],byte 'h'
180
    je    fs_info_h
181
    cmp   [eax+21],byte 'H'
182
    je    fs_info_h
183
    cmp   [eax+21],byte 'r'
184
    je    fs_info_r
185
    cmp   [eax+21],byte 'R'
186
    je    fs_info_r
187
    mov   eax,3                 ;if unknown disk
188
    xor   ebx,ebx
189
    xor   ecx,ecx
190
    xor   edx,edx
191
    jmp   fs_info1
192
  fs_info_r:
193
    call  ramdisk_free_space    ;if ramdisk
194
    mov   ecx,edi               ;free space in ecx
195
    shr   ecx,9                 ;free clusters
196
    mov   ebx,2847              ;total clusters
197
    mov   edx,512               ;cluster size
198
    xor   eax,eax               ;always 0
199
    jmp   fs_info1
200
  fs_info_h:                    ;if harddisk
201
    call  get_hd_info
202
  fs_info1:
203
    pop   edi
204
    mov   [esp+36],eax
205
    mov   [esp+24],ebx           ; total clusters on disk
206
    mov   [esp+32],ecx           ; free clusters on disk
207
    mov   [edi],edx              ; cluster size in bytes
208
    ret                          ;end of code - Mihasik
209
 
210
  fs_noroot:
211
 
212
    push  dword [eax+0]         ; read/write/delete/.../makedir/rename/lba/run
213
    push  dword [eax+4]         ; 512 block number to read
214
    push  dword [eax+8]         ; bytes to write/append or 512 blocks to read
215
    mov   ebx,[eax+12]
216
    add   ebx,std_application_base_address
217
    push  ebx                   ; abs start of return/save area
218
 
219
    lea   esi,[eax+20]          ; abs start of dir + filename
220
    mov   edi,[eax+16]
221
    add   edi,std_application_base_address    ; abs start of work area
222
 
223
    call  expand_pathz
224
 
225
    push  edi                   ; dir start
226
    push  ebx                   ; name of file start
227
 
228
    mov   eax,[edi+1]
229
    cmp   eax,'RD  '
230
    je    fs_yesramdisk
231
    cmp   eax,'RAMD'
232
    jne   fs_noramdisk
233
 
234
  fs_yesramdisk:
235
 
236
    cmp   byte [edi+1+11],0
237
    je    fs_give_dir1
238
 
239
    mov   eax,[edi+1+12]
240
    cmp   eax,'1   '
241
    je    fs_yesramdisk_first
242
    cmp   eax,'FIRS'
243
    jne   fs_noramdisk
244
 
245
  fs_yesramdisk_first:
246
 
247
    cmp   dword [esp+20],8      ; LBA read ramdisk
248
    jne   fs_no_LBA_read_ramdisk
249
 
250
    mov   eax,[esp+16]          ; LBA block to read
251
    mov   ecx,[esp+8]           ; abs pointer to return area
252
 
253
    call  LBA_read_ramdisk
254
    jmp   file_system_return
255
 
256
 
257
  fs_no_LBA_read_ramdisk:
258
 
259
    cmp   dword [esp+20],0      ; READ
260
    jne   fs_noramdisk_read
261
 
262
    mov   eax,[esp+4]           ; fname
263
    add   eax,2*12+1
264
    mov   ebx,[esp+16]          ; block start
265
    inc   ebx
266
    mov   ecx,[esp+12]          ; block count
267
    mov   edx,[esp+8]           ; return
268
    mov   esi,[esp+0]
269
    sub   esi,eax
270
    add   esi,12+1              ; file name length
271
    call  fileread
272
 
273
    jmp   file_system_return
274
 
275
 
276
  fs_noramdisk_read:
277
 
278
    cmp   dword [esp+20],1      ; WRITE
279
    jne   fs_noramdisk_write
280
 
281
    mov   eax,[esp+4]           ; fname
282
    add   eax,2*12+1
283
    mov   ebx,[esp+8]           ; buffer
284
    mov   ecx,[esp+12]          ; count to write
285
    mov   edx,0                 ; create new
286
    call  filesave
287
 
288
    ; eax=0 ok - eax=1 not enough free space
289
 
290
    jmp   file_system_return
291
 
292
  fs_noramdisk_write:
293
 
294
    cmp   dword [esp+20],16     ; START APPLICATION
295
    jne   fs_noramdisk_start_application
296
 
297
    mov   eax,[esp+4]           ; fname
298
    add   eax,2*12+1
299
 
300
    xor   ebx,ebx               ; parameters to pass
301
    cmp   dword [esp+12],ebx;0
302
    je    no_fl_start_param
303
    mov   ebx, [esp+12]
304
    add   ebx, std_application_base_address
305
  no_fl_start_param:
306
    mov   edx,[esp+16]        ; flags
307
 
308
    call  start_application_fl
309
 
310
    jmp   file_system_startapp_return
311
 
312
  fs_noramdisk_start_application:     ;there's new code - Mihasik
313
    cmp   dword [esp+20],2      ;DELETE
314
    jne   fs_noramdisk_delete
315
    mov   eax,[esp+4]           ; fname
316
    add   eax,2*12+1
317
    call  filedelete
318
    jmp   file_system_return
319
 
320
  fs_noramdisk_delete:
321
  fs_noramdisk:
322
 
323
  ;********************************************************************
324
    mov   eax,[edi+1]
325
    cmp   eax,'FD  '
326
    je    fs_yesflpdisk
327
    cmp   eax,'FLOP'
328
    jne   fs_noflpdisk
329
 
330
  fs_yesflpdisk:
331
    call   reserve_flp
332
 
333
    cmp   byte [edi+1+11],0
334
    je    fs_give_dir1
335
 
336
    mov   eax,[edi+1+12]
337
    cmp   eax,'1   '
338
    je    fs_yesflpdisk_first
339
    cmp   eax,'FIRS'
340
    je    fs_yesflpdisk_first
341
    cmp   eax,'2   '
342
    je    fs_yesflpdisk_second
343
    cmp   eax,'SECO'
344
    jne   fs_noflpdisk
345
    jmp   fs_yesflpdisk_second
346
 
347
  fs_yesflpdisk_first:
348
    mov   [flp_number],1
349
    jmp   fs_yesflpdisk_start
350
  fs_yesflpdisk_second:
351
    mov   [flp_number],2
352
  fs_yesflpdisk_start:
353
    cmp   dword [esp+20],0      ; READ
354
    jne   fs_noflpdisk_read
355
 
356
    mov   eax,[esp+4]           ; fname
357
    add   eax,2*12+1
358
    mov   ebx,[esp+16]          ; block start
359
    inc   ebx
360
    mov   ecx,[esp+12]          ; block count
361
    mov   edx,[esp+8]           ; return
362
    mov   esi,[esp+0]
363
    sub   esi,eax
364
    add   esi,12+1              ; file name length
365
    call  floppy_fileread
366
 
367
    jmp   file_system_return
368
 
369
 
370
  fs_noflpdisk_read:
371
 
372
    cmp   dword [esp+20],1      ; WRITE
373
    jne   fs_noflpdisk_write
374
 
375
    mov   eax,[esp+4]           ; fname
376
    add   eax,2*12+1
377
    mov   ebx,[esp+8]           ; buffer
378
    mov   ecx,[esp+12]          ; count to write
379
    mov   edx,0                 ; create new
380
    call  floppy_filesave
381
 
382
    ; eax=0 ok - eax=1 not enough free space
383
 
384
    jmp   file_system_return
385
 
386
  fs_noflpdisk_write:
387
 
388
    cmp   dword [esp+20],2      ; DELETE
389
    jne   fs_noflpdisk_delete
390
 
391
    mov   eax,[esp+4]           ; fname
392
    add   eax,2*12+1
393
    call  floppy_filedelete
394
    mov   [flp_status],0
395
    jmp   file_system_return
396
 
397
  fs_noflpdisk_delete:
398
    cmp   dword [esp+20],16     ; START APPLICATION
399
    jne   fs_noflpdisk_start_application
400
 
401
    mov   eax,[esp+4]           ; fname
402
    add   eax,2*12+1
403
 
404
    xor   ebx,ebx               ; parameters to pass
405
    cmp   dword [esp+12],ebx;0
406
    je    no_flp_start_param
407
    mov   ebx,[0x3010]
408
    mov   ebx,[ebx+0x10]
409
    add   ebx,[esp+12]
410
 
411
  no_flp_start_param:
412
    mov   edx,[esp+16]        ; flags
413
 
414
    call  start_application_floppy
415
 
416
file_system_startapp_return:
417
    mov    ebx, [esp+24+24]    ; do not modify ebx in application
418
    jmp   file_system_return
419
 
420
  fs_noflpdisk_start_application:
421
 
422
  fs_noflpdisk:
423
  ;*****************************************************************
424
 
425
    mov   eax,[edi+1]
426
    cmp   eax,'HD0 '
427
    je    fs_yesharddisk_IDE0
428
    cmp   eax,'HD1 '
429
    je    fs_yesharddisk_IDE1
430
    cmp   eax,'HD2 '
431
    je    fs_yesharddisk_IDE2
432
    cmp   eax,'HD3 '
433
    je    fs_yesharddisk_IDE3
434
    jmp   old_path_harddisk
435
fs_yesharddisk_IDE0:
436
     call  reserve_hd1
437
     mov  [hdbase],0x1f0
438
     mov  [hdid],0x0
439
     mov  [hdpos],1
440
     jmp  fs_yesharddisk_partition
441
fs_yesharddisk_IDE1:
442
     call  reserve_hd1
443
     mov  [hdbase],0x1f0
444
     mov  [hdid],0x10
445
     mov  [hdpos],2
446
     jmp  fs_yesharddisk_partition
447
fs_yesharddisk_IDE2:
448
     call  reserve_hd1
449
     mov  [hdbase],0x170
450
     mov  [hdid],0x0
451
     mov  [hdpos],3
452
     jmp  fs_yesharddisk_partition
453
fs_yesharddisk_IDE3:
454
     call  reserve_hd1
455
     mov  [hdbase],0x170
456
     mov  [hdid],0x10
457
     mov  [hdpos],4
458
fs_yesharddisk_partition:
459
;    call  choice_necessity_partition
460
;    jmp   fs_yesharddisk_all
461
    jmp   fs_for_new_semantic
462
 
463
choice_necessity_partition:
464
    mov   eax,[edi+1+12]
465
    call  StringToNumber
466
        mov   [fat32part],eax
467
choice_necessity_partition_1:
468
    mov   ecx,[hdpos]
469
    xor   eax,eax
470
    mov   [0xfe10], eax    ; entries in hd cache
471
    mov   edx,0x40002
472
 search_partition_array:
473
    mov   bl,[edx]
474
    movzx ebx,bl
475
    add   eax,ebx
476
    inc   edx
477
    loop  search_partition_array
478
    sub   eax,ebx
479
    add   eax,[fat32part]
480
    dec   eax
481
    xor   edx,edx
482
    imul  eax,100
483
    add   eax,0x4000a
484
    mov   [transfer_adress],eax
485
    call  partition_data_transfer_1
486
    ret
487
 
488
 old_path_harddisk:
489
    mov   eax,[edi+1]
490
    cmp   eax,'HD  '
491
    je    fs_yesharddisk
492
    cmp   eax,'HARD'
493
    jne   fs_noharddisk
494
 
495
  fs_yesharddisk:
496
    cmp   dword [esp+20],8      ; LBA read
497
    jne   fs_no_LBA_read
498
    mov   eax,[esp+16]          ; LBA block to read
499
    lea   ebx,[edi+1+12]        ; pointer to FIRST/SECOND/THIRD/FOURTH
500
    mov   ecx,[esp+8]           ; abs pointer to return area
501
    call  LBA_read
502
    jmp   file_system_return
503
 
504
  fs_no_LBA_read:
505
 
506
    cmp   byte [edi+1+11],0     ; directory read
507
    je    fs_give_dir1
508
    call  reserve_hd1
509
 fs_for_new_semantic:
510
    call  choice_necessity_partition
511
 
512
  fs_yesharddisk_all:
513
    mov   eax,1
514
    cmp    dword [esp+20], 16
515
    jnz    @f
516
    neg    eax
517
@@:    mov    ebx, [esp+24+24]
518
    cmp   [hdpos],0             ; is hd base set?
519
    jz    hd_err_return
520
    cmp   [fat32part],0         ; is partition set?
521
    jnz   @f
522
hd_err_return:
523
    and   [hd1_status], 0
524
    jmp   file_system_return
525
@@:
526
 
527
    cmp   dword [esp+20],0      ; READ
528
    jne   fs_noharddisk_read
529
 
530
    mov   eax,[esp+0]           ; /fname
531
    lea   edi,[eax+12]
532
    mov   byte [eax],0          ; path to asciiz
533
    inc   eax                   ; filename start
534
 
535
    mov   ebx,[esp+12]          ; count to read
536
    mov   ecx,[esp+8]           ; buffer
537
    mov   edx,[esp+4]
538
    add   edx,12*2              ; dir start
539
    sub   edi,edx               ; path length
540
    mov   esi,[esp+16]          ; blocks to read
541
 
542
    call  file_read
543
 
544
    mov   edi,[esp+0]
545
    mov   byte [edi],'/'
546
 
547
    jmp   file_system_return
548
 
549
  fs_noharddisk_read:
550
 
551
 
552
    cmp   dword [esp+20],1      ; WRITE
553
    jne   fs_noharddisk_write
554
 
555
    mov   eax,[esp+0]           ; /fname
556
    mov   byte [eax],0          ; path to asciiz
557
    inc   eax                   ; filename start
558
 
559
    mov   ebx,[esp+12]          ; count to write
560
    mov   ecx,[esp+8]           ; buffer
561
    mov   edx,[esp+4]
562
    add   edx,12*2              ; path start
563
 
564
    call  file_write
565
 
566
    mov   edi,[esp+0]
567
    mov   byte [edi],'/'
568
 
569
    ; eax=0 ok - eax=1 not enough free space
570
 
571
    jmp   file_system_return
572
 
573
 
574
  fs_noharddisk_write:
575
 
576
    cmp   dword [esp+20],2      ; DELETE
577
    jne   fs_noharddisk_delete
578
 
579
    mov   eax,[esp+0]           ; /dirname or /filename
580
    mov   byte [eax],0          ; path to asciiz
581
    inc   eax                   ; filename start
582
    mov   edx,[esp+4]
583
    add   edx,12*2              ; path start
584
 
585
    call  removedir
586
 
587
    mov   edi,[esp+0]
588
    mov   byte [edi],'/'
589
 
590
    jmp   file_system_return
591
 
592
  fs_noharddisk_delete:
593
 
594
    cmp   dword [esp+20],4      ; MAKEDIR
595
    jne   fs_noharddisk_makedir
596
 
597
    mov   eax,[esp+0]           ; /dirname
598
    mov   byte [eax],0          ; path to asciiz
599
    inc   eax                   ; filename start
600
    mov   edx,[esp+4]
601
    add   edx,12*2              ; path start
602
 
603
    call  makedir
604
 
605
    mov   edi,[esp+0]
606
    mov   byte [edi],'/'
607
 
608
    jmp   file_system_return
609
 
610
  fs_noharddisk_makedir:
611
 
612
    cmp   dword [esp+20],5      ; RENAME
613
    jne   fs_noharddisk_rename
614
 
615
    mov   edi,[esp+0]           ; start of source file name
616
    add   edi,12+1              ; continue after name
617
    call  expand_pathz          ; convert destination name
618
 
619
    mov   eax,[edi+1]
620
    cmp   eax,'HD  '
621
    je    fs_rename_test1
622
    cmp   eax,'HARD'
623
    jne   fs_rename_error
624
 
625
  fs_rename_test1:
626
    mov   eax,[edi+1+12]
627
    cmp   eax,'1   '
628
    je    fs_rename_start
629
    cmp   eax,'FIRS'
630
    jne   fs_rename_error
631
 
632
  fs_rename_start:
633
    mov   byte [ebx],0          ; path to asciiz
634
    inc   ebx                   ; filename start
635
    add   edi,12*2              ; path start
636
    cmp   byte [ebx],0
637
    je    fs_rename_error
638
    cmp   byte [ebx],32
639
    je    fs_rename_error
640
 
641
    mov   eax,[esp+0]           ; /filename
642
    mov   byte [eax],0          ; path to asciiz
643
    inc   eax                   ; filename start
644
    mov   edx,[esp+4]
645
    add   edx,12*2              ; path start
646
 
647
    call  rename
648
 
649
    mov   edi,[esp+0]
650
    mov   byte [edi],'/'
651
 
652
    jmp   file_system_return
653
 
654
  fs_rename_error:
655
    mov   eax,4                 ; partition not defined at hd
656
    jmp   file_system_return
657
 
658
  fs_noharddisk_rename:
659
 
660
    cmp   dword [esp+20],16     ; START APPLICATION
661
    jne   fs_noharddisk_start_application
662
 
663
    mov   eax,[esp+4]           ; fname
664
    add   eax,12*2
665
 
666
    mov   ebx,[esp+0]           ; length
667
    sub   ebx,eax
668
    add   ebx,12
669
 
670
    mov   ecx,[esp+4]           ; work area
671
    add   ecx,512
672
 
673
    xor   ebp,ebp               ; parameters to pass
674
    cmp   dword [esp+12],ebp;0
675
    je    no_hd_start_param
676
    mov   ebp, [esp+12]
677
    add   ebp, std_application_base_address
678
  no_hd_start_param:
679
    mov   edx,[esp+16]        ; flags
680
 
681
    call  start_application_hd
682
 
683
    jmp   file_system_startapp_return
684
 
685
  fs_noharddisk_start_application:
686
 
687
  fs_noharddisk:
688
; \begin{diamond}[18.03.2006]
689
    mov    eax, 5        ; file not found
690
;   ,    ?
691
    cmp    dword [esp+20], 16
692
    jnz    @f
693
    neg    eax
694
@@:    mov    ebx, [esp+24+24]    ; do not change ebx in application
695
; \end{diamond}[18.03.2006]
696
 
697
  file_system_return:
698
 
699
    add   esp,24
700
 
701
    mov   [esp+36],eax
702
    mov   [esp+24],ebx
703
    ret
704
 
705
 
706
  fs_give_dir1:
707
 
708
; \begin{diamond}[18.03.2006]
709
; /RD,/FD,/HD - only read is allowed
710
; other operations return "access denied", eax=10
711
; (execute operation returns eax=-10)
712
    cmp    dword [esp+20], 0
713
    jz    .read
714
    add    esp, 20
715
    pop    ecx
716
    mov    eax, 10
717
    cmp    ecx, 16
718
    jnz    @f
719
    neg    eax
720
@@:    mov    [esp+36], eax
721
    ret
722
.read:
723
; \end{diamond}[18.03.2006]
724
    mov   al,0x10
725
    mov   ebx,1
726
    mov   edi,[esp+8]
727
    mov   esi,dir1
728
  fs_d1_new:
729
    mov   ecx,11
730
;    cld
731
    rep   movsb
732
    stosb
733
    add   edi,32-11-1
734
    dec   ebx
735
    jne   fs_d1_new
736
 
737
    add   esp,24
738
 
739
    and   dword [esp+36],0      ; ok read
740
    mov   dword [esp+24],32*1   ; dir/data size
741
    ret
742
 
743
 
744
 
745
LBA_read_ramdisk:
746
 
747
    cmp   [lba_read_enabled],1
748
    je    lbarrl1
749
 
750
    xor   ebx,ebx
751
    mov   eax,2
752
    ret
753
 
754
  lbarrl1:
755
 
756
    cmp   eax,18*2*80
757
    jb    lbarrl2
758
    xor   ebx,ebx
759
    mov   eax,3
760
    ret
761
 
762
  lbarrl2:
763
 
764
    pushad
765
 
766
    call  restorefatchain
767
 
768
    mov   edi,ecx
769
    mov   esi,eax
770
 
771
    shl   esi,9
772
    add   esi,0x100000
773
    mov   ecx,512/4
774
;    cld
775
    rep   movsd
776
 
777
    popad
778
 
779
    xor   ebx,ebx
780
    xor   eax,eax
781
    ret
782
 
783
LBA_read:
784
 
785
; IN:
786
;
787
; eax = LBA block to read
788
; ebx = pointer to FIRST/SECOND/THIRD/FOURTH
789
; ecx = abs pointer to return area
790
 
791
    cmp   [lba_read_enabled],1
792
    je    lbarl1
793
    mov   eax,2
794
    ret
795
 
796
  lbarl1:
797
 
798
    call  reserve_hd1
799
 
800
    push  eax
801
    push  ecx
802
 
803
    mov   edi,hd_address_table
804
    mov   esi,dir1
805
    mov   eax,[ebx]
806
    mov   edx,'1   '
807
    mov   ecx,4
808
  blar0:
809
    cmp   eax,[esi]
810
    je    blar2
811
    cmp   eax,edx
812
    je    blar2
813
    inc   edx
814
    add   edi,8
815
    add   esi,11
816
    dec   ecx
817
    jnz   blar0
818
 
819
    mov   eax,1
820
    mov   ebx,1
821
    jmp   LBA_read_ret
822
 
823
  blar2:
824
    mov   eax,[edi+0]
825
    mov   ebx,[edi+4]
826
 
827
    mov  [hdbase],eax
828
    mov  [hdid],ebx
829
 
830
    call  wait_for_hd_idle
831
    cmp   [hd_error],0
832
    jne   hd_lba_error
833
 
834
    ; eax = hd port
835
    ; ebx = set for primary (0x00) or slave (0x10)
836
 
837
    cli
838
 
839
    mov   edx,eax
840
    inc   edx
841
    xor   eax,eax
842
    out   dx,al
843
    inc   edx
844
    inc   eax
845
    out   dx,al
846
    inc   edx
847
    mov   eax,[esp+4]
848
    out   dx,al
849
    shr   eax,8
850
    inc   edx
851
    out   dx,al
852
    shr   eax,8
853
    inc   edx
854
    out   dx,al
855
    shr   eax,8
856
    inc   edx
857
    and   al,1+2+4+8
858
    add   al,bl
859
    add   al,128+64+32
860
    out   dx,al
861
 
862
    inc   edx
863
    mov   al,20h
864
    out   dx,al
865
 
866
    sti
867
 
868
    call  wait_for_sector_buffer
869
    cmp   [hd_error],0
870
    jne   hd_lba_error
871
 
872
    cli
873
 
874
    mov   edi,[esp+0]
875
    mov   ecx,256
876
    sub   edx,7
877
    cld
878
    rep   insw
879
 
880
    sti
881
 
882
    xor   eax,eax
883
    xor   ebx,ebx
884
 
885
  LBA_read_ret:
886
    mov [hd_error],0
887
    mov   [hd1_status],0
888
    add   esp,2*4
889
 
890
    ret
891
 
892
 
893
expand_pathz:
894
; IN:
895
;   esi = asciiz path & file
896
;   edi = buffer for path & file name
897
; OUT:
898
;   edi = directory & file : / 11 + / 11 + / 11 - zero terminated
899
;   ebx = /file name - zero terminated
900
;   esi = pointer after source
901
 
902
    push  eax
903
    push  ecx
904
    push  edi ;[esp+0]
905
 
906
  pathz_start:
907
    mov   byte [edi],'/'
908
    inc   edi
909
    mov   al,32
910
    mov   ecx,11
911
    cld
912
    rep   stosb                 ; clear filename area
913
    sub   edi,11
914
    mov   ebx,edi               ; start of dir/file name
915
 
916
  pathz_new_char:
917
    mov   al,[esi]
918
    inc   esi
919
    cmp   al,0
920
    je    pathz_end
921
 
922
    cmp   al,'/'
923
    jne   pathz_not_path
924
    cmp   edi,ebx               ; skip first '/'
925
    jz    pathz_new_char
926
    lea   edi,[ebx+11]          ; start of next directory
927
    jmp   pathz_start
928
 
929
  pathz_not_path:
930
    cmp   al,'.'
931
    jne   pathz_not_ext
932
    lea   edi,[ebx+8]           ; start of extension
933
    jmp   pathz_new_char
934
 
935
  pathz_not_ext:
936
    cmp   al,'a'
937
    jb    pathz_not_low
938
    cmp   al,'z'
939
    ja    pathz_not_low
940
    sub   al,0x20               ; char to uppercase
941
 
942
  pathz_not_low:
943
    mov   [edi],al
944
    inc   edi
945
    mov   eax,[esp+0]           ; start_of_dest_path
946
    add   eax,512               ; keep maximum path under 512 bytes
947
    cmp   edi,eax
948
    jb    pathz_new_char
949
 
950
  pathz_end:
951
    cmp   ebx,edi               ; if path end with '/'
952
    jnz   pathz_put_zero        ; go back 1 level
953
    sub   ebx,12
954
 
955
  pathz_put_zero:
956
    mov   byte [ebx+11],0
957
    dec   ebx                   ; include '/' char into file name
958
    pop   edi
959
    pop   ecx
960
    pop   eax
961
    ret
962
 
963
;*******************************************
964
;* string to number
965
;* input eax - 4 byte string
966
;* output eax - number
967
;*******************************************
968
StringToNumber:
969
;         
970
;    :
971
;        EDI -    .     0Dh
972
;    :
973
;        CF -  :
974
;            0 -  ;
975
;            1 - 
976
;         CF=0,  AX - .
977
 
978
    push    bx
979
    push    cx
980
    push    dx
981
    push    edi
982
    mov   [partition_string],eax
983
    mov    edi,partition_string
984
    xor    cx,cx
985
i1:
986
    mov    al,[edi]
987
    cmp    al,32  ;13
988
    je    i_exit
989
;    cmp    al,'0'
990
;    jb    err
991
;    cmp    al,'9'
992
;    ja    err
993
    sub    al,48
994
    shl    cx,1
995
    jc    err
996
    mov    bx,cx
997
    shl    cx,1
998
    jc    err
999
    shl    cx,1
1000
    jc    err
1001
    add    cx,bx
1002
    jc    err
1003
    cbw
1004
    add    cx,ax
1005
    jc    err
1006
i3:
1007
    inc    edi
1008
    jmp    i1
1009
i_exit:
1010
    mov    ax,cx
1011
    clc
1012
i4:
1013
    movzx  eax,ax
1014
    pop    edi
1015
    pop    dx
1016
    pop    cx
1017
    pop    bx
1018
    ret
1019
 
1020
err:
1021
    stc
1022
    jmp    i4
1023
 
1024
partition_string: dd 0
1025
                  db 32