Changeset 5212 in vbox for trunk/src/VBox/Devices/Storage
- Timestamp:
- Oct 9, 2007 6:43:56 PM (17 years ago)
- Location:
- trunk/src/VBox/Devices/Storage
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Storage/DrvHostBase.cpp
r5184 r5212 1 /* $Id$ */ 1 2 /** @file 2 * 3 * VBox storage devices: 4 * Host base drive access driver 3 * DrvHostBase - Host base drive access driver. 5 4 */ 6 5 … … 46 45 # include <errno.h> 47 46 # include <stropts.h> 47 # include <malloc.h> 48 48 # include <sys/dkio.h> 49 extern "C" char *getfullblkname(char *); 49 50 50 51 #elif defined(RT_OS_WINDOWS) … … 734 735 735 736 737 #ifndef RT_OS_SOLARIS 736 738 /** 737 739 * Wrapper for open / RTFileOpen / IOKit. … … 920 922 return rc; 921 923 922 #elif defined(RT_OS_LINUX) || defined(RT_OS_SOLARIS)924 #elif defined(RT_OS_LINUX) 923 925 /** @todo we've got RTFILE_O_NON_BLOCK now. Change the code to use RTFileOpen. */ 924 926 int FileDevice = open(pThis->pszDeviceOpen, (pThis->fReadOnlyConfig ? O_RDONLY : O_RDWR) | O_NONBLOCK); … … 934 936 } 935 937 938 #else /* RT_OS_SOLARIS */ 939 940 /** 941 * Solaris wrapper for RTFileOpen. 942 * 943 * Solaris has to deal with two filehandles, a block and a raw one. Rather than messing 944 * with drvHostBaseOpen's function signature & body, having a seperate one is better. 945 * 946 * @returns VBox status code. 947 */ 948 static int drvHostBaseOpen(PDRVHOSTBASE pThis, PRTFILE pBlockFileDevice, PRTFILE pFileRawDevice, bool fReadOnly) 949 { 950 unsigned fFlags = (pThis->fReadOnlyConfig ? RTFILE_O_READ : RTFILE_O_READWRITE) | RTFILE_O_NON_BLOCK; 951 int rc = RTFileOpen(pBlockFileDevice, pThis->pszDeviceOpen, fFlags); 952 if (RT_SUCCESS(rc)) 953 { 954 rc = RTFileOpen(pFileRawDevice, pThis->pszRawDeviceOpen, fFlags); 955 if (RT_FAILURE(rc)) 956 RTFileClose(BlockFileDevice); 957 } 958 return rc; 959 } 960 #endif /* RT_OS_SOLARIS */ 961 936 962 937 963 /** … … 951 977 952 978 RTFILE FileDevice; 979 #ifdef RT_OS_SOLARIS 980 RTFILE FileRawDevice; 981 int rc = drvHostBaseOpen(pThis, &FileDevice, &FileRawDevice, pThis->fReadOnlyConfig); 982 #else 953 983 int rc = drvHostBaseOpen(pThis, &FileDevice, pThis->fReadOnlyConfig); 984 #endif 954 985 if (VBOX_FAILURE(rc)) 955 986 { … … 957 988 { 958 989 LogFlow(("%s-%d: drvHostBaseReopen: '%s' - retry readonly (%Vrc)\n", pThis->pDrvIns->pDrvReg->szDriverName, pThis->pDrvIns->iInstance, pThis->pszDeviceOpen, rc)); 990 #ifdef RT_OS_SOLARIS 991 rc = drvHostBaseOpen(pThis, &FileDevice, &FileRawDevice, false); 992 #else 959 993 rc = drvHostBaseOpen(pThis, &FileDevice, false); 994 #endif 960 995 } 961 996 if (VBOX_FAILURE(rc)) … … 969 1004 else 970 1005 pThis->fReadOnly = pThis->fReadOnlyConfig; 1006 1007 #ifdef RT_OS_SOLARIS 1008 if (pThis->FileRawDevice != NIL_RTFILE) 1009 RTFileClose(pThis->FileRawDevice); 1010 pThis->FileRawDevice = FileRawDevice; 1011 #endif 971 1012 972 1013 if (pThis->FileDevice != NIL_RTFILE) … … 1023 1064 */ 1024 1065 struct dk_minfo MediaInfo; 1025 if (ioctl(pThis->File Device, DKIOCGMEDIAINFO, &MediaInfo) == 0)1066 if (ioctl(pThis->FileRawDevice, DKIOCGMEDIAINFO, &MediaInfo) == 0) 1026 1067 { 1027 1068 *pcb = MediaInfo.dki_capacity * (uint64_t)MediaInfo.dki_lbsize; … … 1562 1603 #endif 1563 1604 1605 #ifdef RT_OS_SOLARIS 1606 if (pThis->FileRawDevice != NIL_RTFILE) 1607 { 1608 int rc = RTFileClose(pThis->FileRawDevice); 1609 AssertRC(rc); 1610 pThis->FileRawDevice = NIL_RTFILE; 1611 } 1612 1613 if (pThis->pszRawDeviceOpen) 1614 { 1615 RTStrFree(pThis->pszRawDeviceOpen); 1616 pThis->pszRawDeviceOpen = NULL; 1617 } 1618 #endif 1619 1564 1620 if (pThis->pszDevice) 1565 1621 { … … 1619 1675 pThis->FileDevice = NIL_RTFILE; 1620 1676 #endif 1677 #ifdef RT_OS_SOLARIS 1678 pThis->FileRawDevice = NIL_RTFILE; 1679 #endif 1621 1680 pThis->enmType = enmType; 1622 1681 //pThis->cErrors = 0; … … 1758 1817 pThis->fUnitMask = 1 << iBit; 1759 1818 RTStrAPrintf(&pThis->pszDeviceOpen, "\\\\.\\%s", pThis->pszDevice); 1819 1820 #elif defined(RT_OS_SOLARIS) 1821 char *pszBlockDevName = getfullblkname(pThis->pszDevice); 1822 if (!pszBlockDevName) 1823 return VERR_NO_MEMORY; 1824 pThis->pszDeviceOpen = RTStrDup(pszBlockDevName); /* for RTStrFree() */ 1825 free(pszBlockDevName); 1826 pThis->pszRawDeviceOpen = RTStrDup(pThis->pszDevice); 1827 1760 1828 #else 1761 1829 pThis->pszDeviceOpen = RTStrDup(pThis->pszDevice); 1762 1830 #endif 1831 1763 1832 if (!pThis->pszDeviceOpen) 1764 1833 return VERR_NO_MEMORY; … … 1859 1928 pThis->FileDevice = NIL_RTFILE; 1860 1929 #endif 1861 /* Disable CD/DVD passthrough in case it was enabled. Would cause 1930 #ifdef RT_OS_SOLARIS 1931 pThis->FileRawDevice = NIL_RTFILE; 1932 #endif 1933 1934 /* 1935 * Disable CD/DVD passthrough in case it was enabled. Would cause 1862 1936 * weird failures later when the guest issues commands. These would 1863 1937 * all fail because of the invalid file handle. So use the normal 1864 1938 * virtual CD/DVD code, which deals more gracefully with unavailable 1865 * "media" - actually a complete drive in this case. */ 1939 * "media" - actually a complete drive in this case. 1940 */ 1866 1941 pThis->IBlock.pfnSendCmd = NULL; 1867 1942 AssertMsgFailed(("Could not open host device %s, rc=%Vrc\n", pszDevice, rc)); -
trunk/src/VBox/Devices/Storage/DrvHostBase.h
r4071 r5212 1 /* $Id$ */ 1 2 /** @file 2 * 3 * VBox storage devices: 4 * Host base drive access driver 3 * DrvHostBase - Host base drive access driver. 5 4 */ 6 5 … … 53 52 /** Device name to open (RTStrFree). */ 54 53 char *pszDeviceOpen; 54 #ifdef RT_OS_SOLARIS 55 /** Device name of raw device (RTStrFree). */ 56 char *pszRawDeviceOpen; 57 #endif 55 58 /** Uuid of the drive. */ 56 59 RTUUID Uuid; … … 77 80 /** The filehandle of the device. */ 78 81 RTFILE FileDevice; 82 #endif 83 #ifdef RT_OS_SOLARIS 84 /** The raw filehandle of the device. */ 85 RTFILE FileRawDevice; 79 86 #endif 80 87 -
trunk/src/VBox/Devices/Storage/DrvHostDVD.cpp
r5184 r5212 1 /* $Id$ */ 1 2 /** @file 2 * 3 * VBox storage devices: 4 * Host DVD block driver 3 * DrvHostDVD - Host DVD block driver. 5 4 */ 6 5 … … 132 131 133 132 #elif defined(RT_OS_SOLARIS) 134 rc = ioctl(pThis->File Device, DKIOCEJECT, 0);133 rc = ioctl(pThis->FileRawDevice, DKIOCEJECT, 0); 135 134 if (rc < 0) 136 135 { … … 221 220 222 221 #elif defined(RT_OS_SOLARIS) 223 int rc = ioctl(pThis->File Device, fLock ? DKIOCLOCK : DKIOCUNLOCK, 0);222 int rc = ioctl(pThis->FileRawDevice, fLock ? DKIOCLOCK : DKIOCUNLOCK, 0); 224 223 if (rc < 0) 225 224 { … … 326 325 /* Need to pass the previous state and DKIO_NONE for the first time. */ 327 326 static dkio_state DeviceState = DKIO_NONE; 328 int rc2 = ioctl(pThis->File Device, DKIOCSTATE, &DeviceState);327 int rc2 = ioctl(pThis->FileRawDevice, DKIOCSTATE, &DeviceState); 329 328 if (rc2 == 0) 330 329 { … … 509 508 510 509 /* We need root privileges for user-SCSI under Solaris. */ 511 rc = ioctl(pThis->File Device, USCSICMD, &usc);510 rc = ioctl(pThis->FileRawDevice, USCSICMD, &usc); 512 511 if (rc < 0) 513 512 { … … 625 624 if (*pEffUserID == 0) 626 625 return VINF_SUCCESS; 626 else 627 { 628 if (seteuid(0) == 0) 629 { 630 *pEffUserID = 0; 631 return VINF_SUCCESS; 632 } 633 else 634 return VERR_PERMISSION_DENIED; 635 } 636 } 637 638 /** 639 * Setuid wrapper to relinquish root access. 640 * 641 * @returns VBox error code. 642 * @param pUserID Pointer to user ID. 643 * @param pEffUserID Pointer to effective user ID. 644 */ 645 static int solarisExitRootMode(uid_t *pUserID, uid_t *pEffUserID) 646 { 647 /* Get back to user mode. */ 648 if (*pEffUserID == 0) 649 { 650 if (seteuid(*pUserID) == 0) 651 { 652 *pEffUserID = *pUserID; 653 return VINF_SUCCESS; 654 } 655 else 656 return VERR_PERMISSION_DENIED; 657 } 658 return VINF_SUCCESS; 659 } 660 661 /** 662 * Setuid wrapper to gain root access. 663 * 664 * @returns VBox error code. 665 * @param pUserID Pointer to user ID. 666 * @param pEffUserID Pointer to effective user ID. 667 */ 668 static int solarisEnterRootMode(uid_t *pUserID, uid_t *pEffUserID) 669 { 670 /* Increase privilege if required */ 671 if (*pEffUserID == 0) 672 return VINF_SUCCESS; 627 673 if (seteuid(0) == 0) 628 674 { … … 720 766 rc = DRVHostBaseInitFinish(pThis); 721 767 } 722 723 768 if (VBOX_FAILURE(rc)) 724 769 {
Note:
See TracChangeset
for help on using the changeset viewer.