Subversion Repositories Kolibri OS

Rev

Rev 160 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 160 Rev 171
Line 5... Line 5...
5
;;  FAT16/32 functions for KolibriOS                               ;;
5
;;  FAT16/32 functions for KolibriOS                               ;;
6
;;                                                                 ;;
6
;;                                                                 ;;
7
;;  Copyright 2002 Paolo Minazzi, paolo.minazzi@inwind.it          ;;
7
;;  Copyright 2002 Paolo Minazzi, paolo.minazzi@inwind.it          ;;
8
;;                                                                 ;;
8
;;                                                                 ;;
9
;;  See file COPYING for details                                   ;;
9
;;  See file COPYING for details                                   ;;
-
 
10
;;  08.10.2006 LFN delete file/folder - diamond                    ;;
10
;;  20.08.2006 LFN set file size (truncate/extend) - diamond       ;;
11
;;  20.08.2006 LFN set file size (truncate/extend) - diamond       ;;
11
;;  17.08.2006 LFN write/append to file - diamond                  ;;
12
;;  17.08.2006 LFN write/append to file - diamond                  ;;
12
;;  23.06.2006 LFN start application - diamond                     ;;
13
;;  23.06.2006 LFN start application - diamond                     ;;
13
;;  15.06.2006 LFN get/set file/folder info - diamond              ;;
14
;;  15.06.2006 LFN get/set file/folder info - diamond              ;;
14
;;  27.05.2006 LFN create/rewrite file - diamond                   ;;
15
;;  27.05.2006 LFN create/rewrite file - diamond                   ;;
Line 59... Line 60...
59
PUSHAD_EBX equ [esp+16]
60
PUSHAD_EBX equ [esp+16]
60
PUSHAD_EBP equ [esp+8]
61
PUSHAD_EBP equ [esp+8]
61
PUSHAD_ESI equ [esp+4]
62
PUSHAD_ESI equ [esp+4]
62
PUSHAD_EDI equ [esp+0]
63
PUSHAD_EDI equ [esp+0]
Line -... Line 64...
-
 
64
 
-
 
65
uglobal
63
 
66
align 4
64
cluster              dd 0       ; used by file_write,makedir,append
67
cluster              dd 0       ; used by file_write,makedir,append
65
partition_count      dd 0       ; partitions found by set_FAT32_variables
68
partition_count      dd 0       ; partitions found by set_FAT32_variables
66
longname_sec1        dd 0       ; used by analyze_directory to save 2 previous
69
longname_sec1        dd 0       ; used by analyze_directory to save 2 previous
Line 81... Line 84...
81
old_filesize         dd 0       ; used by append
84
old_filesize         dd 0       ; used by append
82
new_filepos          dd 0       ; used by append
85
new_filepos          dd 0       ; used by append
83
bytes2write          dd 0       ; used by append
86
bytes2write          dd 0       ; used by append
Line 84... Line 87...
84
 
87
 
-
 
88
cache_search_start   dd 0       ; used by find_empty_slot
Line -... Line 89...
-
 
89
endg
85
cache_search_start   dd 0       ; used by find_empty_slot
90
 
86
 
91
iglobal
Line 87... Line 92...
87
fat_in_cache         dd -1
92
fat_in_cache         dd -1
-
 
93
endg
-
 
94
 
88
fat_cache:           times 512 db 0
95
uglobal
89
 
96
align 4
90
uglobal
97
fat_cache:           times 512 db 0
91
 Sector512:                      ; label for dev_hdcd.inc
98
 Sector512:                      ; label for dev_hdcd.inc
92
  buffer:              times 512 db 0
99
  buffer:              times 512 db 0
Line 978... Line 985...
978
    jne   make_dir_error_2
985
    jne   make_dir_error_2
979
    mov   [hd1_status],0
986
    mov   [hd1_status],0
980
    xor   eax,eax
987
    xor   eax,eax
981
    ret
988
    ret
Line 982... Line -...
982
 
-
 
983
 
-
 
984
removedir:
-
 
985
;-----------------------------------------------------
-
 
986
; input  : eax = file/directory name
-
 
987
;          edx = path
-
 
988
; output : eax = 0 - ok
-
 
989
;                3 - unknown FS
-
 
990
;                5 - file not found
-
 
991
;               10 - access denied
-
 
992
;-----------------------------------------------------
-
 
993
    cmp   [fat_type],0
-
 
994
    jnz   remove_dir_fat_ok
-
 
995
    mov   eax,ERROR_UNKNOWN_FS
-
 
996
    ret
-
 
997
 
-
 
998
  remove_dir_fat_ok:
-
 
999
;    call  reserve_hd1
-
 
1000
 
-
 
1001
    push  edi
-
 
1002
    mov   edi,1                 ; allow directory remove
-
 
1003
    call  file_delete
-
 
1004
    cmp   [hd_error],0
-
 
1005
    jne   @f
-
 
1006
 
-
 
1007
    pop   edi
-
 
1008
 
-
 
1009
    call  update_disk           ; write all of cache and fat to hd
-
 
1010
  @@:
-
 
1011
    mov   [hd1_status],0
-
 
1012
    ret
-
 
1013
   
-
 
1014
 
989
 
1015
add_disk_free_space:
990
add_disk_free_space:
1016
;-----------------------------------------------------
991
;-----------------------------------------------------
1017
; input  : ecx = cluster count
992
; input  : ecx = cluster count
1018
; Note   : negative = remove clusters from free space
993
; Note   : negative = remove clusters from free space
Line 2338... Line 2313...
2338
        jae     fat16_root_next_sector
2313
        jae     fat16_root_next_sector
2339
        add     edi, 0x20
2314
        add     edi, 0x20
2340
        ret     ; CF=0
2315
        ret     ; CF=0
2341
fat16_root_next_sector:
2316
fat16_root_next_sector:
2342
; read next sector
2317
; read next sector
-
 
2318
        push    [longname_sec2]
-
 
2319
        pop     [longname_sec1]
2343
        push    ecx
2320
        push    ecx
2344
        mov     ecx, [eax+4]
2321
        mov     ecx, [eax+4]
-
 
2322
        push    ecx
-
 
2323
        add     ecx, [ROOT_START]
-
 
2324
        mov     [longname_sec2], ecx
-
 
2325
        pop     ecx
2345
        inc     ecx
2326
        inc     ecx
2346
        mov     [eax+4], ecx
2327
        mov     [eax+4], ecx
2347
        cmp     ecx, [ROOT_SECTORS]
2328
        cmp     ecx, [ROOT_SECTORS]
2348
        pop     ecx
2329
        pop     ecx
2349
        jae     fat16_root_first.readerr
2330
        jae     fat16_root_first.readerr
Line 2389... Line 2370...
2389
        cmp     edi, buffer+0x200-0x20
2370
        cmp     edi, buffer+0x200-0x20
2390
        jae     fat_notroot_next_sector
2371
        jae     fat_notroot_next_sector
2391
        add     edi, 0x20
2372
        add     edi, 0x20
2392
        ret     ; CF=0
2373
        ret     ; CF=0
2393
fat_notroot_next_sector:
2374
fat_notroot_next_sector:
-
 
2375
        push    [longname_sec2]
-
 
2376
        pop     [longname_sec1]
-
 
2377
        push    eax
-
 
2378
        call    fat_get_sector
-
 
2379
        mov     [longname_sec2], eax
-
 
2380
        pop     eax
2394
        push    ecx
2381
        push    ecx
2395
        mov     ecx, [eax+4]
2382
        mov     ecx, [eax+4]
2396
        inc     ecx
2383
        inc     ecx
2397
        cmp     ecx, [SECTORS_PER_CLUSTER]
2384
        cmp     ecx, [SECTORS_PER_CLUSTER]
2398
        jae     fat_notroot_next_cluster
2385
        jae     fat_notroot_next_cluster
Line 3637... Line 3624...
3637
;--------------------------------------------------------------
3624
;--------------------------------------------------------------
Line 3638... Line 3625...
3638
 
3625
 
3639
.flags:
3626
.flags:
3640
        cmp     [fat_type], 0
3627
        cmp     [fat_type], 0
3641
        jnz     @f
3628
        jnz     @f
3642
        mov     eax, ERROR_UNKNOWN_FS
3629
        mov     eax, -ERROR_UNKNOWN_FS
3643
        ret
3630
        ret
3644
@@:
3631
@@:
3645
        cmp     byte [esi], 0
3632
        cmp     byte [esi], 0
3646
        jnz     @f
3633
        jnz     @f
Line 3720... Line 3707...
3720
.err:
3707
.err:
3721
        popad
3708
        popad
3722
        mov     eax, 11
3709
        mov     eax, 11
3723
        ret
3710
        ret
Line -... Line 3711...
-
 
3711
 
-
 
3712
;----------------------------------------------------------------
-
 
3713
;
-
 
3714
;  fs_HdDelete - delete file or empty folder from hard disk
-
 
3715
;
-
 
3716
;  esi  points to filename
-
 
3717
;
-
 
3718
;  ret  eax = 0 ok or other = errormsg
-
 
3719
;
-
 
3720
;--------------------------------------------------------------
-
 
3721
fs_HdDelete:
-
 
3722
        cmp     [fat_type], 0
-
 
3723
        jnz     @f
-
 
3724
        push    ERROR_UNKNOWN_FS
-
 
3725
.pop_ret:
-
 
3726
        pop     eax
-
 
3727
        ret
-
 
3728
@@:
-
 
3729
        cmp     byte [esi], 0
-
 
3730
        jnz     @f
-
 
3731
; cannot delete root!
-
 
3732
.access_denied:
-
 
3733
        push    ERROR_ACCESS_DENIED
-
 
3734
        jmp     .pop_ret
-
 
3735
@@:
-
 
3736
        and     [longname_sec1], 0
-
 
3737
        and     [longname_sec2], 0
-
 
3738
        push    edi
-
 
3739
        call    hd_find_lfn
-
 
3740
        jnc     .found
-
 
3741
        pop     edi
-
 
3742
        push    ERROR_FILE_NOT_FOUND
-
 
3743
        jmp     .pop_ret
-
 
3744
.found:
-
 
3745
        cmp     dword [edi], '.   '
-
 
3746
        jz      .access_denied2
-
 
3747
        cmp     dword [edi], '..  '
-
 
3748
        jz      .access_denied2
-
 
3749
        test    byte [edi+11], 10h
-
 
3750
        jz      .dodel
-
 
3751
; we can delete only empty folders!
-
 
3752
        pushad
-
 
3753
        mov     ebp, [edi+20-2]
-
 
3754
        mov     bp, [edi+26]
-
 
3755
        xor     ecx, ecx
-
 
3756
        lea     eax, [ebp-2]
-
 
3757
        imul    eax, [SECTORS_PER_CLUSTER]
-
 
3758
        add     eax, [DATA_START]
-
 
3759
        mov     ebx, buffer
-
 
3760
        call    hd_read
-
 
3761
        cmp     [hd_error], 0
-
 
3762
        jnz     .err1
-
 
3763
        add     ebx, 2*0x20
-
 
3764
.checkempty:
-
 
3765
        cmp     byte [ebx], 0
-
 
3766
        jz      .empty
-
 
3767
        cmp     byte [ebx], 0xE5
-
 
3768
        jnz     .notempty
-
 
3769
        add     ebx, 0x20
-
 
3770
        cmp     ebx, buffer+0x200
-
 
3771
        jb      .checkempty
-
 
3772
        inc     ecx
-
 
3773
        cmp     ecx, [SECTORS_PER_CLUSTER]
-
 
3774
        jb      @f
-
 
3775
        mov     eax, ebp
-
 
3776
        call    get_FAT
-
 
3777
        cmp     [hd_error], 0
-
 
3778
        jnz     .err1
-
 
3779
        mov     ebp, eax
-
 
3780
        xor     ecx, ecx
-
 
3781
@@:
-
 
3782
        lea     eax, [ebp-2]
-
 
3783
        imul    eax, [SECTORS_PER_CLUSTER]
-
 
3784
        add     eax, [DATA_START]
-
 
3785
        add     eax, ecx
-
 
3786
        mov     ebx, buffer
-
 
3787
        call    hd_read
-
 
3788
        cmp     [hd_error], 0
-
 
3789
        jz      .checkempty
-
 
3790
.err1:
-
 
3791
        popad
-
 
3792
.err2:
-
 
3793
        pop     edi
-
 
3794
        push    11
-
 
3795
        pop     eax
-
 
3796
        ret
-
 
3797
.notempty:
-
 
3798
        popad
-
 
3799
.access_denied2:
-
 
3800
        pop     edi
-
 
3801
        push    ERROR_ACCESS_DENIED
-
 
3802
        pop     eax
-
 
3803
        ret
-
 
3804
.empty:
-
 
3805
        popad
-
 
3806
        push    ebx
-
 
3807
        mov     ebx, buffer
-
 
3808
        call    hd_read
-
 
3809
        pop     ebx
-
 
3810
        cmp     [hd_error], 0
-
 
3811
        jnz     .err2
-
 
3812
.dodel:
-
 
3813
        push    eax
-
 
3814
        mov     eax, [edi+20-2]
-
 
3815
        mov     ax, [edi+26]
-
 
3816
        xchg    eax, [esp]
-
 
3817
; delete folder entry
-
 
3818
        mov     byte [edi], 0xE5
-
 
3819
; delete LFN (if present)
-
 
3820
.lfndel:
-
 
3821
        cmp     edi, buffer
-
 
3822
        ja      @f
-
 
3823
        cmp     [longname_sec2], 0
-
 
3824
        jz      .lfndone
-
 
3825
        push    [longname_sec2]
-
 
3826
        push    [longname_sec1]
-
 
3827
        pop     [longname_sec2]
-
 
3828
        and     [longname_sec1], 0
-
 
3829
        push    ebx
-
 
3830
        mov     ebx, buffer
-
 
3831
        call    hd_write
-
 
3832
        mov     eax, [esp+4]
-
 
3833
        call    hd_read
-
 
3834
        pop     ebx
-
 
3835
        pop     eax
-
 
3836
        mov     edi, buffer+0x200
-
 
3837
@@:
-
 
3838
        sub     edi, 0x20
-
 
3839
        cmp     byte [edi], 0xE5
-
 
3840
        jz      .lfndone
-
 
3841
        cmp     byte [edi+11], 0xF
-
 
3842
        jnz     .lfndone
-
 
3843
        mov     byte [edi], 0xE5
-
 
3844
        jmp     .lfndel
-
 
3845
.lfndone:
-
 
3846
        push    ebx
-
 
3847
        mov     ebx, buffer
-
 
3848
        call    hd_write
-
 
3849
        pop     ebx
-
 
3850
; delete FAT chain
-
 
3851
        pop     eax
-
 
3852
        call    clear_cluster_chain
-
 
3853
        call    update_disk
-
 
3854
        pop     edi
-
 
3855
        xor     eax, eax
-
 
3856
        cmp     [hd_error], 0
-
 
3857
        jz      @f
-
 
3858
        mov     al, 11
-
 
3859
@@:
-
 
3860
        ret
3724
 
3861