VirtualBox

source: vbox/trunk/src/VBox/Devices/Storage/VSCSI/VSCSIVpdPagePool.cpp@ 98110

Last change on this file since 98110 was 98103, checked in by vboxsync, 2 years ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.1 KB
Line 
1/* $Id: VSCSIVpdPagePool.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * Virtual SCSI driver: VPD page pool
4 */
5
6/*
7 * Copyright (C) 2011-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 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28
29/*********************************************************************************************************************************
30* Header Files *
31*********************************************************************************************************************************/
32#define LOG_GROUP LOG_GROUP_VSCSI
33#include <VBox/log.h>
34#include <VBox/err.h>
35#include <iprt/mem.h>
36#include <iprt/assert.h>
37
38#include "VSCSIInternal.h"
39
40
41/*********************************************************************************************************************************
42* Structures and Typedefs *
43*********************************************************************************************************************************/
44
45/**
46 * A VSCSI VPD page.
47 */
48typedef struct VSCSIVPDPAGE
49{
50 /** List node. */
51 RTLISTNODE NodePages;
52 /** Page size. */
53 size_t cbPage;
54 /** Page data - variable size. */
55 uint8_t abPage[1];
56} VSCSIVPDPAGE;
57/** Pointer to a VPD page. */
58typedef VSCSIVPDPAGE *PVSCSIVPDPAGE;
59
60
61/*********************************************************************************************************************************
62* Internal Functions *
63*********************************************************************************************************************************/
64
65int vscsiVpdPagePoolInit(PVSCSIVPDPOOL pVScsiVpdPool)
66{
67 RTListInit(&pVScsiVpdPool->ListPages);
68 return VINF_SUCCESS;
69}
70
71
72void vscsiVpdPagePoolDestroy(PVSCSIVPDPOOL pVScsiVpdPool)
73{
74 PVSCSIVPDPAGE pIt, pItNext;
75
76 RTListForEachSafe(&pVScsiVpdPool->ListPages, pIt, pItNext, VSCSIVPDPAGE, NodePages)
77 {
78 RTListNodeRemove(&pIt->NodePages);
79 RTMemFree(pIt);
80 }
81}
82
83
84int vscsiVpdPagePoolAllocNewPage(PVSCSIVPDPOOL pVScsiVpdPool, uint8_t uPage, size_t cbPage, uint8_t **ppbPage)
85{
86 int rc = VINF_SUCCESS;
87 PVSCSIVPDPAGE pPage;
88
89 /* Check that the page doesn't exist already. */
90 RTListForEach(&pVScsiVpdPool->ListPages, pPage, VSCSIVPDPAGE, NodePages)
91 {
92 if (pPage->abPage[1] == uPage)
93 return VERR_ALREADY_EXISTS;
94 }
95
96 pPage = (PVSCSIVPDPAGE)RTMemAllocZ(RT_UOFFSETOF_DYN(VSCSIVPDPAGE, abPage[cbPage]));
97 if (pPage)
98 {
99 pPage->cbPage = cbPage;
100 pPage->abPage[1] = uPage;
101 RTListAppend(&pVScsiVpdPool->ListPages, &pPage->NodePages);
102 *ppbPage = &pPage->abPage[0];
103 }
104 else
105 rc = VERR_NO_MEMORY;
106
107 return rc;
108}
109
110
111int vscsiVpdPagePoolQueryPage(PVSCSIVPDPOOL pVScsiVpdPool, PVSCSIREQINT pVScsiReq, uint8_t uPage)
112{
113 PVSCSIVPDPAGE pPage;
114
115 /* Check that the page doesn't exist already. */
116 RTListForEach(&pVScsiVpdPool->ListPages, pPage, VSCSIVPDPAGE, NodePages)
117 {
118 if (pPage->abPage[1] == uPage)
119 {
120 vscsiReqSetXferSize(pVScsiReq, pPage->cbPage);
121 RTSgBufCopyFromBuf(&pVScsiReq->SgBuf, &pPage->abPage[0], pPage->cbPage);
122 return VINF_SUCCESS;
123 }
124 }
125
126 return VERR_NOT_FOUND;
127}
128
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