Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
431 serge 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                              ;;
2465 Serge 3
;; Copyright (C) KolibriOS team 2004-2011. All rights reserved. ;;
431 serge 4
;; Distributed under terms of the GNU General Public License    ;;
5
;;                                                              ;;
6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7
 
593 mikedld 8
$Revision: 3725 $
9
 
10
 
2434 Serge 11
;*************************************************************
1410 turbanoff 12
;* 13.02.2010 Find all partition and check supported FS
578 mario79 13
;* 12.07.2007 Check all 4 entry of MBR and EMBR
14
;* 29.04.2006 Elimination of hangup after the
15
;*             expiration hd_wait_timeout -  Mario79
16
;* 28.01.2006 find all Fat16/32 partition in all input point
17
;*            to MBR - Mario79
65 mario79 18
;*************************************************************
19
 
277 diamond 20
uglobal
65 mario79 21
align 4
256 diamond 22
 
65 mario79 23
;******************************************************
431 serge 24
; Please do not change this place - variables  in text
65 mario79 25
; Mario79
26
; START place
27
;******************************************************
28
PARTITION_START      dd 0x3f
29
PARTITION_END        dd 0
1410 turbanoff 30
fs_type              db 0       ; 1=NTFS, 2=EXT2/3, 16=FAT16, 32=FAT32
277 diamond 31
align 4
256 diamond 32
 
33
fs_dependent_data_start:
34
; FATxx data
35
 
2987 Serge 36
.partition      dd      ?
37
                rb      80
65 mario79 38
 
256 diamond 39
fs_dependent_data_end:
321 diamond 40
file_system_data_size = $ - PARTITION_START
41
if file_system_data_size > 96
2434 Serge 42
ERROR:
43
       sizeof(file system data) too big!
1379 turbanoff 44
end if
256 diamond 45
 
46
virtual at fs_dependent_data_start
47
; NTFS data
48
ntfs_data:
49
.sectors_per_cluster    dd      ?
50
.mft_cluster            dd      ?
51
.mftmirr_cluster        dd      ?
52
.frs_size               dd      ?       ; FRS size in bytes
53
.iab_size               dd      ?       ; IndexAllocationBuffer size in bytes
54
.frs_buffer             dd      ?
55
.iab_buffer             dd      ?
56
.mft_retrieval          dd      ?
57
.mft_retrieval_size     dd      ?
58
.mft_retrieval_alloc    dd      ?
59
.mft_retrieval_end      dd      ?
60
.cur_index_size         dd      ?
61
.cur_index_buf          dd      ?
62
if $ > fs_dependent_data_end
2434 Serge 63
ERROR:
64
       increase sizeof(fs_dependent_data)!
256 diamond 65
end if
1379 turbanoff 66
end virtual
67
 
1378 turbanoff 68
virtual at fs_dependent_data_start
69
; EXT2 data
70
ext2_data:
1379 turbanoff 71
    .log_block_size                 dd ?
72
    .block_size                     dd ?
73
    .count_block_in_block           dd ?
74
    .blocks_per_group               dd ?
75
    .global_desc_table              dd ?
2434 Serge 76
    .root_inode                     dd ?        ; pointer to root inode in memory
1379 turbanoff 77
    .inode_size                     dd ?
2434 Serge 78
    .count_pointer_in_block         dd ?        ;  block_size / 4
79
    .count_pointer_in_block_square  dd ?        ; (block_size / 4)**2
3725 Serge 80
    .ext2_save_block                dd ?   ;RUS: блок на глобальную 1 процедуру   ;ENG: block for 1 global procedure
81
    .ext2_temp_block                dd ?   ;RUS: блок для мелких процедур         ;ENG: block for small procedures
82
    .ext2_save_inode                dd ?   ;RUS: inode на глобальную процедуру    ;ENG: inode for global procedure
83
    .ext2_temp_inode                dd ?   ;RUS: inode для мелких процедур        ;ENG: inode for small procedures
2434 Serge 84
    .sb                             dd ?    ; superblock
1419 turbanoff 85
    .groups_count                   dd ?
1378 turbanoff 86
if $ > fs_dependent_data_end
2434 Serge 87
ERROR:
88
       increase sizeof(fs_dependent_data)!
1378 turbanoff 89
end if
256 diamond 90
end virtual
1379 turbanoff 91
 
65 mario79 92
;***************************************************************************
93
; End place
94
; Mario79
95
;***************************************************************************
277 diamond 96
endg
97
iglobal
65 mario79 98
 
99
  partition_types:              ; list of fat16/32 partitions
100
    db    0x04                  ; DOS: fat16 <32M
101
    db    0x06                  ; DOS: fat16 >32M
102
    db    0x0b                  ; WIN95: fat32
103
    db    0x0c                  ; WIN95: fat32, LBA-mapped
104
    db    0x0e                  ; WIN95: fat16, LBA-mapped
105
    db    0x14                  ; Hidden DOS: fat16 <32M
106
    db    0x16                  ; Hidden DOS: fat16 >32M
107
    db    0x1b                  ; Hidden WIN95: fat32
108
    db    0x1c                  ; Hidden WIN95: fat32, LBA-mapped
109
    db    0x1e                  ; Hidden WIN95: fat16, LBA-mapped
110
    db    0xc4                  ; DRDOS/secured: fat16 <32M
111
    db    0xc6                  ; DRDOS/secured: fat16 >32M
112
    db    0xcb                  ; DRDOS/secured: fat32
113
    db    0xcc                  ; DRDOS/secured: fat32, LBA-mapped
114
    db    0xce                  ; DRDOS/secured: fat16, LBA-mapped
115
    db    0xd4                  ; Old Multiuser DOS secured: fat16 <32M
116
    db    0xd6                  ; Old Multiuser DOS secured: fat16 >32M
256 diamond 117
    db    0x07                  ; NTFS
1379 turbanoff 118
    db    0x27                  ; NTFS, hidden
1378 turbanoff 119
    db    0x83                  ; Linux native file system (ext2fs)
65 mario79 120
  partition_types_end:
121
 
122
 
123
  extended_types:               ; list of extended partitions
124
    db    0x05                  ; DOS: extended partition
125
    db    0x0f                  ; WIN95: extended partition, LBA-mapped
126
    db    0xc5                  ; DRDOS/secured: extended partition
127
    db    0xd5                  ; Old Multiuser DOS secured: extended partition
128
  extended_types_end:
129
 
130
endg
131
 
132
; Partition chain used:
1379 turbanoff 133
; MBR <---------------------
134
; |                         |
135
; |-> PARTITION1          |
136
; |-> EXTENDED PARTITION -        ;not need be second partition
137
; |-> PARTITION3
138
; |-> PARTITION4
139
 
1378 turbanoff 140
set_PARTITION_variables:
141
set_FAT32_variables:        ;deprecated
2434 Serge 142
        and     [problem_partition], 0
143
        call    reserve_hd1
144
        call    reserve_hd_channel
65 mario79 145
 
2434 Serge 146
        pushad
709 diamond 147
 
2434 Serge 148
        cmp     dword [hdpos], 0
149
        je      problem_hd
65 mario79 150
 
2434 Serge 151
        xor     ecx, ecx        ; partition count
1410 turbanoff 152
    ;or    edx,-1                ; flag for partition
2434 Serge 153
        xor     eax, eax        ; address MBR
154
        xor     ebp, ebp        ; extended partition start
65 mario79 155
 
1378 turbanoff 156
new_mbr:
2434 Serge 157
        test    ebp, ebp        ; is there extended partition? (MBR or EMBR)
158
        jnz     extended_already_set; yes
159
        xchg    ebp, eax        ; no. set it now
65 mario79 160
 
161
extended_already_set:
2434 Serge 162
        add     eax, ebp        ; mbr=mbr+0, ext_part=ext_start+relat_start
163
        mov     ebx, buffer
164
        call    hd_read
165
        cmp     [hd_error], 0
166
        jne     problem_hd
65 mario79 167
 
2434 Serge 168
        cmp     word [ebx+0x1fe], 0xaa55; is it valid boot sector?
169
        jnz     end_partition_chain
170
        push    eax                ; push only one time
171
        cmp     dword [ebx+0x1be+0xc], 0; skip over empty partition
172
        jnz     test_primary_partition_0
173
        cmp     dword [ebx+0x1be+0xc+16], 0
174
        jnz     test_primary_partition_1
175
        cmp     dword [ebx+0x1be+0xc+16+16], 0
176
        jnz     test_primary_partition_2
177
        cmp     dword [ebx+0x1be+0xc+16+16+16], 0
178
        jnz     test_primary_partition_3
179
        pop     eax
180
        jmp     end_partition_chain
1378 turbanoff 181
 
182
test_primary_partition_0:
2434 Serge 183
        mov     al, [ebx+0x1be+4]; get primary partition type
184
        call    scan_partition_types
185
        jnz     test_primary_partition_1; no. skip over
65 mario79 186
 
2434 Serge 187
        inc     ecx
188
        cmp     ecx, [known_part]; is it wanted partition?
189
        jnz     test_primary_partition_1; no
190
 
1410 turbanoff 191
        pop     eax
192
        ;mov     edx, eax                ; start sector
2434 Serge 193
        add     eax, [ebx+0x1be+8]      ; add relative start
1410 turbanoff 194
        ;mov     [PARTITON_START],edx
2434 Serge 195
        ;push    edx
1410 turbanoff 196
        mov     edx, [ebx+0x1be+12]     ; length
197
        ;add     edx, eax                ; add length
198
        ;dec     edx                     ; PARTITION_END is inclusive
199
        ;mov     [PARTITION_END], edx    ; note that this can be changed
256 diamond 200
                                        ; when file system data will be available
1410 turbanoff 201
        mov     cl, [ebx+0x1be+4]       ; fs_type
202
        ;mov     [fs_type], dl           ; save for FS recognizer (separate FAT vs NTFS)
2434 Serge 203
        ;pop     edx
1410 turbanoff 204
        jmp     hd_and_partition_ok
256 diamond 205
 
1378 turbanoff 206
test_primary_partition_1:
2434 Serge 207
        mov     al, [ebx+0x1be+4+16]; get primary partition type
208
        call    scan_partition_types
209
        jnz     test_primary_partition_2  ; no. skip over
65 mario79 210
 
2434 Serge 211
        inc     ecx
212
        cmp     ecx, [known_part]; is it wanted partition?
213
        jnz     test_primary_partition_2  ; no
65 mario79 214
 
2434 Serge 215
        pop     eax
216
        add     eax, [ebx+0x1be+8+16]
217
        mov     edx, [ebx+0x1be+12+16]
218
        mov     cl, [ebx+0x1be+4+16]
219
        jmp     hd_and_partition_ok
220
 
1410 turbanoff 221
        ;mov     edx, eax
222
        ;add     edx, [ebx+0x1be+8+16]
223
        ;push    edx
224
        ;add     edx, [ebx+0x1be+12+16]
225
        ;dec     edx
226
        ;mov     [PARTITION_END], edx
227
        ;mov     al, [ebx+0x1be+4+16]
228
        ;mov     [fs_type], dl
229
        ;pop     edx
65 mario79 230
 
1378 turbanoff 231
test_primary_partition_2:
2434 Serge 232
        mov     al, [ebx+0x1be+4+16+16]; get primary partition type
233
        call    scan_partition_types
234
        jnz     test_primary_partition_3  ; no. skip over
65 mario79 235
 
2434 Serge 236
        inc     ecx
237
        cmp     ecx, [known_part]; is it wanted partition?
238
        jnz     test_primary_partition_3  ; no
239
 
240
        pop     eax
241
        add     eax, [ebx+0x1be+8+16+16]
242
        mov     edx, [ebx+0x1be+12+16+16]
243
        mov     cl, [ebx+0x1be+4+16+16]
1410 turbanoff 244
        jmp     hd_and_partition_ok
245
        ;mov     edx, eax
246
        ;add     edx, [ebx+0x1be+8+16+16]
247
        ;push    edx
248
        ;add     edx, [ebx+0x1be+12+16+16]
249
        ;dec     edx
250
        ;mov     [PARTITION_END], edx
251
        ;mov     al, [ebx+0x1be+4+16+16]
252
        ;mov     [fs_type], dl
253
        ;pop     edx
65 mario79 254
 
1378 turbanoff 255
test_primary_partition_3:
2434 Serge 256
        mov     al, [ebx+0x1be+4+16+16+16]; get primary partition type
257
        call    scan_partition_types
258
        jnz     test_ext_partition_0  ; no. skip over
65 mario79 259
 
2434 Serge 260
        inc     ecx
261
        cmp     ecx, [known_part]; is it wanted partition?
262
        jnz     test_ext_partition_0; no
65 mario79 263
 
2434 Serge 264
        pop     eax
265
        add     eax, [ebx+0x1be+8+16+16+16]
266
        mov     edx, [ebx+0x1be+12+16+16+16]
267
        mov     cl, [ebx+0x1be+4+16+16+16]
268
        jmp     hd_and_partition_ok
269
 
1410 turbanoff 270
        ;mov     edx, eax
271
        ;add     edx, [ebx+0x1be+8+16+16+16]
272
        ;push    edx
273
        ;add     edx, [ebx+0x1be+12+16+16+16]
274
        ;dec     edx
275
        ;mov     [PARTITION_END], edx
276
        ;mov     al, [ebx+0x1be+4+16+16+16]
277
        ;mov     [fs_type], dl
278
        ;pop     edx
65 mario79 279
 
2434 Serge 280
test_ext_partition_0:
3555 Serge 281
        pop     eax         ; просто выкидываем из стека
2434 Serge 282
        mov     al, [ebx+0x1be+4]; get extended partition type
283
        call    scan_extended_types
284
        jnz     test_ext_partition_1
65 mario79 285
 
2434 Serge 286
        mov     eax, [ebx+0x1be+8]; add relative start
287
        test    eax, eax        ; is there extended partition?
288
        jnz     new_mbr         ; yes. read it
65 mario79 289
 
1378 turbanoff 290
test_ext_partition_1:
2434 Serge 291
        mov     al, [ebx+0x1be+4+16]; get extended partition type
292
        call    scan_extended_types
293
        jnz     test_ext_partition_2
65 mario79 294
 
2434 Serge 295
        mov     eax, [ebx+0x1be+8+16]; add relative start
296
        test    eax, eax        ; is there extended partition?
297
        jnz     new_mbr         ; yes. read it
65 mario79 298
 
1378 turbanoff 299
test_ext_partition_2:
2434 Serge 300
        mov     al, [ebx+0x1be+4+16+16]; get extended partition type
301
        call    scan_extended_types
302
        jnz     test_ext_partition_3
65 mario79 303
 
2434 Serge 304
        mov     eax, [ebx+0x1be+8+16+16]; add relative start
305
        test    eax, eax        ; is there extended partition?
306
        jnz     new_mbr         ; yes. read it
1378 turbanoff 307
 
308
test_ext_partition_3:
2434 Serge 309
        mov     al, [ebx+0x1be+4+16+16+16]; get extended partition type
310
        call    scan_extended_types
311
        jnz     end_partition_chain; no. end chain
65 mario79 312
 
2434 Serge 313
        mov     eax, [ebx+0x1be+8+16+16+16]; get start of extended partition
314
        test    eax, eax        ; is there extended partition?
315
        jnz     new_mbr         ; yes. read it
1378 turbanoff 316
 
65 mario79 317
end_partition_chain:
1410 turbanoff 318
    ;mov   [partition_count],ecx
65 mario79 319
 
1410 turbanoff 320
    ;cmp   edx,-1                ; found wanted partition?
321
    ;jnz   hd_and_partition_ok   ; yes. install it
2434 Serge 322
    ;jmp   problem_partition_or_fat
323
problem_hd:
324
        or      [problem_partition], 2
325
        jmp     return_from_part_set
65 mario79 326
 
1410 turbanoff 327
 
65 mario79 328
scan_partition_types:
2434 Serge 329
        push    ecx
330
        mov     edi, partition_types
331
        mov     ecx, partition_types_end-partition_types
332
        cld
333
        repne scasb             ; is partition type ok?
334
        pop     ecx
335
        ret
65 mario79 336
 
337
scan_extended_types:
2434 Serge 338
        push    ecx
339
        mov     edi, extended_types
340
        mov     ecx, extended_types_end-extended_types
341
        cld
342
        repne scasb             ; is it extended partition?
343
        pop     ecx
344
        ret
65 mario79 345
 
346
problem_fat_dec_count:          ; bootsector is missing or another problem
1410 turbanoff 347
;    dec   [partition_count]     ; remove it from partition_count
65 mario79 348
 
349
problem_partition_or_fat:
2434 Serge 350
        or      [problem_partition], 1
351
 
1410 turbanoff 352
return_from_part_set:
2434 Serge 353
        popad
1410 turbanoff 354
    ;mov   [fs_type],0
2434 Serge 355
        call    free_hd_channel
356
        mov     [hd1_status], 0 ; free
357
        ret
65 mario79 358
 
2434 Serge 359
hd_and_partition_ok:
360
 
361
;eax = PARTITION_START edx=PARTITION_LENGTH cl=fs_type
362
        mov     [fs_type], cl
1410 turbanoff 363
    ;mov   eax,edx
2434 Serge 364
        mov     [PARTITION_START], eax
365
        add     edx, eax
366
        dec     edx
367
        mov     [PARTITION_END], edx
65 mario79 368
 
1410 turbanoff 369
   ;     mov     edx, [PARTITION_END]
370
   ;     sub     edx, eax
3555 Serge 371
   ;     inc     edx     ; edx = length of partition зачем оно нам??
1410 turbanoff 372
 
256 diamond 373
;    mov   [hd_setup],1
2434 Serge 374
        mov     ebx, buffer
375
        call    hd_read         ; read boot sector of partition
256 diamond 376
        cmp     [hd_error], 0
377
        jz      boot_read_ok
378
        cmp     [fs_type], 7
379
        jnz     problem_fat_dec_count
380
; NTFS duplicates bootsector:
381
; NT4/2k/XP+ saves bootsector copy in the end of disk
382
; NT 3.51 saves bootsector copy in the middle of disk
383
        and     [hd_error], 0
384
        mov     eax, [PARTITION_END]
385
        call    hd_read
386
        cmp     [hd_error], 0
387
        jnz     @f
388
        call    ntfs_test_bootsec
389
        jnc     boot_read_ok
390
@@:
391
        and     [hd_error], 0
392
        mov     eax, edx
393
        shr     eax, 1
394
        add     eax, [PARTITION_START]
395
        call    hd_read
396
        cmp     [hd_error], 0
1378 turbanoff 397
        jnz     problem_fat_dec_count   ; no chance...
256 diamond 398
boot_read_ok:
1378 turbanoff 399
 
256 diamond 400
; if we are running on NTFS, check bootsector
74 mario79 401
 
1378 turbanoff 402
        call    ntfs_test_bootsec      ; test ntfs
1379 turbanoff 403
        jnc     ntfs_setup
404
 
405
        call    ext2_test_superblock   ; test ext2fs
1410 turbanoff 406
        jnc     ext2_setup
1379 turbanoff 407
 
2434 Serge 408
        mov     eax, [PARTITION_START]  ;ext2 test changes [buffer]
1410 turbanoff 409
        call    hd_read
1379 turbanoff 410
        cmp     [hd_error], 0
1410 turbanoff 411
        jnz     problem_fat_dec_count
1378 turbanoff 412
 
2987 Serge 413
        push    0
414
        mov     eax, [PARTITION_END]
415
        sub     eax, [PARTITION_START]
416
        inc     eax
417
        push    eax
418
        push    0
419
        push    [PARTITION_START]
420
        push    ebp
421
        push    ebp
422
        mov     ebp, esp
423
        mov     esi, 'old'      ; special value: there is no DISK structure
424
        push    1       ; bootsector read successfully
425
        call    fat_create_partition
426
        add     esp, 4*7
2434 Serge 427
        test    eax, eax
428
        jz      problem_fat_dec_count
2987 Serge 429
        mov     [fs_dependent_data_start.partition], eax
430
        mov     al, [eax+FAT.fs_type]
431
        mov     [fs_type], al
65 mario79 432
 
2434 Serge 433
        popad
434
        call    free_hd_channel
435
        mov     [hd1_status], 0 ; free
436
        ret