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

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

Now locating Master LVM-sectors when scanning disks [v1.1.1-testing]

Note that if LVM is set to be ignored in the SETUP, checking for a
signature will not be done and thus no Master LVM sectors will be found.

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