VirtualBox

source: vbox/trunk/include/iprt/sg.h@ 28271

Last change on this file since 28271 was 28117, checked in by vboxsync, 15 years ago

Runtime/Sg: Add advanced compare method

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.9 KB
Line 
1/** @file
2 * IPRT - S/G buffer handling.
3 */
4
5/*
6 * Copyright (C) 2010 Sun Microsystems, Inc.
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 *
16 * The contents of this file may alternatively be used under the terms
17 * of the Common Development and Distribution License Version 1.0
18 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
19 * VirtualBox OSE distribution, in which case the provisions of the
20 * CDDL are applicable instead of those of the GPL.
21 *
22 * You may elect to license modified versions of this file under the
23 * terms and conditions of either the GPL or the CDDL or both.
24 *
25 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
26 * Clara, CA 95054 USA or visit http://www.sun.com if you need
27 * additional information or have any questions.
28 */
29
30#ifndef ___iprt_sg_h
31#define ___iprt_sg_h
32
33#include <iprt/types.h>
34
35RT_C_DECLS_BEGIN
36
37/**
38 * A S/G entry.
39 */
40typedef struct RTSGSEG
41{
42 /** Pointer to the segment buffer. */
43 void *pvSeg;
44 /** Size of the segment buffer. */
45 size_t cbSeg;
46} RTSGSEG;
47/** Pointer to a S/G entry. */
48typedef RTSGSEG *PRTSGSEG;
49/** Pointer to a const S/G entry. */
50typedef const RTSGSEG *PCRTSGSEG;
51/** Pointer to a S/G entry pointer. */
52typedef PRTSGSEG *PPRTSGSEG;
53
54/**
55 * A S/G buffer.
56 *
57 * The members should be treated as private.
58 */
59typedef struct RTSGBUF
60{
61 /** Pointer to the scatter/gather array. */
62 PCRTSGSEG pcaSeg;
63 /** Number of segments. */
64 unsigned cSeg;
65 /** Current segment we are in. */
66 unsigned idxSeg;
67 /** Pointer to the current segment start. */
68 void *pvSegCurr;
69 /** Number of bytes left in the current buffer. */
70 size_t cbSegLeft;
71} RTSGBUF;
72/** Pointer to a S/G entry. */
73typedef RTSGBUF *PRTSGBUF;
74/** Pointer to a const S/G entry. */
75typedef const RTSGBUF *PCRTSGBUF;
76/** Pointer to a S/G entry pointer. */
77typedef PRTSGBUF *PPRTSGBUF;
78
79/**
80 * Initialize a S/G buffer structure.
81 *
82 * @returns nothing.
83 * @param pSgBuf Pointer to the S/G buffer to initialize.
84 * @param pcaSeg Pointer to the start of the segment array.
85 * @param cSeg Number of segments in the array.
86 */
87RTDECL(void) RTSgBufInit(PRTSGBUF pSgBuf, PCRTSGSEG pcaSeg, unsigned cSeg);
88
89/**
90 * Resets the internal buffer position of the S/G buffer to the beginning.
91 *
92 * @returns nothing.
93 * @param pSgBuf The S/G buffer to reset.
94 */
95RTDECL(void) RTSgBufReset(PRTSGBUF pSgBuf);
96
97/**
98 * Clones a given S/G buffer.
99 *
100 * @returns nothing.
101 * @param pSgBufNew The new S/G buffer to clone to.
102 * @param pSgBufOld The source S/G buffer to clone from.
103 *
104 * @note This is only a shallow copy. Both S/G buffers will point to the
105 * same segment array.
106 */
107RTDECL(void) RTSgBufClone(PRTSGBUF pSgBufNew, PCRTSGBUF pSgBufOld);
108
109/**
110 * Copy data between two S/G buffers.
111 *
112 * @returns The number of bytes copied.
113 * @param pSgBufDst The destination S/G buffer.
114 * @param pSgBufSrc The source S/G buffer.
115 * @param cbCopy Number of bytes to copy.
116 *
117 * @note This operation advances the internal buffer pointer of both S/G buffers.
118 */
119RTDECL(size_t) RTSgBufCopy(PRTSGBUF pSgBufDst, PRTSGBUF pSgBufSrc, size_t cbCopy);
120
121/**
122 * Compares the content of two S/G buffers.
123 *
124 * @returns Whatever memcmp returns.
125 * @param pSgBuf1 First S/G buffer.
126 * @param pSgBuf2 Second S/G buffer.
127 * @param cbCmp How many bytes to compare.
128 *
129 * @note This operation doesn't change the internal position of the S/G buffers.
130 */
131RTDECL(int) RTSgBufCmp(PCRTSGBUF pSgBuf1, PCRTSGBUF pSgBuf2, size_t cbCmp);
132
133/**
134 * Compares the content of two S/G buffers - advanced version.
135 *
136 * @returns Whatever memcmp returns.
137 * @param pSgBuf1 First S/G buffer.
138 * @param pSgBuf2 Second S/G buffer.
139 * @param cbCmp How many bytes to compare.
140 * @param pcbOff Where to store the offset of the first different byte
141 * in the buffer starting from the position of the S/G
142 * buffer before this call.
143 * @param fAdvance Flag whether the internal buffer position should be advanced.
144 *
145 */
146RTDECL(int) RTSgBufCmpEx(PRTSGBUF pSgBuf1, PRTSGBUF pSgBuf2, size_t cbCmp,
147 size_t *pcbOff, bool fAdvance);
148
149/**
150 * Fills an S/G buf with a constant byte.
151 *
152 * @returns The number of actually filled bytes.
153 * Can be less than than cbSet if the end of the S/G buffer was reached.
154 * @param pSgBuf The S/G buffer.
155 * @param ubFill The byte to fill the buffer with.
156 * @param cbSet How many bytes to set.
157 *
158 * @note This operation advances the internal buffer pointer of the S/G buffer.
159 */
160RTDECL(size_t) RTSgBufSet(PRTSGBUF pSgBuf, uint8_t ubFill, size_t cbSet);
161
162/**
163 * Copies data from an S/G buffer into a given non scattered buffer.
164 *
165 * @returns Number of bytes copied.
166 * @param pSgBuf The S/G buffer to copy from.
167 * @param pvBuf Buffer to copy the data into.
168 * @param cbCopy How many bytes to copy.
169 *
170 * @note This operation advances the internal buffer pointer of the S/G buffer.
171 */
172RTDECL(size_t) RTSgBufCopyToBuf(PRTSGBUF pSgBuf, void *pvBuf, size_t cbCopy);
173
174/**
175 * Copies data from a non scattered buffer into an S/G buffer.
176 *
177 * @returns Number of bytes copied.
178 * @param pSgBuf The S/G buffer to copy to.
179 * @param pvBuf Buffer to copy the data into.
180 * @param cbCopy How many bytes to copy.
181 *
182 * @note This operation advances the internal buffer pointer of the S/G buffer.
183 */
184RTDECL(size_t) RTSgBufCopyFromBuf(PRTSGBUF pSgBuf, void *pvBuf, size_t cbCopy);
185
186/**
187 * Advances the internal buffer pointer.
188 *
189 * @returns Number of bytes the pointer was moved forward.
190 * @param pSgBuf The S/G buffer.
191 * @param cbAdvance Number of bytes to move forward.
192 */
193RTDECL(size_t) RTSgBufAdvance(PRTSGBUF pSgBuf, size_t cbAdvance);
194
195/**
196 * Constructs a new segment array starting from the current position
197 * and describing the given number of bytes.
198 *
199 * @returns Number of bytes the array describes.
200 * @param pSgBuf The S/G buffer.
201 * @param paSeg The unitialized segment array.
202 * @param pcSeg The number of segments the given array has.
203 * This will hold the actual number of entries needed upon return.
204 * @param cbData Number of bytes the new array should describe.
205 *
206 * @note This operation advances the internal buffer pointer of the S/G buffer.
207 */
208RTDECL(size_t) RTSgBufSegArrayCreate(PRTSGBUF pSgBuf, PRTSGSEG paSeg, unsigned *pcSeg, size_t cbData);
209
210RT_C_DECLS_END
211
212/** @} */
213
214#endif
215
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