Subversion Repositories Kolibri OS

Rev

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

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