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

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

Removed Linux noise [v1.1.1-testing]

This stuff was already commented out and not applicable anymore.
It was used to directly boot Linux kernels from FAT some eons ago.
Linux is supported by chain-loading GRUB.

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