Subversion Repositories Kolibri OS

Rev

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

Rev 3681 Rev 3742
Line 3... Line 3...
3
;; Copyright (C) KolibriOS team 2011-2012. All rights reserved. ;;
3
;; Copyright (C) KolibriOS team 2011-2012. All rights reserved. ;;
4
;; Distributed under terms of the GNU General Public License    ;;
4
;; Distributed under terms of the GNU General Public License    ;;
5
;;                                                              ;;
5
;;                                                              ;;
6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 7... Line 7...
7
 
7
 
Line 8... Line 8...
8
$Revision: 3681 $
8
$Revision: 3742 $
9
 
9
 
10
; =============================================================================
10
; =============================================================================
11
; ================================= Constants =================================
11
; ================================= Constants =================================
Line 184... Line 184...
184
; Length of the partition in sectors.
184
; Length of the partition in sectors.
185
        Disk            dd ?
185
        Disk            dd ?
186
; Pointer to parent DISK structure.
186
; Pointer to parent DISK structure.
187
        FSUserFunctions dd ?
187
        FSUserFunctions dd ?
188
; Handlers for the sysfunction 70h. This field is a pointer to the following
188
; Handlers for the sysfunction 70h. This field is a pointer to the following
-
 
189
; array. The first dword is pointer to disconnect handler.
189
; array. The first dword is a number of supported subfunctions, other dwords
190
; The first dword is a number of supported subfunctions, other dwords
190
; point to handlers of corresponding subfunctions.
191
; point to handlers of corresponding subfunctions.
191
; This field is 0 if file system is not recognized.
-
 
192
; ...fs-specific data may follow...
192
; ...fs-specific data may follow...
193
ends
193
ends
Line 194... Line 194...
194
 
194
 
195
; This is an external structure, it represents an entry in the partition table.
195
; This is an external structure, it represents an entry in the partition table.
Line 499... Line 499...
499
        mov     esi, [esi+DISK.Partitions]
499
        mov     esi, [esi+DISK.Partitions]
500
        test    edi, edi
500
        test    edi, edi
501
        jz      .nofree
501
        jz      .nofree
502
.freeloop:
502
.freeloop:
503
        lodsd
503
        lodsd
-
 
504
        mov     ecx, [eax+PARTITION.FSUserFunctions]
504
        call    free
505
        call    dword [ecx]
505
        dec     edi
506
        dec     edi
506
        jnz     .freeloop
507
        jnz     .freeloop
507
.nofree:
508
.nofree:
508
        pop     edi esi
509
        pop     edi esi
509
; 3b. Free the cache.
510
; 3b. Free the cache.
Line 725... Line 726...
725
        jnz     .mbr
726
        jnz     .mbr
726
.notmbr:
727
.notmbr:
727
; 10. This is not an  MBR. The media is not partitioned. Create one partition
728
; 10. This is not an  MBR. The media is not partitioned. Create one partition
728
; which covers all the media and abort the loop.
729
; which covers all the media and abort the loop.
729
        stdcall disk_add_partition, 0, 0, \
730
        stdcall disk_add_partition, 0, 0, \
730
                dword [esi+DISK.MediaInfo.Capacity], dword [esi+DISK.MediaInfo.Capacity+4]
731
                dword [esi+DISK.MediaInfo.Capacity], dword [esi+DISK.MediaInfo.Capacity+4], esi
731
        jmp     .done
732
        jmp     .done
732
.mbr:
733
.mbr:
733
; 11. Process all entries of the new MBR/EBR
734
; 11. Process all entries of the new MBR/EBR
734
        lea     ecx, [ebx+0x1be]        ; ecx -> partition table
735
        lea     ecx, [ebx+0x1be]        ; ecx -> partition table
735
        push    0       ; assume no extended partition
736
        push    0       ; assume no extended partition
Line 853... Line 854...
853
        xor     edx, edx
854
        xor     edx, edx
854
        add     eax, [ecx+PARTITION_TABLE_ENTRY.FirstAbsSector]
855
        add     eax, [ecx+PARTITION_TABLE_ENTRY.FirstAbsSector]
855
        adc     edx, 0
856
        adc     edx, 0
856
        push    ecx
857
        push    ecx
857
        stdcall disk_add_partition, eax, edx, \
858
        stdcall disk_add_partition, eax, edx, \
858
                [ecx+PARTITION_TABLE_ENTRY.Length], 0
859
                [ecx+PARTITION_TABLE_ENTRY.Length], 0, esi
859
        pop     ecx
860
        pop     ecx
860
.nothing:
861
.nothing:
861
; 5. Return.
862
; 5. Return.
862
        ret
863
        ret
863
.extended:
864
.extended:
Line 867... Line 868...
867
        ret
868
        ret
Line 868... Line 869...
868
 
869
 
869
; This is an internal function called from disk_scan_partitions and
870
; This is an internal function called from disk_scan_partitions and
870
; process_partition_table_entry. It adds one partition to the list of
871
; process_partition_table_entry. It adds one partition to the list of
-
 
872
; partitions for the media.
-
 
873
; Important note: start, length, disk MUST be present and
-
 
874
; MUST be in the same order as in PARTITION structure.
871
; partitions for the media.
875
; esi duplicates [disk].
872
proc disk_add_partition stdcall uses ebx edi, start:qword, length:qword
876
proc disk_add_partition stdcall uses ebx edi, start:qword, length:qword, disk:dword
873
; 1. Check that this partition will not exceed the limit on total number.
877
; 1. Check that this partition will not exceed the limit on total number.
874
        cmp     [esi+DISK.NumPartitions], MAX_NUM_PARTITIONS
878
        cmp     [esi+DISK.NumPartitions], MAX_NUM_PARTITIONS
875
        jae     .nothing
879
        jae     .nothing
876
; 2. Check that this partition does not overlap with any already registered
880
; 2. Check that this partition does not overlap with any already registered
Line 972... Line 976...
972
; with ebp-based frame arguments start from ebp+8, since [ebp]=saved ebp
976
; with ebp-based frame arguments start from ebp+8, since [ebp]=saved ebp
973
; and [ebp+4]=return address.
977
; and [ebp+4]=return address.
974
virtual at ebp+8
978
virtual at ebp+8
975
.start  dq      ?
979
.start  dq      ?
976
.length dq      ?
980
.length dq      ?
-
 
981
.disk   dd      ?
977
end virtual
982
end virtual
-
 
983
; 1. Read the bootsector to the buffer.
978
; When disk_add_partition is called, ebx contains a pointer to
984
; When disk_add_partition is called, ebx contains a pointer to
979
; a two-sectors-sized buffer. This function saves ebx in the stack
985
; a three-sectors-sized buffer. This function saves ebx in the stack
980
; immediately before ebp.
986
; immediately before ebp.
981
virtual at ebp-4
-
 
982
.buffer dd      ?
987
        mov     ebx, [ebp-4] ; get buffer
983
end virtual
-
 
984
; 1. Read the bootsector to the buffer.
988
        add     ebx, 512     ; advance over MBR data to bootsector data
985
        mov     al, DISKFUNC.read
989
        add     ebp, 8       ; ebp points to part of PARTITION structure
986
        mov     ebx, [.buffer]
990
        xor     eax, eax     ; first sector of the partition
987
        add     ebx, 512
991
        call    fs_read32_sys
988
        push    1
992
        push    eax
989
        stdcall disk_call_driver, ebx, dword [.start], dword [.start+4], esp
-
 
990
; 2. Run tests for all supported filesystems. If at least one test succeeded,
993
; 2. Run tests for all supported filesystems. If at least one test succeeded,
991
; go to 4.
994
; go to 4.
-
 
995
; For tests:
992
; For tests: qword [ebp+8] = partition start, qword [ebp+10h] = partition
996
; ebp -> first three fields of PARTITION structure, .start, .length, .disk;
993
; length, [esp] = 0 if reading bootsector failed or 1 if succeeded,
997
; [esp] = error code after bootsector read: 0 = ok, otherwise = failed,
994
; ebx points to the buffer for bootsector.
998
; ebx points to the buffer for bootsector,
-
 
999
; ebx+512 points to 512-bytes buffer that can be used for anything.
995
        call    fat_create_partition
1000
        call    fat_create_partition
996
        test    eax, eax
1001
        test    eax, eax
997
        jnz     .success
1002
        jnz     .success
-
 
1003
        call    ntfs_create_partition
-
 
1004
        test    eax, eax
-
 
1005
        jnz     .success
-
 
1006
        call    ext2_create_partition
-
 
1007
        test    eax, eax
-
 
1008
        jnz     .success
998
; 3. No file system has recognized the volume, so just allocate the PARTITION
1009
; 3. No file system has recognized the volume, so just allocate the PARTITION
999
; structure without extra fields.
1010
; structure without extra fields.
1000
        movi    eax, sizeof.PARTITION
1011
        movi    eax, sizeof.PARTITION
1001
        call    malloc
1012
        call    malloc
1002
        test    eax, eax
1013
        test    eax, eax
1003
        jz      .nothing
1014
        jz      .nothing
1004
        mov     edx, dword [.start]
1015
        mov     edx, dword [ebp+PARTITION.FirstSector]
1005
        mov     dword [eax+PARTITION.FirstSector], edx
1016
        mov     dword [eax+PARTITION.FirstSector], edx
1006
        mov     edx, dword [.start+4]
1017
        mov     edx, dword [ebp+PARTITION.FirstSector+4]
1007
        mov     dword [eax+PARTITION.FirstSector+4], edx
1018
        mov     dword [eax+PARTITION.FirstSector+4], edx
1008
        mov     edx, dword [.length]
1019
        mov     edx, dword [ebp+PARTITION.Length]
1009
        mov     dword [eax+PARTITION.Length], edx
1020
        mov     dword [eax+PARTITION.Length], edx
1010
        mov     edx, dword [.length+4]
1021
        mov     edx, dword [ebp+PARTITION.Length+4]
1011
        mov     dword [eax+PARTITION.Length+4], edx
1022
        mov     dword [eax+PARTITION.Length+4], edx
1012
        mov     [eax+PARTITION.Disk], esi
1023
        mov     [eax+PARTITION.Disk], esi
1013
        and     [eax+PARTITION.FSUserFunctions], 0
1024
        mov     [eax+PARTITION.FSUserFunctions], default_fs_functions
1014
.success:
1025
.success:
1015
.nothing:
1026
.nothing:
-
 
1027
        sub     ebp, 8 ; restore ebp
1016
; 4. Return with eax = pointer to PARTITION or NULL.
1028
; 4. Return with eax = pointer to PARTITION or NULL.
1017
        pop     ecx
1029
        pop     ecx
1018
        ret
1030
        ret
Line -... Line 1031...
-
 
1031
 
-
 
1032
iglobal
-
 
1033
align 4
-
 
1034
default_fs_functions:
-
 
1035
        dd      free
-
 
1036
        dd      0       ; no user functions
-
 
1037
endg
1019
 
1038
 
1020
; This function is called from file_system_lfn.
1039
; This function is called from file_system_lfn.
1021
; This handler gets the control each time when fn 70 is called
1040
; This handler gets the control each time when fn 70 is called
1022
; with unknown item of root subdirectory.
1041
; with unknown item of root subdirectory.
1023
; in: esi -> name
1042
; in: esi -> name
Line 1198... Line 1217...
1198
        cmp     ecx, [edx+DISK.NumPartitions]
1217
        cmp     ecx, [edx+DISK.NumPartitions]
1199
        jae     .notfound
1218
        jae     .notfound
1200
        mov     eax, [edx+DISK.Partitions]
1219
        mov     eax, [edx+DISK.Partitions]
1201
        mov     eax, [eax+ecx*4]
1220
        mov     eax, [eax+ecx*4]
1202
        mov     edi, [eax+PARTITION.FSUserFunctions]
1221
        mov     edi, [eax+PARTITION.FSUserFunctions]
1203
        test    edi, edi
-
 
1204
        jz      .nofs
-
 
1205
        mov     ecx, [ebx]
1222
        mov     ecx, [ebx]
1206
        cmp     [edi], ecx
1223
        cmp     [edi+4], ecx
1207
        jbe     .unsupported
1224
        jbe     .unsupported
1208
        push    edx
1225
        push    edx
1209
        push    ebp
1226
        push    ebp
1210
        mov     ebp, eax
1227
        mov     ebp, eax
1211
        call    dword [edi+4+ecx*4]
1228
        call    dword [edi+8+ecx*4]
1212
        pop     ebp
1229
        pop     ebp
1213
        pop     edx
1230
        pop     edx
1214
        mov     dword [esp+32], eax
1231
        mov     dword [esp+32], eax
1215
        mov     dword [esp+20], ebx
1232
        mov     dword [esp+20], ebx
1216
.cleanup:
1233
.cleanup:
Line 1223... Line 1240...
1223
        jmp     .cleanup
1240
        jmp     .cleanup
1224
.notfound:
1241
.notfound:
1225
        mov     dword [esp+32], ERROR_FILE_NOT_FOUND
1242
        mov     dword [esp+32], ERROR_FILE_NOT_FOUND
1226
        jmp     .cleanup
1243
        jmp     .cleanup
1227
.unsupported:
1244
.unsupported:
-
 
1245
        cmp     edi, default_fs_functions
-
 
1246
        jz      .nofs
1228
        mov     dword [esp+32], ERROR_UNSUPPORTED_FS
1247
        mov     dword [esp+32], ERROR_UNSUPPORTED_FS
1229
        jmp     .cleanup
1248
        jmp     .cleanup
1230
.nomedia:
1249
.nomedia:
1231
        test    ecx, ecx
1250
        test    ecx, ecx
1232
        jnz     .notfound
1251
        jnz     .notfound