1 | /* $Id: fileaio.h 96407 2022-08-22 17:43:14Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IPRT - Internal RTFileAio header.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2009-2022 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 IPRT_INCLUDED_INTERNAL_fileaio_h
|
---|
38 | #define IPRT_INCLUDED_INTERNAL_fileaio_h
|
---|
39 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
40 | # pragma once
|
---|
41 | #endif
|
---|
42 |
|
---|
43 | #include <iprt/file.h>
|
---|
44 | #include "internal/magics.h"
|
---|
45 |
|
---|
46 | /*******************************************************************************
|
---|
47 | * Structures and Typedefs *
|
---|
48 | *******************************************************************************/
|
---|
49 | /**
|
---|
50 | * Defined request states.
|
---|
51 | */
|
---|
52 | typedef enum RTFILEAIOREQSTATE
|
---|
53 | {
|
---|
54 | /** Prepared. */
|
---|
55 | RTFILEAIOREQSTATE_PREPARED = 0,
|
---|
56 | /** Submitted. */
|
---|
57 | RTFILEAIOREQSTATE_SUBMITTED,
|
---|
58 | /** Completed. */
|
---|
59 | RTFILEAIOREQSTATE_COMPLETED,
|
---|
60 | /** Omni present 32bit hack. */
|
---|
61 | RTFILEAIOREQSTATE_32BIT_HACK = 0x7fffffff
|
---|
62 | } RTFILEAIOREQSTATE;
|
---|
63 |
|
---|
64 | /*******************************************************************************
|
---|
65 | * Defined Constants And Macros *
|
---|
66 | *******************************************************************************/
|
---|
67 |
|
---|
68 | /** Return true if the specified request is not valid, false otherwise. */
|
---|
69 | #define RTFILEAIOREQ_IS_NOT_VALID(pReq) \
|
---|
70 | (RT_UNLIKELY(!RT_VALID_PTR(pReq) || (pReq->u32Magic != RTFILEAIOREQ_MAGIC)))
|
---|
71 |
|
---|
72 | /** Validates a context handle and returns VERR_INVALID_HANDLE if not valid. */
|
---|
73 | #define RTFILEAIOREQ_VALID_RETURN_RC(pReq, rc) \
|
---|
74 | do { \
|
---|
75 | AssertPtrReturn((pReq), (rc)); \
|
---|
76 | AssertReturn((pReq)->u32Magic == RTFILEAIOREQ_MAGIC, (rc)); \
|
---|
77 | } while (0)
|
---|
78 |
|
---|
79 | /** Validates a context handle and returns VERR_INVALID_HANDLE if not valid. */
|
---|
80 | #define RTFILEAIOREQ_VALID_RETURN(pReq) RTFILEAIOREQ_VALID_RETURN_RC((pReq), VERR_INVALID_HANDLE)
|
---|
81 |
|
---|
82 | /** Validates a context handle and returns (void) if not valid. */
|
---|
83 | #define RTFILEAIOREQ_VALID_RETURN_VOID(pReq) \
|
---|
84 | do { \
|
---|
85 | AssertPtrReturnVoid(pReq); \
|
---|
86 | AssertReturnVoid((pReq)->u32Magic == RTFILEAIOREQ_MAGIC); \
|
---|
87 | } while (0)
|
---|
88 |
|
---|
89 | /** Validates a context handle and returns the specified rc if not valid. */
|
---|
90 | #define RTFILEAIOCTX_VALID_RETURN_RC(pCtx, rc) \
|
---|
91 | do { \
|
---|
92 | AssertPtrReturn((pCtx), (rc)); \
|
---|
93 | AssertReturn((pCtx)->u32Magic == RTFILEAIOCTX_MAGIC, (rc)); \
|
---|
94 | } while (0)
|
---|
95 |
|
---|
96 | /** Validates a context handle and returns VERR_INVALID_HANDLE if not valid. */
|
---|
97 | #define RTFILEAIOCTX_VALID_RETURN(pCtx) RTFILEAIOCTX_VALID_RETURN_RC((pCtx), VERR_INVALID_HANDLE)
|
---|
98 |
|
---|
99 | /** Checks if a request is in the specified state and returns the specified rc if not. */
|
---|
100 | #define RTFILEAIOREQ_STATE_RETURN_RC(pReq, State, rc) \
|
---|
101 | do { \
|
---|
102 | if (RT_UNLIKELY(pReq->enmState != RTFILEAIOREQSTATE_##State)) \
|
---|
103 | return rc; \
|
---|
104 | } while (0)
|
---|
105 |
|
---|
106 | /** Checks if a request is not in the specified state and returns the specified rc if it is. */
|
---|
107 | #define RTFILEAIOREQ_NOT_STATE_RETURN_RC(pReq, State, rc) \
|
---|
108 | do { \
|
---|
109 | if (RT_UNLIKELY(pReq->enmState == RTFILEAIOREQSTATE_##State)) \
|
---|
110 | return rc; \
|
---|
111 | } while (0)
|
---|
112 |
|
---|
113 | /** Checks if a request in the given states and sserts if not. */
|
---|
114 | #define RTFIELAIOREQ_ASSERT_STATE(pReq, State) \
|
---|
115 | do { \
|
---|
116 | AssertPtr((pReq)); \
|
---|
117 | Assert((pReq)->u32Magic == RTFILEAIOREQ_MAGIC); \
|
---|
118 | Assert((pReq)->enmState == RTFILEAIOREQSTATE_##State); \
|
---|
119 | } while (0)
|
---|
120 |
|
---|
121 | /** Sets the request into a specific state. */
|
---|
122 | #define RTFILEAIOREQ_SET_STATE(pReq, State) \
|
---|
123 | do { \
|
---|
124 | pReq->enmState = RTFILEAIOREQSTATE_##State; \
|
---|
125 | } while (0)
|
---|
126 |
|
---|
127 |
|
---|
128 | RT_C_DECLS_BEGIN
|
---|
129 |
|
---|
130 | RT_C_DECLS_END
|
---|
131 |
|
---|
132 | #endif /* !IPRT_INCLUDED_INTERNAL_fileaio_h */
|
---|
133 |
|
---|