VirtualBox

source: vbox/trunk/include/VBox/scsiinline.h@ 68813

Last change on this file since 68813 was 68669, checked in by vboxsync, 7 years ago

include file build fixes (kmk -C include)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.8 KB
Line 
1/* $Id: scsiinline.h 68669 2017-09-06 00:32:34Z vboxsync $ */
2/** @file
3 * VirtualBox: SCSI inline helpers used by devices, drivers, etc.
4 */
5
6/*
7 * Copyright (C) 2006-2016 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18#ifndef ___VBox_scsiinline_h
19#define ___VBox_scsiinline_h
20
21#include <iprt/stdint.h>
22
23/** @defgroup grp_scsi_inline The SCSI inline helpers
24 * @{
25 */
26
27
28/**
29 * Converts a given 16bit value to big endian and stores it in the given buffer.
30 *
31 * @returns nothing.
32 * @param pbBuf The buffer to store the value into.
33 * @param u16Val The value to store.
34 */
35DECLINLINE(void) scsiH2BE_U16(uint8_t *pbBuf, uint16_t u16Val)
36{
37 pbBuf[0] = u16Val >> 8;
38 pbBuf[1] = u16Val;
39}
40
41
42/**
43 * Converts a given 24bit value to big endian and stores it in the given buffer.
44 *
45 * @returns nothing.
46 * @param pbBuf The buffer to store the value into.
47 * @param u32Val The value to store.
48 */
49DECLINLINE(void) scsiH2BE_U24(uint8_t *pbBuf, uint32_t u32Val)
50{
51 pbBuf[0] = u32Val >> 16;
52 pbBuf[1] = u32Val >> 8;
53 pbBuf[2] = u32Val;
54}
55
56
57/**
58 * Converts a given 32bit value to big endian and stores it in the given buffer.
59 *
60 * @returns nothing.
61 * @param pbBuf The buffer to store the value into.
62 * @param u32Val The value to store.
63 */
64DECLINLINE(void) scsiH2BE_U32(uint8_t *pbBuf, uint32_t u32Val)
65{
66 pbBuf[0] = u32Val >> 24;
67 pbBuf[1] = u32Val >> 16;
68 pbBuf[2] = u32Val >> 8;
69 pbBuf[3] = u32Val;
70}
71
72
73/**
74 * Converts a given 64bit value to big endian and stores it in the given buffer.
75 *
76 * @returns nothing.
77 * @param pbBuf The buffer to store the value into.
78 * @param u64Val The value to store.
79 */
80DECLINLINE(void) scsiH2BE_U64(uint8_t *pbBuf, uint64_t u64Val)
81{
82 pbBuf[0] = u64Val >> 56;
83 pbBuf[1] = u64Val >> 48;
84 pbBuf[2] = u64Val >> 40;
85 pbBuf[3] = u64Val >> 32;
86 pbBuf[4] = u64Val >> 24;
87 pbBuf[5] = u64Val >> 16;
88 pbBuf[6] = u64Val >> 8;
89 pbBuf[7] = u64Val;
90}
91
92/**
93 * Returns a 16bit value read from the given buffer converted to host endianess.
94 *
95 * @returns The converted 16bit value.
96 * @param pbBuf The buffer to read the value from.
97 */
98DECLINLINE(uint16_t) scsiBE2H_U16(const uint8_t *pbBuf)
99{
100 return (pbBuf[0] << 8) | pbBuf[1];
101}
102
103
104/**
105 * Returns a 24bit value read from the given buffer converted to host endianess.
106 *
107 * @returns The converted 24bit value as a 32bit unsigned integer.
108 * @param pbBuf The buffer to read the value from.
109 */
110DECLINLINE(uint32_t) scsiBE2H_U24(const uint8_t *pbBuf)
111{
112 return (pbBuf[0] << 16) | (pbBuf[1] << 8) | pbBuf[2];
113}
114
115
116/**
117 * Returns a 32bit value read from the given buffer converted to host endianess.
118 *
119 * @returns The converted 32bit value.
120 * @param pbBuf The buffer to read the value from.
121 */
122DECLINLINE(uint32_t) scsiBE2H_U32(const uint8_t *pbBuf)
123{
124 return (pbBuf[0] << 24) | (pbBuf[1] << 16) | (pbBuf[2] << 8) | pbBuf[3];
125}
126
127
128/**
129 * Returns a 64bit value read from the given buffer converted to host endianess.
130 *
131 * @returns The converted 64bit value.
132 * @param pbBuf The buffer to read the value from.
133 */
134DECLINLINE(uint64_t) scsiBE2H_U64(const uint8_t *pbBuf)
135{
136 return ((uint64_t)pbBuf[0] << 56)
137 | ((uint64_t)pbBuf[1] << 48)
138 | ((uint64_t)pbBuf[2] << 40)
139 | ((uint64_t)pbBuf[3] << 32)
140 | ((uint64_t)pbBuf[4] << 24)
141 | ((uint64_t)pbBuf[5] << 16)
142 | ((uint64_t)pbBuf[6] << 8)
143 | (uint64_t)pbBuf[7];
144}
145
146
147/**
148 * Converts the given LBA number to the MSF (Minutes:Seconds:Frames) format
149 * and stores it in the given buffer.
150 *
151 * @returns nothing.
152 * @param pbBuf The buffer to store the value into.
153 * @param iLBA The LBA to convert.
154 */
155DECLINLINE(void) scsiLBA2MSF(uint8_t *pbBuf, uint32_t iLBA)
156{
157 iLBA += 150;
158 pbBuf[0] = (iLBA / 75) / 60;
159 pbBuf[1] = (iLBA / 75) % 60;
160 pbBuf[2] = iLBA % 75;
161}
162
163
164/**
165 * Converts a MSF formatted address value read from the given buffer
166 * to an LBA number.
167 *
168 * @returns The LBA number.
169 * @param pbBuf The buffer to read the MSF formatted address
170 * from.
171 */
172DECLINLINE(uint32_t) scsiMSF2LBA(const uint8_t *pbBuf)
173{
174 return (pbBuf[0] * 60 + pbBuf[1]) * 75 + pbBuf[2];
175}
176
177
178/**
179 * Copies a given string to the given destination padding all unused space
180 * in the destination with spaces.
181 *
182 * @returns nothing.
183 * @param pbDst Where to store the string padded with spaces.
184 * @param pbSrc The string to copy.
185 * @param cbSize Size of the destination buffer.
186 */
187DECLINLINE(void) scsiPadStr(uint8_t *pbDst, const char *pbSrc, uint32_t cbSize)
188{
189 uint32_t i;
190 for (i = 0; i < cbSize; i++)
191 {
192 if (*pbSrc)
193 pbDst[i] = *pbSrc++;
194 else
195 pbDst[i] = ' ';
196 }
197}
198
199
200/**
201 * Copies a given string to the given destination padding all unused space
202 * in the destination with spaces.
203 *
204 * @returns nothing.
205 * @param pbDst Where to store the string padded with spaces.
206 * @param pbSrc The string to copy.
207 * @param cbSize Size of the destination buffer.
208 */
209DECLINLINE(void) scsiPadStrS(int8_t *pbDst, const char *pbSrc, uint32_t cbSize)
210{
211 uint32_t i;
212 for (i = 0; i < cbSize; i++)
213 {
214 if (*pbSrc)
215 pbDst[i] = *pbSrc++;
216 else
217 pbDst[i] = ' ';
218 }
219}
220
221/** @} */
222
223#endif
224
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette