VirtualBox

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

Last change on this file since 546 was 1, checked in by vboxsync, 55 years ago

import

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.9 KB
Line 
1/** @file
2 *
3 * VBox storage devices:
4 * Host floppy block driver
5 */
6
7/*
8 * Copyright (C) 2006 InnoTek Systemberatung GmbH
9 *
10 * This file is part of VirtualBox Open Source Edition (OSE), as
11 * available from http://www.virtualbox.org. This file is free software;
12 * you can redistribute it and/or modify it under the terms of the GNU
13 * General Public License as published by the Free Software Foundation,
14 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
15 * distribution. VirtualBox OSE is distributed in the hope that it will
16 * be useful, but WITHOUT ANY WARRANTY of any kind.
17 *
18 * If you received this file as part of a commercial VirtualBox
19 * distribution, then only the terms of your commercial VirtualBox
20 * license agreement apply instead of the previous paragraph.
21 */
22
23
24/*******************************************************************************
25* Header Files *
26*******************************************************************************/
27#define LOG_GROUP LOG_GROUP_DRV_HOST_FLOPPY
28#ifdef __LINUX__
29# include <sys/ioctl.h>
30# include <linux/fd.h>
31# include <sys/fcntl.h>
32# include <errno.h>
33
34# elif defined(__WIN__)
35# include <windows.h>
36# include <dbt.h>
37
38#elif defined(__L4ENV__)
39
40#else /* !__WIN__ nor __LINUX__ nor __L4ENV__ */
41# error "Unsupported Platform."
42#endif /* !__WIN__ nor __LINUX__ nor __L4ENV__ */
43
44#include <VBox/pdm.h>
45#include <VBox/cfgm.h>
46#include <VBox/mm.h>
47#include <VBox/err.h>
48
49#include <VBox/log.h>
50#include <iprt/assert.h>
51#include <iprt/file.h>
52#include <iprt/string.h>
53#include <iprt/thread.h>
54#include <iprt/semaphore.h>
55#include <iprt/uuid.h>
56#include <iprt/asm.h>
57#include <iprt/critsect.h>
58
59#include "Builtins.h"
60#include "DrvHostBase.h"
61
62
63/**
64 * Floppy driver instance data.
65 */
66typedef struct DRVHOSTFLOPPY
67{
68 DRVHOSTBASE Base;
69 /** Previous poll status. */
70 bool fPrevDiskIn;
71
72} DRVHOSTFLOPPY, *PDRVHOSTFLOPPY;
73
74
75
76#ifdef __LINUX__
77/**
78 * Get media size and do change processing.
79 *
80 * @param pThis The instance data.
81 */
82static DECLCALLBACK(int) drvHostFloppyGetMediaSize(PDRVHOSTBASE pThis, uint64_t *pcb)
83{
84 int rc = ioctl(pThis->FileDevice, FDFLUSH);
85 if (rc)
86 {
87 rc = RTErrConvertFromErrno (errno);
88 Log(("DrvHostFloppy: FDFLUSH ioctl(%s) failed, errno=%d rc=%Vrc\n", pThis->pszDevice, errno, rc));
89 return rc;
90 }
91
92 floppy_drive_struct DrvStat;
93 rc = ioctl(pThis->FileDevice, FDGETDRVSTAT, &DrvStat);
94 if (rc)
95 {
96 rc = RTErrConvertFromErrno(errno);
97 Log(("DrvHostFloppy: FDGETDRVSTAT ioctl(%s) failed, errno=%d rc=%Vrc\n", pThis->pszDevice, errno, rc));
98 return rc;
99 }
100 pThis->fReadOnly = !!(DrvStat.flags & FD_DISK_WRITABLE);
101
102 return RTFileSeek(pThis->FileDevice, 0, RTFILE_SEEK_END, pcb);
103}
104#endif /* __LINUX__ */
105
106
107#ifdef __LINUX__
108/**
109 * This thread will periodically poll the Floppy for media presence.
110 *
111 * @returns Ignored.
112 * @param ThreadSelf Handle of this thread. Ignored.
113 * @param pvUser Pointer to the driver instance structure.
114 */
115static DECLCALLBACK(int) drvHostFloppyPoll(PDRVHOSTBASE pThis)
116{
117 PDRVHOSTFLOPPY pThisFloppy = (PDRVHOSTFLOPPY)pThis;
118 floppy_drive_struct DrvStat;
119 int rc = ioctl(pThis->FileDevice, FDPOLLDRVSTAT, &DrvStat);
120 if (rc)
121 return RTErrConvertFromErrno(errno);
122
123 RTCritSectEnter(&pThis->CritSect);
124 bool fDiskIn = !(DrvStat.flags & (FD_VERIFY | FD_DISK_NEWCHANGE));
125 if ( fDiskIn
126 && !pThisFloppy->fPrevDiskIn)
127 {
128 if (pThis->fMediaPresent)
129 DRVHostBaseMediaNotPresent(pThis);
130 rc = DRVHostBaseMediaPresent(pThis);
131 if (VBOX_FAILURE(rc))
132 {
133 pThisFloppy->fPrevDiskIn = fDiskIn;
134 RTCritSectLeave(&pThis->CritSect);
135 return rc;
136 }
137 }
138
139 if ( !fDiskIn
140 && pThisFloppy->fPrevDiskIn
141 && pThis->fMediaPresent)
142 DRVHostBaseMediaNotPresent(pThis);
143 pThisFloppy->fPrevDiskIn = fDiskIn;
144
145 RTCritSectLeave(&pThis->CritSect);
146 return VINF_SUCCESS;
147}
148#endif /* __LINUX__ */
149
150
151/**
152 * @copydoc FNPDMDRVCONSTRUCT
153 */
154static DECLCALLBACK(int) drvHostFloppyConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfgHandle)
155{
156 PDRVHOSTFLOPPY pThis = PDMINS2DATA(pDrvIns, PDRVHOSTFLOPPY);
157 LogFlow(("drvHostFloppyConstruct: iInstance=%d\n", pDrvIns->iInstance));
158
159 /*
160 * Validate configuration.
161 */
162 if (!CFGMR3AreValuesValid(pCfgHandle, "Path\0ReadOnly\0Interval\0Locked\0BIOSVisible\0"))
163 return VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES;
164
165 /*
166 * Init instance data.
167 */
168 int rc = DRVHostBaseInitData(pDrvIns, pCfgHandle, PDMBLOCKTYPE_FLOPPY_1_44);
169 if (VBOX_SUCCESS(rc))
170 {
171 /*
172 * Override stuff.
173 */
174#ifdef __LINUX__
175 pThis->Base.pfnPoll = drvHostFloppyPoll;
176 pThis->Base.pfnGetMediaSize = drvHostFloppyGetMediaSize;
177#endif
178
179 /*
180 * 2nd init part.
181 */
182 rc = DRVHostBaseInitFinish(&pThis->Base);
183 if (VBOX_SUCCESS(rc))
184 {
185 LogFlow(("drvHostFloppyConstruct: return %Vrc\n", rc));
186 return rc;
187 }
188 }
189 DRVHostBaseDestruct(pDrvIns);
190
191 LogFlow(("drvHostFloppyConstruct: returns %Vrc\n", rc));
192 return rc;
193}
194
195
196/**
197 * Block driver registration record.
198 */
199const PDMDRVREG g_DrvHostFloppy =
200{
201 /* u32Version */
202 PDM_DRVREG_VERSION,
203 /* szDriverName */
204 "HostFloppy",
205 /* pszDescription */
206 "Host Floppy Block Driver.",
207 /* fFlags */
208 PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT,
209 /* fClass. */
210 PDM_DRVREG_CLASS_BLOCK,
211 /* cMaxInstances */
212 ~0,
213 /* cbInstance */
214 sizeof(DRVHOSTFLOPPY),
215 /* pfnConstruct */
216 drvHostFloppyConstruct,
217 /* pfnDestruct */
218 DRVHostBaseDestruct,
219 /* pfnIOCtl */
220 NULL,
221 /* pfnPowerOn */
222 NULL,
223 /* pfnReset */
224 NULL,
225 /* pfnSuspend */
226 NULL,
227 /* pfnResume */
228 NULL,
229 /* pfnDetach */
230 NULL
231};
232
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