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

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

More hard-coded '80h' corrections [v1.1.1-testing]

Code in 'partmain.asm' around line 1350 needs some more attention.
Possibly the whole 'boot-flag' stuff is not needed with modern BIOSses.
Updating them is disabled for now, which should only affect very old
BIOSses that don't leave this checking to the MBR code.

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