Subversion Repositories Kolibri OS

Rev

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

Rev 1376 Rev 2382
Line 3... Line 3...
3
;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;;
3
;; Copyright (C) KolibriOS team 2004-2007. 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: 1376 $
8
$Revision: 2382 $
-
 
9
 
9
 
10
 
10
 
11
;*************************************************************
11
;*************************************************************
12
;* 13.02.2010 Find all partition and check supported FS
12
;* 12.07.2007 Check all 4 entry of MBR and EMBR
13
;* 12.07.2007 Check all 4 entry of MBR and EMBR
13
;* 29.04.2006 Elimination of hangup after the
14
;* 29.04.2006 Elimination of hangup after the
Line 24... Line 25...
24
; Mario79
25
; Mario79
25
; START place
26
; START place
26
;******************************************************
27
;******************************************************
27
PARTITION_START      dd 0x3f
28
PARTITION_START      dd 0x3f
28
PARTITION_END        dd 0
29
PARTITION_END        dd 0
29
fs_type              db 0       ; 0=none, 1=NTFS, 16=FAT16, 32=FAT32
30
fs_type              db 0       ; 1=NTFS, 2=EXT2/3, 16=FAT16, 32=FAT32
30
align 4
31
align 4
Line 31... Line 32...
31
 
32
 
32
fs_dependent_data_start:
33
fs_dependent_data_start:
Line 52... Line 53...
52
fatStartScan         dd 2
53
fatStartScan         dd 2
Line 53... Line 54...
53
 
54
 
54
fs_dependent_data_end:
55
fs_dependent_data_end:
55
file_system_data_size = $ - PARTITION_START
56
file_system_data_size = $ - PARTITION_START
-
 
57
if file_system_data_size > 96
56
if file_system_data_size > 96
58
ERROR:
57
ERROR: sizeof(file system data) too big!
59
       sizeof(file system data) too big!
Line 58... Line 60...
58
end if
60
end if
59
 
61
 
60
virtual at fs_dependent_data_start
62
virtual at fs_dependent_data_start
Line 72... Line 74...
72
.mft_retrieval_alloc    dd      ?
74
.mft_retrieval_alloc    dd      ?
73
.mft_retrieval_end      dd      ?
75
.mft_retrieval_end      dd      ?
74
.cur_index_size         dd      ?
76
.cur_index_size         dd      ?
75
.cur_index_buf          dd      ?
77
.cur_index_buf          dd      ?
76
if $ > fs_dependent_data_end
78
if $ > fs_dependent_data_end
-
 
79
ERROR:
77
ERROR: increase sizeof(fs_dependent_data)!
80
       increase sizeof(fs_dependent_data)!
-
 
81
end if
-
 
82
end virtual
-
 
83
 
-
 
84
virtual at fs_dependent_data_start
-
 
85
; EXT2 data
-
 
86
ext2_data:
-
 
87
    .log_block_size                 dd ?
-
 
88
    .block_size                     dd ?
-
 
89
    .count_block_in_block           dd ?
-
 
90
    .blocks_per_group               dd ?
-
 
91
    .inodes_per_group               dd ?
-
 
92
    .global_desc_table              dd ?
-
 
93
    .root_inode                     dd ?        ; pointer to root inode in memory
-
 
94
    .inode_size                     dd ?
-
 
95
    .count_pointer_in_block         dd ?        ;  block_size / 4
-
 
96
    .count_pointer_in_block_square  dd ?        ; (block_size / 4)**2
-
 
97
    .ext2_save_block                dd ?    ; ¡«®ª ­  £«®¡ «ì­ãî 1 ¯à®æ¥¤ãàã
-
 
98
    .ext2_temp_block                dd ?    ; ¡«®ª ¤«ï ¬¥«ª¨å ¯à®æ¥¤ãà
-
 
99
    .ext2_save_inode                dd ?    ; inode ­  £«®¡ «ì­ãî ¯à®æ¥¤ãàã
-
 
100
    .ext2_temp_inode                dd ?    ; inode ¤«ï ¬¥«ª¨å ¯à®æ¥¤ãà
-
 
101
    .sb                             dd ?    ; superblock
-
 
102
    .groups_count                   dd ?
-
 
103
if $ > fs_dependent_data_end
-
 
104
ERROR:
-
 
105
       increase sizeof(fs_dependent_data)!
78
end if
106
end if
79
end virtual
107
end virtual
Line 80... Line 108...
80
 
108
 
81
;***************************************************************************
109
;***************************************************************************
Line 103... Line 131...
103
    db    0xce                  ; DRDOS/secured: fat16, LBA-mapped
131
    db    0xce                  ; DRDOS/secured: fat16, LBA-mapped
104
    db    0xd4                  ; Old Multiuser DOS secured: fat16 <32M
132
    db    0xd4                  ; Old Multiuser DOS secured: fat16 <32M
105
    db    0xd6                  ; Old Multiuser DOS secured: fat16 >32M
133
    db    0xd6                  ; Old Multiuser DOS secured: fat16 >32M
106
    db    0x07                  ; NTFS
134
    db    0x07                  ; NTFS
107
    db    0x27                  ; NTFS, hidden
135
    db    0x27                  ; NTFS, hidden
-
 
136
    db    0x83                  ; Linux native file system (ext2fs)
108
  partition_types_end:
137
  partition_types_end:
Line 109... Line 138...
109
 
138
 
110
 
139
 
Line 116... Line 145...
116
  extended_types_end:
145
  extended_types_end:
Line 117... Line 146...
117
 
146
 
Line 118... Line 147...
118
endg
147
endg
119
 
-
 
120
; Partition chain used:
-
 
121
; MBR        ;   PARTITION2 ;   PARTITION3 ;   PARTITION4
148
 
122
;==========================================================
149
; Partition chain used:
123
; fat16/32   +-- fat16/32   +-- fat16/32   +-- fat16/32   +--
150
; MBR <---------------------
124
; extended --+   extended --+   extended --+   extended --+
151
; |                         |
125
; 0              0              0              0
152
; |-> PARTITION1          |
126
; 0              0              0              0
-
 
127
; Notes:
153
; |-> EXTENDED PARTITION -        ;not need be second partition
128
; - extended partition need to be in second entry on table
154
; |-> PARTITION3
129
; - it will skip over removed partitions
155
; |-> PARTITION4
-
 
156
 
130
 
157
set_PARTITION_variables:
131
set_FAT32_variables:
158
set_FAT32_variables:        ;deprecated
132
    mov   [problem_partition],0
159
        and     [problem_partition], 0
Line 133... Line 160...
133
    call  reserve_hd1
160
        call    reserve_hd1
Line 134... Line 161...
134
    call  reserve_hd_channel
161
        call    reserve_hd_channel
135
 
162
 
Line 136... Line 163...
136
    pushad
163
        pushad
137
 
164
 
138
    cmp   dword [hdpos],0
165
        cmp     dword [hdpos], 0
139
    je    problem_hd
166
        je      problem_hd
Line 140... Line 167...
140
 
167
 
141
    xor   ecx,ecx               ; partition count
168
        xor     ecx, ecx        ; partition count
142
    mov   edx,-1                ; flag for partition
169
    ;or    edx,-1                ; flag for partition
143
    xor   eax,eax               ; read MBR
170
        xor     eax, eax        ; address MBR
Line 144... Line 171...
144
    xor   ebp,ebp               ; extended partition start
171
        xor     ebp, ebp        ; extended partition start
145
 
172
 
Line 155... Line 182...
155
    cmp  [hd_error],0
182
        cmp     [hd_error], 0
156
    jne  problem_hd
183
        jne     problem_hd
Line 157... Line 184...
157
 
184
 
158
    cmp   word [ebx+0x1fe],0xaa55 ; is it valid boot sector?
185
        cmp     word [ebx+0x1fe], 0xaa55; is it valid boot sector?
-
 
186
        jnz     end_partition_chain
159
    jnz   end_partition_chain
187
        push    eax                ; push only one time
160
    cmp   dword [ebx+0x1be+0xc],0 ; skip over empty partition
-
 
161
;    jz    next_partition
188
        cmp     dword [ebx+0x1be+0xc], 0; skip over empty partition
162
    jnz    .next_primary_partition
189
        jnz     test_primary_partition_0
163
    cmp   dword [ebx+0x1be+0xc+16],0
190
        cmp     dword [ebx+0x1be+0xc+16], 0
164
    jnz    next_primary_partition
191
        jnz     test_primary_partition_1
165
    cmp   dword [ebx+0x1be+0xc+16+16],0
192
        cmp     dword [ebx+0x1be+0xc+16+16], 0
166
    jnz    next_primary_partition_1
193
        jnz     test_primary_partition_2
167
    cmp   dword [ebx+0x1be+0xc+16+16+16],0
194
        cmp     dword [ebx+0x1be+0xc+16+16+16], 0
-
 
195
        jnz     test_primary_partition_3
168
    jnz    next_primary_partition_2
196
        pop     eax
Line 169... Line 197...
169
    jmp   next_partition
197
        jmp     end_partition_chain
170
    
-
 
171
.next_primary_partition:
198
 
172
    push  eax
199
test_primary_partition_0:
173
    mov   al,[ebx+0x1be+4]      ; get primary partition type
-
 
174
    call  scan_partition_types
200
        mov     al, [ebx+0x1be+4]; get primary partition type
Line 175... Line 201...
175
    pop   eax
201
        call    scan_partition_types
176
    jnz   next_primary_partition        ; no. skip over
202
        jnz     test_primary_partition_1; no. skip over
177
 
203
 
Line -... Line 204...
-
 
204
        inc     ecx
178
    inc   ecx
205
        cmp     ecx, [known_part]; is it wanted partition?
179
    cmp   ecx,[fat32part]       ; is it wanted partition?
206
        jnz     test_primary_partition_1; no
-
 
207
 
180
    jnz   next_primary_partition        ; no
208
        pop     eax
181
 
209
        ;mov     edx, eax                ; start sector
-
 
210
        add     eax, [ebx+0x1be+8]      ; add relative start
182
        mov     edx, eax                ; start sector
211
        ;mov     [PARTITON_START],edx
183
        add     edx, [ebx+0x1be+8]      ; add relative start
212
        ;push    edx
184
        push    edx
213
        mov     edx, [ebx+0x1be+12]     ; length
185
        add     edx, [ebx+0x1be+12]     ; add length
214
        ;add     edx, eax                ; add length
186
        dec     edx                     ; PARTITION_END is inclusive
215
        ;dec     edx                     ; PARTITION_END is inclusive
187
        mov     [PARTITION_END], edx    ; note that this can be changed
216
        ;mov     [PARTITION_END], edx    ; note that this can be changed
-
 
217
                                        ; when file system data will be available
Line 188... Line 218...
188
                                        ; when file system data will be available
218
        mov     cl, [ebx+0x1be+4]       ; fs_type
189
        mov     dl, [ebx+0x1be+4]
-
 
190
        mov     [fs_type], dl           ; save for FS recognizer (separate FAT vs NTFS)
219
        ;mov     [fs_type], dl           ; save for FS recognizer (separate FAT vs NTFS)
191
        pop     edx
220
        ;pop     edx
192
 
-
 
193
next_primary_partition:
221
        jmp     hd_and_partition_ok
Line 194... Line 222...
194
    push  eax
222
 
195
    mov   al,[ebx+0x1be+4+16]      ; get primary partition type
223
test_primary_partition_1:
196
    call  scan_partition_types
224
        mov     al, [ebx+0x1be+4+16]; get primary partition type
Line -... Line 225...
-
 
225
        call    scan_partition_types
-
 
226
        jnz     test_primary_partition_2  ; no. skip over
-
 
227
 
-
 
228
        inc     ecx
-
 
229
        cmp     ecx, [known_part]; is it wanted partition?
-
 
230
        jnz     test_primary_partition_2  ; no
197
    pop   eax
231
 
198
    jnz   next_primary_partition_1        ; no. skip over
232
        pop     eax
199
 
233
        add     eax, [ebx+0x1be+8+16]
200
    inc   ecx
234
        mov     edx, [ebx+0x1be+12+16]
201
    cmp   ecx,[fat32part]       ; is it wanted partition?
235
        mov     cl, [ebx+0x1be+4+16]
202
    jnz   next_primary_partition_1        ; no
236
        jmp     hd_and_partition_ok
203
 
237
 
204
        mov     edx, eax
238
        ;mov     edx, eax
205
        add     edx, [ebx+0x1be+8+16]
239
        ;add     edx, [ebx+0x1be+8+16]
Line 206... Line 240...
206
        push    edx
240
        ;push    edx
207
        add     edx, [ebx+0x1be+12+16]
-
 
208
        dec     edx
241
        ;add     edx, [ebx+0x1be+12+16]
209
        mov     [PARTITION_END], edx
242
        ;dec     edx
210
        mov     dl, [ebx+0x1be+4+16]
-
 
211
        mov     [fs_type], dl
243
        ;mov     [PARTITION_END], edx
Line 212... Line 244...
212
        pop     edx
244
        ;mov     al, [ebx+0x1be+4+16]
213
 
245
        ;mov     [fs_type], dl
214
next_primary_partition_1:
246
        ;pop     edx
Line -... Line 247...
-
 
247
 
-
 
248
test_primary_partition_2:
-
 
249
        mov     al, [ebx+0x1be+4+16+16]; get primary partition type
-
 
250
        call    scan_partition_types
-
 
251
        jnz     test_primary_partition_3  ; no. skip over
215
    push  eax
252
 
216
    mov   al,[ebx+0x1be+4+16+16]      ; get primary partition type
253
        inc     ecx
217
    call  scan_partition_types
254
        cmp     ecx, [known_part]; is it wanted partition?
218
    pop   eax
255
        jnz     test_primary_partition_3  ; no
219
    jnz   next_primary_partition_2        ; no. skip over
256
 
220
 
257
        pop     eax
221
    inc   ecx
258
        add     eax, [ebx+0x1be+8+16+16]
222
    cmp   ecx,[fat32part]       ; is it wanted partition?
259
        mov     edx, [ebx+0x1be+12+16+16]
223
    jnz   next_primary_partition_2        ; no
260
        mov     cl, [ebx+0x1be+4+16+16]
Line 224... Line 261...
224
 
261
        jmp     hd_and_partition_ok
225
        mov     edx, eax
-
 
226
        add     edx, [ebx+0x1be+8+16+16]
262
        ;mov     edx, eax
227
        push    edx
263
        ;add     edx, [ebx+0x1be+8+16+16]
228
        add     edx, [ebx+0x1be+12+16+16]
-
 
229
        dec     edx
264
        ;push    edx
Line 230... Line 265...
230
        mov     [PARTITION_END], edx
265
        ;add     edx, [ebx+0x1be+12+16+16]
231
        mov     dl, [ebx+0x1be+4+16+16]
266
        ;dec     edx
232
        mov     [fs_type], dl
267
        ;mov     [PARTITION_END], edx
Line -... Line 268...
-
 
268
        ;mov     al, [ebx+0x1be+4+16+16]
-
 
269
        ;mov     [fs_type], dl
-
 
270
        ;pop     edx
-
 
271
 
-
 
272
test_primary_partition_3:
-
 
273
        mov     al, [ebx+0x1be+4+16+16+16]; get primary partition type
233
        pop     edx
274
        call    scan_partition_types
234
 
275
        jnz     test_ext_partition_0  ; no. skip over
235
next_primary_partition_2:
276
 
236
    push  eax
277
        inc     ecx
237
    mov   al,[ebx+0x1be+4+16+16+16]      ; get primary partition type
278
        cmp     ecx, [known_part]; is it wanted partition?
238
    call  scan_partition_types
279
        jnz     test_ext_partition_0; no
239
    pop   eax
280
 
240
    jnz   next_partition        ; no. skip over
281
        pop     eax
241
 
282
        add     eax, [ebx+0x1be+8+16+16+16]
Line 242... Line 283...
242
    inc   ecx
283
        mov     edx, [ebx+0x1be+12+16+16+16]
243
    cmp   ecx,[fat32part]       ; is it wanted partition?
284
        mov     cl, [ebx+0x1be+4+16+16+16]
244
    jnz   next_partition        ; no
285
        jmp     hd_and_partition_ok
245
 
286
 
246
        mov     edx, eax
-
 
247
        add     edx, [ebx+0x1be+8+16+16+16]
287
        ;mov     edx, eax
Line 248... Line 288...
248
        push    edx
288
        ;add     edx, [ebx+0x1be+8+16+16+16]
249
        add     edx, [ebx+0x1be+12+16+16+16]
289
        ;push    edx
250
        dec     edx
290
        ;add     edx, [ebx+0x1be+12+16+16+16]
Line 251... Line 291...
251
        mov     [PARTITION_END], edx
291
        ;dec     edx
252
        mov     dl, [ebx+0x1be+4+16+16+16]
-
 
253
        mov     [fs_type], dl
292
        ;mov     [PARTITION_END], edx
254
        pop     edx
293
        ;mov     al, [ebx+0x1be+4+16+16+16]
255
 
-
 
256
next_partition:
294
        ;mov     [fs_type], dl
Line 257... Line 295...
257
    push  eax
295
        ;pop     edx
258
    mov   al,[ebx+0x1be+4]   ; get extended partition type
296
 
259
    call  scan_extended_types
297
test_ext_partition_0:
Line 260... Line 298...
260
    pop   eax
298
        pop     eax         ; ¯à®áâ® ¢ëª¨¤ë¢ ¥¬ ¨§ á⥪ 
261
    jnz   next_partition_1
-
 
262
 
299
        mov     al, [ebx+0x1be+4]; get extended partition type
263
    mov   eax,[ebx+0x1be+8]     ; add relative start
300
        call    scan_extended_types
264
    test  eax,eax               ; is there extended partition?
-
 
265
    jnz   new_partition         ; yes. read it
301
        jnz     test_ext_partition_1
Line 266... Line 302...
266
 
302
 
267
next_partition_1:
303
        mov     eax, [ebx+0x1be+8]; add relative start
268
    push  eax
304
        test    eax, eax        ; is there extended partition?
Line 269... Line 305...
269
    mov   al,[ebx+0x1be+4+16]   ; get extended partition type
305
        jnz     new_mbr         ; yes. read it
270
    call  scan_extended_types
-
 
271
    pop   eax
306
 
272
    jnz   next_partition_2
307
test_ext_partition_1:
273
 
-
 
274
    mov   eax,[ebx+0x1be+8+16]     ; add relative start
308
        mov     al, [ebx+0x1be+4+16]; get extended partition type
Line 275... Line 309...
275
    test  eax,eax               ; is there extended partition?
309
        call    scan_extended_types
276
    jnz   new_partition         ; yes. read it
310
        jnz     test_ext_partition_2
277
 
311
 
Line 278... Line 312...
278
next_partition_2:
312
        mov     eax, [ebx+0x1be+8+16]; add relative start
279
    push  eax
313
        test    eax, eax        ; is there extended partition?
-
 
314
        jnz     new_mbr         ; yes. read it
-
 
315
 
-
 
316
test_ext_partition_2:
-
 
317
        mov     al, [ebx+0x1be+4+16+16]; get extended partition type
-
 
318
        call    scan_extended_types
-
 
319
        jnz     test_ext_partition_3
-
 
320
 
Line 280... Line -...
280
    mov   al,[ebx+0x1be+4+16+16]   ; get extended partition type
-
 
281
    call  scan_extended_types
-
 
282
    pop   eax
-
 
Line 283... Line 321...
283
    jnz   next_partition_3
321
        mov     eax, [ebx+0x1be+8+16+16]; add relative start
284
 
322
        test    eax, eax        ; is there extended partition?
285
    mov   eax,[ebx+0x1be+8+16+16]     ; add relative start
323
        jnz     new_mbr         ; yes. read it
286
    test  eax,eax               ; is there extended partition?
324
 
Line 321... Line 359...
321
    repne scasb                 ; is it extended partition?
359
        repne scasb             ; is it extended partition?
322
    pop   ecx
360
        pop     ecx
323
    ret
361
        ret
Line 324... Line 362...
324
 
362
 
325
problem_fat_dec_count:          ; bootsector is missing or another problem
363
problem_fat_dec_count:          ; bootsector is missing or another problem
Line 326... Line 364...
326
    dec   [partition_count]     ; remove it from partition_count
364
;    dec   [partition_count]     ; remove it from partition_count
327
 
365
 
328
problem_partition_or_fat:
-
 
Line -... Line 366...
-
 
366
problem_partition_or_fat:
-
 
367
        or      [problem_partition], 1
329
problem_hd:
368
 
330
    popad
369
return_from_part_set:
331
 
370
        popad
332
    mov   [fs_type],0
-
 
333
    call  free_hd_channel
371
    ;mov   [fs_type],0
Line 334... Line 372...
334
    mov   [hd1_status],0        ; free
372
        call    free_hd_channel
-
 
373
        mov     [hd1_status], 0 ; free
-
 
374
        ret
-
 
375
 
335
    mov   [problem_partition],1
376
hd_and_partition_ok:
336
    ret
377
 
-
 
378
;eax = PARTITION_START edx=PARTITION_LENGTH cl=fs_type
-
 
379
        mov     [fs_type], cl
-
 
380
    ;mov   eax,edx
-
 
381
        mov     [PARTITION_START], eax
337
 
382
        add     edx, eax
338
hd_and_partition_ok:
383
        dec     edx
339
    mov   eax,edx
384
        mov     [PARTITION_END], edx
Line 340... Line 385...
340
    mov   [PARTITION_START],eax
385
 
341
        mov     edx, [PARTITION_END]
386
   ;     mov     edx, [PARTITION_END]
342
        sub     edx, eax
387
   ;     sub     edx, eax
343
        inc     edx     ; edx = length of partition
388
   ;     inc     edx     ; edx = length of partition § ç¥¬ ®­® ­ ¬??
Line 364... Line 409...
364
        mov     eax, edx
409
        mov     eax, edx
365
        shr     eax, 1
410
        shr     eax, 1
366
        add     eax, [PARTITION_START]
411
        add     eax, [PARTITION_START]
367
        call    hd_read
412
        call    hd_read
368
        cmp     [hd_error], 0
413
        cmp     [hd_error], 0
369
        jnz     problem_fat_dec_count   ; ­¥ áã¤ì¡ ...
414
        jnz     problem_fat_dec_count   ; no chance...
370
boot_read_ok:
415
boot_read_ok:
371
;        mov     [hd_setup], 0
-
 
-
 
416
 
372
; if we are running on NTFS, check bootsector
417
; if we are running on NTFS, check bootsector
373
;        cmp     [fs_type], 7
-
 
374
;        jz      ntfs_setup
-
 
-
 
418
 
375
        call    ntfs_test_bootsec
419
        call    ntfs_test_bootsec      ; test ntfs
376
        jnc     ntfs_setup
420
        jnc     ntfs_setup
Line -... Line 421...
-
 
421
 
-
 
422
        call    ext2_test_superblock   ; test ext2fs
-
 
423
        jnc     ext2_setup
-
 
424
 
-
 
425
        mov     eax, [PARTITION_START]  ;ext2 test changes [buffer]
-
 
426
        call    hd_read
-
 
427
        cmp     [hd_error], 0
-
 
428
        jnz     problem_fat_dec_count
377
 
429
 
378
    cmp   word [ebx+0x1fe],0xaa55 ; is it valid boot sector?
430
        cmp     word [ebx+0x1fe], 0xaa55; is it valid boot sector?
Line 379... Line 431...
379
    jnz   problem_fat_dec_count
431
        jnz     problem_fat_dec_count
380
 
432
 
Line 477... Line 529...
477
    mov   [fatMASK],0x0000FFFF
529
        mov     [fatMASK], 0x0000FFFF
478
    mov   [fs_type],16         ; Fat16
530
        mov     [fs_type], 16  ; Fat16
479
    call  free_hd_channel
531
        call    free_hd_channel
480
    mov   [hd1_status],0        ; free
532
        mov     [hd1_status], 0 ; free
481
    ret
533
        ret
-
 
534
>