Subversion Repositories Kolibri OS

Rev

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

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