VirtualBox

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

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

Devices/Storage/DrvHost*: Move determining the medai size to the host specific sources

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.3 KB
Line 
1/* $Id: DrvHostFloppy.cpp 64247 2016-10-13 13:09:21Z 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#endif
31
32#include <VBox/vmm/pdmdrv.h>
33#include <VBox/vmm/pdmstorageifs.h>
34#include <iprt/assert.h>
35#include <iprt/file.h>
36#include <iprt/string.h>
37#include <iprt/thread.h>
38#include <iprt/semaphore.h>
39#include <iprt/uuid.h>
40#include <iprt/asm.h>
41#include <iprt/critsect.h>
42
43#include "VBoxDD.h"
44#include "DrvHostBase.h"
45
46
47/**
48 * Floppy driver instance data.
49 */
50typedef struct DRVHOSTFLOPPY
51{
52 DRVHOSTBASE Base;
53 /** Previous poll status. */
54 bool fPrevDiskIn;
55
56} DRVHOSTFLOPPY, *PDRVHOSTFLOPPY;
57
58
59#ifdef RT_OS_LINUX
60/**
61 * This thread will periodically poll the Floppy for media presence.
62 *
63 * @returns Ignored.
64 * @param ThreadSelf Handle of this thread. Ignored.
65 * @param pvUser Pointer to the driver instance structure.
66 */
67static DECLCALLBACK(int) drvHostFloppyPoll(PDRVHOSTBASE pThis)
68{
69 PDRVHOSTFLOPPY pThisFloppy = (PDRVHOSTFLOPPY)pThis;
70 floppy_drive_struct DrvStat;
71 int rc = ioctl(RTFileToNative(pThis->hFileDevice), FDPOLLDRVSTAT, &DrvStat);
72 if (rc)
73 return RTErrConvertFromErrno(errno);
74
75 RTCritSectEnter(&pThis->CritSect);
76 bool fDiskIn = !(DrvStat.flags & (FD_VERIFY | FD_DISK_NEWCHANGE));
77 if ( fDiskIn
78 && !pThisFloppy->fPrevDiskIn)
79 {
80 if (pThis->fMediaPresent)
81 DRVHostBaseMediaNotPresent(pThis);
82 rc = DRVHostBaseMediaPresent(pThis);
83 if (RT_FAILURE(rc))
84 {
85 pThisFloppy->fPrevDiskIn = fDiskIn;
86 RTCritSectLeave(&pThis->CritSect);
87 return rc;
88 }
89 }
90
91 if ( !fDiskIn
92 && pThisFloppy->fPrevDiskIn
93 && pThis->fMediaPresent)
94 DRVHostBaseMediaNotPresent(pThis);
95 pThisFloppy->fPrevDiskIn = fDiskIn;
96
97 RTCritSectLeave(&pThis->CritSect);
98 return VINF_SUCCESS;
99}
100#endif /* RT_OS_LINUX */
101
102
103/**
104 * @copydoc FNPDMDRVCONSTRUCT
105 */
106static DECLCALLBACK(int) drvHostFloppyConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags)
107{
108 RT_NOREF(fFlags);
109 PDRVHOSTFLOPPY pThis = PDMINS_2_DATA(pDrvIns, PDRVHOSTFLOPPY);
110 LogFlow(("drvHostFloppyConstruct: iInstance=%d\n", pDrvIns->iInstance));
111
112 /*
113 * Init instance data.
114 */
115 int rc = DRVHostBaseInitData(pDrvIns, pCfg, PDMMEDIATYPE_FLOPPY_1_44);
116 if (RT_SUCCESS(rc))
117 {
118 /*
119 * Validate configuration.
120 */
121 if (CFGMR3AreValuesValid(pCfg, "Path\0ReadOnly\0Interval\0Locked\0BIOSVisible\0"))
122 {
123 /*
124 * Override stuff.
125 */
126#ifdef RT_OS_LINUX
127 pThis->Base.pfnPoll = drvHostFloppyPoll;
128#endif
129
130 /*
131 * 2nd init part.
132 */
133 rc = DRVHostBaseInitFinish(&pThis->Base);
134 }
135 else
136 {
137 pThis->Base.fAttachFailError = true;
138 rc = VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES;
139 }
140 }
141 if (RT_FAILURE(rc))
142 {
143 if (!pThis->Base.fAttachFailError)
144 {
145 /* Suppressing the attach failure error must not affect the normal
146 * DRVHostBaseDestruct, so reset this flag below before leaving. */
147 pThis->Base.fKeepInstance = true;
148 rc = VINF_SUCCESS;
149 }
150 DRVHostBaseDestruct(pDrvIns);
151 pThis->Base.fKeepInstance = false;
152 }
153
154 LogFlow(("drvHostFloppyConstruct: returns %Rrc\n", rc));
155 return rc;
156}
157
158
159/**
160 * Block driver registration record.
161 */
162const PDMDRVREG g_DrvHostFloppy =
163{
164 /* u32Version */
165 PDM_DRVREG_VERSION,
166 /* szName */
167 "HostFloppy",
168 /* szRCMod */
169 "",
170 /* szR0Mod */
171 "",
172 /* pszDescription */
173 "Host Floppy Block Driver.",
174 /* fFlags */
175 PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT,
176 /* fClass. */
177 PDM_DRVREG_CLASS_BLOCK,
178 /* cMaxInstances */
179 ~0U,
180 /* cbInstance */
181 sizeof(DRVHOSTFLOPPY),
182 /* pfnConstruct */
183 drvHostFloppyConstruct,
184 /* pfnDestruct */
185 DRVHostBaseDestruct,
186 /* pfnRelocate */
187 NULL,
188 /* pfnIOCtl */
189 NULL,
190 /* pfnPowerOn */
191 NULL,
192 /* pfnReset */
193 NULL,
194 /* pfnSuspend */
195 NULL,
196 /* pfnResume */
197 NULL,
198 /* pfnAttach */
199 NULL,
200 /* pfnDetach */
201 NULL,
202 /* pfnPowerOff */
203 NULL,
204 /* pfnSoftReset */
205 NULL,
206 /* u32EndVersion */
207 PDM_DRVREG_VERSION
208};
209
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