Changeset 64316 in vbox for trunk/src/VBox/Devices/Storage/DrvHostBase-solaris.cpp
- Timestamp:
- Oct 19, 2016 11:59:42 AM (9 years ago)
- svn:sync-xref-src-repo-rev:
- 111389
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Storage/DrvHostBase-solaris.cpp
r64278 r64316 33 33 34 34 #include <iprt/file.h> 35 36 /** 37 * Host backend specific data. 38 */ 39 typedef struct DRVHOSTBASEOS 40 { 41 /** The filehandle of the device. */ 42 RTFILE hFileDevice; 43 /** The raw filehandle of the device. */ 44 RTFILE hFileRawDevice; 45 /** Device name of raw device (RTStrFree). */ 46 char *pszRawDeviceOpen; 47 } DRVHOSTBASEOS; 48 /** Pointer to the host backend specific data. */ 49 typedef DRVHOSTBASEOS *PDRVHOSBASEOS; 50 AssertCompile(sizeof(DRVHOSTBASEOS) <= 64); 51 52 #define DRVHOSTBASE_OS_INT_DECLARED 35 53 #include "DrvHostBase.h" 36 54 … … 40 58 * return the value. BUT... this might be prohibitively slow. 41 59 */ 60 61 /** 62 * Checks if the current user is authorized using Solaris' role-based access control. 63 * Made as a separate function with so that it need not be invoked each time we need 64 * to gain root access. 65 * 66 * @returns VBox error code. 67 */ 68 static int solarisCheckUserAuth() 69 { 70 /* Uses Solaris' role-based access control (RBAC).*/ 71 struct passwd *pPass = getpwuid(getuid()); 72 if (pPass == NULL || chkauthattr("solaris.device.cdrw", pPass->pw_name) == 0) 73 return VERR_PERMISSION_DENIED; 74 75 return VINF_SUCCESS; 76 } 42 77 43 78 /** … … 148 183 solarisEnterRootMode(&effUserID); /** @todo check return code when this really works. */ 149 184 #endif 150 rc = ioctl(RTFileToNative(pThis-> hFileRawDevice), USCSICMD, &usc);185 rc = ioctl(RTFileToNative(pThis->Os.hFileRawDevice), USCSICMD, &usc); 151 186 #ifdef VBOX_WITH_SUID_WRAPPER 152 187 solarisExitRootMode(&effUserID); … … 175 210 */ 176 211 struct dk_minfo MediaInfo; 177 if (ioctl(RTFileToNative(pThis-> hFileRawDevice), DKIOCGMEDIAINFO, &MediaInfo) == 0)212 if (ioctl(RTFileToNative(pThis->Os.hFileRawDevice), DKIOCGMEDIAINFO, &MediaInfo) == 0) 178 213 { 179 214 *pcb = MediaInfo.dki_capacity * (uint64_t)MediaInfo.dki_lbsize; 180 215 return VINF_SUCCESS; 181 216 } 182 return RTFileSeek(pThis-> hFileDevice, 0, RTFILE_SEEK_END, pcb);217 return RTFileSeek(pThis->Os.hFileDevice, 0, RTFILE_SEEK_END, pcb); 183 218 } 184 219 … … 186 221 DECLHIDDEN(int) drvHostBaseReadOs(PDRVHOSTBASE pThis, uint64_t off, void *pvBuf, size_t cbRead) 187 222 { 188 return RTFileReadAt(pThis-> hFileDevice, off, pvBuf, cbRead, NULL);223 return RTFileReadAt(pThis->Os.hFileDevice, off, pvBuf, cbRead, NULL); 189 224 } 190 225 … … 192 227 DECLHIDDEN(int) drvHostBaseWriteOs(PDRVHOSTBASE pThis, uint64_t off, const void *pvBuf, size_t cbWrite) 193 228 { 194 return RTFileWriteAt(pThis-> hFileDevice, off, pvBuf, cbWrite, NULL);229 return RTFileWriteAt(pThis->Os.hFileDevice, off, pvBuf, cbWrite, NULL); 195 230 } 196 231 … … 198 233 DECLHIDDEN(int) drvHostBaseFlushOs(PDRVHOSTBASE pThis) 199 234 { 200 return RTFileFlush(pThis-> hFileDevice);235 return RTFileFlush(pThis->Os.hFileDevice); 201 236 } 202 237 … … 204 239 DECLHIDDEN(int) drvHostBaseDoLockOs(PDRVHOSTBASE pThis, bool fLock) 205 240 { 206 int rc = ioctl(RTFileToNative(pThis-> hFileRawDevice), fLock ? DKIOCLOCK : DKIOCUNLOCK, 0);241 int rc = ioctl(RTFileToNative(pThis->Os.hFileRawDevice), fLock ? DKIOCLOCK : DKIOCUNLOCK, 0); 207 242 if (rc < 0) 208 243 { … … 221 256 DECLHIDDEN(int) drvHostBaseEjectOs(PDRVHOSTBASE pThis) 222 257 { 223 int rc = ioctl(RTFileToNative(pThis-> hFileRawDevice), DKIOCEJECT, 0);258 int rc = ioctl(RTFileToNative(pThis->Os.hFileRawDevice), DKIOCEJECT, 0); 224 259 if (rc < 0) 225 260 { … … 246 281 static dkio_state s_DeviceState = DKIO_NONE; 247 282 dkio_state PreviousState = s_DeviceState; 248 int rc = ioctl(RTFileToNative(pThis-> hFileRawDevice), DKIOCSTATE, &s_DeviceState);283 int rc = ioctl(RTFileToNative(pThis->Os.hFileRawDevice), DKIOCSTATE, &s_DeviceState); 249 284 if (rc == 0) 250 285 { … … 258 293 259 294 260 DECLHIDDEN(int) drvHostBasePollerWakeupOs(PDRVHOSTBASE pThis) 261 { 262 return RTSemEventSignal(pThis->EventPoller); 295 DECLHIDDEN(void) drvHostBaseInitOs(PDRVHOSTBASE pThis) 296 { 297 pThis->Os.hFileDevice = NIL_RTFILE; 298 pThis->Os.hFileRawDevice = NIL_RTFILE; 299 pThis->Os.pszRawDeviceOpen = NULL; 300 } 301 302 303 DECLHIDDEN(int) drvHostBaseOpenOs(PDRVHOSTBASE pThis, bool fReadOnly) 304 { 305 #ifdef VBOX_WITH_SUID_WRAPPER /* Solaris setuid for Passthrough mode. */ 306 if ( (pThis->enmType == PDMMEDIATYPE_CDROM || pThis->enmType == PDMMEDIATYPE_DVD) 307 && pThis->IMedia.pfnSendCmd) 308 { 309 rc = solarisCheckUserAuth(); 310 if (RT_FAILURE(rc)) 311 { 312 Log(("DVD: solarisCheckUserAuth failed. Permission denied!\n")); 313 return rc; 314 } 315 } 316 #endif /* VBOX_WITH_SUID_WRAPPER */ 317 318 char *pszBlockDevName = getfullblkname(pThis->pszDevice); 319 if (!pszBlockDevName) 320 return VERR_NO_MEMORY; 321 pThis->pszDeviceOpen = RTStrDup(pszBlockDevName); /* for RTStrFree() */ 322 free(pszBlockDevName); 323 pThis->Os.pszRawDeviceOpen = RTStrDup(pThis->pszDevice); 324 if (!pThis->pszDeviceOpen || !pThis->Os.pszRawDeviceOpen); 325 return VERR_NO_MEMORY; 326 327 unsigned fFlags = (fReadOnly ? RTFILE_O_READ : RTFILE_O_READWRITE) 328 | RTFILE_O_OPEN | RTFILE_O_DENY_NONE | RTFILE_O_NON_BLOCK; 329 int rc = RTFileOpen(&pThis->Os.hFileDevice, pThis->pszDeviceOpen, fFlags); 330 if (RT_SUCCESS(rc)) 331 { 332 rc = RTFileOpen(&pThis->Os.hFileRawDevice, pThis->Os.pszRawDeviceOpen, fFlags); 333 if (RT_SUCCESS(rc)) 334 return rc; 335 336 LogRel(("DVD: failed to open device %s rc=%Rrc\n", pThis->Os.pszRawDeviceOpen, rc)); 337 RTFileClose(pThis->Os.hFileDevice); 338 } 339 else 340 LogRel(("DVD: failed to open device %s rc=%Rrc\n", pThis->pszDeviceOpen, rc)); 341 return rc; 342 } 343 344 345 DECLHIDDEN(int) drvHostBaseMediaRefreshOs(PDRVHOSTBASE pThis) 346 { 347 RT_NOREF(pThis); 348 return VINF_SUCCESS; 349 } 350 351 352 DECLHIDDEN(bool) drvHostBaseIsMediaPollingRequiredOs(PDRVHOSTBASE pThis) 353 { 354 if (pThis->enmType == PDMMEDIATYPE_CDROM || pThis->enmType == PDMMEDIATYPE_DVD) 355 return true; 356 357 AssertMsgFailed(("Solaris supports only CD/DVD host drive access\n")); 358 return false; 263 359 } 264 360 … … 266 362 DECLHIDDEN(void) drvHostBaseDestructOs(PDRVHOSTBASE pThis) 267 363 { 268 if (pThis->EventPoller != NULL) 269 { 270 RTSemEventDestroy(pThis->EventPoller); 271 pThis->EventPoller = NULL; 272 } 273 274 if (pThis->hFileDevice != NIL_RTFILE) 275 { 276 int rc = RTFileClose(pThis->hFileDevice); 364 /* 365 * Unlock the drive if we've locked it or we're in passthru mode. 366 */ 367 if ( pThis->fLocked 368 && pThis->Os.hFileDevice != NIL_RTFILE 369 && pThis->pfnDoLock) 370 { 371 int rc = pThis->pfnDoLock(pThis, false); 372 if (RT_SUCCESS(rc)) 373 pThis->fLocked = false; 374 } 375 376 if (pThis->Os.hFileDevice != NIL_RTFILE) 377 { 378 int rc = RTFileClose(pThis->Os.hFileDevice); 277 379 AssertRC(rc); 278 pThis-> hFileDevice = NIL_RTFILE;279 } 280 281 if (pThis-> hFileRawDevice != NIL_RTFILE)282 { 283 int rc = RTFileClose(pThis-> hFileRawDevice);380 pThis->Os.hFileDevice = NIL_RTFILE; 381 } 382 383 if (pThis->Os.hFileRawDevice != NIL_RTFILE) 384 { 385 int rc = RTFileClose(pThis->Os.hFileRawDevice); 284 386 AssertRC(rc); 285 pThis-> hFileRawDevice = NIL_RTFILE;286 } 287 288 if (pThis-> pszRawDeviceOpen)289 { 290 RTStrFree(pThis-> pszRawDeviceOpen);291 pThis-> pszRawDeviceOpen = NULL;292 } 293 } 294 387 pThis->Os.hFileRawDevice = NIL_RTFILE; 388 } 389 390 if (pThis->Os.pszRawDeviceOpen) 391 { 392 RTStrFree(pThis->Os.pszRawDeviceOpen); 393 pThis->Os.pszRawDeviceOpen = NULL; 394 } 395 } 396
Note:
See TracChangeset
for help on using the changeset viewer.