VirtualBox

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

Last change on this file since 76507 was 76507, checked in by vboxsync, 5 years ago

/include: scm --fix-header-guards. bugref:9344

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

© 2023 Oracle
ContactPrivacy policyTerms of Use