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

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

Removed these obsolete functions [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
414
415
416 add ax, wptr [CurPartition_Location+0] ; +Partition-Absolute
417 adc bx, wptr [CurPartition_Location+2] ; sectors
418
419
420 ; Load the partition sector
421 mov si, offset [TmpSector]
422 call DriveIO_LoadSector
423
424 push si
425 mov bx, 4B4Dh ; Magic 'MK' :)
426 call MBR_GetCheckOfSector
427 mov PartCRC, bx ; Save Partition's-CRC
428
429 ; ------------------------------ Gets internal infos of partition type
430 mov al, PartSystemID
431 call PART_SearchFileSysName
432 ; Replies AH - FileSysFlags, AL - UnhiddenID, SI - FileSystemNamePtr
433 mov di, si
434 mov PartTypeFlags, ah
435 mov PartSystemID, al ; Use Unhidden-ID
436 pop si
437
438 ;================================
439 ; AL - File System ID (Unhidden)
440 ; AH - File System Flags
441 ; SI - Boot-Record of Partition
442 ; DI - File System Name
443 ;================================
444
445 cmp PartSystemID, 07h ; We got IFS here?
446 jne PCCTP_IFSdone
447 ; Check, if 'JFS ' is at DWORD offset 36h ; Rousseau: JFS check (LVM / IPT?)
448 cmp wptr [si+36h], 'FJ'
449 jne PCCTP_IFSnoJFS
450 cmp wptr [si+38h], ' S'
451 jne PCCTP_IFSnoJFS
452 mov PartSystemID, 0FCh ; FC is JFS internally
453 jmp PCCTP_IFSdone
454 PCCTP_IFSnoJFS:
455 ; Check, if 'HPFS' is at DWORD offset 36h
456 cmp wptr [si+36h], 'PH'
457 jne PCCTP_ProbablyNTFS
458 cmp wptr [si+38h], 'SF'
459 je PCCTP_IFSdone ; 07 is HPFS internally
460 PCCTP_ProbablyNTFS:
461 inc PartSystemID ; 08 is NTFS instead of 07
462 PCCTP_IFSdone:
463
464
465 ; First check, if LVM Information Sector is available and this partition
466 ; is supported.
467 push ax
468 push dx
469 push si
470 push di
471 mov si, wptr [PartPtr]
472 mov ax, wptr [si+LocBRPT_RelativeBegin] ; Absolute Sector
473 mov dx, wptr [si+LocBRPT_RelativeBegin+2]
474 add ax, wptr [CurPartition_Location+0] ; +Partition-Absolute
475 adc dx, wptr [CurPartition_Location+2] ; sectors
476
477 mov si, offset [LVMSector]
478
479IFDEF AUX_DEBUG
480 IF 0
481 DBG_TEXT_OUT_AUX 'LVMSector'
482 PUSHRF
483 call DEBUG_DumpRegisters
484 call AuxIO_DumpSector
485 ;~ call AuxIO_DumpParagraph
486 ;~ call AuxIO_TeletypeNL
487 POPRF
488 ENDIF
489ENDIF
490
491 call LVM_SearchForPartition ; Search for DX:AX partition
492
493 jnc PCCTP_CheckBootRecord
494 ; Check, if volume has driveletter assigned and remember it for later
495 mov al, [si+LocLVM_VolumeLetter]
496 or al, al
497 jnz PCCTP_HasVolumeLetter
498 mov al, 1 ; 0 would mean "not LVM supported"
499 PCCTP_HasVolumeLetter:
500 ; Save VolumeLetter in separate table
501 ;movzx bx, NewPartitions ; NewPartitions is one behind here, so
502 mov bl,NewPartitions ; NewPartitions is one behind here, so
503 mov bh,0
504
505 mov [PartitionVolumeLetters+bx], al ; it's already a zero-based offset
506 ; Now copy VolumeID and VolumeName to temporary space
507 mov di, offset MBR_NoName_Patched
508 mov ax, [si+LocLVM_PartitionID]
509 stosw
510 mov ax, [si+LocLVM_PartitionID+2]
511 stosw
512 ; Set Serial-Field to LVM-VolumeID
513
514 push di
515 add si, LocLVM_VolumeName ; Use LVM VolumeName
516 ;add si, LocLVM_PartitionName ; Use LVM PartitionName
517 mov cx, 5
518 rep movsw ; Copy LVM-PartitionName to Temp Space
519 movsb ; (11 bytes in total)
520 pop di
521
522
523
524IFDEF AUX_DEBUG
525 IF 0
526 DBG_TEXT_OUT_AUX 'LVMSector-2'
527 PUSHRF
528 mov si, di
529 call AuxIO_Print
530 ;~ call DEBUG_DumpRegisters
531 ;~ call AuxIO_DumpSector
532 ;~ call AuxIO_DumpParagraph
533 ;~ call AuxIO_TeletypeNL
534 POPRF
535 ENDIF
536ENDIF
537
538
539 ; Check if this is an IBM-BM partition
540 cmp PartSystemID, 0ah
541 jne PCCTP_NoIbmBm
542
543 ; It is, so override the name given by IBM-BM by one that
544 ; fits in 11 chars.
545 mov si, offset ibm_bm_name
546 mov cx,5
547 rep movsw
548 movsb
549
550
551
552 PCCTP_NoIbmBm:
553 pop di
554 pop si
555 pop dx
556 pop ax
557 mov si, offset MBR_NoName_Patched
558 xor ah, ah ; no Flags_NoPartName
559 jmp PCCTP_NameSearchInIPT
560
561 PCCTP_CheckBootRecord:
562 pop di
563 pop si
564 pop dx
565 pop ax
566
567 test ah, FileSysFlags_NoName ; No-Name-Flag ? -> No Partition Name
568
569 jz PCCTP_ThereIsAName
570 jmp PCCTP_ThereIsNoName ; available
571
572 PCCTP_ThereIsAName:
573
574 ; We check for NTFS (got detected a little bit earlier in this routine)
575 cmp PartSystemID, 08h ; We got IFS/NTFS here?
576 jne PCCTP_IsNoNTFS
577 jmp PCCTP_ThereIsNoName ; NTFS has no volume label
578 PCCTP_IsNoNTFS:
579 add si, 2Bh ; DS:SI - Partition-Name
580 test ah, FileSysFlags_FAT32 ; FAT32 specific name getting ?
581
582 jz PCCTP_ResumeNormal
583
584 add si, 1Ch ; Fix for FAT 32, shiat
585 PCCTP_ResumeNormal:
586 mov cx, 11 ; 11 bytes length
587 call PART_CheckForValidPartName
588 jc PCCTP_ThereIsAName2
589
590 jmp PCCTP_ThereIsNoName
591
592 PCCTP_ThereIsAName2:
593
594 sub si, 4 ; DS:SI -> Serial&Name (15-Bytes)
595 xor ah, ah ; no Flags_NoPartName
596; jmp PCCTP_NameSearchInIPT
597
598 ;=======================================================
599 ; NAME SEARCH in IPT-Table
600 ; DS:SI - Serial&Name of Current Partition (15-Bytes)
601 ; AH - NoPartName-Flag (!MUST! be merged with Flags)
602 ;=======================================================
603 PCCTP_NameSearchInIPT:
604 xor ah, ah ; no Flags_NoPartName cause PartName valid
605 mov di, offset PartitionTable ; ES:DI - IPT-Start
606 mov dl, CFG_Partitions
607 or dl, dl
608 jnz PCCTP_SerialNameCompLoop
609 jmp PCCTP_CompareFailed
610 PCCTP_SerialNameCompLoop:
611 mov al, [di+LocIPT_Flags]
612 test al, Flags_NowFound
613 jnz PCCTP_SerialNameAlreadyFound
614 ; Now compare IPT with current Partition
615 mov cx, 15 ; Serial&Name (15-Bytes)
616 push si
617 push di
618 repz cmpsb
619 pop di
620 pop si
621
622 jne PCCTP_NoMatchYet
623
624 jmp PCCTP_Match
625
626 PCCTP_NoMatchYet:
627
628 PCCTP_SerialNameAlreadyFound:
629 add di, LocIPT_LenOfIPT
630 dec dl
631 jnz PCCTP_SerialNameCompLoop
632
633 ; if we didn't find Serial&Name, let's try Name-only without Serial
634 mov di, offset PartitionTable ; ES:DI - IPT-Start
635 mov dl, CFG_Partitions
636 PCCTP_NameCompLoop:
637 mov al, [di+LocIPT_Flags]
638 test al, Flags_NowFound
639 jnz PCCTP_NameAlreadyFound
640 ; Now compare IPT with current Partition
641 mov cx, 11 ; Name only (11-Bytes)
642 push si
643 push di
644 add si, 4
645 add di, 4 ; Skip over Serial-Field
646 repz cmpsb
647 pop di
648 pop si
649 jne PCCTP_NameNoMatch
650 mov cx, [si+0] ; Get Serial
651 mov [di+0], cx
652 mov cx, [si+2]
653 mov [di+2], cx ; ...and put it into IPT
654 jmp PCCTP_Match
655 PCCTP_NameNoMatch:
656 PCCTP_NameAlreadyFound:
657 add di, LocIPT_LenOfIPT
658 dec dl
659 jnz PCCTP_NameCompLoop
660 PCCTP_NameCompFailed:
661
662 ; So finally we search for Location and PartitionID
663 push si
664 ; Initialize some stuff for Location-Search
665 mov dh, PartSystemID
666 mov si, [PartPtr] ; DS:SI - Cur Partition Table
667 ; Relative Sector to MBR/EPR
668 mov cx, wptr [si+LocBRPT_RelativeBegin]
669 mov bx, wptr [si+LocBRPT_RelativeBegin+2]
670 add cx, [CurPartition_Location+0]
671 add bx, [CurPartition_Location+2]
672 ; BX:CX - Absolute First Sector of Partition on HDD
673 pop si
674 mov di, offset PartitionTable ; ES:DI - IPT-Start
675 mov dl, CFG_Partitions
676 PCCTP_NameLocCompLoop:
677 mov al, [di+LocIPT_Flags]
678 test al, Flags_NowFound
679 jnz PCCTP_NameLocAlreadyFound
680 ; Now compare IPT with current Partition
681 cmp dh, [di+LocIPT_SystemID]
682 jne PCCTP_NameLocMismatch
683 cmp cx, [di+LocIPT_AbsoluteBegin]
684 jne PCCTP_NameLocMismatch
685 cmp bx, [di+LocIPT_AbsoluteBegin+2]
686 jne PCCTP_NameLocMismatch
687 ; We matched location, now copy the current PartitionID and Name to
688 ; the old IPT.
689 push di
690 add di, LocIPT_Serial ; DS:SI - LocIPT-Serial&Name
691 mov cx, 15
692 rep movsb ; Copy 15 bytes
693 pop di
694 jmp PCCTP_Match
695 PCCTP_NameLocMismatch:
696 PCCTP_NameLocAlreadyFound:
697 add di, LocIPT_LenOfIPT
698 dec dl
699 jnz PCCTP_NameLocCompLoop
700 ; None of the searches worked, so forget it...
701 jmp PCCTP_CompareFailed
702
703 PCCTP_ThereIsNoName:
704 ; Try to find this partition by comparing location and PartitionID
705 ; aka LocIPT_AbsoluteBegin:dword and LocIPT_SystemID
706 ; If found, simply go to the normal match-routine, otherwise use the
707 ; File-System-Name to build the Volume-Label for the New IPT Entry.
708 mov dh, PartSystemID
709 mov si, [PartPtr] ; DS:SI - Cur Partition Table
710 ; Relative Sector to MBR/EPR
711 mov cx, wptr [si+LocBRPT_RelativeBegin]
712 mov bx, wptr [si+LocBRPT_RelativeBegin+2]
713 add cx, [CurPartition_Location+0]
714 add bx, [CurPartition_Location+2]
715 ; Build a standard-Volume Label from FileSystemNamePtr
716 ; We have to call SearchFileSysName again because of NTFS
717 push ax
718 push cx
719 mov al, dh
720 call PART_SearchFileSysName ; We want SI here <- FileSystemNamePtr
721 mov di, offset MBR_NoName_Patched
722 xor ax, ax
723 stosw
724 stosw ; Set Serial-Field to "NUL"
725 mov cx, 4
726 rep movsw ; Copy FileSystemName to Temp Space
727 xor ax, ax
728 stosw
729 stosb ; Fill last 3 bytes with "NUL"
730 mov si, offset MBR_NoName_Patched
731 pop cx
732 pop ax
733 ;=======================================================
734 ; LOCATION SEARCH in IPT-Table
735 ; DH - PartitionID of Current Partition
736 ; BX:CX - AbsoluteBegin of Current Partition
737 ; AH - NoPartName-Flag (!MUST! be merged with Flags)
738 ; DS:SI - Serial&Name of Current Partition (15-Bytes)
739 ;=======================================================
740 PCCTP_LocSearchInIPT:
741 mov ah, Flags_NoPartName ;set Flags_NoPartName, PartName invalid
742 mov di, offset PartitionTable ; ES:DI - IPT-Start
743 mov dl, CFG_Partitions
744 or dl, dl
745 jz PCCTP_LocCompFailed
746 PCCTP_LocCompLoop:
747 mov al, [di+LocIPT_Flags]
748 test al, Flags_NowFound
749 jnz PCCTP_LocAlreadyFound
750 ; Now compare IPT with current Partition
751 cmp dh, [di+LocIPT_SystemID]
752 jne PCCTP_LocMismatch
753 cmp cx, [di+LocIPT_AbsoluteBegin]
754 jne PCCTP_LocMismatch
755 cmp bx, [di+LocIPT_AbsoluteBegin+2]
756 jne PCCTP_LocMismatch
757 jmp PCCTP_Match
758 PCCTP_LocMismatch:
759 PCCTP_LocAlreadyFound:
760 add di, LocIPT_LenOfIPT
761 dec dl
762 jnz PCCTP_LocCompLoop
763 PCCTP_LocCompFailed:
764 jmp PCCTP_CompareFailed
765
766 ; ==================================
767 ; =MATCH=, found partition in IPT...
768 ; AH - NoPartName-Flag (!MUST! be merged with Flags)
769 ; DL - IPT Partition Number from Loop (inverted)
770 ; ES:DI - LocIPT-Pointer to found IPT-entry
771 ; ==================================
772 PCCTP_Match:
773 mov ch, ah
774 ; Save the new location of this partition in the Xref-Table
775 ; for converting HideConfig.
776 mov dh, dl
777 mov dl, CFG_Partitions
778 sub dl, dh
779 mov dh, NewPartitions ; is actually a counter
780 call PARTSCAN_DefXref ; DL-IPT-Partition, DH-NewPartition
781
782 ; Get Saved-Flags...
783 mov cl, bptr [di+LocIPT_Flags] ; Use saved Flags
784
785 ; ...and Saved-CRC if available...
786 mov ax, wptr [di+LocIPT_BootRecordCRC]
787 or ax, ax
788 jz PCCTP_UseNewComputedCRC
789 mov PartCRC, ax ; Use saved IPT-CRC
790 PCCTP_UseNewComputedCRC:
791 ; ...and mark partition in IPT as already found
792 or bptr [di+LocIPT_Flags], Flags_NowFound
793 ; ...get Serial&Name from IPT-table...
794 mov si, di
795 add si, LocIPT_Serial ; DS:SI - LocIPT-Serial&Name
796 jmp PCCTP_AddToNew
797
798 ; =================================
799 ; =FAILED= search, not found in IPT
800 ; AH - NoPartName-Flag (!MUST! be merged with Flags)
801 ; DS:SI - Serial&Name of Current Partition (15-Bytes)
802 ; =================================
803 PCCTP_CompareFailed:
804 mov ch, ah
805 ; Insert Default Flags...
806 mov cl, LocIPT_DefaultFlags
807
808 mov al, PartTypeFlags
809 ; May I auto-add partitions ?
810 test byte ptr [CFG_PartitionsDetect], 1
811 jz PCCTP_MayNotAddAny ; add, but non-bootable
812 test al, FileSysFlags_BootAble ; AH kam von SearchFileSysName
813 jnz PCCTP_PerhapsBootAble
814 PCCTP_MayNotAddAny:
815 mov cl, LocIPT_DefaultNonBootFlags
816 PCCTP_PerhapsBootAble:
817
818 ; On FAT32-partitions, default to P-Flag (which means using M$-hack)
819 ; Anyway, this hack has to be globaly activated by the user manually...
820 cmp PartSystemID, 09h ; Hardcoded: FAT32
821 je PCCTP_NeedsExtMShack
822 cmp PartSystemID, 0Bh
823 je PCCTP_NeedsExtMShack
824 cmp PartSystemID, 0Ch
825 je PCCTP_NeedsExtMShack
826 cmp PartSystemID, 0Eh ; FAT16 above 8 GB
827 jne PCCTP_NoExtMShack
828 ; We only get here, when the SystemID seems to be an M$ "invention"...
829 PCCTP_NeedsExtMShack:
830 or cl, Flags_ExtPartMShack
831 PCCTP_NoExtMShack:
832
833 ;================================================
834 ; CL - IPT-Partition-Flags, CH - NoPartName-Flag
835 ; DS:SI - PartSerial&Name (15-Bytes)
836 ;================================================
837 PCCTP_AddToNew:
838 mov al, Flags_NoPartName ; Unset NoPartName
839 not al
840 and cl, al
841 or cl, ch ; CL = Both CL and CH merged
842
843 ; Calculate Pointer to IPT
844 mov di, offset NewPartTable ; ES:DI - NewPartTable
845 ;movzx ax, NewPartitions
846 mov al,NewPartitions
847 mov ah,0
848
849 mov bl, LocIPT_LenOfIPT
850 mul bl
851 add di, ax ; ES:DI - Last+1 Entry of NewPartTable
852
853 ; Now finally write this partition to our IPT
854 ;=============================================
855 push cx
856 mov cx, 15 ; Copy Serial&Name...
857 rep movsb
858 pop cx
859
860 mov si, [PartPtr] ; DS:SI - Cur Partition Entry
861 mov al, bptr [CurPartition_Location+4] ; Drive
862 stosb
863 mov al, PartSystemID ; Unhidden SystemID
864 stosb
865 mov al, cl ; Partition-Flags from register...
866 stosb
867 mov ax, PartCRC ; BootRecordCRC...
868 stosw
869 mov al, bptr [si+LocBRPT_BeginHead]
870 stosb
871 mov ax, wptr [si+LocBRPT_BeginSector] ; Cylinder/Sector
872 stosw
873 mov al, bptr [CurPartition_Location+5] ; Head of Part-Table
874 stosb
875 mov ax, wptr [CurPartition_Location+6] ; Cylinder/Sector
876 stosw
877 mov ax, wptr [si+LocBRPT_RelativeBegin]
878 mov bx, wptr [si+LocBRPT_RelativeBegin+2]
879 mov cx, wptr [CurPartition_Location+0] ; +Partition-Absolute
880 mov dx, wptr [CurPartition_Location+2] ; sectors
881 add ax, cx
882 adc bx, dx
883 stosw
884 mov ax, bx
885 stosw
886 mov ax, cx ; Absolute sector of partition table
887 stosw
888 mov ax, dx
889 stosw
890 inc byte ptr [NewPartitions]; Adjusted for Wasm ; NEW IPT Entry DONE
891
892 cmp byte ptr [NewPartitions], LocIPT_MaxPartitions
893 jbe PCCTP_NotTooManyPartitions
894
895 ; Should not be reached since scanning is stopped outside this
896 ; function when partition limit exceeds.
897 mov si, offset TXT_TooManyPartitions
898 call MBR_Teletype
899 jmp MBR_HaltSystem
900
901
902 PCCTP_NotTooManyPartitions:
903 ; UNHIDE PARTITION, if it was hidden previously
904 mov al, PartSystemID
905 cmp al, 08h ; internally IFS/NTFS?
906 je PCCTP_GotInternalIFS
907 cmp al, 0FCh ; internally IFS/JFS?
908 jne PCCTP_NoInternalIFS
909 PCCTP_GotInternalIFS:
910 mov al, 07h
911 PCCTP_NoInternalIFS:
912 mov bptr [si+LocBRPT_SystemID], al
913
914 ; Calculate Size of this partition and put it into separate table...
915 ;movzx ax, NewPartitions
916 mov al,NewPartitions
917 mov ah,0
918
919 dec ax
920 mov bx, ax
921 shl ax, 1
922 shl bx, 2
923 add ax, bx ; My way [tm] of multiplying with 6
924 mov di, offset PartitionSizeTable
925 add di, ax ; DI - Partition Size-Element
926 mov ax, wptr [si+LocBRPT_AbsoluteLength] ; Sector-Size
927 mov bx, wptr [si+LocBRPT_AbsoluteLength+2]
928 call PART_FillOutSizeElement
929 ret
930PARTSCAN_CheckThisPartition EndP
931
932stop_scanning db 0
933
934; ===================
935; X-REFERENCE STUFF -> PartitionXref
936; ===================
937
938; Reset X-Reference
939PARTSCAN_ResetXref Proc Near Uses ax cx di
940 mov di, offset PartitionXref ; X-Reference for later syncing
941 mov cx, LocIPT_MaxPartitions
942 mov ax, 0FFFFh ; Fill up with FFh
943 rep stosb
944 mov di, offset NewHidePartTable ; Temporary Hide-Config Table
945 ;~ mov cx, LocIPT_MaxPartitions * LocIPT_LenOfIPT
946 mov cx, LocIPT_MaxPartitions * LocHPT_LenOfHPT
947 rep stosb ; Fill up with FFFFh
948 mov di, offset NewDriveLetters
949 mov cx, LocIPT_MaxPartitions ; Temporary Logical-Drive Letter Table
950 xor ax, ax
951 rep stosb ; Fill up with 0000h
952 ret
953PARTSCAN_ResetXref EndP
954
955
956
957; In: DL - Partition Number in IPT
958; DH - Partition Number in NewPartitionTable
959; Destroyed: None
960PARTSCAN_DefXref Proc Near Uses ax bx cx dx si di
961 ;movzx bx, dl
962 mov bl,dl
963 mov bh,0
964
965 mov bptr [PartitionXref+bx], dh ; X-Reference
966 ; Copy Hide-Config of IPT partition to new location in new table
967 mov si, offset HidePartitionTable
968 mov di, offset NewHidePartTable
969 ;~ mov bl, LocIPT_MaxPartitions
970 mov bl, LocHPT_LenOfHPT
971 mov al, dl
972 mul bl
973 add si, ax
974 mov al, dh
975 mul bl
976 add di, ax
977 ;~ mov cx, LocIPT_MaxPartitions
978 mov cx, LocHPT_LenOfHPT
979 rep movsb ; Copy Hide-Config to NewHideTable
980 ; Process Logical-Drive-Letter table as well...
981 ;movzx bx, dl
982 mov bl,dl
983 mov bh,0
984
985 mov al, bptr [DriveLetters+bx] ; Get Drv-Letter from org. pos
986 ;movzx bx, dh
987 mov bl,dl
988 mov bh,0
989
990 mov bptr [NewDriveLetters+bx], al ; Put Drv-Letter to new pos
991 ret
992PARTSCAN_DefXref EndP
993
994
995
996; In: DL - Partition Number in previous IPT
997; Out: DH - Partition Number in NewPartitionTable
998; Destroyed: None
999PARTSCAN_GetXref Proc Near Uses bx
1000 ;movzx bx, dl
1001 mov bl,dl
1002 mov bh,0
1003
1004 mov dh, bptr [PartitionXref+bx] ; X-Reference
1005 ret
1006PARTSCAN_GetXref EndP
1007
1008
1009;
1010; Rousseau: Adjusted for packed hidden-part-table !
1011; Needs to be re-written.
1012;
1013; This here updates the contents of the Hide-Configuration to the current IPT
1014; table.
1015PARTSCAN_SyncHideConfigWithXref Proc Near Uses ax bx cx dx si di
1016 mov si, offset NewHidePartTable
1017 mov di, offset HidePartitionTable
1018 mov dh, LocIPT_MaxPartitions ; Max entries in hide-tables.
1019
1020 PSSHCWX_SyncPartLoop:
1021 mov cl, LocIPT_MaxPartitions ; Max entries per hide-entry.
1022 xor dl, dl ; Partition Lost Counter
1023
1024 mov ch,0 ; Index.
1025
1026 PSSHCWX_SyncLoop:
1027 mov bx,si
1028
1029 ;~ lodsb ; Get Part-Pointer from Hide-Cfg
1030
1031 push dx
1032 mov dl,ch
1033 mov dh,6
1034 call CONV_GetBitfieldValue
1035 pop dx
1036
1037 ;~ cmp al, 0FFh
1038 cmp al, 3Fh
1039 je PSSHCWX_SyncEmpty
1040 ;movzx bx, al
1041 mov bl,al
1042 mov bh,0
1043
1044 mov al, [PartitionXref+bx] ; Translate it
1045 ;~ cmp al, 0FFh
1046 cmp al, 3Fh
1047 je PSSHCWX_PartLost
1048
1049 PSSHCWX_SyncEmpty:
1050 mov bx,di
1051 ;~ stosb ; Put translated pointer to new table
1052
1053 push dx
1054 mov dl,ch
1055 mov dh,6
1056 call CONV_SetBitfieldValue
1057 pop dx
1058
1059 inc ch
1060 dec cl
1061 jnz PSSHCWX_SyncLoop
1062
1063 jmp PSSHCWX_SyncLoopEnd
1064
1065 PSSHCWX_PartLost:
1066 inc dl ; One partition got lost...
1067 dec cl
1068 jnz PSSHCWX_SyncLoop
1069
1070 PSSHCWX_SyncLoopEnd:
1071
1072
1073IFDEF AUX_DEBUG
1074 IF 0
1075 pushf
1076 pusha
1077 mov al,dl
1078 call AuxIO_TeletypeHexByte
1079 call AuxIO_TeletypeNL
1080 popa
1081 popf
1082 ENDIF
1083ENDIF
1084
1085
1086 or dl, dl
1087 jz PSSHCWX_NothingLost
1088 ;~ mov al, 0FFh ; Influences OVERWRITE BUG ! (OUT OF BOUNDS !!)
1089 mov al, 3Fh
1090
1091 PSSHCWX_LostFillLoop: ; CHECK !!
1092 ;~ stosb
1093 dec cl
1094 jnz PSSHCWX_LostFillLoop
1095
1096 IFDEF AUX_DEBUG
1097 IF 0
1098 pushf
1099 pusha
1100 mov ax,di
1101 call AuxIO_TeletypeHexWord
1102 call AuxIO_TeletypeNL
1103 popa
1104 popf
1105 ENDIF
1106 ENDIF
1107
1108 PSSHCWX_NothingLost:
1109 add si, LocHPT_LenOfHPT
1110 add di, LocHPT_LenOfHPT
1111 dec dh
1112 jnz PSSHCWX_SyncPartLoop
1113
1114 ret
1115PARTSCAN_SyncHideConfigWithXref EndP
1116
1117ibm_bm_name db 'OS2 BootMgr',0
1118;win_bm_name: db 'BOOTMGR',0
Note: See TracBrowser for help on using the repository browser.