diff options
author | Oliver Bolte <obo@openoffice.org> | 2008-07-22 16:02:21 +0000 |
---|---|---|
committer | Oliver Bolte <obo@openoffice.org> | 2008-07-22 16:02:21 +0000 |
commit | e9b7436485b73723d44c2012d08e3b128e26614e (patch) | |
tree | 7b53a45e74be4650759aa2ae7da2a1cd53478c29 /sal | |
parent | 841945393d85880d19fa95726e7dd36d782caf9f (diff) |
INTEGRATION: CWS os2port03 (1.4.32); FILE MERGED
2008/07/16 12:25:53 obr 1.4.32.2: RESYNC: (1.4-1.6); FILE MERGED
2008/01/29 14:43:40 ydario 1.4.32.1: Added missing code for cdrom, removed *nix floppy functions.
Issue number:i85203
Submitted by:ydario
Diffstat (limited to 'sal')
-rw-r--r-- | sal/osl/os2/file.cxx | 1075 |
1 files changed, 50 insertions, 1025 deletions
diff --git a/sal/osl/os2/file.cxx b/sal/osl/os2/file.cxx index 3f8e89cab..ca9a6ba7d 100644 --- a/sal/osl/os2/file.cxx +++ b/sal/osl/os2/file.cxx @@ -7,7 +7,7 @@ * OpenOffice.org - a multi-platform office productivity suite * * $RCSfile: file.cxx,v $ - * $Revision: 1.6 $ + * $Revision: 1.7 $ * * This file is part of OpenOffice.org. * @@ -211,24 +211,6 @@ static oslVolumeDeviceHandle osl_isFloppyDrive(const sal_Char* pszPath); static oslFileError osl_mountFloppy(oslVolumeDeviceHandle hFloppy); static oslFileError osl_unmountFloppy(oslVolumeDeviceHandle hFloppy); - -#if defined(SOLARIS) -static sal_Bool osl_isFloppyMounted(sal_Char* pszPath, sal_Char* pszMountPath); -static sal_Bool osl_getFloppyMountEntry(const sal_Char* pszPath, sal_Char* pBuffer); -static sal_Bool osl_checkFloppyPath(sal_Char* pszPath, sal_Char* pszFilePath, sal_Char* pszDevicePath); -#endif - -#if defined(LINUX) -static sal_Bool osl_isFloppyMounted(oslVolumeDeviceHandleImpl* pDevice); -static sal_Bool osl_getFloppyMountEntry(const sal_Char* pszPath, oslVolumeDeviceHandleImpl* pItem); -#endif - - -#if defined(IRIX) -static sal_Bool osl_isFloppyMounted(oslVolumeDeviceHandleImpl* pDevice); -static sal_Bool osl_getFloppyMountEntry(const sal_Char* pszPath, oslVolumeDeviceHandleImpl* pItem); -#endif - #ifdef DEBUG_OSL_FILE static void osl_printFloppyHandle(oslVolumeDeviceHandleImpl* hFloppy); #endif @@ -1317,9 +1299,49 @@ typedef struct drivebpb USHORT attributes; // device attributes BYTE fill[6]; // documented for IOCtl } DRIVEBPB; // end of struct "drivebpb" + +struct CDInfo { + USHORT usCount; + USHORT usFirst; +}; + #pragma pack(pop) /*****************************************************************************/ +// Get number of cdrom readers +/*****************************************************************************/ +BOOL GetCDInfo( CDInfo * pCDInfo ) +{ + HFILE hFileCD; + ULONG ulAction; + + if( NO_ERROR == DosOpen( (PCSZ)"\\DEV\\CD-ROM2$", + &hFileCD, &ulAction, 0, FILE_NORMAL, + OPEN_ACTION_OPEN_IF_EXISTS, + OPEN_SHARE_DENYNONE | OPEN_ACCESS_READONLY, NULL )) { + ULONG ulDataSize = sizeof(CDInfo); + APIRET rc = DosDevIOCtl( hFileCD, 0x82, 0x60, NULL, 0, + NULL, (PVOID)pCDInfo, ulDataSize, &ulDataSize); + DosClose( hFileCD); + if(rc == NO_ERROR) + return TRUE; + } + // failed + pCDInfo->usFirst = 0; + pCDInfo->usCount = 0; + return FALSE; +} + +/*****************************************************************************/ +// Determine if unit is a cdrom or not +/*****************************************************************************/ +BOOL DriveIsCDROM(UINT uiDrive, CDInfo *pCDInfo) +{ + return (uiDrive >= pCDInfo->usFirst) + && (uiDrive < (pCDInfo->usFirst + pCDInfo->usCount)); +} + +/*****************************************************************************/ // Determine attached fstype, e.g. HPFS for specified drive /*****************************************************************************/ BOOL TxFsType // RET FS type resolved @@ -1430,6 +1452,14 @@ static oslFileError get_drive_type(const char* path, oslVolumeInfo* pInfo) return osl_File_E_None; } + // query system for CD drives + CDInfo cdInfo; + GetCDInfo(&cdInfo); + + // query if drive is a CDROM + if (DriveIsCDROM( Drive_Letter - 'A', &cdInfo)) + pInfo->uAttributes |= osl_Volume_Attribute_CompactDisc | osl_Volume_Attribute_Removeable; + if (TxFsIsRemovable( (char*)path)) pInfo->uAttributes |= osl_Volume_Attribute_Removeable; @@ -1441,6 +1471,7 @@ static oslFileError get_drive_type(const char* path, oslVolumeInfo* pInfo) //- Note, connected Win-NT drives use the REAL FS-name like NTFS! if ((strncasecmp( fstype, "LAN", 3) == 0) //- OS/2 LAN drives + || (strncasecmp( fstype, "NDFS", 4) == 0) //- NetDrive || (strncasecmp( fstype, "REMOTE", 5) == 0) ) //- NT disconnected pInfo->uAttributes |= osl_Volume_Attribute_Remote; else if (strncasecmp( fstype, "RAMFS", 5) == 0) @@ -3063,1011 +3094,6 @@ static void osl_freeVolumeDeviceHandleImpl (oslVolumeDeviceHandleImpl* pHandle) rtl_freeMemory (pHandle); } -/****************************************************************************** - * - * SOLARIS FLOPPY FUNCTIONS - * - *****************************************************************************/ - -#if defined(SOLARIS) -/* compare a given devicename with the typical device names on a Solaris box */ -static sal_Bool -osl_isAFloppyDevice (const char* pDeviceName) -{ - const char* pFloppyDevice [] = { - "/dev/fd", "/dev/rfd", - "/dev/diskette", "/dev/rdiskette", - "/vol/dev/diskette", "/vol/dev/rdiskette" - }; - - int i; - for (i = 0; i < (sizeof(pFloppyDevice)/sizeof(pFloppyDevice[0])); i++) - { - if (strncmp(pDeviceName, pFloppyDevice[i], strlen(pFloppyDevice[i])) == 0) - return sal_True; - } - return sal_False; -} - -/* compare two directories whether the first may be a parent of the second. this - * does not realpath() resolving */ -static sal_Bool -osl_isAParentDirectory (const char* pParentDir, const char* pSubDir) -{ - return strncmp(pParentDir, pSubDir, strlen(pParentDir)) == 0; -} - -/* the name of the routine is obviously silly. But anyway create a - * oslVolumeDeviceHandle with correct mount point, device name and a resolved filepath - * only if pszPath points to file or directory on a floppy */ -static oslVolumeDeviceHandle -osl_isFloppyDrive(const sal_Char* pszPath) -{ - FILE* pMountTab; - struct mnttab aMountEnt; - oslVolumeDeviceHandleImpl* pHandle; - - if ((pHandle = osl_newVolumeDeviceHandleImpl()) == NULL) - { - return NULL; - } - if (realpath(pszPath, pHandle->pszFilePath) == NULL) - { - osl_freeVolumeDeviceHandleImpl (pHandle); - return NULL; - } - if ((pMountTab = fopen (MOUNTTAB, "r")) == NULL) - { - osl_freeVolumeDeviceHandleImpl (pHandle); - return NULL; - } - - while (getmntent(pMountTab, &aMountEnt) == 0) - { - const char *pMountPoint = aMountEnt.mnt_mountp; - const char *pDevice = aMountEnt.mnt_special; - if ( osl_isAParentDirectory (aMountEnt.mnt_mountp, pHandle->pszFilePath) - && osl_isAFloppyDevice (aMountEnt.mnt_special)) - { - /* skip the last item for it is the name of the disk */ - char * pc = strrchr( aMountEnt.mnt_special, '/' ); - - if ( NULL != pc ) - { - int len = pc - aMountEnt.mnt_special; - - strncpy( pHandle->pszDevice, aMountEnt.mnt_special, len ); - pHandle->pszDevice[len] = '\0'; - } - else - { - /* #106048 use save str functions to avoid buffer overflows */ - memset(pHandle->pszDevice, 0, sizeof(pHandle->pszDevice)); - strncpy(pHandle->pszDevice, aMountEnt.mnt_special, sizeof(pHandle->pszDevice) - 1); - } - - /* remember the mount point */ - memset(pHandle->pszMountPoint, 0, sizeof(pHandle->pszMountPoint)); - strncpy(pHandle->pszMountPoint, aMountEnt.mnt_mountp, sizeof(pHandle->pszMountPoint) - 1); - - fclose (pMountTab); - return pHandle; - } - } - - fclose (pMountTab); - osl_freeVolumeDeviceHandleImpl (pHandle); - return NULL; -} - -static oslFileError osl_mountFloppy(oslVolumeDeviceHandle hFloppy) -{ - FILE* pMountTab; - struct mnttab aMountEnt; - oslVolumeDeviceHandleImpl* pHandle = (oslVolumeDeviceHandleImpl*) hFloppy; - - int nRet=0; - sal_Char pszCmd[512] = ""; - - if ( pHandle == 0 ) - return osl_File_E_INVAL; - - /* FIXME: don't know what this is good for */ - if ( pHandle->ident[0] != 'O' || pHandle->ident[1] != 'V' || pHandle->ident[2] != 'D' || pHandle->ident[3] != 'H' ) - return osl_File_E_INVAL; - - snprintf(pszCmd, sizeof(pszCmd), "eject -q %s > /dev/null 2>&1", pHandle->pszDevice); - - nRet = system( pszCmd ); - - switch ( WEXITSTATUS(nRet) ) - { - case 0: - { - /* lookup the device in mount tab again */ - if ((pMountTab = fopen (MOUNTTAB, "r")) == NULL) - return osl_File_E_BUSY; - - while (getmntent(pMountTab, &aMountEnt) == 0) - { - const char *pMountPoint = aMountEnt.mnt_mountp; - const char *pDevice = aMountEnt.mnt_special; - if ( 0 == strncmp( pHandle->pszDevice, aMountEnt.mnt_special, strlen(pHandle->pszDevice) ) ) - { - memset(pHandle->pszMountPoint, 0, sizeof(pHandle->pszMountPoint)); - strncpy (pHandle->pszMountPoint, aMountEnt.mnt_mountp, sizeof(pHandle->pszMountPoint) - 1); - - fclose (pMountTab); - return osl_File_E_None; - } - } - - fclose (pMountTab); - return osl_File_E_BUSY; - } - //break; // break not necessary here, see return statements before - - case 1: - return osl_File_E_BUSY; - - default: - break; - } - - return osl_File_E_BUSY; -} - -static oslFileError osl_unmountFloppy(oslVolumeDeviceHandle hFloppy) -{ -// FILE* pMountTab; -// struct mnttab aMountEnt; - oslVolumeDeviceHandleImpl* pHandle = (oslVolumeDeviceHandleImpl*) hFloppy; - - int nRet=0; - sal_Char pszCmd[512] = ""; - - if ( pHandle == 0 ) - return osl_File_E_INVAL; - - /* FIXME: don't know what this is good for */ - if ( pHandle->ident[0] != 'O' || pHandle->ident[1] != 'V' || pHandle->ident[2] != 'D' || pHandle->ident[3] != 'H' ) - return osl_File_E_INVAL; - - snprintf(pszCmd, sizeof(pszCmd), "eject %s > /dev/null 2>&1", pHandle->pszDevice); - - nRet = system( pszCmd ); - - switch ( WEXITSTATUS(nRet) ) - { - case 0: - { - FILE* pMountTab; - struct mnttab aMountEnt; - - /* lookup if device is still in mount tab */ - if ((pMountTab = fopen (MOUNTTAB, "r")) == NULL) - return osl_File_E_BUSY; - - while (getmntent(pMountTab, &aMountEnt) == 0) - { - const char *pMountPoint = aMountEnt.mnt_mountp; - const char *pDevice = aMountEnt.mnt_special; - if ( 0 == strncmp( pHandle->pszDevice, aMountEnt.mnt_special, strlen(pHandle->pszDevice) ) ) - { - fclose (pMountTab); - return osl_File_E_BUSY; - } - } - - fclose (pMountTab); - pHandle->pszMountPoint[0] = 0; - return osl_File_E_None; - } - - //break; //break not necessary, see return statements before - - case 1: - return osl_File_E_NODEV; - - case 4: - pHandle->pszMountPoint[0] = 0; - return osl_File_E_None; - - default: - break; - } - - return osl_File_E_BUSY; -} - -#endif /* SOLARIS */ - -/****************************************************************************** - * - * LINUX FLOPPY FUNCTIONS - * - *****************************************************************************/ - -#if defined(LINUX) -static oslVolumeDeviceHandle -osl_isFloppyDrive (const sal_Char* pszPath) -{ - oslVolumeDeviceHandleImpl* pItem = osl_newVolumeDeviceHandleImpl(); - if (osl_getFloppyMountEntry(pszPath, pItem)) - return (oslVolumeDeviceHandle) pItem; - - osl_freeVolumeDeviceHandleImpl (pItem); - return 0; -} -#endif /* LINUX */ - -#if defined(LINUX) -static oslFileError osl_mountFloppy(oslVolumeDeviceHandle hFloppy) -{ - sal_Bool bRet = sal_False; - oslVolumeDeviceHandleImpl* pItem=0; - int nRet; - sal_Char pszCmd[PATH_MAX]; - sal_Char* pszMountProg = "mount"; - sal_Char* pszSuDo = 0; - sal_Char* pszTmp = 0; - - pszCmd[0] = '\0'; - -#ifdef TRACE_OSL_FILE - fprintf(stderr,"In osl_mountFloppy\n"); -#endif - - pItem = (oslVolumeDeviceHandleImpl*) hFloppy; - - if ( pItem == 0 ) - { -#ifdef TRACE_OSL_FILE - fprintf(stderr,"Out osl_mountFloppy [pItem == 0]\n"); -#endif - - return osl_File_E_INVAL; - } - - if ( pItem->ident[0] != 'O' || pItem->ident[1] != 'V' || pItem->ident[2] != 'D' || pItem->ident[3] != 'H' ) - { -#ifdef TRACE_OSL_FILE - fprintf(stderr,"Out osl_mountFloppy [invalid handle]\n"); -#endif - return osl_File_E_INVAL; - } - - bRet = osl_isFloppyMounted(pItem); - if ( bRet == sal_True ) - { -#ifdef DEBUG_OSL_FILE - fprintf(stderr,"detected mounted floppy at '%s'\n",pItem->pszMountPoint); -#endif - return osl_File_E_BUSY; - } - - /* mfe: we can't use the mount(2) system call!!! */ - /* even if we are root */ - /* since mtab is not updated!!! */ - /* but we need it to be updated */ - /* some "magic" must be done */ - -/* nRet = mount(pItem->pszDevice,pItem->pszMountPoint,0,0,0); */ -/* if ( nRet != 0 ) */ -/* { */ -/* nRet=errno; */ -/* #ifdef DEBUG_OSL_FILE */ -/* perror("mount"); */ -/* #endif */ -/* } */ - - pszTmp = getenv("SAL_MOUNT_MOUNTPROG"); - if ( pszTmp != 0 ) - { - pszMountProg=pszTmp; - } - - pszTmp=getenv("SAL_MOUNT_SU_DO"); - if ( pszTmp != 0 ) - { - pszSuDo=pszTmp; - } - - if ( pszSuDo != 0 ) - { - snprintf(pszCmd, sizeof(pszCmd), "%s %s %s %s",pszSuDo,pszMountProg,pItem->pszDevice,pItem->pszMountPoint); - } - else - { - snprintf(pszCmd, sizeof(pszCmd), "%s %s",pszMountProg,pItem->pszMountPoint); - } - - -#ifdef DEBUG_OSL_FILE - fprintf(stderr,"executing '%s'\n",pszCmd); -#endif - - nRet = system(pszCmd); - -#ifdef DEBUG_OSL_FILE - fprintf(stderr,"call returned '%i'\n",nRet); - fprintf(stderr,"exit status is '%i'\n", WEXITSTATUS(nRet)); -#endif - - - switch ( WEXITSTATUS(nRet) ) - { - case 0: - nRet=0; - break; - - case 2: - nRet=EPERM; - break; - - case 4: - nRet=ENOENT; - break; - - case 8: - nRet=EINTR; - break; - - case 16: - nRet=EPERM; - break; - - case 32: - nRet=EBUSY; - break; - - case 64: - nRet=EAGAIN; - break; - - default: - nRet=EBUSY; - break; - } - - return ((0 == nRet) ? oslTranslateFileError(OSL_FET_SUCCESS, nRet) : oslTranslateFileError(OSL_FET_ERROR, nRet)); -} -#endif /* LINUX */ - - -#if defined(LINUX) -static oslFileError osl_unmountFloppy(oslVolumeDeviceHandle hFloppy) -{ - oslVolumeDeviceHandleImpl* pItem=0; - int nRet=0; - sal_Char pszCmd[PATH_MAX]; - sal_Char* pszTmp = 0; - sal_Char* pszSuDo = 0; - sal_Char* pszUmountProg = "umount"; - - pszCmd[0] = '\0'; - -#ifdef TRACE_OSL_FILE - fprintf(stderr,"In osl_unmountFloppy\n"); -#endif - - pItem = (oslVolumeDeviceHandleImpl*) hFloppy; - - if ( pItem == 0 ) - { -#ifdef TRACE_OSL_FILE - fprintf(stderr,"Out osl_unmountFloppy [pItem==0]\n"); -#endif - return osl_File_E_INVAL; - } - - if ( pItem->ident[0] != 'O' || pItem->ident[1] != 'V' || pItem->ident[2] != 'D' || pItem->ident[3] != 'H' ) - { -#ifdef TRACE_OSL_FILE - fprintf(stderr,"Out osl_unmountFloppy [invalid handle]\n"); -#endif - return osl_File_E_INVAL; - } - - /* mfe: we can't use the umount(2) system call!!! */ - /* even if we are root */ - /* since mtab is not updated!!! */ - /* but we need it to be updated */ - /* some "magic" must be done */ - -/* nRet=umount(pItem->pszDevice); */ -/* if ( nRet != 0 ) */ -/* { */ -/* nRet = errno; */ - -/* #ifdef DEBUG_OSL_FILE */ -/* perror("mount"); */ -/* #endif */ -/* } */ - - - pszTmp = getenv("SAL_MOUNT_UMOUNTPROG"); - if ( pszTmp != 0 ) - { - pszUmountProg=pszTmp; - } - - pszTmp = getenv("SAL_MOUNT_SU_DO"); - if ( pszTmp != 0 ) - { - pszSuDo=pszTmp; - } - - if ( pszSuDo != 0 ) - { - snprintf(pszCmd, sizeof(pszCmd), "%s %s %s",pszSuDo,pszUmountProg,pItem->pszMountPoint); - } - else - { - snprintf(pszCmd, sizeof(pszCmd), "%s %s",pszUmountProg,pItem->pszMountPoint); - } - - -#ifdef DEBUG_OSL_FILE - fprintf(stderr,"executing '%s'\n",pszCmd); -#endif - - nRet = system(pszCmd); - -#ifdef DEBUG_OSL_FILE - fprintf(stderr,"call returned '%i'\n",nRet); - fprintf(stderr,"exit status is '%i'\n", WEXITSTATUS(nRet)); -#endif - - switch ( WEXITSTATUS(nRet) ) - { - case 0: - nRet=0; - break; - - default: - nRet=EBUSY; - break; - } - -#ifdef TRACE_OSL_FILE - fprintf(stderr,"Out osl_unmountFloppy [ok]\n"); -#endif - - return ((0 == nRet) ? oslTranslateFileError(OSL_FET_SUCCESS, nRet) : oslTranslateFileError(OSL_FET_ERROR, nRet)); - -/* return osl_File_E_None;*/ -} - -#endif /* LINUX */ - -#if defined(LINUX) -static sal_Bool -osl_getFloppyMountEntry(const sal_Char* pszPath, oslVolumeDeviceHandleImpl* pItem) -{ - struct mntent* pMountEnt; - FILE* pMountTab; - - pMountTab = setmntent (MOUNTTAB, "r"); - if (pMountTab == 0) - return sal_False; - - while ((pMountEnt = getmntent(pMountTab)) != 0) - { - if ( strncmp(pMountEnt->mnt_dir, pszPath, strlen(pMountEnt->mnt_dir)) == 0 - && strncmp(pMountEnt->mnt_fsname, "/dev/fd", strlen("/dev/fd")) == 0) - { - memset(pItem->pszMountPoint, 0, sizeof(pItem->pszMountPoint)); - strncpy(pItem->pszMountPoint, pMountEnt->mnt_dir, sizeof(pItem->pszMountPoint) - 1); - - memset(pItem->pszFilePath, 0, sizeof(pItem->pszFilePath)); - strncpy(pItem->pszFilePath, pMountEnt->mnt_dir, sizeof(pItem->pszFilePath) - 1); - - memset(pItem->pszDevice, 0, sizeof(pItem->pszDevice)); - strncpy(pItem->pszDevice, pMountEnt->mnt_fsname, sizeof(pItem->pszDevice) - 1); - - endmntent (pMountTab); - return sal_True; - } - } - - endmntent (pMountTab); - return sal_False; -} -#endif /* LINUX */ - -#if defined(LINUX) -static sal_Bool -osl_isFloppyMounted (oslVolumeDeviceHandleImpl* pDevice) -{ - oslVolumeDeviceHandleImpl aItem; - - if ( osl_getFloppyMountEntry (pDevice->pszMountPoint, &aItem) - && strcmp (aItem.pszMountPoint, pDevice->pszMountPoint) == 0 - && strcmp (aItem.pszDevice, pDevice->pszDevice) == 0) - { - return sal_True; - } - return sal_False; -} -#endif /* LINUX */ - -/****************************************************************************** - * - * IRIX FLOPPY FUNCTIONS - * - *****************************************************************************/ - -#if defined(IRIX) -static oslVolumeDeviceHandle osl_isFloppyDrive(const sal_Char* pszPath) -{ - oslVolumeDeviceHandleImpl* pItem = osl_newVolumeDeviceHandleImpl (); - sal_Bool bRet = sal_False; - -#ifdef TRACE_OSL_FILE - fprintf(stderr,"In osl_isFloppyDrive\n"); -#endif - - bRet=osl_getFloppyMountEntry(pszPath,pItem); - - if ( bRet == sal_False ) - { -#ifdef TRACE_OSL_FILE - fprintf(stderr,"Out osl_isFloppyDrive [not a floppy]\n"); -#endif - rtl_freeMemory(pItem); - return 0; - } - - -#ifdef DEBUG_OSL_FILE - osl_printFloppyHandle(pItem); -#endif -#ifdef TRACE_OSL_FILE - fprintf(stderr,"Out osl_isFloppyDrive [ok]\n"); -#endif - - return (oslVolumeDeviceHandle) pItem; -} - - -static oslFileError osl_mountFloppy(oslVolumeDeviceHandle hFloppy) -{ - sal_Bool bRet = sal_False; - oslVolumeDeviceHandleImpl* pItem=0; - int nRet; - sal_Char pszCmd[PATH_MAX]; - sal_Char* pszMountProg = "mount"; - sal_Char* pszSuDo = 0; - sal_Char* pszTmp = 0; - - pszCmd[0] = '\0'; - -#ifdef TRACE_OSL_FILE - fprintf(stderr,"In osl_mountFloppy\n"); -#endif - - pItem = (oslVolumeDeviceHandleImpl*) hFloppy; - - if ( pItem == 0 ) - { -#ifdef TRACE_OSL_FILE - fprintf(stderr,"Out osl_mountFloppy [pItem == 0]\n"); -#endif - - return osl_File_E_INVAL; - } - - if ( pItem->ident[0] != 'O' || pItem->ident[1] != 'V' || pItem->ident[2] != 'D' || pItem->ident[3] != 'H' ) - { -#ifdef TRACE_OSL_FILE - fprintf(stderr,"Out osl_mountFloppy [invalid handle]\n"); -#endif - return osl_File_E_INVAL; - } - - bRet = osl_isFloppyMounted(pItem); - if ( bRet == sal_True ) - { -#ifdef DEBUG_OSL_FILE - fprintf(stderr,"detected mounted floppy at '%s'\n",pItem->pszMountPoint); -#endif - return osl_File_E_BUSY; - } - - /* mfe: we can't use the mount(2) system call!!! */ - /* even if we are root */ - /* since mtab is not updated!!! */ - /* but we need it to be updated */ - /* some "magic" must be done */ - -/* nRet = mount(pItem->pszDevice,pItem->pszMountPoint,0,0,0); */ -/* if ( nRet != 0 ) */ -/* { */ -/* nRet=errno; */ -/* #ifdef DEBUG_OSL_FILE */ -/* perror("mount"); */ -/* #endif */ -/* } */ - - pszTmp = getenv("SAL_MOUNT_MOUNTPROG"); - if ( pszTmp != 0 ) - { - pszMountProg=pszTmp; - } - - pszTmp=getenv("SAL_MOUNT_SU_DO"); - if ( pszTmp != 0 ) - { - pszSuDo=pszTmp; - } - - if ( pszSuDo != 0 ) - { - snprintf(pszCmd, sizeof(pszCmd), "%s %s %s %s",pszSuDo,pszMountProg,pItem->pszDevice,pItem->pszMountPoint); - } - else - { - snprintf(pszCmd, sizeof(pszCmd), "%s %s",pszMountProg,pItem->pszMountPoint); - } - - -#ifdef DEBUG_OSL_FILE - fprintf(stderr,"executing '%s'\n",pszCmd); -#endif - - nRet = system(pszCmd); - -#ifdef DEBUG_OSL_FILE - fprintf(stderr,"call returned '%i'\n",nRet); - fprintf(stderr,"exit status is '%i'\n", WEXITSTATUS(nRet)); -#endif - - - switch ( WEXITSTATUS(nRet) ) - { - case 0: - nRet=0; - break; - - case 2: - nRet=EPERM; - break; - - case 4: - nRet=ENOENT; - break; - - case 8: - nRet=EINTR; - break; - - case 16: - nRet=EPERM; - break; - - case 32: - nRet=EBUSY; - break; - - case 64: - nRet=EAGAIN; - break; - - default: - nRet=EBUSY; - break; - } - - return ((0 == nRet) ? oslTranslateFileError(OSL_FET_SUCCESS, nRet) : oslTranslateFileError(OSL_FET_ERROR, nRet)); -} - -static oslFileError osl_unmountFloppy(oslVolumeDeviceHandle hFloppy) -{ - oslVolumeDeviceHandleImpl* pItem=0; - int nRet=0; - sal_Char pszCmd[PATH_MAX]; - sal_Char* pszTmp = 0; - sal_Char* pszSuDo = 0; - sal_Char* pszUmountProg = "umount"; - - pszCmd[0] = '\0'; - -#ifdef TRACE_OSL_FILE - fprintf(stderr,"In osl_unmountFloppy\n"); -#endif - - pItem = (oslVolumeDeviceHandleImpl*) hFloppy; - - if ( pItem == 0 ) - { -#ifdef TRACE_OSL_FILE - fprintf(stderr,"Out osl_unmountFloppy [pItem==0]\n"); -#endif - return osl_File_E_INVAL; - } - - if ( pItem->ident[0] != 'O' || pItem->ident[1] != 'V' || pItem->ident[2] != 'D' || pItem->ident[3] != 'H' ) - { -#ifdef TRACE_OSL_FILE - fprintf(stderr,"Out osl_unmountFloppy [invalid handle]\n"); -#endif - return osl_File_E_INVAL; - } - - /* mfe: we can't use the umount(2) system call!!! */ - /* even if we are root */ - /* since mtab is not updated!!! */ - /* but we need it to be updated */ - /* some "magic" must be done */ - -/* nRet=umount(pItem->pszDevice); */ -/* if ( nRet != 0 ) */ -/* { */ -/* nRet = errno; */ - -/* #ifdef DEBUG_OSL_FILE */ -/* perror("mount"); */ -/* #endif */ -/* } */ - - - pszTmp = getenv("SAL_MOUNT_UMOUNTPROG"); - if ( pszTmp != 0 ) - { - pszUmountProg=pszTmp; - } - - pszTmp = getenv("SAL_MOUNT_SU_DO"); - if ( pszTmp != 0 ) - { - pszSuDo=pszTmp; - } - - if ( pszSuDo != 0 ) - { - snprintf(pszCmd, sizeof(pszCmd), "%s %s %s",pszSuDo,pszUmountProg,pItem->pszMountPoint); - } - else - { - snprintf(pszCmd, sizeof(pszCmd), "%s %s",pszUmountProg,pItem->pszMountPoint); - } - - -#ifdef DEBUG_OSL_FILE - fprintf(stderr,"executing '%s'\n",pszCmd); -#endif - - nRet = system(pszCmd); - -#ifdef DEBUG_OSL_FILE - fprintf(stderr,"call returned '%i'\n",nRet); - fprintf(stderr,"exit status is '%i'\n", WEXITSTATUS(nRet)); -#endif - - switch ( WEXITSTATUS(nRet) ) - { - case 0: - nRet=0; - break; - - default: - nRet=EBUSY; - break; - } - -#ifdef TRACE_OSL_FILE - fprintf(stderr,"Out osl_unmountFloppy [ok]\n"); -#endif - - return ((0 == nRet) ? oslTranslateFileError(OSL_FET_SUCCESS, nRet) : oslTranslateFileError(OSL_FET_ERROR, nRet)); - -/* return osl_File_E_None;*/ -} - -static sal_Bool osl_getFloppyMountEntry(const sal_Char* pszPath, oslVolumeDeviceHandleImpl* pItem) -{ - struct mntent* pMountEnt=0; - sal_Char buffer[PATH_MAX]; - FILE* mntfile=0; - int nRet=0; - - buffer[0] = '\0'; - - mntfile = setmntent(MOUNTTAB,"r"); - -#ifdef TRACE_OSL_FILE - fprintf(stderr,"In osl_getFloppyMountEntry\n"); -#endif - - memset(buffer, 0, sizeof(buffer)); - strncpy(buffer, pszPath, sizeof(buffer) - 1); - -#ifdef DEBUG_OSL_FILE - fprintf(stderr,"Checking mount of %s\n",buffer); -#endif - - - if ( mntfile == 0 ) - { - nRet=errno; -#ifdef DEBUG_OSL_FILE - perror("mounttab"); -#endif -#ifdef TRACE_OSL_FILE - fprintf(stderr,"Out osl_getFloppyMountEntry [mntfile]\n"); -#endif - return sal_False; - } - - pMountEnt=getmntent(mntfile); - while ( pMountEnt != 0 ) - { -#ifdef DEBUG_OSL_FILE -/* fprintf(stderr,"mnt_fsname : %s\n",pMountEnt->mnt_fsname); */ -/* fprintf(stderr,"mnt_dir : %s\n",pMountEnt->mnt_dir); */ -/* fprintf(stderr,"mnt_type : %s\n",pMountEnt->mnt_type);*/ -#endif - if ( strcmp(pMountEnt->mnt_dir,buffer) == 0 && - strncmp(pMountEnt->mnt_fsname,"/dev/fd",strlen("/dev/fd")) == 0 ) - { - - memset(pItem->pszMountPoint, 0, sizeof(pItem->pszMountPoint)); - strncpy(pItem->pszMountPoint, pMountEnt->mnt_dir, sizeof(pItem->pszMountPoint) - 1); - - memset(pItem->pszFilePath, 0, sizeof(pItem->pszFilePath)); - strncpy(pItem->pszFilePath, pMountEnt->mnt_dir, sizeof(pItem->pszFilePath) - 1); - - memset(pItem->pszDevice, 0, sizeof(pItem->pszDevice)); - strncpy(pItem->pszDevice, pMountEnt->mnt_fsname, sizeof(pItem->pszDevice) - 1); - - fclose(mntfile); -#ifdef DEBUG_OSL_FILE - fprintf(stderr,"Mount Point found '%s'\n",pItem->pszMountPoint); -#endif -#ifdef TRACE_OSL_FILE - fprintf(stderr,"Out osl_getFloppyMountEntry [found]\n"); -#endif - return sal_True; - } -#ifdef DEBUG_OSL_FILE -/* fprintf(stderr,"=================\n");*/ -#endif - pMountEnt=getmntent(mntfile); - } - -#ifdef TRACE_OSL_FILE - fprintf(stderr,"Out osl_getFloppyMountEntry [not found]\n"); -#endif - - fclose(mntfile); - return sal_False; -} - -static sal_Bool osl_isFloppyMounted(oslVolumeDeviceHandleImpl* pDevice) -{ - sal_Char buffer[PATH_MAX]; - oslVolumeDeviceHandleImpl* pItem=0; - sal_Bool bRet=0; - - buffer[0] = '\0'; - -#ifdef TRACE_OSL_FILE - fprintf(stderr,"In osl_isFloppyMounted\n"); -#endif - - pItem = osl_newVolumeDeviceHandleImpl (); - if ( pItem == 0 ) - return osl_File_E_NOMEM; - - memset(buffer, 0, sizeof(buffer)); - strncpy(buffer, pDevice->pszMountPoint, sizeof(buffer) - 1); - -#ifdef DEBUG_OSL_FILE - fprintf(stderr,"Checking mount of %s\n",buffer); -#endif - - bRet = osl_getFloppyMountEntry(buffer,pItem); - - if ( bRet == sal_False ) - { -#ifdef TRACE_OSL_FILE - fprintf(stderr,"Out osl_isFloppyMounted [not mounted]\n"); -#endif - return sal_False; - } - - if (strcmp(pItem->pszMountPoint, pDevice->pszMountPoint) == 0 && - strcmp(pItem->pszDevice,pDevice->pszDevice) == 0) - { -#ifdef TRACE_OSL_FILE - fprintf(stderr,"Out osl_isFloppyMounted [is mounted]\n"); -#endif - rtl_freeMemory(pItem); - return sal_True; - } - -#ifdef TRACE_OSL_FILE - fprintf(stderr,"Out osl_isFloppyMounted [may be EBUSY]\n"); -#endif - - rtl_freeMemory(pItem); - return sal_False; -} -#endif /* IRIX */ - - -/* NetBSD floppy functions have to be added here. Until we have done that, - * we use the MACOSX definitions for nonexistent floppy. - * */ - -/****************************************************************************** - * - * MAC OS X FLOPPY FUNCTIONS - * - *****************************************************************************/ - -#if (defined(MACOSX) || defined(NETBSD) || defined(FREEBSD)) -static oslVolumeDeviceHandle osl_isFloppyDrive(const sal_Char* pszPath) -{ - return NULL; -} -#endif /* MACOSX */ - -#if ( defined(MACOSX) || defined(NETBSD) || defined(FREEBSD)) -static oslFileError osl_mountFloppy(oslVolumeDeviceHandle hFloppy) -{ - return osl_File_E_BUSY; -} -#endif /* MACOSX */ - -#if ( defined(MACOSX) || defined(NETBSD) || defined(FREEBSD)) -static oslFileError osl_unmountFloppy(oslVolumeDeviceHandle hFloppy) -{ - return osl_File_E_BUSY; -} -#endif /* MACOSX */ - -#if ( defined(MACOSX) || defined(NETBSD) || defined(FREEBSD)) -static sal_Bool osl_getFloppyMountEntry(const sal_Char* pszPath, oslVolumeDeviceHandleImpl* pItem) -{ - return sal_False; -} -#endif /* MACOSX */ - -#if ( defined(MACOSX) || defined(NETBSD) || defined(FREEBSD)) -static sal_Bool osl_isFloppyMounted(oslVolumeDeviceHandleImpl* pDevice) -{ - return sal_False; -} -#endif /* MACOSX */ - - -#ifdef DEBUG_OSL_FILE -static void osl_printFloppyHandle(oslVolumeDeviceHandleImpl* pItem) -{ - if (pItem == 0 ) - { - fprintf(stderr,"NULL Handle\n"); - return; - } - if ( pItem->ident[0] != 'O' || pItem->ident[1] != 'V' || pItem->ident[2] != 'D' || pItem->ident[3] != 'H' ) - { -#ifdef TRACE_OSL_FILE - fprintf(stderr,"Invalid Handle]\n"); -#endif - return; - } - - - fprintf(stderr,"MountPoint : '%s'\n",pItem->pszMountPoint); - fprintf(stderr,"FilePath : '%s'\n",pItem->pszFilePath); - fprintf(stderr,"Device : '%s'\n",pItem->pszDevice); - - return; -} -#endif - /****************************************************************************** * @@ -4128,4 +3154,3 @@ static void osl_printFloppyHandle(oslVolumeDeviceHandleImpl* pItem) #endif #endif /* OS2 */ - |