source: trunk/BOOTCODE/REGULAR/PARTSCAN.ASM@ 43

Last change on this file since 43 was 43, checked in by Ben Rietbroek, 12 years ago

BSS Corruption Problem located (auxdebug on) [2012-02-21]

WARNING!!

All commits upto and including the commit of [2012-05-13] contain
a severe bug!! Building from these sources and then disabling
the 'force LBA' feature while also using the drive-letter feature or
editing the label can DESTROY THE MBR on ALL ATTACHED DISKS!!
DO NOT DISABLE 'FORCE LBA USAGE' WHEN BUILT FROM THE THESE COMMITS!!

Problem

o Function with Xrefs goes out-of-bounds because hideparttable is too small

Has only 30 entries and should be 45.
Lost partition checker initializes out-of-bounds.

Info

o About the hideparttable

For each partition it can be specified which other partitions need to
be hidden when that partition is booted. This is useful for legacy DOS
but also braindead Windows that presents HPFS/JFS partitions as
unformatted and tries to persuade the user to format them.
With v1.07 the numer of partitions that can be handled was expanded from
30 to 45, but the size of the hideparttable was overseen.

o The need to compress the hideparttable

The old size was 30x30=900 bytes while the required size is 45x45=2045 bytes.
This amount of space is not available in the image.
Since 6 bits are enough to identify the partition number to be hidden,
the solution is to devide the table into bitfields. This will result
in a table of (45*45*6)/8=1519 bytes, which can be fitted.

Changes

Revamped the sources quite a bit and moved the history to a separate
file. (AIR-BOOT.HIS)

New

o FIXCODE script for Linux

Just until the C version is ready...

File size: 32.2 KB
Line 
1; AiR-BOOT (c) Copyright 1998-2008 M. Kiewitz
2;
3; This file is part of AiR-BOOT
4;
5; AiR-BOOT is free software: you can redistribute it and/or modify it under
6; the terms of the GNU General Public License as published by the Free
7; Software Foundation, either version 3 of the License, or (at your option)
8; any later version.
9;
10; AiR-BOOT is distributed in the hope that it will be useful, but WITHOUT ANY
11; WARRANTY: without even the implied warranty of MERCHANTABILITY or FITNESS
12; FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13; details.
14;
15; You should have received a copy of the GNU General Public License along with
16; AiR-BOOT. If not, see <http://www.gnu.org/licenses/>.
17;
18;---------------------------------------------------------------------------
19; AiR-BOOT / PARTiTiON SCANNING
20;---------------------------------------------------------------------------
21
22
23IFDEF ModuleNames
24DB 'PARTSCAN',0
25ENDIF
26
27; Note: This is complex code. So make sure that you know what you are doing in
28; here.
29
30PARTSCAN_ScanForPartitions Proc Near
31 ; Reset X-Reference
32 call PARTSCAN_ResetXref
33
34 mov dh, TotalHarddiscs
35 xor al, al
36 mov NewPartitions, al
37
38 mov CurIO_Scanning, 1 ; Set flag due scanning partitions
39 mov dl, 80h ; is first harddisc
40 PSSFP_HarddiscLoop:
41
42 push dx
43 call PARTSCAN_ScanDriveForPartitions
44 pop dx
45 inc dl
46 dec dh
47 jnz PSSFP_HarddiscLoop
48 mov CurIO_Scanning, 0 ; Reset flag due scanning complete
49
50 ; Use X-Reference to sync NewPartitionTable with Hide-Config
51 call PARTSCAN_SyncHideConfigWithXref
52
53 ; Now we copy the new IPT over the old one...
54 mov si, offset NewPartTable
55 mov di, offset PartitionTable
56 ;movzx ax, NewPartitions
57 mov al,NewPartitions
58 mov ah,0
59
60 mov CFG_Partitions, al
61 mov bl, LocIPT_LenOfIPT
62 mul bl
63 mov cx, ax
64 rep movsb
65
66 ; and the New Logical Drive Letter table as well...
67 mov si, offset NewDriveLetters
68 mov di, offset DriveLetters
69 mov cx, LocIPT_MaxPartitions
70 rep movsb
71
72; [Linux support removed since v1.02]
73; ; Search for any Linux partition and remember, if it got found...
74; mov si, offset PartitionTable
75; movzx cx, CFG_Partitions
76; xor dl, dl ; DL - Is Linux here ?
77; or cx, cx
78; jz PSSFP_NoPartitions
79; PSSFP_LinuxLoop:
80; cmp bptr [si+LocIPT_SystemID], 083h ; Hard-Coded
81; jne PSSFP_NoLinux
82; mov dl, 1 ; Linux found...
83; PSSFP_NoLinux:
84; add si, LocIPT_LenOfIPT
85; loop PSSFP_LinuxLoop
86; PSSFP_NoPartitions:
87; mov GotLinux, dl ; Set Flag
88
89 ; ...and finally check, if we need to set a Drive-Letter
90 mov dl, AutoDrvLetter
91 or dl, dl
92 jz PSSFP_NoAutoDriveLetter
93 ;movzx cx, CFG_Partitions
94 mov cl,CFG_Partitions
95 mov ch,0
96
97 or cx, cx
98 jz PSSFP_NoAutoDriveLetter
99 mov si, offset PartitionTable
100 mov di, offset DriveLetters
101 mov ax, wptr [AutoDrvLetterSerial]
102 mov bx, wptr [AutoDrvLetterSerial+2]
103 PSSFP_AutoDrvLetterLoop:
104 cmp ax, [si+LocIPT_Serial]
105 jne PSSFP_AutoDrvLetterNoMatch
106 cmp bx, [si+LocIPT_Serial+2]
107 jne PSSFP_AutoDrvLetterNoMatch
108 ; We got a match, so set Drive-Letter in DL
109 or bptr [si+LocIPT_Flags], Flags_DriveLetter
110 mov [di], dl
111 PSSFP_AutoDrvLetterNoMatch:
112 add si, LocIPT_LenOfIPT
113 inc di
114 loop PSSFP_AutoDrvLetterLoop
115 mov AutoDrvLetter, 0 ; Disable after processing...
116 PSSFP_NoAutoDriveLetter:
117 ret
118PARTSCAN_ScanForPartitions EndP
119
120; Scannt die Festplatte auf jegliche Partitionstabellen...
121; Falls eine fehlerhafte Partition gefunden wird, wird abgebrochen.
122; falls eine Extended Partition (DOS) gefunden wird, wird erneut gescannt.
123PARTSCAN_ScanDriveForPartitions Proc Near
124 xor ax, ax
125 xor bx, bx ; Location Absoluter Sektor 0
126 mov cx, 0001h
127 xor dh, dh ; Location Zylinder 0, Side 0, Sektor 1 MBR
128 mov [ExtendedAbsPosSet], al
129 mov wptr [ExtendedAbsPos+0], ax
130 mov wptr [ExtendedAbsPos+2], ax
131 PSSDFP_LoadThisPartition:
132
133 call DriveIO_LoadPartition ; Load a partition record
134
135 jc PSSDFP_InvalidPartition
136
137 ; LVM Support - Reads LVM Information Sector
138 call DriveIO_LoadLVMSector ; Load LVM sector
139
140 call PARTSCAN_ScanPartition
141 IFDEF ReleaseCode
142 call DriveIO_SavePartition
143 ENDIF
144 call PARTSCAN_ScanPartitionForExtended
145 jc PSSDFP_LoadThisPartition
146 PSSDFP_InvalidPartition:
147 ret
148PARTSCAN_ScanDriveForPartitions EndP
149
150; Scans Current Partition for Extended Partitions, if found, AX,BX,CX,DX will
151; be set to this location and Carry will be set
152PARTSCAN_ScanPartitionForExtended Proc Near Uses si
153 mov si, offset PartitionSector+446 ; DS:SI - 1st partition entry
154 xor ax, ax
155 PSSPFE_ScanLoop:
156 mov al, [si+LocBRPT_SystemID]
157 cmp al, 5 ; Is Partition EXTENDED ?
158 je PSSPFE_ExtendedPartition
159 cmp al, 0Fh ; Is Partition EXTENDED (M$) ?
160 je PSSPFE_ExtendedPartition
161 jmp PSSPFE_IgnorePartition
162 PSSPFE_ExtendedPartition:
163 mov ax, wptr [si+LocBRPT_RelativeBegin]
164 mov bx, wptr [si+LocBRPT_RelativeBegin+2]
165 add ax, wptr [ExtendedAbsPos+0] ; Adjust...
166 adc bx, wptr [ExtendedAbsPos+2] ; (Shit Design!)
167 test [ExtendedAbsPosSet], 1
168 jnz PSSPFE_ExtendedMainKnown
169 mov wptr [ExtendedAbsPos+0], ax
170 mov wptr [ExtendedAbsPos+2], bx
171 mov [ExtendedAbsPosSet], 1
172 PSSPFE_ExtendedMainKnown:
173 mov cx, wptr [si+LocBRPT_BeginSector] ; Cylinder/Sector
174 mov dh, bptr [si+LocBRPT_BeginHead] ; Head
175 mov dl, bptr [CurPartition_Location+4] ; Drive
176 stc
177 jmp PSSPFE_EndOfSearch
178 PSSPFE_IgnorePartition:
179 add si, LocBRPT_LenOfEntry
180 cmp si, 500+offset PartitionSector
181 jb PSSPFE_ScanLoop
182 clc
183 PSSPFE_EndOfSearch:
184 ret
185PARTSCAN_ScanPartitionForExtended EndP
186
187; The following routines have NOT *DS* set to CS, so we must address via ES
188PARTSCAN_ScanPartition Proc Near Uses ax si
189 mov si, offset PartitionSector+446 ; DS:SI - 1st Partition-Entry
190 PSSP_ScanLoop:
191 mov al, bptr [si+LocBRPT_SystemID]
192 cmp al, 5 ; Is Partition EXTENDED ?
193 je PSSP_IgnorePartition
194 cmp al, 0Fh ; Is Partition EXTENDED (M$-DOS7) ?
195 je PSSP_IgnorePartition
196 cmp al, 0 ; Is Partition EMPTY ?
197 je PSSP_IgnorePartition
198 ; Ignore these partitions, because there are no real Partitions
199 call DEBUG_DumpBSSSectors
200 call PARTSCAN_CheckThisPartition
201 call DEBUG_DumpBSSSectors
202 PSSP_IgnorePartition:
203 ; L”scht das Boot-Able Flag...
204 and byte ptr [si+LocBRPT_Flags], 7Fh ; Reset the Active-Flag
205 add si, LocBRPT_LenOfEntry ; 16 Bytes per partition entry
206 cmp si, 500+offset PartitionSector
207 jb PSSP_ScanLoop
208 ; If we are on first HDD and in primary partition table -> mark primary
209 cmp bptr [CurPartition_Location+4], 80h ; Drive
210 jne PSSP_NoMarkPrimary
211 cmp wptr [CurPartition_Location+0], 0
212 jne PSSP_NoMarkPrimary
213 cmp wptr [CurPartition_Location+2], 0 ; Absolute Location
214 jne PSSP_NoMarkPrimary
215 call PART_MarkFirstGoodPrimary
216 PSSP_NoMarkPrimary:
217 ret
218PARTSCAN_ScanPartition EndP
219
220MBR_NoName_Patched db 15 dup (0)
221
222; Will insert this partition into NewPartTable and compare it to our "old"
223; LocIPT-table. If the same partition is found there, Flags&CRC are taken from
224; the old table, otherwise they are generated freshly.
225; Will also fill out PartitionXref to sync HideConfig later
226; In: SI - Points to Partition-Entry (16-Bytes)
227PARTSCAN_CheckThisPartition Proc Near Uses di si
228 local PartSystemID:byte, PartTypeFlags:byte
229 local PartCRC:word, PartPtr:word
230
231 mov wptr [PartPtr], si ; Save Pointer to PartitionEntry
232
233 mov al, bptr [si+LocBRPT_SystemID]
234 mov PartSystemID, al
235
236 mov cx, wptr [si+LocBRPT_BeginSector] ; Cylinder/Sector
237 mov dh, bptr [si+LocBRPT_BeginHead] ; Head
238 mov dl, bptr [CurPartition_Location+4] ; Drive
239 mov ax, wptr [si+LocBRPT_RelativeBegin] ; Absolute Sector
240 mov bx, wptr [si+LocBRPT_RelativeBegin+2]
241 add ax, wptr [CurPartition_Location+0] ; +Partition-Absolute
242 adc bx, wptr [CurPartition_Location+2] ; sectors
243
244 ; Sets up DS:SI - TmpSector
245 call DriveIO_LoadTmpSector ; Loads Boot record ; Rousseau: LOAD PARTITION BOOT RECORD !!
246
247
248
249 push si
250 mov bx, 4B4Dh ; Magic 'MK' :)
251 call MBR_GetCheckOfSector
252 mov PartCRC, bx ; Save Partition's-CRC
253
254 ; ------------------------------ Gets internal infos of partition type
255 mov al, PartSystemID
256 call PART_SearchFileSysName
257 ; Replies AH - FileSysFlags, AL - UnhiddenID, SI - FileSystemNamePtr
258 mov di, si
259 mov PartTypeFlags, ah
260 mov PartSystemID, al ; Use Unhidden-ID
261 pop si
262
263 ;================================
264 ; AL - File System ID (Unhidden)
265 ; AH - File System Flags
266 ; SI - Boot-Record of Partition
267 ; DI - File System Name
268 ;================================
269
270 cmp PartSystemID, 07h ; We got IFS here?
271 jne PCCTP_IFSdone
272 ; Check, if 'JFS ' is at DWORD offset 36h ; Rousseau: JFS check (LVM / IPT?)
273 cmp wptr [si+36h], 'FJ'
274 jne PCCTP_IFSnoJFS
275 cmp wptr [si+38h], ' S'
276 jne PCCTP_IFSnoJFS
277 mov PartSystemID, 0FCh ; FC is JFS internally
278 jmp PCCTP_IFSdone
279 PCCTP_IFSnoJFS:
280 ; Check, if 'HPFS' is at DWORD offset 36h
281 cmp wptr [si+36h], 'PH'
282 jne PCCTP_ProbablyNTFS
283 cmp wptr [si+38h], 'SF'
284 je PCCTP_IFSdone ; 07 is HPFS internally
285 PCCTP_ProbablyNTFS:
286 inc PartSystemID ; 08 is NTFS instead of 07
287 PCCTP_IFSdone:
288
289
290 ; First check, if LVM Information Sector is available and this partition
291 ; is supported.
292 push ax
293 push dx
294 push si
295 push di
296 mov si, wptr [PartPtr]
297 mov ax, wptr [si+LocBRPT_RelativeBegin] ; Absolute Sector
298 mov dx, wptr [si+LocBRPT_RelativeBegin+2]
299 add ax, wptr [CurPartition_Location+0] ; +Partition-Absolute
300 adc dx, wptr [CurPartition_Location+2] ; sectors
301 mov si, offset LVMSector
302 call LVM_SearchForPartition ; Search for DX:AX partition
303 jnc PCCTP_CheckBootRecord
304 ; Check, if volume has driveletter assigned and remember it for later
305 mov al, [si+LocLVM_VolumeLetter]
306 or al, al
307 jnz PCCTP_HasVolumeLetter
308 mov al, 1 ; 0 would mean "not LVM supported"
309 PCCTP_HasVolumeLetter:
310 ; Save VolumeLetter in separate table
311 ;movzx bx, NewPartitions ; NewPartitions is one behind here, so
312 mov bl,NewPartitions ; NewPartitions is one behind here, so
313 mov bh,0
314
315 mov [PartitionVolumeLetters+bx], al ; it's already a zero-based offset
316 ; Now copy VolumeID and VolumeName to temporary space
317 mov di, offset MBR_NoName_Patched
318 mov ax, [si+LocLVM_PartitionID]
319 stosw
320 mov ax, [si+LocLVM_PartitionID+2]
321 stosw
322 ; Set Serial-Field to LVM-VolumeID
323
324 push di
325 add si, LocLVM_VolumeName ; Use LVM VolumeName
326 ;add si, LocLVM_PartitionName ; Use LVM PartitionName
327 mov cx, 5
328 rep movsw ; Copy LVM-PartitionName to Temp Space
329 movsb ; (11 bytes in total)
330 pop di
331
332
333 ; Check if this is an IBM-BM partition
334 cmp PartSystemID, 0ah
335 jne PCCTP_NoIbmBm
336
337 ; It is, so override the name given by IBM-BM by one that
338 ; fits in 11 chars.
339 mov si, offset ibm_bm_name
340 mov cx,5
341 rep movsw
342 movsb
343
344
345
346 PCCTP_NoIbmBm:
347 pop di
348 pop si
349 pop dx
350 pop ax
351 mov si, offset MBR_NoName_Patched
352 xor ah, ah ; no Flags_NoPartName
353 jmp PCCTP_NameSearchInIPT
354
355 PCCTP_CheckBootRecord:
356 pop di
357 pop si
358 pop dx
359 pop ax
360
361 test ah, FileSysFlags_NoName ; No-Name-Flag ? -> No Partition Name
362
363 jz PCCTP_ThereIsAName
364 jmp PCCTP_ThereIsNoName ; available
365
366 PCCTP_ThereIsAName:
367
368 ; We check for NTFS (got detected a little bit earlier in this routine)
369 cmp PartSystemID, 08h ; We got IFS/NTFS here?
370 jne PCCTP_IsNoNTFS
371 jmp PCCTP_ThereIsNoName ; NTFS has no volume label
372 PCCTP_IsNoNTFS:
373 add si, 2Bh ; DS:SI - Partition-Name
374 test ah, FileSysFlags_FAT32 ; FAT32 specific name getting ?
375
376 jz PCCTP_ResumeNormal
377
378 add si, 1Ch ; Fix for FAT 32, shiat
379 PCCTP_ResumeNormal:
380 mov cx, 11 ; 11 bytes length
381 call PART_CheckForValidPartName
382 jc PCCTP_ThereIsAName2
383
384 jmp PCCTP_ThereIsNoName
385
386 PCCTP_ThereIsAName2:
387
388 sub si, 4 ; DS:SI -> Serial&Name (15-Bytes)
389 xor ah, ah ; no Flags_NoPartName
390; jmp PCCTP_NameSearchInIPT
391
392 ;=======================================================
393 ; NAME SEARCH in IPT-Table
394 ; DS:SI - Serial&Name of Current Partition (15-Bytes)
395 ; AH - NoPartName-Flag (!MUST! be merged with Flags)
396 ;=======================================================
397 PCCTP_NameSearchInIPT:
398 xor ah, ah ; no Flags_NoPartName cause PartName valid
399 mov di, offset PartitionTable ; ES:DI - IPT-Start
400 mov dl, CFG_Partitions
401 or dl, dl
402 jnz PCCTP_SerialNameCompLoop
403 jmp PCCTP_CompareFailed
404 PCCTP_SerialNameCompLoop:
405 mov al, [di+LocIPT_Flags]
406 test al, Flags_NowFound
407 jnz PCCTP_SerialNameAlreadyFound
408 ; Now compare IPT with current Partition
409 mov cx, 15 ; Serial&Name (15-Bytes)
410 push si
411 push di
412 repz cmpsb
413 pop di
414 pop si
415
416 jne PCCTP_NoMatchYet
417
418 jmp PCCTP_Match
419
420 PCCTP_NoMatchYet:
421
422 PCCTP_SerialNameAlreadyFound:
423 add di, LocIPT_LenOfIPT
424 dec dl
425 jnz PCCTP_SerialNameCompLoop
426
427 ; if we didn't find Serial&Name, let's try Name-only without Serial
428 mov di, offset PartitionTable ; ES:DI - IPT-Start
429 mov dl, CFG_Partitions
430 PCCTP_NameCompLoop:
431 mov al, [di+LocIPT_Flags]
432 test al, Flags_NowFound
433 jnz PCCTP_NameAlreadyFound
434 ; Now compare IPT with current Partition
435 mov cx, 11 ; Name only (11-Bytes)
436 push si
437 push di
438 add si, 4
439 add di, 4 ; Skip over Serial-Field
440 repz cmpsb
441 pop di
442 pop si
443 jne PCCTP_NameNoMatch
444 mov cx, [si+0] ; Get Serial
445 mov [di+0], cx
446 mov cx, [si+2]
447 mov [di+2], cx ; ...and put it into IPT
448 jmp PCCTP_Match
449 PCCTP_NameNoMatch:
450 PCCTP_NameAlreadyFound:
451 add di, LocIPT_LenOfIPT
452 dec dl
453 jnz PCCTP_NameCompLoop
454 PCCTP_NameCompFailed:
455
456 ; So finally we search for Location and PartitionID
457 push si
458 ; Initialize some stuff for Location-Search
459 mov dh, PartSystemID
460 mov si, [PartPtr] ; DS:SI - Cur Partition Table
461 ; Relative Sector to MBR/EPR
462 mov cx, wptr [si+LocBRPT_RelativeBegin]
463 mov bx, wptr [si+LocBRPT_RelativeBegin+2]
464 add cx, [CurPartition_Location+0]
465 add bx, [CurPartition_Location+2]
466 ; BX:CX - Absolute First Sector of Partition on HDD
467 pop si
468 mov di, offset PartitionTable ; ES:DI - IPT-Start
469 mov dl, CFG_Partitions
470 PCCTP_NameLocCompLoop:
471 mov al, [di+LocIPT_Flags]
472 test al, Flags_NowFound
473 jnz PCCTP_NameLocAlreadyFound
474 ; Now compare IPT with current Partition
475 cmp dh, [di+LocIPT_SystemID]
476 jne PCCTP_NameLocMismatch
477 cmp cx, [di+LocIPT_AbsoluteBegin]
478 jne PCCTP_NameLocMismatch
479 cmp bx, [di+LocIPT_AbsoluteBegin+2]
480 jne PCCTP_NameLocMismatch
481 ; We matched location, now copy the current PartitionID and Name to
482 ; the old IPT.
483 push di
484 add di, LocIPT_Serial ; DS:SI - LocIPT-Serial&Name
485 mov cx, 15
486 rep movsb ; Copy 15 bytes
487 pop di
488 jmp PCCTP_Match
489 PCCTP_NameLocMismatch:
490 PCCTP_NameLocAlreadyFound:
491 add di, LocIPT_LenOfIPT
492 dec dl
493 jnz PCCTP_NameLocCompLoop
494 ; None of the searches worked, so forget it...
495 jmp PCCTP_CompareFailed
496
497 PCCTP_ThereIsNoName:
498 ; Try to find this partition by comparing location and PartitionID
499 ; aka LocIPT_AbsoluteBegin:dword and LocIPT_SystemID
500 ; If found, simply go to the normal match-routine, otherwise use the
501 ; File-System-Name to build the Volume-Label for the New IPT Entry.
502 mov dh, PartSystemID
503 mov si, [PartPtr] ; DS:SI - Cur Partition Table
504 ; Relative Sector to MBR/EPR
505 mov cx, wptr [si+LocBRPT_RelativeBegin]
506 mov bx, wptr [si+LocBRPT_RelativeBegin+2]
507 add cx, [CurPartition_Location+0]
508 add bx, [CurPartition_Location+2]
509 ; Build a standard-Volume Label from FileSystemNamePtr
510 ; We have to call SearchFileSysName again because of NTFS
511 push ax
512 push cx
513 mov al, dh
514 call PART_SearchFileSysName ; We want SI here <- FileSystemNamePtr
515 mov di, offset MBR_NoName_Patched
516 xor ax, ax
517 stosw
518 stosw ; Set Serial-Field to "NUL"
519 mov cx, 4
520 rep movsw ; Copy FileSystemName to Temp Space
521 xor ax, ax
522 stosw
523 stosb ; Fill last 3 bytes with "NUL"
524 mov si, offset MBR_NoName_Patched
525 pop cx
526 pop ax
527 ;=======================================================
528 ; LOCATION SEARCH in IPT-Table
529 ; DH - PartitionID of Current Partition
530 ; BX:CX - AbsoluteBegin of Current Partition
531 ; AH - NoPartName-Flag (!MUST! be merged with Flags)
532 ; DS:SI - Serial&Name of Current Partition (15-Bytes)
533 ;=======================================================
534 PCCTP_LocSearchInIPT:
535 mov ah, Flags_NoPartName ;set Flags_NoPartName, PartName invalid
536 mov di, offset PartitionTable ; ES:DI - IPT-Start
537 mov dl, CFG_Partitions
538 or dl, dl
539 jz PCCTP_LocCompFailed
540 PCCTP_LocCompLoop:
541 mov al, [di+LocIPT_Flags]
542 test al, Flags_NowFound
543 jnz PCCTP_LocAlreadyFound
544 ; Now compare IPT with current Partition
545 cmp dh, [di+LocIPT_SystemID]
546 jne PCCTP_LocMismatch
547 cmp cx, [di+LocIPT_AbsoluteBegin]
548 jne PCCTP_LocMismatch
549 cmp bx, [di+LocIPT_AbsoluteBegin+2]
550 jne PCCTP_LocMismatch
551 jmp PCCTP_Match
552 PCCTP_LocMismatch:
553 PCCTP_LocAlreadyFound:
554 add di, LocIPT_LenOfIPT
555 dec dl
556 jnz PCCTP_LocCompLoop
557 PCCTP_LocCompFailed:
558 jmp PCCTP_CompareFailed
559
560 ; ==================================
561 ; =MATCH=, found partition in IPT...
562 ; AH - NoPartName-Flag (!MUST! be merged with Flags)
563 ; DL - IPT Partition Number from Loop (inverted)
564 ; ES:DI - LocIPT-Pointer to found IPT-entry
565 ; ==================================
566 PCCTP_Match:
567 mov ch, ah
568 ; Save the new location of this partition in the Xref-Table
569 ; for converting HideConfig.
570 mov dh, dl
571 mov dl, CFG_Partitions
572 sub dl, dh
573 mov dh, NewPartitions ; is actually a counter
574 call PARTSCAN_DefXref ; DL-IPT-Partition, DH-NewPartition
575
576 ; Get Saved-Flags...
577 mov cl, bptr [di+LocIPT_Flags] ; Use saved Flags
578
579 ; ...and Saved-CRC if available...
580 mov ax, wptr [di+LocIPT_BootRecordCRC]
581 or ax, ax
582 jz PCCTP_UseNewComputedCRC
583 mov PartCRC, ax ; Use saved IPT-CRC
584 PCCTP_UseNewComputedCRC:
585 ; ...and mark partition in IPT as already found
586 or bptr [di+LocIPT_Flags], Flags_NowFound
587 ; ...get Serial&Name from IPT-table...
588 mov si, di
589 add si, LocIPT_Serial ; DS:SI - LocIPT-Serial&Name
590 jmp PCCTP_AddToNew
591
592 ; =================================
593 ; =FAILED= search, not found in IPT
594 ; AH - NoPartName-Flag (!MUST! be merged with Flags)
595 ; DS:SI - Serial&Name of Current Partition (15-Bytes)
596 ; =================================
597 PCCTP_CompareFailed:
598 mov ch, ah
599 ; Default Flags hinzufgen...
600 mov cl, LocIPT_DefaultFlags
601
602 mov al, PartTypeFlags
603 ; May I auto-add partitions ?
604 test CFG_PartitionsDetect, 1
605 jz PCCTP_MayNotAddAny ; add, but non-bootable
606 test al, FileSysFlags_BootAble ; AH kam von SearchFileSysName
607 jnz PCCTP_PerhapsBootAble
608 PCCTP_MayNotAddAny:
609 mov cl, LocIPT_DefaultNonBootFlags
610 PCCTP_PerhapsBootAble:
611
612 ; On FAT32-partitions, default to P-Flag (which means using M$-hack)
613 ; Anyway, this hack has to be globaly activated by the user manually...
614 cmp PartSystemID, 09h ; Hardcoded: FAT32
615 je PCCTP_NeedsExtMShack
616 cmp PartSystemID, 0Bh
617 je PCCTP_NeedsExtMShack
618 cmp PartSystemID, 0Ch
619 je PCCTP_NeedsExtMShack
620 cmp PartSystemID, 0Eh ; FAT16 above 8 GB
621 jne PCCTP_NoExtMShack
622 ; We only get here, when the SystemID seems to be an M$ "invention"...
623 PCCTP_NeedsExtMShack:
624 or cl, Flags_ExtPartMShack
625 PCCTP_NoExtMShack:
626
627 ;================================================
628 ; CL - IPT-Partition-Flags, CH - NoPartName-Flag
629 ; DS:SI - PartSerial&Name (15-Bytes)
630 ;================================================
631 PCCTP_AddToNew:
632 mov al, Flags_NoPartName ; Unset NoPartName
633 not al
634 and cl, al
635 or cl, ch ; CL = Both CL and CH merged
636
637 ; Calculate Pointer to IPT
638 mov di, offset NewPartTable ; ES:DI - NewPartTable
639 ;movzx ax, NewPartitions
640 mov al,NewPartitions
641 mov ah,0
642
643 mov bl, LocIPT_LenOfIPT
644 mul bl
645 add di, ax ; ES:DI - Last+1 Entry of NewPartTable
646
647 ; Now finally write this partition to our IPT
648 ;=============================================
649 push cx
650 mov cx, 15 ; Copy Serial&Name...
651 rep movsb
652 pop cx
653
654 mov si, [PartPtr] ; DS:SI - Cur Partition Entry
655 mov al, bptr [CurPartition_Location+4] ; Drive
656 stosb
657 mov al, PartSystemID ; Unhidden SystemID
658 stosb
659 mov al, cl ; Partition-Flags from register...
660 stosb
661 mov ax, PartCRC ; BootRecordCRC...
662 stosw
663 mov al, bptr [si+LocBRPT_BeginHead]
664 stosb
665 mov ax, wptr [si+LocBRPT_BeginSector] ; Cylinder/Sector
666 stosw
667 mov al, bptr [CurPartition_Location+5] ; Head of Part-Table
668 stosb
669 mov ax, wptr [CurPartition_Location+6] ; Cylinder/Sector
670 stosw
671 mov ax, wptr [si+LocBRPT_RelativeBegin]
672 mov bx, wptr [si+LocBRPT_RelativeBegin+2]
673 mov cx, wptr [CurPartition_Location+0] ; +Partition-Absolute
674 mov dx, wptr [CurPartition_Location+2] ; sectors
675 add ax, cx
676 adc bx, dx
677 stosw
678 mov ax, bx
679 stosw
680 mov ax, cx ; Absolute sector of partition table
681 stosw
682 mov ax, dx
683 stosw
684 inc NewPartitions ; NEW IPT Entry DONE
685
686 cmp NewPartitions, LocIPT_MaxPartitions
687 jbe PCCTP_NotTooManyPartitions
688
689 mov si, offset TXT_TooManyPartitions
690 call MBR_Teletype
691 jmp MBR_HaltSystem
692
693
694 PCCTP_NotTooManyPartitions:
695 ; UNHIDE PARTITION, if it was hidden previously
696 mov al, PartSystemID
697 cmp al, 08h ; internally IFS/NTFS?
698 je PCCTP_GotInternalIFS
699 cmp al, 0FCh ; internally IFS/JFS?
700 jne PCCTP_NoInternalIFS
701 PCCTP_GotInternalIFS:
702 mov al, 07h
703 PCCTP_NoInternalIFS:
704 mov bptr [si+LocBRPT_SystemID], al
705
706 ; Calculate Size of this partition and put it into separate table...
707 ;movzx ax, NewPartitions
708 mov al,NewPartitions
709 mov ah,0
710
711 dec ax
712 mov bx, ax
713 shl ax, 1
714 shl bx, 2
715 add ax, bx ; My way [tm] of multiplying with 6
716 mov di, offset PartitionSizeTable
717 add di, ax ; DI - Partition Size-Element
718 mov ax, wptr [si+LocBRPT_AbsoluteLength] ; Sector-Size
719 mov bx, wptr [si+LocBRPT_AbsoluteLength+2]
720 call PART_FillOutSizeElement
721 ret
722PARTSCAN_CheckThisPartition EndP
723
724stop_scanning db 0
725
726; ===================
727; X-REFERENCE STUFF -> PartitionXref
728; ===================
729
730; Reset X-Reference
731PARTSCAN_ResetXref Proc Near Uses ax cx di
732 mov di, offset PartitionXref ; X-Reference for later syncing
733 mov cx, LocIPT_MaxPartitions
734 mov ax, 0FFFFh ; Fill up with FFh -- Influences OVERWRITE BUG !
735 rep stosb
736 mov di, offset NewHidePartTable ; Temporary Hide-Config Table
737 ;~ mov cx, LocIPT_MaxPartitions * LocIPT_LenOfIPT
738 mov cx, LocIPT_MaxPartitions * LocHPT_LenOfHPT ; Checken !!!
739 rep stosb ; Fill up with FFFFh
740 mov di, offset NewDriveLetters
741 mov cx, LocIPT_MaxPartitions ; Temporary Logical-Drive Letter Table
742 xor ax, ax
743 rep stosb ; Fill up with 0000h
744 ret
745PARTSCAN_ResetXref EndP
746
747
748
749; In: DL - Partition Number in IPT
750; DH - Partition Number in NewPartitionTable
751; Destroyed: None
752PARTSCAN_DefXref Proc Near Uses ax bx cx dx si di
753 ;movzx bx, dl
754 mov bl,dl
755 mov bh,0
756
757 mov bptr [PartitionXref+bx], dh ; X-Reference
758 ; Copy Hide-Config of IPT partition to new location in new table
759 mov si, offset HidePartitionTable
760 mov di, offset NewHidePartTable
761 mov bl, LocIPT_MaxPartitions
762 mov al, dl
763 mul bl
764 add si, ax
765 mov al, dh
766 mul bl
767 add di, ax
768 mov cx, LocIPT_MaxPartitions
769 rep movsb ; Copy Hide-Config to NewHideTable
770 ; Process Logical-Drive-Letter table as well...
771 ;movzx bx, dl
772 mov bl,dl
773 mov bh,0
774
775 mov al, bptr [DriveLetters+bx] ; Get Drv-Letter from org. pos
776 ;movzx bx, dh
777 mov bl,dl
778 mov bh,0
779
780 mov bptr [NewDriveLetters+bx], al ; Put Drv-Letter to new pos
781 ret
782PARTSCAN_DefXref EndP
783
784
785
786; In: DL - Partition Number in previous IPT
787; Out: DH - Partition Number in NewPartitionTable
788; Destroyed: None
789PARTSCAN_GetXref Proc Near Uses bx
790 ;movzx bx, dl
791 mov bl,dl
792 mov bh,0
793
794 mov dh, bptr [PartitionXref+bx] ; X-Reference
795 ret
796PARTSCAN_GetXref EndP
797
798
799
800; This here updates the contents of the Hide-Configuration to the current IPT
801; table.
802PARTSCAN_SyncHideConfigWithXref Proc Near Uses ax bx cx dx si di
803 mov si, offset NewHidePartTable
804 mov di, offset HidePartitionTable
805 mov ch, LocIPT_MaxPartitions
806 PSSHCWX_SyncPartLoop:
807 mov cl, LocIPT_MaxPartitions
808 xor dl, dl ; Partition Lost Counter
809 PSSHCWX_SyncLoop:
810 lodsb ; Get Part-Pointer from Hide-Cfg
811 cmp al, 0FFh
812 je PSSHCWX_SyncEmpty
813 ;movzx bx, al
814 mov bl,al
815 mov bh,0
816
817 mov al, [PartitionXref+bx] ; Translate it
818 cmp al, 0FFh
819 je PSSHCWX_PartLost
820 PSSHCWX_SyncEmpty:
821 stosb ; Put translated pointer to new table
822 dec cl
823 jnz PSSHCWX_SyncLoop
824 jmp PSSHCWX_SyncLoopEnd
825 PSSHCWX_PartLost:
826 inc dl ; One partition got lost...
827 dec cl
828 jnz PSSHCWX_SyncLoop
829
830 PSSHCWX_SyncLoopEnd:
831 or dl, dl
832 jz PSSHCWX_NothingLost
833 mov al, 0FFh ; Influences OVERWRITE BUG ! (OUT OF BOUNDS !!)
834 PSSHCWX_LostFillLoop:
835 stosb
836 dec cl
837 jnz PSSHCWX_LostFillLoop
838
839 ; debug code
840 mov ax,di
841 call AuxIO_TeletypeHexWord
842 call AuxIO_TeletypeNL
843
844 PSSHCWX_NothingLost:
845 dec ch
846 jnz PSSHCWX_SyncPartLoop
847 ret
848PARTSCAN_SyncHideConfigWithXref EndP
849
850ibm_bm_name db 'OS2 BootMgr',0
851;win_bm_name: db 'BOOTMGR',0
Note: See TracBrowser for help on using the repository browser.