Kaydet (Commit) 4fa8d043 authored tarafından François Tigeot's avatar François Tigeot

Remove unused floppy-handling code

üst 01ea91ef
......@@ -110,31 +110,6 @@ typedef struct _oslVolumeDeviceHandleImpl
sal_uInt32 RefCount;
} oslVolumeDeviceHandleImpl;
/******************************************************************************
*
* 'removeable device' aka floppy functions
*
*****************************************************************************/
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 /* SOLARIS */
#if defined(LINUX)
static sal_Bool osl_isFloppyMounted(oslVolumeDeviceHandleImpl* pDevice);
static sal_Bool osl_getFloppyMountEntry(const sal_Char* pszPath, oslVolumeDeviceHandleImpl* pItem);
#endif /* LINUX */
#ifdef DEBUG_OSL_FILE
static void osl_printFloppyHandle(oslVolumeDeviceHandleImpl* hFloppy);
#endif /* DEBUG_OSL_FILE */
/******************************************************************************
*
* C-String Function Declarations
......@@ -376,20 +351,6 @@ static oslFileError osl_psz_getVolumeInformation (
#endif /* __OSL_STATFS_TYPENAME */
if (uFieldMask & osl_VolumeInfo_Mask_DeviceHandle)
{
/* FIXME: check also entries in mntent for the device
and fill it with correct values */
*pInfo->pDeviceHandle = osl_isFloppyDrive(pszDirectory);
if (*pInfo->pDeviceHandle)
{
pInfo->uValidFields |= osl_VolumeInfo_Mask_DeviceHandle;
pInfo->uAttributes |= osl_Volume_Attribute_Removeable;
pInfo->uValidFields |= osl_VolumeInfo_Mask_Attributes;
}
}
return osl_File_E_None;
}
......@@ -408,8 +369,6 @@ oslFileError osl_unmountVolumeDevice( oslVolumeDeviceHandle Handle )
{
oslFileError tErr = osl_File_E_NOSYS;
tErr = osl_unmountFloppy(Handle);
/* Perhaps current working directory is set to mount point */
if ( tErr )
......@@ -419,9 +378,6 @@ oslFileError osl_unmountVolumeDevice( oslVolumeDeviceHandle Handle )
if ( pszHomeDir && strlen( pszHomeDir ) && 0 == chdir( pszHomeDir ) )
{
/* try again */
tErr = osl_unmountFloppy(Handle);
OSL_ENSURE( tErr, "osl_unmountVolumeDevice: CWD was set to volume mount point" );
}
}
......@@ -437,8 +393,6 @@ oslFileError osl_automountVolumeDevice( oslVolumeDeviceHandle Handle )
{
oslFileError tErr = osl_File_E_NOSYS;
tErr = osl_mountFloppy(Handle);
return tErr;
}
......@@ -475,11 +429,6 @@ oslFileError osl_getVolumeDeviceMountPath( oslVolumeDeviceHandle Handle, rtl_uSt
return osl_File_E_INVAL;
}
#ifdef DEBUG_OSL_FILE
fprintf(stderr,"Handle is:\n");
osl_printFloppyHandle(pItem);
#endif
snprintf(Buffer, sizeof(Buffer), "file://%s", pItem->pszMountPoint);
#ifdef DEBUG_OSL_FILE
......@@ -579,610 +528,4 @@ static void osl_freeVolumeDeviceHandleImpl (oslVolumeDeviceHandleImpl* pHandle)
}
#endif
/******************************************************************************
*
* 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 < SAL_N_ELEMENTS(pFloppyDevice); 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];
const 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;
const 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 */
/* NetBSD floppy functions have to be added here. Until we have done that,
* we use the MACOSX definitions for nonexistent floppy.
* */
/******************************************************************************
*
* Dummy floppy functions: no stinking floppies
*
*****************************************************************************/
#if (defined(MACOSX) || defined(IOS) || defined(ANDROID) || defined(NETBSD) || defined(FREEBSD) || \
defined(AIX) || defined(OPENBSD) || defined(DRAGONFLY))
static oslVolumeDeviceHandle osl_isFloppyDrive(const sal_Char* pszPath)
{
(void)pszPath;
return NULL;
}
#endif
#if ( defined(MACOSX) || defined(IOS) || defined(ANDROID) || defined(NETBSD) || defined(FREEBSD) || \
defined(AIX) || defined(OPENBSD) || defined(DRAGONFLY))
static oslFileError osl_mountFloppy(oslVolumeDeviceHandle hFloppy)
{
(void)hFloppy;
return osl_File_E_BUSY;
}
#endif
#if ( defined(MACOSX) || defined(IOS) || defined(ANDROID) || defined(NETBSD) || defined(FREEBSD) || \
defined(AIX) || defined(OPENBSD) || defined(DRAGONFLY))
static oslFileError osl_unmountFloppy(oslVolumeDeviceHandle hFloppy)
{
(void)hFloppy;
return osl_File_E_BUSY;
}
#endif
#if ( defined(NETBSD) || defined(FREEBSD) || defined(OPENBSD) || defined(DRAGONFLY) )
static sal_Bool osl_getFloppyMountEntry(const sal_Char* pszPath, oslVolumeDeviceHandleImpl* pItem)
{
return sal_False;
}
#endif /* NETBSD || FREEBSD || OPENBSD */
#if ( defined(NETBSD) || defined(FREEBSD) || defined(OPENBSD) || defined(DRAGONFLY) )
static sal_Bool osl_isFloppyMounted(oslVolumeDeviceHandleImpl* pDevice)
{
return sal_False;
}
#endif /* NETBSD || FREEBSD || OPENBSD */
#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
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment