Subversion Repositories Kolibri OS

Rev

Rev 578 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 578 Rev 593
1
$Revision: 578 $
-
 
2
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3
;;                                                              ;;
2
;;                                                              ;;
4
;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;;
3
;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;;
5
;; Distributed under terms of the GNU General Public License    ;;
4
;; Distributed under terms of the GNU General Public License    ;;
6
;;                                                              ;;
5
;;                                                              ;;
7
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
 
7
 
-
 
8
$Revision: 593 $
-
 
9
 
8
 
10
 
9
;*************************************************************
11
;*************************************************************
10
;* 12.07.2007 Check all 4 entry of MBR and EMBR
12
;* 12.07.2007 Check all 4 entry of MBR and EMBR
11
;* 29.04.2006 Elimination of hangup after the
13
;* 29.04.2006 Elimination of hangup after the
12
;*             expiration hd_wait_timeout -  Mario79
14
;*             expiration hd_wait_timeout -  Mario79
13
;* 28.01.2006 find all Fat16/32 partition in all input point
15
;* 28.01.2006 find all Fat16/32 partition in all input point
14
;*            to MBR - Mario79
16
;*            to MBR - Mario79
15
;*************************************************************
17
;*************************************************************
16
 
18
 
17
uglobal
19
uglobal
18
align 4
20
align 4
19
 
21
 
20
;******************************************************
22
;******************************************************
21
; Please do not change this place - variables  in text
23
; Please do not change this place - variables  in text
22
; Mario79
24
; Mario79
23
; START place
25
; START place
24
;******************************************************
26
;******************************************************
25
PARTITION_START      dd 0x3f
27
PARTITION_START      dd 0x3f
26
PARTITION_END        dd 0
28
PARTITION_END        dd 0
27
fs_type              db 0       ; 0=none, 1=NTFS, 16=FAT16, 32=FAT32
29
fs_type              db 0       ; 0=none, 1=NTFS, 16=FAT16, 32=FAT32
28
align 4
30
align 4
29
 
31
 
30
fs_dependent_data_start:
32
fs_dependent_data_start:
31
; FATxx data
33
; FATxx data
32
 
34
 
33
SECTORS_PER_FAT      dd 0x1f3a
35
SECTORS_PER_FAT      dd 0x1f3a
34
NUMBER_OF_FATS       dd 0x2
36
NUMBER_OF_FATS       dd 0x2
35
SECTORS_PER_CLUSTER  dd 0x8
37
SECTORS_PER_CLUSTER  dd 0x8
36
BYTES_PER_SECTOR     dd 0x200   ; Note: if BPS <> 512 need lots of changes
38
BYTES_PER_SECTOR     dd 0x200   ; Note: if BPS <> 512 need lots of changes
37
ROOT_CLUSTER         dd 2       ; first rootdir cluster
39
ROOT_CLUSTER         dd 2       ; first rootdir cluster
38
FAT_START            dd 0       ; start of fat table
40
FAT_START            dd 0       ; start of fat table
39
ROOT_START           dd 0       ; start of rootdir (only fat16)
41
ROOT_START           dd 0       ; start of rootdir (only fat16)
40
ROOT_SECTORS         dd 0       ; count of rootdir sectors (only fat16)
42
ROOT_SECTORS         dd 0       ; count of rootdir sectors (only fat16)
41
DATA_START           dd 0       ; start of data area (=first cluster 2)
43
DATA_START           dd 0       ; start of data area (=first cluster 2)
42
LAST_CLUSTER         dd 0       ; last availabe cluster
44
LAST_CLUSTER         dd 0       ; last availabe cluster
43
ADR_FSINFO           dd 0       ; used only by fat32
45
ADR_FSINFO           dd 0       ; used only by fat32
44
 
46
 
45
fatRESERVED          dd 0x0FFFFFF6
47
fatRESERVED          dd 0x0FFFFFF6
46
fatBAD               dd 0x0FFFFFF7
48
fatBAD               dd 0x0FFFFFF7
47
fatEND               dd 0x0FFFFFF8
49
fatEND               dd 0x0FFFFFF8
48
fatMASK              dd 0x0FFFFFFF
50
fatMASK              dd 0x0FFFFFFF
49
 
51
 
50
fs_dependent_data_end:
52
fs_dependent_data_end:
51
file_system_data_size = $ - PARTITION_START
53
file_system_data_size = $ - PARTITION_START
52
if file_system_data_size > 96
54
if file_system_data_size > 96
53
ERROR: sizeof(file system data) too big!
55
ERROR: sizeof(file system data) too big!
54
end if
56
end if
55
 
57
 
56
virtual at fs_dependent_data_start
58
virtual at fs_dependent_data_start
57
; NTFS data
59
; NTFS data
58
ntfs_data:
60
ntfs_data:
59
.sectors_per_cluster    dd      ?
61
.sectors_per_cluster    dd      ?
60
.mft_cluster            dd      ?
62
.mft_cluster            dd      ?
61
.mftmirr_cluster        dd      ?
63
.mftmirr_cluster        dd      ?
62
.frs_size               dd      ?       ; FRS size in bytes
64
.frs_size               dd      ?       ; FRS size in bytes
63
.iab_size               dd      ?       ; IndexAllocationBuffer size in bytes
65
.iab_size               dd      ?       ; IndexAllocationBuffer size in bytes
64
.frs_buffer             dd      ?
66
.frs_buffer             dd      ?
65
.iab_buffer             dd      ?
67
.iab_buffer             dd      ?
66
.mft_retrieval          dd      ?
68
.mft_retrieval          dd      ?
67
.mft_retrieval_size     dd      ?
69
.mft_retrieval_size     dd      ?
68
.mft_retrieval_alloc    dd      ?
70
.mft_retrieval_alloc    dd      ?
69
.mft_retrieval_end      dd      ?
71
.mft_retrieval_end      dd      ?
70
.cur_index_size         dd      ?
72
.cur_index_size         dd      ?
71
.cur_index_buf          dd      ?
73
.cur_index_buf          dd      ?
72
if $ > fs_dependent_data_end
74
if $ > fs_dependent_data_end
73
ERROR: increase sizeof(fs_dependent_data)!
75
ERROR: increase sizeof(fs_dependent_data)!
74
end if
76
end if
75
end virtual
77
end virtual
76
 
78
 
77
;***************************************************************************
79
;***************************************************************************
78
; End place
80
; End place
79
; Mario79
81
; Mario79
80
;***************************************************************************
82
;***************************************************************************
81
endg
83
endg
82
iglobal
84
iglobal
83
 
85
 
84
  partition_types:              ; list of fat16/32 partitions
86
  partition_types:              ; list of fat16/32 partitions
85
    db    0x04                  ; DOS: fat16 <32M
87
    db    0x04                  ; DOS: fat16 <32M
86
    db    0x06                  ; DOS: fat16 >32M
88
    db    0x06                  ; DOS: fat16 >32M
87
    db    0x0b                  ; WIN95: fat32
89
    db    0x0b                  ; WIN95: fat32
88
    db    0x0c                  ; WIN95: fat32, LBA-mapped
90
    db    0x0c                  ; WIN95: fat32, LBA-mapped
89
    db    0x0e                  ; WIN95: fat16, LBA-mapped
91
    db    0x0e                  ; WIN95: fat16, LBA-mapped
90
    db    0x14                  ; Hidden DOS: fat16 <32M
92
    db    0x14                  ; Hidden DOS: fat16 <32M
91
    db    0x16                  ; Hidden DOS: fat16 >32M
93
    db    0x16                  ; Hidden DOS: fat16 >32M
92
    db    0x1b                  ; Hidden WIN95: fat32
94
    db    0x1b                  ; Hidden WIN95: fat32
93
    db    0x1c                  ; Hidden WIN95: fat32, LBA-mapped
95
    db    0x1c                  ; Hidden WIN95: fat32, LBA-mapped
94
    db    0x1e                  ; Hidden WIN95: fat16, LBA-mapped
96
    db    0x1e                  ; Hidden WIN95: fat16, LBA-mapped
95
    db    0xc4                  ; DRDOS/secured: fat16 <32M
97
    db    0xc4                  ; DRDOS/secured: fat16 <32M
96
    db    0xc6                  ; DRDOS/secured: fat16 >32M
98
    db    0xc6                  ; DRDOS/secured: fat16 >32M
97
    db    0xcb                  ; DRDOS/secured: fat32
99
    db    0xcb                  ; DRDOS/secured: fat32
98
    db    0xcc                  ; DRDOS/secured: fat32, LBA-mapped
100
    db    0xcc                  ; DRDOS/secured: fat32, LBA-mapped
99
    db    0xce                  ; DRDOS/secured: fat16, LBA-mapped
101
    db    0xce                  ; DRDOS/secured: fat16, LBA-mapped
100
    db    0xd4                  ; Old Multiuser DOS secured: fat16 <32M
102
    db    0xd4                  ; Old Multiuser DOS secured: fat16 <32M
101
    db    0xd6                  ; Old Multiuser DOS secured: fat16 >32M
103
    db    0xd6                  ; Old Multiuser DOS secured: fat16 >32M
102
    db    0x07                  ; NTFS
104
    db    0x07                  ; NTFS
103
  partition_types_end:
105
  partition_types_end:
104
 
106
 
105
 
107
 
106
  extended_types:               ; list of extended partitions
108
  extended_types:               ; list of extended partitions
107
    db    0x05                  ; DOS: extended partition
109
    db    0x05                  ; DOS: extended partition
108
    db    0x0f                  ; WIN95: extended partition, LBA-mapped
110
    db    0x0f                  ; WIN95: extended partition, LBA-mapped
109
    db    0xc5                  ; DRDOS/secured: extended partition
111
    db    0xc5                  ; DRDOS/secured: extended partition
110
    db    0xd5                  ; Old Multiuser DOS secured: extended partition
112
    db    0xd5                  ; Old Multiuser DOS secured: extended partition
111
  extended_types_end:
113
  extended_types_end:
112
 
114
 
113
endg
115
endg
114
 
116
 
115
; Partition chain used:
117
; Partition chain used:
116
; MBR        ;   PARTITION2 ;   PARTITION3 ;   PARTITION4
118
; MBR        ;   PARTITION2 ;   PARTITION3 ;   PARTITION4
117
;==========================================================
119
;==========================================================
118
; fat16/32   +-- fat16/32   +-- fat16/32   +-- fat16/32   +--
120
; fat16/32   +-- fat16/32   +-- fat16/32   +-- fat16/32   +--
119
; extended --+   extended --+   extended --+   extended --+
121
; extended --+   extended --+   extended --+   extended --+
120
; 0              0              0              0
122
; 0              0              0              0
121
; 0              0              0              0
123
; 0              0              0              0
122
; Notes:
124
; Notes:
123
; - extended partition need to be in second entry on table
125
; - extended partition need to be in second entry on table
124
; - it will skip over removed partitions
126
; - it will skip over removed partitions
125
 
127
 
126
set_FAT32_variables:
128
set_FAT32_variables:
127
    mov   [problem_partition],0
129
    mov   [problem_partition],0
128
    call  reserve_hd1
130
    call  reserve_hd1
129
    call  reserve_hd_channel
131
    call  reserve_hd_channel
130
 
132
 
131
    cmp   dword [hdpos],0
133
    cmp   dword [hdpos],0
132
    je    problem_hd
134
    je    problem_hd
133
 
135
 
134
    pushad
136
    pushad
135
    xor   ecx,ecx               ; partition count
137
    xor   ecx,ecx               ; partition count
136
    mov   edx,-1                ; flag for partition
138
    mov   edx,-1                ; flag for partition
137
    xor   eax,eax               ; read MBR
139
    xor   eax,eax               ; read MBR
138
    xor   ebp,ebp               ; extended partition start
140
    xor   ebp,ebp               ; extended partition start
139
 
141
 
140
new_partition:
142
new_partition:
141
    test  ebp,ebp               ; is there extended partition?
143
    test  ebp,ebp               ; is there extended partition?
142
    jnz   extended_already_set  ; yes
144
    jnz   extended_already_set  ; yes
143
    xchg  ebp,eax               ; no. set it now
145
    xchg  ebp,eax               ; no. set it now
144
 
146
 
145
extended_already_set:
147
extended_already_set:
146
    add   eax,ebp               ; mbr=mbr+0, ext_part=ext_start+relat_start
148
    add   eax,ebp               ; mbr=mbr+0, ext_part=ext_start+relat_start
147
    mov   ebx,buffer
149
    mov   ebx,buffer
148
    call  hd_read
150
    call  hd_read
149
    cmp  [hd_error],0
151
    cmp  [hd_error],0
150
    jne  problem_hd
152
    jne  problem_hd
151
 
153
 
152
    cmp   word [ebx+0x1fe],0xaa55 ; is it valid boot sector?
154
    cmp   word [ebx+0x1fe],0xaa55 ; is it valid boot sector?
153
    jnz   end_partition_chain
155
    jnz   end_partition_chain
154
    cmp   dword [ebx+0x1be+0xc],0 ; skip over empty partition
156
    cmp   dword [ebx+0x1be+0xc],0 ; skip over empty partition
155
;    jz    next_partition
157
;    jz    next_partition
156
    jnz    .next_primary_partition
158
    jnz    .next_primary_partition
157
    cmp   dword [ebx+0x1be+0xc+16],0
159
    cmp   dword [ebx+0x1be+0xc+16],0
158
    jnz    next_primary_partition
160
    jnz    next_primary_partition
159
    cmp   dword [ebx+0x1be+0xc+16+16],0
161
    cmp   dword [ebx+0x1be+0xc+16+16],0
160
    jnz    next_primary_partition_1
162
    jnz    next_primary_partition_1
161
    cmp   dword [ebx+0x1be+0xc+16+16+16],0
163
    cmp   dword [ebx+0x1be+0xc+16+16+16],0
162
    jnz    next_primary_partition_2
164
    jnz    next_primary_partition_2
163
    jmp   next_partition
165
    jmp   next_partition
164
    
166
    
165
.next_primary_partition:
167
.next_primary_partition:
166
    push  eax
168
    push  eax
167
    mov   al,[ebx+0x1be+4]      ; get primary partition type
169
    mov   al,[ebx+0x1be+4]      ; get primary partition type
168
    call  scan_partition_types
170
    call  scan_partition_types
169
    pop   eax
171
    pop   eax
170
    jnz   next_primary_partition        ; no. skip over
172
    jnz   next_primary_partition        ; no. skip over
171
 
173
 
172
    inc   ecx
174
    inc   ecx
173
    cmp   ecx,[fat32part]       ; is it wanted partition?
175
    cmp   ecx,[fat32part]       ; is it wanted partition?
174
    jnz   next_primary_partition        ; no
176
    jnz   next_primary_partition        ; no
175
 
177
 
176
        mov     edx, eax                ; start sector
178
        mov     edx, eax                ; start sector
177
        add     edx, [ebx+0x1be+8]      ; add relative start
179
        add     edx, [ebx+0x1be+8]      ; add relative start
178
        push    edx
180
        push    edx
179
        add     edx, [ebx+0x1be+12]     ; add length
181
        add     edx, [ebx+0x1be+12]     ; add length
180
        dec     edx                     ; PARTITION_END is inclusive
182
        dec     edx                     ; PARTITION_END is inclusive
181
        mov     [PARTITION_END], edx    ; note that this can be changed
183
        mov     [PARTITION_END], edx    ; note that this can be changed
182
                                        ; when file system data will be available
184
                                        ; when file system data will be available
183
        mov     dl, [ebx+0x1be+4]
185
        mov     dl, [ebx+0x1be+4]
184
        mov     [fs_type], dl           ; save for FS recognizer (separate FAT vs NTFS)
186
        mov     [fs_type], dl           ; save for FS recognizer (separate FAT vs NTFS)
185
        pop     edx
187
        pop     edx
186
 
188
 
187
next_primary_partition:
189
next_primary_partition:
188
    push  eax
190
    push  eax
189
    mov   al,[ebx+0x1be+4+16]      ; get primary partition type
191
    mov   al,[ebx+0x1be+4+16]      ; get primary partition type
190
    call  scan_partition_types
192
    call  scan_partition_types
191
    pop   eax
193
    pop   eax
192
    jnz   next_primary_partition_1        ; no. skip over
194
    jnz   next_primary_partition_1        ; no. skip over
193
 
195
 
194
    inc   ecx
196
    inc   ecx
195
    cmp   ecx,[fat32part]       ; is it wanted partition?
197
    cmp   ecx,[fat32part]       ; is it wanted partition?
196
    jnz   next_primary_partition_1        ; no
198
    jnz   next_primary_partition_1        ; no
197
 
199
 
198
        mov     edx, eax
200
        mov     edx, eax
199
        add     edx, [ebx+0x1be+8+16]
201
        add     edx, [ebx+0x1be+8+16]
200
        push    edx
202
        push    edx
201
        add     edx, [ebx+0x1be+12+16]
203
        add     edx, [ebx+0x1be+12+16]
202
        dec     edx
204
        dec     edx
203
        mov     [PARTITION_END], edx
205
        mov     [PARTITION_END], edx
204
        mov     dl, [ebx+0x1be+4+16]
206
        mov     dl, [ebx+0x1be+4+16]
205
        mov     [fs_type], dl
207
        mov     [fs_type], dl
206
        pop     edx
208
        pop     edx
207
 
209
 
208
next_primary_partition_1:
210
next_primary_partition_1:
209
    push  eax
211
    push  eax
210
    mov   al,[ebx+0x1be+4+16+16]      ; get primary partition type
212
    mov   al,[ebx+0x1be+4+16+16]      ; get primary partition type
211
    call  scan_partition_types
213
    call  scan_partition_types
212
    pop   eax
214
    pop   eax
213
    jnz   next_primary_partition_2        ; no. skip over
215
    jnz   next_primary_partition_2        ; no. skip over
214
 
216
 
215
    inc   ecx
217
    inc   ecx
216
    cmp   ecx,[fat32part]       ; is it wanted partition?
218
    cmp   ecx,[fat32part]       ; is it wanted partition?
217
    jnz   next_primary_partition_2        ; no
219
    jnz   next_primary_partition_2        ; no
218
 
220
 
219
        mov     edx, eax
221
        mov     edx, eax
220
        add     edx, [ebx+0x1be+8+16+16]
222
        add     edx, [ebx+0x1be+8+16+16]
221
        push    edx
223
        push    edx
222
        add     edx, [ebx+0x1be+12+16+16]
224
        add     edx, [ebx+0x1be+12+16+16]
223
        dec     edx
225
        dec     edx
224
        mov     [PARTITION_END], edx
226
        mov     [PARTITION_END], edx
225
        mov     dl, [ebx+0x1be+4+16+16]
227
        mov     dl, [ebx+0x1be+4+16+16]
226
        mov     [fs_type], dl
228
        mov     [fs_type], dl
227
        pop     edx
229
        pop     edx
228
 
230
 
229
next_primary_partition_2:
231
next_primary_partition_2:
230
    push  eax
232
    push  eax
231
    mov   al,[ebx+0x1be+4+16+16+16]      ; get primary partition type
233
    mov   al,[ebx+0x1be+4+16+16+16]      ; get primary partition type
232
    call  scan_partition_types
234
    call  scan_partition_types
233
    pop   eax
235
    pop   eax
234
    jnz   next_partition        ; no. skip over
236
    jnz   next_partition        ; no. skip over
235
 
237
 
236
    inc   ecx
238
    inc   ecx
237
    cmp   ecx,[fat32part]       ; is it wanted partition?
239
    cmp   ecx,[fat32part]       ; is it wanted partition?
238
    jnz   next_partition        ; no
240
    jnz   next_partition        ; no
239
 
241
 
240
        mov     edx, eax
242
        mov     edx, eax
241
        add     edx, [ebx+0x1be+8+16+16+16]
243
        add     edx, [ebx+0x1be+8+16+16+16]
242
        push    edx
244
        push    edx
243
        add     edx, [ebx+0x1be+12+16+16+16]
245
        add     edx, [ebx+0x1be+12+16+16+16]
244
        dec     edx
246
        dec     edx
245
        mov     [PARTITION_END], edx
247
        mov     [PARTITION_END], edx
246
        mov     dl, [ebx+0x1be+4+16+16+16]
248
        mov     dl, [ebx+0x1be+4+16+16+16]
247
        mov     [fs_type], dl
249
        mov     [fs_type], dl
248
        pop     edx
250
        pop     edx
249
 
251
 
250
next_partition:
252
next_partition:
251
    push  eax
253
    push  eax
252
    mov   al,[ebx+0x1be+4]   ; get extended partition type
254
    mov   al,[ebx+0x1be+4]   ; get extended partition type
253
    call  scan_extended_types
255
    call  scan_extended_types
254
    pop   eax
256
    pop   eax
255
    jnz   next_partition_1
257
    jnz   next_partition_1
256
 
258
 
257
    mov   eax,[ebx+0x1be+8]     ; add relative start
259
    mov   eax,[ebx+0x1be+8]     ; add relative start
258
    test  eax,eax               ; is there extended partition?
260
    test  eax,eax               ; is there extended partition?
259
    jnz   new_partition         ; yes. read it
261
    jnz   new_partition         ; yes. read it
260
 
262
 
261
next_partition_1:
263
next_partition_1:
262
    push  eax
264
    push  eax
263
    mov   al,[ebx+0x1be+4+16]   ; get extended partition type
265
    mov   al,[ebx+0x1be+4+16]   ; get extended partition type
264
    call  scan_extended_types
266
    call  scan_extended_types
265
    pop   eax
267
    pop   eax
266
    jnz   next_partition_2
268
    jnz   next_partition_2
267
 
269
 
268
    mov   eax,[ebx+0x1be+8+16]     ; add relative start
270
    mov   eax,[ebx+0x1be+8+16]     ; add relative start
269
    test  eax,eax               ; is there extended partition?
271
    test  eax,eax               ; is there extended partition?
270
    jnz   new_partition         ; yes. read it
272
    jnz   new_partition         ; yes. read it
271
 
273
 
272
next_partition_2:
274
next_partition_2:
273
    push  eax
275
    push  eax
274
    mov   al,[ebx+0x1be+4+16+16]   ; get extended partition type
276
    mov   al,[ebx+0x1be+4+16+16]   ; get extended partition type
275
    call  scan_extended_types
277
    call  scan_extended_types
276
    pop   eax
278
    pop   eax
277
    jnz   next_partition_3
279
    jnz   next_partition_3
278
 
280
 
279
    mov   eax,[ebx+0x1be+8+16+16]     ; add relative start
281
    mov   eax,[ebx+0x1be+8+16+16]     ; add relative start
280
    test  eax,eax               ; is there extended partition?
282
    test  eax,eax               ; is there extended partition?
281
    jnz   new_partition         ; yes. read it
283
    jnz   new_partition         ; yes. read it
282
    
284
    
283
next_partition_3:
285
next_partition_3:
284
    push  eax
286
    push  eax
285
    mov   al,[ebx+0x1be+4+16+16+16]   ; get extended partition type
287
    mov   al,[ebx+0x1be+4+16+16+16]   ; get extended partition type
286
    call  scan_extended_types
288
    call  scan_extended_types
287
    pop   eax
289
    pop   eax
288
    jnz   end_partition_chain   ; no. end chain
290
    jnz   end_partition_chain   ; no. end chain
289
 
291
 
290
    mov   eax,[ebx+0x1be+8+16+16+16]  ; get start of extended partition
292
    mov   eax,[ebx+0x1be+8+16+16+16]  ; get start of extended partition
291
    test  eax,eax               ; is there extended partition?
293
    test  eax,eax               ; is there extended partition?
292
    jnz   new_partition         ; yes. read it
294
    jnz   new_partition         ; yes. read it
293
    
295
    
294
end_partition_chain:
296
end_partition_chain:
295
    mov   [partition_count],ecx
297
    mov   [partition_count],ecx
296
 
298
 
297
    cmp   edx,-1                ; found wanted partition?
299
    cmp   edx,-1                ; found wanted partition?
298
    jnz   hd_and_partition_ok   ; yes. install it
300
    jnz   hd_and_partition_ok   ; yes. install it
299
    jmp   problem_partition_or_fat
301
    jmp   problem_partition_or_fat
300
 
302
 
301
scan_partition_types:
303
scan_partition_types:
302
    push  ecx
304
    push  ecx
303
    mov   edi,partition_types
305
    mov   edi,partition_types
304
    mov   ecx,partition_types_end-partition_types
306
    mov   ecx,partition_types_end-partition_types
305
    cld
307
    cld
306
    repne scasb                 ; is partition type ok?
308
    repne scasb                 ; is partition type ok?
307
    pop   ecx
309
    pop   ecx
308
    ret
310
    ret
309
 
311
 
310
scan_extended_types:
312
scan_extended_types:
311
    push  ecx
313
    push  ecx
312
    mov   edi,extended_types
314
    mov   edi,extended_types
313
    mov   ecx,extended_types_end-extended_types
315
    mov   ecx,extended_types_end-extended_types
314
    cld
316
    cld
315
    repne scasb                 ; is it extended partition?
317
    repne scasb                 ; is it extended partition?
316
    pop   ecx
318
    pop   ecx
317
    ret
319
    ret
318
 
320
 
319
problem_fat_dec_count:          ; bootsector is missing or another problem
321
problem_fat_dec_count:          ; bootsector is missing or another problem
320
    dec   [partition_count]     ; remove it from partition_count
322
    dec   [partition_count]     ; remove it from partition_count
321
 
323
 
322
problem_partition_or_fat:
324
problem_partition_or_fat:
323
    popad
325
    popad
324
 
326
 
325
problem_hd:
327
problem_hd:
326
    mov   [fs_type],0
328
    mov   [fs_type],0
327
    call  free_hd_channel
329
    call  free_hd_channel
328
    mov   [hd1_status],0        ; free
330
    mov   [hd1_status],0        ; free
329
    mov   [problem_partition],1
331
    mov   [problem_partition],1
330
    ret
332
    ret
331
 
333
 
332
hd_and_partition_ok:
334
hd_and_partition_ok:
333
    mov   eax,edx
335
    mov   eax,edx
334
    mov   [PARTITION_START],eax
336
    mov   [PARTITION_START],eax
335
        mov     edx, [PARTITION_END]
337
        mov     edx, [PARTITION_END]
336
        sub     edx, eax
338
        sub     edx, eax
337
        inc     edx     ; edx = length of partition
339
        inc     edx     ; edx = length of partition
338
 
340
 
339
;    mov   [hd_setup],1
341
;    mov   [hd_setup],1
340
    mov   ebx,buffer
342
    mov   ebx,buffer
341
    call  hd_read               ; read boot sector of partition
343
    call  hd_read               ; read boot sector of partition
342
        cmp     [hd_error], 0
344
        cmp     [hd_error], 0
343
        jz      boot_read_ok
345
        jz      boot_read_ok
344
        cmp     [fs_type], 7
346
        cmp     [fs_type], 7
345
        jnz     problem_fat_dec_count
347
        jnz     problem_fat_dec_count
346
; NTFS duplicates bootsector:
348
; NTFS duplicates bootsector:
347
; NT4/2k/XP+ saves bootsector copy in the end of disk
349
; NT4/2k/XP+ saves bootsector copy in the end of disk
348
; NT 3.51 saves bootsector copy in the middle of disk
350
; NT 3.51 saves bootsector copy in the middle of disk
349
        and     [hd_error], 0
351
        and     [hd_error], 0
350
        mov     eax, [PARTITION_END]
352
        mov     eax, [PARTITION_END]
351
        call    hd_read
353
        call    hd_read
352
        cmp     [hd_error], 0
354
        cmp     [hd_error], 0
353
        jnz     @f
355
        jnz     @f
354
        call    ntfs_test_bootsec
356
        call    ntfs_test_bootsec
355
        jnc     boot_read_ok
357
        jnc     boot_read_ok
356
@@:
358
@@:
357
        and     [hd_error], 0
359
        and     [hd_error], 0
358
        mov     eax, edx
360
        mov     eax, edx
359
        shr     eax, 1
361
        shr     eax, 1
360
        add     eax, [PARTITION_START]
362
        add     eax, [PARTITION_START]
361
        call    hd_read
363
        call    hd_read
362
        cmp     [hd_error], 0
364
        cmp     [hd_error], 0
363
        jnz     problem_fat_dec_count   ; ­¥ áã¤ì¡ ...
365
        jnz     problem_fat_dec_count   ; ­¥ áã¤ì¡ ...
364
boot_read_ok:
366
boot_read_ok:
365
;        mov     [hd_setup], 0
367
;        mov     [hd_setup], 0
366
; if we are running on NTFS, check bootsector
368
; if we are running on NTFS, check bootsector
367
        cmp     [fs_type], 7
369
        cmp     [fs_type], 7
368
        jz      ntfs_setup
370
        jz      ntfs_setup
369
 
371
 
370
    cmp   word [ebx+0x1fe],0xaa55 ; is it valid boot sector?
372
    cmp   word [ebx+0x1fe],0xaa55 ; is it valid boot sector?
371
    jnz   problem_fat_dec_count
373
    jnz   problem_fat_dec_count
372
 
374
 
373
    movzx eax,word [ebx+0xe]    ; sectors reserved
375
    movzx eax,word [ebx+0xe]    ; sectors reserved
374
    add   eax,[PARTITION_START]
376
    add   eax,[PARTITION_START]
375
    mov   [FAT_START],eax       ; fat_start = partition_start + reserved
377
    mov   [FAT_START],eax       ; fat_start = partition_start + reserved
376
 
378
 
377
    movzx eax,byte [ebx+0xd]    ; sectors per cluster
379
    movzx eax,byte [ebx+0xd]    ; sectors per cluster
378
    mov   [SECTORS_PER_CLUSTER],eax
380
    mov   [SECTORS_PER_CLUSTER],eax
379
 
381
 
380
    movzx ecx,word [ebx+0xb]    ; bytes per sector
382
    movzx ecx,word [ebx+0xb]    ; bytes per sector
381
    mov   [BYTES_PER_SECTOR],ecx
383
    mov   [BYTES_PER_SECTOR],ecx
382
 
384
 
383
    movzx eax,word [ebx+0x11]   ; count of rootdir entries (=0 fat32)
385
    movzx eax,word [ebx+0x11]   ; count of rootdir entries (=0 fat32)
384
    mov   edx,32
386
    mov   edx,32
385
    mul   edx
387
    mul   edx
386
    dec   ecx
388
    dec   ecx
387
    add   eax,ecx               ; round up if not equal count
389
    add   eax,ecx               ; round up if not equal count
388
    inc   ecx                   ; bytes per sector
390
    inc   ecx                   ; bytes per sector
389
    div   ecx
391
    div   ecx
390
    mov   [ROOT_SECTORS],eax    ; count of rootdir sectors
392
    mov   [ROOT_SECTORS],eax    ; count of rootdir sectors
391
 
393
 
392
    movzx eax,word [ebx+0x16]   ; sectors per fat <65536
394
    movzx eax,word [ebx+0x16]   ; sectors per fat <65536
393
    test  eax,eax
395
    test  eax,eax
394
    jnz   fat16_fatsize
396
    jnz   fat16_fatsize
395
    mov   eax,[ebx+0x24]        ; sectors per fat
397
    mov   eax,[ebx+0x24]        ; sectors per fat
396
  fat16_fatsize:
398
  fat16_fatsize:
397
    mov   [SECTORS_PER_FAT],eax
399
    mov   [SECTORS_PER_FAT],eax
398
 
400
 
399
    movzx eax,byte [ebx+0x10]   ; number of fats
401
    movzx eax,byte [ebx+0x10]   ; number of fats
400
    test  eax,eax               ; if 0 it's not fat partition
402
    test  eax,eax               ; if 0 it's not fat partition
401
    jz    problem_fat_dec_count
403
    jz    problem_fat_dec_count
402
    mov   [NUMBER_OF_FATS],eax
404
    mov   [NUMBER_OF_FATS],eax
403
    imul  eax,[SECTORS_PER_FAT]
405
    imul  eax,[SECTORS_PER_FAT]
404
    add   eax,[FAT_START]
406
    add   eax,[FAT_START]
405
    mov   [ROOT_START],eax      ; rootdir = fat_start + fat_size * fat_count
407
    mov   [ROOT_START],eax      ; rootdir = fat_start + fat_size * fat_count
406
    add   eax,[ROOT_SECTORS]    ; rootdir sectors should be 0 on fat32
408
    add   eax,[ROOT_SECTORS]    ; rootdir sectors should be 0 on fat32
407
    mov   [DATA_START],eax      ; data area = rootdir + rootdir_size
409
    mov   [DATA_START],eax      ; data area = rootdir + rootdir_size
408
 
410
 
409
    movzx eax,word [ebx+0x13]   ; total sector count <65536
411
    movzx eax,word [ebx+0x13]   ; total sector count <65536
410
    test  eax,eax
412
    test  eax,eax
411
    jnz   fat16_total
413
    jnz   fat16_total
412
    mov   eax,[ebx+0x20]        ; total sector count
414
    mov   eax,[ebx+0x20]        ; total sector count
413
  fat16_total:
415
  fat16_total:
414
    add   eax,[PARTITION_START]
416
    add   eax,[PARTITION_START]
415
    dec   eax
417
    dec   eax
416
    mov   [PARTITION_END],eax
418
    mov   [PARTITION_END],eax
417
    inc   eax
419
    inc   eax
418
    sub   eax,[DATA_START]      ; eax = count of data sectors
420
    sub   eax,[DATA_START]      ; eax = count of data sectors
419
    xor   edx,edx
421
    xor   edx,edx
420
    div   dword [SECTORS_PER_CLUSTER]
422
    div   dword [SECTORS_PER_CLUSTER]
421
    inc   eax
423
    inc   eax
422
    mov   [LAST_CLUSTER],eax
424
    mov   [LAST_CLUSTER],eax
423
    dec   eax                   ; cluster count
425
    dec   eax                   ; cluster count
424
 
426
 
425
    ; limits by Microsoft Hardware White Paper v1.03
427
    ; limits by Microsoft Hardware White Paper v1.03
426
    cmp   eax,4085              ; 0xff5
428
    cmp   eax,4085              ; 0xff5
427
    jb    problem_fat_dec_count ; fat12 not supported
429
    jb    problem_fat_dec_count ; fat12 not supported
428
    cmp   eax,65525             ; 0xfff5
430
    cmp   eax,65525             ; 0xfff5
429
    jb    fat16_partition
431
    jb    fat16_partition
430
 
432
 
431
fat32_partition:
433
fat32_partition:
432
    mov   eax,[ebx+0x2c]        ; rootdir cluster
434
    mov   eax,[ebx+0x2c]        ; rootdir cluster
433
    mov   [ROOT_CLUSTER],eax
435
    mov   [ROOT_CLUSTER],eax
434
    movzx eax,word [ebx+0x30]   ; fs info sector
436
    movzx eax,word [ebx+0x30]   ; fs info sector
435
    add   eax,[PARTITION_START]
437
    add   eax,[PARTITION_START]
436
    mov   [ADR_FSINFO],eax
438
    mov   [ADR_FSINFO],eax
437
 
439
 
438
    popad
440
    popad
439
 
441
 
440
    mov   [fatRESERVED],0x0FFFFFF6
442
    mov   [fatRESERVED],0x0FFFFFF6
441
    mov   [fatBAD],0x0FFFFFF7
443
    mov   [fatBAD],0x0FFFFFF7
442
    mov   [fatEND],0x0FFFFFF8
444
    mov   [fatEND],0x0FFFFFF8
443
    mov   [fatMASK],0x0FFFFFFF
445
    mov   [fatMASK],0x0FFFFFFF
444
    mov   [fs_type],32         ; Fat32
446
    mov   [fs_type],32         ; Fat32
445
    call  free_hd_channel
447
    call  free_hd_channel
446
    mov   [hd1_status],0        ; free
448
    mov   [hd1_status],0        ; free
447
    ret
449
    ret
448
 
450
 
449
fat16_partition:
451
fat16_partition:
450
    xor   eax,eax
452
    xor   eax,eax
451
    mov   [ROOT_CLUSTER],eax
453
    mov   [ROOT_CLUSTER],eax
452
 
454
 
453
    popad
455
    popad
454
 
456
 
455
    mov   [fatRESERVED],0x0000FFF6
457
    mov   [fatRESERVED],0x0000FFF6
456
    mov   [fatBAD],0x0000FFF7
458
    mov   [fatBAD],0x0000FFF7
457
    mov   [fatEND],0x0000FFF8
459
    mov   [fatEND],0x0000FFF8
458
    mov   [fatMASK],0x0000FFFF
460
    mov   [fatMASK],0x0000FFFF
459
    mov   [fs_type],16         ; Fat16
461
    mov   [fs_type],16         ; Fat16
460
    call  free_hd_channel
462
    call  free_hd_channel
461
    mov   [hd1_status],0        ; free
463
    mov   [hd1_status],0        ; free
462
    ret
464
    ret
463
>
465
>
464
>
466
>
465
>
467
>
466
>
468
>
467
>
469
>
468
>
470
>