Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
2288 clevermous 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                              ;;
2455 mario79 3
;; Copyright (C) KolibriOS team 2004-2011. All rights reserved. ;;
2288 clevermous 4
;; Distributed under terms of the GNU General Public License    ;;
5
;;                                                              ;;
6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7
 
8
$Revision: 3539 $
9
 
10
 
1410 turbanoff 11
;*************************************************************
2288 clevermous 12
;* 13.02.2010 Find all partition and check supported FS
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
18
;*************************************************************
19
 
20
uglobal
21
align 4
22
 
23
;******************************************************
24
; Please do not change this place - variables  in text
25
; Mario79
26
; START place
27
;******************************************************
28
PARTITION_START      dd 0x3f
29
PARTITION_END        dd 0
30
fs_type              db 0       ; 1=NTFS, 2=EXT2/3, 16=FAT16, 32=FAT32
31
align 4
32
 
33
fs_dependent_data_start:
34
; FATxx data
35
 
2643 clevermous 36
.partition      dd      ?
37
                rb      80
2288 clevermous 38
 
39
fs_dependent_data_end:
40
file_system_data_size = $ - PARTITION_START
41
if file_system_data_size > 96
42
ERROR:
43
       sizeof(file system data) too big!
44
end if
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
63
ERROR:
64
       increase sizeof(fs_dependent_data)!
65
end if
66
end virtual
67
 
68
virtual at fs_dependent_data_start
69
; EXT2 data
70
ext2_data:
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 ?
76
    .root_inode                     dd ?        ; pointer to root inode in memory
77
    .inode_size                     dd ?
78
    .count_pointer_in_block         dd ?        ;  block_size / 4
79
    .count_pointer_in_block_square  dd ?        ; (block_size / 4)**2
3539 clevermous 80
    .ext2_save_block                dd ?    ; блок на глобальную 1 процедуру
81
    .ext2_temp_block                dd ?    ; блок для мелких процедур
82
    .ext2_save_inode                dd ?    ; inode на глобальную процедуру
83
    .ext2_temp_inode                dd ?    ; inode для мелких процедур
1419 turbanoff 84
    .sb                             dd ?    ; superblock
2288 clevermous 85
    .groups_count                   dd ?
86
if $ > fs_dependent_data_end
87
ERROR:
88
       increase sizeof(fs_dependent_data)!
89
end if
90
end virtual
1410 turbanoff 91
 
2288 clevermous 92
;***************************************************************************
93
; End place
94
; Mario79
95
;***************************************************************************
96
endg
97
iglobal
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
117
    db    0x07                  ; NTFS
118
    db    0x27                  ; NTFS, hidden
119
    db    0x83                  ; Linux native file system (ext2fs)
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:
133
; MBR <---------------------
134
; |                         |
135
; |-> PARTITION1          |
136
; |-> EXTENDED PARTITION -        ;not need be second partition
137
; |-> PARTITION3
138
; |-> PARTITION4
139
 
140
set_PARTITION_variables:
141
set_FAT32_variables:        ;deprecated
142
        and     [problem_partition], 0
143
        call    reserve_hd1
144
        call    reserve_hd_channel
145
 
146
        pushad
147
 
148
        cmp     dword [hdpos], 0
149
        je      problem_hd
150
 
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
155
 
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
160
 
161
extended_already_set:
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
167
 
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
181
 
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
186
 
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
1410 turbanoff 193
        add     eax, [ebx+0x1be+8]      ; add relative start
2288 clevermous 194
        ;mov     [PARTITON_START],edx
1410 turbanoff 195
        ;push    edx
2288 clevermous 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
200
                                        ; when file system data will be available
201
        mov     cl, [ebx+0x1be+4]       ; fs_type
202
        ;mov     [fs_type], dl           ; save for FS recognizer (separate FAT vs NTFS)
1410 turbanoff 203
        ;pop     edx
2288 clevermous 204
        jmp     hd_and_partition_ok
1410 turbanoff 205
 
2288 clevermous 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
210
 
211
        inc     ecx
212
        cmp     ecx, [known_part]; is it wanted partition?
213
        jnz     test_primary_partition_2  ; no
214
 
1410 turbanoff 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
 
2288 clevermous 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
230
 
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
235
 
236
        inc     ecx
237
        cmp     ecx, [known_part]; is it wanted partition?
238
        jnz     test_primary_partition_3  ; no
239
 
1410 turbanoff 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]
2288 clevermous 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
1410 turbanoff 254
 
2288 clevermous 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
259
 
260
        inc     ecx
261
        cmp     ecx, [known_part]; is it wanted partition?
262
        jnz     test_ext_partition_0; no
263
 
1410 turbanoff 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
2288 clevermous 269
 
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
279
 
1410 turbanoff 280
test_ext_partition_0:
3539 clevermous 281
        pop     eax         ; просто выкидываем из стека
2288 clevermous 282
        mov     al, [ebx+0x1be+4]; get extended partition type
283
        call    scan_extended_types
284
        jnz     test_ext_partition_1
285
 
286
        mov     eax, [ebx+0x1be+8]; add relative start
287
        test    eax, eax        ; is there extended partition?
288
        jnz     new_mbr         ; yes. read it
289
 
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
294
 
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
298
 
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
 
317
end_partition_chain:
318
    ;mov   [partition_count],ecx
319
 
320
    ;cmp   edx,-1                ; found wanted partition?
321
    ;jnz   hd_and_partition_ok   ; yes. install it
1410 turbanoff 322
    ;jmp   problem_partition_or_fat
323
problem_hd:
2288 clevermous 324
        or      [problem_partition], 2
325
        jmp     return_from_part_set
1410 turbanoff 326
 
2288 clevermous 327
 
328
scan_partition_types:
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
336
 
337
scan_extended_types:
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
345
 
346
problem_fat_dec_count:          ; bootsector is missing or another problem
347
;    dec   [partition_count]     ; remove it from partition_count
348
 
349
problem_partition_or_fat:
350
        or      [problem_partition], 1
351
 
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
358
 
1410 turbanoff 359
hd_and_partition_ok:
360
 
361
;eax = PARTITION_START edx=PARTITION_LENGTH cl=fs_type
2288 clevermous 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
1410 turbanoff 368
 
2288 clevermous 369
   ;     mov     edx, [PARTITION_END]
370
   ;     sub     edx, eax
3539 clevermous 371
   ;     inc     edx     ; edx = length of partition зачем оно нам??
2288 clevermous 372
 
373
;    mov   [hd_setup],1
374
        mov     ebx, buffer
375
        call    hd_read         ; read boot sector of partition
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
397
        jnz     problem_fat_dec_count   ; no chance...
398
boot_read_ok:
399
 
400
; if we are running on NTFS, check bootsector
401
 
402
        call    ntfs_test_bootsec      ; test ntfs
403
        jnc     ntfs_setup
404
 
405
        call    ext2_test_superblock   ; test ext2fs
406
        jnc     ext2_setup
407
 
408
        mov     eax, [PARTITION_START]  ;ext2 test changes [buffer]
409
        call    hd_read
410
        cmp     [hd_error], 0
411
        jnz     problem_fat_dec_count
412
 
2643 clevermous 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
2288 clevermous 427
        test    eax, eax
428
        jz      problem_fat_dec_count
2643 clevermous 429
        mov     [fs_dependent_data_start.partition], eax
430
        mov     al, [eax+FAT.fs_type]
431
        mov     [fs_type], al
2288 clevermous 432
 
433
        popad
434
        call    free_hd_channel
435
        mov     [hd1_status], 0 ; free
436
        ret