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

Last change on this file since 65 was 57, checked in by Ben Rietbroek, 10 years ago

All source-files lowercased [v1.1.1-testing]

Some standard files like 'COPYING', 'LICENSE', etc. have not been
converted to lower case because they are usually distributed uppercased.

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