source: trunk/bootcode/regular/partscan.asm@ 164

Last change on this file since 164 was 164, checked in by Ben Rietbroek, 8 years ago

Flushed changes in local cache (debugging state) [v1.1.1-testing]

CAUTION:
This is a testbuild !
AirBoot uses the BIOS to access disks and a small coding error can trash
partition tables or other vital disk structures. You are advised to make
backups of TRACK0 and EBRs before using this testbuild. More info at:
https://rousseaux.github.io/netlabs.air-boot/pdf/AirBoot-v1.1.0-manual.pdf

File size: 39.0 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 MODULE_NAMES
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
32IFDEF AUX_DEBUG
33 IF 0
34 DBG_TEXT_OUT_AUX 'PARTSCAN_ScanForPartitions:'
35 PUSHRF
36 ;~ call DEBUG_DumpRegisters
37 ;~ call AuxIO_DumpParagraph
38 ;~ call AuxIO_TeletypeNL
39 POPRF
40 ENDIF
41ENDIF
42
43 ; Reset X-Reference
44 call PARTSCAN_ResetXref
45
46 mov dh, [TotalHarddiscs]
47 xor al, al
48 mov [NewPartitions], al
49
50 mov byte ptr [CurIO_Scanning], 1 ; Set flag due scanning partitions
51 mov dl, 80h ; is first harddisc
52 PSSFP_HarddiscLoop:
53
54; ========================================================= [ Scan Partitions ]
55
56 push dx
57 call PARTSCAN_ScanDriveForPartitions
58 pop dx
59 inc dl
60 dec dh
61 jnz PSSFP_HarddiscLoop
62 mov byte ptr [CurIO_Scanning], 0 ; Reset flag due scanning complete
63
64IFDEF AUX_DEBUG
65 IF 0
66 PUSHRF
67 call DEBUG_DumpHidePartTables
68 POPRF
69 ENDIF
70ENDIF
71
72 ; Use X-Reference to sync NewPartitionTable with Hide-Config
73 call PARTSCAN_SyncHideConfigWithXref
74
75IFDEF AUX_DEBUG
76 IF 0
77 PUSHRF
78 call DEBUG_DumpHidePartTables
79 POPRF
80 ENDIF
81ENDIF
82
83 ; Now we copy the new IPT over the old one...
84 mov si, offset [NewPartTable]
85 mov di, offset [PartitionTable]
86 ;movzx ax, NewPartitions
87 mov al,NewPartitions
88 mov ah,0
89
90 mov CFG_Partitions, al
91 mov bl, LocIPT_LenOfIPT
92 mul bl
93 mov cx, ax
94 rep movsb
95
96 ; and the New Logical Drive Letter table as well...
97 mov si, offset [NewDriveLetters]
98 mov di, offset [DriveLetters]
99 mov cx, LocIPT_MaxPartitions
100 rep movsb
101
102 ; ...and finally check, if we need to set a Drive-Letter
103 mov dl, [AutoDrvLetter]
104 or dl, dl
105 jz PSSFP_NoAutoDriveLetter
106 ;movzx cx, CFG_Partitions
107 mov cl, [CFG_Partitions]
108 mov ch,0
109
110 or cx, cx
111 jz PSSFP_NoAutoDriveLetter
112 mov si, offset [PartitionTable]
113 mov di, offset [DriveLetters]
114 mov ax, word ptr [AutoDrvLetterSerial+00h]
115 mov bx, word ptr [AutoDrvLetterSerial+02h]
116 PSSFP_AutoDrvLetterLoop:
117 cmp ax, [si+LocIPT_Serial]
118 jne PSSFP_AutoDrvLetterNoMatch
119 cmp bx, [si+LocIPT_Serial+2]
120 jne PSSFP_AutoDrvLetterNoMatch
121 ; We got a match, so set Drive-Letter in DL
122 or bptr [si+LocIPT_Flags], Flags_DriveLetter
123 mov [di], dl
124 PSSFP_AutoDrvLetterNoMatch:
125 add si, LocIPT_LenOfIPT
126 inc di
127 loop PSSFP_AutoDrvLetterLoop
128 mov byte ptr [AutoDrvLetter], 0 ; Disable after processing...
129 PSSFP_NoAutoDriveLetter:
130 ret
131PARTSCAN_ScanForPartitions EndP
132
133
134
135;
136; This function reconnects a forced drive-letter with it's partition
137; when partitions are removed.
138;
139PARTSCAN_UpdateDriveLetters Proc
140
141IFDEF AUX_DEBUG
142 IF 0
143 DBG_TEXT_OUT_AUX 'PARTSCAN_UpdateDriveLetters:'
144 PUSHRF
145 ;~ call DEBUG_DumpRegisters
146 ;~ call AuxIO_DumpParagraph
147 ;~ call AuxIO_TeletypeNL
148 POPRF
149 ENDIF
150ENDIF
151
152 pusha
153 xor bx,bx ; index-pointer
154 xor cx,cx ; counter
155 xor dx,dx ; backup index-pointer
156 mov cl,LocIPT_MaxPartitions ; nr of entries to process
157 mov si,offset [PartitionXref] ; old-new relation table
158 mov di,offset [DriveLetters] ; forced drive-letters table
159
160 ;
161 ; Loop over each entry in the xref-table to see if the partition
162 ; has been removed or has been given a new index in the IPT.
163 ; A removed partition has 0ffh in it's slot and for a partition
164 ; that has a new index in the IPT the value at the slot is different
165 ; from the index of the slot in the xref-table.
166 ;
167 PARTSCAN_UpdateDriveLetters_next_entry:
168 jcxz PARTSCAN_UpdateDriveLetters_done
169 dec cl ; decrement counter
170 mov al,[si+bx] ; get possibly old index for this entry
171 mov dl,bl ; save current index
172 inc bl ; advance index-pointer
173 inc al ; 0ffh will become 0, part removed so continue
174 jz PARTSCAN_UpdateDriveLetters_next_entry
175
176 ;
177 ; If value in slot is the same as the index of the slot then
178 ; the partition has not moved in the IPT.
179 ;
180 dec al ; restore possibly out-of-date index
181 cmp al,dl ; same as array index? then ok, do next
182 je PARTSCAN_UpdateDriveLetters_next_entry
183
184;!
185;! DEBUG_PROBE
186;!
187IFDEF AUX_DEBUGx
188 push 1234h
189 call DEBUG_Probe
190ENDIF
191
192 ;
193 ; The partition has moved in the IPT so we lookup it's forced
194 ; drive-letter at the old location and put it at the new one.
195 ; The old location is identified by the index in the xref-table
196 ; and the new location is identified by the value at that index.
197 ; Thus, when no partitions have been deleted or added, the xref-table
198 ; contains the sequence 0,1,2,3,...,n,0ffh,0ffh, etc.
199 ; The value 0ffh means that no partition is using the slot.
200 ;
201 xor ah,ah ; no drive-letter
202 dec bl ; backup index-pointer one position
203 xchg ah,[di+bx] ; get drive-letter and store zero
204 xchg bl,al ; use slot value as new index
205 mov [di+bx],ah ; store drive-letter
206 xchg al,bl ; restore index-pointer
207 inc bl ; point to next entry
208 jmp PARTSCAN_UpdateDriveLetters_next_entry
209 PARTSCAN_UpdateDriveLetters_done:
210 popa
211 ret
212PARTSCAN_UpdateDriveLetters EndP
213
214
215
216
217; Scannt die Festplatte auf jegliche Partitionstabellen...
218; Falls eine fehlerhafte Partition gefunden wird, wird abgebrochen.
219; falls eine Extended Partition (DOS) gefunden wird, wird erneut gescannt.
220PARTSCAN_ScanDriveForPartitions Proc Near
221
222IFDEF AUX_DEBUG
223 IF 0
224 DBG_TEXT_OUT_AUX 'PARTSCAN_ScanDriveForPartitions:'
225 PUSHRF
226 ;~ call DEBUG_DumpRegisters
227 ;~ call AuxIO_DumpParagraph
228 ;~ call AuxIO_TeletypeNL
229 POPRF
230 ENDIF
231ENDIF
232
233 xor ax, ax
234 xor bx, bx ; Location Absoluter Sektor 0
235 mov cx, 0001h
236 xor dh, dh ; Location Zylinder 0, Side 0, Sektor 1 MBR
237 mov [ExtendedAbsPosSet], al
238 mov wptr [ExtendedAbsPos+0], ax
239 mov wptr [ExtendedAbsPos+2], ax
240 PSSDFP_LoadThisPartition:
241
242 call DriveIO_LoadPartition ; Load a partition record
243
244 jc PSSDFP_InvalidPartition
245
246 ; LVM Support - Reads LVM Information Sector
247 call DriveIO_LoadLVMSector ; Load LVM sector
248
249 call PARTSCAN_ScanPartition
250
251 call DriveIO_SavePartition
252
253 call PARTSCAN_ScanPartitionForExtended
254 jc PSSDFP_LoadThisPartition
255
256 PSSDFP_InvalidPartition:
257 ret
258PARTSCAN_ScanDriveForPartitions EndP
259
260; Scans Current Partition for Extended Partitions, if found, AX,BX,CX,DX will
261; be set to this location and Carry will be set
262PARTSCAN_ScanPartitionForExtended Proc Near Uses si
263
264IFDEF AUX_DEBUG
265 IF 0
266 DBG_TEXT_OUT_AUX 'PARTSCAN_ScanPartitionForExtended:'
267 PUSHRF
268 ;~ call DEBUG_DumpRegisters
269 ;~ call AuxIO_DumpParagraph
270 ;~ call AuxIO_TeletypeNL
271 POPRF
272 ENDIF
273ENDIF
274
275 mov si, offset PartitionSector+446 ; DS:SI - 1st partition entry
276 xor ax, ax
277 PSSPFE_ScanLoop:
278 mov al, [si+LocBRPT_SystemID]
279 cmp al, 5 ; Is Partition EXTENDED ?
280 je PSSPFE_ExtendedPartition
281 cmp al, 0Fh ; Is Partition EXTENDED (M$) ?
282 je PSSPFE_ExtendedPartition
283 jmp PSSPFE_IgnorePartition
284 PSSPFE_ExtendedPartition:
285 mov ax, wptr [si+LocBRPT_RelativeBegin]
286 mov bx, wptr [si+LocBRPT_RelativeBegin+2]
287 add ax, wptr [ExtendedAbsPos+0] ; Adjust...
288 adc bx, wptr [ExtendedAbsPos+2] ; (Shit Design!)
289 test byte ptr [ExtendedAbsPosSet], 1
290 jnz PSSPFE_ExtendedMainKnown
291 mov wptr [ExtendedAbsPos+0], ax
292 mov wptr [ExtendedAbsPos+2], bx
293 mov byte ptr [ExtendedAbsPosSet], 1
294 PSSPFE_ExtendedMainKnown:
295 mov cx, wptr [si+LocBRPT_BeginSector] ; Cylinder/Sector
296 mov dh, bptr [si+LocBRPT_BeginHead] ; Head
297 mov dl, bptr [CurPartition_Location+4] ; Drive
298 stc
299 jmp PSSPFE_EndOfSearch
300 PSSPFE_IgnorePartition:
301 add si, LocBRPT_LenOfEntry
302 cmp si, 500+offset PartitionSector
303 jb PSSPFE_ScanLoop
304 clc
305 PSSPFE_EndOfSearch:
306 ret
307PARTSCAN_ScanPartitionForExtended EndP
308
309; The following routines have NOT *DS* set to CS, so we must address via ES
310PARTSCAN_ScanPartition Proc Near Uses ax si
311
312IFDEF AUX_DEBUG
313 IF 0
314 DBG_TEXT_OUT_AUX 'PARTSCAN_ScanPartition:'
315 PUSHRF
316 ;~ call DEBUG_DumpRegisters
317 ;~ call AuxIO_DumpParagraph
318 ;~ call AuxIO_TeletypeNL
319 POPRF
320 ENDIF
321ENDIF
322
323
324 mov si, offset [PartitionSector+446] ; DS:SI - 1st Partition-Entry
325 PSSP_ScanLoop:
326 mov al, bptr [si+LocBRPT_SystemID]
327 cmp al, 5 ; Is Partition EXTENDED ?
328 je PSSP_IgnorePartition
329 cmp al, 0Fh ; Is Partition EXTENDED (M$-DOS7) ?
330 je PSSP_IgnorePartition
331 cmp al, 0 ; Is Partition EMPTY ?
332 je PSSP_IgnorePartition
333 ; Ignore these partitions, because there are no real Partitions
334
335 ;
336 ; Stop scanning if too many partitions.
337 ;
338 cmp word ptr cs:[NewPartitions],LocIPT_MaxPartitions
339 jae skip_check
340 call PARTSCAN_CheckThisPartition
341 jmp PSSP_IgnorePartition
342 skip_check:
343 ; Cannot boot LVM-Data partitions
344 pusha
345 mov byte ptr cs:[TooManyPartitions],1
346 mov cx, 0C04h
347 ;~ mov si, offset TXT_ERROR_TooManyPartitions
348 mov si, offset TXT_TooManyPartitions
349 add si,5 ; We stole this string, so skip new-line and dash.
350 ;~ call SETUP_Warning_AreYouSure
351 call SETUP_ShowErrorBox
352 popa
353
354 PSSP_IgnorePartition:
355 ; Only clear the boot-flag on the boot-disk.
356 ; Clearing the boot-flags on other disks would prevent booting them
357 ; from the BIOS. (TRAC ticket #6)
358 cmp dl, [BIOS_BootDisk] ; See if this is boot-disk
359 jne PSSP_Skip_Clear_BootFlag ; Nope, skip clear flag
360 and byte ptr [si+LocBRPT_Flags], 7Fh ; Reset the Active-Flag
361 PSSP_Skip_Clear_BootFlag:
362 add si, LocBRPT_LenOfEntry ; 16 Bytes per partition entry
363 cmp si, 500+offset PartitionSector
364 jb PSSP_ScanLoop
365 ; If we are on first HDD and in primary partition table -> mark primary
366 mov al, [BIOS_BootDisk]
367 cmp bptr [CurPartition_Location+4], al ; Drive
368 jne PSSP_NoMarkPrimary
369 cmp wptr [CurPartition_Location+0], 0
370 jne PSSP_NoMarkPrimary
371 cmp wptr [CurPartition_Location+2], 0 ; Absolute Location
372 jne PSSP_NoMarkPrimary
373 call PART_MarkFirstGoodPrimary
374 PSSP_NoMarkPrimary:
375 ret
376PARTSCAN_ScanPartition EndP
377
378MBR_NoName_Patched db 15 dup (0)
379
380; Will insert this partition into NewPartTable and compare it to our "old"
381; LocIPT-table. If the same partition is found there, Flags&CRC are taken from
382; the old table, otherwise they are generated freshly.
383; Will also fill out PartitionXref to sync HideConfig later
384; In: SI - Points to Partition-Entry (16-Bytes)
385PARTSCAN_CheckThisPartition Proc Near Uses di si
386
387 local PartSystemID:byte, PartTypeFlags:byte
388 local PartCRC:word, PartPtr:word
389
390IFDEF AUX_DEBUG
391 IF 0
392 DBG_TEXT_OUT_AUX 'PARTSCAN_CheckThisPartition:'
393 PUSHRF
394 call DEBUG_DumpRegisters
395 ;~ call AuxIO_DumpParagraph
396 ;~ call AuxIO_TeletypeNL
397 POPRF
398 ENDIF
399ENDIF
400
401
402 mov wptr [PartPtr], si ; Save Pointer to PartitionEntry
403
404 mov al, bptr [si+LocBRPT_SystemID]
405 mov PartSystemID, al
406
407 mov cx, wptr [si+LocBRPT_BeginSector] ; Cylinder/Sector
408 mov dh, bptr [si+LocBRPT_BeginHead] ; Head
409 mov dl, bptr [CurPartition_Location+4] ; Drive
410 mov ax, wptr [si+LocBRPT_RelativeBegin] ; Absolute Sector
411 mov bx, wptr [si+LocBRPT_RelativeBegin+2]
412
413 add ax, wptr [CurPartition_Location+0] ; +Partition-Absolute
414 adc bx, wptr [CurPartition_Location+2] ; sectors
415
416 ; Load the partition sector
417 mov si, offset [TmpSector]
418 call DriveIO_LoadSector
419
420 push si
421 mov bx, 4B4Dh ; Magic 'MK' :)
422 call MBR_GetCheckOfSector
423 mov PartCRC, bx ; Save Partition's-CRC
424
425 ; ------------------------------ Gets internal infos of partition type
426 mov al, PartSystemID
427 call PART_SearchFileSysName
428 ; Replies AH - FileSysFlags, AL - UnhiddenID, SI - FileSystemNamePtr
429 mov di, si
430 mov PartTypeFlags, ah
431 mov PartSystemID, al ; Use Unhidden-ID
432 pop si
433
434 ;================================
435 ; AL - File System ID (Unhidden)
436 ; AH - File System Flags
437 ; SI - Boot-Record of Partition
438 ; DI - File System Name
439 ;================================
440
441 cmp PartSystemID, 07h ; We got IFS here?
442 jne PCCTP_IFSdone
443 ; Check, if 'JFS ' is at DWORD offset 36h ; Rousseau: JFS check (LVM / IPT?)
444 cmp wptr [si+36h], 'FJ'
445 jne PCCTP_IFSnoJFS
446 cmp wptr [si+38h], ' S'
447 jne PCCTP_IFSnoJFS
448 mov PartSystemID, 0FCh ; FC is JFS internally
449 jmp PCCTP_IFSdone
450 PCCTP_IFSnoJFS:
451 ; Check, if 'HPFS' is at DWORD offset 36h
452 cmp wptr [si+36h], 'PH'
453 jne PCCTP_ProbablyNTFS
454 cmp wptr [si+38h], 'SF'
455 je PCCTP_IFSdone ; 07 is HPFS internally
456 PCCTP_ProbablyNTFS:
457 inc PartSystemID ; 08 is NTFS instead of 07
458 PCCTP_IFSdone:
459
460
461 ; First check, if LVM Information Sector is available and this partition
462 ; is supported.
463 push ax
464 push dx
465 push si
466 push di
467 mov si, wptr [PartPtr]
468 mov ax, wptr [si+LocBRPT_RelativeBegin] ; Absolute Sector
469 mov dx, wptr [si+LocBRPT_RelativeBegin+2]
470 add ax, wptr [CurPartition_Location+0] ; +Partition-Absolute
471 adc dx, wptr [CurPartition_Location+2] ; sectors
472
473 mov si, offset [LVMSector]
474
475IFDEF AUX_DEBUG
476 IF 0
477 DBG_TEXT_OUT_AUX 'LVMSector'
478 PUSHRF
479 call DEBUG_DumpRegisters
480 call AuxIO_DumpSector
481 ;~ call AuxIO_DumpParagraph
482 ;~ call AuxIO_TeletypeNL
483 POPRF
484 ENDIF
485ENDIF
486
487 call LVM_SearchForPartition ; Search for DX:AX partition
488
489 jnc PCCTP_CheckBootRecord
490 ; Check, if volume has driveletter assigned and remember it for later
491 mov al, [si+LocLVM_VolumeLetter]
492 or al, al
493 jnz PCCTP_HasVolumeLetter
494 mov al, 1 ; 0 would mean "not LVM supported"
495 PCCTP_HasVolumeLetter:
496 ; Save VolumeLetter in separate table
497 ;movzx bx, NewPartitions ; NewPartitions is one behind here, so
498 mov bl,NewPartitions ; NewPartitions is one behind here, so
499 mov bh,0
500
501 mov [PartitionVolumeLetters+bx], al ; it's already a zero-based offset
502 ; Now copy VolumeID and VolumeName to temporary space
503 mov di, offset MBR_NoName_Patched
504 mov ax, [si+LocLVM_PartitionID]
505 stosw
506 mov ax, [si+LocLVM_PartitionID+2]
507 stosw
508 ; Set Serial-Field to LVM-VolumeID
509
510 push di
511 add si, LocLVM_VolumeName ; Use LVM VolumeName
512 ;add si, LocLVM_PartitionName ; Use LVM PartitionName
513 mov cx, 5
514 rep movsw ; Copy LVM-PartitionName to Temp Space
515 movsb ; (11 bytes in total)
516 pop di
517
518IFDEF AUX_DEBUG
519 IF 0
520 DBG_TEXT_OUT_AUX 'Name'
521 PUSHRF
522 mov si, di
523 call AuxIO_Print
524 ;~ call DEBUG_DumpRegisters
525 ;~ call AuxIO_DumpSector
526 ;~ call AuxIO_DumpParagraph
527 ;~ call AuxIO_TeletypeNL
528 POPRF
529 ENDIF
530ENDIF
531
532 ; Check if this is an IBM-BM partition
533 cmp PartSystemID, 0ah
534 jne PCCTP_NoIbmBm
535
536 ; It is, so override the name given by IBM-BM by one that
537 ; fits in 11 chars.
538 mov si, offset ibm_bm_name
539 mov cx,5
540 rep movsw
541 movsb
542
543
544
545 PCCTP_NoIbmBm:
546 pop di
547 pop si
548 pop dx
549 pop ax
550 mov si, offset MBR_NoName_Patched
551 xor ah, ah ; no Flags_NoPartName
552 jmp PCCTP_NameSearchInIPT
553
554 PCCTP_CheckBootRecord:
555 pop di
556 pop si
557 pop dx
558 pop ax
559
560 test ah, FileSysFlags_NoName ; No-Name-Flag ? -> No Partition Name
561
562 jz PCCTP_ThereIsAName
563 jmp PCCTP_ThereIsNoName ; available
564
565 PCCTP_ThereIsAName:
566
567 ; We check for NTFS (got detected a little bit earlier in this routine)
568 cmp PartSystemID, 08h ; We got IFS/NTFS here?
569 jne PCCTP_IsNoNTFS
570 jmp PCCTP_ThereIsNoName ; NTFS has no volume label
571 PCCTP_IsNoNTFS:
572 add si, 2Bh ; DS:SI - Partition-Name
573 test ah, FileSysFlags_FAT32 ; FAT32 specific name getting ?
574
575 jz PCCTP_ResumeNormal
576
577 add si, 1Ch ; Fix for FAT 32, shiat
578 PCCTP_ResumeNormal:
579 mov cx, 11 ; 11 bytes length
580 call PART_CheckForValidPartName
581 jc PCCTP_ThereIsAName2
582
583 jmp PCCTP_ThereIsNoName
584
585 PCCTP_ThereIsAName2:
586
587 sub si, 4 ; DS:SI -> Serial&Name (15-Bytes)
588 xor ah, ah ; no Flags_NoPartName
589; jmp PCCTP_NameSearchInIPT
590
591 ;=======================================================
592 ; NAME SEARCH in IPT-Table
593 ; DS:SI - Serial&Name of Current Partition (15-Bytes)
594 ; AH - NoPartName-Flag (!MUST! be merged with Flags)
595 ;=======================================================
596 PCCTP_NameSearchInIPT:
597 xor ah, ah ; no Flags_NoPartName cause PartName valid
598 mov di, offset PartitionTable ; ES:DI - IPT-Start
599 mov dl, CFG_Partitions
600 or dl, dl
601 jnz PCCTP_SerialNameCompLoop
602 jmp PCCTP_CompareFailed
603 PCCTP_SerialNameCompLoop:
604 mov al, [di+LocIPT_Flags]
605 test al, Flags_NowFound
606 jnz PCCTP_SerialNameAlreadyFound
607 ; Now compare IPT with current Partition
608 mov cx, 15 ; Serial&Name (15-Bytes)
609 push si
610 push di
611 repz cmpsb
612 pop di
613 pop si
614
615 jne PCCTP_NoMatchYet
616
617 jmp PCCTP_Match
618
619 PCCTP_NoMatchYet:
620
621 PCCTP_SerialNameAlreadyFound:
622 add di, LocIPT_LenOfIPT
623 dec dl
624 jnz PCCTP_SerialNameCompLoop
625
626 ; if we didn't find Serial&Name, let's try Name-only without Serial
627 mov di, offset PartitionTable ; ES:DI - IPT-Start
628 mov dl, CFG_Partitions
629 PCCTP_NameCompLoop:
630 mov al, [di+LocIPT_Flags]
631 test al, Flags_NowFound
632 jnz PCCTP_NameAlreadyFound
633 ; Now compare IPT with current Partition
634 mov cx, 11 ; Name only (11-Bytes)
635 push si
636 push di
637 add si, 4
638 add di, 4 ; Skip over Serial-Field
639 repz cmpsb
640 pop di
641 pop si
642 jne PCCTP_NameNoMatch
643 mov cx, [si+0] ; Get Serial
644 mov [di+0], cx
645 mov cx, [si+2]
646 mov [di+2], cx ; ...and put it into IPT
647 jmp PCCTP_Match
648 PCCTP_NameNoMatch:
649 PCCTP_NameAlreadyFound:
650 add di, LocIPT_LenOfIPT
651 dec dl
652 jnz PCCTP_NameCompLoop
653 PCCTP_NameCompFailed:
654
655 ; So finally we search for Location and PartitionID
656 push si
657 ; Initialize some stuff for Location-Search
658 mov dh, PartSystemID
659 mov si, [PartPtr] ; DS:SI - Cur Partition Table
660 ; Relative Sector to MBR/EPR
661 mov cx, wptr [si+LocBRPT_RelativeBegin]
662 mov bx, wptr [si+LocBRPT_RelativeBegin+2]
663 add cx, [CurPartition_Location+0]
664 add bx, [CurPartition_Location+2]
665 ; BX:CX - Absolute First Sector of Partition on HDD
666 pop si
667 mov di, offset PartitionTable ; ES:DI - IPT-Start
668 mov dl, CFG_Partitions
669 PCCTP_NameLocCompLoop:
670 mov al, [di+LocIPT_Flags]
671 test al, Flags_NowFound
672 jnz PCCTP_NameLocAlreadyFound
673 ; Now compare IPT with current Partition
674 cmp dh, [di+LocIPT_SystemID]
675 jne PCCTP_NameLocMismatch
676 cmp cx, [di+LocIPT_AbsoluteBegin]
677 jne PCCTP_NameLocMismatch
678 cmp bx, [di+LocIPT_AbsoluteBegin+2]
679 jne PCCTP_NameLocMismatch
680 ; We matched location, now copy the current PartitionID and Name to
681 ; the old IPT.
682 push di
683 add di, LocIPT_Serial ; DS:SI - LocIPT-Serial&Name
684 mov cx, 15
685 rep movsb ; Copy 15 bytes
686 pop di
687 jmp PCCTP_Match
688 PCCTP_NameLocMismatch:
689 PCCTP_NameLocAlreadyFound:
690 add di, LocIPT_LenOfIPT
691 dec dl
692 jnz PCCTP_NameLocCompLoop
693 ; None of the searches worked, so forget it...
694 jmp PCCTP_CompareFailed
695
696 PCCTP_ThereIsNoName:
697 ; Try to find this partition by comparing location and PartitionID
698 ; aka LocIPT_AbsoluteBegin:dword and LocIPT_SystemID
699 ; If found, simply go to the normal match-routine, otherwise use the
700 ; File-System-Name to build the Volume-Label for the New IPT Entry.
701 mov dh, PartSystemID
702 mov si, [PartPtr] ; DS:SI - Cur Partition Table
703 ; Relative Sector to MBR/EPR
704 mov cx, wptr [si+LocBRPT_RelativeBegin]
705 mov bx, wptr [si+LocBRPT_RelativeBegin+2]
706 add cx, [CurPartition_Location+0]
707 add bx, [CurPartition_Location+2]
708 ; Build a standard-Volume Label from FileSystemNamePtr
709 ; We have to call SearchFileSysName again because of NTFS
710 push ax
711 push cx
712 mov al, dh
713 call PART_SearchFileSysName ; We want SI here <- FileSystemNamePtr
714 mov di, offset MBR_NoName_Patched
715 xor ax, ax
716 stosw
717 stosw ; Set Serial-Field to "NUL"
718 mov cx, 4
719 rep movsw ; Copy FileSystemName to Temp Space
720 xor ax, ax
721 stosw
722 stosb ; Fill last 3 bytes with "NUL"
723 mov si, offset MBR_NoName_Patched
724 pop cx
725 pop ax
726 ;=======================================================
727 ; LOCATION SEARCH in IPT-Table
728 ; DH - PartitionID of Current Partition
729 ; BX:CX - AbsoluteBegin of Current Partition
730 ; AH - NoPartName-Flag (!MUST! be merged with Flags)
731 ; DS:SI - Serial&Name of Current Partition (15-Bytes)
732 ;=======================================================
733 PCCTP_LocSearchInIPT:
734 mov ah, Flags_NoPartName ;set Flags_NoPartName, PartName invalid
735 mov di, offset PartitionTable ; ES:DI - IPT-Start
736 mov dl, CFG_Partitions
737 or dl, dl
738 jz PCCTP_LocCompFailed
739 PCCTP_LocCompLoop:
740 mov al, [di+LocIPT_Flags]
741 test al, Flags_NowFound
742 jnz PCCTP_LocAlreadyFound
743 ; Now compare IPT with current Partition
744 cmp dh, [di+LocIPT_SystemID]
745 jne PCCTP_LocMismatch
746 cmp cx, [di+LocIPT_AbsoluteBegin]
747 jne PCCTP_LocMismatch
748 cmp bx, [di+LocIPT_AbsoluteBegin+2]
749 jne PCCTP_LocMismatch
750 jmp PCCTP_Match
751 PCCTP_LocMismatch:
752 PCCTP_LocAlreadyFound:
753 add di, LocIPT_LenOfIPT
754 dec dl
755 jnz PCCTP_LocCompLoop
756 PCCTP_LocCompFailed:
757 jmp PCCTP_CompareFailed
758
759 ; ==================================
760 ; =MATCH=, found partition in IPT...
761 ; AH - NoPartName-Flag (!MUST! be merged with Flags)
762 ; DL - IPT Partition Number from Loop (inverted)
763 ; ES:DI - LocIPT-Pointer to found IPT-entry
764 ; ==================================
765 PCCTP_Match:
766 mov ch, ah
767 ; Save the new location of this partition in the Xref-Table
768 ; for converting HideConfig.
769 mov dh, dl
770 mov dl, CFG_Partitions
771 sub dl, dh
772 mov dh, NewPartitions ; is actually a counter
773 call PARTSCAN_DefXref ; DL-IPT-Partition, DH-NewPartition
774
775 ; Get Saved-Flags...
776 mov cl, bptr [di+LocIPT_Flags] ; Use saved Flags
777
778 ; ...and Saved-CRC if available...
779 mov ax, wptr [di+LocIPT_BootRecordCRC]
780 or ax, ax
781 jz PCCTP_UseNewComputedCRC
782 mov PartCRC, ax ; Use saved IPT-CRC
783 PCCTP_UseNewComputedCRC:
784 ; ...and mark partition in IPT as already found
785 or bptr [di+LocIPT_Flags], Flags_NowFound
786 ; ...get Serial&Name from IPT-table...
787 mov si, di
788 add si, LocIPT_Serial ; DS:SI - LocIPT-Serial&Name
789 jmp PCCTP_AddToNew
790
791 ; =================================
792 ; =FAILED= search, not found in IPT
793 ; AH - NoPartName-Flag (!MUST! be merged with Flags)
794 ; DS:SI - Serial&Name of Current Partition (15-Bytes)
795 ; =================================
796 PCCTP_CompareFailed:
797 mov ch, ah
798 ; Insert Default Flags...
799 mov cl, LocIPT_DefaultFlags
800
801 mov al, PartTypeFlags
802 ; May I auto-add partitions ?
803 test byte ptr [CFG_PartitionsDetect], 1
804 jz PCCTP_MayNotAddAny ; add, but non-bootable
805 test al, FileSysFlags_BootAble ; AH kam von SearchFileSysName
806 jnz PCCTP_PerhapsBootAble
807 PCCTP_MayNotAddAny:
808 mov cl, LocIPT_DefaultNonBootFlags
809 PCCTP_PerhapsBootAble:
810
811 ; On FAT32-partitions, default to P-Flag (which means using M$-hack)
812 ; Anyway, this hack has to be globaly activated by the user manually...
813 cmp PartSystemID, 09h ; Hardcoded: FAT32
814 je PCCTP_NeedsExtMShack
815 cmp PartSystemID, 0Bh
816 je PCCTP_NeedsExtMShack
817 cmp PartSystemID, 0Ch
818 je PCCTP_NeedsExtMShack
819 cmp PartSystemID, 0Eh ; FAT16 above 8 GB
820 jne PCCTP_NoExtMShack
821 ; We only get here, when the SystemID seems to be an M$ "invention"...
822 PCCTP_NeedsExtMShack:
823 or cl, Flags_ExtPartMShack
824 PCCTP_NoExtMShack:
825
826 ;================================================
827 ; CL - IPT-Partition-Flags, CH - NoPartName-Flag
828 ; DS:SI - PartSerial&Name (15-Bytes)
829 ;================================================
830 PCCTP_AddToNew:
831 mov al, Flags_NoPartName ; Unset NoPartName
832 not al
833 and cl, al
834 or cl, ch ; CL = Both CL and CH merged
835
836 ; Calculate Pointer to IPT
837 mov di, offset NewPartTable ; ES:DI - NewPartTable
838 ;movzx ax, NewPartitions
839 mov al,NewPartitions
840 mov ah,0
841
842 mov bl, LocIPT_LenOfIPT
843 mul bl
844 add di, ax ; ES:DI - Last+1 Entry of NewPartTable
845
846 ; Now finally write this partition to our IPT
847 ;=============================================
848 push cx
849 mov cx, 15 ; Copy Serial&Name...
850 rep movsb
851 pop cx
852
853 mov si, [PartPtr] ; DS:SI - Cur Partition Entry
854 mov al, bptr [CurPartition_Location+4] ; Drive
855 stosb
856 mov al, PartSystemID ; Unhidden SystemID
857 stosb
858 mov al, cl ; Partition-Flags from register...
859 stosb
860 mov ax, PartCRC ; BootRecordCRC...
861 stosw
862 mov al, bptr [si+LocBRPT_BeginHead]
863 stosb
864 mov ax, wptr [si+LocBRPT_BeginSector] ; Cylinder/Sector
865 stosw
866 mov al, bptr [CurPartition_Location+5] ; Head of Part-Table
867 stosb
868 mov ax, wptr [CurPartition_Location+6] ; Cylinder/Sector
869 stosw
870 mov ax, wptr [si+LocBRPT_RelativeBegin]
871 mov bx, wptr [si+LocBRPT_RelativeBegin+2]
872 mov cx, wptr [CurPartition_Location+0] ; +Partition-Absolute
873 mov dx, wptr [CurPartition_Location+2] ; sectors
874 add ax, cx
875 adc bx, dx
876 stosw
877 mov ax, bx
878 stosw
879 mov ax, cx ; Absolute sector of partition table
880 stosw
881 mov ax, dx
882 stosw
883 inc byte ptr [NewPartitions]; Adjusted for Wasm ; NEW IPT Entry DONE
884
885 cmp byte ptr [NewPartitions], LocIPT_MaxPartitions
886 jbe PCCTP_NotTooManyPartitions
887
888 ; Should not be reached since scanning is stopped outside this
889 ; function when partition limit exceeds.
890 mov si, offset TXT_TooManyPartitions
891 call MBR_Teletype
892 jmp MBR_HaltSystem
893
894
895 PCCTP_NotTooManyPartitions:
896 ; UNHIDE PARTITION, if it was hidden previously
897 mov al, PartSystemID
898 cmp al, 08h ; internally IFS/NTFS?
899 je PCCTP_GotInternalIFS
900 cmp al, 0FCh ; internally IFS/JFS?
901 jne PCCTP_NoInternalIFS
902 PCCTP_GotInternalIFS:
903 mov al, 07h
904 PCCTP_NoInternalIFS:
905 mov bptr [si+LocBRPT_SystemID], al
906
907 ; Calculate Size of this partition and put it into separate table...
908 ;movzx ax, NewPartitions
909 mov al,NewPartitions
910 mov ah,0
911
912 dec ax
913 mov bx, ax
914 shl ax, 1
915 shl bx, 2
916 add ax, bx ; My way [tm] of multiplying with 6
917 mov di, offset PartitionSizeTable
918 add di, ax ; DI - Partition Size-Element
919 mov ax, wptr [si+LocBRPT_AbsoluteLength] ; Sector-Size
920 mov bx, wptr [si+LocBRPT_AbsoluteLength+2]
921 call PART_FillOutSizeElement
922 ret
923PARTSCAN_CheckThisPartition EndP
924
925stop_scanning db 0
926
927; ===================
928; X-REFERENCE STUFF -> PartitionXref
929; ===================
930
931; Reset X-Reference
932PARTSCAN_ResetXref Proc Near Uses ax cx di
933 mov di, offset PartitionXref ; X-Reference for later syncing
934 mov cx, LocIPT_MaxPartitions
935 mov ax, 0FFFFh ; Fill up with FFh
936 rep stosb
937 mov di, offset NewHidePartTable ; Temporary Hide-Config Table
938 ;~ mov cx, LocIPT_MaxPartitions * LocIPT_LenOfIPT
939 mov cx, LocIPT_MaxPartitions * LocHPT_LenOfHPT
940 rep stosb ; Fill up with FFFFh
941 mov di, offset NewDriveLetters
942 mov cx, LocIPT_MaxPartitions ; Temporary Logical-Drive Letter Table
943 xor ax, ax
944 rep stosb ; Fill up with 0000h
945 ret
946PARTSCAN_ResetXref EndP
947
948
949
950; In: DL - Partition Number in IPT
951; DH - Partition Number in NewPartitionTable
952; Destroyed: None
953PARTSCAN_DefXref Proc Near Uses ax bx cx dx si di
954 ;movzx bx, dl
955 mov bl,dl
956 mov bh,0
957
958 mov bptr [PartitionXref+bx], dh ; X-Reference
959 ; Copy Hide-Config of IPT partition to new location in new table
960 mov si, offset HidePartitionTable
961 mov di, offset NewHidePartTable
962 ;~ mov bl, LocIPT_MaxPartitions
963 mov bl, LocHPT_LenOfHPT
964 mov al, dl
965 mul bl
966 add si, ax
967 mov al, dh
968 mul bl
969 add di, ax
970 ;~ mov cx, LocIPT_MaxPartitions
971 mov cx, LocHPT_LenOfHPT
972 rep movsb ; Copy Hide-Config to NewHideTable
973 ; Process Logical-Drive-Letter table as well...
974 ;movzx bx, dl
975 mov bl,dl
976 mov bh,0
977
978 mov al, bptr [DriveLetters+bx] ; Get Drv-Letter from org. pos
979 ;movzx bx, dh
980 mov bl,dl
981 mov bh,0
982
983 mov bptr [NewDriveLetters+bx], al ; Put Drv-Letter to new pos
984 ret
985PARTSCAN_DefXref EndP
986
987
988
989; In: DL - Partition Number in previous IPT
990; Out: DH - Partition Number in NewPartitionTable
991; Destroyed: None
992PARTSCAN_GetXref Proc Near Uses bx
993 ;movzx bx, dl
994 mov bl,dl
995 mov bh,0
996
997 mov dh, bptr [PartitionXref+bx] ; X-Reference
998 ret
999PARTSCAN_GetXref EndP
1000
1001
1002;
1003; Rousseau: Adjusted for packed hidden-part-table !
1004; Needs to be re-written.
1005;
1006; This here updates the contents of the Hide-Configuration to the current IPT
1007; table.
1008PARTSCAN_SyncHideConfigWithXref Proc Near Uses ax bx cx dx si di
1009 mov si, offset NewHidePartTable
1010 mov di, offset HidePartitionTable
1011 mov dh, LocIPT_MaxPartitions ; Max entries in hide-tables.
1012
1013 PSSHCWX_SyncPartLoop:
1014 mov cl, LocIPT_MaxPartitions ; Max entries per hide-entry.
1015 xor dl, dl ; Partition Lost Counter
1016
1017 mov ch,0 ; Index.
1018
1019 PSSHCWX_SyncLoop:
1020 mov bx,si
1021
1022 ;~ lodsb ; Get Part-Pointer from Hide-Cfg
1023
1024 push dx
1025 mov dl,ch
1026 mov dh,6
1027 call CONV_GetBitfieldValue
1028 pop dx
1029
1030 ;~ cmp al, 0FFh
1031 cmp al, 3Fh
1032 je PSSHCWX_SyncEmpty
1033 ;movzx bx, al
1034 mov bl,al
1035 mov bh,0
1036
1037 mov al, [PartitionXref+bx] ; Translate it
1038 ;~ cmp al, 0FFh
1039 cmp al, 3Fh
1040 je PSSHCWX_PartLost
1041
1042 PSSHCWX_SyncEmpty:
1043 mov bx,di
1044 ;~ stosb ; Put translated pointer to new table
1045
1046 push dx
1047 mov dl,ch
1048 mov dh,6
1049 call CONV_SetBitfieldValue
1050 pop dx
1051
1052 inc ch
1053 dec cl
1054 jnz PSSHCWX_SyncLoop
1055
1056 jmp PSSHCWX_SyncLoopEnd
1057
1058 PSSHCWX_PartLost:
1059 inc dl ; One partition got lost...
1060 dec cl
1061 jnz PSSHCWX_SyncLoop
1062
1063 PSSHCWX_SyncLoopEnd:
1064
1065
1066IFDEF AUX_DEBUG
1067 IF 0
1068 pushf
1069 pusha
1070 mov al,dl
1071 call AuxIO_TeletypeHexByte
1072 call AuxIO_TeletypeNL
1073 popa
1074 popf
1075 ENDIF
1076ENDIF
1077
1078
1079 or dl, dl
1080 jz PSSHCWX_NothingLost
1081 ;~ mov al, 0FFh ; Influences OVERWRITE BUG ! (OUT OF BOUNDS !!)
1082 mov al, 3Fh
1083
1084 PSSHCWX_LostFillLoop: ; CHECK !!
1085 ;~ stosb
1086 dec cl
1087 jnz PSSHCWX_LostFillLoop
1088
1089 IFDEF AUX_DEBUG
1090 IF 0
1091 pushf
1092 pusha
1093 mov ax,di
1094 call AuxIO_TeletypeHexWord
1095 call AuxIO_TeletypeNL
1096 popa
1097 popf
1098 ENDIF
1099 ENDIF
1100
1101 PSSHCWX_NothingLost:
1102 add si, LocHPT_LenOfHPT
1103 add di, LocHPT_LenOfHPT
1104 dec dh
1105 jnz PSSHCWX_SyncPartLoop
1106
1107 ret
1108PARTSCAN_SyncHideConfigWithXref EndP
1109
1110ibm_bm_name db 'OS2 BootMgr',0
1111;win_bm_name: db 'BOOTMGR',0
Note: See TracBrowser for help on using the repository browser.