VirtualBox

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

Last change on this file since 56690 was 56292, checked in by vboxsync, 10 years ago

Devices: Updated (C) year.

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