VirtualBox

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

Last change on this file since 61541 was 57358, checked in by vboxsync, 9 years ago

*: scm cleanup run.

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