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

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

Removed the ancient 'ReleaseCode' conditional [v1.1.1-testing]

This was used in pre v1.07 versions to create a DOS .COM executable
for debugging. It has never been used in v1.07+ versions and debugging
is now done using the serial port from native AirBoot. Time to get rid
of this unused stuff.

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.0 KB
Line 
1; AiR-BOOT (c) Copyright 1998-2008 M. Kiewitz
2;
3; This file is part of AiR-BOOT
4;
5; AiR-BOOT is free software: you can redistribute it and/or modify it under
6; the terms of the GNU General Public License as published by the Free
7; Software Foundation, either version 3 of the License, or (at your option)
8; any later version.
9;
10; AiR-BOOT is distributed in the hope that it will be useful, but WITHOUT ANY
11; WARRANTY: without even the implied warranty of MERCHANTABILITY or FITNESS
12; FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13; details.
14;
15; You should have received a copy of the GNU General Public License along with
16; AiR-BOOT. If not, see <http://www.gnu.org/licenses/>.
17;
18;---------------------------------------------------------------------------
19; AiR-BOOT / PARTiTiON SCANNING
20;---------------------------------------------------------------------------
21
22
23IFDEF MODULE_NAMES
24DB 'PARTSCAN',0
25ENDIF
26
27; Note: This is complex code. So make sure that you know what you are doing in
28; here.
29
30PARTSCAN_ScanForPartitions Proc Near
31 ; 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, 080h ; 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 cmp bptr [CurPartition_Location+4], 80h ; Drive
316 jne PSSP_NoMarkPrimary
317 cmp wptr [CurPartition_Location+0], 0
318 jne PSSP_NoMarkPrimary
319 cmp wptr [CurPartition_Location+2], 0 ; Absolute Location
320 jne PSSP_NoMarkPrimary
321 call PART_MarkFirstGoodPrimary
322 PSSP_NoMarkPrimary:
323 ret
324PARTSCAN_ScanPartition EndP
325
326MBR_NoName_Patched db 15 dup (0)
327
328; Will insert this partition into NewPartTable and compare it to our "old"
329; LocIPT-table. If the same partition is found there, Flags&CRC are taken from
330; the old table, otherwise they are generated freshly.
331; Will also fill out PartitionXref to sync HideConfig later
332; In: SI - Points to Partition-Entry (16-Bytes)
333PARTSCAN_CheckThisPartition Proc Near Uses di si
334 local PartSystemID:byte, PartTypeFlags:byte
335 local PartCRC:word, PartPtr:word
336
337 mov wptr [PartPtr], si ; Save Pointer to PartitionEntry
338
339 mov al, bptr [si+LocBRPT_SystemID]
340 mov PartSystemID, al
341
342 mov cx, wptr [si+LocBRPT_BeginSector] ; Cylinder/Sector
343 mov dh, bptr [si+LocBRPT_BeginHead] ; Head
344 mov dl, bptr [CurPartition_Location+4] ; Drive
345 mov ax, wptr [si+LocBRPT_RelativeBegin] ; Absolute Sector
346 mov bx, wptr [si+LocBRPT_RelativeBegin+2]
347 add ax, wptr [CurPartition_Location+0] ; +Partition-Absolute
348 adc bx, wptr [CurPartition_Location+2] ; sectors
349
350
351
352 ; Sets up DS:SI - TmpSector
353 call DriveIO_LoadTmpSector ; Loads Boot record
354
355
356
357 push si
358 mov bx, 4B4Dh ; Magic 'MK' :)
359 call MBR_GetCheckOfSector
360 mov PartCRC, bx ; Save Partition's-CRC
361
362 ; ------------------------------ Gets internal infos of partition type
363 mov al, PartSystemID
364 call PART_SearchFileSysName
365 ; Replies AH - FileSysFlags, AL - UnhiddenID, SI - FileSystemNamePtr
366 mov di, si
367 mov PartTypeFlags, ah
368 mov PartSystemID, al ; Use Unhidden-ID
369 pop si
370
371 ;================================
372 ; AL - File System ID (Unhidden)
373 ; AH - File System Flags
374 ; SI - Boot-Record of Partition
375 ; DI - File System Name
376 ;================================
377
378 cmp PartSystemID, 07h ; We got IFS here?
379 jne PCCTP_IFSdone
380 ; Check, if 'JFS ' is at DWORD offset 36h ; Rousseau: JFS check (LVM / IPT?)
381 cmp wptr [si+36h], 'FJ'
382 jne PCCTP_IFSnoJFS
383 cmp wptr [si+38h], ' S'
384 jne PCCTP_IFSnoJFS
385 mov PartSystemID, 0FCh ; FC is JFS internally
386 jmp PCCTP_IFSdone
387 PCCTP_IFSnoJFS:
388 ; Check, if 'HPFS' is at DWORD offset 36h
389 cmp wptr [si+36h], 'PH'
390 jne PCCTP_ProbablyNTFS
391 cmp wptr [si+38h], 'SF'
392 je PCCTP_IFSdone ; 07 is HPFS internally
393 PCCTP_ProbablyNTFS:
394 inc PartSystemID ; 08 is NTFS instead of 07
395 PCCTP_IFSdone:
396
397
398 ; First check, if LVM Information Sector is available and this partition
399 ; is supported.
400 push ax
401 push dx
402 push si
403 push di
404 mov si, wptr [PartPtr]
405 mov ax, wptr [si+LocBRPT_RelativeBegin] ; Absolute Sector
406 mov dx, wptr [si+LocBRPT_RelativeBegin+2]
407 add ax, wptr [CurPartition_Location+0] ; +Partition-Absolute
408 adc dx, wptr [CurPartition_Location+2] ; sectors
409 mov si, offset LVMSector
410 call LVM_SearchForPartition ; Search for DX:AX partition
411 jnc PCCTP_CheckBootRecord
412 ; Check, if volume has driveletter assigned and remember it for later
413 mov al, [si+LocLVM_VolumeLetter]
414 or al, al
415 jnz PCCTP_HasVolumeLetter
416 mov al, 1 ; 0 would mean "not LVM supported"
417 PCCTP_HasVolumeLetter:
418 ; Save VolumeLetter in separate table
419 ;movzx bx, NewPartitions ; NewPartitions is one behind here, so
420 mov bl,NewPartitions ; NewPartitions is one behind here, so
421 mov bh,0
422
423 mov [PartitionVolumeLetters+bx], al ; it's already a zero-based offset
424 ; Now copy VolumeID and VolumeName to temporary space
425 mov di, offset MBR_NoName_Patched
426 mov ax, [si+LocLVM_PartitionID]
427 stosw
428 mov ax, [si+LocLVM_PartitionID+2]
429 stosw
430 ; Set Serial-Field to LVM-VolumeID
431
432 push di
433 add si, LocLVM_VolumeName ; Use LVM VolumeName
434 ;add si, LocLVM_PartitionName ; Use LVM PartitionName
435 mov cx, 5
436 rep movsw ; Copy LVM-PartitionName to Temp Space
437 movsb ; (11 bytes in total)
438 pop di
439
440
441 ; Check if this is an IBM-BM partition
442 cmp PartSystemID, 0ah
443 jne PCCTP_NoIbmBm
444
445 ; It is, so override the name given by IBM-BM by one that
446 ; fits in 11 chars.
447 mov si, offset ibm_bm_name
448 mov cx,5
449 rep movsw
450 movsb
451
452
453
454 PCCTP_NoIbmBm:
455 pop di
456 pop si
457 pop dx
458 pop ax
459 mov si, offset MBR_NoName_Patched
460 xor ah, ah ; no Flags_NoPartName
461 jmp PCCTP_NameSearchInIPT
462
463 PCCTP_CheckBootRecord:
464 pop di
465 pop si
466 pop dx
467 pop ax
468
469 test ah, FileSysFlags_NoName ; No-Name-Flag ? -> No Partition Name
470
471 jz PCCTP_ThereIsAName
472 jmp PCCTP_ThereIsNoName ; available
473
474 PCCTP_ThereIsAName:
475
476 ; We check for NTFS (got detected a little bit earlier in this routine)
477 cmp PartSystemID, 08h ; We got IFS/NTFS here?
478 jne PCCTP_IsNoNTFS
479 jmp PCCTP_ThereIsNoName ; NTFS has no volume label
480 PCCTP_IsNoNTFS:
481 add si, 2Bh ; DS:SI - Partition-Name
482 test ah, FileSysFlags_FAT32 ; FAT32 specific name getting ?
483
484 jz PCCTP_ResumeNormal
485
486 add si, 1Ch ; Fix for FAT 32, shiat
487 PCCTP_ResumeNormal:
488 mov cx, 11 ; 11 bytes length
489 call PART_CheckForValidPartName
490 jc PCCTP_ThereIsAName2
491
492 jmp PCCTP_ThereIsNoName
493
494 PCCTP_ThereIsAName2:
495
496 sub si, 4 ; DS:SI -> Serial&Name (15-Bytes)
497 xor ah, ah ; no Flags_NoPartName
498; jmp PCCTP_NameSearchInIPT
499
500 ;=======================================================
501 ; NAME SEARCH in IPT-Table
502 ; DS:SI - Serial&Name of Current Partition (15-Bytes)
503 ; AH - NoPartName-Flag (!MUST! be merged with Flags)
504 ;=======================================================
505 PCCTP_NameSearchInIPT:
506 xor ah, ah ; no Flags_NoPartName cause PartName valid
507 mov di, offset PartitionTable ; ES:DI - IPT-Start
508 mov dl, CFG_Partitions
509 or dl, dl
510 jnz PCCTP_SerialNameCompLoop
511 jmp PCCTP_CompareFailed
512 PCCTP_SerialNameCompLoop:
513 mov al, [di+LocIPT_Flags]
514 test al, Flags_NowFound
515 jnz PCCTP_SerialNameAlreadyFound
516 ; Now compare IPT with current Partition
517 mov cx, 15 ; Serial&Name (15-Bytes)
518 push si
519 push di
520 repz cmpsb
521 pop di
522 pop si
523
524 jne PCCTP_NoMatchYet
525
526 jmp PCCTP_Match
527
528 PCCTP_NoMatchYet:
529
530 PCCTP_SerialNameAlreadyFound:
531 add di, LocIPT_LenOfIPT
532 dec dl
533 jnz PCCTP_SerialNameCompLoop
534
535 ; if we didn't find Serial&Name, let's try Name-only without Serial
536 mov di, offset PartitionTable ; ES:DI - IPT-Start
537 mov dl, CFG_Partitions
538 PCCTP_NameCompLoop:
539 mov al, [di+LocIPT_Flags]
540 test al, Flags_NowFound
541 jnz PCCTP_NameAlreadyFound
542 ; Now compare IPT with current Partition
543 mov cx, 11 ; Name only (11-Bytes)
544 push si
545 push di
546 add si, 4
547 add di, 4 ; Skip over Serial-Field
548 repz cmpsb
549 pop di
550 pop si
551 jne PCCTP_NameNoMatch
552 mov cx, [si+0] ; Get Serial
553 mov [di+0], cx
554 mov cx, [si+2]
555 mov [di+2], cx ; ...and put it into IPT
556 jmp PCCTP_Match
557 PCCTP_NameNoMatch:
558 PCCTP_NameAlreadyFound:
559 add di, LocIPT_LenOfIPT
560 dec dl
561 jnz PCCTP_NameCompLoop
562 PCCTP_NameCompFailed:
563
564 ; So finally we search for Location and PartitionID
565 push si
566 ; Initialize some stuff for Location-Search
567 mov dh, PartSystemID
568 mov si, [PartPtr] ; DS:SI - Cur Partition Table
569 ; Relative Sector to MBR/EPR
570 mov cx, wptr [si+LocBRPT_RelativeBegin]
571 mov bx, wptr [si+LocBRPT_RelativeBegin+2]
572 add cx, [CurPartition_Location+0]
573 add bx, [CurPartition_Location+2]
574 ; BX:CX - Absolute First Sector of Partition on HDD
575 pop si
576 mov di, offset PartitionTable ; ES:DI - IPT-Start
577 mov dl, CFG_Partitions
578 PCCTP_NameLocCompLoop:
579 mov al, [di+LocIPT_Flags]
580 test al, Flags_NowFound
581 jnz PCCTP_NameLocAlreadyFound
582 ; Now compare IPT with current Partition
583 cmp dh, [di+LocIPT_SystemID]
584 jne PCCTP_NameLocMismatch
585 cmp cx, [di+LocIPT_AbsoluteBegin]
586 jne PCCTP_NameLocMismatch
587 cmp bx, [di+LocIPT_AbsoluteBegin+2]
588 jne PCCTP_NameLocMismatch
589 ; We matched location, now copy the current PartitionID and Name to
590 ; the old IPT.
591 push di
592 add di, LocIPT_Serial ; DS:SI - LocIPT-Serial&Name
593 mov cx, 15
594 rep movsb ; Copy 15 bytes
595 pop di
596 jmp PCCTP_Match
597 PCCTP_NameLocMismatch:
598 PCCTP_NameLocAlreadyFound:
599 add di, LocIPT_LenOfIPT
600 dec dl
601 jnz PCCTP_NameLocCompLoop
602 ; None of the searches worked, so forget it...
603 jmp PCCTP_CompareFailed
604
605 PCCTP_ThereIsNoName:
606 ; Try to find this partition by comparing location and PartitionID
607 ; aka LocIPT_AbsoluteBegin:dword and LocIPT_SystemID
608 ; If found, simply go to the normal match-routine, otherwise use the
609 ; File-System-Name to build the Volume-Label for the New IPT Entry.
610 mov dh, PartSystemID
611 mov si, [PartPtr] ; DS:SI - Cur Partition Table
612 ; Relative Sector to MBR/EPR
613 mov cx, wptr [si+LocBRPT_RelativeBegin]
614 mov bx, wptr [si+LocBRPT_RelativeBegin+2]
615 add cx, [CurPartition_Location+0]
616 add bx, [CurPartition_Location+2]
617 ; Build a standard-Volume Label from FileSystemNamePtr
618 ; We have to call SearchFileSysName again because of NTFS
619 push ax
620 push cx
621 mov al, dh
622 call PART_SearchFileSysName ; We want SI here <- FileSystemNamePtr
623 mov di, offset MBR_NoName_Patched
624 xor ax, ax
625 stosw
626 stosw ; Set Serial-Field to "NUL"
627 mov cx, 4
628 rep movsw ; Copy FileSystemName to Temp Space
629 xor ax, ax
630 stosw
631 stosb ; Fill last 3 bytes with "NUL"
632 mov si, offset MBR_NoName_Patched
633 pop cx
634 pop ax
635 ;=======================================================
636 ; LOCATION SEARCH in IPT-Table
637 ; DH - PartitionID of Current Partition
638 ; BX:CX - AbsoluteBegin of Current Partition
639 ; AH - NoPartName-Flag (!MUST! be merged with Flags)
640 ; DS:SI - Serial&Name of Current Partition (15-Bytes)
641 ;=======================================================
642 PCCTP_LocSearchInIPT:
643 mov ah, Flags_NoPartName ;set Flags_NoPartName, PartName invalid
644 mov di, offset PartitionTable ; ES:DI - IPT-Start
645 mov dl, CFG_Partitions
646 or dl, dl
647 jz PCCTP_LocCompFailed
648 PCCTP_LocCompLoop:
649 mov al, [di+LocIPT_Flags]
650 test al, Flags_NowFound
651 jnz PCCTP_LocAlreadyFound
652 ; Now compare IPT with current Partition
653 cmp dh, [di+LocIPT_SystemID]
654 jne PCCTP_LocMismatch
655 cmp cx, [di+LocIPT_AbsoluteBegin]
656 jne PCCTP_LocMismatch
657 cmp bx, [di+LocIPT_AbsoluteBegin+2]
658 jne PCCTP_LocMismatch
659 jmp PCCTP_Match
660 PCCTP_LocMismatch:
661 PCCTP_LocAlreadyFound:
662 add di, LocIPT_LenOfIPT
663 dec dl
664 jnz PCCTP_LocCompLoop
665 PCCTP_LocCompFailed:
666 jmp PCCTP_CompareFailed
667
668 ; ==================================
669 ; =MATCH=, found partition in IPT...
670 ; AH - NoPartName-Flag (!MUST! be merged with Flags)
671 ; DL - IPT Partition Number from Loop (inverted)
672 ; ES:DI - LocIPT-Pointer to found IPT-entry
673 ; ==================================
674 PCCTP_Match:
675 mov ch, ah
676 ; Save the new location of this partition in the Xref-Table
677 ; for converting HideConfig.
678 mov dh, dl
679 mov dl, CFG_Partitions
680 sub dl, dh
681 mov dh, NewPartitions ; is actually a counter
682 call PARTSCAN_DefXref ; DL-IPT-Partition, DH-NewPartition
683
684 ; Get Saved-Flags...
685 mov cl, bptr [di+LocIPT_Flags] ; Use saved Flags
686
687 ; ...and Saved-CRC if available...
688 mov ax, wptr [di+LocIPT_BootRecordCRC]
689 or ax, ax
690 jz PCCTP_UseNewComputedCRC
691 mov PartCRC, ax ; Use saved IPT-CRC
692 PCCTP_UseNewComputedCRC:
693 ; ...and mark partition in IPT as already found
694 or bptr [di+LocIPT_Flags], Flags_NowFound
695 ; ...get Serial&Name from IPT-table...
696 mov si, di
697 add si, LocIPT_Serial ; DS:SI - LocIPT-Serial&Name
698 jmp PCCTP_AddToNew
699
700 ; =================================
701 ; =FAILED= search, not found in IPT
702 ; AH - NoPartName-Flag (!MUST! be merged with Flags)
703 ; DS:SI - Serial&Name of Current Partition (15-Bytes)
704 ; =================================
705 PCCTP_CompareFailed:
706 mov ch, ah
707 ; Insert Default Flags...
708 mov cl, LocIPT_DefaultFlags
709
710 mov al, PartTypeFlags
711 ; May I auto-add partitions ?
712 test byte ptr [CFG_PartitionsDetect], 1
713 jz PCCTP_MayNotAddAny ; add, but non-bootable
714 test al, FileSysFlags_BootAble ; AH kam von SearchFileSysName
715 jnz PCCTP_PerhapsBootAble
716 PCCTP_MayNotAddAny:
717 mov cl, LocIPT_DefaultNonBootFlags
718 PCCTP_PerhapsBootAble:
719
720 ; On FAT32-partitions, default to P-Flag (which means using M$-hack)
721 ; Anyway, this hack has to be globaly activated by the user manually...
722 cmp PartSystemID, 09h ; Hardcoded: FAT32
723 je PCCTP_NeedsExtMShack
724 cmp PartSystemID, 0Bh
725 je PCCTP_NeedsExtMShack
726 cmp PartSystemID, 0Ch
727 je PCCTP_NeedsExtMShack
728 cmp PartSystemID, 0Eh ; FAT16 above 8 GB
729 jne PCCTP_NoExtMShack
730 ; We only get here, when the SystemID seems to be an M$ "invention"...
731 PCCTP_NeedsExtMShack:
732 or cl, Flags_ExtPartMShack
733 PCCTP_NoExtMShack:
734
735 ;================================================
736 ; CL - IPT-Partition-Flags, CH - NoPartName-Flag
737 ; DS:SI - PartSerial&Name (15-Bytes)
738 ;================================================
739 PCCTP_AddToNew:
740 mov al, Flags_NoPartName ; Unset NoPartName
741 not al
742 and cl, al
743 or cl, ch ; CL = Both CL and CH merged
744
745 ; Calculate Pointer to IPT
746 mov di, offset NewPartTable ; ES:DI - NewPartTable
747 ;movzx ax, NewPartitions
748 mov al,NewPartitions
749 mov ah,0
750
751 mov bl, LocIPT_LenOfIPT
752 mul bl
753 add di, ax ; ES:DI - Last+1 Entry of NewPartTable
754
755 ; Now finally write this partition to our IPT
756 ;=============================================
757 push cx
758 mov cx, 15 ; Copy Serial&Name...
759 rep movsb
760 pop cx
761
762 mov si, [PartPtr] ; DS:SI - Cur Partition Entry
763 mov al, bptr [CurPartition_Location+4] ; Drive
764 stosb
765 mov al, PartSystemID ; Unhidden SystemID
766 stosb
767 mov al, cl ; Partition-Flags from register...
768 stosb
769 mov ax, PartCRC ; BootRecordCRC...
770 stosw
771 mov al, bptr [si+LocBRPT_BeginHead]
772 stosb
773 mov ax, wptr [si+LocBRPT_BeginSector] ; Cylinder/Sector
774 stosw
775 mov al, bptr [CurPartition_Location+5] ; Head of Part-Table
776 stosb
777 mov ax, wptr [CurPartition_Location+6] ; Cylinder/Sector
778 stosw
779 mov ax, wptr [si+LocBRPT_RelativeBegin]
780 mov bx, wptr [si+LocBRPT_RelativeBegin+2]
781 mov cx, wptr [CurPartition_Location+0] ; +Partition-Absolute
782 mov dx, wptr [CurPartition_Location+2] ; sectors
783 add ax, cx
784 adc bx, dx
785 stosw
786 mov ax, bx
787 stosw
788 mov ax, cx ; Absolute sector of partition table
789 stosw
790 mov ax, dx
791 stosw
792 inc byte ptr [NewPartitions]; Adjusted for Wasm ; NEW IPT Entry DONE
793
794 cmp byte ptr [NewPartitions], LocIPT_MaxPartitions
795 jbe PCCTP_NotTooManyPartitions
796
797 ; Should not be reached since scanning is stopped outside this
798 ; function when partition limit exceeds.
799 mov si, offset TXT_TooManyPartitions
800 call MBR_Teletype
801 jmp MBR_HaltSystem
802
803
804 PCCTP_NotTooManyPartitions:
805 ; UNHIDE PARTITION, if it was hidden previously
806 mov al, PartSystemID
807 cmp al, 08h ; internally IFS/NTFS?
808 je PCCTP_GotInternalIFS
809 cmp al, 0FCh ; internally IFS/JFS?
810 jne PCCTP_NoInternalIFS
811 PCCTP_GotInternalIFS:
812 mov al, 07h
813 PCCTP_NoInternalIFS:
814 mov bptr [si+LocBRPT_SystemID], al
815
816 ; Calculate Size of this partition and put it into separate table...
817 ;movzx ax, NewPartitions
818 mov al,NewPartitions
819 mov ah,0
820
821 dec ax
822 mov bx, ax
823 shl ax, 1
824 shl bx, 2
825 add ax, bx ; My way [tm] of multiplying with 6
826 mov di, offset PartitionSizeTable
827 add di, ax ; DI - Partition Size-Element
828 mov ax, wptr [si+LocBRPT_AbsoluteLength] ; Sector-Size
829 mov bx, wptr [si+LocBRPT_AbsoluteLength+2]
830 call PART_FillOutSizeElement
831 ret
832PARTSCAN_CheckThisPartition EndP
833
834stop_scanning db 0
835
836; ===================
837; X-REFERENCE STUFF -> PartitionXref
838; ===================
839
840; Reset X-Reference
841PARTSCAN_ResetXref Proc Near Uses ax cx di
842 mov di, offset PartitionXref ; X-Reference for later syncing
843 mov cx, LocIPT_MaxPartitions
844 mov ax, 0FFFFh ; Fill up with FFh
845 rep stosb
846 mov di, offset NewHidePartTable ; Temporary Hide-Config Table
847 ;~ mov cx, LocIPT_MaxPartitions * LocIPT_LenOfIPT
848 mov cx, LocIPT_MaxPartitions * LocHPT_LenOfHPT
849 rep stosb ; Fill up with FFFFh
850 mov di, offset NewDriveLetters
851 mov cx, LocIPT_MaxPartitions ; Temporary Logical-Drive Letter Table
852 xor ax, ax
853 rep stosb ; Fill up with 0000h
854 ret
855PARTSCAN_ResetXref EndP
856
857
858
859; In: DL - Partition Number in IPT
860; DH - Partition Number in NewPartitionTable
861; Destroyed: None
862PARTSCAN_DefXref Proc Near Uses ax bx cx dx si di
863 ;movzx bx, dl
864 mov bl,dl
865 mov bh,0
866
867 mov bptr [PartitionXref+bx], dh ; X-Reference
868 ; Copy Hide-Config of IPT partition to new location in new table
869 mov si, offset HidePartitionTable
870 mov di, offset NewHidePartTable
871 ;~ mov bl, LocIPT_MaxPartitions
872 mov bl, LocHPT_LenOfHPT
873 mov al, dl
874 mul bl
875 add si, ax
876 mov al, dh
877 mul bl
878 add di, ax
879 ;~ mov cx, LocIPT_MaxPartitions
880 mov cx, LocHPT_LenOfHPT
881 rep movsb ; Copy Hide-Config to NewHideTable
882 ; Process Logical-Drive-Letter table as well...
883 ;movzx bx, dl
884 mov bl,dl
885 mov bh,0
886
887 mov al, bptr [DriveLetters+bx] ; Get Drv-Letter from org. pos
888 ;movzx bx, dh
889 mov bl,dl
890 mov bh,0
891
892 mov bptr [NewDriveLetters+bx], al ; Put Drv-Letter to new pos
893 ret
894PARTSCAN_DefXref EndP
895
896
897
898; In: DL - Partition Number in previous IPT
899; Out: DH - Partition Number in NewPartitionTable
900; Destroyed: None
901PARTSCAN_GetXref Proc Near Uses bx
902 ;movzx bx, dl
903 mov bl,dl
904 mov bh,0
905
906 mov dh, bptr [PartitionXref+bx] ; X-Reference
907 ret
908PARTSCAN_GetXref EndP
909
910
911;
912; Rousseau: Adjusted for packed hidden-part-table !
913; Needs to be re-written.
914;
915; This here updates the contents of the Hide-Configuration to the current IPT
916; table.
917PARTSCAN_SyncHideConfigWithXref Proc Near Uses ax bx cx dx si di
918 mov si, offset NewHidePartTable
919 mov di, offset HidePartitionTable
920 mov dh, LocIPT_MaxPartitions ; Max entries in hide-tables.
921
922 PSSHCWX_SyncPartLoop:
923 mov cl, LocIPT_MaxPartitions ; Max entries per hide-entry.
924 xor dl, dl ; Partition Lost Counter
925
926 mov ch,0 ; Index.
927
928 PSSHCWX_SyncLoop:
929 mov bx,si
930
931 ;~ lodsb ; Get Part-Pointer from Hide-Cfg
932
933 push dx
934 mov dl,ch
935 mov dh,6
936 call CONV_GetBitfieldValue
937 pop dx
938
939 ;~ cmp al, 0FFh
940 cmp al, 3Fh
941 je PSSHCWX_SyncEmpty
942 ;movzx bx, al
943 mov bl,al
944 mov bh,0
945
946 mov al, [PartitionXref+bx] ; Translate it
947 ;~ cmp al, 0FFh
948 cmp al, 3Fh
949 je PSSHCWX_PartLost
950
951 PSSHCWX_SyncEmpty:
952 mov bx,di
953 ;~ stosb ; Put translated pointer to new table
954
955 push dx
956 mov dl,ch
957 mov dh,6
958 call CONV_SetBitfieldValue
959 pop dx
960
961 inc ch
962 dec cl
963 jnz PSSHCWX_SyncLoop
964
965 jmp PSSHCWX_SyncLoopEnd
966
967 PSSHCWX_PartLost:
968 inc dl ; One partition got lost...
969 dec cl
970 jnz PSSHCWX_SyncLoop
971
972 PSSHCWX_SyncLoopEnd:
973
974
975 IFDEF AUX_DEBUG
976 ;~ pusha
977 ;~ mov al,dl
978 ;~ call AuxIO_TeletypeHexByte
979 ;~ call AuxIO_TeletypeNL
980 ;~ popa
981 ENDIF
982
983
984 or dl, dl
985 jz PSSHCWX_NothingLost
986 ;~ mov al, 0FFh ; Influences OVERWRITE BUG ! (OUT OF BOUNDS !!)
987 mov al, 3Fh
988
989 PSSHCWX_LostFillLoop: ; CHECK !!
990 ;~ stosb
991 dec cl
992 jnz PSSHCWX_LostFillLoop
993
994 IFDEF AUX_DEBUG
995 ; debug code
996 ;~ mov ax,di
997 ;~ call AuxIO_TeletypeHexWord
998 ;~ call AuxIO_TeletypeNL
999 ENDIF
1000
1001 PSSHCWX_NothingLost:
1002 add si, LocHPT_LenOfHPT
1003 add di, LocHPT_LenOfHPT
1004 dec dh
1005 jnz PSSHCWX_SyncPartLoop
1006
1007 ret
1008PARTSCAN_SyncHideConfigWithXref EndP
1009
1010ibm_bm_name db 'OS2 BootMgr',0
1011;win_bm_name: db 'BOOTMGR',0
Note: See TracBrowser for help on using the repository browser.