Subversion Repositories Kolibri OS

Rev

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

Rev 74 Rev 256
Line 4... Line 4...
4
;* 28.01.2006 find all Fat16/32 partition in all input point *
4
;* 28.01.2006 find all Fat16/32 partition in all input point *
5
;*            to MBR - Mario79                               *
5
;*            to MBR - Mario79                               *
6
;*************************************************************
6
;*************************************************************
Line 7... Line 7...
7
 
7
 
-
 
8
align 4
-
 
9
 
8
align 4
10
iglobal
9
;******************************************************
11
;******************************************************
10
; Please do not change this place - variables  in text 
12
; Please do not change this place - variables  in text 
11
; Mario79
13
; Mario79
12
; START place
14
; START place
13
;******************************************************
15
;******************************************************
14
PARTITION_START      dd 0x3f
16
PARTITION_START      dd 0x3f
-
 
17
PARTITION_END        dd 0
-
 
18
fs_type              db 0       ; 0=none, 1=NTFS, 16=FAT16, 32=FAT32
-
 
19
 
-
 
20
fs_dependent_data_start:
-
 
21
; FATxx data
15
PARTITION_END        dd 0
22
 
16
SECTORS_PER_FAT      dd 0x1f3a
23
SECTORS_PER_FAT      dd 0x1f3a
17
NUMBER_OF_FATS       dd 0x2
24
NUMBER_OF_FATS       dd 0x2
18
SECTORS_PER_CLUSTER  dd 0x8
25
SECTORS_PER_CLUSTER  dd 0x8
19
BYTES_PER_SECTOR     dd 0x200   ; Note: if BPS <> 512 need lots of changes
26
BYTES_PER_SECTOR     dd 0x200   ; Note: if BPS <> 512 need lots of changes
Line 28... Line 35...
28
fatRESERVED          dd 0x0FFFFFF6
35
fatRESERVED          dd 0x0FFFFFF6
29
fatBAD               dd 0x0FFFFFF7
36
fatBAD               dd 0x0FFFFFF7
30
fatEND               dd 0x0FFFFFF8
37
fatEND               dd 0x0FFFFFF8
31
fatMASK              dd 0x0FFFFFFF
38
fatMASK              dd 0x0FFFFFFF
Line -... Line 39...
-
 
39
 
-
 
40
fs_dependent_data_end:
-
 
41
 
-
 
42
virtual at fs_dependent_data_start
-
 
43
; NTFS data
-
 
44
ntfs_data:
-
 
45
.sectors_per_cluster    dd      ?
-
 
46
.mft_cluster            dd      ?
32
 
47
.mftmirr_cluster        dd      ?
-
 
48
.frs_size               dd      ?       ; FRS size in bytes
-
 
49
.iab_size               dd      ?       ; IndexAllocationBuffer size in bytes
-
 
50
.frs_buffer             dd      ?
-
 
51
.iab_buffer             dd      ?
-
 
52
.mft_retrieval          dd      ?
-
 
53
.mft_retrieval_size     dd      ?
-
 
54
.mft_retrieval_alloc    dd      ?
-
 
55
.mft_retrieval_end      dd      ?
-
 
56
.cur_index_size         dd      ?
-
 
57
.cur_index_buf          dd      ?
-
 
58
if $ > fs_dependent_data_end
-
 
59
ERROR: increase sizeof(fs_dependent_data)!
-
 
60
end if
-
 
61
end virtual
33
fat_type             db 0       ; 0=none, 16=fat16, 32=fat32
62
 
34
;***************************************************************************
63
;***************************************************************************
35
; End place
64
; End place
36
; Mario79
65
; Mario79
Line 37... Line -...
37
;***************************************************************************
-
 
38
 
66
;***************************************************************************
39
iglobal
67
 
40
  partition_types:              ; list of fat16/32 partitions
68
  partition_types:              ; list of fat16/32 partitions
41
    db    0x04                  ; DOS: fat16 <32M
69
    db    0x04                  ; DOS: fat16 <32M
42
    db    0x06                  ; DOS: fat16 >32M
70
    db    0x06                  ; DOS: fat16 >32M
Line 53... Line 81...
53
    db    0xcb                  ; DRDOS/secured: fat32
81
    db    0xcb                  ; DRDOS/secured: fat32
54
    db    0xcc                  ; DRDOS/secured: fat32, LBA-mapped
82
    db    0xcc                  ; DRDOS/secured: fat32, LBA-mapped
55
    db    0xce                  ; DRDOS/secured: fat16, LBA-mapped
83
    db    0xce                  ; DRDOS/secured: fat16, LBA-mapped
56
    db    0xd4                  ; Old Multiuser DOS secured: fat16 <32M
84
    db    0xd4                  ; Old Multiuser DOS secured: fat16 <32M
57
    db    0xd6                  ; Old Multiuser DOS secured: fat16 >32M
85
    db    0xd6                  ; Old Multiuser DOS secured: fat16 >32M
-
 
86
    db    0x07                  ; NTFS
58
  partition_types_end:
87
  partition_types_end:
Line 59... Line 88...
59
 
88
 
60
 
89
 
Line 120... Line 149...
120
    cmp   ecx,[fat32part]       ; is it wanted partition?
149
    cmp   ecx,[fat32part]       ; is it wanted partition?
121
    jnz   next_primary_partition        ; no
150
    jnz   next_primary_partition        ; no
Line 122... Line 151...
122
 
151
 
123
    mov   edx,eax               ; start sector
152
        mov     edx, eax                ; start sector
-
 
153
        add     edx, [ebx+0x1be+8]      ; add relative start
-
 
154
        push    edx
-
 
155
        add     edx, [ebx+0x1be+12]     ; add length
-
 
156
        dec     edx                     ; PARTITION_END is inclusive
-
 
157
        mov     [PARTITION_END], edx    ; note that this can be changed
-
 
158
                                        ; when file system data will be available
-
 
159
        mov     dl, [ebx+0x1be+4]
-
 
160
        mov     [fs_type], dl           ; save for FS recognizer (separate FAT vs NTFS)
Line 124... Line 161...
124
    add   edx,[ebx+0x1be+8]     ; add relative start
161
        pop     edx
125
    
162
 
126
next_primary_partition:
163
next_primary_partition:
127
    push  eax
164
    push  eax
Line 132... Line 169...
132
 
169
 
133
    inc   ecx
170
    inc   ecx
134
    cmp   ecx,[fat32part]       ; is it wanted partition?
171
    cmp   ecx,[fat32part]       ; is it wanted partition?
Line -... Line 172...
-
 
172
    jnz   next_primary_partition_1        ; no
135
    jnz   next_primary_partition_1        ; no
173
 
-
 
174
        mov     edx, eax
136
 
175
        add     edx, [ebx+0x1be+8+16]
-
 
176
        push    edx
-
 
177
        add     edx, [ebx+0x1be+12+16]
-
 
178
        dec     edx
-
 
179
        mov     [PARTITION_END], edx
-
 
180
        mov     dl, [ebx+0x1be+4+16]
Line 137... Line 181...
137
    mov   edx,eax               ; start sector
181
        mov     [fs_type], dl
138
    add   edx,[ebx+0x1be+8+16]     ; add relative start
182
        pop     edx
139
 
183
 
140
next_primary_partition_1:
184
next_primary_partition_1:
Line 146... Line 190...
146
 
190
 
147
    inc   ecx
191
    inc   ecx
148
    cmp   ecx,[fat32part]       ; is it wanted partition?
192
    cmp   ecx,[fat32part]       ; is it wanted partition?
Line -... Line 193...
-
 
193
    jnz   next_primary_partition_2        ; no
149
    jnz   next_primary_partition_2        ; no
194
 
-
 
195
        mov     edx, eax
150
 
196
        add     edx, [ebx+0x1be+8+16+16]
-
 
197
        push    edx
-
 
198
        add     edx, [ebx+0x1be+12+16+16]
-
 
199
        dec     edx
-
 
200
        mov     [PARTITION_END], edx
-
 
201
        mov     dl, [ebx+0x1be+4+16+16]
Line 151... Line 202...
151
    mov   edx,eax               ; start sector
202
        mov     [fs_type], dl
152
    add   edx,[ebx+0x1be+8+16+16]     ; add relative start
203
        pop     edx
153
 
204
 
154
next_primary_partition_2:
205
next_primary_partition_2:
Line 160... Line 211...
160
 
211
 
161
    inc   ecx
212
    inc   ecx
162
    cmp   ecx,[fat32part]       ; is it wanted partition?
213
    cmp   ecx,[fat32part]       ; is it wanted partition?
Line -... Line 214...
-
 
214
    jnz   next_partition        ; no
163
    jnz   next_partition        ; no
215
 
-
 
216
        mov     edx, eax
164
 
217
        add     edx, [ebx+0x1be+8+16+16+16]
-
 
218
        push    edx
-
 
219
        add     edx, [ebx+0x1be+12+16+16+16]
-
 
220
        dec     edx
-
 
221
        mov     [PARTITION_END], edx
-
 
222
        mov     dl, [ebx+0x1be+4+16+16+16]
Line 165... Line 223...
165
    mov   edx,eax               ; start sector
223
        mov     [fs_type], dl
166
    add   edx,[ebx+0x1be+8+16+16+16]     ; add relative start
224
        pop     edx
167
 
225
 
168
next_partition:
226
next_partition:
Line 239... Line 297...
239
 
297
 
240
problem_partition_or_fat:
298
problem_partition_or_fat:
Line 241... Line 299...
241
    popad
299
    popad
242
 
300
 
243
problem_hd:
301
problem_hd:
244
    mov   [fat_type],0
302
    mov   [fs_type],0
245
    mov   [hd1_status],0        ; free
303
    mov   [hd1_status],0        ; free
Line 246... Line 304...
246
    mov   [problem_partition],1
304
    mov   [problem_partition],1
247
    ret
305
    ret
248
 
306
 
-
 
307
hd_and_partition_ok:
-
 
308
    mov   eax,edx
-
 
309
    mov   [PARTITION_START],eax
Line 249... Line 310...
249
hd_and_partition_ok:
310
        mov     edx, [PARTITION_END]
250
    mov   eax,edx
311
        sub     edx, eax
251
    mov   [PARTITION_START],eax
312
        inc     edx     ; edx = length of partition
252
 
313
 
-
 
314
;    mov   [hd_setup],1
-
 
315
    mov   ebx,buffer
253
    mov   [hd_setup],1
316
    call  hd_read               ; read boot sector of partition
-
 
317
        cmp     [hd_error], 0
-
 
318
        jz      boot_read_ok
-
 
319
        cmp     [fs_type], 7
-
 
320
        jnz     problem_fat_dec_count
-
 
321
; NTFS duplicates bootsector:
-
 
322
; NT4/2k/XP+ saves bootsector copy in the end of disk
-
 
323
; NT 3.51 saves bootsector copy in the middle of disk
-
 
324
        and     [hd_error], 0
-
 
325
        mov     eax, [PARTITION_END]
-
 
326
        call    hd_read
254
    mov   ebx,buffer
327
        cmp     [hd_error], 0
-
 
328
        jnz     @f
-
 
329
        call    ntfs_test_bootsec
-
 
330
        jnc     boot_read_ok
-
 
331
@@:
-
 
332
        and     [hd_error], 0
-
 
333
        mov     eax, edx
-
 
334
        shr     eax, 1
-
 
335
        add     eax, [PARTITION_START]
255
    call  hd_read               ; read boot sector of partition
336
        call    hd_read
-
 
337
        cmp     [hd_error], 0
-
 
338
        jnz     problem_fat_dec_count   ; ­¥ áã¤ì¡ ...
-
 
339
boot_read_ok:
Line 256... Line 340...
256
    cmp  [hd_error],0
340
;        mov     [hd_setup], 0
257
    jne  problem_fat_dec_count
341
; if we are running on NTFS, check bootsector
Line 258... Line 342...
258
 
342
        cmp     [fs_type], 7
Line 330... Line 414...
330
 
414
 
331
    mov   [fatRESERVED],0x0FFFFFF6
415
    mov   [fatRESERVED],0x0FFFFFF6
332
    mov   [fatBAD],0x0FFFFFF7
416
    mov   [fatBAD],0x0FFFFFF7
333
    mov   [fatEND],0x0FFFFFF8
417
    mov   [fatEND],0x0FFFFFF8
334
    mov   [fatMASK],0x0FFFFFFF
418
    mov   [fatMASK],0x0FFFFFFF
335
    mov   [fat_type],32         ; Fat32
419
    mov   [fs_type],32         ; Fat32
336
    mov   [hd1_status],0        ; free
420
    mov   [hd1_status],0        ; free
Line 337... Line 421...
337
    ret
421
    ret
338
 
422
 
Line 344... Line 428...
344
 
428
 
345
    mov   [fatRESERVED],0x0000FFF6
429
    mov   [fatRESERVED],0x0000FFF6
346
    mov   [fatBAD],0x0000FFF7
430
    mov   [fatBAD],0x0000FFF7
347
    mov   [fatEND],0x0000FFF8
431
    mov   [fatEND],0x0000FFF8
348
    mov   [fatMASK],0x0000FFFF
432
    mov   [fatMASK],0x0000FFFF
349
    mov   [fat_type],16         ; Fat16
433
    mov   [fs_type],16         ; Fat16
350
    mov   [hd1_status],0        ; free
434
    mov   [hd1_status],0        ; free