| 1 |
|
|---|
| 2 | ; Disclaimer:
|
|---|
| 3 | ;=============
|
|---|
| 4 | ; The sourcecode is released via www.netlabs.org CVS *ONLY*.
|
|---|
| 5 | ; You MUST NOT upload it to other servers nor republish it in any way.
|
|---|
| 6 | ; The sourcecode is still COPYRIGHTED and NOT RELEASED UNDER GPL.
|
|---|
| 7 | ; It's (c) Copyright 1998-2003 by Martin Kiewitz.
|
|---|
| 8 | ; You may recompile the source and do *PRIVATE* modifications, but please keep
|
|---|
| 9 | ; in mind that modifying this code needs at least *some* assembly skill. If
|
|---|
| 10 | ; you mess up your system, because you needed to hack your way through, don't
|
|---|
| 11 | ; blame me. Releasing a customized version of AiR-BOOT, selling it in any form
|
|---|
| 12 | ; or reusing parts of this source is *PROHIBITED*. Ask me, if you have some
|
|---|
| 13 | ; idea about new functionality *before* developing the code, otherwise I will
|
|---|
| 14 | ; definitely reject it. Also please accept, that I have some basic design
|
|---|
| 15 | ; rules on AiR-BOOT and I will maintain them at all costs, so this won't get
|
|---|
| 16 | ; another GRUB.
|
|---|
| 17 |
|
|---|
| 18 | ;---------------------------------------------------------------------------
|
|---|
| 19 | ; AiR-BOOT / PARTiTiON SCANNING
|
|---|
| 20 | ;---------------------------------------------------------------------------
|
|---|
| 21 |
|
|---|
| 22 | ; Note: This is complex code. Also some of this functions have DS != CS, so
|
|---|
| 23 | ; make sure that you know what you are doing in here.
|
|---|
| 24 |
|
|---|
| 25 | PARTSCAN_ScanForPartitions Proc Near Uses
|
|---|
| 26 | ; Reset X-Reference
|
|---|
| 27 | call PARTSCAN_ResetXref
|
|---|
| 28 |
|
|---|
| 29 | push ds si
|
|---|
| 30 | push 0040h
|
|---|
| 31 | pop ds
|
|---|
| 32 | mov si, 0075h
|
|---|
| 33 | mov dh, ds:[si] ; 40:75 -> POST: Total Harddiscs == DL
|
|---|
| 34 | pop si ds
|
|---|
| 35 | mov TotalHarddiscs, dh
|
|---|
| 36 | xor al, al
|
|---|
| 37 | mov NewPartitions, al
|
|---|
| 38 |
|
|---|
| 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 |
|
|---|
| 48 | ; Use X-Reference to sync NewPartitionTable with Hide-Config
|
|---|
| 49 | call PARTSCAN_SyncHideConfigWithXref
|
|---|
| 50 |
|
|---|
| 51 | ; Now we copy the new IPT over the old one...
|
|---|
| 52 | mov si, offset NewPartTable
|
|---|
| 53 | mov di, offset PartitionTable
|
|---|
| 54 | movzx ax, NewPartitions
|
|---|
| 55 | mov CFG_Partitions, al
|
|---|
| 56 | mov bl, LocIPT_LenOfIPT
|
|---|
| 57 | mul bl
|
|---|
| 58 | mov cx, ax
|
|---|
| 59 | rep movsb
|
|---|
| 60 |
|
|---|
| 61 | ; and the New Logical Drive Letter table as well...
|
|---|
| 62 | mov si, offset NewDriveLetters
|
|---|
| 63 | mov di, offset DriveLetters
|
|---|
| 64 | mov cx, LocIPT_MaxPartitions/2
|
|---|
| 65 | rep movsw
|
|---|
| 66 |
|
|---|
| 67 | ; Search for any Linux partition and remember, if it got found...
|
|---|
| 68 | mov si, offset PartitionTable
|
|---|
| 69 | movzx cx, CFG_Partitions
|
|---|
| 70 | xor dl, dl ; DL - Is Linux here ?
|
|---|
| 71 | or cx, cx
|
|---|
| 72 | jz PSSFP_NoPartitions
|
|---|
| 73 | PSSFP_LinuxLoop:
|
|---|
| 74 | cmp bptr [si+LocIPT_SystemID], 083h ; Hard-Coded
|
|---|
| 75 | jne PSSFP_NoLinux
|
|---|
| 76 | mov dl, 1 ; Linux found...
|
|---|
| 77 | PSSFP_NoLinux:
|
|---|
| 78 | add si, LocIPT_LenOfIPT
|
|---|
| 79 | loop PSSFP_LinuxLoop
|
|---|
| 80 | PSSFP_NoPartitions:
|
|---|
| 81 | mov GotLinux, dl ; Set Flag
|
|---|
| 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 | or cx, cx
|
|---|
| 89 | jz PSSFP_NoAutoDriveLetter
|
|---|
| 90 | mov si, offset PartitionTable
|
|---|
| 91 | mov di, offset DriveLetters
|
|---|
| 92 | mov ax, wptr [AutoDrvLetterSerial]
|
|---|
| 93 | mov bx, wptr [AutoDrvLetterSerial+2]
|
|---|
| 94 | PSSFP_AutoDrvLetterLoop:
|
|---|
| 95 | cmp ax, [si+LocIPT_Serial]
|
|---|
| 96 | jne PSSFP_AutoDrvLetterNoMatch
|
|---|
| 97 | cmp bx, [si+LocIPT_Serial+2]
|
|---|
| 98 | jne PSSFP_AutoDrvLetterNoMatch
|
|---|
| 99 | ; We got a match, so set Drive-Letter in DL
|
|---|
| 100 | or bptr [si+LocIPT_Flags], Flags_DriveLetter
|
|---|
| 101 | mov [di], dl
|
|---|
| 102 | PSSFP_AutoDrvLetterNoMatch:
|
|---|
| 103 | add si, LocIPT_LenOfIPT
|
|---|
| 104 | inc di
|
|---|
| 105 | loop PSSFP_AutoDrvLetterLoop
|
|---|
| 106 | mov AutoDrvLetter, 0 ; Disable after processing...
|
|---|
| 107 | PSSFP_NoAutoDriveLetter:
|
|---|
| 108 | ret
|
|---|
| 109 | PARTSCAN_ScanForPartitions EndP
|
|---|
| 110 |
|
|---|
| 111 | ; Scannt die Festplatte auf jegliche Partitionstabellen...
|
|---|
| 112 | ; Falls eine fehlerhafte Partition gefunden wird, wird abgebrochen.
|
|---|
| 113 | ; falls eine Extended Partition (DOS) gefunden wird, wird erneut gescannt.
|
|---|
| 114 | PARTSCAN_ScanDriveForPartitions Proc Near Uses
|
|---|
| 115 | xor ax, ax
|
|---|
| 116 | xor bx, bx ; Location Absoluter Sektor 0
|
|---|
| 117 | mov cx, 0001h
|
|---|
| 118 | xor dh, dh ; Location Zylinder 0, Side 0, Sektor 1 MBR
|
|---|
| 119 | mov [ExtendedAbsPosSet], al
|
|---|
| 120 | mov wptr [ExtendedAbsPos+0], ax
|
|---|
| 121 | mov wptr [ExtendedAbsPos+2], ax
|
|---|
| 122 | PSSDFP_LoadThisPartition:
|
|---|
| 123 | call DriveIO_LoadPartition
|
|---|
| 124 | jc PSSDFP_InvalidPartition
|
|---|
| 125 | call PARTSCAN_ScanPartition
|
|---|
| 126 | IFDEF ReleaseCode
|
|---|
| 127 | call DriveIO_SavePartition
|
|---|
| 128 | ENDIF
|
|---|
| 129 | call PARTSCAN_ScanPartitionForExtended
|
|---|
| 130 | jc PSSDFP_LoadThisPartition
|
|---|
| 131 | PSSDFP_InvalidPartition:
|
|---|
| 132 | ret
|
|---|
| 133 | PARTSCAN_ScanDriveForPartitions EndP
|
|---|
| 134 |
|
|---|
| 135 | ; The following routines have NOT *DS* set to CS, so we must address via ES
|
|---|
| 136 | PARTSCAN_ScanPartition Proc Near Uses ax ds si
|
|---|
| 137 | push ExecBaseSeg
|
|---|
| 138 | pop ds
|
|---|
| 139 | mov si, ExecBasePtr
|
|---|
| 140 | add si, 446 ; DS:SI - First Partition-Entry
|
|---|
| 141 | PSSP_ScanLoop:
|
|---|
| 142 | mov al, bptr ds:[si+LocBRPT_SystemID]
|
|---|
| 143 | cmp al, 5 ; Is Partition EXTENDED ?
|
|---|
| 144 | je PSSP_IgnorePartition
|
|---|
| 145 | cmp al, 0Fh ; Is Partition EXTENDED (M$-DOS7) ?
|
|---|
| 146 | je PSSP_IgnorePartition
|
|---|
| 147 | cmp al, 0 ; Is Partition EMPTY ?
|
|---|
| 148 | je PSSP_IgnorePartition
|
|---|
| 149 | ; Ignore this Partitions, because there are no real Partitions
|
|---|
| 150 | call PARTSCAN_CheckThisPartition
|
|---|
| 151 | PSSP_IgnorePartition:
|
|---|
| 152 | ; Lscht das Boot-Able Flag...
|
|---|
| 153 | and byte ptr ds:[si+LocBRPT_Flags], 7Fh ; Reset the Active-Flag
|
|---|
| 154 | add si, LocBRPT_LenOfEntry ; 16 Bytes per partition entry
|
|---|
| 155 | cmp si, 500+ExecBasePtr
|
|---|
| 156 | jb PSSP_ScanLoop
|
|---|
| 157 | ; If we are on first HDD and in primary partition table -> mark primary
|
|---|
| 158 | cmp bptr es:[CurPartition_Location+4], 80h ; Drive
|
|---|
| 159 | jne PSSP_NoMarkPrimary
|
|---|
| 160 | cmp wptr es:[CurPartition_Location+0], 0
|
|---|
| 161 | jne PSSP_NoMarkPrimary
|
|---|
| 162 | cmp wptr es:[CurPartition_Location+2], 0 ; Absolute Location
|
|---|
| 163 | jne PSSP_NoMarkPrimary
|
|---|
| 164 | call PART_MarkFirstGoodPrimary
|
|---|
| 165 | PSSP_NoMarkPrimary:
|
|---|
| 166 | ret
|
|---|
| 167 | PARTSCAN_ScanPartition EndP
|
|---|
| 168 |
|
|---|
| 169 | MBR_NoName_Patched db 15 dup (0)
|
|---|
| 170 |
|
|---|
| 171 | ; Will insert this partition into NewPartTable and compare it to our "old"
|
|---|
| 172 | ; LocIPT-table. If the same partition is found there, Flags&CRC are taken from
|
|---|
| 173 | ; the old table, otherwise they are generated freshly.
|
|---|
| 174 | ; Will also fill out PartitionXref to sync HideConfig later
|
|---|
| 175 | ; In: DS:SI - Partition-Entry (16-Bytes)
|
|---|
| 176 | ; ES - is CS
|
|---|
| 177 | ; (DS is *NOT* CS here)
|
|---|
| 178 | PARTSCAN_CheckThisPartition Proc Near Uses di ds si
|
|---|
| 179 | local PartSystemID:byte, PartTypeFlags:byte
|
|---|
| 180 | local PartCRC:word, PartPtr:dword
|
|---|
| 181 |
|
|---|
| 182 | mov ax, ds
|
|---|
| 183 | mov wptr [PartPtr+2], ax ; ...
|
|---|
| 184 | mov wptr [PartPtr+0], si ; Save Pointer to PartitionEntry
|
|---|
| 185 |
|
|---|
| 186 | mov al, bptr ds:[si+LocBRPT_SystemID]
|
|---|
| 187 | mov PartSystemID, al
|
|---|
| 188 |
|
|---|
| 189 | mov cx, wptr ds:[si+LocBRPT_BeginSector] ; Cylinder/Sector
|
|---|
| 190 | mov dh, bptr ds:[si+LocBRPT_BeginHead] ; Head
|
|---|
| 191 | mov dl, bptr es:[CurPartition_Location+4] ; Drive
|
|---|
| 192 | mov ax, wptr ds:[si+LocBRPT_RelativeBegin] ; Absolute Sector
|
|---|
| 193 | mov bx, wptr ds:[si+LocBRPT_RelativeBegin+2]
|
|---|
| 194 | add ax, wptr es:[CurPartition_Location+0] ; +Partition-Absolute
|
|---|
| 195 | adc bx, wptr es:[CurPartition_Location+2] ; sectors
|
|---|
| 196 | call DriveIO_LoadTmpSector ; Loads Boot record
|
|---|
| 197 | ; Sets up DS:SI - TmpSector
|
|---|
| 198 |
|
|---|
| 199 | push si
|
|---|
| 200 | mov bx, 4B4Dh ; Magic 'MK' :)
|
|---|
| 201 | call MBR_GetCheckOfSector
|
|---|
| 202 | mov PartCRC, bx ; Save Partition's-CRC
|
|---|
| 203 |
|
|---|
| 204 | ; ------------------------------ Gets internal infos of partition type
|
|---|
| 205 | mov al, PartSystemID
|
|---|
| 206 | call PART_SearchFileSysName
|
|---|
| 207 | ; Replies AH - FileSysFlags, AL - UnhiddenID, SI - FileSystemNamePtr
|
|---|
| 208 | mov di, si
|
|---|
| 209 | mov PartTypeFlags, ah
|
|---|
| 210 | mov PartSystemID, al ; Use Unhidden-ID
|
|---|
| 211 | pop si
|
|---|
| 212 |
|
|---|
| 213 | ;================================
|
|---|
| 214 | ; AL - File System ID (Unhidden)
|
|---|
| 215 | ; AH - File System Flags
|
|---|
| 216 | ; SI - Boot-Record of Partition
|
|---|
| 217 | ; DI - File System Name
|
|---|
| 218 | ; DS==CS here
|
|---|
| 219 | ;================================
|
|---|
| 220 |
|
|---|
| 221 | test ah, FileSysFlags_NoName ; No-Name-Flag ? -> No Partition Name
|
|---|
| 222 | jnz PCCTP_ThereIsNoName ; available
|
|---|
| 223 | cmp PartSystemID, 07h ; We got IFS here?
|
|---|
| 224 | jne PCCTP_NotNTFS
|
|---|
| 225 | ; Check, if 'HPFS' is at DWORD offset 36h
|
|---|
| 226 | cmp wptr ds:[si+36h], 'PH'
|
|---|
| 227 | jne PCCTP_SeemsNTFS
|
|---|
| 228 | cmp wptr ds:[si+38h], 'SF'
|
|---|
| 229 | je PCCTP_NotNTFS
|
|---|
| 230 | PCCTP_SeemsNTFS:
|
|---|
| 231 | inc PartSystemID
|
|---|
| 232 | jmp PCCTP_ThereIsNoName
|
|---|
| 233 | PCCTP_NotNTFS:
|
|---|
| 234 | test ah, FileSysFlags_FAT32 ; FAT32 specific name getting ?
|
|---|
| 235 | jz PCCTP_ResumeNormal
|
|---|
| 236 | add si, 1Ch ; Fix for FAT 32, shiat
|
|---|
| 237 | PCCTP_ResumeNormal:
|
|---|
| 238 | add si, 2Bh ; DS:SI - Partition-Name
|
|---|
| 239 | mov cx, 11 ; 11 bytes length
|
|---|
| 240 | call PART_CheckForValidPartName
|
|---|
| 241 | jnc PCCTP_ThereIsNoName
|
|---|
| 242 | ; jnc PCCTP_SetNameToNoName
|
|---|
| 243 | sub si, 4 ; DS:SI -> Serial&Name (15-Bytes)
|
|---|
| 244 | xor ah, ah ; no Flags_NoPartName
|
|---|
| 245 | jmp PCCTP_NameSearchInIPT
|
|---|
| 246 |
|
|---|
| 247 | ; WAS: NTFS/HPFS detection problem
|
|---|
| 248 | ; PCCTP_SetNameToNoName:
|
|---|
| 249 | ; cmp PartSystemID, 07h ; We got HPFS that failed ?
|
|---|
| 250 | ; jne PCCTP_NotHPFS ; -> is NTFS (internal type 08h)
|
|---|
| 251 | ; inc PartSystemID ; All that fails is Microsoft <bg>
|
|---|
| 252 | ; PCCTP_NotHPFS:
|
|---|
| 253 | ; jmp PCCTP_ThereIsNoName
|
|---|
| 254 |
|
|---|
| 255 | ;=======================================================
|
|---|
| 256 | ; NAME SEARCH in IPT-Table
|
|---|
| 257 | ; DS:SI - Serial&Name of Current Partition (15-Bytes)
|
|---|
| 258 | ; AH - NoPartName-Flag (!MUST! be merged with Flags)
|
|---|
| 259 | ;=======================================================
|
|---|
| 260 | PCCTP_NameSearchInIPT:
|
|---|
| 261 | xor ah, ah ; no Flags_NoPartName cause PartName valid
|
|---|
| 262 | mov di, offset PartitionTable ; ES:DI - IPT-Start
|
|---|
| 263 | mov dl, es:CFG_Partitions
|
|---|
| 264 | or dl, dl
|
|---|
| 265 | jz PCCTP_NameCompFailed
|
|---|
| 266 | PCCTP_SerialNameCompLoop:
|
|---|
| 267 | mov al, es:[di+LocIPT_Flags]
|
|---|
| 268 | test al, Flags_NowFound
|
|---|
| 269 | jnz PCCTP_SerialNameAlreadyFound
|
|---|
| 270 | ; Now compare IPT with current Partition
|
|---|
| 271 | mov cx, 15 ; Serial&Name (15-Bytes)
|
|---|
| 272 | push si di
|
|---|
| 273 | repz cmpsb
|
|---|
| 274 | pop di si
|
|---|
| 275 | je PCCTP_Match
|
|---|
| 276 | PCCTP_SerialNameAlreadyFound:
|
|---|
| 277 | add di, LocIPT_LenOfIPT
|
|---|
| 278 | dec dl
|
|---|
| 279 | jnz PCCTP_SerialNameCompLoop
|
|---|
| 280 |
|
|---|
| 281 | ; if we didn't find Serial&Name, let's try Name-only without Serial
|
|---|
| 282 | mov di, offset PartitionTable ; ES:DI - IPT-Start
|
|---|
| 283 | mov dl, CFG_Partitions
|
|---|
| 284 | PCCTP_NameCompLoop:
|
|---|
| 285 | mov al, es:[di+LocIPT_Flags]
|
|---|
| 286 | test al, Flags_NowFound
|
|---|
| 287 | jnz PCCTP_NameAlreadyFound
|
|---|
| 288 | ; Now compare IPT with current Partition
|
|---|
| 289 | mov cx, 11 ; Name only (11-Bytes)
|
|---|
| 290 | push si di
|
|---|
| 291 | add si, 4
|
|---|
| 292 | add di, 4 ; Skip over Serial-Field
|
|---|
| 293 | repz cmpsb
|
|---|
| 294 | pop di si
|
|---|
| 295 | jne PCCTP_NameNoMatch
|
|---|
| 296 | mov cx, ds:[si+0] ; Get Serial
|
|---|
| 297 | mov es:[di+0], cx
|
|---|
| 298 | mov cx, ds:[si+2]
|
|---|
| 299 | mov es:[di+2], cx ; ...and put it into IPT
|
|---|
| 300 | jmp PCCTP_Match
|
|---|
| 301 | PCCTP_NameNoMatch:
|
|---|
| 302 | PCCTP_NameAlreadyFound:
|
|---|
| 303 | add di, LocIPT_LenOfIPT
|
|---|
| 304 | dec dl
|
|---|
| 305 | jnz PCCTP_NameCompLoop
|
|---|
| 306 | PCCTP_NameCompFailed:
|
|---|
| 307 | jmp PCCTP_CompareFailed
|
|---|
| 308 |
|
|---|
| 309 | PCCTP_ThereIsNoName:
|
|---|
| 310 | ; First, try to find this partition by comparing location and PartitionID
|
|---|
| 311 | ; aka LocIPT_AbsoluteBegin:dword and LocIPT_SystemID
|
|---|
| 312 | ; If found, simply go to the normal match-routine, otherwise use the
|
|---|
| 313 | ; File-System-Name to build the Volume-Label for the New IPT Entry.
|
|---|
| 314 | mov dh, PartSystemID
|
|---|
| 315 | push ds
|
|---|
| 316 | lds si, dptr PartPtr ; DS:SI - Cur Partition Entry
|
|---|
| 317 | ; Relative Sector to MBR/EPR
|
|---|
| 318 | mov cx, wptr ds:[si+LocBRPT_RelativeBegin]
|
|---|
| 319 | mov bx, wptr ds:[si+LocBRPT_RelativeBegin+2]
|
|---|
| 320 | add cx, cs:[CurPartition_Location+0]
|
|---|
| 321 | add bx, cs:[CurPartition_Location+2]
|
|---|
| 322 | ; BX:CX - Absolute First Sector of Partition on HDD
|
|---|
| 323 | pop ds
|
|---|
| 324 | ; Build a standard-Volume Label from FileSystemNamePtr
|
|---|
| 325 | ; We have to call SearchFileSysName again because of NTFS
|
|---|
| 326 | push ax cx
|
|---|
| 327 | mov al, dh
|
|---|
| 328 | call PART_SearchFileSysName ; We want SI here <- FileSystemNamePtr
|
|---|
| 329 | mov di, offset MBR_NoName_Patched
|
|---|
| 330 | add di, 4 ; Skip Serial-Field
|
|---|
| 331 | mov cx, 8
|
|---|
| 332 | rep movsb ; Copy FileSystemName to Temp Space
|
|---|
| 333 | mov si, offset MBR_NoName_Patched
|
|---|
| 334 | pop cx ax
|
|---|
| 335 | ;=======================================================
|
|---|
| 336 | ; LOCATION SEARCH in IPT-Table
|
|---|
| 337 | ; DH - PartitionID of Current Partition
|
|---|
| 338 | ; BX:CX - AbsoluteBegin of Current Partition
|
|---|
| 339 | ; AH - NoPartName-Flag (!MUST! be merged with Flags)
|
|---|
| 340 | ; DS:SI - Serial&Name of Current Partition (15-Bytes)
|
|---|
| 341 | ;=======================================================
|
|---|
| 342 | PCCTP_LocSearchInIPT:
|
|---|
| 343 | mov ah, Flags_NoPartName ;set Flags_NoPartName, PartName invalid
|
|---|
| 344 | mov di, offset PartitionTable ; ES:DI - IPT-Start
|
|---|
| 345 | mov dl, es:CFG_Partitions
|
|---|
| 346 | or dl, dl
|
|---|
| 347 | jz PCCTP_LocCompFailed
|
|---|
| 348 | PCCTP_LocCompLoop:
|
|---|
| 349 | mov al, es:[di+LocIPT_Flags]
|
|---|
| 350 | test al, Flags_NowFound
|
|---|
| 351 | jnz PCCTP_LocAlreadyFound
|
|---|
| 352 | ; Now compare IPT with current Partition
|
|---|
| 353 | cmp dh, es:[di+LocIPT_SystemID]
|
|---|
| 354 | jne PCCTP_LocMismatch
|
|---|
| 355 | cmp cx, es:[di+LocIPT_AbsoluteBegin]
|
|---|
| 356 | jne PCCTP_LocMismatch
|
|---|
| 357 | cmp bx, es:[di+LocIPT_AbsoluteBegin+2]
|
|---|
| 358 | jne PCCTP_LocMismatch
|
|---|
| 359 | jmp PCCTP_Match
|
|---|
| 360 | PCCTP_LocMismatch:
|
|---|
| 361 | PCCTP_LocAlreadyFound:
|
|---|
| 362 | add di, LocIPT_LenOfIPT
|
|---|
| 363 | dec dl
|
|---|
| 364 | jnz PCCTP_LocCompLoop
|
|---|
| 365 | PCCTP_LocCompFailed:
|
|---|
| 366 | jmp PCCTP_CompareFailed
|
|---|
| 367 |
|
|---|
| 368 | ; ==================================
|
|---|
| 369 | ; =MATCH=, found partition in IPT...
|
|---|
| 370 | ; AH - NoPartName-Flag (!MUST! be merged with Flags)
|
|---|
| 371 | ; DL - IPT Partition Number from Loop (inverted)
|
|---|
| 372 | ; ES:DI - LocIPT-Pointer to found IPT-entry
|
|---|
| 373 | ; ==================================
|
|---|
| 374 | PCCTP_Match:
|
|---|
| 375 | mov ch, ah
|
|---|
| 376 | ; Save the new location of this partition in the Xref-Table
|
|---|
| 377 | ; for converting HideConfig.
|
|---|
| 378 | mov dh, dl
|
|---|
| 379 | mov dl, es:CFG_Partitions
|
|---|
| 380 | sub dl, dh
|
|---|
| 381 | mov dh, NewPartitions ; is actually a counter
|
|---|
| 382 | call PARTSCAN_DefXref ; DL-IPT-Partition, DH-NewPartition
|
|---|
| 383 |
|
|---|
| 384 | ; Get Saved-Flags...
|
|---|
| 385 | mov cl, byte ptr es:[di+LocIPT_Flags] ; Use saved Flags
|
|---|
| 386 |
|
|---|
| 387 | ; ...and Saved-CRC if available...
|
|---|
| 388 | mov ax, wptr es:[di+LocIPT_BootRecordCRC]
|
|---|
| 389 | or ax, ax
|
|---|
| 390 | jz PCCTP_UseNewComputedCRC
|
|---|
| 391 | mov PartCRC, ax ; Use saved IPT-CRC
|
|---|
| 392 | PCCTP_UseNewComputedCRC:
|
|---|
| 393 | ; ...and mark partition in IPT as already found
|
|---|
| 394 | or byte ptr es:[di+LocIPT_Flags], Flags_NowFound
|
|---|
| 395 | ; ...get Serial&Name from IPT-table...
|
|---|
| 396 | mov si, di
|
|---|
| 397 | add si, LocIPT_Serial ; DS:SI - LocIPT-Serial&Name
|
|---|
| 398 | jmp PCCTP_AddToNew
|
|---|
| 399 |
|
|---|
| 400 | ; =================================
|
|---|
| 401 | ; =FAILED= search, not found in IPT
|
|---|
| 402 | ; AH - NoPartName-Flag (!MUST! be merged with Flags)
|
|---|
| 403 | ; DS:SI - Serial&Name of Current Partition (15-Bytes)
|
|---|
| 404 | ; =================================
|
|---|
| 405 | PCCTP_CompareFailed:
|
|---|
| 406 | mov ch, ah
|
|---|
| 407 | ; Default Flags hinzufgen...
|
|---|
| 408 | mov cl, LocIPT_DefaultFlags
|
|---|
| 409 |
|
|---|
| 410 | mov al, PartTypeFlags
|
|---|
| 411 | ; May I auto-add partitions ?
|
|---|
| 412 | test es:CFG_PartitionsDetect, 1
|
|---|
| 413 | jz PCCTP_MayNotAddAny ; add, but non-bootable
|
|---|
| 414 | test al, FileSysFlags_BootAble ; AH kam von SearchFileSysName
|
|---|
| 415 | jnz PCCTP_PerhapsBootAble
|
|---|
| 416 | PCCTP_MayNotAddAny:
|
|---|
| 417 | mov cl, LocIPT_DefaultNonBootFlags
|
|---|
| 418 | PCCTP_PerhapsBootAble:
|
|---|
| 419 |
|
|---|
| 420 | ; On FAT32-partitions, default to P-Flag (which means using M$-hack)
|
|---|
| 421 | ; Anyway, this hack has to be globaly activated by the user manually...
|
|---|
| 422 | cmp PartSystemID, 09h ; Hardcoded: FAT32
|
|---|
| 423 | je PCCTP_NeedsExtMShack
|
|---|
| 424 | cmp PartSystemID, 0Bh
|
|---|
| 425 | je PCCTP_NeedsExtMShack
|
|---|
| 426 | cmp PartSystemID, 0Ch
|
|---|
| 427 | je PCCTP_NeedsExtMShack
|
|---|
| 428 | cmp PartSystemID, 0Eh ; FAT16 above 8 GB
|
|---|
| 429 | jne PCCTP_NoExtMShack
|
|---|
| 430 | ; We only get here, when the SystemID seems to be an M$ "invention"...
|
|---|
| 431 | PCCTP_NeedsExtMShack:
|
|---|
| 432 | or cl, Flags_ExtPartMShack
|
|---|
| 433 | PCCTP_NoExtMShack:
|
|---|
| 434 |
|
|---|
| 435 | ;================================================
|
|---|
| 436 | ; CL - IPT-Partition-Flags, CH - NoPartName-Flag
|
|---|
| 437 | ; DS:SI - PartSerial&Name (15-Bytes)
|
|---|
| 438 | ;================================================
|
|---|
| 439 | PCCTP_AddToNew:
|
|---|
| 440 | mov al, Flags_NoPartName ; Unset NoPartName
|
|---|
| 441 | not al
|
|---|
| 442 | and cl, al
|
|---|
| 443 | or cl, ch ; CL = Both CL and CH merged
|
|---|
| 444 |
|
|---|
| 445 | ; Calculate Pointer to IPT
|
|---|
| 446 | mov di, offset NewPartTable ; ES:DI - NewPartTable
|
|---|
| 447 | movzx ax, es:NewPartitions
|
|---|
| 448 | mov bl, LocIPT_LenOfIPT
|
|---|
| 449 | mul bl
|
|---|
| 450 | add di, ax ; ES:DI - Last+1 Entry of NewPartTable
|
|---|
| 451 |
|
|---|
| 452 | ; Now finally write this partition to our IPT
|
|---|
| 453 | ;=============================================
|
|---|
| 454 | push cx
|
|---|
| 455 | mov cx, 15 ; Copy Serial&Name...
|
|---|
| 456 | rep movsb
|
|---|
| 457 | pop cx
|
|---|
| 458 |
|
|---|
| 459 | lds si, dptr PartPtr ; DS:SI - Cur Partition Entry
|
|---|
| 460 | mov al, bptr es:[CurPartition_Location+4] ; Drive
|
|---|
| 461 | stosb
|
|---|
| 462 | mov al, PartSystemID ; Unhidden SystemID
|
|---|
| 463 | stosb
|
|---|
| 464 | mov al, cl ; Partition-Flags from register...
|
|---|
| 465 | stosb
|
|---|
| 466 | mov ax, PartCRC ; BootRecordCRC...
|
|---|
| 467 | stosw
|
|---|
| 468 | mov al, bptr ds:[si+LocBRPT_BeginHead]
|
|---|
| 469 | stosb
|
|---|
| 470 | mov ax, wptr ds:[si+LocBRPT_BeginSector] ; Cylinder/Sector
|
|---|
| 471 | stosw
|
|---|
| 472 | mov al, bptr es:[CurPartition_Location+5] ; Head of Part-Table
|
|---|
| 473 | stosb
|
|---|
| 474 | mov ax, wptr es:[CurPartition_Location+6] ; Cylinder/Sector
|
|---|
| 475 | stosw
|
|---|
| 476 | mov ax, wptr ds:[si+LocBRPT_RelativeBegin]
|
|---|
| 477 | mov bx, wptr ds:[si+LocBRPT_RelativeBegin+2]
|
|---|
| 478 | mov cx, wptr es:[CurPartition_Location+0] ; +Partition-Absolute
|
|---|
| 479 | mov dx, wptr es:[CurPartition_Location+2] ; sectors
|
|---|
| 480 | add ax, cx
|
|---|
| 481 | adc bx, dx
|
|---|
| 482 | stosw
|
|---|
| 483 | mov ax, bx
|
|---|
| 484 | stosw
|
|---|
| 485 | mov ax, cx ; Absolute sector of partition table
|
|---|
| 486 | stosw
|
|---|
| 487 | mov ax, dx
|
|---|
| 488 | stosw
|
|---|
| 489 | inc es:NewPartitions ; NEW IPT Entry DONE
|
|---|
| 490 |
|
|---|
| 491 | cmp es:NewPartitions, LocIPT_MaxPartitions
|
|---|
| 492 | jbe PCCTP_NotTooManyPartitions
|
|---|
| 493 | mov ax, cs
|
|---|
| 494 | mov ds, ax
|
|---|
| 495 | mov si, offset TXT_TooManyPartitions
|
|---|
| 496 | call MBR_Teletype
|
|---|
| 497 | jmp MBR_HaltSystem
|
|---|
| 498 |
|
|---|
| 499 | PCCTP_NotTooManyPartitions:
|
|---|
| 500 | ; UNHIDE PARTITION, if it was hidden previously
|
|---|
| 501 | mov al, PartSystemID
|
|---|
| 502 | cmp al, 08h ; internally NTFS ?
|
|---|
| 503 | jne PCCTP_NoInternalNTFS
|
|---|
| 504 | dec al
|
|---|
| 505 | PCCTP_NoInternalNTFS:
|
|---|
| 506 | mov bptr ds:[si+LocBRPT_SystemID], al
|
|---|
| 507 |
|
|---|
| 508 | ; Calculate Size of this partition...
|
|---|
| 509 | movzx ax, es:NewPartitions
|
|---|
| 510 | dec ax
|
|---|
| 511 | mov bx, ax
|
|---|
| 512 | shl ax, 1
|
|---|
| 513 | shl bx, 2
|
|---|
| 514 | add ax, bx ; My way [tm] of multiplying with 6
|
|---|
| 515 | mov di, offset PartitionSizeTable
|
|---|
| 516 | add di, ax ; DI - Partition Size-Element
|
|---|
| 517 | mov ax, wptr ds:[si+LocBRPT_AbsoluteLength] ; Sector-Size
|
|---|
| 518 | mov bx, wptr ds:[si+LocBRPT_AbsoluteLength+2]
|
|---|
| 519 | call PART_FillOutSizeElement
|
|---|
| 520 | ret
|
|---|
| 521 | PARTSCAN_CheckThisPartition EndP
|
|---|
| 522 |
|
|---|
| 523 | ; Scans Current Partition for Extended Partitions, if found, AX,BX,CX,DX will
|
|---|
| 524 | ; be set to this location and Carry will be set
|
|---|
| 525 | PARTSCAN_ScanPartitionForExtended Proc Near Uses ds si
|
|---|
| 526 | mov ax, ExecBaseSeg
|
|---|
| 527 | mov ds, ax
|
|---|
| 528 | mov si, ExecBasePtr
|
|---|
| 529 | add si, 446 ; DS:SI - First Partition Entry
|
|---|
| 530 | xor ax, ax
|
|---|
| 531 | PSSPFE_ScanLoop:
|
|---|
| 532 | mov al, ds:[si+LocBRPT_SystemID]
|
|---|
| 533 | cmp al, 5 ; Is Partition EXTENDED ?
|
|---|
| 534 | je PSSPFE_ExtendedPartition
|
|---|
| 535 | cmp al, 0Fh ; Is Partition EXTENDED (M$) ?
|
|---|
| 536 | je PSSPFE_ExtendedPartition
|
|---|
| 537 | jmp PSSPFE_IgnorePartition
|
|---|
| 538 | PSSPFE_ExtendedPartition:
|
|---|
| 539 | mov ax, wptr ds:[si+LocBRPT_RelativeBegin]
|
|---|
| 540 | mov bx, wptr ds:[si+LocBRPT_RelativeBegin+2]
|
|---|
| 541 | add ax, wptr es:[ExtendedAbsPos+0] ; Adjust...
|
|---|
| 542 | adc bx, wptr es:[ExtendedAbsPos+2] ; (Shit Design!)
|
|---|
| 543 | test es:[ExtendedAbsPosSet], 1
|
|---|
| 544 | jnz PSSPFE_ExtendedMainKnown
|
|---|
| 545 | mov wptr es:[ExtendedAbsPos+0], ax
|
|---|
| 546 | mov wptr es:[ExtendedAbsPos+2], bx
|
|---|
| 547 | mov cs:[ExtendedAbsPosSet], 1
|
|---|
| 548 | PSSPFE_ExtendedMainKnown:
|
|---|
| 549 | mov cx, wptr ds:[si+LocBRPT_BeginSector] ; Cylinder/Sector
|
|---|
| 550 | mov dh, bptr ds:[si+LocBRPT_BeginHead] ; Head
|
|---|
| 551 | mov dl, bptr es:[CurPartition_Location+4] ; Drive
|
|---|
| 552 | stc
|
|---|
| 553 | jmp PSSPFE_EndOfSearch
|
|---|
| 554 | PSSPFE_IgnorePartition:
|
|---|
| 555 | add si, LocBRPT_LenOfEntry
|
|---|
| 556 | cmp si, 500+ExecBasePtr
|
|---|
| 557 | jb PSSPFE_ScanLoop
|
|---|
| 558 | clc
|
|---|
| 559 | PSSPFE_EndOfSearch:
|
|---|
| 560 | ret
|
|---|
| 561 | PARTSCAN_ScanPartitionForExtended EndP
|
|---|
| 562 |
|
|---|
| 563 | ; ===================
|
|---|
| 564 | ; X-REFERENCE STUFF -> PartitionXref
|
|---|
| 565 | ; ===================
|
|---|
| 566 |
|
|---|
| 567 | ; The following routines have DS==CS again
|
|---|
| 568 |
|
|---|
| 569 | ; Reset X-Reference
|
|---|
| 570 | PARTSCAN_ResetXref Proc Near Uses ax cx es di
|
|---|
| 571 | push cs
|
|---|
| 572 | pop es
|
|---|
| 573 | mov di, offset PartitionXref ; X-Reference for later syncing
|
|---|
| 574 | mov cx, LocIPT_MaxPartitions
|
|---|
| 575 | mov ax, 0FFFFh ; Fill up with FFh
|
|---|
| 576 | rep stosb
|
|---|
| 577 | mov di, offset NewHidePartTable ; Temporary Hide-Config Table
|
|---|
| 578 | mov cx, 450 ; Size is 900
|
|---|
| 579 | rep stosw ; Fill up with FFFFh
|
|---|
| 580 | mov di, offset NewDriveLetters
|
|---|
| 581 | mov cx, 15 ; Temporary Logical-Drive Letter Table
|
|---|
| 582 | xor ax, ax ; Size is 30
|
|---|
| 583 | rep stosw ; Fill up with 0000h
|
|---|
| 584 | ret
|
|---|
| 585 | PARTSCAN_ResetXref EndP
|
|---|
| 586 |
|
|---|
| 587 | ; In: DL - Partition Number in IPT
|
|---|
| 588 | ; DH - Partition Number in NewPartitionTable
|
|---|
| 589 | ; Destroyed: None
|
|---|
| 590 | PARTSCAN_DefXref Proc Near Uses ax bx cx dx si di
|
|---|
| 591 | movzx bx, dl
|
|---|
| 592 | mov bptr [PartitionXref+bx], dh ; X-Reference
|
|---|
| 593 | ; Copy Hide-Config of IPT partition to new location in new table
|
|---|
| 594 | mov si, offset HidePartitionTable
|
|---|
| 595 | mov di, offset NewHidePartTable
|
|---|
| 596 | mov bl, LocIPT_MaxPartitions
|
|---|
| 597 | mov al, dl
|
|---|
| 598 | mul bl
|
|---|
| 599 | add si, ax
|
|---|
| 600 | mov al, dh
|
|---|
| 601 | mul bl
|
|---|
| 602 | add di, ax
|
|---|
| 603 | mov cx, LocIPT_MaxPartitions
|
|---|
| 604 | rep movsb ; Copy Hide-Config to NewHideTable
|
|---|
| 605 | ; Process Logical-Drive-Letter table as well...
|
|---|
| 606 | movzx bx, dl
|
|---|
| 607 | mov al, bptr [DriveLetters+bx] ; Get Drv-Letter from org. pos
|
|---|
| 608 | movzx bx, dh
|
|---|
| 609 | mov bptr [NewDriveLetters+bx], al ; Put Drv-Letter to new pos
|
|---|
| 610 | ret
|
|---|
| 611 | PARTSCAN_DefXref EndP
|
|---|
| 612 |
|
|---|
| 613 | ; In: DL - Partition Number in previous IPT
|
|---|
| 614 | ; Out: DH - Partition Number in NewPartitionTable
|
|---|
| 615 | ; Destroyed: None
|
|---|
| 616 | PARTSCAN_GetXref Proc Near Uses bx
|
|---|
| 617 | movzx bx, dl
|
|---|
| 618 | mov dh, bptr [PartitionXref+bx] ; X-Reference
|
|---|
| 619 | ret
|
|---|
| 620 | PARTSCAN_GetXref EndP
|
|---|
| 621 |
|
|---|
| 622 | ; This here updates the contents of the Hide-Configuration to the current IPT
|
|---|
| 623 | ; table.
|
|---|
| 624 | PARTSCAN_SyncHideConfigWithXref Proc Near Uses ax bx cx dx si di
|
|---|
| 625 | mov si, offset NewHidePartTable
|
|---|
| 626 | mov di, offset HidePartitionTable
|
|---|
| 627 | mov ch, LocIPT_MaxPartitions
|
|---|
| 628 | PSSHCWX_SyncPartLoop:
|
|---|
| 629 | mov cl, LocIPT_MaxPartitions
|
|---|
| 630 | xor dl, dl ; Partition Lost Counter
|
|---|
| 631 | PSSHCWX_SyncLoop:
|
|---|
| 632 | lodsb ; Get Part-Pointer from Hide-Cfg
|
|---|
| 633 | cmp al, 0FFh
|
|---|
| 634 | je PSSHCWX_SyncEmpty
|
|---|
| 635 | movzx bx, al
|
|---|
| 636 | mov al, [PartitionXref+bx] ; Translate it
|
|---|
| 637 | cmp al, 0FFh
|
|---|
| 638 | je PSSHCWX_PartLost
|
|---|
| 639 | PSSHCWX_SyncEmpty:
|
|---|
| 640 | stosb ; Put translated pointer to new table
|
|---|
| 641 | dec cl
|
|---|
| 642 | jnz PSSHCWX_SyncLoop
|
|---|
| 643 | jmp PSSHCWX_SyncLoopEnd
|
|---|
| 644 | PSSHCWX_PartLost:
|
|---|
| 645 | inc dl ; One partition got lost...
|
|---|
| 646 | dec cl
|
|---|
| 647 | jnz PSSHCWX_SyncLoop
|
|---|
| 648 |
|
|---|
| 649 | PSSHCWX_SyncLoopEnd:
|
|---|
| 650 | or dl, dl
|
|---|
| 651 | jz PSSHCWX_NothingLost
|
|---|
| 652 | mov al, 0FFh
|
|---|
| 653 | PSSHCWX_LostFillLoop:
|
|---|
| 654 | stosb
|
|---|
| 655 | dec cl
|
|---|
| 656 | jnz PSSHCWX_LostFillLoop
|
|---|
| 657 | PSSHCWX_NothingLost:
|
|---|
| 658 | dec ch
|
|---|
| 659 | jnz PSSHCWX_SyncPartLoop
|
|---|
| 660 | ret
|
|---|
| 661 | PARTSCAN_SyncHideConfigWithXref EndP
|
|---|