Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
431 serge 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                              ;;
2540 hidnplayr 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
 
2540 hidnplayr 8
$Revision $
593 mikedld 9
 
10
 
65 mario79 11
;*************************************************************
2382 hidnplayr 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
2382 hidnplayr 30
fs_type              db 0       ; 1=NTFS, 2=EXT2/3, 16=FAT16, 32=FAT32
277 diamond 31
align 4
256 diamond 32
 
3359 hidnplayr 33
fs_dependent_data_start:
34
; FATxx data
35
 
36
.partition      dd      ?
37
                rb      80
38
 
39
fs_dependent_data_end:
40
file_system_data_size = $ - PARTITION_START
41
if file_system_data_size > 96
2382 hidnplayr 42
ERROR:
43
       sizeof(file system data) too big!
321 diamond 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
2382 hidnplayr 63
ERROR:
64
       increase sizeof(fs_dependent_data)!
256 diamond 65
end if
66
end virtual
67
 
2382 hidnplayr 68
virtual at fs_dependent_data_start
69
; EXT2 data
70
ext2_data:
71
    .log_block_size                 dd ?
3359 hidnplayr 72
    .block_size                     dd ?
73
    .count_block_in_block           dd ?
74
    .blocks_per_group               dd ?
75
    .global_desc_table              dd ?
76
    .root_inode                     dd ?        ; pointer to root inode in memory
77
    .inode_size                     dd ?
2382 hidnplayr 78
    .count_pointer_in_block         dd ?        ;  block_size / 4
79
    .count_pointer_in_block_square  dd ?        ; (block_size / 4)**2
80
    .ext2_save_block                dd ?    ; блок на глобальную 1 процедуру
81
    .ext2_temp_block                dd ?    ; блок для мелких процедур
82
    .ext2_save_inode                dd ?    ; inode на глобальную процедуру
83
    .ext2_temp_inode                dd ?    ; inode для мелких процедур
84
    .sb                             dd ?    ; superblock
85
    .groups_count                   dd ?
86
if $ > fs_dependent_data_end
87
ERROR:
88
       increase sizeof(fs_dependent_data)!
89
end if
90
end virtual
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
709 diamond 118
    db    0x27                  ; NTFS, hidden
2382 hidnplayr 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:
2382 hidnplayr 133
; MBR <---------------------
134
; |                         |
135
; |-> PARTITION1          |
136
; |-> EXTENDED PARTITION -        ;not need be second partition
137
; |-> PARTITION3
138
; |-> PARTITION4
65 mario79 139
 
2382 hidnplayr 140
set_PARTITION_variables:
141
set_FAT32_variables:        ;deprecated
142
        and     [problem_partition], 0
143
        call    reserve_hd1
144
        call    reserve_hd_channel
65 mario79 145
 
2382 hidnplayr 146
        pushad
709 diamond 147
 
2382 hidnplayr 148
        cmp     dword [hdpos], 0
149
        je      problem_hd
65 mario79 150
 
2382 hidnplayr 151
        xor     ecx, ecx        ; partition count
152
    ;or    edx,-1                ; flag for partition
153
        xor     eax, eax        ; address MBR
154
        xor     ebp, ebp        ; extended partition start
65 mario79 155
 
2382 hidnplayr 156
new_mbr:
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:
2382 hidnplayr 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
 
2382 hidnplayr 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
65 mario79 181
 
2382 hidnplayr 182
test_primary_partition_0:
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
 
2382 hidnplayr 187
        inc     ecx
188
        cmp     ecx, [known_part]; is it wanted partition?
189
        jnz     test_primary_partition_1; no
190
 
191
        pop     eax
192
        ;mov     edx, eax                ; start sector
193
        add     eax, [ebx+0x1be+8]      ; add relative start
194
        ;mov     [PARTITON_START],edx
195
        ;push    edx
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
2382 hidnplayr 201
        mov     cl, [ebx+0x1be+4]       ; fs_type
202
        ;mov     [fs_type], dl           ; save for FS recognizer (separate FAT vs NTFS)
203
        ;pop     edx
204
        jmp     hd_and_partition_ok
256 diamond 205
 
2382 hidnplayr 206
test_primary_partition_1:
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
 
2382 hidnplayr 211
        inc     ecx
212
        cmp     ecx, [known_part]; is it wanted partition?
213
        jnz     test_primary_partition_2  ; no
65 mario79 214
 
2382 hidnplayr 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
65 mario79 220
 
2382 hidnplayr 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
 
2382 hidnplayr 231
test_primary_partition_2:
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
 
2382 hidnplayr 236
        inc     ecx
237
        cmp     ecx, [known_part]; is it wanted partition?
238
        jnz     test_primary_partition_3  ; no
65 mario79 239
 
2382 hidnplayr 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]
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
 
2382 hidnplayr 255
test_primary_partition_3:
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
 
2382 hidnplayr 260
        inc     ecx
261
        cmp     ecx, [known_part]; is it wanted partition?
262
        jnz     test_ext_partition_0; no
65 mario79 263
 
2382 hidnplayr 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
65 mario79 269
 
2382 hidnplayr 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
 
2382 hidnplayr 280
test_ext_partition_0:
281
        pop     eax         ; просто выкидываем из стека
282
        mov     al, [ebx+0x1be+4]; get extended partition type
283
        call    scan_extended_types
284
        jnz     test_ext_partition_1
65 mario79 285
 
2382 hidnplayr 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
 
2382 hidnplayr 290
test_ext_partition_1:
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
 
2382 hidnplayr 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
 
2382 hidnplayr 299
test_ext_partition_2:
300
        mov     al, [ebx+0x1be+4+16+16]; get extended partition type
301
        call    scan_extended_types
302
        jnz     test_ext_partition_3
303
 
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
307
 
308
test_ext_partition_3:
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
312
 
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
316
 
65 mario79 317
end_partition_chain:
2382 hidnplayr 318
    ;mov   [partition_count],ecx
65 mario79 319
 
2382 hidnplayr 320
    ;cmp   edx,-1                ; found wanted partition?
321
    ;jnz   hd_and_partition_ok   ; yes. install it
322
    ;jmp   problem_partition_or_fat
323
problem_hd:
324
        or      [problem_partition], 2
325
        jmp     return_from_part_set
65 mario79 326
 
2382 hidnplayr 327
 
65 mario79 328
scan_partition_types:
2382 hidnplayr 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:
2382 hidnplayr 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
2382 hidnplayr 347
;    dec   [partition_count]     ; remove it from partition_count
65 mario79 348
 
349
problem_partition_or_fat:
2382 hidnplayr 350
        or      [problem_partition], 1
65 mario79 351
 
2382 hidnplayr 352
return_from_part_set:
353
        popad
354
    ;mov   [fs_type],0
355
        call    free_hd_channel
356
        mov     [hd1_status], 0 ; free
357
        ret
65 mario79 358
 
359
hd_and_partition_ok:
360
 
2382 hidnplayr 361
;eax = PARTITION_START edx=PARTITION_LENGTH cl=fs_type
362
        mov     [fs_type], cl
363
    ;mov   eax,edx
364
        mov     [PARTITION_START], eax
365
        add     edx, eax
366
        dec     edx
367
        mov     [PARTITION_END], edx
368
 
369
   ;     mov     edx, [PARTITION_END]
370
   ;     sub     edx, eax
371
   ;     inc     edx     ; edx = length of partition зачем оно нам??
372
 
256 diamond 373
;    mov   [hd_setup],1
2382 hidnplayr 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
2382 hidnplayr 397
        jnz     problem_fat_dec_count   ; no chance...
256 diamond 398
boot_read_ok:
2382 hidnplayr 399
 
256 diamond 400
; if we are running on NTFS, check bootsector
2382 hidnplayr 401
 
402
        call    ntfs_test_bootsec      ; test ntfs
709 diamond 403
        jnc     ntfs_setup
74 mario79 404
 
2382 hidnplayr 405
        call    ext2_test_superblock   ; test ext2fs
406
        jnc     ext2_setup
65 mario79 407
 
2382 hidnplayr 408
        mov     eax, [PARTITION_START]  ;ext2 test changes [buffer]
409
        call    hd_read
3359 hidnplayr 410
        cmp     [hd_error], 0
411
        jnz     problem_fat_dec_count
412
 
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
427
        test    eax, eax
428
        jz      problem_fat_dec_count
429
        mov     [fs_dependent_data_start.partition], eax
430
        mov     al, [eax+FAT.fs_type]
431
        mov     [fs_type], al
432
 
433
        popad
434
        call    free_hd_channel
435
        mov     [hd1_status], 0 ; free
436
        ret