Subversion Repositories Kolibri OS

Rev

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

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