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

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

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