source: trunk/BOOTCODE/REGULAR/PARTSCAN.ASM@ 41

Last change on this file since 41 was 40, checked in by Ben Rietbroek, 12 years ago

Converting to JWasm -- phase 3 (not working) [2012-02-16]

WARNING!!

All commits upto and including the commit of [2012-05-13] contain
a severe bug!! Building from these sources and then disabling
the 'force LBA' feature while also using the drive-letter feature or
editing the label can DESTROY THE MBR on ALL ATTACHED DISKS!!
DO NOT DISABLE 'FORCE LBA USAGE' WHEN BUILT FROM THE THESE COMMITS!!

Problems

o Problem with location of BSS
o Problem with segments

Info

o Adjusted DISCLAIM.TXT

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