| 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 / LVM
|
|---|
| 20 | ;---------------------------------------------------------------------------
|
|---|
| 21 |
|
|---|
| 22 | LVM_InitCRCTable Proc Near Uses
|
|---|
| 23 | ; Initializes our LVM-CRC-Table
|
|---|
| 24 | xor cl, cl
|
|---|
| 25 | mov di, offset LVM_CRCTable
|
|---|
| 26 | LVM_ICRCT_Loop:
|
|---|
| 27 | movzx ax, cl
|
|---|
| 28 | xor dx, dx ; DX:AX - CRC-Value
|
|---|
| 29 | mov ch, 8
|
|---|
| 30 | LVM_ICRCT_Loop2:
|
|---|
| 31 | shr dx, 1
|
|---|
| 32 | rcr ax, 1 ; Shift value 1 to the right
|
|---|
| 33 | jnc LVM_ICRCT_NoXOR
|
|---|
| 34 | xor dx, 0EDB8h
|
|---|
| 35 | xor ax, 8320h
|
|---|
| 36 | LVM_ICRCT_NoXOR:
|
|---|
| 37 | dec ch
|
|---|
| 38 | jnz LVM_ICRCT_Loop2
|
|---|
| 39 | mov wptr [di+0], ax
|
|---|
| 40 | mov wptr [di+2], dx
|
|---|
| 41 | add di, 4
|
|---|
| 42 | add cl, 1
|
|---|
| 43 | jnc LVM_ICRCT_Loop
|
|---|
| 44 | ret
|
|---|
| 45 | LVM_InitCRCTable EndP
|
|---|
| 46 |
|
|---|
| 47 | ; Calculates an LVM-Sector CRC of a given sector
|
|---|
| 48 | ; In: DS:SI - Points to Sector...
|
|---|
| 49 | ; Out: DX:AX - LVM CRC
|
|---|
| 50 | ; Destroyed: None
|
|---|
| 51 | LVM_GetSectorCRC Proc Near Uses bx cx
|
|---|
| 52 | push wptr [si+LocLVM_CRC]
|
|---|
| 53 | push wptr [si+LocLVM_CRC+2]
|
|---|
| 54 | push si
|
|---|
| 55 | mov wptr [si+LocLVM_CRC], 0
|
|---|
| 56 | mov wptr [si+LocLVM_CRC+2], 0
|
|---|
| 57 | mov ax, -1
|
|---|
| 58 | mov dx, -1
|
|---|
| 59 | mov cx, 512
|
|---|
| 60 | LVM_GSCRC_Loop:
|
|---|
| 61 | xor bh, bh
|
|---|
| 62 | mov bl, al ; Save last byte to BL
|
|---|
| 63 | mov al, ah
|
|---|
| 64 | mov ah, dl
|
|---|
| 65 | mov dl, dh
|
|---|
| 66 | xor dh, dh ; SHR DX:AX, 8
|
|---|
| 67 | xor bl, [si]
|
|---|
| 68 | inc si ; XOR last byte with [data]
|
|---|
| 69 | shl bx, 1
|
|---|
| 70 | shl bx, 1
|
|---|
| 71 | xor ax, wptr [LVM_CRCTable+bx+0]
|
|---|
| 72 | xor dx, wptr [LVM_CRCTable+bx+2] ; XOR with CRC-Table
|
|---|
| 73 | loop LVM_GSCRC_Loop
|
|---|
| 74 | pop si
|
|---|
| 75 | pop wptr [si+LocLVM_CRC+2]
|
|---|
| 76 | pop wptr [si+LocLVM_CRC]
|
|---|
| 77 | ret
|
|---|
| 78 | LVM_GetSectorCRC EndP
|
|---|
| 79 |
|
|---|
| 80 | ; Checks DS:[SI], if a valid LVM Signature is found (sets carry in that case)
|
|---|
| 81 | ; This does not check for valid LVM CRC (which also needs to be done)
|
|---|
| 82 | ; In: DS:SI - Sector that needs to get checked...
|
|---|
| 83 | ; Out: Carry set, if valid LVM signature found
|
|---|
| 84 | ; Destroyed: None
|
|---|
| 85 | LVM_CheckSectorSignature Proc Near Uses
|
|---|
| 86 | test [CFG_IgnoreLVM], 1 ; We are supposed to ignore LVM, so
|
|---|
| 87 | jnz LVMCSS_InvalidSignature ; any sector is bad!
|
|---|
| 88 | cmp wptr [si+LocLVM_SignatureStart], 5202h
|
|---|
| 89 | jne LVMCSS_InvalidSignature
|
|---|
| 90 | cmp wptr [si+LocLVM_SignatureStart+2], 'BM'
|
|---|
| 91 | jne LVMCSS_InvalidSignature
|
|---|
| 92 | cmp wptr [si+LocLVM_SignatureStart+4], 'MP'
|
|---|
| 93 | jne LVMCSS_InvalidSignature
|
|---|
| 94 | cmp wptr [si+LocLVM_SignatureStart+6], 'DF'
|
|---|
| 95 | jne LVMCSS_InvalidSignature
|
|---|
| 96 | stc
|
|---|
| 97 | ret
|
|---|
| 98 | LVMCSS_InvalidSignature:
|
|---|
| 99 | clc
|
|---|
| 100 | ret
|
|---|
| 101 | LVM_CheckSectorSignature EndP
|
|---|
| 102 |
|
|---|
| 103 | ; Checks Sector for a valid LVM CRC is encountered
|
|---|
| 104 | ; First one should check for a valid signature and call this later.
|
|---|
| 105 | ; In: DS:SI - Sector that needs to get checked...
|
|---|
| 106 | ; Out: Carry set, if LVM CRC valid
|
|---|
| 107 | ; Destroyed: None
|
|---|
| 108 | LVM_CheckSectorCRC Proc Near Uses ax dx
|
|---|
| 109 | call LVM_GetSectorCRC
|
|---|
| 110 | cmp ax, wptr [si+LocLVM_CRC]
|
|---|
| 111 | jne LVMCSCRC_BadCRC
|
|---|
| 112 | cmp dx, wptr [si+LocLVM_CRC+2]
|
|---|
| 113 | jne LVMCSCRC_BadCRC
|
|---|
| 114 | stc
|
|---|
| 115 | ret
|
|---|
| 116 | LVMCSCRC_BadCRC:
|
|---|
| 117 | clc
|
|---|
| 118 | ret
|
|---|
| 119 | LVM_CheckSectorCRC EndP
|
|---|
| 120 |
|
|---|
| 121 | ; Updates Sector with valid LVM CRC
|
|---|
| 122 | ; This one doesn't check, if it's really an LVM sector, so check before!
|
|---|
| 123 | ; In: DS:SI - Sector that needs to get checked...
|
|---|
| 124 | ; Out: None, CRC updated
|
|---|
| 125 | ; Destroyed: None
|
|---|
| 126 | LVM_UpdateSectorCRC Proc Near Uses ax dx
|
|---|
| 127 | call LVM_GetSectorCRC
|
|---|
| 128 | mov wptr [si+LocLVM_CRC], ax
|
|---|
| 129 | mov wptr [si+LocLVM_CRC+2], dx
|
|---|
| 130 | ret
|
|---|
| 131 | LVM_UpdateSectorCRC EndP
|
|---|
| 132 |
|
|---|
| 133 | ; Searches for a partition in LVM Information Sector and sets SI to point to
|
|---|
| 134 | ; the LVM-entry. It will also set CARRY then.
|
|---|
| 135 | ; In: DX:AX - LBA starting sector of partition to be searched
|
|---|
| 136 | ; DS:SI - Valid (previously checked) LVM-Information-Sector
|
|---|
| 137 | ; Out: Carry set, if partition found
|
|---|
| 138 | ; DS:SI - points to LVM information entry
|
|---|
| 139 | ; Destroyed: None
|
|---|
| 140 | LVM_SearchForPartition Proc Near Uses cx
|
|---|
| 141 | cmp bptr [si+LocLVM_SignatureStart], LocLVM_SignatureByte0
|
|---|
| 142 | jne LVMSFP_NotFound ; Quick Check, if LVM sector there
|
|---|
| 143 | add si, LocLVM_StartOfEntries
|
|---|
| 144 | mov cl, LocLVM_MaxEntries
|
|---|
| 145 | LVMSFP_Loop:
|
|---|
| 146 | cmp ax, [si+LocLVM_PartitionStart]
|
|---|
| 147 | jne LVMSFP_NextEntry
|
|---|
| 148 | cmp dx, [si+LocLVM_PartitionStart+2]
|
|---|
| 149 | je LVMSFP_FoundIt
|
|---|
| 150 | LVMSFP_NextEntry:
|
|---|
| 151 | add si, LocLVM_LenOfEntry
|
|---|
| 152 | dec cl
|
|---|
| 153 | jnz LVMSFP_Loop
|
|---|
| 154 | LVMSFP_NotFound:
|
|---|
| 155 | clc
|
|---|
| 156 | ret
|
|---|
| 157 | LVMSFP_FoundIt:
|
|---|
| 158 | stc
|
|---|
| 159 | ret
|
|---|
| 160 | LVM_SearchForPartition EndP
|
|---|
| 161 |
|
|---|
| 162 | ; Removes a given drive-letter from the whole LVM information sector
|
|---|
| 163 | ; In: CH - drive-letter (ascii)
|
|---|
| 164 | ; DS:SI - LVM-Information-Sector
|
|---|
| 165 | ; Out: LVM-Information-Sector updated (including LVM CRC)
|
|---|
| 166 | ; Destroyed: None
|
|---|
| 167 | LVM_RemoveVolLetterFromSector Proc Near Uses cx
|
|---|
| 168 | cmp bptr [si+LocLVM_SignatureStart], LocLVM_SignatureByte0
|
|---|
| 169 | jne LVMRVLFS_Done ; Quick Check, if LVM sector there
|
|---|
| 170 | push si
|
|---|
| 171 | add si, LocLVM_StartOfEntries
|
|---|
| 172 | mov cl, LocLVM_MaxEntries
|
|---|
| 173 | LVMRVLFS_Loop:
|
|---|
| 174 | cmp ch, [si+LocLVM_VolumeLetter]
|
|---|
| 175 | jne LVMRVLFS_NextEntry
|
|---|
| 176 | ; Reset drive-letter, if matched
|
|---|
| 177 | mov bptr [si+LocLVM_VolumeLetter], 0
|
|---|
| 178 | LVMRVLFS_NextEntry:
|
|---|
| 179 | add si, LocLVM_LenOfEntry
|
|---|
| 180 | dec cl
|
|---|
| 181 | jnz LVMRVLFS_Loop
|
|---|
| 182 | pop si
|
|---|
| 183 | call LVM_UpdateSectorCRC
|
|---|
| 184 | LVMRVLFS_Done:
|
|---|
| 185 | ret
|
|---|
| 186 | LVM_RemoveVolLetterFromSector EndP
|
|---|
| 187 |
|
|---|
| 188 | ; Reassigns LVM volume driveletter
|
|---|
| 189 | ; Will remove the drive-letter from any volume that got it currently
|
|---|
| 190 | ; and finally change the drive-letter of the given partition
|
|---|
| 191 | ; In: AL - drive-letter
|
|---|
| 192 | ; DS:SI - points to partition, that needs that driveletter
|
|---|
| 193 | ; Out: None
|
|---|
| 194 | ; Destroyed: AX
|
|---|
| 195 | LVM_DoLetterReassignment Proc Near Uses bx cx dx si di
|
|---|
| 196 | mov di, si ; Save SI in DI (Partition-pointer)
|
|---|
| 197 | mov ch, al ; and AL in CH (drive-letter)
|
|---|
| 198 | xor bx, bx
|
|---|
| 199 | mov cl, CFG_Partitions
|
|---|
| 200 | or cl, cl
|
|---|
| 201 | jz LVMDLR_SkipRemove
|
|---|
| 202 | LVMDLR_RemoveLoop:
|
|---|
| 203 | cmp bptr [PartitionVolumeLetters+bx], ch
|
|---|
| 204 | jne LVMDLR_NextPartition
|
|---|
| 205 | ; One volume that has our wanted drive-letter, so remove it!
|
|---|
| 206 | mov dl, bl
|
|---|
| 207 | call PART_GetPartitionPointer ; DL - partition -> SI
|
|---|
| 208 | ; Now set CurPartition_Location for the DriveIO-functions to work
|
|---|
| 209 | mov ax, wptr [si+LocIPT_AbsolutePartTable]
|
|---|
| 210 | mov wptr [CurPartition_Location+0], ax
|
|---|
| 211 | mov ax, wptr [si+LocIPT_AbsolutePartTable+2]
|
|---|
| 212 | mov wptr [CurPartition_Location+2], ax
|
|---|
| 213 | mov ax, wptr [si+LocIPT_LocationPartTable+1]
|
|---|
| 214 | mov wptr [CurPartition_Location+6], ax
|
|---|
| 215 | mov ah, bptr [si+LocIPT_LocationPartTable+0]
|
|---|
| 216 | mov al, [si+LocIPT_Drive]
|
|---|
| 217 | mov wptr [CurPartition_Location+4], ax
|
|---|
| 218 | call DriveIO_LoadLVMSector ; SI points now to LVM-Sector
|
|---|
| 219 | call LVM_RemoveVolLetterFromSector
|
|---|
| 220 | IFDEF ReleaseCode
|
|---|
| 221 | call DriveIO_SaveLVMSector ; Save sector
|
|---|
| 222 | ENDIF
|
|---|
| 223 | LVMDLR_NextPartition:
|
|---|
| 224 | inc bx
|
|---|
| 225 | dec cl
|
|---|
| 226 | jnz LVMDLR_RemoveLoop
|
|---|
| 227 | LVMDLR_SkipRemove:
|
|---|
| 228 | ; Set CurPartition_Location information of destination partition
|
|---|
| 229 | mov ax, wptr [di+LocIPT_AbsolutePartTable]
|
|---|
| 230 | mov wptr [CurPartition_Location+0], ax
|
|---|
| 231 | mov ax, wptr [di+LocIPT_AbsolutePartTable+2]
|
|---|
| 232 | mov wptr [CurPartition_Location+2], ax
|
|---|
| 233 | mov ah, bptr [di+LocIPT_LocationPartTable+0]
|
|---|
| 234 | mov al, [di+LocIPT_Drive]
|
|---|
| 235 | mov wptr [CurPartition_Location+4], ax
|
|---|
| 236 | mov ax, wptr [di+LocIPT_LocationPartTable+1]
|
|---|
| 237 | mov wptr [CurPartition_Location+6], ax
|
|---|
| 238 | call DriveIO_LoadLVMSector ; SI points now to LVM-Sector
|
|---|
| 239 | mov ax, wptr [di+LocIPT_AbsoluteBegin]
|
|---|
| 240 | mov dx, wptr [di+LocIPT_AbsoluteBegin+2]
|
|---|
| 241 | mov di, si ; Save SI in DI
|
|---|
| 242 | call LVM_SearchForPartition
|
|---|
| 243 | jnc LVMDLR_DestPartNotFound
|
|---|
| 244 | ; Set new volume letter
|
|---|
| 245 | mov bptr [si+LocLVM_VolumeLetter], ch
|
|---|
| 246 | mov si, di ; SI - LVM Sector again
|
|---|
| 247 | call LVM_UpdateSectorCRC ; Update LVM-CRC now
|
|---|
| 248 | IFDEF ReleaseCode
|
|---|
| 249 | call DriveIO_SaveLVMSector ; Save sector
|
|---|
| 250 | ENDIF
|
|---|
| 251 | LVMDLR_DestPartNotFound:
|
|---|
| 252 | ; This here is done for safety, because we misuse CurPartition_Location
|
|---|
| 253 | xor ax, ax
|
|---|
| 254 | mov di, offset CurPartition_Location
|
|---|
| 255 | mov cx, 4
|
|---|
| 256 | rep stosw ; NUL out CurPartition_Location
|
|---|
| 257 | ret
|
|---|
| 258 | LVM_DoLetterReassignment EndP
|
|---|