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

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

Scan the disks for info prior to partition scanning [v1.1.1-testing]

This populates the DISKINFO structures for each disk found, which means
that size, BIOS geometry, LVM info etc. is now available.

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