Changeset 65107 in vbox
- Timestamp:
- Jan 4, 2017 2:06:14 PM (8 years ago)
- svn:sync-xref-src-repo-rev:
- 112610
- File:
-
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/VBox/scsiinline.h
r65106 r65107 1 1 /* $Id$ */ 2 2 /** @file 3 * Virtual SCSI driver: Inline helpers3 * VirtualBox: SCSI inline helpers used by devices, drivers, etc. 4 4 */ 5 5 … … 15 15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. 16 16 */ 17 #ifndef ___V SCSIInline_h18 #define ___V SCSIInline_h17 #ifndef ___VBox_scsiinline_h 18 #define ___VBox_scsiinline_h 19 19 20 20 #include <iprt/stdint.h> 21 21 22 DECLINLINE(void) vscsiH2BEU16(uint8_t *pbBuf, uint16_t val) 23 { 24 pbBuf[0] = val >> 8; 25 pbBuf[1] = val; 26 } 27 28 29 DECLINLINE(void) vscsiH2BEU24(uint8_t *pbBuf, uint32_t val) 30 { 31 pbBuf[0] = val >> 16; 32 pbBuf[1] = val >> 8; 33 pbBuf[2] = val; 34 } 35 36 37 DECLINLINE(void) vscsiH2BEU32(uint8_t *pbBuf, uint32_t val) 38 { 39 pbBuf[0] = val >> 24; 40 pbBuf[1] = val >> 16; 41 pbBuf[2] = val >> 8; 42 pbBuf[3] = val; 43 } 44 45 DECLINLINE(void) vscsiH2BEU64(uint8_t *pbBuf, uint64_t val) 46 { 47 pbBuf[0] = val >> 56; 48 pbBuf[1] = val >> 48; 49 pbBuf[2] = val >> 40; 50 pbBuf[3] = val >> 32; 51 pbBuf[4] = val >> 24; 52 pbBuf[5] = val >> 16; 53 pbBuf[6] = val >> 8; 54 pbBuf[7] = val; 55 } 56 57 DECLINLINE(uint16_t) vscsiBE2HU16(const uint8_t *pbBuf) 22 /** @defgroup grp_scsi_inline The SCSI inline helpers 23 * @{ 24 */ 25 26 27 /** 28 * Converts a given 16bit value to big endian and stores it in the given buffer. 29 * 30 * @returns nothing. 31 * @param pbBuf The buffer to store the value into. 32 * @param u16Val The value to store. 33 */ 34 DECLINLINE(void) scsiH2BE_U16(uint8_t *pbBuf, uint16_t u16Val) 35 { 36 pbBuf[0] = u16Val >> 8; 37 pbBuf[1] = u16Val; 38 } 39 40 41 /** 42 * Converts a given 24bit value to big endian and stores it in the given buffer. 43 * 44 * @returns nothing. 45 * @param pbBuf The buffer to store the value into. 46 * @param u32Val The value to store. 47 */ 48 DECLINLINE(void) scsiH2BE_U24(uint8_t *pbBuf, uint32_t u32Val) 49 { 50 pbBuf[0] = u32Val >> 16; 51 pbBuf[1] = u32Val >> 8; 52 pbBuf[2] = u32Val; 53 } 54 55 56 /** 57 * Converts a given 32bit value to big endian and stores it in the given buffer. 58 * 59 * @returns nothing. 60 * @param pbBuf The buffer to store the value into. 61 * @param u32Val The value to store. 62 */ 63 DECLINLINE(void) scsiH2BE_U32(uint8_t *pbBuf, uint32_t u32Val) 64 { 65 pbBuf[0] = u32Val >> 24; 66 pbBuf[1] = u32Val >> 16; 67 pbBuf[2] = u32Val >> 8; 68 pbBuf[3] = u32Val; 69 } 70 71 72 /** 73 * Converts a given 64bit value to big endian and stores it in the given buffer. 74 * 75 * @returns nothing. 76 * @param pbBuf The buffer to store the value into. 77 * @param u64Val The value to store. 78 */ 79 DECLINLINE(void) scsiH2BE_U64(uint8_t *pbBuf, uint64_t u64Val) 80 { 81 pbBuf[0] = u64Val >> 56; 82 pbBuf[1] = u64Val >> 48; 83 pbBuf[2] = u64Val >> 40; 84 pbBuf[3] = u64Val >> 32; 85 pbBuf[4] = u64Val >> 24; 86 pbBuf[5] = u64Val >> 16; 87 pbBuf[6] = u64Val >> 8; 88 pbBuf[7] = u64Val; 89 } 90 91 /** 92 * Returns a 16bit value read from the given buffer converted to host endianess. 93 * 94 * @returns The converted 16bit value. 95 * @param pbBuf The buffer to read the value from. 96 */ 97 DECLINLINE(uint16_t) scsiBE2H_U16(const uint8_t *pbBuf) 58 98 { 59 99 return (pbBuf[0] << 8) | pbBuf[1]; … … 61 101 62 102 63 DECLINLINE(uint32_t) vscsiBE2HU24(const uint8_t *pbBuf) 103 /** 104 * Returns a 24bit value read from the given buffer converted to host endianess. 105 * 106 * @returns The converted 24bit value as a 32bit unsigned integer. 107 * @param pbBuf The buffer to read the value from. 108 */ 109 DECLINLINE(uint32_t) scsiBE2H_U24(const uint8_t *pbBuf) 64 110 { 65 111 return (pbBuf[0] << 16) | (pbBuf[1] << 8) | pbBuf[2]; … … 67 113 68 114 69 DECLINLINE(uint32_t) vscsiBE2HU32(const uint8_t *pbBuf) 115 /** 116 * Returns a 32bit value read from the given buffer converted to host endianess. 117 * 118 * @returns The converted 32bit value. 119 * @param pbBuf The buffer to read the value from. 120 */ 121 DECLINLINE(uint32_t) scsiBE2H_U32(const uint8_t *pbBuf) 70 122 { 71 123 return (pbBuf[0] << 24) | (pbBuf[1] << 16) | (pbBuf[2] << 8) | pbBuf[3]; 72 124 } 73 125 74 DECLINLINE(uint64_t) vscsiBE2HU64(const uint8_t *pbBuf) 126 127 /** 128 * Returns a 64bit value read from the given buffer converted to host endianess. 129 * 130 * @returns The converted 64bit value. 131 * @param pbBuf The buffer to read the value from. 132 */ 133 DECLINLINE(uint64_t) scsiBE2H_U64(const uint8_t *pbBuf) 75 134 { 76 135 return ((uint64_t)pbBuf[0] << 56) … … 84 143 } 85 144 86 DECLINLINE(void) vscsiPadStr(int8_t *pbDst, const char *pbSrc, uint32_t cbSize) 145 146 /** 147 * Converts the given LBA number to the MSF (Minutes:Seconds:Frames) format 148 * and stores it in the given buffer. 149 * 150 * @returns nothing. 151 * @param pbBuf The buffer to store the value into. 152 * @param iLBA The LBA to convert. 153 */ 154 DECLINLINE(void) scsiLBA2MSF(uint8_t *pbBuf, uint32_t iLBA) 155 { 156 iLBA += 150; 157 pbBuf[0] = (iLBA / 75) / 60; 158 pbBuf[1] = (iLBA / 75) % 60; 159 pbBuf[2] = iLBA % 75; 160 } 161 162 163 /** 164 * Converts a MSF formatted address value read from the given buffer 165 * to an LBA number. 166 * 167 * @returns The LBA number. 168 * @param pbBuf The buffer to read the MSF formatted address 169 * from. 170 */ 171 DECLINLINE(uint32_t) scsiMSF2LBA(const uint8_t *pbBuf) 172 { 173 return (pbBuf[0] * 60 + pbBuf[1]) * 75 + pbBuf[2]; 174 } 175 176 177 /** 178 * Copies a given string to the given destination padding all unused space 179 * in the destination with spaces. 180 * 181 * @returns nothing. 182 * @param pDst Where to store the string padded with spaces. 183 * @param pbSrc The string to copy. 184 * @param cbSize Size of the destination buffer. 185 */ 186 DECLINLINE(void) scsiPadStr(uint8_t *pbDst, const char *pbSrc, uint32_t cbSize) 87 187 { 88 188 for (uint32_t i = 0; i < cbSize; i++) … … 95 195 } 96 196 97 #endif /* ___VSCSIInline_h */ 98 197 198 /** 199 * Copies a given string to the given destination padding all unused space 200 * in the destination with spaces. 201 * 202 * @returns nothing. 203 * @param pDst Where to store the string padded with spaces. 204 * @param pbSrc The string to copy. 205 * @param cbSize Size of the destination buffer. 206 */ 207 DECLINLINE(void) scsiPadStrS(int8_t *pbDst, const char *pbSrc, uint32_t cbSize) 208 { 209 for (uint32_t i = 0; i < cbSize; i++) 210 { 211 if (*pbSrc) 212 pbDst[i] = *pbSrc++; 213 else 214 pbDst[i] = ' '; 215 } 216 } 217 218 /** @} */ 219 220 #endif /* ___VBox_scsiinline_h */ 221
Note:
See TracChangeset
for help on using the changeset viewer.