[64241] | 1 | /* $Id: DrvHostBase-linux.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
|
---|
| 2 | /** @file
|
---|
| 3 | * DrvHostBase - Host base drive access driver, Linux specifics.
|
---|
| 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[98103] | 7 | * Copyright (C) 2006-2023 Oracle and/or its affiliates.
|
---|
[64241] | 8 | *
|
---|
[96407] | 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
|
---|
[64241] | 26 | */
|
---|
[76382] | 27 |
|
---|
[76396] | 28 |
|
---|
[76382] | 29 | /*********************************************************************************************************************************
|
---|
| 30 | * Header Files *
|
---|
| 31 | *********************************************************************************************************************************/
|
---|
[64241] | 32 | #define LOG_GROUP LOG_GROUP_DRV_HOST_BASE
|
---|
| 33 | #include <sys/ioctl.h>
|
---|
| 34 | #include <sys/fcntl.h>
|
---|
| 35 | #include <errno.h>
|
---|
| 36 | #include <linux/version.h>
|
---|
| 37 | /* All the following crap is apparently not necessary anymore since Linux
|
---|
| 38 | * version 2.6.29. */
|
---|
| 39 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 29)
|
---|
| 40 | /* This is a hack to work around conflicts between these linux kernel headers
|
---|
| 41 | * and the GLIBC tcpip headers. They have different declarations of the 4
|
---|
| 42 | * standard byte order functions. */
|
---|
| 43 | # define _LINUX_BYTEORDER_GENERIC_H
|
---|
| 44 | /* This is another hack for not bothering with C++ unfriendly byteswap macros. */
|
---|
| 45 | /* Those macros that are needed are defined in the header below. */
|
---|
| 46 | # include "swab.h"
|
---|
| 47 | #endif
|
---|
[64246] | 48 | #include <linux/fd.h>
|
---|
[64241] | 49 | #include <linux/cdrom.h>
|
---|
| 50 | #include <limits.h>
|
---|
| 51 |
|
---|
| 52 | #include <iprt/mem.h>
|
---|
| 53 | #include <iprt/file.h>
|
---|
[76382] | 54 | #include <iprt/string.h>
|
---|
[76404] | 55 | #include <VBox/err.h>
|
---|
[64241] | 56 | #include <VBox/scsi.h>
|
---|
| 57 |
|
---|
[65078] | 58 |
|
---|
[64316] | 59 | /**
|
---|
[76382] | 60 | * Host backend specific data (needed by DrvHostBase.h).
|
---|
[64316] | 61 | */
|
---|
| 62 | typedef struct DRVHOSTBASEOS
|
---|
| 63 | {
|
---|
| 64 | /** The filehandle of the device. */
|
---|
| 65 | RTFILE hFileDevice;
|
---|
| 66 | /** Double buffer required for ioctl with the Linux kernel as long as we use
|
---|
| 67 | * remap_pfn_range() instead of vm_insert_page(). */
|
---|
| 68 | uint8_t *pbDoubleBuffer;
|
---|
| 69 | /** Previous disk inserted indicator for the media polling on floppy drives. */
|
---|
| 70 | bool fPrevDiskIn;
|
---|
| 71 | } DRVHOSTBASEOS;
|
---|
| 72 | /** Pointer to the host backend specific data. */
|
---|
| 73 | typedef DRVHOSTBASEOS *PDRVHOSBASEOS;
|
---|
| 74 | AssertCompile(sizeof(DRVHOSTBASEOS) <= 64);
|
---|
| 75 |
|
---|
| 76 | #define DRVHOSTBASE_OS_INT_DECLARED
|
---|
[64241] | 77 | #include "DrvHostBase.h"
|
---|
| 78 |
|
---|
[76382] | 79 |
|
---|
| 80 | /*********************************************************************************************************************************
|
---|
| 81 | * Defined Constants And Macros *
|
---|
| 82 | *********************************************************************************************************************************/
|
---|
| 83 | /** Maximum buffer size supported by the kernel interface. */
|
---|
| 84 | #define LNX_SCSI_MAX_BUFFER_SIZE (100 * _1K)
|
---|
| 85 |
|
---|
| 86 |
|
---|
| 87 |
|
---|
| 88 |
|
---|
| 89 |
|
---|
[64241] | 90 | DECLHIDDEN(int) drvHostBaseScsiCmdOs(PDRVHOSTBASE pThis, const uint8_t *pbCmd, size_t cbCmd, PDMMEDIATXDIR enmTxDir,
|
---|
| 91 | void *pvBuf, uint32_t *pcbBuf, uint8_t *pbSense, size_t cbSense, uint32_t cTimeoutMillies)
|
---|
| 92 | {
|
---|
| 93 | /*
|
---|
| 94 | * Minimal input validation.
|
---|
| 95 | */
|
---|
| 96 | Assert(enmTxDir == PDMMEDIATXDIR_NONE || enmTxDir == PDMMEDIATXDIR_FROM_DEVICE || enmTxDir == PDMMEDIATXDIR_TO_DEVICE);
|
---|
| 97 | Assert(!pvBuf || pcbBuf);
|
---|
| 98 | Assert(pvBuf || enmTxDir == PDMMEDIATXDIR_NONE);
|
---|
[64244] | 99 | Assert(pbSense || !cbSense); RT_NOREF(cbSense);
|
---|
[64241] | 100 | AssertPtr(pbCmd);
|
---|
| 101 | Assert(cbCmd <= 16 && cbCmd >= 1);
|
---|
| 102 |
|
---|
[64316] | 103 | /* Allocate the temporary buffer lazily. */
|
---|
| 104 | if(RT_UNLIKELY(!pThis->Os.pbDoubleBuffer))
|
---|
| 105 | {
|
---|
[65078] | 106 | pThis->Os.pbDoubleBuffer = (uint8_t *)RTMemAlloc(LNX_SCSI_MAX_BUFFER_SIZE);
|
---|
[64316] | 107 | if (!pThis->Os.pbDoubleBuffer)
|
---|
| 108 | return VERR_NO_MEMORY;
|
---|
| 109 | }
|
---|
| 110 |
|
---|
[64241] | 111 | int rc = VERR_GENERAL_FAILURE;
|
---|
| 112 | int direction;
|
---|
| 113 | struct cdrom_generic_command cgc;
|
---|
| 114 |
|
---|
| 115 | switch (enmTxDir)
|
---|
| 116 | {
|
---|
| 117 | case PDMMEDIATXDIR_NONE:
|
---|
| 118 | Assert(*pcbBuf == 0);
|
---|
| 119 | direction = CGC_DATA_NONE;
|
---|
| 120 | break;
|
---|
| 121 | case PDMMEDIATXDIR_FROM_DEVICE:
|
---|
| 122 | Assert(*pcbBuf != 0);
|
---|
[65078] | 123 | Assert(*pcbBuf <= LNX_SCSI_MAX_BUFFER_SIZE);
|
---|
[64241] | 124 | /* Make sure that the buffer is clear for commands reading
|
---|
| 125 | * data. The actually received data may be shorter than what
|
---|
| 126 | * we expect, and due to the unreliable feedback about how much
|
---|
| 127 | * data the ioctl actually transferred, it's impossible to
|
---|
| 128 | * prevent that. Returning previous buffer contents may cause
|
---|
| 129 | * security problems inside the guest OS, if users can issue
|
---|
| 130 | * commands to the CDROM device. */
|
---|
[64316] | 131 | memset(pThis->Os.pbDoubleBuffer, '\0', *pcbBuf);
|
---|
[64241] | 132 | direction = CGC_DATA_READ;
|
---|
| 133 | break;
|
---|
| 134 | case PDMMEDIATXDIR_TO_DEVICE:
|
---|
| 135 | Assert(*pcbBuf != 0);
|
---|
[65078] | 136 | Assert(*pcbBuf <= LNX_SCSI_MAX_BUFFER_SIZE);
|
---|
[64316] | 137 | memcpy(pThis->Os.pbDoubleBuffer, pvBuf, *pcbBuf);
|
---|
[64241] | 138 | direction = CGC_DATA_WRITE;
|
---|
| 139 | break;
|
---|
| 140 | default:
|
---|
| 141 | AssertMsgFailed(("enmTxDir invalid!\n"));
|
---|
| 142 | direction = CGC_DATA_NONE;
|
---|
| 143 | }
|
---|
| 144 | memset(&cgc, '\0', sizeof(cgc));
|
---|
| 145 | memcpy(cgc.cmd, pbCmd, RT_MIN(CDROM_PACKET_SIZE, cbCmd));
|
---|
[64316] | 146 | cgc.buffer = (unsigned char *)pThis->Os.pbDoubleBuffer;
|
---|
[64241] | 147 | cgc.buflen = *pcbBuf;
|
---|
| 148 | cgc.stat = 0;
|
---|
| 149 | Assert(cbSense >= sizeof(struct request_sense));
|
---|
| 150 | cgc.sense = (struct request_sense *)pbSense;
|
---|
| 151 | cgc.data_direction = direction;
|
---|
| 152 | cgc.quiet = false;
|
---|
| 153 | cgc.timeout = cTimeoutMillies;
|
---|
[64316] | 154 | rc = ioctl(RTFileToNative(pThis->Os.hFileDevice), CDROM_SEND_PACKET, &cgc);
|
---|
[64241] | 155 | if (rc < 0)
|
---|
| 156 | {
|
---|
| 157 | if (errno == EBUSY)
|
---|
| 158 | rc = VERR_PDM_MEDIA_LOCKED;
|
---|
| 159 | else if (errno == ENOSYS)
|
---|
| 160 | rc = VERR_NOT_SUPPORTED;
|
---|
| 161 | else
|
---|
| 162 | {
|
---|
| 163 | rc = RTErrConvertFromErrno(errno);
|
---|
| 164 | if (rc == VERR_ACCESS_DENIED && cgc.sense->sense_key == SCSI_SENSE_NONE)
|
---|
| 165 | cgc.sense->sense_key = SCSI_SENSE_ILLEGAL_REQUEST;
|
---|
| 166 | Log2(("%s: error status %d, rc=%Rrc\n", __FUNCTION__, cgc.stat, rc));
|
---|
| 167 | }
|
---|
| 168 | }
|
---|
| 169 | switch (enmTxDir)
|
---|
| 170 | {
|
---|
| 171 | case PDMMEDIATXDIR_FROM_DEVICE:
|
---|
[64316] | 172 | memcpy(pvBuf, pThis->Os.pbDoubleBuffer, *pcbBuf);
|
---|
[64241] | 173 | break;
|
---|
| 174 | default:
|
---|
| 175 | ;
|
---|
| 176 | }
|
---|
| 177 | Log2(("%s: after ioctl: cgc.buflen=%d txlen=%d\n", __FUNCTION__, cgc.buflen, *pcbBuf));
|
---|
| 178 | /* The value of cgc.buflen does not reliably reflect the actual amount
|
---|
| 179 | * of data transferred (for packet commands with little data transfer
|
---|
| 180 | * it's 0). So just assume that everything worked ok. */
|
---|
| 181 |
|
---|
| 182 | return rc;
|
---|
| 183 | }
|
---|
| 184 |
|
---|
[65078] | 185 |
|
---|
| 186 | DECLHIDDEN(size_t) drvHostBaseScsiCmdGetBufLimitOs(PDRVHOSTBASE pThis)
|
---|
| 187 | {
|
---|
| 188 | RT_NOREF(pThis);
|
---|
| 189 |
|
---|
| 190 | return LNX_SCSI_MAX_BUFFER_SIZE;
|
---|
| 191 | }
|
---|
| 192 |
|
---|
| 193 |
|
---|
[64246] | 194 | DECLHIDDEN(int) drvHostBaseGetMediaSizeOs(PDRVHOSTBASE pThis, uint64_t *pcb)
|
---|
| 195 | {
|
---|
| 196 | int rc = VERR_INVALID_STATE;
|
---|
| 197 |
|
---|
| 198 | if (PDMMEDIATYPE_IS_FLOPPY(pThis->enmType))
|
---|
| 199 | {
|
---|
[64316] | 200 | rc = ioctl(RTFileToNative(pThis->Os.hFileDevice), FDFLUSH);
|
---|
[64246] | 201 | if (rc)
|
---|
| 202 | {
|
---|
| 203 | rc = RTErrConvertFromErrno (errno);
|
---|
| 204 | Log(("DrvHostFloppy: FDFLUSH ioctl(%s) failed, errno=%d rc=%Rrc\n", pThis->pszDevice, errno, rc));
|
---|
| 205 | return rc;
|
---|
| 206 | }
|
---|
| 207 |
|
---|
| 208 | floppy_drive_struct DrvStat;
|
---|
[64316] | 209 | rc = ioctl(RTFileToNative(pThis->Os.hFileDevice), FDGETDRVSTAT, &DrvStat);
|
---|
[64246] | 210 | if (rc)
|
---|
| 211 | {
|
---|
| 212 | rc = RTErrConvertFromErrno(errno);
|
---|
| 213 | Log(("DrvHostFloppy: FDGETDRVSTAT ioctl(%s) failed, errno=%d rc=%Rrc\n", pThis->pszDevice, errno, rc));
|
---|
| 214 | return rc;
|
---|
| 215 | }
|
---|
| 216 | pThis->fReadOnly = !(DrvStat.flags & FD_DISK_WRITABLE);
|
---|
[64316] | 217 | rc = RTFileSeek(pThis->Os.hFileDevice, 0, RTFILE_SEEK_END, pcb);
|
---|
[64246] | 218 | }
|
---|
| 219 | else if (pThis->enmType == PDMMEDIATYPE_CDROM || pThis->enmType == PDMMEDIATYPE_DVD)
|
---|
| 220 | {
|
---|
| 221 | /* Clear the media-changed-since-last-call-thingy just to be on the safe side. */
|
---|
[64316] | 222 | ioctl(RTFileToNative(pThis->Os.hFileDevice), CDROM_MEDIA_CHANGED, CDSL_CURRENT);
|
---|
| 223 | rc = RTFileSeek(pThis->Os.hFileDevice, 0, RTFILE_SEEK_END, pcb);
|
---|
[64246] | 224 | }
|
---|
| 225 |
|
---|
| 226 | return rc;
|
---|
| 227 | }
|
---|
| 228 |
|
---|
[64251] | 229 |
|
---|
| 230 | DECLHIDDEN(int) drvHostBaseReadOs(PDRVHOSTBASE pThis, uint64_t off, void *pvBuf, size_t cbRead)
|
---|
| 231 | {
|
---|
[64316] | 232 | return RTFileReadAt(pThis->Os.hFileDevice, off, pvBuf, cbRead, NULL);
|
---|
[64251] | 233 | }
|
---|
| 234 |
|
---|
| 235 |
|
---|
| 236 | DECLHIDDEN(int) drvHostBaseWriteOs(PDRVHOSTBASE pThis, uint64_t off, const void *pvBuf, size_t cbWrite)
|
---|
| 237 | {
|
---|
[64316] | 238 | return RTFileWriteAt(pThis->Os.hFileDevice, off, pvBuf, cbWrite, NULL);
|
---|
[64251] | 239 | }
|
---|
| 240 |
|
---|
| 241 |
|
---|
| 242 | DECLHIDDEN(int) drvHostBaseFlushOs(PDRVHOSTBASE pThis)
|
---|
| 243 | {
|
---|
[64316] | 244 | return RTFileFlush(pThis->Os.hFileDevice);
|
---|
[64251] | 245 | }
|
---|
| 246 |
|
---|
[64252] | 247 |
|
---|
[64278] | 248 | DECLHIDDEN(int) drvHostBaseDoLockOs(PDRVHOSTBASE pThis, bool fLock)
|
---|
| 249 | {
|
---|
[64316] | 250 | int rc = ioctl(RTFileToNative(pThis->Os.hFileDevice), CDROM_LOCKDOOR, (int)fLock);
|
---|
[64278] | 251 | if (rc < 0)
|
---|
| 252 | {
|
---|
| 253 | if (errno == EBUSY)
|
---|
| 254 | rc = VERR_ACCESS_DENIED;
|
---|
| 255 | else if (errno == EDRIVE_CANT_DO_THIS)
|
---|
| 256 | rc = VERR_NOT_SUPPORTED;
|
---|
| 257 | else
|
---|
| 258 | rc = RTErrConvertFromErrno(errno);
|
---|
| 259 | }
|
---|
| 260 |
|
---|
| 261 | return rc;
|
---|
| 262 | }
|
---|
| 263 |
|
---|
| 264 |
|
---|
| 265 | DECLHIDDEN(int) drvHostBaseEjectOs(PDRVHOSTBASE pThis)
|
---|
| 266 | {
|
---|
[64316] | 267 | int rc = ioctl(RTFileToNative(pThis->Os.hFileDevice), CDROMEJECT, 0);
|
---|
[64278] | 268 | if (rc < 0)
|
---|
| 269 | {
|
---|
| 270 | if (errno == EBUSY)
|
---|
| 271 | rc = VERR_PDM_MEDIA_LOCKED;
|
---|
| 272 | else if (errno == ENOSYS)
|
---|
| 273 | rc = VERR_NOT_SUPPORTED;
|
---|
| 274 | else
|
---|
| 275 | rc = RTErrConvertFromErrno(errno);
|
---|
| 276 | }
|
---|
| 277 |
|
---|
| 278 | return rc;
|
---|
| 279 | }
|
---|
| 280 |
|
---|
| 281 |
|
---|
| 282 | DECLHIDDEN(int) drvHostBaseQueryMediaStatusOs(PDRVHOSTBASE pThis, bool *pfMediaChanged, bool *pfMediaPresent)
|
---|
| 283 | {
|
---|
[64316] | 284 | int rc = VINF_SUCCESS;
|
---|
[64278] | 285 |
|
---|
[64316] | 286 | if (PDMMEDIATYPE_IS_FLOPPY(pThis->enmType))
|
---|
| 287 | {
|
---|
| 288 | floppy_drive_struct DrvStat;
|
---|
| 289 | int rcLnx = ioctl(RTFileToNative(pThis->Os.hFileDevice), FDPOLLDRVSTAT, &DrvStat);
|
---|
| 290 | if (!rcLnx)
|
---|
| 291 | {
|
---|
| 292 | bool fDiskIn = !(DrvStat.flags & (FD_VERIFY | FD_DISK_NEWCHANGE));
|
---|
| 293 | *pfMediaPresent = fDiskIn;
|
---|
| 294 |
|
---|
| 295 | if (fDiskIn != pThis->Os.fPrevDiskIn)
|
---|
| 296 | *pfMediaChanged = true;
|
---|
| 297 |
|
---|
| 298 | pThis->Os.fPrevDiskIn = fDiskIn;
|
---|
| 299 | }
|
---|
| 300 | else
|
---|
| 301 | rc = RTErrConvertFromErrno(errno);
|
---|
| 302 | }
|
---|
| 303 | else
|
---|
| 304 | {
|
---|
| 305 | *pfMediaPresent = ioctl(RTFileToNative(pThis->Os.hFileDevice), CDROM_DRIVE_STATUS, CDSL_CURRENT) == CDS_DISC_OK;
|
---|
| 306 | *pfMediaChanged = false;
|
---|
| 307 | if (pThis->fMediaPresent != *pfMediaPresent)
|
---|
| 308 | *pfMediaChanged = ioctl(RTFileToNative(pThis->Os.hFileDevice), CDROM_MEDIA_CHANGED, CDSL_CURRENT) == 1;
|
---|
| 309 | }
|
---|
| 310 |
|
---|
| 311 | return rc;
|
---|
[64278] | 312 | }
|
---|
| 313 |
|
---|
| 314 |
|
---|
[64316] | 315 | DECLHIDDEN(void) drvHostBaseInitOs(PDRVHOSTBASE pThis)
|
---|
[64252] | 316 | {
|
---|
[64316] | 317 | pThis->Os.hFileDevice = NIL_RTFILE;
|
---|
| 318 | pThis->Os.pbDoubleBuffer = NULL;
|
---|
| 319 | pThis->Os.fPrevDiskIn = false;
|
---|
[64252] | 320 | }
|
---|
| 321 |
|
---|
| 322 |
|
---|
[64316] | 323 | DECLHIDDEN(int) drvHostBaseOpenOs(PDRVHOSTBASE pThis, bool fReadOnly)
|
---|
| 324 | {
|
---|
| 325 | uint32_t fFlags = (fReadOnly ? RTFILE_O_READ : RTFILE_O_READWRITE) | RTFILE_O_OPEN | RTFILE_O_DENY_NONE | RTFILE_O_NON_BLOCK;
|
---|
| 326 | return RTFileOpen(&pThis->Os.hFileDevice, pThis->pszDevice, fFlags);
|
---|
| 327 | }
|
---|
| 328 |
|
---|
| 329 |
|
---|
| 330 | DECLHIDDEN(int) drvHostBaseMediaRefreshOs(PDRVHOSTBASE pThis)
|
---|
| 331 | {
|
---|
| 332 | /*
|
---|
| 333 | * Need to re-open the device because it will kill off any cached data
|
---|
| 334 | * that Linux for some peculiar reason thinks should survive a media change.
|
---|
| 335 | */
|
---|
| 336 | if (pThis->Os.hFileDevice != NIL_RTFILE)
|
---|
| 337 | {
|
---|
| 338 | RTFileClose(pThis->Os.hFileDevice);
|
---|
| 339 | pThis->Os.hFileDevice = NIL_RTFILE;
|
---|
| 340 | }
|
---|
| 341 | int rc = drvHostBaseOpenOs(pThis, pThis->fReadOnlyConfig);
|
---|
| 342 | if (RT_FAILURE(rc))
|
---|
| 343 | {
|
---|
| 344 | if (!pThis->fReadOnlyConfig)
|
---|
| 345 | {
|
---|
| 346 | LogFlow(("%s-%d: drvHostBaseMediaRefreshOs: '%s' - retry readonly (%Rrc)\n",
|
---|
| 347 | pThis->pDrvIns->pReg->szName, pThis->pDrvIns->iInstance, pThis->pszDevice, rc));
|
---|
| 348 | rc = drvHostBaseOpenOs(pThis, true);
|
---|
| 349 | }
|
---|
| 350 | if (RT_FAILURE(rc))
|
---|
| 351 | {
|
---|
| 352 | LogFlow(("%s-%d: failed to open device '%s', rc=%Rrc\n",
|
---|
| 353 | pThis->pDrvIns->pReg->szName, pThis->pDrvIns->iInstance, pThis->pszDevice, rc));
|
---|
| 354 | return rc;
|
---|
| 355 | }
|
---|
| 356 | pThis->fReadOnly = true;
|
---|
| 357 | }
|
---|
| 358 | else
|
---|
| 359 | pThis->fReadOnly = pThis->fReadOnlyConfig;
|
---|
| 360 |
|
---|
| 361 | return rc;
|
---|
| 362 | }
|
---|
| 363 |
|
---|
| 364 |
|
---|
| 365 | DECLHIDDEN(bool) drvHostBaseIsMediaPollingRequiredOs(PDRVHOSTBASE pThis)
|
---|
| 366 | {
|
---|
| 367 | RT_NOREF(pThis);
|
---|
| 368 | return true; /* On Linux we always use media polling. */
|
---|
| 369 | }
|
---|
| 370 |
|
---|
| 371 |
|
---|
[64252] | 372 | DECLHIDDEN(void) drvHostBaseDestructOs(PDRVHOSTBASE pThis)
|
---|
| 373 | {
|
---|
[64316] | 374 | /*
|
---|
| 375 | * Unlock the drive if we've locked it or we're in passthru mode.
|
---|
| 376 | */
|
---|
| 377 | if ( pThis->fLocked
|
---|
| 378 | && pThis->Os.hFileDevice != NIL_RTFILE
|
---|
| 379 | && pThis->pfnDoLock)
|
---|
[64252] | 380 | {
|
---|
[64316] | 381 | int rc = pThis->pfnDoLock(pThis, false);
|
---|
| 382 | if (RT_SUCCESS(rc))
|
---|
| 383 | pThis->fLocked = false;
|
---|
[64252] | 384 | }
|
---|
| 385 |
|
---|
[64316] | 386 | if (pThis->Os.pbDoubleBuffer)
|
---|
[64252] | 387 | {
|
---|
[64316] | 388 | RTMemFree(pThis->Os.pbDoubleBuffer);
|
---|
| 389 | pThis->Os.pbDoubleBuffer = NULL;
|
---|
[64252] | 390 | }
|
---|
| 391 |
|
---|
[64316] | 392 | if (pThis->Os.hFileDevice != NIL_RTFILE)
|
---|
[64252] | 393 | {
|
---|
[64316] | 394 | int rc = RTFileClose(pThis->Os.hFileDevice);
|
---|
[64252] | 395 | AssertRC(rc);
|
---|
[64316] | 396 | pThis->Os.hFileDevice = NIL_RTFILE;
|
---|
[64252] | 397 | }
|
---|
| 398 | }
|
---|
| 399 |
|
---|