VirtualBox

source: vbox/trunk/src/VBox/Devices/Storage/DrvHostFloppy.cpp@ 64249

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

Windows build fix

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.4 KB
Line 
1/* $Id: DrvHostFloppy.cpp 64249 2016-10-13 13:16:45Z vboxsync $ */
2/** @file
3 *
4 * VBox storage devices:
5 * Host floppy block driver
6 */
7
8/*
9 * Copyright (C) 2006-2016 Oracle Corporation
10 *
11 * This file is part of VirtualBox Open Source Edition (OSE), as
12 * available from http://www.virtualbox.org. This file is free software;
13 * you can redistribute it and/or modify it under the terms of the GNU
14 * General Public License (GPL) as published by the Free Software
15 * Foundation, in version 2 as it comes in the "COPYING" file of the
16 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
17 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
18 */
19
20
21/*********************************************************************************************************************************
22* Header Files *
23*********************************************************************************************************************************/
24#define LOG_GROUP LOG_GROUP_DRV_HOST_FLOPPY
25#ifdef RT_OS_LINUX
26# include <sys/ioctl.h>
27# include <linux/fd.h>
28# include <sys/fcntl.h>
29# include <errno.h>
30# elif defined(RT_OS_WINDOWS)
31# include <iprt/win/windows.h>
32# include <dbt.h>
33#endif
34
35#include <VBox/vmm/pdmdrv.h>
36#include <VBox/vmm/pdmstorageifs.h>
37#include <iprt/assert.h>
38#include <iprt/file.h>
39#include <iprt/string.h>
40#include <iprt/thread.h>
41#include <iprt/semaphore.h>
42#include <iprt/uuid.h>
43#include <iprt/asm.h>
44#include <iprt/critsect.h>
45
46#include "VBoxDD.h"
47#include "DrvHostBase.h"
48
49
50/**
51 * Floppy driver instance data.
52 */
53typedef struct DRVHOSTFLOPPY
54{
55 DRVHOSTBASE Base;
56 /** Previous poll status. */
57 bool fPrevDiskIn;
58
59} DRVHOSTFLOPPY, *PDRVHOSTFLOPPY;
60
61
62#ifdef RT_OS_LINUX
63/**
64 * This thread will periodically poll the Floppy for media presence.
65 *
66 * @returns Ignored.
67 * @param ThreadSelf Handle of this thread. Ignored.
68 * @param pvUser Pointer to the driver instance structure.
69 */
70static DECLCALLBACK(int) drvHostFloppyPoll(PDRVHOSTBASE pThis)
71{
72 PDRVHOSTFLOPPY pThisFloppy = (PDRVHOSTFLOPPY)pThis;
73 floppy_drive_struct DrvStat;
74 int rc = ioctl(RTFileToNative(pThis->hFileDevice), FDPOLLDRVSTAT, &DrvStat);
75 if (rc)
76 return RTErrConvertFromErrno(errno);
77
78 RTCritSectEnter(&pThis->CritSect);
79 bool fDiskIn = !(DrvStat.flags & (FD_VERIFY | FD_DISK_NEWCHANGE));
80 if ( fDiskIn
81 && !pThisFloppy->fPrevDiskIn)
82 {
83 if (pThis->fMediaPresent)
84 DRVHostBaseMediaNotPresent(pThis);
85 rc = DRVHostBaseMediaPresent(pThis);
86 if (RT_FAILURE(rc))
87 {
88 pThisFloppy->fPrevDiskIn = fDiskIn;
89 RTCritSectLeave(&pThis->CritSect);
90 return rc;
91 }
92 }
93
94 if ( !fDiskIn
95 && pThisFloppy->fPrevDiskIn
96 && pThis->fMediaPresent)
97 DRVHostBaseMediaNotPresent(pThis);
98 pThisFloppy->fPrevDiskIn = fDiskIn;
99
100 RTCritSectLeave(&pThis->CritSect);
101 return VINF_SUCCESS;
102}
103#endif /* RT_OS_LINUX */
104
105
106/**
107 * @copydoc FNPDMDRVCONSTRUCT
108 */
109static DECLCALLBACK(int) drvHostFloppyConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags)
110{
111 RT_NOREF(fFlags);
112 PDRVHOSTFLOPPY pThis = PDMINS_2_DATA(pDrvIns, PDRVHOSTFLOPPY);
113 LogFlow(("drvHostFloppyConstruct: iInstance=%d\n", pDrvIns->iInstance));
114
115 /*
116 * Init instance data.
117 */
118 int rc = DRVHostBaseInitData(pDrvIns, pCfg, PDMMEDIATYPE_FLOPPY_1_44);
119 if (RT_SUCCESS(rc))
120 {
121 /*
122 * Validate configuration.
123 */
124 if (CFGMR3AreValuesValid(pCfg, "Path\0ReadOnly\0Interval\0Locked\0BIOSVisible\0"))
125 {
126 /*
127 * Override stuff.
128 */
129#ifdef RT_OS_LINUX
130 pThis->Base.pfnPoll = drvHostFloppyPoll;
131#endif
132
133 /*
134 * 2nd init part.
135 */
136 rc = DRVHostBaseInitFinish(&pThis->Base);
137 }
138 else
139 {
140 pThis->Base.fAttachFailError = true;
141 rc = VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES;
142 }
143 }
144 if (RT_FAILURE(rc))
145 {
146 if (!pThis->Base.fAttachFailError)
147 {
148 /* Suppressing the attach failure error must not affect the normal
149 * DRVHostBaseDestruct, so reset this flag below before leaving. */
150 pThis->Base.fKeepInstance = true;
151 rc = VINF_SUCCESS;
152 }
153 DRVHostBaseDestruct(pDrvIns);
154 pThis->Base.fKeepInstance = false;
155 }
156
157 LogFlow(("drvHostFloppyConstruct: returns %Rrc\n", rc));
158 return rc;
159}
160
161
162/**
163 * Block driver registration record.
164 */
165const PDMDRVREG g_DrvHostFloppy =
166{
167 /* u32Version */
168 PDM_DRVREG_VERSION,
169 /* szName */
170 "HostFloppy",
171 /* szRCMod */
172 "",
173 /* szR0Mod */
174 "",
175 /* pszDescription */
176 "Host Floppy Block Driver.",
177 /* fFlags */
178 PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT,
179 /* fClass. */
180 PDM_DRVREG_CLASS_BLOCK,
181 /* cMaxInstances */
182 ~0U,
183 /* cbInstance */
184 sizeof(DRVHOSTFLOPPY),
185 /* pfnConstruct */
186 drvHostFloppyConstruct,
187 /* pfnDestruct */
188 DRVHostBaseDestruct,
189 /* pfnRelocate */
190 NULL,
191 /* pfnIOCtl */
192 NULL,
193 /* pfnPowerOn */
194 NULL,
195 /* pfnReset */
196 NULL,
197 /* pfnSuspend */
198 NULL,
199 /* pfnResume */
200 NULL,
201 /* pfnAttach */
202 NULL,
203 /* pfnDetach */
204 NULL,
205 /* pfnPowerOff */
206 NULL,
207 /* pfnSoftReset */
208 NULL,
209 /* u32EndVersion */
210 PDM_DRVREG_VERSION
211};
212
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette