VirtualBox

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

Last change on this file since 100791 was 99739, checked in by vboxsync, 19 months ago

*: doxygen corrections (mostly about removing @returns from functions returning void).

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