1*87d2adbcSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*87d2adbcSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*87d2adbcSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*87d2adbcSAndrew Rist * distributed with this work for additional information 6*87d2adbcSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*87d2adbcSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*87d2adbcSAndrew Rist * "License"); you may not use this file except in compliance 9*87d2adbcSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*87d2adbcSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*87d2adbcSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*87d2adbcSAndrew Rist * software distributed under the License is distributed on an 15*87d2adbcSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*87d2adbcSAndrew Rist * KIND, either express or implied. See the License for the 17*87d2adbcSAndrew Rist * specific language governing permissions and limitations 18*87d2adbcSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*87d2adbcSAndrew Rist *************************************************************/ 21*87d2adbcSAndrew Rist 22*87d2adbcSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir 25cdf0e10cSrcweir /************************************************************************ 26cdf0e10cSrcweir * ToDo 27cdf0e10cSrcweir * 28cdf0e10cSrcweir * Fix osl_getCanonicalName 29cdf0e10cSrcweir * 30cdf0e10cSrcweir * - Fix: check for corresponding struct sizes in exported functions 31cdf0e10cSrcweir * - check size/use of oslDirectory 32cdf0e10cSrcweir * - check size/use of oslDirectoryItem 33cdf0e10cSrcweir * - check size/use of oslFileStatus 34cdf0e10cSrcweir * - check size/use of oslVolumeDeviceHandle 35cdf0e10cSrcweir * - check size/use of oslVolumeInfo 36cdf0e10cSrcweir * - check size/use of oslFileHandle 37cdf0e10cSrcweir ***********************************************************************/ 38cdf0e10cSrcweir 39cdf0e10cSrcweir #define INCL_DOSDEVIOCTL // OS2 device definitions 40cdf0e10cSrcweir 41cdf0e10cSrcweir #include "system.h" 42cdf0e10cSrcweir #include <rtl/alloc.h> 43cdf0e10cSrcweir 44cdf0e10cSrcweir #include "osl/file.hxx" 45cdf0e10cSrcweir 46cdf0e10cSrcweir 47cdf0e10cSrcweir #include <sal/types.h> 48cdf0e10cSrcweir #include <osl/thread.h> 49cdf0e10cSrcweir #include <osl/diagnose.h> 50cdf0e10cSrcweir #include "file_error_transl.h" 51cdf0e10cSrcweir #include <osl/time.h> 52cdf0e10cSrcweir 53cdf0e10cSrcweir #ifndef _FILE_URL_H_ 54cdf0e10cSrcweir #include "file_url.h" 55cdf0e10cSrcweir #endif 56cdf0e10cSrcweir 57cdf0e10cSrcweir #include "file_path_helper.hxx" 58cdf0e10cSrcweir #include "uunxapi.hxx" 59cdf0e10cSrcweir 60cdf0e10cSrcweir #ifndef _STRING_H_ 61cdf0e10cSrcweir #include <string.h> 62cdf0e10cSrcweir #endif 63cdf0e10cSrcweir 64cdf0e10cSrcweir #ifndef _CTYPE_H_ 65cdf0e10cSrcweir #include <ctype.h> 66cdf0e10cSrcweir #endif 67cdf0e10cSrcweir 68cdf0e10cSrcweir #ifndef _WCHAR_H_ 69cdf0e10cSrcweir #include <wchar.h> 70cdf0e10cSrcweir #endif 71cdf0e10cSrcweir 72cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1 73cdf0e10cSrcweir extern void debug_ustring(rtl_uString*); 74cdf0e10cSrcweir #endif 75cdf0e10cSrcweir 76cdf0e10cSrcweir 77cdf0e10cSrcweir #ifdef DEBUG_OSL_FILE 78cdf0e10cSrcweir # define PERROR( a, b ) perror( a ); fprintf( stderr, b ) 79cdf0e10cSrcweir #else 80cdf0e10cSrcweir # define PERROR( a, b ) 81cdf0e10cSrcweir #endif 82cdf0e10cSrcweir 83cdf0e10cSrcweir extern "C" oslFileHandle osl_createFileHandleFromFD( int fd ); 84cdf0e10cSrcweir 85cdf0e10cSrcweir struct errentry errtable[] = { 86cdf0e10cSrcweir { NO_ERROR, osl_File_E_None }, /* 0 */ 87cdf0e10cSrcweir { ERROR_INVALID_FUNCTION, osl_File_E_INVAL }, /* 1 */ 88cdf0e10cSrcweir { ERROR_FILE_NOT_FOUND, osl_File_E_NOENT }, /* 2 */ 89cdf0e10cSrcweir { ERROR_PATH_NOT_FOUND, osl_File_E_NOENT }, /* 3 */ 90cdf0e10cSrcweir { ERROR_TOO_MANY_OPEN_FILES, osl_File_E_MFILE }, /* 4 */ 91cdf0e10cSrcweir { ERROR_ACCESS_DENIED, osl_File_E_ACCES }, /* 5 */ 92cdf0e10cSrcweir { ERROR_INVALID_HANDLE, osl_File_E_BADF }, /* 6 */ 93cdf0e10cSrcweir { ERROR_ARENA_TRASHED, osl_File_E_NOMEM }, /* 7 */ 94cdf0e10cSrcweir { ERROR_NOT_ENOUGH_MEMORY, osl_File_E_NOMEM }, /* 8 */ 95cdf0e10cSrcweir { ERROR_INVALID_BLOCK, osl_File_E_NOMEM }, /* 9 */ 96cdf0e10cSrcweir { ERROR_BAD_ENVIRONMENT, osl_File_E_2BIG }, /* 10 */ 97cdf0e10cSrcweir { ERROR_BAD_FORMAT, osl_File_E_NOEXEC }, /* 11 */ 98cdf0e10cSrcweir { ERROR_INVALID_ACCESS, osl_File_E_INVAL }, /* 12 */ 99cdf0e10cSrcweir { ERROR_INVALID_DATA, osl_File_E_INVAL }, /* 13 */ 100cdf0e10cSrcweir { ERROR_INVALID_DRIVE, osl_File_E_NOENT }, /* 15 */ 101cdf0e10cSrcweir { ERROR_CURRENT_DIRECTORY, osl_File_E_ACCES }, /* 16 */ 102cdf0e10cSrcweir { ERROR_NOT_SAME_DEVICE, osl_File_E_XDEV }, /* 17 */ 103cdf0e10cSrcweir { ERROR_NO_MORE_FILES, osl_File_E_NOENT }, /* 18 */ 104cdf0e10cSrcweir { ERROR_NOT_READY, osl_File_E_NOTREADY }, /* 21 */ 105cdf0e10cSrcweir { ERROR_LOCK_VIOLATION, osl_File_E_ACCES }, /* 33 */ 106cdf0e10cSrcweir { ERROR_BAD_NETPATH, osl_File_E_NOENT }, /* 53 */ 107cdf0e10cSrcweir { ERROR_NETWORK_ACCESS_DENIED, osl_File_E_ACCES }, /* 65 */ 108cdf0e10cSrcweir { ERROR_BAD_NET_NAME, osl_File_E_NOENT }, /* 67 */ 109cdf0e10cSrcweir { ERROR_FILE_EXISTS, osl_File_E_EXIST }, /* 80 */ 110cdf0e10cSrcweir { ERROR_CANNOT_MAKE, osl_File_E_ACCES }, /* 82 */ 111cdf0e10cSrcweir { ERROR_FAIL_I24, osl_File_E_ACCES }, /* 83 */ 112cdf0e10cSrcweir { ERROR_INVALID_PARAMETER, osl_File_E_INVAL }, /* 87 */ 113cdf0e10cSrcweir { ERROR_NO_PROC_SLOTS, osl_File_E_AGAIN }, /* 89 */ 114cdf0e10cSrcweir { ERROR_DRIVE_LOCKED, osl_File_E_ACCES }, /* 108 */ 115cdf0e10cSrcweir { ERROR_BROKEN_PIPE, osl_File_E_PIPE }, /* 109 */ 116cdf0e10cSrcweir { ERROR_DISK_FULL, osl_File_E_NOSPC }, /* 112 */ 117cdf0e10cSrcweir { ERROR_INVALID_TARGET_HANDLE, osl_File_E_BADF }, /* 114 */ 118cdf0e10cSrcweir { ERROR_INVALID_HANDLE, osl_File_E_INVAL }, /* 124 */ 119cdf0e10cSrcweir { ERROR_WAIT_NO_CHILDREN, osl_File_E_CHILD }, /* 128 */ 120cdf0e10cSrcweir { ERROR_CHILD_NOT_COMPLETE, osl_File_E_CHILD }, /* 129 */ 121cdf0e10cSrcweir { ERROR_DIRECT_ACCESS_HANDLE, osl_File_E_BADF }, /* 130 */ 122cdf0e10cSrcweir { ERROR_NEGATIVE_SEEK, osl_File_E_INVAL }, /* 131 */ 123cdf0e10cSrcweir { ERROR_SEEK_ON_DEVICE, osl_File_E_ACCES }, /* 132 */ 124cdf0e10cSrcweir { ERROR_DIR_NOT_EMPTY, osl_File_E_NOTEMPTY }, /* 145 */ 125cdf0e10cSrcweir { ERROR_NOT_LOCKED, osl_File_E_ACCES }, /* 158 */ 126cdf0e10cSrcweir { ERROR_BAD_PATHNAME, osl_File_E_NOENT }, /* 161 */ 127cdf0e10cSrcweir { ERROR_MAX_THRDS_REACHED, osl_File_E_AGAIN }, /* 164 */ 128cdf0e10cSrcweir { ERROR_LOCK_FAILED, osl_File_E_ACCES }, /* 167 */ 129cdf0e10cSrcweir { ERROR_ALREADY_EXISTS, osl_File_E_EXIST }, /* 183 */ 130cdf0e10cSrcweir { ERROR_FILENAME_EXCED_RANGE, osl_File_E_NOENT }, /* 206 */ 131cdf0e10cSrcweir { ERROR_NESTING_NOT_ALLOWED, osl_File_E_AGAIN }, /* 215 */ 132cdf0e10cSrcweir { ERROR_DIRECTORY, osl_File_E_NOENT }, /* 267 */ 133cdf0e10cSrcweir //{ ERROR_NOT_ENOUGH_QUOTA, osl_File_E_NOMEM } /* 1816 */ 134cdf0e10cSrcweir }; 135cdf0e10cSrcweir 136cdf0e10cSrcweir #define ELEMENTS_OF_ARRAY(arr) (sizeof(arr)/(sizeof((arr)[0]))) 137cdf0e10cSrcweir 138cdf0e10cSrcweir //##################################################### 139cdf0e10cSrcweir oslFileError MapError(APIRET dwError) 140cdf0e10cSrcweir { 141cdf0e10cSrcweir for (int i = 0; i < ELEMENTS_OF_ARRAY(errtable); ++i ) 142cdf0e10cSrcweir { 143cdf0e10cSrcweir if (dwError == errtable[i].oscode) 144cdf0e10cSrcweir return static_cast<oslFileError>(errtable[i].errnocode); 145cdf0e10cSrcweir } 146cdf0e10cSrcweir return osl_File_E_INVAL; 147cdf0e10cSrcweir } 148cdf0e10cSrcweir 149cdf0e10cSrcweir /****************************************************************************** 150cdf0e10cSrcweir * 151cdf0e10cSrcweir * static members 152cdf0e10cSrcweir * 153cdf0e10cSrcweir *****************************************************************************/ 154cdf0e10cSrcweir 155cdf0e10cSrcweir static const char * pFileLockEnvVar = (char *) -1; 156cdf0e10cSrcweir 157cdf0e10cSrcweir 158cdf0e10cSrcweir /****************************************************************************** 159cdf0e10cSrcweir * 160cdf0e10cSrcweir * C-String Function Declarations 161cdf0e10cSrcweir * 162cdf0e10cSrcweir *****************************************************************************/ 163cdf0e10cSrcweir 164cdf0e10cSrcweir static oslFileError osl_psz_getVolumeInformation(const sal_Char* , oslVolumeInfo* pInfo, sal_uInt32 uFieldMask); 165cdf0e10cSrcweir static oslFileError osl_psz_removeFile(const sal_Char* pszPath); 166cdf0e10cSrcweir static oslFileError osl_psz_createDirectory(const sal_Char* pszPath); 167cdf0e10cSrcweir static oslFileError osl_psz_removeDirectory(const sal_Char* pszPath); 168cdf0e10cSrcweir static oslFileError osl_psz_copyFile(const sal_Char* pszPath, const sal_Char* pszDestPath); 169cdf0e10cSrcweir static oslFileError osl_psz_moveFile(const sal_Char* pszPath, const sal_Char* pszDestPath); 170cdf0e10cSrcweir static oslFileError osl_psz_setFileTime(const sal_Char* strFilePath, const TimeValue* pCreationTime, const TimeValue* pLastAccessTime, const TimeValue* pLastWriteTime); 171cdf0e10cSrcweir 172cdf0e10cSrcweir 173cdf0e10cSrcweir /****************************************************************************** 174cdf0e10cSrcweir * 175cdf0e10cSrcweir * Static Module Utility Function Declarations 176cdf0e10cSrcweir * 177cdf0e10cSrcweir *****************************************************************************/ 178cdf0e10cSrcweir 179cdf0e10cSrcweir static oslFileError oslDoCopy(const sal_Char* pszSourceFileName, const sal_Char* pszDestFileName, mode_t nMode, size_t nSourceSize, int DestFileExists); 180cdf0e10cSrcweir static oslFileError oslChangeFileModes(const sal_Char* pszFileName, mode_t nMode, time_t nAcTime, time_t nModTime, uid_t nUID, gid_t nGID); 181cdf0e10cSrcweir static int oslDoCopyLink(const sal_Char* pszSourceFileName, const sal_Char* pszDestFileName); 182cdf0e10cSrcweir static int oslDoCopyFile(const sal_Char* pszSourceFileName, const sal_Char* pszDestFileName, size_t nSourceSize, mode_t mode); 183cdf0e10cSrcweir static oslFileError oslDoMoveFile(const sal_Char* pszPath, const sal_Char* pszDestPath); 184cdf0e10cSrcweir rtl_uString* oslMakeUStrFromPsz(const sal_Char* pszStr,rtl_uString** uStr); 185cdf0e10cSrcweir 186cdf0e10cSrcweir /****************************************************************************** 187cdf0e10cSrcweir * 188cdf0e10cSrcweir * Non-Static Utility Function Declarations 189cdf0e10cSrcweir * 190cdf0e10cSrcweir *****************************************************************************/ 191cdf0e10cSrcweir 192cdf0e10cSrcweir extern "C" int UnicodeToText( char *, size_t, const sal_Unicode *, sal_Int32 ); 193cdf0e10cSrcweir extern "C" int TextToUnicode( 194cdf0e10cSrcweir const char* text, size_t text_buffer_size, sal_Unicode* unic_text, sal_Int32 unic_text_buffer_size); 195cdf0e10cSrcweir 196cdf0e10cSrcweir /****************************************************************************** 197cdf0e10cSrcweir * 198cdf0e10cSrcweir * 'removeable device' aka floppy functions 199cdf0e10cSrcweir * 200cdf0e10cSrcweir *****************************************************************************/ 201cdf0e10cSrcweir 202cdf0e10cSrcweir static oslVolumeDeviceHandle osl_isFloppyDrive(const sal_Char* pszPath); 203cdf0e10cSrcweir static oslFileError osl_mountFloppy(oslVolumeDeviceHandle hFloppy); 204cdf0e10cSrcweir static oslFileError osl_unmountFloppy(oslVolumeDeviceHandle hFloppy); 205cdf0e10cSrcweir 206cdf0e10cSrcweir #ifdef DEBUG_OSL_FILE 207cdf0e10cSrcweir static void osl_printFloppyHandle(oslVolumeDeviceHandleImpl* hFloppy); 208cdf0e10cSrcweir #endif 209cdf0e10cSrcweir 210cdf0e10cSrcweir /********************************************** 211cdf0e10cSrcweir * _osl_openLocalRoot 212cdf0e10cSrcweir * enumerate available drives 213cdf0e10cSrcweir *********************************************/ 214cdf0e10cSrcweir static oslFileError _osl_openLocalRoot( rtl_uString *strDirectoryPath, oslDirectory *pDirectory) 215cdf0e10cSrcweir { 216cdf0e10cSrcweir rtl_uString *ustrSystemPath = NULL; 217cdf0e10cSrcweir oslFileError error; 218cdf0e10cSrcweir 219cdf0e10cSrcweir if ( !pDirectory ) 220cdf0e10cSrcweir return osl_File_E_INVAL; 221cdf0e10cSrcweir 222cdf0e10cSrcweir *pDirectory = NULL; 223cdf0e10cSrcweir 224cdf0e10cSrcweir error = osl_getSystemPathFromFileURL_Ex( strDirectoryPath, &ustrSystemPath, sal_False ); 225cdf0e10cSrcweir 226cdf0e10cSrcweir if ( osl_File_E_None == error ) 227cdf0e10cSrcweir { 228cdf0e10cSrcweir /* create and initialize impl structure */ 229cdf0e10cSrcweir DirectoryImpl* pDirImpl = (DirectoryImpl*) rtl_allocateMemory( sizeof(DirectoryImpl) ); 230cdf0e10cSrcweir if( pDirImpl ) 231cdf0e10cSrcweir { 232cdf0e10cSrcweir ULONG ulDriveNum; 233cdf0e10cSrcweir APIRET rc; 234cdf0e10cSrcweir pDirImpl->uType = DIRECTORYTYPE_LOCALROOT; 235cdf0e10cSrcweir pDirImpl->ustrPath = ustrSystemPath; 236cdf0e10cSrcweir rc = DosQueryCurrentDisk (&ulDriveNum, &pDirImpl->ulDriveMap); 237cdf0e10cSrcweir pDirImpl->pDirStruct = 0; 238cdf0e10cSrcweir pDirImpl->ulNextDrive = 1; 239cdf0e10cSrcweir pDirImpl->ulNextDriveMask = 1; 240cdf0e10cSrcweir 241cdf0e10cSrcweir // determine number of floppy-drives 242cdf0e10cSrcweir BYTE nFloppies; 243cdf0e10cSrcweir rc = DosDevConfig( (void*) &nFloppies, DEVINFO_FLOPPY ); 244cdf0e10cSrcweir if (nFloppies == 0) { 245cdf0e10cSrcweir // if no floppies, start with 3rd drive (C:) 246cdf0e10cSrcweir pDirImpl->ulNextDrive = 3; 247cdf0e10cSrcweir pDirImpl->ulNextDriveMask <<= 2; 248cdf0e10cSrcweir } else if (nFloppies == 1) { 249cdf0e10cSrcweir // mask drive B (second bit) in this case 250cdf0e10cSrcweir pDirImpl->ulDriveMap &= ~0x02; 251cdf0e10cSrcweir } 252cdf0e10cSrcweir *pDirectory = (oslDirectory) pDirImpl; 253cdf0e10cSrcweir return osl_File_E_None; 254cdf0e10cSrcweir } 255cdf0e10cSrcweir else 256cdf0e10cSrcweir { 257cdf0e10cSrcweir errno = osl_File_E_NOMEM; 258cdf0e10cSrcweir } 259cdf0e10cSrcweir 260cdf0e10cSrcweir } 261cdf0e10cSrcweir 262cdf0e10cSrcweir rtl_uString_release( ustrSystemPath ); 263cdf0e10cSrcweir return error; 264cdf0e10cSrcweir } 265cdf0e10cSrcweir 266cdf0e10cSrcweir /********************************************** 267cdf0e10cSrcweir * _osl_getNextDrive 268cdf0e10cSrcweir *********************************************/ 269cdf0e10cSrcweir static oslFileError SAL_CALL _osl_getNextDrive( 270cdf0e10cSrcweir oslDirectory Directory, oslDirectoryItem *pItem, sal_uInt32 uHint ) 271cdf0e10cSrcweir { 272cdf0e10cSrcweir DirectoryImpl *pDirImpl = (DirectoryImpl *)Directory; 273cdf0e10cSrcweir DirectoryItem_Impl *pItemImpl = NULL; 274cdf0e10cSrcweir rtl_uString * ustrDrive = NULL; 275cdf0e10cSrcweir BOOL fSuccess; 276cdf0e10cSrcweir char buffer[3]; 277cdf0e10cSrcweir 278cdf0e10cSrcweir uHint = uHint; /* avoid warnings */ 279cdf0e10cSrcweir 280cdf0e10cSrcweir if ( !pItem ) 281cdf0e10cSrcweir return osl_File_E_INVAL; 282cdf0e10cSrcweir 283cdf0e10cSrcweir *pItem = NULL; 284cdf0e10cSrcweir 285cdf0e10cSrcweir if ( !pDirImpl ) 286cdf0e10cSrcweir return osl_File_E_INVAL; 287cdf0e10cSrcweir 288cdf0e10cSrcweir while( pDirImpl->ulNextDrive <= 26) 289cdf0e10cSrcweir { 290cdf0e10cSrcweir // exit if bit==1 -> drive found 291cdf0e10cSrcweir if (pDirImpl->ulDriveMap & pDirImpl->ulNextDriveMask) { 292cdf0e10cSrcweir 293cdf0e10cSrcweir /* convert file name to unicode */ 294cdf0e10cSrcweir buffer[0] = '@' + pDirImpl->ulNextDrive; 295cdf0e10cSrcweir buffer[1] = ':'; 296cdf0e10cSrcweir buffer[2] = 0; 297cdf0e10cSrcweir 298cdf0e10cSrcweir pItemImpl = (DirectoryItem_Impl*) rtl_allocateMemory(sizeof(DirectoryItem_Impl)); 299cdf0e10cSrcweir if ( !pItemImpl ) 300cdf0e10cSrcweir return osl_File_E_NOMEM; 301cdf0e10cSrcweir 302cdf0e10cSrcweir memset( pItemImpl, 0, sizeof(DirectoryItem_Impl) ); 303cdf0e10cSrcweir pItemImpl->uType = DIRECTORYITEM_DRIVE; 304cdf0e10cSrcweir pItemImpl->nRefCount = 1; 305cdf0e10cSrcweir 306cdf0e10cSrcweir rtl_string2UString( &pItemImpl->ustrDrive, buffer, 3, 307cdf0e10cSrcweir osl_getThreadTextEncoding(), OSTRING_TO_OUSTRING_CVTFLAGS ); 308cdf0e10cSrcweir OSL_ASSERT(pItemImpl->ustrDrive != 0); 309cdf0e10cSrcweir 310cdf0e10cSrcweir /* use drive as directory item */ 311cdf0e10cSrcweir *pItem = (oslDirectoryItem) pItemImpl; 312cdf0e10cSrcweir } 313cdf0e10cSrcweir // scan next bit position 314cdf0e10cSrcweir pDirImpl->ulNextDrive++; 315cdf0e10cSrcweir pDirImpl->ulNextDriveMask <<= 1; 316cdf0e10cSrcweir 317cdf0e10cSrcweir if (*pItem) // item assigned, return now. 318cdf0e10cSrcweir return osl_File_E_None; 319cdf0e10cSrcweir } 320cdf0e10cSrcweir 321cdf0e10cSrcweir // no more items 322cdf0e10cSrcweir return osl_File_E_NOENT; 323cdf0e10cSrcweir } 324cdf0e10cSrcweir 325cdf0e10cSrcweir /********************************************** 326cdf0e10cSrcweir * _osl_readdir_impl_ 327cdf0e10cSrcweir * 328cdf0e10cSrcweir * readdir wrapper, filters out "." and ".." 329cdf0e10cSrcweir * on request 330cdf0e10cSrcweir *********************************************/ 331cdf0e10cSrcweir 332cdf0e10cSrcweir static struct dirent* _osl_readdir_impl_(DIR* pdir, sal_Bool bFilterLocalAndParentDir) 333cdf0e10cSrcweir { 334cdf0e10cSrcweir struct dirent* pdirent; 335cdf0e10cSrcweir 336cdf0e10cSrcweir while ((pdirent = readdir(pdir)) != NULL) 337cdf0e10cSrcweir { 338cdf0e10cSrcweir if (bFilterLocalAndParentDir && 339cdf0e10cSrcweir ((0 == strcmp(pdirent->d_name, ".")) || (0 == strcmp(pdirent->d_name, "..")))) 340cdf0e10cSrcweir continue; 341cdf0e10cSrcweir else 342cdf0e10cSrcweir break; 343cdf0e10cSrcweir } 344cdf0e10cSrcweir 345cdf0e10cSrcweir return pdirent; 346cdf0e10cSrcweir } 347cdf0e10cSrcweir 348cdf0e10cSrcweir /******************************************************************* 349cdf0e10cSrcweir * osl_openDirectory 350cdf0e10cSrcweir ******************************************************************/ 351cdf0e10cSrcweir 352cdf0e10cSrcweir oslFileError SAL_CALL osl_openDirectory(rtl_uString* ustrDirectoryURL, oslDirectory* pDirectory) 353cdf0e10cSrcweir { 354cdf0e10cSrcweir rtl_uString* ustrSystemPath = NULL; 355cdf0e10cSrcweir oslFileError eRet; 356cdf0e10cSrcweir 357cdf0e10cSrcweir char path[PATH_MAX]; 358cdf0e10cSrcweir 359cdf0e10cSrcweir OSL_ASSERT(ustrDirectoryURL && (ustrDirectoryURL->length > 0)); 360cdf0e10cSrcweir OSL_ASSERT(pDirectory); 361cdf0e10cSrcweir 362cdf0e10cSrcweir if (0 == ustrDirectoryURL->length ) 363cdf0e10cSrcweir return osl_File_E_INVAL; 364cdf0e10cSrcweir 365cdf0e10cSrcweir if ( 0 == rtl_ustr_compareIgnoreAsciiCase( ustrDirectoryURL->buffer, (const sal_Unicode*)L"file:///" ) ) 366cdf0e10cSrcweir return _osl_openLocalRoot( ustrDirectoryURL, pDirectory ); 367cdf0e10cSrcweir 368cdf0e10cSrcweir /* convert file URL to system path */ 369cdf0e10cSrcweir eRet = osl_getSystemPathFromFileURL_Ex(ustrDirectoryURL, &ustrSystemPath, sal_False); 370cdf0e10cSrcweir 371cdf0e10cSrcweir if( osl_File_E_None != eRet ) 372cdf0e10cSrcweir return eRet; 373cdf0e10cSrcweir 374cdf0e10cSrcweir osl_systemPathRemoveSeparator(ustrSystemPath); 375cdf0e10cSrcweir 376cdf0e10cSrcweir /* convert unicode path to text */ 377cdf0e10cSrcweir if ( UnicodeToText( path, PATH_MAX, ustrSystemPath->buffer, ustrSystemPath->length ) ) 378cdf0e10cSrcweir { 379cdf0e10cSrcweir // if only the drive is specified (x:), add a \ (x:\) otherwise current 380cdf0e10cSrcweir // directory is browsed instead of root. 381cdf0e10cSrcweir if (strlen( path) == 2 && path[1] == ':') 382cdf0e10cSrcweir strcat( path, "\\"); 383cdf0e10cSrcweir /* open directory */ 384cdf0e10cSrcweir DIR *pdir = opendir( path ); 385cdf0e10cSrcweir 386cdf0e10cSrcweir if( pdir ) 387cdf0e10cSrcweir { 388cdf0e10cSrcweir /* create and initialize impl structure */ 389cdf0e10cSrcweir DirectoryImpl* pDirImpl = (DirectoryImpl*) rtl_allocateMemory( sizeof(DirectoryImpl) ); 390cdf0e10cSrcweir 391cdf0e10cSrcweir if( pDirImpl ) 392cdf0e10cSrcweir { 393cdf0e10cSrcweir pDirImpl->uType = DIRECTORYTYPE_FILESYSTEM; 394cdf0e10cSrcweir pDirImpl->pDirStruct = pdir; 395cdf0e10cSrcweir pDirImpl->ustrPath = ustrSystemPath; 396cdf0e10cSrcweir 397cdf0e10cSrcweir *pDirectory = (oslDirectory) pDirImpl; 398cdf0e10cSrcweir return osl_File_E_None; 399cdf0e10cSrcweir } 400cdf0e10cSrcweir else 401cdf0e10cSrcweir { 402cdf0e10cSrcweir errno = ENOMEM; 403cdf0e10cSrcweir closedir( pdir ); 404cdf0e10cSrcweir } 405cdf0e10cSrcweir } 406cdf0e10cSrcweir else 407cdf0e10cSrcweir /* should be removed by optimizer in product version */ 408cdf0e10cSrcweir PERROR( "osl_openDirectory", path ); 409cdf0e10cSrcweir } 410cdf0e10cSrcweir 411cdf0e10cSrcweir rtl_uString_release( ustrSystemPath ); 412cdf0e10cSrcweir 413cdf0e10cSrcweir return oslTranslateFileError(OSL_FET_ERROR, errno); 414cdf0e10cSrcweir } 415cdf0e10cSrcweir 416cdf0e10cSrcweir 417cdf0e10cSrcweir /**************************************************************************** 418cdf0e10cSrcweir * osl_getNextDirectoryItem 419cdf0e10cSrcweir ***************************************************************************/ 420cdf0e10cSrcweir 421cdf0e10cSrcweir oslFileError SAL_CALL osl_getNextDirectoryItem(oslDirectory Directory, oslDirectoryItem* pItem, sal_uInt32 uHint) 422cdf0e10cSrcweir { 423cdf0e10cSrcweir DirectoryImpl* pDirImpl = (DirectoryImpl*)Directory; 424cdf0e10cSrcweir DirectoryItem_Impl *pItemImpl = NULL; 425cdf0e10cSrcweir rtl_uString* ustrFileName = NULL; 426cdf0e10cSrcweir rtl_uString* ustrFilePath = NULL; 427cdf0e10cSrcweir struct dirent* pEntry; 428cdf0e10cSrcweir 429cdf0e10cSrcweir OSL_ASSERT(Directory); 430cdf0e10cSrcweir OSL_ASSERT(pItem); 431cdf0e10cSrcweir 432cdf0e10cSrcweir if ((NULL == Directory) || (NULL == pItem)) 433cdf0e10cSrcweir return osl_File_E_INVAL; 434cdf0e10cSrcweir 435cdf0e10cSrcweir if ( pDirImpl->uType == DIRECTORYTYPE_LOCALROOT) 436cdf0e10cSrcweir return _osl_getNextDrive( Directory, pItem, uHint ); 437cdf0e10cSrcweir 438cdf0e10cSrcweir pEntry = _osl_readdir_impl_(pDirImpl->pDirStruct, sal_True); 439cdf0e10cSrcweir 440cdf0e10cSrcweir if (NULL == pEntry) 441cdf0e10cSrcweir return osl_File_E_NOENT; 442cdf0e10cSrcweir 443cdf0e10cSrcweir pItemImpl = (DirectoryItem_Impl*) rtl_allocateMemory(sizeof(DirectoryItem_Impl)); 444cdf0e10cSrcweir if ( !pItemImpl ) 445cdf0e10cSrcweir return osl_File_E_NOMEM; 446cdf0e10cSrcweir 447cdf0e10cSrcweir memset( pItemImpl, 0, sizeof(DirectoryItem_Impl) ); 448cdf0e10cSrcweir pItemImpl->uType = DIRECTORYITEM_FILE; 449cdf0e10cSrcweir pItemImpl->nRefCount = 1; 450cdf0e10cSrcweir pItemImpl->d_attr = pEntry->d_attr; 451cdf0e10cSrcweir 452cdf0e10cSrcweir /* convert file name to unicode */ 453cdf0e10cSrcweir rtl_string2UString( &ustrFileName, pEntry->d_name, strlen( pEntry->d_name ), 454cdf0e10cSrcweir osl_getThreadTextEncoding(), OSTRING_TO_OUSTRING_CVTFLAGS ); 455cdf0e10cSrcweir OSL_ASSERT(ustrFileName != 0); 456cdf0e10cSrcweir 457cdf0e10cSrcweir osl_systemPathMakeAbsolutePath(pDirImpl->ustrPath, ustrFileName, &pItemImpl->ustrFilePath); 458cdf0e10cSrcweir rtl_uString_release( ustrFileName ); 459cdf0e10cSrcweir 460cdf0e10cSrcweir *pItem = (oslDirectoryItem)pItemImpl; 461cdf0e10cSrcweir return osl_File_E_None; 462cdf0e10cSrcweir } 463cdf0e10cSrcweir 464cdf0e10cSrcweir /****************************************************************************/ 465cdf0e10cSrcweir /* osl_closeDirectory */ 466cdf0e10cSrcweir /****************************************************************************/ 467cdf0e10cSrcweir 468cdf0e10cSrcweir oslFileError SAL_CALL osl_closeDirectory( oslDirectory Directory ) 469cdf0e10cSrcweir { 470cdf0e10cSrcweir DirectoryImpl* pDirImpl = (DirectoryImpl*) Directory; 471cdf0e10cSrcweir oslFileError err = osl_File_E_None; 472cdf0e10cSrcweir 473cdf0e10cSrcweir OSL_ASSERT( Directory ); 474cdf0e10cSrcweir 475cdf0e10cSrcweir if( NULL == pDirImpl ) 476cdf0e10cSrcweir return osl_File_E_INVAL; 477cdf0e10cSrcweir 478cdf0e10cSrcweir switch ( pDirImpl->uType ) 479cdf0e10cSrcweir { 480cdf0e10cSrcweir case DIRECTORYTYPE_FILESYSTEM: 481cdf0e10cSrcweir if( closedir( pDirImpl->pDirStruct ) ) 482cdf0e10cSrcweir err = oslTranslateFileError(OSL_FET_ERROR, errno); 483cdf0e10cSrcweir break; 484cdf0e10cSrcweir case DIRECTORYTYPE_LOCALROOT: 485cdf0e10cSrcweir err = osl_File_E_None; 486cdf0e10cSrcweir break; 487cdf0e10cSrcweir #if 0 488cdf0e10cSrcweir case DIRECTORYTYPE_NETROOT: 489cdf0e10cSrcweir { 490cdf0e10cSrcweir DWORD err = WNetCloseEnum(pDirImpl->hDirectory); 491cdf0e10cSrcweir eError = (err == NO_ERROR) ? osl_File_E_None : MapError(err); 492cdf0e10cSrcweir } 493cdf0e10cSrcweir break; 494cdf0e10cSrcweir #endif 495cdf0e10cSrcweir default: 496cdf0e10cSrcweir OSL_ENSURE( 0, "Invalid directory type" ); 497cdf0e10cSrcweir break; 498cdf0e10cSrcweir } 499cdf0e10cSrcweir 500cdf0e10cSrcweir /* cleanup members */ 501cdf0e10cSrcweir rtl_uString_release( pDirImpl->ustrPath ); 502cdf0e10cSrcweir 503cdf0e10cSrcweir rtl_freeMemory( pDirImpl ); 504cdf0e10cSrcweir 505cdf0e10cSrcweir return err; 506cdf0e10cSrcweir } 507cdf0e10cSrcweir 508cdf0e10cSrcweir /****************************************************************************/ 509cdf0e10cSrcweir /* osl_getDirectoryItem */ 510cdf0e10cSrcweir /****************************************************************************/ 511cdf0e10cSrcweir 512cdf0e10cSrcweir oslFileError SAL_CALL osl_getDirectoryItem( rtl_uString* ustrFileURL, oslDirectoryItem* pItem ) 513cdf0e10cSrcweir { 514cdf0e10cSrcweir rtl_uString* strSysFilePath = NULL; 515cdf0e10cSrcweir oslFileError error = osl_File_E_INVAL; 516cdf0e10cSrcweir ULONG dwPathType; 517cdf0e10cSrcweir PATHTYPE type = PATHTYPE_FILE; 518cdf0e10cSrcweir 519cdf0e10cSrcweir OSL_ASSERT(ustrFileURL); 520cdf0e10cSrcweir OSL_ASSERT(pItem); 521cdf0e10cSrcweir 522cdf0e10cSrcweir /* Assume failure */ 523cdf0e10cSrcweir if ( !pItem ) 524cdf0e10cSrcweir return osl_File_E_INVAL; 525cdf0e10cSrcweir *pItem = NULL; 526cdf0e10cSrcweir 527cdf0e10cSrcweir if (0 == ustrFileURL->length || NULL == pItem) 528cdf0e10cSrcweir return osl_File_E_INVAL; 529cdf0e10cSrcweir 530cdf0e10cSrcweir error = osl_getSystemPathFromFileURL_Ex(ustrFileURL, &strSysFilePath, sal_False); 531cdf0e10cSrcweir 532cdf0e10cSrcweir if (osl_File_E_None != error) 533cdf0e10cSrcweir return error; 534cdf0e10cSrcweir 535cdf0e10cSrcweir dwPathType = IsValidFilePath( strSysFilePath->buffer, NULL, VALIDATEPATH_NORMAL ); 536cdf0e10cSrcweir 537cdf0e10cSrcweir if ( dwPathType & PATHTYPE_IS_VOLUME ) 538cdf0e10cSrcweir type = PATHTYPE_VOLUME; 539cdf0e10cSrcweir else if ( dwPathType & PATHTYPE_IS_SERVER ) 540cdf0e10cSrcweir type = PATHTYPE_NETSERVER; 541cdf0e10cSrcweir else 542cdf0e10cSrcweir type = PATHTYPE_FILE; 543cdf0e10cSrcweir 544cdf0e10cSrcweir switch ( type ) 545cdf0e10cSrcweir { 546cdf0e10cSrcweir case PATHTYPE_NETSERVER: 547cdf0e10cSrcweir { 548cdf0e10cSrcweir DirectoryItem_Impl* pItemImpl = 549cdf0e10cSrcweir reinterpret_cast<DirectoryItem_Impl*>(rtl_allocateMemory(sizeof(DirectoryItem_Impl))); 550cdf0e10cSrcweir 551cdf0e10cSrcweir if ( !pItemImpl ) 552cdf0e10cSrcweir error = osl_File_E_NOMEM; 553cdf0e10cSrcweir 554cdf0e10cSrcweir if ( osl_File_E_None == error ) 555cdf0e10cSrcweir { 556cdf0e10cSrcweir memset( pItemImpl, 0, sizeof(DirectoryItem_Impl) ); 557cdf0e10cSrcweir pItemImpl->uType = DIRECTORYITEM_SERVER; 558cdf0e10cSrcweir pItemImpl->nRefCount = 1; 559cdf0e10cSrcweir rtl_uString_assign( &pItemImpl->ustrFilePath, strSysFilePath ); 560cdf0e10cSrcweir 561cdf0e10cSrcweir *pItem = pItemImpl; 562cdf0e10cSrcweir } 563cdf0e10cSrcweir } 564cdf0e10cSrcweir break; 565cdf0e10cSrcweir case PATHTYPE_VOLUME: 566cdf0e10cSrcweir { 567cdf0e10cSrcweir DirectoryItem_Impl* pItemImpl = 568cdf0e10cSrcweir reinterpret_cast<DirectoryItem_Impl*>(rtl_allocateMemory(sizeof(DirectoryItem_Impl))); 569cdf0e10cSrcweir 570cdf0e10cSrcweir if ( !pItemImpl ) 571cdf0e10cSrcweir error = osl_File_E_NOMEM; 572cdf0e10cSrcweir 573cdf0e10cSrcweir if ( osl_File_E_None == error ) 574cdf0e10cSrcweir { 575cdf0e10cSrcweir memset( pItemImpl, 0, sizeof(DirectoryItem_Impl) ); 576cdf0e10cSrcweir pItemImpl->uType = DIRECTORYITEM_DRIVE; 577cdf0e10cSrcweir pItemImpl->nRefCount = 1; 578cdf0e10cSrcweir rtl_uString_assign( &pItemImpl->ustrDrive, strSysFilePath ); 579cdf0e10cSrcweir 580cdf0e10cSrcweir if ( pItemImpl->ustrDrive->buffer[pItemImpl->ustrDrive->length-1] != sal_Unicode('\\') ) 581cdf0e10cSrcweir rtl_uString_newConcat( &pItemImpl->ustrDrive, 582cdf0e10cSrcweir pItemImpl->ustrDrive, rtl::OUString::createFromAscii( "\\" ).pData); 583cdf0e10cSrcweir 584cdf0e10cSrcweir *pItem = pItemImpl; 585cdf0e10cSrcweir } 586cdf0e10cSrcweir } 587cdf0e10cSrcweir break; 588cdf0e10cSrcweir default: 589cdf0e10cSrcweir case PATHTYPE_FILE: 590cdf0e10cSrcweir { 591cdf0e10cSrcweir if ( strSysFilePath->length > 0 && strSysFilePath->buffer[strSysFilePath->length - 1] == '\\' ) 592cdf0e10cSrcweir rtl_uString_newFromStr_WithLength( &strSysFilePath, strSysFilePath->buffer, strSysFilePath->length - 1 ); 593cdf0e10cSrcweir 594cdf0e10cSrcweir if (0 == access_u(strSysFilePath, F_OK)) 595cdf0e10cSrcweir { 596cdf0e10cSrcweir DirectoryItem_Impl *pItemImpl = 597cdf0e10cSrcweir reinterpret_cast<DirectoryItem_Impl*>(rtl_allocateMemory(sizeof(DirectoryItem_Impl))); 598cdf0e10cSrcweir 599cdf0e10cSrcweir memset( pItemImpl, 0, sizeof(DirectoryItem_Impl) ); 600cdf0e10cSrcweir pItemImpl->uType = DIRECTORYITEM_FILE; 601cdf0e10cSrcweir pItemImpl->nRefCount = 1; 602cdf0e10cSrcweir rtl_uString_assign( &pItemImpl->ustrFilePath, strSysFilePath ); 603cdf0e10cSrcweir 604cdf0e10cSrcweir *pItem = pItemImpl; 605cdf0e10cSrcweir } 606cdf0e10cSrcweir else 607cdf0e10cSrcweir error = oslTranslateFileError(OSL_FET_ERROR, errno); 608cdf0e10cSrcweir } 609cdf0e10cSrcweir break; 610cdf0e10cSrcweir } 611cdf0e10cSrcweir 612cdf0e10cSrcweir if ( strSysFilePath ) 613cdf0e10cSrcweir rtl_uString_release( strSysFilePath ); 614cdf0e10cSrcweir 615cdf0e10cSrcweir return error; 616cdf0e10cSrcweir } 617cdf0e10cSrcweir 618cdf0e10cSrcweir /****************************************************************************/ 619cdf0e10cSrcweir /* osl_acquireDirectoryItem */ 620cdf0e10cSrcweir /****************************************************************************/ 621cdf0e10cSrcweir 622cdf0e10cSrcweir oslFileError osl_acquireDirectoryItem( oslDirectoryItem Item ) 623cdf0e10cSrcweir { 624cdf0e10cSrcweir OSL_ASSERT( Item ); 625cdf0e10cSrcweir DirectoryItem_Impl *pItemImpl = (DirectoryItem_Impl *)Item; 626cdf0e10cSrcweir 627cdf0e10cSrcweir if ( !pItemImpl ) 628cdf0e10cSrcweir return osl_File_E_INVAL; 629cdf0e10cSrcweir 630cdf0e10cSrcweir pItemImpl->nRefCount++; 631cdf0e10cSrcweir return osl_File_E_None; 632cdf0e10cSrcweir } 633cdf0e10cSrcweir 634cdf0e10cSrcweir /****************************************************************************/ 635cdf0e10cSrcweir /* osl_releaseDirectoryItem */ 636cdf0e10cSrcweir /****************************************************************************/ 637cdf0e10cSrcweir 638cdf0e10cSrcweir oslFileError osl_releaseDirectoryItem( oslDirectoryItem Item ) 639cdf0e10cSrcweir { 640cdf0e10cSrcweir OSL_ASSERT( Item ); 641cdf0e10cSrcweir DirectoryItem_Impl *pItemImpl = (DirectoryItem_Impl *)Item; 642cdf0e10cSrcweir 643cdf0e10cSrcweir if ( !pItemImpl ) 644cdf0e10cSrcweir return osl_File_E_INVAL; 645cdf0e10cSrcweir 646cdf0e10cSrcweir if ( ! --pItemImpl->nRefCount ) 647cdf0e10cSrcweir { 648cdf0e10cSrcweir if (pItemImpl->ustrFilePath) 649cdf0e10cSrcweir rtl_uString_release( pItemImpl->ustrFilePath ); 650cdf0e10cSrcweir if (pItemImpl->ustrDrive) 651cdf0e10cSrcweir rtl_uString_release( pItemImpl->ustrDrive ); 652cdf0e10cSrcweir rtl_freeMemory( pItemImpl ); 653cdf0e10cSrcweir } 654cdf0e10cSrcweir return osl_File_E_None; 655cdf0e10cSrcweir } 656cdf0e10cSrcweir 657cdf0e10cSrcweir /**************************************************************************** 658cdf0e10cSrcweir * osl_createFileHandleFromFD 659cdf0e10cSrcweir ***************************************************************************/ 660cdf0e10cSrcweir 661cdf0e10cSrcweir oslFileHandle osl_createFileHandleFromFD( int fd ) 662cdf0e10cSrcweir { 663cdf0e10cSrcweir oslFileHandleImpl* pHandleImpl = NULL; 664cdf0e10cSrcweir 665cdf0e10cSrcweir if ( fd >= 0 ) 666cdf0e10cSrcweir { 667cdf0e10cSrcweir pHandleImpl = (oslFileHandleImpl*) rtl_allocateMemory( sizeof(oslFileHandleImpl) ); 668cdf0e10cSrcweir 669cdf0e10cSrcweir if( pHandleImpl ) 670cdf0e10cSrcweir { 671cdf0e10cSrcweir pHandleImpl->ustrFilePath = NULL; 672cdf0e10cSrcweir rtl_uString_new( &pHandleImpl->ustrFilePath ); 673cdf0e10cSrcweir pHandleImpl->fd = fd; 674cdf0e10cSrcweir 675cdf0e10cSrcweir /* FIXME: should detect whether the file has been locked */ 676cdf0e10cSrcweir pHandleImpl->bLocked = sal_True; 677cdf0e10cSrcweir } 678cdf0e10cSrcweir } 679cdf0e10cSrcweir 680cdf0e10cSrcweir return (oslFileHandle)pHandleImpl; 681cdf0e10cSrcweir } 682cdf0e10cSrcweir 683cdf0e10cSrcweir /**************************************************************************** 684cdf0e10cSrcweir * osl_openFile 685cdf0e10cSrcweir ***************************************************************************/ 686cdf0e10cSrcweir 687cdf0e10cSrcweir oslFileError osl_openFile( rtl_uString* ustrFileURL, oslFileHandle* pHandle, sal_uInt32 uFlags ) 688cdf0e10cSrcweir { 689cdf0e10cSrcweir oslFileHandleImpl* pHandleImpl = NULL; 690cdf0e10cSrcweir oslFileError eRet; 691cdf0e10cSrcweir rtl_uString* ustrFilePath = NULL; 692cdf0e10cSrcweir 693cdf0e10cSrcweir char buffer[PATH_MAX]; 694cdf0e10cSrcweir int fd; 695cdf0e10cSrcweir int mode = S_IRUSR | S_IRGRP | S_IROTH; 696cdf0e10cSrcweir int flags = O_RDONLY; 697cdf0e10cSrcweir 698cdf0e10cSrcweir struct flock aflock; 699cdf0e10cSrcweir 700cdf0e10cSrcweir /* locking the complete file */ 701cdf0e10cSrcweir aflock.l_type = 0; 702cdf0e10cSrcweir aflock.l_whence = SEEK_SET; 703cdf0e10cSrcweir aflock.l_start = 0; 704cdf0e10cSrcweir aflock.l_len = 0; 705cdf0e10cSrcweir 706cdf0e10cSrcweir OSL_ASSERT( ustrFileURL ); 707cdf0e10cSrcweir OSL_ASSERT( pHandle ); 708cdf0e10cSrcweir 709cdf0e10cSrcweir if( ( 0 == ustrFileURL->length ) ) 710cdf0e10cSrcweir return osl_File_E_INVAL; 711cdf0e10cSrcweir 712cdf0e10cSrcweir /* convert file URL to system path */ 713cdf0e10cSrcweir eRet = osl_getSystemPathFromFileURL( ustrFileURL, &ustrFilePath ); 714cdf0e10cSrcweir 715cdf0e10cSrcweir if( osl_File_E_None != eRet ) 716cdf0e10cSrcweir return eRet; 717cdf0e10cSrcweir 718cdf0e10cSrcweir osl_systemPathRemoveSeparator(ustrFilePath); 719cdf0e10cSrcweir 720cdf0e10cSrcweir /* convert unicode path to text */ 721cdf0e10cSrcweir if( UnicodeToText( buffer, PATH_MAX, ustrFilePath->buffer, ustrFilePath->length ) ) 722cdf0e10cSrcweir { 723cdf0e10cSrcweir /* we do not open devices or such here */ 724cdf0e10cSrcweir if( !( uFlags & osl_File_OpenFlag_Create ) ) 725cdf0e10cSrcweir { 726cdf0e10cSrcweir struct stat aFileStat; 727cdf0e10cSrcweir 728cdf0e10cSrcweir if( 0 > stat( buffer, &aFileStat ) ) 729cdf0e10cSrcweir { 730cdf0e10cSrcweir PERROR( "osl_openFile", buffer ); 731cdf0e10cSrcweir eRet = oslTranslateFileError(OSL_FET_ERROR, errno ); 732cdf0e10cSrcweir } 733cdf0e10cSrcweir 734cdf0e10cSrcweir else if( !S_ISREG( aFileStat.st_mode ) ) 735cdf0e10cSrcweir { 736cdf0e10cSrcweir eRet = osl_File_E_INVAL; 737cdf0e10cSrcweir } 738cdf0e10cSrcweir } 739cdf0e10cSrcweir 740cdf0e10cSrcweir if( osl_File_E_None == eRet ) 741cdf0e10cSrcweir { 742cdf0e10cSrcweir /* 743cdf0e10cSrcweir * set flags and mode 744cdf0e10cSrcweir */ 745cdf0e10cSrcweir 746cdf0e10cSrcweir if ( uFlags & osl_File_OpenFlag_Write ) 747cdf0e10cSrcweir { 748cdf0e10cSrcweir mode |= S_IWUSR | S_IWGRP | S_IWOTH; 749cdf0e10cSrcweir flags = O_RDWR; 750cdf0e10cSrcweir aflock.l_type = F_WRLCK; 751cdf0e10cSrcweir } 752cdf0e10cSrcweir 753cdf0e10cSrcweir if ( uFlags & osl_File_OpenFlag_Create ) 754cdf0e10cSrcweir { 755cdf0e10cSrcweir mode |= S_IWUSR | S_IWGRP | S_IWOTH; 756cdf0e10cSrcweir flags = O_CREAT | O_EXCL | O_RDWR; 757cdf0e10cSrcweir } 758cdf0e10cSrcweir 759cdf0e10cSrcweir /* open the file */ 760cdf0e10cSrcweir fd = open( buffer, flags | O_BINARY, mode); 761cdf0e10cSrcweir if ( fd >= 0 ) 762cdf0e10cSrcweir { 763cdf0e10cSrcweir sal_Bool bNeedsLock = ( ( uFlags & osl_File_OpenFlag_NoLock ) == 0 ); 764cdf0e10cSrcweir sal_Bool bLocked = sal_False; 765cdf0e10cSrcweir if( bNeedsLock ) 766cdf0e10cSrcweir { 767cdf0e10cSrcweir /* check if file lock is enabled and clear l_type member of flock otherwise */ 768cdf0e10cSrcweir if( (char *) -1 == pFileLockEnvVar ) 769cdf0e10cSrcweir { 770cdf0e10cSrcweir /* FIXME: this is not MT safe */ 771cdf0e10cSrcweir pFileLockEnvVar = getenv("SAL_ENABLE_FILE_LOCKING"); 772cdf0e10cSrcweir 773cdf0e10cSrcweir if( NULL == pFileLockEnvVar) 774cdf0e10cSrcweir pFileLockEnvVar = getenv("STAR_ENABLE_FILE_LOCKING"); 775cdf0e10cSrcweir } 776cdf0e10cSrcweir 777cdf0e10cSrcweir if( NULL == pFileLockEnvVar ) 778cdf0e10cSrcweir aflock.l_type = 0; 779cdf0e10cSrcweir 780cdf0e10cSrcweir /* lock the file if flock.l_type is set */ 781cdf0e10cSrcweir bLocked = ( F_WRLCK != aflock.l_type || -1 != fcntl( fd, F_SETLK, &aflock ) ); 782cdf0e10cSrcweir } 783cdf0e10cSrcweir 784cdf0e10cSrcweir if ( !bNeedsLock || bLocked ) 785cdf0e10cSrcweir { 786cdf0e10cSrcweir /* allocate memory for impl structure */ 787cdf0e10cSrcweir pHandleImpl = (oslFileHandleImpl*) rtl_allocateMemory( sizeof(oslFileHandleImpl) ); 788cdf0e10cSrcweir if( pHandleImpl ) 789cdf0e10cSrcweir { 790cdf0e10cSrcweir pHandleImpl->ustrFilePath = ustrFilePath; 791cdf0e10cSrcweir pHandleImpl->fd = fd; 792cdf0e10cSrcweir pHandleImpl->bLocked = bLocked; 793cdf0e10cSrcweir 794cdf0e10cSrcweir *pHandle = (oslFileHandle) pHandleImpl; 795cdf0e10cSrcweir 796cdf0e10cSrcweir return osl_File_E_None; 797cdf0e10cSrcweir } 798cdf0e10cSrcweir else 799cdf0e10cSrcweir { 800cdf0e10cSrcweir errno = ENOMEM; 801cdf0e10cSrcweir } 802cdf0e10cSrcweir } 803cdf0e10cSrcweir 804cdf0e10cSrcweir close( fd ); 805cdf0e10cSrcweir } 806cdf0e10cSrcweir 807cdf0e10cSrcweir PERROR( "osl_openFile", buffer ); 808cdf0e10cSrcweir eRet = oslTranslateFileError(OSL_FET_ERROR, errno ); 809cdf0e10cSrcweir } 810cdf0e10cSrcweir } 811cdf0e10cSrcweir else 812cdf0e10cSrcweir eRet = osl_File_E_INVAL; 813cdf0e10cSrcweir 814cdf0e10cSrcweir rtl_uString_release( ustrFilePath ); 815cdf0e10cSrcweir return eRet; 816cdf0e10cSrcweir } 817cdf0e10cSrcweir 818cdf0e10cSrcweir /****************************************************************************/ 819cdf0e10cSrcweir /* osl_closeFile */ 820cdf0e10cSrcweir /****************************************************************************/ 821cdf0e10cSrcweir 822cdf0e10cSrcweir oslFileError osl_closeFile( oslFileHandle Handle ) 823cdf0e10cSrcweir { 824cdf0e10cSrcweir oslFileHandleImpl* pHandleImpl = (oslFileHandleImpl *) Handle; 825cdf0e10cSrcweir oslFileError eRet = osl_File_E_INVAL; 826cdf0e10cSrcweir 827cdf0e10cSrcweir OSL_ASSERT( Handle ); 828cdf0e10cSrcweir 829cdf0e10cSrcweir if( pHandleImpl ) 830cdf0e10cSrcweir { 831cdf0e10cSrcweir rtl_uString_release( pHandleImpl->ustrFilePath ); 832cdf0e10cSrcweir 833cdf0e10cSrcweir /* release file lock if locking is enabled */ 834cdf0e10cSrcweir if( pFileLockEnvVar ) 835cdf0e10cSrcweir { 836cdf0e10cSrcweir struct flock aflock; 837cdf0e10cSrcweir 838cdf0e10cSrcweir aflock.l_type = F_UNLCK; 839cdf0e10cSrcweir aflock.l_whence = SEEK_SET; 840cdf0e10cSrcweir aflock.l_start = 0; 841cdf0e10cSrcweir aflock.l_len = 0; 842cdf0e10cSrcweir 843cdf0e10cSrcweir if ( pHandleImpl->bLocked ) 844cdf0e10cSrcweir { 845cdf0e10cSrcweir /* FIXME: check if file is really locked ? */ 846cdf0e10cSrcweir 847cdf0e10cSrcweir /* release the file share lock on this file */ 848cdf0e10cSrcweir if( -1 == fcntl( pHandleImpl->fd, F_SETLK, &aflock ) ) 849cdf0e10cSrcweir PERROR( "osl_closeFile", "unlock failed" ); 850cdf0e10cSrcweir } 851cdf0e10cSrcweir } 852cdf0e10cSrcweir 853cdf0e10cSrcweir if( 0 > close( pHandleImpl->fd ) ) 854cdf0e10cSrcweir { 855cdf0e10cSrcweir eRet = oslTranslateFileError(OSL_FET_ERROR, errno ); 856cdf0e10cSrcweir } 857cdf0e10cSrcweir else 858cdf0e10cSrcweir eRet = osl_File_E_None; 859cdf0e10cSrcweir 860cdf0e10cSrcweir rtl_freeMemory( pHandleImpl ); 861cdf0e10cSrcweir } 862cdf0e10cSrcweir 863cdf0e10cSrcweir return eRet; 864cdf0e10cSrcweir } 865cdf0e10cSrcweir 866cdf0e10cSrcweir /****************************************************************************/ 867cdf0e10cSrcweir /* osl_isEndOfFile */ 868cdf0e10cSrcweir /****************************************************************************/ 869cdf0e10cSrcweir 870cdf0e10cSrcweir oslFileError SAL_CALL osl_isEndOfFile( oslFileHandle Handle, sal_Bool *pIsEOF ) 871cdf0e10cSrcweir { 872cdf0e10cSrcweir oslFileHandleImpl* pHandleImpl = (oslFileHandleImpl *) Handle; 873cdf0e10cSrcweir oslFileError eRet = osl_File_E_INVAL; 874cdf0e10cSrcweir 875cdf0e10cSrcweir if ( pHandleImpl) 876cdf0e10cSrcweir { 877cdf0e10cSrcweir long curPos = lseek( pHandleImpl->fd, 0, SEEK_CUR ); 878cdf0e10cSrcweir 879cdf0e10cSrcweir if ( curPos >= 0 ) 880cdf0e10cSrcweir { 881cdf0e10cSrcweir long endPos = lseek( pHandleImpl->fd, 0, SEEK_END ); 882cdf0e10cSrcweir 883cdf0e10cSrcweir if ( endPos >= 0 ) 884cdf0e10cSrcweir { 885cdf0e10cSrcweir *pIsEOF = ( curPos == endPos ); 886cdf0e10cSrcweir curPos = lseek( pHandleImpl->fd, curPos, SEEK_SET ); 887cdf0e10cSrcweir 888cdf0e10cSrcweir if ( curPos >= 0 ) 889cdf0e10cSrcweir eRet = osl_File_E_None; 890cdf0e10cSrcweir else 891cdf0e10cSrcweir eRet = oslTranslateFileError(OSL_FET_ERROR, errno ); 892cdf0e10cSrcweir } 893cdf0e10cSrcweir else 894cdf0e10cSrcweir eRet = oslTranslateFileError(OSL_FET_ERROR, errno ); 895cdf0e10cSrcweir } 896cdf0e10cSrcweir else 897cdf0e10cSrcweir eRet = oslTranslateFileError(OSL_FET_ERROR, errno ); 898cdf0e10cSrcweir } 899cdf0e10cSrcweir 900cdf0e10cSrcweir return eRet; 901cdf0e10cSrcweir } 902cdf0e10cSrcweir 903cdf0e10cSrcweir 904cdf0e10cSrcweir /****************************************************************************/ 905cdf0e10cSrcweir /* osl_moveFile */ 906cdf0e10cSrcweir /****************************************************************************/ 907cdf0e10cSrcweir 908cdf0e10cSrcweir oslFileError osl_moveFile( rtl_uString* ustrFileURL, rtl_uString* ustrDestURL ) 909cdf0e10cSrcweir { 910cdf0e10cSrcweir char srcPath[PATH_MAX]; 911cdf0e10cSrcweir char destPath[PATH_MAX]; 912cdf0e10cSrcweir oslFileError eRet; 913cdf0e10cSrcweir APIRET rc; 914cdf0e10cSrcweir 915cdf0e10cSrcweir OSL_ASSERT( ustrFileURL ); 916cdf0e10cSrcweir OSL_ASSERT( ustrDestURL ); 917cdf0e10cSrcweir 918cdf0e10cSrcweir /* convert source url to system path */ 919cdf0e10cSrcweir eRet = FileURLToPath( srcPath, PATH_MAX, ustrFileURL ); 920cdf0e10cSrcweir if( eRet != osl_File_E_None ) 921cdf0e10cSrcweir return eRet; 922cdf0e10cSrcweir 923cdf0e10cSrcweir /* convert destination url to system path */ 924cdf0e10cSrcweir eRet = FileURLToPath( destPath, PATH_MAX, ustrDestURL ); 925cdf0e10cSrcweir if( eRet != osl_File_E_None ) 926cdf0e10cSrcweir return eRet; 927cdf0e10cSrcweir 928cdf0e10cSrcweir //YD 01/05/06 rename() can overwrite existing files. 929cdf0e10cSrcweir rc = DosDelete( (PCSZ)destPath); 930cdf0e10cSrcweir rc = DosMove( (PCSZ)srcPath, (PCSZ)destPath); 931cdf0e10cSrcweir if (!rc) 932cdf0e10cSrcweir eRet = osl_File_E_None; 933cdf0e10cSrcweir else 934cdf0e10cSrcweir eRet = MapError( rc); 935cdf0e10cSrcweir 936cdf0e10cSrcweir return eRet; 937cdf0e10cSrcweir } 938cdf0e10cSrcweir 939cdf0e10cSrcweir /****************************************************************************/ 940cdf0e10cSrcweir /* osl_copyFile */ 941cdf0e10cSrcweir /****************************************************************************/ 942cdf0e10cSrcweir 943cdf0e10cSrcweir #define TMP_DEST_FILE_EXTENSION ".osl-tmp" 944cdf0e10cSrcweir 945cdf0e10cSrcweir static oslFileError oslDoCopy(const sal_Char* pszSourceFileName, const sal_Char* pszDestFileName, mode_t nMode, size_t nSourceSize, int DestFileExists) 946cdf0e10cSrcweir { 947cdf0e10cSrcweir int nRet=0; 948cdf0e10cSrcweir sal_Char pszTmpDestFile[PATH_MAX]; 949cdf0e10cSrcweir size_t size_tmp_dest_buff = sizeof(pszTmpDestFile); 950cdf0e10cSrcweir 951cdf0e10cSrcweir /* Quick fix for #106048, the whole copy file function seems 952cdf0e10cSrcweir to be erroneous anyway and needs to be rewritten. 953cdf0e10cSrcweir Besides osl_copyFile is currently not used from OO/SO code. 954cdf0e10cSrcweir */ 955cdf0e10cSrcweir memset(pszTmpDestFile, 0, size_tmp_dest_buff); 956cdf0e10cSrcweir 957cdf0e10cSrcweir if ( DestFileExists ) 958cdf0e10cSrcweir { 959cdf0e10cSrcweir strncpy(pszTmpDestFile, pszDestFileName, size_tmp_dest_buff - 1); 960cdf0e10cSrcweir 961cdf0e10cSrcweir if ((strlen(pszTmpDestFile) + strlen(TMP_DEST_FILE_EXTENSION)) >= size_tmp_dest_buff) 962cdf0e10cSrcweir return osl_File_E_NAMETOOLONG; 963cdf0e10cSrcweir 964cdf0e10cSrcweir strncat(pszTmpDestFile, TMP_DEST_FILE_EXTENSION, strlen(TMP_DEST_FILE_EXTENSION)); 965cdf0e10cSrcweir 966cdf0e10cSrcweir /* FIXME: what if pszTmpDestFile already exists? */ 967cdf0e10cSrcweir /* with getcanonical??? */ 968cdf0e10cSrcweir nRet=rename(pszDestFileName,pszTmpDestFile); 969cdf0e10cSrcweir } 970cdf0e10cSrcweir 971cdf0e10cSrcweir /* mfe: should be S_ISREG */ 972cdf0e10cSrcweir if ( !S_ISLNK(nMode) ) 973cdf0e10cSrcweir { 974cdf0e10cSrcweir /* copy SourceFile to DestFile */ 975cdf0e10cSrcweir nRet = oslDoCopyFile(pszSourceFileName,pszDestFileName,nSourceSize, nMode); 976cdf0e10cSrcweir } 977cdf0e10cSrcweir /* mfe: OK redundant at the moment */ 978cdf0e10cSrcweir else if ( S_ISLNK(nMode) ) 979cdf0e10cSrcweir { 980cdf0e10cSrcweir nRet = oslDoCopyLink(pszSourceFileName,pszDestFileName); 981cdf0e10cSrcweir } 982cdf0e10cSrcweir else 983cdf0e10cSrcweir { 984cdf0e10cSrcweir /* mfe: what to do here? */ 985cdf0e10cSrcweir nRet=ENOSYS; 986cdf0e10cSrcweir } 987cdf0e10cSrcweir 988cdf0e10cSrcweir if ( nRet > 0 && DestFileExists == 1 ) 989cdf0e10cSrcweir { 990cdf0e10cSrcweir unlink(pszDestFileName); 991cdf0e10cSrcweir rename(pszTmpDestFile,pszDestFileName); 992cdf0e10cSrcweir } 993cdf0e10cSrcweir 994cdf0e10cSrcweir if ( nRet > 0 ) 995cdf0e10cSrcweir { 996cdf0e10cSrcweir return oslTranslateFileError(OSL_FET_ERROR, nRet); 997cdf0e10cSrcweir } 998cdf0e10cSrcweir 999cdf0e10cSrcweir if ( DestFileExists == 1 ) 1000cdf0e10cSrcweir { 1001cdf0e10cSrcweir unlink(pszTmpDestFile); 1002cdf0e10cSrcweir } 1003cdf0e10cSrcweir 1004cdf0e10cSrcweir return osl_File_E_None; 1005cdf0e10cSrcweir } 1006cdf0e10cSrcweir 1007cdf0e10cSrcweir /***************************************** 1008cdf0e10cSrcweir * oslChangeFileModes 1009cdf0e10cSrcweir ****************************************/ 1010cdf0e10cSrcweir 1011cdf0e10cSrcweir static oslFileError oslChangeFileModes( const sal_Char* pszFileName, mode_t nMode, time_t nAcTime, time_t nModTime, uid_t nUID, gid_t nGID) 1012cdf0e10cSrcweir { 1013cdf0e10cSrcweir int nRet=0; 1014cdf0e10cSrcweir struct utimbuf aTimeBuffer; 1015cdf0e10cSrcweir 1016cdf0e10cSrcweir nRet = chmod(pszFileName,nMode); 1017cdf0e10cSrcweir if ( nRet < 0 ) 1018cdf0e10cSrcweir { 1019cdf0e10cSrcweir nRet=errno; 1020cdf0e10cSrcweir return oslTranslateFileError(OSL_FET_ERROR, nRet); 1021cdf0e10cSrcweir } 1022cdf0e10cSrcweir 1023cdf0e10cSrcweir aTimeBuffer.actime=nAcTime; 1024cdf0e10cSrcweir aTimeBuffer.modtime=nModTime; 1025cdf0e10cSrcweir nRet=utime(pszFileName,&aTimeBuffer); 1026cdf0e10cSrcweir if ( nRet < 0 ) 1027cdf0e10cSrcweir { 1028cdf0e10cSrcweir nRet=errno; 1029cdf0e10cSrcweir return oslTranslateFileError(OSL_FET_ERROR, nRet); 1030cdf0e10cSrcweir } 1031cdf0e10cSrcweir 1032cdf0e10cSrcweir if ( nUID != getuid() ) 1033cdf0e10cSrcweir { 1034cdf0e10cSrcweir nUID=getuid(); 1035cdf0e10cSrcweir } 1036cdf0e10cSrcweir 1037cdf0e10cSrcweir nRet=chown(pszFileName,nUID,nGID); 1038cdf0e10cSrcweir if ( nRet < 0 ) 1039cdf0e10cSrcweir { 1040cdf0e10cSrcweir nRet=errno; 1041cdf0e10cSrcweir 1042cdf0e10cSrcweir /* mfe: do not return an error here! */ 1043cdf0e10cSrcweir /* return oslTranslateFileError(nRet);*/ 1044cdf0e10cSrcweir } 1045cdf0e10cSrcweir 1046cdf0e10cSrcweir return osl_File_E_None; 1047cdf0e10cSrcweir } 1048cdf0e10cSrcweir 1049cdf0e10cSrcweir /***************************************** 1050cdf0e10cSrcweir * oslDoCopyLink 1051cdf0e10cSrcweir ****************************************/ 1052cdf0e10cSrcweir 1053cdf0e10cSrcweir static int oslDoCopyLink(const sal_Char* pszSourceFileName, const sal_Char* pszDestFileName) 1054cdf0e10cSrcweir { 1055cdf0e10cSrcweir int nRet=0; 1056cdf0e10cSrcweir 1057cdf0e10cSrcweir /* mfe: if dest file is symbolic link remove the link and place the file instead (hro says so) */ 1058cdf0e10cSrcweir /* mfe: if source is a link copy the link and not the file it points to (hro says so) */ 1059cdf0e10cSrcweir sal_Char pszLinkContent[PATH_MAX]; 1060cdf0e10cSrcweir 1061cdf0e10cSrcweir pszLinkContent[0] = '\0'; 1062cdf0e10cSrcweir 1063cdf0e10cSrcweir nRet = readlink(pszSourceFileName,pszLinkContent,PATH_MAX); 1064cdf0e10cSrcweir 1065cdf0e10cSrcweir if ( nRet < 0 ) 1066cdf0e10cSrcweir { 1067cdf0e10cSrcweir nRet=errno; 1068cdf0e10cSrcweir return nRet; 1069cdf0e10cSrcweir } 1070cdf0e10cSrcweir else 1071cdf0e10cSrcweir pszLinkContent[ nRet ] = 0; 1072cdf0e10cSrcweir 1073cdf0e10cSrcweir nRet = symlink(pszLinkContent,pszDestFileName); 1074cdf0e10cSrcweir 1075cdf0e10cSrcweir if ( nRet < 0 ) 1076cdf0e10cSrcweir { 1077cdf0e10cSrcweir nRet=errno; 1078cdf0e10cSrcweir return nRet; 1079cdf0e10cSrcweir } 1080cdf0e10cSrcweir 1081cdf0e10cSrcweir return 0; 1082cdf0e10cSrcweir } 1083cdf0e10cSrcweir 1084cdf0e10cSrcweir /***************************************** 1085cdf0e10cSrcweir * oslDoCopyFile 1086cdf0e10cSrcweir ****************************************/ 1087cdf0e10cSrcweir 1088cdf0e10cSrcweir static int oslDoCopyFile(const sal_Char* pszSourceFileName, const sal_Char* pszDestFileName, size_t nSourceSize, mode_t mode) 1089cdf0e10cSrcweir { 1090cdf0e10cSrcweir int SourceFileFD=0; 1091cdf0e10cSrcweir int DestFileFD=0; 1092cdf0e10cSrcweir int nRet=0; 1093cdf0e10cSrcweir void* pSourceFile=0; 1094cdf0e10cSrcweir char buffer[ 4096]; 1095cdf0e10cSrcweir 1096cdf0e10cSrcweir SourceFileFD=open(pszSourceFileName,O_RDONLY | O_BINARY); 1097cdf0e10cSrcweir if ( SourceFileFD < 0 ) 1098cdf0e10cSrcweir { 1099cdf0e10cSrcweir nRet=errno; 1100cdf0e10cSrcweir return nRet; 1101cdf0e10cSrcweir } 1102cdf0e10cSrcweir 1103cdf0e10cSrcweir DestFileFD=open(pszDestFileName, O_WRONLY | O_CREAT | O_BINARY, mode); 1104cdf0e10cSrcweir if ( DestFileFD < 0 ) 1105cdf0e10cSrcweir { 1106cdf0e10cSrcweir nRet=errno; 1107cdf0e10cSrcweir close(SourceFileFD); 1108cdf0e10cSrcweir return nRet; 1109cdf0e10cSrcweir } 1110cdf0e10cSrcweir 1111cdf0e10cSrcweir /* HACK: because memory mapping fails on various 1112cdf0e10cSrcweir platforms if the size of the source file is 0 byte */ 1113cdf0e10cSrcweir if (0 == nSourceSize) 1114cdf0e10cSrcweir { 1115cdf0e10cSrcweir close(SourceFileFD); 1116cdf0e10cSrcweir close(DestFileFD); 1117cdf0e10cSrcweir return 0; 1118cdf0e10cSrcweir } 1119cdf0e10cSrcweir 1120cdf0e10cSrcweir while( (nRet = read(SourceFileFD, buffer, sizeof(buffer))) !=0 ) 1121cdf0e10cSrcweir { 1122cdf0e10cSrcweir nRet = write( DestFileFD, buffer, nRet); 1123cdf0e10cSrcweir } 1124cdf0e10cSrcweir 1125cdf0e10cSrcweir close(SourceFileFD); 1126cdf0e10cSrcweir close(DestFileFD); 1127cdf0e10cSrcweir 1128cdf0e10cSrcweir return nRet; 1129cdf0e10cSrcweir } 1130cdf0e10cSrcweir 1131cdf0e10cSrcweir static oslFileError osl_psz_copyFile( const sal_Char* pszPath, const sal_Char* pszDestPath ) 1132cdf0e10cSrcweir { 1133cdf0e10cSrcweir time_t nAcTime=0; 1134cdf0e10cSrcweir time_t nModTime=0; 1135cdf0e10cSrcweir uid_t nUID=0; 1136cdf0e10cSrcweir gid_t nGID=0; 1137cdf0e10cSrcweir int nRet=0; 1138cdf0e10cSrcweir mode_t nMode=0; 1139cdf0e10cSrcweir struct stat aFileStat; 1140cdf0e10cSrcweir oslFileError tErr=osl_File_E_invalidError; 1141cdf0e10cSrcweir size_t nSourceSize=0; 1142cdf0e10cSrcweir int DestFileExists=1; 1143cdf0e10cSrcweir 1144cdf0e10cSrcweir /* mfe: does the source file really exists? */ 1145cdf0e10cSrcweir nRet = lstat(pszPath,&aFileStat); 1146cdf0e10cSrcweir 1147cdf0e10cSrcweir if ( nRet < 0 ) 1148cdf0e10cSrcweir { 1149cdf0e10cSrcweir nRet=errno; 1150cdf0e10cSrcweir return oslTranslateFileError(OSL_FET_ERROR, nRet); 1151cdf0e10cSrcweir } 1152cdf0e10cSrcweir 1153cdf0e10cSrcweir /* mfe: we do only copy files here! */ 1154cdf0e10cSrcweir if ( S_ISDIR(aFileStat.st_mode) ) 1155cdf0e10cSrcweir { 1156cdf0e10cSrcweir return osl_File_E_ISDIR; 1157cdf0e10cSrcweir } 1158cdf0e10cSrcweir 1159cdf0e10cSrcweir nSourceSize=(size_t)aFileStat.st_size; 1160cdf0e10cSrcweir nMode=aFileStat.st_mode; 1161cdf0e10cSrcweir nAcTime=aFileStat.st_atime; 1162cdf0e10cSrcweir nModTime=aFileStat.st_mtime; 1163cdf0e10cSrcweir nUID=aFileStat.st_uid; 1164cdf0e10cSrcweir nGID=aFileStat.st_gid; 1165cdf0e10cSrcweir 1166cdf0e10cSrcweir nRet = stat(pszDestPath,&aFileStat); 1167cdf0e10cSrcweir if ( nRet < 0 ) 1168cdf0e10cSrcweir { 1169cdf0e10cSrcweir nRet=errno; 1170cdf0e10cSrcweir 1171cdf0e10cSrcweir if ( nRet == ENOENT ) 1172cdf0e10cSrcweir { 1173cdf0e10cSrcweir DestFileExists=0; 1174cdf0e10cSrcweir } 1175cdf0e10cSrcweir /* return oslTranslateFileError(nRet);*/ 1176cdf0e10cSrcweir } 1177cdf0e10cSrcweir 1178cdf0e10cSrcweir /* mfe: the destination file must not be a directory! */ 1179cdf0e10cSrcweir if ( nRet == 0 && S_ISDIR(aFileStat.st_mode) ) 1180cdf0e10cSrcweir { 1181cdf0e10cSrcweir return osl_File_E_ISDIR; 1182cdf0e10cSrcweir } 1183cdf0e10cSrcweir else 1184cdf0e10cSrcweir { 1185cdf0e10cSrcweir /* mfe: file does not exists or is no dir */ 1186cdf0e10cSrcweir } 1187cdf0e10cSrcweir 1188cdf0e10cSrcweir tErr = oslDoCopy(pszPath,pszDestPath,nMode,nSourceSize,DestFileExists); 1189cdf0e10cSrcweir 1190cdf0e10cSrcweir if ( tErr != osl_File_E_None ) 1191cdf0e10cSrcweir { 1192cdf0e10cSrcweir return tErr; 1193cdf0e10cSrcweir } 1194cdf0e10cSrcweir 1195cdf0e10cSrcweir /* 1196cdf0e10cSrcweir * mfe: ignore return code 1197cdf0e10cSrcweir * since only the success of the copy is 1198cdf0e10cSrcweir * important 1199cdf0e10cSrcweir */ 1200cdf0e10cSrcweir oslChangeFileModes(pszDestPath,nMode,nAcTime,nModTime,nUID,nGID); 1201cdf0e10cSrcweir 1202cdf0e10cSrcweir return tErr; 1203cdf0e10cSrcweir } 1204cdf0e10cSrcweir 1205cdf0e10cSrcweir oslFileError osl_copyFile( rtl_uString* ustrFileURL, rtl_uString* ustrDestURL ) 1206cdf0e10cSrcweir { 1207cdf0e10cSrcweir char srcPath[PATH_MAX]; 1208cdf0e10cSrcweir char destPath[PATH_MAX]; 1209cdf0e10cSrcweir oslFileError eRet; 1210cdf0e10cSrcweir APIRET rc; 1211cdf0e10cSrcweir 1212cdf0e10cSrcweir OSL_ASSERT( ustrFileURL ); 1213cdf0e10cSrcweir OSL_ASSERT( ustrDestURL ); 1214cdf0e10cSrcweir 1215cdf0e10cSrcweir /* convert source url to system path */ 1216cdf0e10cSrcweir eRet = FileURLToPath( srcPath, PATH_MAX, ustrFileURL ); 1217cdf0e10cSrcweir if( eRet != osl_File_E_None ) 1218cdf0e10cSrcweir return eRet; 1219cdf0e10cSrcweir 1220cdf0e10cSrcweir /* convert destination url to system path */ 1221cdf0e10cSrcweir eRet = FileURLToPath( destPath, PATH_MAX, ustrDestURL ); 1222cdf0e10cSrcweir if( eRet != osl_File_E_None ) 1223cdf0e10cSrcweir return eRet; 1224cdf0e10cSrcweir 1225cdf0e10cSrcweir return osl_psz_copyFile( srcPath, destPath ); 1226cdf0e10cSrcweir } 1227cdf0e10cSrcweir 1228cdf0e10cSrcweir /****************************************************************************/ 1229cdf0e10cSrcweir /* osl_removeFile */ 1230cdf0e10cSrcweir /****************************************************************************/ 1231cdf0e10cSrcweir 1232cdf0e10cSrcweir oslFileError osl_removeFile( rtl_uString* ustrFileURL ) 1233cdf0e10cSrcweir { 1234cdf0e10cSrcweir char path[PATH_MAX]; 1235cdf0e10cSrcweir oslFileError eRet; 1236cdf0e10cSrcweir APIRET rc; 1237cdf0e10cSrcweir 1238cdf0e10cSrcweir OSL_ASSERT( ustrFileURL ); 1239cdf0e10cSrcweir 1240cdf0e10cSrcweir /* convert file url to system path */ 1241cdf0e10cSrcweir eRet = FileURLToPath( path, PATH_MAX, ustrFileURL ); 1242cdf0e10cSrcweir if( eRet != osl_File_E_None ) 1243cdf0e10cSrcweir return eRet; 1244cdf0e10cSrcweir 1245cdf0e10cSrcweir rc = DosDelete( (PCSZ)path); 1246cdf0e10cSrcweir if (!rc) 1247cdf0e10cSrcweir eRet = osl_File_E_None; 1248cdf0e10cSrcweir else 1249cdf0e10cSrcweir eRet = MapError( rc); 1250cdf0e10cSrcweir 1251cdf0e10cSrcweir return eRet; 1252cdf0e10cSrcweir } 1253cdf0e10cSrcweir 1254cdf0e10cSrcweir /****************************************************************************/ 1255cdf0e10cSrcweir /* osl_getVolumeInformation */ 1256cdf0e10cSrcweir /****************************************************************************/ 1257cdf0e10cSrcweir 1258cdf0e10cSrcweir #define TXFSDC_BLOCKR 0x00 // block device removable 1259cdf0e10cSrcweir #define TXFSDC_GETBPB 0x00 // get device bpb info 1260cdf0e10cSrcweir #define TXFSBPB_REMOVABLE 0x08 // BPB attribute for removable 1261cdf0e10cSrcweir 1262cdf0e10cSrcweir typedef struct drivecmd 1263cdf0e10cSrcweir { 1264cdf0e10cSrcweir BYTE cmd; // 0=unlock 1=lock 2=eject 1265cdf0e10cSrcweir BYTE drv; // 0=A, 1=B 2=C ... 1266cdf0e10cSrcweir } DRIVECMD; // end of struct "drivecmd" 1267cdf0e10cSrcweir 1268cdf0e10cSrcweir #pragma pack(push, 1) // byte packing 1269cdf0e10cSrcweir typedef struct txfs_ebpb // ext. boot parameter block 1270cdf0e10cSrcweir { // at offset 0x0b in bootsector 1271cdf0e10cSrcweir USHORT SectSize; // 0B bytes per sector 1272cdf0e10cSrcweir BYTE ClustSize; // 0D sectors per cluster 1273cdf0e10cSrcweir USHORT FatOffset; // 0E sectors to 1st FAT 1274cdf0e10cSrcweir BYTE NrOfFats; // 10 nr of FATS (FAT only) 1275cdf0e10cSrcweir USHORT RootEntries; // 11 Max entries \ (FAT only) 1276cdf0e10cSrcweir USHORT Sectors; // 13 nr of sectors if < 64K 1277cdf0e10cSrcweir BYTE MediaType; // 15 mediatype (F8 for HD) 1278cdf0e10cSrcweir USHORT FatSectors; // 16 sectors/FAT (FAT only) 1279cdf0e10cSrcweir USHORT LogGeoSect; // 18 sectors/Track 1280cdf0e10cSrcweir USHORT LogGeoHead; // 1a nr of heads 1281cdf0e10cSrcweir ULONG HiddenSectors; // 1c sector-offset from MBR/EBR 1282cdf0e10cSrcweir ULONG BigSectors; // 20 nr of sectors if >= 64K 1283cdf0e10cSrcweir } TXFS_EBPB; // last byte is at offset 0x23 1284cdf0e10cSrcweir 1285cdf0e10cSrcweir typedef struct drivebpb 1286cdf0e10cSrcweir { 1287cdf0e10cSrcweir TXFS_EBPB ebpb; // extended BPB 1288cdf0e10cSrcweir BYTE reserved[6]; 1289cdf0e10cSrcweir USHORT cyls; 1290cdf0e10cSrcweir BYTE type; 1291cdf0e10cSrcweir USHORT attributes; // device attributes 1292cdf0e10cSrcweir BYTE fill[6]; // documented for IOCtl 1293cdf0e10cSrcweir } DRIVEBPB; // end of struct "drivebpb" 1294cdf0e10cSrcweir 1295cdf0e10cSrcweir struct CDInfo { 1296cdf0e10cSrcweir USHORT usCount; 1297cdf0e10cSrcweir USHORT usFirst; 1298cdf0e10cSrcweir }; 1299cdf0e10cSrcweir 1300cdf0e10cSrcweir #pragma pack(pop) 1301cdf0e10cSrcweir 1302cdf0e10cSrcweir /*****************************************************************************/ 1303cdf0e10cSrcweir // Get number of cdrom readers 1304cdf0e10cSrcweir /*****************************************************************************/ 1305cdf0e10cSrcweir BOOL GetCDInfo( CDInfo * pCDInfo ) 1306cdf0e10cSrcweir { 1307cdf0e10cSrcweir HFILE hFileCD; 1308cdf0e10cSrcweir ULONG ulAction; 1309cdf0e10cSrcweir 1310cdf0e10cSrcweir if( NO_ERROR == DosOpen( (PCSZ)"\\DEV\\CD-ROM2$", 1311cdf0e10cSrcweir &hFileCD, &ulAction, 0, FILE_NORMAL, 1312cdf0e10cSrcweir OPEN_ACTION_OPEN_IF_EXISTS, 1313cdf0e10cSrcweir OPEN_SHARE_DENYNONE | OPEN_ACCESS_READONLY, NULL )) { 1314cdf0e10cSrcweir ULONG ulDataSize = sizeof(CDInfo); 1315cdf0e10cSrcweir APIRET rc = DosDevIOCtl( hFileCD, 0x82, 0x60, NULL, 0, 1316cdf0e10cSrcweir NULL, (PVOID)pCDInfo, ulDataSize, &ulDataSize); 1317cdf0e10cSrcweir DosClose( hFileCD); 1318cdf0e10cSrcweir if(rc == NO_ERROR) 1319cdf0e10cSrcweir return TRUE; 1320cdf0e10cSrcweir } 1321cdf0e10cSrcweir // failed 1322cdf0e10cSrcweir pCDInfo->usFirst = 0; 1323cdf0e10cSrcweir pCDInfo->usCount = 0; 1324cdf0e10cSrcweir return FALSE; 1325cdf0e10cSrcweir } 1326cdf0e10cSrcweir 1327cdf0e10cSrcweir /*****************************************************************************/ 1328cdf0e10cSrcweir // Determine if unit is a cdrom or not 1329cdf0e10cSrcweir /*****************************************************************************/ 1330cdf0e10cSrcweir BOOL DriveIsCDROM(UINT uiDrive, CDInfo *pCDInfo) 1331cdf0e10cSrcweir { 1332cdf0e10cSrcweir return (uiDrive >= pCDInfo->usFirst) 1333cdf0e10cSrcweir && (uiDrive < (pCDInfo->usFirst + pCDInfo->usCount)); 1334cdf0e10cSrcweir } 1335cdf0e10cSrcweir 1336cdf0e10cSrcweir /*****************************************************************************/ 1337cdf0e10cSrcweir // Determine attached fstype, e.g. HPFS for specified drive 1338cdf0e10cSrcweir /*****************************************************************************/ 1339cdf0e10cSrcweir BOOL TxFsType // RET FS type resolved 1340cdf0e10cSrcweir ( 1341cdf0e10cSrcweir char *drive, // IN Drive specification 1342cdf0e10cSrcweir char *fstype, // OUT Attached FS type 1343cdf0e10cSrcweir char *details // OUT details (UNC) or NULL 1344cdf0e10cSrcweir ) 1345cdf0e10cSrcweir { 1346cdf0e10cSrcweir BOOL rc = FALSE; 1347cdf0e10cSrcweir FSQBUFFER2 *fsinfo; // Attached FS info 1348cdf0e10cSrcweir ULONG fsdlen = 2048; // Fs info data length 1349cdf0e10cSrcweir 1350cdf0e10cSrcweir strcpy(fstype, "none"); 1351cdf0e10cSrcweir if (details) 1352cdf0e10cSrcweir { 1353cdf0e10cSrcweir strcpy(details, ""); 1354cdf0e10cSrcweir } 1355cdf0e10cSrcweir if ((fsinfo = (FSQBUFFER2*)calloc(1, fsdlen)) != NULL) 1356cdf0e10cSrcweir { 1357cdf0e10cSrcweir if (DosQFSAttach((PCSZ)drive, 0, 1, fsinfo, &fsdlen) == NO_ERROR) 1358cdf0e10cSrcweir { 1359cdf0e10cSrcweir strcpy(fstype, (char*) fsinfo->szName + fsinfo->cbName +1); 1360cdf0e10cSrcweir if (details && (fsinfo->cbFSAData != 0)) 1361cdf0e10cSrcweir { 1362cdf0e10cSrcweir strcpy( details, (char*) fsinfo->szName + fsinfo->cbName + 1363cdf0e10cSrcweir fsinfo->cbFSDName +2); 1364cdf0e10cSrcweir } 1365cdf0e10cSrcweir rc = TRUE; 1366cdf0e10cSrcweir } 1367cdf0e10cSrcweir free(fsinfo); 1368cdf0e10cSrcweir } 1369cdf0e10cSrcweir return (rc); 1370cdf0e10cSrcweir } // end 'TxFsType' 1371cdf0e10cSrcweir /*---------------------------------------------------------------------------*/ 1372cdf0e10cSrcweir 1373cdf0e10cSrcweir 1374cdf0e10cSrcweir /*****************************************************************************/ 1375cdf0e10cSrcweir // Determine if a driveletter represents a removable medium/device 1376cdf0e10cSrcweir /*****************************************************************************/ 1377cdf0e10cSrcweir BOOL TxFsIsRemovable // RET drive is removable 1378cdf0e10cSrcweir ( 1379cdf0e10cSrcweir char *drive // IN Driveletter to test 1380cdf0e10cSrcweir ) 1381cdf0e10cSrcweir { 1382cdf0e10cSrcweir BOOL rc = FALSE; 1383cdf0e10cSrcweir DRIVECMD IOCtl; 1384cdf0e10cSrcweir DRIVEBPB RemAt; 1385cdf0e10cSrcweir ULONG DataLen; 1386cdf0e10cSrcweir ULONG ParmLen; 1387cdf0e10cSrcweir BYTE NoRem; 1388cdf0e10cSrcweir 1389cdf0e10cSrcweir DosError( FERR_DISABLEHARDERR); // avoid 'not ready' popups 1390cdf0e10cSrcweir 1391cdf0e10cSrcweir ParmLen = sizeof(IOCtl); 1392cdf0e10cSrcweir IOCtl.cmd = TXFSDC_BLOCKR; 1393cdf0e10cSrcweir IOCtl.drv = toupper(drive[0]) - 'A'; 1394cdf0e10cSrcweir DataLen = sizeof(NoRem); 1395cdf0e10cSrcweir 1396cdf0e10cSrcweir if (DosDevIOCtl((HFILE) -1, IOCTL_DISK, 1397cdf0e10cSrcweir DSK_BLOCKREMOVABLE, 1398cdf0e10cSrcweir &IOCtl, ParmLen, &ParmLen, 1399cdf0e10cSrcweir &NoRem, DataLen, &DataLen) == NO_ERROR) 1400cdf0e10cSrcweir { 1401cdf0e10cSrcweir if (NoRem) // non-removable sofar, check 1402cdf0e10cSrcweir { // BPB as well (USB devices) 1403cdf0e10cSrcweir ParmLen = sizeof(IOCtl); 1404cdf0e10cSrcweir IOCtl.cmd = TXFSDC_GETBPB; 1405cdf0e10cSrcweir IOCtl.drv = toupper(drive[0]) - 'A'; 1406cdf0e10cSrcweir DataLen = sizeof(RemAt); 1407cdf0e10cSrcweir 1408cdf0e10cSrcweir if (DosDevIOCtl((HFILE) -1, IOCTL_DISK, 1409cdf0e10cSrcweir DSK_GETDEVICEPARAMS, 1410cdf0e10cSrcweir &IOCtl, ParmLen, &ParmLen, 1411cdf0e10cSrcweir &RemAt, DataLen, &DataLen) == NO_ERROR) 1412cdf0e10cSrcweir 1413cdf0e10cSrcweir { 1414cdf0e10cSrcweir if (RemAt.attributes & TXFSBPB_REMOVABLE) 1415cdf0e10cSrcweir { 1416cdf0e10cSrcweir rc = TRUE; // removable, probably USB 1417cdf0e10cSrcweir } 1418cdf0e10cSrcweir } 1419cdf0e10cSrcweir } 1420cdf0e10cSrcweir else 1421cdf0e10cSrcweir { 1422cdf0e10cSrcweir rc = TRUE; // removable block device 1423cdf0e10cSrcweir } 1424cdf0e10cSrcweir } 1425cdf0e10cSrcweir DosError( FERR_ENABLEHARDERR); // enable criterror handler 1426cdf0e10cSrcweir return (rc); 1427cdf0e10cSrcweir } // end 'TxFsIsRemovable' 1428cdf0e10cSrcweir /*---------------------------------------------------------------------------*/ 1429cdf0e10cSrcweir 1430cdf0e10cSrcweir static oslFileError get_drive_type(const char* path, oslVolumeInfo* pInfo) 1431cdf0e10cSrcweir { 1432cdf0e10cSrcweir char Drive_Letter = toupper( *path); 1433cdf0e10cSrcweir char fstype[ 64]; 1434cdf0e10cSrcweir 1435cdf0e10cSrcweir pInfo->uValidFields |= osl_VolumeInfo_Mask_Attributes; 1436cdf0e10cSrcweir 1437cdf0e10cSrcweir // check for floppy A/B 1438cdf0e10cSrcweir BYTE nFloppies; 1439cdf0e10cSrcweir APIRET rc; 1440cdf0e10cSrcweir rc = DosDevConfig( (void*) &nFloppies, DEVINFO_FLOPPY ); 1441cdf0e10cSrcweir if ((Drive_Letter - 'A') < nFloppies) { 1442cdf0e10cSrcweir pInfo->uAttributes |= osl_Volume_Attribute_Removeable; 1443cdf0e10cSrcweir pInfo->uAttributes |= osl_Volume_Attribute_FloppyDisk; 1444cdf0e10cSrcweir return osl_File_E_None; 1445cdf0e10cSrcweir } 1446cdf0e10cSrcweir 1447cdf0e10cSrcweir // query system for CD drives 1448cdf0e10cSrcweir CDInfo cdInfo; 1449cdf0e10cSrcweir GetCDInfo(&cdInfo); 1450cdf0e10cSrcweir 1451cdf0e10cSrcweir // query if drive is a CDROM 1452cdf0e10cSrcweir if (DriveIsCDROM( Drive_Letter - 'A', &cdInfo)) 1453cdf0e10cSrcweir pInfo->uAttributes |= osl_Volume_Attribute_CompactDisc | osl_Volume_Attribute_Removeable; 1454cdf0e10cSrcweir 1455cdf0e10cSrcweir if (TxFsIsRemovable( (char*)path)) 1456cdf0e10cSrcweir pInfo->uAttributes |= osl_Volume_Attribute_Removeable; 1457cdf0e10cSrcweir 1458cdf0e10cSrcweir if (TxFsType( (char*)path, fstype, NULL) == FALSE) { 1459cdf0e10cSrcweir // query failed, assume fixed disk 1460cdf0e10cSrcweir pInfo->uAttributes |= osl_Volume_Attribute_FixedDisk; 1461cdf0e10cSrcweir return osl_File_E_None; 1462cdf0e10cSrcweir } 1463cdf0e10cSrcweir 1464cdf0e10cSrcweir //- Note, connected Win-NT drives use the REAL FS-name like NTFS! 1465cdf0e10cSrcweir if ((strncasecmp( fstype, "LAN", 3) == 0) //- OS/2 LAN drives 1466cdf0e10cSrcweir || (strncasecmp( fstype, "NDFS", 4) == 0) //- NetDrive 1467cdf0e10cSrcweir || (strncasecmp( fstype, "REMOTE", 5) == 0) ) //- NT disconnected 1468cdf0e10cSrcweir pInfo->uAttributes |= osl_Volume_Attribute_Remote; 1469cdf0e10cSrcweir else if (strncasecmp( fstype, "RAMFS", 5) == 0) 1470cdf0e10cSrcweir pInfo->uAttributes |= osl_Volume_Attribute_RAMDisk; 1471cdf0e10cSrcweir else if ((strncasecmp( fstype, "CD", 2) == 0) // OS2:CDFS, DOS/WIN:CDROM 1472cdf0e10cSrcweir || (strncasecmp( fstype, "UDF", 3) == 0) ) // OS2:UDF DVD's 1473cdf0e10cSrcweir pInfo->uAttributes |= osl_Volume_Attribute_CompactDisc | osl_Volume_Attribute_Removeable; 1474cdf0e10cSrcweir else 1475cdf0e10cSrcweir pInfo->uAttributes |= osl_Volume_Attribute_FixedDisk; 1476cdf0e10cSrcweir 1477cdf0e10cSrcweir return osl_File_E_None; 1478cdf0e10cSrcweir } 1479cdf0e10cSrcweir 1480cdf0e10cSrcweir //############################################# 1481cdf0e10cSrcweir inline bool is_volume_space_info_request(sal_uInt32 field_mask) 1482cdf0e10cSrcweir { 1483cdf0e10cSrcweir return (field_mask & 1484cdf0e10cSrcweir (osl_VolumeInfo_Mask_TotalSpace | 1485cdf0e10cSrcweir osl_VolumeInfo_Mask_UsedSpace | 1486cdf0e10cSrcweir osl_VolumeInfo_Mask_FreeSpace)); 1487cdf0e10cSrcweir } 1488cdf0e10cSrcweir 1489cdf0e10cSrcweir //############################################# 1490cdf0e10cSrcweir static void get_volume_space_information(const char* path, oslVolumeInfo *pInfo) 1491cdf0e10cSrcweir { 1492cdf0e10cSrcweir FSALLOCATE aFSInfoBuf; 1493cdf0e10cSrcweir ULONG nDriveNumber = toupper( *path) - 'A' + 1; 1494cdf0e10cSrcweir 1495cdf0e10cSrcweir // disable error popups 1496cdf0e10cSrcweir DosError(FERR_DISABLEHARDERR); 1497cdf0e10cSrcweir APIRET rc = DosQueryFSInfo( nDriveNumber, FSIL_ALLOC, 1498cdf0e10cSrcweir &aFSInfoBuf, sizeof(aFSInfoBuf) ); 1499cdf0e10cSrcweir // enable error popups 1500cdf0e10cSrcweir DosError(FERR_ENABLEHARDERR); 1501cdf0e10cSrcweir if (!rc) 1502cdf0e10cSrcweir { 1503cdf0e10cSrcweir uint64_t aBytesPerCluster( uint64_t(aFSInfoBuf.cbSector) * 1504cdf0e10cSrcweir uint64_t(aFSInfoBuf.cSectorUnit) ); 1505cdf0e10cSrcweir pInfo->uFreeSpace = aBytesPerCluster * uint64_t(aFSInfoBuf.cUnitAvail); 1506cdf0e10cSrcweir pInfo->uTotalSpace = aBytesPerCluster * uint64_t(aFSInfoBuf.cUnit); 1507cdf0e10cSrcweir pInfo->uUsedSpace = pInfo->uTotalSpace - pInfo->uFreeSpace; 1508cdf0e10cSrcweir pInfo->uValidFields |= osl_VolumeInfo_Mask_TotalSpace | 1509cdf0e10cSrcweir osl_VolumeInfo_Mask_UsedSpace | 1510cdf0e10cSrcweir osl_VolumeInfo_Mask_FreeSpace; 1511cdf0e10cSrcweir } 1512cdf0e10cSrcweir } 1513cdf0e10cSrcweir 1514cdf0e10cSrcweir //############################################# 1515cdf0e10cSrcweir inline bool is_filesystem_attributes_request(sal_uInt32 field_mask) 1516cdf0e10cSrcweir { 1517cdf0e10cSrcweir return (field_mask & 1518cdf0e10cSrcweir (osl_VolumeInfo_Mask_MaxNameLength | 1519cdf0e10cSrcweir osl_VolumeInfo_Mask_MaxPathLength | 1520cdf0e10cSrcweir osl_VolumeInfo_Mask_FileSystemName | 1521cdf0e10cSrcweir osl_VolumeInfo_Mask_FileSystemCaseHandling)); 1522cdf0e10cSrcweir } 1523cdf0e10cSrcweir 1524cdf0e10cSrcweir //############################################# 1525cdf0e10cSrcweir inline bool is_drivetype_request(sal_uInt32 field_mask) 1526cdf0e10cSrcweir { 1527cdf0e10cSrcweir return (field_mask & osl_VolumeInfo_Mask_Attributes); 1528cdf0e10cSrcweir } 1529cdf0e10cSrcweir 1530cdf0e10cSrcweir typedef struct _FSQBUFFER_ 1531cdf0e10cSrcweir { 1532cdf0e10cSrcweir FSQBUFFER2 aBuf; 1533cdf0e10cSrcweir UCHAR sBuf[64]; 1534cdf0e10cSrcweir } FSQBUFFER_; 1535cdf0e10cSrcweir 1536cdf0e10cSrcweir //############################################# 1537cdf0e10cSrcweir static oslFileError get_filesystem_attributes(const char* path, sal_uInt32 field_mask, oslVolumeInfo* pInfo) 1538cdf0e10cSrcweir { 1539cdf0e10cSrcweir pInfo->uAttributes = 0; 1540cdf0e10cSrcweir 1541cdf0e10cSrcweir oslFileError osl_error = osl_File_E_None; 1542cdf0e10cSrcweir 1543cdf0e10cSrcweir // osl_get_drive_type must be called first because 1544cdf0e10cSrcweir // this function resets osl_VolumeInfo_Mask_Attributes 1545cdf0e10cSrcweir // on failure 1546cdf0e10cSrcweir if (is_drivetype_request(field_mask)) 1547cdf0e10cSrcweir osl_error = get_drive_type(path, pInfo); 1548cdf0e10cSrcweir 1549cdf0e10cSrcweir if ((osl_File_E_None == osl_error) && is_filesystem_attributes_request(field_mask)) 1550cdf0e10cSrcweir { 1551cdf0e10cSrcweir FSQBUFFER_ aBuf; 1552cdf0e10cSrcweir ULONG nBufLen; 1553cdf0e10cSrcweir APIRET nRet; 1554cdf0e10cSrcweir 1555cdf0e10cSrcweir nBufLen = sizeof( aBuf ); 1556cdf0e10cSrcweir // disable error popups 1557cdf0e10cSrcweir DosError(FERR_DISABLEHARDERR); 1558cdf0e10cSrcweir nRet = DosQueryFSAttach( (PCSZ)path, 0, FSAIL_QUERYNAME, (_FSQBUFFER2*) &aBuf, &nBufLen ); 1559cdf0e10cSrcweir if ( !nRet ) 1560cdf0e10cSrcweir { 1561cdf0e10cSrcweir char *pType = (char*)(aBuf.aBuf.szName + aBuf.aBuf.cbName + 1); 1562cdf0e10cSrcweir pInfo->uValidFields |= osl_VolumeInfo_Mask_MaxNameLength; 1563cdf0e10cSrcweir pInfo->uMaxNameLength = _MAX_FNAME; 1564cdf0e10cSrcweir 1565cdf0e10cSrcweir pInfo->uValidFields |= osl_VolumeInfo_Mask_MaxPathLength; 1566cdf0e10cSrcweir pInfo->uMaxPathLength = _MAX_PATH; 1567cdf0e10cSrcweir 1568cdf0e10cSrcweir pInfo->uValidFields |= osl_VolumeInfo_Mask_FileSystemName; 1569cdf0e10cSrcweir rtl_uString_newFromAscii(&pInfo->ustrFileSystemName, pType); 1570cdf0e10cSrcweir 1571cdf0e10cSrcweir // case is preserved always except for FAT 1572cdf0e10cSrcweir if (strcmp( pType, "FAT" )) 1573cdf0e10cSrcweir pInfo->uAttributes |= osl_Volume_Attribute_Case_Is_Preserved; 1574cdf0e10cSrcweir 1575cdf0e10cSrcweir pInfo->uValidFields |= osl_VolumeInfo_Mask_Attributes; 1576cdf0e10cSrcweir } 1577cdf0e10cSrcweir // enable error popups 1578cdf0e10cSrcweir DosError(FERR_ENABLEHARDERR); 1579cdf0e10cSrcweir } 1580cdf0e10cSrcweir return osl_error; 1581cdf0e10cSrcweir } 1582cdf0e10cSrcweir 1583cdf0e10cSrcweir oslFileError SAL_CALL osl_getVolumeInformation( rtl_uString* ustrDirectoryURL, oslVolumeInfo* pInfo, sal_uInt32 uFieldMask ) 1584cdf0e10cSrcweir { 1585cdf0e10cSrcweir char volume_root[PATH_MAX]; 1586cdf0e10cSrcweir oslFileError error; 1587cdf0e10cSrcweir 1588cdf0e10cSrcweir OSL_ASSERT( ustrDirectoryURL ); 1589cdf0e10cSrcweir OSL_ASSERT( pInfo ); 1590cdf0e10cSrcweir 1591cdf0e10cSrcweir /* convert directory url to system path */ 1592cdf0e10cSrcweir error = FileURLToPath( volume_root, PATH_MAX, ustrDirectoryURL ); 1593cdf0e10cSrcweir if( error != osl_File_E_None ) 1594cdf0e10cSrcweir return error; 1595cdf0e10cSrcweir 1596cdf0e10cSrcweir if (!pInfo) 1597cdf0e10cSrcweir return osl_File_E_INVAL; 1598cdf0e10cSrcweir 1599cdf0e10cSrcweir pInfo->uValidFields = 0; 1600cdf0e10cSrcweir 1601cdf0e10cSrcweir if ((error = get_filesystem_attributes(volume_root, uFieldMask, pInfo)) != osl_File_E_None) 1602cdf0e10cSrcweir return error; 1603cdf0e10cSrcweir 1604cdf0e10cSrcweir if (is_volume_space_info_request(uFieldMask)) 1605cdf0e10cSrcweir get_volume_space_information(volume_root, pInfo); 1606cdf0e10cSrcweir 1607cdf0e10cSrcweir if (uFieldMask & osl_VolumeInfo_Mask_DeviceHandle) 1608cdf0e10cSrcweir { 1609cdf0e10cSrcweir pInfo->uValidFields |= osl_VolumeInfo_Mask_DeviceHandle; 1610cdf0e10cSrcweir rtl_uString* uVolumeRoot; 1611cdf0e10cSrcweir rtl_uString_newFromAscii( &uVolumeRoot, volume_root); 1612cdf0e10cSrcweir osl_getFileURLFromSystemPath( uVolumeRoot, (rtl_uString**)&pInfo->pDeviceHandle); 1613cdf0e10cSrcweir rtl_uString_release( uVolumeRoot); 1614cdf0e10cSrcweir } 1615cdf0e10cSrcweir 1616cdf0e10cSrcweir return osl_File_E_None; 1617cdf0e10cSrcweir } 1618cdf0e10cSrcweir 1619cdf0e10cSrcweir /****************************************************************************/ 1620cdf0e10cSrcweir /* osl_getFileStatus */ 1621cdf0e10cSrcweir /****************************************************************************/ 1622cdf0e10cSrcweir static oslFileError _osl_getDriveInfo( 1623cdf0e10cSrcweir oslDirectoryItem Item, oslFileStatus *pStatus, sal_uInt32 uFieldMask) 1624cdf0e10cSrcweir { 1625cdf0e10cSrcweir DirectoryItem_Impl *pItemImpl = (DirectoryItem_Impl *)Item; 1626cdf0e10cSrcweir sal_Unicode cDrive[3]; 1627cdf0e10cSrcweir sal_Unicode cRoot[4]; 1628cdf0e10cSrcweir 1629cdf0e10cSrcweir if ( !pItemImpl ) 1630cdf0e10cSrcweir return osl_File_E_INVAL; 1631cdf0e10cSrcweir 1632cdf0e10cSrcweir pStatus->uValidFields = 0; 1633cdf0e10cSrcweir 1634cdf0e10cSrcweir cDrive[0] = pItemImpl->ustrDrive->buffer[0]; 1635cdf0e10cSrcweir cDrive[1] = (sal_Unicode)':'; 1636cdf0e10cSrcweir cDrive[2] = 0; 1637cdf0e10cSrcweir cRoot[0] = pItemImpl->ustrDrive->buffer[0]; 1638cdf0e10cSrcweir cRoot[1] = (sal_Unicode)':'; 1639cdf0e10cSrcweir cRoot[2] = 0; 1640cdf0e10cSrcweir 1641cdf0e10cSrcweir if ( uFieldMask & osl_FileStatus_Mask_FileName ) 1642cdf0e10cSrcweir { 1643cdf0e10cSrcweir if ( pItemImpl->ustrDrive->buffer[0] == '\\' && 1644cdf0e10cSrcweir pItemImpl->ustrDrive->buffer[1] == '\\' ) 1645cdf0e10cSrcweir { 1646cdf0e10cSrcweir LPCWSTR lpFirstBkSlash = wcschr( (const wchar_t*)&pItemImpl->ustrDrive->buffer[2], '\\' ); 1647cdf0e10cSrcweir 1648cdf0e10cSrcweir if ( lpFirstBkSlash && lpFirstBkSlash[1] ) 1649cdf0e10cSrcweir { 1650cdf0e10cSrcweir LPCWSTR lpLastBkSlash = wcschr( (const wchar_t*)&lpFirstBkSlash[1], '\\' ); 1651cdf0e10cSrcweir 1652cdf0e10cSrcweir if ( lpLastBkSlash ) 1653cdf0e10cSrcweir rtl_uString_newFromStr_WithLength( &pStatus->ustrFileName, (sal_Unicode*)&lpFirstBkSlash[1], lpLastBkSlash - lpFirstBkSlash - 1 ); 1654cdf0e10cSrcweir else 1655cdf0e10cSrcweir rtl_uString_newFromStr( &pStatus->ustrFileName, (sal_Unicode*)&lpFirstBkSlash[1] ); 1656cdf0e10cSrcweir pStatus->uValidFields |= osl_FileStatus_Mask_FileName; 1657cdf0e10cSrcweir } 1658cdf0e10cSrcweir } 1659cdf0e10cSrcweir else 1660cdf0e10cSrcweir { 1661cdf0e10cSrcweir FSINFO aFSInfoBuf; 1662cdf0e10cSrcweir ULONG ulFSInfoLevel = FSIL_VOLSER; 1663cdf0e10cSrcweir ULONG nDriveNumber; 1664cdf0e10cSrcweir char szFileName[ _MAX_PATH]; 1665cdf0e10cSrcweir 1666cdf0e10cSrcweir nDriveNumber = toupper(*cDrive) - 'A' + 1; 1667cdf0e10cSrcweir memset( &aFSInfoBuf, 0, sizeof(FSINFO) ); 1668cdf0e10cSrcweir // disable error popups 1669cdf0e10cSrcweir DosError(FERR_DISABLEHARDERR); 1670cdf0e10cSrcweir APIRET rc = DosQueryFSInfo( nDriveNumber, ulFSInfoLevel, &aFSInfoBuf, sizeof(FSINFO) ); 1671cdf0e10cSrcweir // enable error popups 1672cdf0e10cSrcweir DosError(FERR_ENABLEHARDERR); 1673cdf0e10cSrcweir memset( szFileName, 0, sizeof( szFileName)); 1674cdf0e10cSrcweir *szFileName = toupper(*cDrive); 1675cdf0e10cSrcweir strcat( szFileName, ": ["); 1676cdf0e10cSrcweir if ( !rc || aFSInfoBuf.vol.cch) 1677cdf0e10cSrcweir strncat( szFileName, aFSInfoBuf.vol.szVolLabel, aFSInfoBuf.vol.cch); 1678cdf0e10cSrcweir strcat( szFileName, "]"); 1679cdf0e10cSrcweir rtl_uString_newFromAscii( &pStatus->ustrFileName, szFileName ); 1680cdf0e10cSrcweir 1681cdf0e10cSrcweir pStatus->uValidFields |= osl_FileStatus_Mask_FileName; 1682cdf0e10cSrcweir } 1683cdf0e10cSrcweir } 1684cdf0e10cSrcweir 1685cdf0e10cSrcweir pStatus->eType = osl_File_Type_Volume; 1686cdf0e10cSrcweir pStatus->uValidFields |= osl_FileStatus_Mask_Type; 1687cdf0e10cSrcweir 1688cdf0e10cSrcweir if ( uFieldMask & osl_FileStatus_Mask_FileURL ) 1689cdf0e10cSrcweir { 1690cdf0e10cSrcweir rtl_uString *ustrSystemPath = NULL; 1691cdf0e10cSrcweir 1692cdf0e10cSrcweir rtl_uString_newFromStr( &ustrSystemPath, pItemImpl->ustrDrive->buffer ); 1693cdf0e10cSrcweir osl_getFileURLFromSystemPath( ustrSystemPath, &pStatus->ustrFileURL ); 1694cdf0e10cSrcweir rtl_uString_release( ustrSystemPath ); 1695cdf0e10cSrcweir pStatus->uValidFields |= osl_FileStatus_Mask_FileURL; 1696cdf0e10cSrcweir } 1697cdf0e10cSrcweir 1698cdf0e10cSrcweir return osl_File_E_None; 1699cdf0e10cSrcweir } 1700cdf0e10cSrcweir 1701cdf0e10cSrcweir oslFileError SAL_CALL osl_getFileStatus( 1702cdf0e10cSrcweir oslDirectoryItem Item, 1703cdf0e10cSrcweir oslFileStatus *pStatus, 1704cdf0e10cSrcweir sal_uInt32 uFieldMask ) 1705cdf0e10cSrcweir { 1706cdf0e10cSrcweir DirectoryItem_Impl *pItemImpl = (DirectoryItem_Impl *)Item; 1707cdf0e10cSrcweir struct stat file_stat; 1708cdf0e10cSrcweir 1709cdf0e10cSrcweir if ( !pItemImpl ) 1710cdf0e10cSrcweir return osl_File_E_INVAL; 1711cdf0e10cSrcweir 1712cdf0e10cSrcweir if ( pItemImpl->uType == DIRECTORYITEM_DRIVE) 1713cdf0e10cSrcweir return _osl_getDriveInfo( Item, pStatus, uFieldMask ); 1714cdf0e10cSrcweir 1715cdf0e10cSrcweir osl::lstat(pItemImpl->ustrFilePath, file_stat); 1716cdf0e10cSrcweir if ( uFieldMask & osl_FileStatus_Mask_Validate ) 1717cdf0e10cSrcweir { 1718cdf0e10cSrcweir uFieldMask &= ~ osl_FileStatus_Mask_Validate; 1719cdf0e10cSrcweir } 1720cdf0e10cSrcweir 1721cdf0e10cSrcweir /* If no fields to retrieve left ignore pStatus */ 1722cdf0e10cSrcweir if ( !uFieldMask ) 1723cdf0e10cSrcweir return osl_File_E_None; 1724cdf0e10cSrcweir 1725cdf0e10cSrcweir /* Otherwise, this must be a valid pointer */ 1726cdf0e10cSrcweir if ( !pStatus ) 1727cdf0e10cSrcweir return osl_File_E_INVAL; 1728cdf0e10cSrcweir 1729cdf0e10cSrcweir if ( pStatus->uStructSize != sizeof(oslFileStatus) ) 1730cdf0e10cSrcweir return osl_File_E_INVAL; 1731cdf0e10cSrcweir 1732cdf0e10cSrcweir pStatus->uValidFields = 0; 1733cdf0e10cSrcweir 1734cdf0e10cSrcweir /* File time stamps */ 1735cdf0e10cSrcweir 1736cdf0e10cSrcweir if ( (uFieldMask & osl_FileStatus_Mask_ModifyTime)) 1737cdf0e10cSrcweir { 1738cdf0e10cSrcweir pStatus->aModifyTime.Seconds = file_stat.st_mtime; 1739cdf0e10cSrcweir pStatus->aModifyTime.Nanosec = 0; 1740cdf0e10cSrcweir pStatus->uValidFields |= osl_FileStatus_Mask_ModifyTime; 1741cdf0e10cSrcweir } 1742cdf0e10cSrcweir 1743cdf0e10cSrcweir if ( (uFieldMask & osl_FileStatus_Mask_AccessTime)) 1744cdf0e10cSrcweir { 1745cdf0e10cSrcweir pStatus->aAccessTime.Seconds = file_stat.st_atime; 1746cdf0e10cSrcweir pStatus->aAccessTime.Nanosec = 0; 1747cdf0e10cSrcweir pStatus->uValidFields |= osl_FileStatus_Mask_AccessTime; 1748cdf0e10cSrcweir } 1749cdf0e10cSrcweir 1750cdf0e10cSrcweir if ( (uFieldMask & osl_FileStatus_Mask_CreationTime)) 1751cdf0e10cSrcweir { 1752cdf0e10cSrcweir pStatus->aAccessTime.Seconds = file_stat.st_birthtime; 1753cdf0e10cSrcweir pStatus->aAccessTime.Nanosec = 0; 1754cdf0e10cSrcweir pStatus->uValidFields |= osl_FileStatus_Mask_CreationTime; 1755cdf0e10cSrcweir } 1756cdf0e10cSrcweir 1757cdf0e10cSrcweir /* Most of the fields are already set, regardless of requiered fields */ 1758cdf0e10cSrcweir 1759cdf0e10cSrcweir osl_systemPathGetFileNameOrLastDirectoryPart(pItemImpl->ustrFilePath, &pStatus->ustrFileName); 1760cdf0e10cSrcweir pStatus->uValidFields |= osl_FileStatus_Mask_FileName; 1761cdf0e10cSrcweir 1762cdf0e10cSrcweir if (S_ISLNK(file_stat.st_mode)) 1763cdf0e10cSrcweir pStatus->eType = osl_File_Type_Link; 1764cdf0e10cSrcweir else if (S_ISDIR(file_stat.st_mode)) 1765cdf0e10cSrcweir pStatus->eType = osl_File_Type_Directory; 1766cdf0e10cSrcweir else if (S_ISREG(file_stat.st_mode)) 1767cdf0e10cSrcweir pStatus->eType = osl_File_Type_Regular; 1768cdf0e10cSrcweir else if (S_ISFIFO(file_stat.st_mode)) 1769cdf0e10cSrcweir pStatus->eType = osl_File_Type_Fifo; 1770cdf0e10cSrcweir else if (S_ISSOCK(file_stat.st_mode)) 1771cdf0e10cSrcweir pStatus->eType = osl_File_Type_Socket; 1772cdf0e10cSrcweir else if (S_ISCHR(file_stat.st_mode) || S_ISBLK(file_stat.st_mode)) 1773cdf0e10cSrcweir pStatus->eType = osl_File_Type_Special; 1774cdf0e10cSrcweir else 1775cdf0e10cSrcweir pStatus->eType = osl_File_Type_Unknown; 1776cdf0e10cSrcweir 1777cdf0e10cSrcweir pStatus->uValidFields |= osl_FileStatus_Mask_Type; 1778cdf0e10cSrcweir 1779cdf0e10cSrcweir pStatus->uAttributes = pItemImpl->d_attr; 1780cdf0e10cSrcweir pStatus->uValidFields |= osl_FileStatus_Mask_Attributes; 1781cdf0e10cSrcweir 1782cdf0e10cSrcweir pStatus->uFileSize = file_stat.st_size; 1783cdf0e10cSrcweir pStatus->uValidFields |= osl_FileStatus_Mask_FileSize; 1784cdf0e10cSrcweir 1785cdf0e10cSrcweir if ( uFieldMask & osl_FileStatus_Mask_LinkTargetURL ) 1786cdf0e10cSrcweir { 1787cdf0e10cSrcweir rtl_uString *ustrFullPath = NULL; 1788cdf0e10cSrcweir 1789cdf0e10cSrcweir rtl_uString_newFromStr( &ustrFullPath, rtl_uString_getStr(pItemImpl->ustrFilePath) ); 1790cdf0e10cSrcweir osl_getFileURLFromSystemPath( ustrFullPath, &pStatus->ustrLinkTargetURL ); 1791cdf0e10cSrcweir rtl_uString_release( ustrFullPath ); 1792cdf0e10cSrcweir 1793cdf0e10cSrcweir pStatus->uValidFields |= osl_FileStatus_Mask_LinkTargetURL; 1794cdf0e10cSrcweir } 1795cdf0e10cSrcweir 1796cdf0e10cSrcweir if ( uFieldMask & osl_FileStatus_Mask_FileURL ) 1797cdf0e10cSrcweir { 1798cdf0e10cSrcweir rtl_uString *ustrFullPath = NULL; 1799cdf0e10cSrcweir 1800cdf0e10cSrcweir rtl_uString_newFromStr( &ustrFullPath, rtl_uString_getStr(pItemImpl->ustrFilePath) ); 1801cdf0e10cSrcweir osl_getFileURLFromSystemPath( ustrFullPath, &pStatus->ustrFileURL ); 1802cdf0e10cSrcweir rtl_uString_release( ustrFullPath ); 1803cdf0e10cSrcweir pStatus->uValidFields |= osl_FileStatus_Mask_FileURL; 1804cdf0e10cSrcweir } 1805cdf0e10cSrcweir 1806cdf0e10cSrcweir return osl_File_E_None; 1807cdf0e10cSrcweir } 1808cdf0e10cSrcweir 1809cdf0e10cSrcweir /****************************************************************************/ 1810cdf0e10cSrcweir /* osl_createDirectory */ 1811cdf0e10cSrcweir /****************************************************************************/ 1812cdf0e10cSrcweir 1813cdf0e10cSrcweir oslFileError osl_createDirectory( rtl_uString* ustrDirectoryURL ) 1814cdf0e10cSrcweir { 1815cdf0e10cSrcweir char path[PATH_MAX]; 1816cdf0e10cSrcweir oslFileError eRet; 1817cdf0e10cSrcweir APIRET rc; 1818cdf0e10cSrcweir 1819cdf0e10cSrcweir OSL_ASSERT( ustrDirectoryURL ); 1820cdf0e10cSrcweir 1821cdf0e10cSrcweir /* convert directory url to system path */ 1822cdf0e10cSrcweir eRet = FileURLToPath( path, PATH_MAX, ustrDirectoryURL ); 1823cdf0e10cSrcweir if( eRet != osl_File_E_None ) 1824cdf0e10cSrcweir return eRet; 1825cdf0e10cSrcweir 1826cdf0e10cSrcweir rc = DosCreateDir( (PCSZ)path, NULL); 1827cdf0e10cSrcweir if (rc == ERROR_ACCESS_DENIED) 1828cdf0e10cSrcweir rc=ERROR_FILE_EXISTS; 1829cdf0e10cSrcweir 1830cdf0e10cSrcweir if (!rc) 1831cdf0e10cSrcweir eRet = osl_File_E_None; 1832cdf0e10cSrcweir else 1833cdf0e10cSrcweir eRet = MapError( rc); 1834cdf0e10cSrcweir 1835cdf0e10cSrcweir return eRet; 1836cdf0e10cSrcweir } 1837cdf0e10cSrcweir 1838cdf0e10cSrcweir /****************************************************************************/ 1839cdf0e10cSrcweir /* osl_removeDirectory */ 1840cdf0e10cSrcweir /****************************************************************************/ 1841cdf0e10cSrcweir 1842cdf0e10cSrcweir oslFileError osl_removeDirectory( rtl_uString* ustrDirectoryURL ) 1843cdf0e10cSrcweir { 1844cdf0e10cSrcweir char path[PATH_MAX]; 1845cdf0e10cSrcweir oslFileError eRet; 1846cdf0e10cSrcweir APIRET rc; 1847cdf0e10cSrcweir 1848cdf0e10cSrcweir OSL_ASSERT( ustrDirectoryURL ); 1849cdf0e10cSrcweir 1850cdf0e10cSrcweir /* convert directory url to system path */ 1851cdf0e10cSrcweir eRet = FileURLToPath( path, PATH_MAX, ustrDirectoryURL ); 1852cdf0e10cSrcweir if( eRet != osl_File_E_None ) 1853cdf0e10cSrcweir return eRet; 1854cdf0e10cSrcweir 1855cdf0e10cSrcweir rc = DosDeleteDir( (PCSZ)path); 1856cdf0e10cSrcweir if (!rc) 1857cdf0e10cSrcweir eRet = osl_File_E_None; 1858cdf0e10cSrcweir else 1859cdf0e10cSrcweir eRet = MapError( rc); 1860cdf0e10cSrcweir 1861cdf0e10cSrcweir return eRet; 1862cdf0e10cSrcweir } 1863cdf0e10cSrcweir 1864cdf0e10cSrcweir //############################################# 1865cdf0e10cSrcweir int path_make_parent(sal_Unicode* path) 1866cdf0e10cSrcweir { 1867cdf0e10cSrcweir int i = rtl_ustr_lastIndexOfChar(path, '/'); 1868cdf0e10cSrcweir 1869cdf0e10cSrcweir if (i > 0) 1870cdf0e10cSrcweir { 1871cdf0e10cSrcweir *(path + i) = 0; 1872cdf0e10cSrcweir return i; 1873cdf0e10cSrcweir } 1874cdf0e10cSrcweir else 1875cdf0e10cSrcweir return 0; 1876cdf0e10cSrcweir } 1877cdf0e10cSrcweir 1878cdf0e10cSrcweir //############################################# 1879cdf0e10cSrcweir int create_dir_with_callback( 1880cdf0e10cSrcweir sal_Unicode* directory_path, 1881cdf0e10cSrcweir oslDirectoryCreationCallbackFunc aDirectoryCreationCallbackFunc, 1882cdf0e10cSrcweir void* pData) 1883cdf0e10cSrcweir { 1884cdf0e10cSrcweir int mode = S_IRWXU | S_IRWXG | S_IRWXO; 1885cdf0e10cSrcweir 1886cdf0e10cSrcweir if (osl::mkdir(directory_path, mode) == 0) 1887cdf0e10cSrcweir { 1888cdf0e10cSrcweir if (aDirectoryCreationCallbackFunc) 1889cdf0e10cSrcweir { 1890cdf0e10cSrcweir rtl::OUString url; 1891cdf0e10cSrcweir osl::FileBase::getFileURLFromSystemPath(directory_path, url); 1892cdf0e10cSrcweir aDirectoryCreationCallbackFunc(pData, url.pData); 1893cdf0e10cSrcweir } 1894cdf0e10cSrcweir return 0; 1895cdf0e10cSrcweir } 1896cdf0e10cSrcweir return errno; 1897cdf0e10cSrcweir } 1898cdf0e10cSrcweir 1899cdf0e10cSrcweir //############################################# 1900cdf0e10cSrcweir oslFileError create_dir_recursively_( 1901cdf0e10cSrcweir sal_Unicode* dir_path, 1902cdf0e10cSrcweir oslDirectoryCreationCallbackFunc aDirectoryCreationCallbackFunc, 1903cdf0e10cSrcweir void* pData) 1904cdf0e10cSrcweir { 1905cdf0e10cSrcweir OSL_PRECOND((rtl_ustr_getLength(dir_path) > 0) && ((dir_path + (rtl_ustr_getLength(dir_path) - 1)) != (dir_path + rtl_ustr_lastIndexOfChar(dir_path, '/'))), \ 1906cdf0e10cSrcweir "Path must not end with a slash"); 1907cdf0e10cSrcweir 1908cdf0e10cSrcweir int native_err = create_dir_with_callback( 1909cdf0e10cSrcweir dir_path, aDirectoryCreationCallbackFunc, pData); 1910cdf0e10cSrcweir 1911cdf0e10cSrcweir if (native_err == 0) 1912cdf0e10cSrcweir return osl_File_E_None; 1913cdf0e10cSrcweir 1914cdf0e10cSrcweir if (native_err != ENOENT) 1915cdf0e10cSrcweir return oslTranslateFileError(OSL_FET_ERROR, native_err); 1916cdf0e10cSrcweir 1917cdf0e10cSrcweir // we step back until '/a_dir' at maximum because 1918cdf0e10cSrcweir // we should get an error unequal ENOENT when 1919cdf0e10cSrcweir // we try to create 'a_dir' at '/' and would so 1920cdf0e10cSrcweir // return before 1921cdf0e10cSrcweir int pos = path_make_parent(dir_path); 1922cdf0e10cSrcweir 1923cdf0e10cSrcweir oslFileError osl_error = create_dir_recursively_( 1924cdf0e10cSrcweir dir_path, aDirectoryCreationCallbackFunc, pData); 1925cdf0e10cSrcweir 1926cdf0e10cSrcweir if (osl_File_E_None != osl_error) 1927cdf0e10cSrcweir return osl_error; 1928cdf0e10cSrcweir 1929cdf0e10cSrcweir dir_path[pos] = '/'; 1930cdf0e10cSrcweir 1931cdf0e10cSrcweir return create_dir_recursively_(dir_path, aDirectoryCreationCallbackFunc, pData); 1932cdf0e10cSrcweir } 1933cdf0e10cSrcweir 1934cdf0e10cSrcweir //####################################### 1935cdf0e10cSrcweir oslFileError SAL_CALL osl_createDirectoryPath( 1936cdf0e10cSrcweir rtl_uString* aDirectoryUrl, 1937cdf0e10cSrcweir oslDirectoryCreationCallbackFunc aDirectoryCreationCallbackFunc, 1938cdf0e10cSrcweir void* pData) 1939cdf0e10cSrcweir { 1940cdf0e10cSrcweir if (aDirectoryUrl == NULL) 1941cdf0e10cSrcweir return osl_File_E_INVAL; 1942cdf0e10cSrcweir 1943cdf0e10cSrcweir rtl::OUString sys_path; 1944cdf0e10cSrcweir oslFileError osl_error = osl_getSystemPathFromFileURL_Ex( 1945cdf0e10cSrcweir aDirectoryUrl, &sys_path.pData, sal_False); 1946cdf0e10cSrcweir 1947cdf0e10cSrcweir if (osl_error != osl_File_E_None) 1948cdf0e10cSrcweir return osl_error; 1949cdf0e10cSrcweir 1950cdf0e10cSrcweir osl::systemPathRemoveSeparator(sys_path); 1951cdf0e10cSrcweir 1952cdf0e10cSrcweir // const_cast because sys_path is a local copy which we want to modify inplace instead of 1953cdf0e10cSrcweir // coyp it into another buffer on the heap again 1954cdf0e10cSrcweir return create_dir_recursively_(sys_path.pData->buffer, aDirectoryCreationCallbackFunc, pData); 1955cdf0e10cSrcweir } 1956cdf0e10cSrcweir 1957cdf0e10cSrcweir /****************************************************************************/ 1958cdf0e10cSrcweir /* osl_getCanonicalName */ 1959cdf0e10cSrcweir /****************************************************************************/ 1960cdf0e10cSrcweir 1961cdf0e10cSrcweir oslFileError osl_getCanonicalName( rtl_uString* ustrFileURL, rtl_uString** pustrValidURL ) 1962cdf0e10cSrcweir { 1963cdf0e10cSrcweir OSL_ENSURE(sal_False, "osl_getCanonicalName not implemented"); 1964cdf0e10cSrcweir 1965cdf0e10cSrcweir rtl_uString_newFromString(pustrValidURL, ustrFileURL); 1966cdf0e10cSrcweir return osl_File_E_None; 1967cdf0e10cSrcweir } 1968cdf0e10cSrcweir 1969cdf0e10cSrcweir 1970cdf0e10cSrcweir /****************************************************************************/ 1971cdf0e10cSrcweir /* osl_setFileAttributes */ 1972cdf0e10cSrcweir /****************************************************************************/ 1973cdf0e10cSrcweir 1974cdf0e10cSrcweir oslFileError osl_setFileAttributes( rtl_uString* ustrFileURL, sal_uInt64 uAttributes ) 1975cdf0e10cSrcweir { 1976cdf0e10cSrcweir char path[PATH_MAX]; 1977cdf0e10cSrcweir oslFileError eRet; 1978cdf0e10cSrcweir FILESTATUS3 fsts3ConfigInfo; 1979cdf0e10cSrcweir ULONG ulBufSize = sizeof(FILESTATUS3); 1980cdf0e10cSrcweir APIRET rc = NO_ERROR; 1981cdf0e10cSrcweir 1982cdf0e10cSrcweir OSL_ASSERT( ustrFileURL ); 1983cdf0e10cSrcweir 1984cdf0e10cSrcweir /* convert file url to system path */ 1985cdf0e10cSrcweir eRet = FileURLToPath( path, PATH_MAX, ustrFileURL ); 1986cdf0e10cSrcweir if( eRet != osl_File_E_None ) 1987cdf0e10cSrcweir return eRet; 1988cdf0e10cSrcweir 1989cdf0e10cSrcweir /* query current attributes */ 1990cdf0e10cSrcweir rc = DosQueryPathInfo( (PCSZ)path, FIL_STANDARD, &fsts3ConfigInfo, ulBufSize); 1991cdf0e10cSrcweir if (rc != NO_ERROR) 1992cdf0e10cSrcweir return MapError( rc); 1993cdf0e10cSrcweir 1994cdf0e10cSrcweir /* set/reset readonly/hidden (see w32\file.cxx) */ 1995cdf0e10cSrcweir fsts3ConfigInfo.attrFile &= ~(FILE_READONLY | FILE_HIDDEN); 1996cdf0e10cSrcweir if ( uAttributes & osl_File_Attribute_ReadOnly ) 1997cdf0e10cSrcweir fsts3ConfigInfo.attrFile |= FILE_READONLY; 1998cdf0e10cSrcweir if ( uAttributes & osl_File_Attribute_Hidden ) 1999cdf0e10cSrcweir fsts3ConfigInfo.attrFile |= FILE_HIDDEN; 2000cdf0e10cSrcweir 2001cdf0e10cSrcweir /* write new attributes */ 2002cdf0e10cSrcweir rc = DosSetPathInfo( (PCSZ)path, FIL_STANDARD, &fsts3ConfigInfo, ulBufSize, 0); 2003cdf0e10cSrcweir if (rc != NO_ERROR) 2004cdf0e10cSrcweir return MapError( rc); 2005cdf0e10cSrcweir 2006cdf0e10cSrcweir /* everything ok */ 2007cdf0e10cSrcweir return osl_File_E_None; 2008cdf0e10cSrcweir } 2009cdf0e10cSrcweir 2010cdf0e10cSrcweir /****************************************************************************/ 2011cdf0e10cSrcweir /* osl_setFileTime */ 2012cdf0e10cSrcweir /****************************************************************************/ 2013cdf0e10cSrcweir 2014cdf0e10cSrcweir oslFileError osl_setFileTime( rtl_uString* ustrFileURL, const TimeValue* pCreationTime, 2015cdf0e10cSrcweir const TimeValue* pLastAccessTime, const TimeValue* pLastWriteTime ) 2016cdf0e10cSrcweir { 2017cdf0e10cSrcweir char path[PATH_MAX]; 2018cdf0e10cSrcweir oslFileError eRet; 2019cdf0e10cSrcweir 2020cdf0e10cSrcweir OSL_ASSERT( ustrFileURL ); 2021cdf0e10cSrcweir 2022cdf0e10cSrcweir /* convert file url to system path */ 2023cdf0e10cSrcweir eRet = FileURLToPath( path, PATH_MAX, ustrFileURL ); 2024cdf0e10cSrcweir if( eRet != osl_File_E_None ) 2025cdf0e10cSrcweir return eRet; 2026cdf0e10cSrcweir 2027cdf0e10cSrcweir return osl_psz_setFileTime( path, pCreationTime, pLastAccessTime, pLastWriteTime ); 2028cdf0e10cSrcweir } 2029cdf0e10cSrcweir 2030cdf0e10cSrcweir /****************************************************************************** 2031cdf0e10cSrcweir * 2032cdf0e10cSrcweir * Exported Module Functions 2033cdf0e10cSrcweir * (independent of C or Unicode Strings) 2034cdf0e10cSrcweir * 2035cdf0e10cSrcweir *****************************************************************************/ 2036cdf0e10cSrcweir 2037cdf0e10cSrcweir 2038cdf0e10cSrcweir /******************************************* 2039cdf0e10cSrcweir osl_readFile 2040cdf0e10cSrcweir ********************************************/ 2041cdf0e10cSrcweir 2042cdf0e10cSrcweir oslFileError osl_readFile(oslFileHandle Handle, void* pBuffer, sal_uInt64 uBytesRequested, sal_uInt64* pBytesRead) 2043cdf0e10cSrcweir { 2044cdf0e10cSrcweir ssize_t nBytes = 0; 2045cdf0e10cSrcweir oslFileHandleImpl* pHandleImpl = (oslFileHandleImpl*)Handle; 2046cdf0e10cSrcweir 2047cdf0e10cSrcweir if ((0 == pHandleImpl) || (pHandleImpl->fd < 0) || (0 == pBuffer) || (0 == pBytesRead)) 2048cdf0e10cSrcweir return osl_File_E_INVAL; 2049cdf0e10cSrcweir 2050cdf0e10cSrcweir nBytes = read(pHandleImpl->fd, pBuffer, uBytesRequested); 2051cdf0e10cSrcweir 2052cdf0e10cSrcweir if (-1 == nBytes) 2053cdf0e10cSrcweir return oslTranslateFileError(OSL_FET_ERROR, errno); 2054cdf0e10cSrcweir 2055cdf0e10cSrcweir *pBytesRead = nBytes; 2056cdf0e10cSrcweir return osl_File_E_None; 2057cdf0e10cSrcweir } 2058cdf0e10cSrcweir 2059cdf0e10cSrcweir /******************************************* 2060cdf0e10cSrcweir osl_writeFile 2061cdf0e10cSrcweir ********************************************/ 2062cdf0e10cSrcweir 2063cdf0e10cSrcweir oslFileError osl_writeFile(oslFileHandle Handle, const void* pBuffer, sal_uInt64 uBytesToWrite, sal_uInt64* pBytesWritten) 2064cdf0e10cSrcweir { 2065cdf0e10cSrcweir ssize_t nBytes = 0; 2066cdf0e10cSrcweir oslFileHandleImpl* pHandleImpl = (oslFileHandleImpl*)Handle; 2067cdf0e10cSrcweir 2068cdf0e10cSrcweir OSL_ASSERT(pHandleImpl); 2069cdf0e10cSrcweir OSL_ASSERT(pBuffer); 2070cdf0e10cSrcweir OSL_ASSERT(pBytesWritten); 2071cdf0e10cSrcweir 2072cdf0e10cSrcweir if ((0 == pHandleImpl) || (0 == pBuffer) || (0 == pBytesWritten)) 2073cdf0e10cSrcweir return osl_File_E_INVAL; 2074cdf0e10cSrcweir 2075cdf0e10cSrcweir OSL_ASSERT(pHandleImpl->fd >= 0); 2076cdf0e10cSrcweir 2077cdf0e10cSrcweir if (pHandleImpl->fd < 0) 2078cdf0e10cSrcweir return osl_File_E_INVAL; 2079cdf0e10cSrcweir 2080cdf0e10cSrcweir nBytes = write(pHandleImpl->fd, pBuffer, uBytesToWrite); 2081cdf0e10cSrcweir 2082cdf0e10cSrcweir if (-1 == nBytes) 2083cdf0e10cSrcweir return oslTranslateFileError(OSL_FET_ERROR, errno); 2084cdf0e10cSrcweir 2085cdf0e10cSrcweir *pBytesWritten = nBytes; 2086cdf0e10cSrcweir return osl_File_E_None; 2087cdf0e10cSrcweir } 2088cdf0e10cSrcweir 2089cdf0e10cSrcweir /******************************************* 2090cdf0e10cSrcweir osl_writeFile 2091cdf0e10cSrcweir ********************************************/ 2092cdf0e10cSrcweir 2093cdf0e10cSrcweir oslFileError osl_setFilePos( oslFileHandle Handle, sal_uInt32 uHow, sal_Int64 uPos ) 2094cdf0e10cSrcweir { 2095cdf0e10cSrcweir oslFileHandleImpl* pHandleImpl=0; 2096cdf0e10cSrcweir int nRet=0; 2097cdf0e10cSrcweir off_t nOffset=0; 2098cdf0e10cSrcweir 2099cdf0e10cSrcweir pHandleImpl = (oslFileHandleImpl*) Handle; 2100cdf0e10cSrcweir if ( pHandleImpl == 0 ) 2101cdf0e10cSrcweir { 2102cdf0e10cSrcweir return osl_File_E_INVAL; 2103cdf0e10cSrcweir } 2104cdf0e10cSrcweir 2105cdf0e10cSrcweir if ( pHandleImpl->fd < 0 ) 2106cdf0e10cSrcweir { 2107cdf0e10cSrcweir return osl_File_E_INVAL; 2108cdf0e10cSrcweir } 2109cdf0e10cSrcweir 2110cdf0e10cSrcweir /* FIXME mfe: setFilePos: Do we have any runtime function to determine LONG_MAX? */ 2111cdf0e10cSrcweir if ( uPos > LONG_MAX ) 2112cdf0e10cSrcweir { 2113cdf0e10cSrcweir return osl_File_E_OVERFLOW; 2114cdf0e10cSrcweir } 2115cdf0e10cSrcweir 2116cdf0e10cSrcweir nOffset=(off_t)uPos; 2117cdf0e10cSrcweir 2118cdf0e10cSrcweir switch(uHow) 2119cdf0e10cSrcweir { 2120cdf0e10cSrcweir case osl_Pos_Absolut: 2121cdf0e10cSrcweir nOffset = lseek(pHandleImpl->fd,nOffset,SEEK_SET); 2122cdf0e10cSrcweir break; 2123cdf0e10cSrcweir 2124cdf0e10cSrcweir case osl_Pos_Current: 2125cdf0e10cSrcweir nOffset = lseek(pHandleImpl->fd,nOffset,SEEK_CUR); 2126cdf0e10cSrcweir break; 2127cdf0e10cSrcweir 2128cdf0e10cSrcweir case osl_Pos_End: 2129cdf0e10cSrcweir nOffset = lseek(pHandleImpl->fd,nOffset,SEEK_END); 2130cdf0e10cSrcweir break; 2131cdf0e10cSrcweir 2132cdf0e10cSrcweir default: 2133cdf0e10cSrcweir return osl_File_E_INVAL; 2134cdf0e10cSrcweir } 2135cdf0e10cSrcweir 2136cdf0e10cSrcweir if ( nOffset < 0 ) 2137cdf0e10cSrcweir { 2138cdf0e10cSrcweir nRet=errno; 2139cdf0e10cSrcweir return oslTranslateFileError(OSL_FET_ERROR, nRet); 2140cdf0e10cSrcweir } 2141cdf0e10cSrcweir 2142cdf0e10cSrcweir return osl_File_E_None; 2143cdf0e10cSrcweir } 2144cdf0e10cSrcweir 2145cdf0e10cSrcweir /************************************************ 2146cdf0e10cSrcweir * osl_getFilePos 2147cdf0e10cSrcweir ***********************************************/ 2148cdf0e10cSrcweir 2149cdf0e10cSrcweir oslFileError osl_getFilePos( oslFileHandle Handle, sal_uInt64* pPos ) 2150cdf0e10cSrcweir { 2151cdf0e10cSrcweir oslFileHandleImpl* pHandleImpl=0; 2152cdf0e10cSrcweir off_t nOffset=0; 2153cdf0e10cSrcweir int nRet=0; 2154cdf0e10cSrcweir 2155cdf0e10cSrcweir pHandleImpl = (oslFileHandleImpl*) Handle; 2156cdf0e10cSrcweir if ( pHandleImpl == 0 || pPos == 0) 2157cdf0e10cSrcweir { 2158cdf0e10cSrcweir return osl_File_E_INVAL; 2159cdf0e10cSrcweir } 2160cdf0e10cSrcweir 2161cdf0e10cSrcweir if ( pHandleImpl->fd < 0 ) 2162cdf0e10cSrcweir { 2163cdf0e10cSrcweir return osl_File_E_INVAL; 2164cdf0e10cSrcweir } 2165cdf0e10cSrcweir 2166cdf0e10cSrcweir nOffset = lseek(pHandleImpl->fd,0,SEEK_CUR); 2167cdf0e10cSrcweir 2168cdf0e10cSrcweir if (nOffset < 0) 2169cdf0e10cSrcweir { 2170cdf0e10cSrcweir nRet =errno; 2171cdf0e10cSrcweir 2172cdf0e10cSrcweir /* *pPos =0; */ 2173cdf0e10cSrcweir 2174cdf0e10cSrcweir return oslTranslateFileError(OSL_FET_ERROR, nRet); 2175cdf0e10cSrcweir } 2176cdf0e10cSrcweir 2177cdf0e10cSrcweir *pPos=nOffset; 2178cdf0e10cSrcweir 2179cdf0e10cSrcweir return osl_File_E_None; 2180cdf0e10cSrcweir } 2181cdf0e10cSrcweir 2182cdf0e10cSrcweir /**************************************************************************** 2183cdf0e10cSrcweir * osl_getFileSize 2184cdf0e10cSrcweir ****************************************************************************/ 2185cdf0e10cSrcweir 2186cdf0e10cSrcweir oslFileError osl_getFileSize( oslFileHandle Handle, sal_uInt64* pSize ) 2187cdf0e10cSrcweir { 2188cdf0e10cSrcweir oslFileHandleImpl* pHandleImpl=(oslFileHandleImpl*) Handle; 2189cdf0e10cSrcweir if (pHandleImpl == 0) 2190cdf0e10cSrcweir return osl_File_E_INVAL; 2191cdf0e10cSrcweir 2192cdf0e10cSrcweir struct stat file_stat; 2193cdf0e10cSrcweir if (fstat(pHandleImpl->fd, &file_stat) == -1) 2194cdf0e10cSrcweir return oslTranslateFileError(OSL_FET_ERROR, errno); 2195cdf0e10cSrcweir 2196cdf0e10cSrcweir *pSize = file_stat.st_size; 2197cdf0e10cSrcweir return osl_File_E_None; 2198cdf0e10cSrcweir } 2199cdf0e10cSrcweir 2200cdf0e10cSrcweir /************************************************ 2201cdf0e10cSrcweir * osl_setFileSize 2202cdf0e10cSrcweir ***********************************************/ 2203cdf0e10cSrcweir 2204cdf0e10cSrcweir oslFileError osl_setFileSize( oslFileHandle Handle, sal_uInt64 uSize ) 2205cdf0e10cSrcweir { 2206cdf0e10cSrcweir oslFileHandleImpl* pHandleImpl=0; 2207cdf0e10cSrcweir off_t nOffset=0; 2208cdf0e10cSrcweir 2209cdf0e10cSrcweir pHandleImpl = (oslFileHandleImpl*) Handle; 2210cdf0e10cSrcweir if ( pHandleImpl == 0 ) 2211cdf0e10cSrcweir { 2212cdf0e10cSrcweir return osl_File_E_INVAL; 2213cdf0e10cSrcweir } 2214cdf0e10cSrcweir 2215cdf0e10cSrcweir if ( pHandleImpl->fd < 0 ) 2216cdf0e10cSrcweir { 2217cdf0e10cSrcweir return osl_File_E_INVAL; 2218cdf0e10cSrcweir } 2219cdf0e10cSrcweir 2220cdf0e10cSrcweir /* FIXME: mfe: setFileSize: Do we have any runtime function to determine LONG_MAX? */ 2221cdf0e10cSrcweir if ( uSize > LONG_MAX ) 2222cdf0e10cSrcweir { 2223cdf0e10cSrcweir return osl_File_E_OVERFLOW; 2224cdf0e10cSrcweir } 2225cdf0e10cSrcweir 2226cdf0e10cSrcweir nOffset = (off_t)uSize; 2227cdf0e10cSrcweir if (ftruncate (pHandleImpl->fd, nOffset) < 0) 2228cdf0e10cSrcweir { 2229cdf0e10cSrcweir /* Failure. Try fallback algorithm */ 2230cdf0e10cSrcweir oslFileError result; 2231cdf0e10cSrcweir struct stat aStat; 2232cdf0e10cSrcweir off_t nCurPos; 2233cdf0e10cSrcweir 2234cdf0e10cSrcweir /* Save original result */ 2235cdf0e10cSrcweir result = oslTranslateFileError (OSL_FET_ERROR, errno); 2236cdf0e10cSrcweir PERROR("ftruncate", "Try osl_setFileSize [fallback]\n"); 2237cdf0e10cSrcweir 2238cdf0e10cSrcweir /* Check against current size. Fail upon 'shrink' */ 2239cdf0e10cSrcweir if (fstat (pHandleImpl->fd, &aStat) < 0) 2240cdf0e10cSrcweir { 2241cdf0e10cSrcweir PERROR("ftruncate: fstat", "Out osl_setFileSize [error]\n"); 2242cdf0e10cSrcweir return (result); 2243cdf0e10cSrcweir } 2244cdf0e10cSrcweir if ((0 <= nOffset) && (nOffset <= aStat.st_size)) 2245cdf0e10cSrcweir { 2246cdf0e10cSrcweir /* Failure upon 'shrink'. Return original result */ 2247cdf0e10cSrcweir return (result); 2248cdf0e10cSrcweir } 2249cdf0e10cSrcweir 2250cdf0e10cSrcweir /* Save current position */ 2251cdf0e10cSrcweir nCurPos = (off_t)lseek (pHandleImpl->fd, (off_t)0, SEEK_CUR); 2252cdf0e10cSrcweir if (nCurPos == (off_t)(-1)) 2253cdf0e10cSrcweir { 2254cdf0e10cSrcweir PERROR("ftruncate: lseek", "Out osl_setFileSize [error]\n"); 2255cdf0e10cSrcweir return (result); 2256cdf0e10cSrcweir } 2257cdf0e10cSrcweir 2258cdf0e10cSrcweir /* Try 'expand' via 'lseek()' and 'write()' */ 2259cdf0e10cSrcweir if (lseek (pHandleImpl->fd, (off_t)(nOffset - 1), SEEK_SET) < 0) 2260cdf0e10cSrcweir { 2261cdf0e10cSrcweir PERROR("ftruncate: lseek", "Out osl_setFileSize [error]\n"); 2262cdf0e10cSrcweir return (result); 2263cdf0e10cSrcweir } 2264cdf0e10cSrcweir if (write (pHandleImpl->fd, (char*)"", (size_t)1) < 0) 2265cdf0e10cSrcweir { 2266cdf0e10cSrcweir /* Failure. Restore saved position */ 2267cdf0e10cSrcweir PERROR("ftruncate: write", "Out osl_setFileSize [error]\n"); 2268cdf0e10cSrcweir if (lseek (pHandleImpl->fd, (off_t)nCurPos, SEEK_SET) < 0) 2269cdf0e10cSrcweir { 2270cdf0e10cSrcweir #ifdef DEBUG_OSL_FILE 2271cdf0e10cSrcweir perror("ftruncate: lseek"); 2272cdf0e10cSrcweir #endif /* DEBUG_OSL_FILE */ 2273cdf0e10cSrcweir } 2274cdf0e10cSrcweir return (result); 2275cdf0e10cSrcweir } 2276cdf0e10cSrcweir 2277cdf0e10cSrcweir /* Success. Restore saved position */ 2278cdf0e10cSrcweir if (lseek (pHandleImpl->fd, (off_t)nCurPos, SEEK_SET) < 0) 2279cdf0e10cSrcweir { 2280cdf0e10cSrcweir PERROR("ftruncate: lseek", "Out osl_setFileSize [error]"); 2281cdf0e10cSrcweir return (result); 2282cdf0e10cSrcweir } 2283cdf0e10cSrcweir } 2284cdf0e10cSrcweir 2285cdf0e10cSrcweir return (osl_File_E_None); 2286cdf0e10cSrcweir } 2287cdf0e10cSrcweir 2288cdf0e10cSrcweir /*###############################################*/ 2289cdf0e10cSrcweir oslFileError SAL_CALL osl_syncFile(oslFileHandle Handle) 2290cdf0e10cSrcweir { 2291cdf0e10cSrcweir oslFileHandleImpl* handle_impl = (oslFileHandleImpl*)Handle; 2292cdf0e10cSrcweir 2293cdf0e10cSrcweir if (handle_impl == 0) 2294cdf0e10cSrcweir return osl_File_E_INVAL; 2295cdf0e10cSrcweir 2296cdf0e10cSrcweir if (fsync(handle_impl->fd) == -1) 2297cdf0e10cSrcweir return oslTranslateFileError(OSL_FET_ERROR, errno); 2298cdf0e10cSrcweir 2299cdf0e10cSrcweir return osl_File_E_None; 2300cdf0e10cSrcweir } 2301cdf0e10cSrcweir 2302cdf0e10cSrcweir /****************************************************************************** 2303cdf0e10cSrcweir * 2304cdf0e10cSrcweir * C-String Versions of Exported Module Functions 2305cdf0e10cSrcweir * 2306cdf0e10cSrcweir *****************************************************************************/ 2307cdf0e10cSrcweir 2308cdf0e10cSrcweir #ifdef HAVE_STATFS_H 2309cdf0e10cSrcweir 2310cdf0e10cSrcweir #if defined(FREEBSD) || defined(NETBSD) || defined(MACOSX) 2311cdf0e10cSrcweir # define __OSL_STATFS_STRUCT struct statfs 2312cdf0e10cSrcweir # define __OSL_STATFS(dir, sfs) statfs((dir), (sfs)) 2313cdf0e10cSrcweir # define __OSL_STATFS_BLKSIZ(a) ((sal_uInt64)((a).f_bsize)) 2314cdf0e10cSrcweir # define __OSL_STATFS_TYPENAME(a) ((a).f_fstypename) 2315cdf0e10cSrcweir # define __OSL_STATFS_ISREMOTE(a) (((a).f_type & MNT_LOCAL) == 0) 2316cdf0e10cSrcweir 2317cdf0e10cSrcweir /* always return true if queried for the properties of 2318cdf0e10cSrcweir the file system. If you think this is wrong under any 2319cdf0e10cSrcweir of the target platforms fix it!!!! */ 2320cdf0e10cSrcweir # define __OSL_STATFS_IS_CASE_SENSITIVE_FS(a) (1) 2321cdf0e10cSrcweir # define __OSL_STATFS_IS_CASE_PRESERVING_FS(a) (1) 2322cdf0e10cSrcweir #endif /* FREEBSD || NETBSD */ 2323cdf0e10cSrcweir 2324cdf0e10cSrcweir #if defined(LINUX) 2325cdf0e10cSrcweir # define __OSL_NFS_SUPER_MAGIC 0x6969 2326cdf0e10cSrcweir # define __OSL_SMB_SUPER_MAGIC 0x517B 2327cdf0e10cSrcweir # define __OSL_MSDOS_SUPER_MAGIC 0x4d44 2328cdf0e10cSrcweir # define __OSL_NTFS_SUPER_MAGIC 0x5346544e 2329cdf0e10cSrcweir # define __OSL_STATFS_STRUCT struct statfs 2330cdf0e10cSrcweir # define __OSL_STATFS(dir, sfs) statfs((dir), (sfs)) 2331cdf0e10cSrcweir # define __OSL_STATFS_BLKSIZ(a) ((sal_uInt64)((a).f_bsize)) 2332cdf0e10cSrcweir # define __OSL_STATFS_IS_NFS(a) (__OSL_NFS_SUPER_MAGIC == (a).f_type) 2333cdf0e10cSrcweir # define __OSL_STATFS_IS_SMB(a) (__OSL_SMB_SUPER_MAGIC == (a).f_type) 2334cdf0e10cSrcweir # define __OSL_STATFS_ISREMOTE(a) (__OSL_STATFS_IS_NFS((a)) || __OSL_STATFS_IS_SMB((a))) 2335cdf0e10cSrcweir # define __OSL_STATFS_IS_CASE_SENSITIVE_FS(a) ((__OSL_MSDOS_SUPER_MAGIC != (a).f_type) && (__OSL_NTFS_SUPER_MAGIC != (a).f_type)) 2336cdf0e10cSrcweir # define __OSL_STATFS_IS_CASE_PRESERVING_FS(a) ((__OSL_MSDOS_SUPER_MAGIC != (a).f_type)) 2337cdf0e10cSrcweir #endif /* LINUX */ 2338cdf0e10cSrcweir 2339cdf0e10cSrcweir #if defined(SOLARIS) 2340cdf0e10cSrcweir # define __OSL_STATFS_STRUCT struct statvfs 2341cdf0e10cSrcweir # define __OSL_STATFS(dir, sfs) statvfs((dir), (sfs)) 2342cdf0e10cSrcweir # define __OSL_STATFS_BLKSIZ(a) ((sal_uInt64)((a).f_frsize)) 2343cdf0e10cSrcweir # define __OSL_STATFS_TYPENAME(a) ((a).f_basetype) 2344cdf0e10cSrcweir # define __OSL_STATFS_ISREMOTE(a) (rtl_str_compare((a).f_basetype, "nfs") == 0) 2345cdf0e10cSrcweir 2346cdf0e10cSrcweir /* always return true if queried for the properties of 2347cdf0e10cSrcweir the file system. If you think this is wrong under any 2348cdf0e10cSrcweir of the target platforms fix it!!!! */ 2349cdf0e10cSrcweir # define __OSL_STATFS_IS_CASE_SENSITIVE_FS(a) (1) 2350cdf0e10cSrcweir # define __OSL_STATFS_IS_CASE_PRESERVING_FS(a) (1) 2351cdf0e10cSrcweir #endif /* SOLARIS */ 2352cdf0e10cSrcweir 2353cdf0e10cSrcweir # define __OSL_STATFS_INIT(a) (memset(&(a), 0, sizeof(__OSL_STATFS_STRUCT))) 2354cdf0e10cSrcweir 2355cdf0e10cSrcweir #else /* no statfs available */ 2356cdf0e10cSrcweir 2357cdf0e10cSrcweir # define __OSL_STATFS_STRUCT struct dummy {int i;} 2358cdf0e10cSrcweir # define __OSL_STATFS_INIT(a) ((void)0) 2359cdf0e10cSrcweir # define __OSL_STATFS(dir, sfs) (1) 2360cdf0e10cSrcweir # define __OSL_STATFS_ISREMOTE(sfs) (0) 2361cdf0e10cSrcweir # define __OSL_STATFS_IS_CASE_SENSITIVE_FS(a) (1) 2362cdf0e10cSrcweir # define __OSL_STATFS_IS_CASE_PRESERVING_FS(a) (1) 2363cdf0e10cSrcweir #endif /* HAVE_STATFS_H */ 2364cdf0e10cSrcweir 2365cdf0e10cSrcweir 2366cdf0e10cSrcweir static oslFileError osl_psz_getVolumeInformation ( 2367cdf0e10cSrcweir const sal_Char* pszDirectory, oslVolumeInfo* pInfo, sal_uInt32 uFieldMask) 2368cdf0e10cSrcweir { 2369cdf0e10cSrcweir __OSL_STATFS_STRUCT sfs; 2370cdf0e10cSrcweir 2371cdf0e10cSrcweir if (!pInfo) 2372cdf0e10cSrcweir return osl_File_E_INVAL; 2373cdf0e10cSrcweir 2374cdf0e10cSrcweir __OSL_STATFS_INIT(sfs); 2375cdf0e10cSrcweir 2376cdf0e10cSrcweir pInfo->uValidFields = 0; 2377cdf0e10cSrcweir pInfo->uAttributes = 0; 2378cdf0e10cSrcweir 2379cdf0e10cSrcweir if ((__OSL_STATFS(pszDirectory, &sfs)) < 0) 2380cdf0e10cSrcweir { 2381cdf0e10cSrcweir oslFileError result = oslTranslateFileError(OSL_FET_ERROR, errno); 2382cdf0e10cSrcweir return (result); 2383cdf0e10cSrcweir } 2384cdf0e10cSrcweir 2385cdf0e10cSrcweir /* FIXME: how to detect the kind of storage (fixed, cdrom, ...) */ 2386cdf0e10cSrcweir if (uFieldMask & osl_VolumeInfo_Mask_Attributes) 2387cdf0e10cSrcweir { 2388cdf0e10cSrcweir if (__OSL_STATFS_ISREMOTE(sfs)) 2389cdf0e10cSrcweir pInfo->uAttributes |= osl_Volume_Attribute_Remote; 2390cdf0e10cSrcweir 2391cdf0e10cSrcweir pInfo->uValidFields |= osl_VolumeInfo_Mask_Attributes; 2392cdf0e10cSrcweir } 2393cdf0e10cSrcweir 2394cdf0e10cSrcweir if (uFieldMask & osl_VolumeInfo_Mask_FileSystemCaseHandling) 2395cdf0e10cSrcweir { 2396cdf0e10cSrcweir if (__OSL_STATFS_IS_CASE_SENSITIVE_FS(sfs)) 2397cdf0e10cSrcweir pInfo->uAttributes |= osl_Volume_Attribute_Case_Sensitive; 2398cdf0e10cSrcweir 2399cdf0e10cSrcweir if (__OSL_STATFS_IS_CASE_PRESERVING_FS(sfs)) 2400cdf0e10cSrcweir pInfo->uAttributes |= osl_Volume_Attribute_Case_Is_Preserved; 2401cdf0e10cSrcweir 2402cdf0e10cSrcweir pInfo->uValidFields |= osl_VolumeInfo_Mask_Attributes; 2403cdf0e10cSrcweir } 2404cdf0e10cSrcweir 2405cdf0e10cSrcweir pInfo->uTotalSpace = 0; 2406cdf0e10cSrcweir pInfo->uFreeSpace = 0; 2407cdf0e10cSrcweir pInfo->uUsedSpace = 0; 2408cdf0e10cSrcweir 2409cdf0e10cSrcweir #if defined(__OSL_STATFS_BLKSIZ) 2410cdf0e10cSrcweir 2411cdf0e10cSrcweir if ((uFieldMask & osl_VolumeInfo_Mask_TotalSpace) || 2412cdf0e10cSrcweir (uFieldMask & osl_VolumeInfo_Mask_UsedSpace)) 2413cdf0e10cSrcweir { 2414cdf0e10cSrcweir pInfo->uTotalSpace = __OSL_STATFS_BLKSIZ(sfs); 2415cdf0e10cSrcweir pInfo->uTotalSpace *= (sal_uInt64)(sfs.f_blocks); 2416cdf0e10cSrcweir pInfo->uValidFields |= osl_VolumeInfo_Mask_TotalSpace; 2417cdf0e10cSrcweir } 2418cdf0e10cSrcweir 2419cdf0e10cSrcweir if ((uFieldMask & osl_VolumeInfo_Mask_FreeSpace) || 2420cdf0e10cSrcweir (uFieldMask & osl_VolumeInfo_Mask_UsedSpace)) 2421cdf0e10cSrcweir { 2422cdf0e10cSrcweir pInfo->uFreeSpace = __OSL_STATFS_BLKSIZ(sfs); 2423cdf0e10cSrcweir 2424cdf0e10cSrcweir if (getuid() == 0) 2425cdf0e10cSrcweir pInfo->uFreeSpace *= (sal_uInt64)(sfs.f_bfree); 2426cdf0e10cSrcweir else 2427cdf0e10cSrcweir pInfo->uFreeSpace *= (sal_uInt64)(sfs.f_bavail); 2428cdf0e10cSrcweir 2429cdf0e10cSrcweir pInfo->uValidFields |= osl_VolumeInfo_Mask_FreeSpace; 2430cdf0e10cSrcweir } 2431cdf0e10cSrcweir 2432cdf0e10cSrcweir #endif /* __OSL_STATFS_BLKSIZ */ 2433cdf0e10cSrcweir 2434cdf0e10cSrcweir if ((pInfo->uValidFields & osl_VolumeInfo_Mask_TotalSpace) && 2435cdf0e10cSrcweir (pInfo->uValidFields & osl_VolumeInfo_Mask_FreeSpace )) 2436cdf0e10cSrcweir { 2437cdf0e10cSrcweir pInfo->uUsedSpace = pInfo->uTotalSpace - pInfo->uFreeSpace; 2438cdf0e10cSrcweir pInfo->uValidFields |= osl_VolumeInfo_Mask_UsedSpace; 2439cdf0e10cSrcweir } 2440cdf0e10cSrcweir 2441cdf0e10cSrcweir pInfo->uMaxNameLength = 0; 2442cdf0e10cSrcweir if (uFieldMask & osl_VolumeInfo_Mask_MaxNameLength) 2443cdf0e10cSrcweir { 2444cdf0e10cSrcweir long nLen = pathconf(pszDirectory, _PC_NAME_MAX); 2445cdf0e10cSrcweir if (nLen > 0) 2446cdf0e10cSrcweir { 2447cdf0e10cSrcweir pInfo->uMaxNameLength = (sal_uInt32)nLen; 2448cdf0e10cSrcweir pInfo->uValidFields |= osl_VolumeInfo_Mask_MaxNameLength; 2449cdf0e10cSrcweir } 2450cdf0e10cSrcweir } 2451cdf0e10cSrcweir 2452cdf0e10cSrcweir pInfo->uMaxPathLength = 0; 2453cdf0e10cSrcweir if (uFieldMask & osl_VolumeInfo_Mask_MaxPathLength) 2454cdf0e10cSrcweir { 2455cdf0e10cSrcweir long nLen = pathconf (pszDirectory, _PC_PATH_MAX); 2456cdf0e10cSrcweir if (nLen > 0) 2457cdf0e10cSrcweir { 2458cdf0e10cSrcweir pInfo->uMaxPathLength = (sal_uInt32)nLen; 2459cdf0e10cSrcweir pInfo->uValidFields |= osl_VolumeInfo_Mask_MaxPathLength; 2460cdf0e10cSrcweir } 2461cdf0e10cSrcweir } 2462cdf0e10cSrcweir 2463cdf0e10cSrcweir #if defined(__OSL_STATFS_TYPENAME) 2464cdf0e10cSrcweir 2465cdf0e10cSrcweir if (uFieldMask & osl_VolumeInfo_Mask_FileSystemName) 2466cdf0e10cSrcweir { 2467cdf0e10cSrcweir rtl_string2UString( 2468cdf0e10cSrcweir &(pInfo->ustrFileSystemName), 2469cdf0e10cSrcweir __OSL_STATFS_TYPENAME(sfs), 2470cdf0e10cSrcweir rtl_str_getLength(__OSL_STATFS_TYPENAME(sfs)), 2471cdf0e10cSrcweir osl_getThreadTextEncoding(), 2472cdf0e10cSrcweir OUSTRING_TO_OSTRING_CVTFLAGS); 2473cdf0e10cSrcweir OSL_ASSERT(pInfo->ustrFileSystemName != 0); 2474cdf0e10cSrcweir 2475cdf0e10cSrcweir pInfo->uValidFields |= osl_VolumeInfo_Mask_FileSystemName; 2476cdf0e10cSrcweir } 2477cdf0e10cSrcweir 2478cdf0e10cSrcweir #endif /* __OSL_STATFS_TYPENAME */ 2479cdf0e10cSrcweir 2480cdf0e10cSrcweir if (uFieldMask & osl_VolumeInfo_Mask_DeviceHandle) 2481cdf0e10cSrcweir { 2482cdf0e10cSrcweir /* FIXME: check also entries in mntent for the device 2483cdf0e10cSrcweir and fill it with correct values */ 2484cdf0e10cSrcweir 2485cdf0e10cSrcweir *pInfo->pDeviceHandle = osl_isFloppyDrive(pszDirectory); 2486cdf0e10cSrcweir 2487cdf0e10cSrcweir if (*pInfo->pDeviceHandle) 2488cdf0e10cSrcweir { 2489cdf0e10cSrcweir pInfo->uValidFields |= osl_VolumeInfo_Mask_DeviceHandle; 2490cdf0e10cSrcweir pInfo->uAttributes |= osl_Volume_Attribute_Removeable; 2491cdf0e10cSrcweir pInfo->uValidFields |= osl_VolumeInfo_Mask_Attributes; 2492cdf0e10cSrcweir } 2493cdf0e10cSrcweir } 2494cdf0e10cSrcweir return osl_File_E_None; 2495cdf0e10cSrcweir } 2496cdf0e10cSrcweir 2497cdf0e10cSrcweir /****************************************** 2498cdf0e10cSrcweir * osl_psz_setFileTime 2499cdf0e10cSrcweir *****************************************/ 2500cdf0e10cSrcweir 2501cdf0e10cSrcweir static oslFileError osl_psz_setFileTime( const sal_Char* pszFilePath, 2502cdf0e10cSrcweir const TimeValue* /*pCreationTime*/, 2503cdf0e10cSrcweir const TimeValue* pLastAccessTime, 2504cdf0e10cSrcweir const TimeValue* pLastWriteTime ) 2505cdf0e10cSrcweir { 2506cdf0e10cSrcweir int nRet=0; 2507cdf0e10cSrcweir struct utimbuf aTimeBuffer; 2508cdf0e10cSrcweir struct stat aFileStat; 2509cdf0e10cSrcweir #ifdef DEBUG_OSL_FILE 2510cdf0e10cSrcweir struct tm* pTM=0; 2511cdf0e10cSrcweir #endif 2512cdf0e10cSrcweir 2513cdf0e10cSrcweir nRet = lstat(pszFilePath,&aFileStat); 2514cdf0e10cSrcweir 2515cdf0e10cSrcweir if ( nRet < 0 ) 2516cdf0e10cSrcweir { 2517cdf0e10cSrcweir nRet=errno; 2518cdf0e10cSrcweir return oslTranslateFileError(OSL_FET_ERROR, nRet); 2519cdf0e10cSrcweir } 2520cdf0e10cSrcweir 2521cdf0e10cSrcweir #ifdef DEBUG_OSL_FILE 2522cdf0e10cSrcweir fprintf(stderr,"File Times are (in localtime):\n"); 2523cdf0e10cSrcweir pTM=localtime(&aFileStat.st_ctime); 2524cdf0e10cSrcweir fprintf(stderr,"CreationTime is '%s'\n",asctime(pTM)); 2525cdf0e10cSrcweir pTM=localtime(&aFileStat.st_atime); 2526cdf0e10cSrcweir fprintf(stderr,"AccessTime is '%s'\n",asctime(pTM)); 2527cdf0e10cSrcweir pTM=localtime(&aFileStat.st_mtime); 2528cdf0e10cSrcweir fprintf(stderr,"Modification is '%s'\n",asctime(pTM)); 2529cdf0e10cSrcweir 2530cdf0e10cSrcweir fprintf(stderr,"File Times are (in UTC):\n"); 2531cdf0e10cSrcweir fprintf(stderr,"CreationTime is '%s'\n",ctime(&aFileStat.st_ctime)); 2532cdf0e10cSrcweir fprintf(stderr,"AccessTime is '%s'\n",ctime(&aTimeBuffer.actime)); 2533cdf0e10cSrcweir fprintf(stderr,"Modification is '%s'\n",ctime(&aTimeBuffer.modtime)); 2534cdf0e10cSrcweir #endif 2535cdf0e10cSrcweir 2536cdf0e10cSrcweir if ( pLastAccessTime != 0 ) 2537cdf0e10cSrcweir { 2538cdf0e10cSrcweir aTimeBuffer.actime=pLastAccessTime->Seconds; 2539cdf0e10cSrcweir } 2540cdf0e10cSrcweir else 2541cdf0e10cSrcweir { 2542cdf0e10cSrcweir aTimeBuffer.actime=aFileStat.st_atime; 2543cdf0e10cSrcweir } 2544cdf0e10cSrcweir 2545cdf0e10cSrcweir if ( pLastWriteTime != 0 ) 2546cdf0e10cSrcweir { 2547cdf0e10cSrcweir aTimeBuffer.modtime=pLastWriteTime->Seconds; 2548cdf0e10cSrcweir } 2549cdf0e10cSrcweir else 2550cdf0e10cSrcweir { 2551cdf0e10cSrcweir aTimeBuffer.modtime=aFileStat.st_mtime; 2552cdf0e10cSrcweir } 2553cdf0e10cSrcweir 2554cdf0e10cSrcweir /* mfe: Creation time not used here! */ 2555cdf0e10cSrcweir 2556cdf0e10cSrcweir #ifdef DEBUG_OSL_FILE 2557cdf0e10cSrcweir fprintf(stderr,"File Times are (in localtime):\n"); 2558cdf0e10cSrcweir pTM=localtime(&aFileStat.st_ctime); 2559cdf0e10cSrcweir fprintf(stderr,"CreationTime now '%s'\n",asctime(pTM)); 2560cdf0e10cSrcweir pTM=localtime(&aTimeBuffer.actime); 2561cdf0e10cSrcweir fprintf(stderr,"AccessTime now '%s'\n",asctime(pTM)); 2562cdf0e10cSrcweir pTM=localtime(&aTimeBuffer.modtime); 2563cdf0e10cSrcweir fprintf(stderr,"Modification now '%s'\n",asctime(pTM)); 2564cdf0e10cSrcweir 2565cdf0e10cSrcweir fprintf(stderr,"File Times are (in UTC):\n"); 2566cdf0e10cSrcweir fprintf(stderr,"CreationTime now '%s'\n",ctime(&aFileStat.st_ctime)); 2567cdf0e10cSrcweir fprintf(stderr,"AccessTime now '%s'\n",ctime(&aTimeBuffer.actime)); 2568cdf0e10cSrcweir fprintf(stderr,"Modification now '%s'\n",ctime(&aTimeBuffer.modtime)); 2569cdf0e10cSrcweir #endif 2570cdf0e10cSrcweir 2571cdf0e10cSrcweir nRet=utime(pszFilePath,&aTimeBuffer); 2572cdf0e10cSrcweir if ( nRet < 0 ) 2573cdf0e10cSrcweir { 2574cdf0e10cSrcweir nRet=errno; 2575cdf0e10cSrcweir return oslTranslateFileError(OSL_FET_ERROR, nRet); 2576cdf0e10cSrcweir } 2577cdf0e10cSrcweir 2578cdf0e10cSrcweir return osl_File_E_None; 2579cdf0e10cSrcweir } 2580cdf0e10cSrcweir 2581cdf0e10cSrcweir 2582cdf0e10cSrcweir /***************************************** 2583cdf0e10cSrcweir * osl_psz_removeFile 2584cdf0e10cSrcweir ****************************************/ 2585cdf0e10cSrcweir #if 0 2586cdf0e10cSrcweir static oslFileError osl_psz_removeFile( const sal_Char* pszPath ) 2587cdf0e10cSrcweir { 2588cdf0e10cSrcweir int nRet=0; 2589cdf0e10cSrcweir struct stat aStat; 2590cdf0e10cSrcweir 2591cdf0e10cSrcweir nRet = stat(pszPath,&aStat); 2592cdf0e10cSrcweir if ( nRet < 0 ) 2593cdf0e10cSrcweir { 2594cdf0e10cSrcweir nRet=errno; 2595cdf0e10cSrcweir return oslTranslateFileError(OSL_FET_ERROR, nRet); 2596cdf0e10cSrcweir } 2597cdf0e10cSrcweir 2598cdf0e10cSrcweir if ( S_ISDIR(aStat.st_mode) ) 2599cdf0e10cSrcweir { 2600cdf0e10cSrcweir return osl_File_E_ISDIR; 2601cdf0e10cSrcweir } 2602cdf0e10cSrcweir 2603cdf0e10cSrcweir nRet = unlink(pszPath); 2604cdf0e10cSrcweir if ( nRet < 0 ) 2605cdf0e10cSrcweir { 2606cdf0e10cSrcweir nRet=errno; 2607cdf0e10cSrcweir return oslTranslateFileError(OSL_FET_ERROR, nRet); 2608cdf0e10cSrcweir } 2609cdf0e10cSrcweir 2610cdf0e10cSrcweir return osl_File_E_None; 2611cdf0e10cSrcweir } 2612cdf0e10cSrcweir #endif 2613cdf0e10cSrcweir 2614cdf0e10cSrcweir /***************************************** 2615cdf0e10cSrcweir * osl_psz_createDirectory 2616cdf0e10cSrcweir ****************************************/ 2617cdf0e10cSrcweir #if 0 2618cdf0e10cSrcweir static oslFileError osl_psz_createDirectory( const sal_Char* pszPath ) 2619cdf0e10cSrcweir { 2620cdf0e10cSrcweir int nRet=0; 2621cdf0e10cSrcweir int mode = S_IRWXU | S_IRWXG | S_IRWXO; 2622cdf0e10cSrcweir 2623cdf0e10cSrcweir nRet = mkdir(pszPath,mode); 2624cdf0e10cSrcweir 2625cdf0e10cSrcweir if ( nRet < 0 ) 2626cdf0e10cSrcweir { 2627cdf0e10cSrcweir nRet=errno; 2628cdf0e10cSrcweir return oslTranslateFileError(OSL_FET_ERROR, nRet); 2629cdf0e10cSrcweir } 2630cdf0e10cSrcweir 2631cdf0e10cSrcweir return osl_File_E_None; 2632cdf0e10cSrcweir } 2633cdf0e10cSrcweir #endif 2634cdf0e10cSrcweir /***************************************** 2635cdf0e10cSrcweir * osl_psz_removeDirectory 2636cdf0e10cSrcweir ****************************************/ 2637cdf0e10cSrcweir #if 0 2638cdf0e10cSrcweir static oslFileError osl_psz_removeDirectory( const sal_Char* pszPath ) 2639cdf0e10cSrcweir { 2640cdf0e10cSrcweir int nRet=0; 2641cdf0e10cSrcweir 2642cdf0e10cSrcweir nRet = rmdir(pszPath); 2643cdf0e10cSrcweir 2644cdf0e10cSrcweir if ( nRet < 0 ) 2645cdf0e10cSrcweir { 2646cdf0e10cSrcweir nRet=errno; 2647cdf0e10cSrcweir return oslTranslateFileError(OSL_FET_ERROR, nRet); 2648cdf0e10cSrcweir } 2649cdf0e10cSrcweir 2650cdf0e10cSrcweir return osl_File_E_None; 2651cdf0e10cSrcweir } 2652cdf0e10cSrcweir #endif 2653cdf0e10cSrcweir /***************************************** 2654cdf0e10cSrcweir * oslDoMoveFile 2655cdf0e10cSrcweir ****************************************/ 2656cdf0e10cSrcweir #if 0 2657cdf0e10cSrcweir static oslFileError oslDoMoveFile( const sal_Char* pszPath, const sal_Char* pszDestPath) 2658cdf0e10cSrcweir { 2659cdf0e10cSrcweir oslFileError tErr=osl_File_E_invalidError; 2660cdf0e10cSrcweir 2661cdf0e10cSrcweir tErr = osl_psz_moveFile(pszPath,pszDestPath); 2662cdf0e10cSrcweir if ( tErr == osl_File_E_None ) 2663cdf0e10cSrcweir { 2664cdf0e10cSrcweir return tErr; 2665cdf0e10cSrcweir } 2666cdf0e10cSrcweir 2667cdf0e10cSrcweir if ( tErr != osl_File_E_XDEV ) 2668cdf0e10cSrcweir { 2669cdf0e10cSrcweir return tErr; 2670cdf0e10cSrcweir } 2671cdf0e10cSrcweir 2672cdf0e10cSrcweir tErr=osl_psz_copyFile(pszPath,pszDestPath); 2673cdf0e10cSrcweir 2674cdf0e10cSrcweir if ( tErr != osl_File_E_None ) 2675cdf0e10cSrcweir { 2676cdf0e10cSrcweir oslFileError tErrRemove; 2677cdf0e10cSrcweir tErrRemove=osl_psz_removeFile(pszDestPath); 2678cdf0e10cSrcweir return tErr; 2679cdf0e10cSrcweir } 2680cdf0e10cSrcweir 2681cdf0e10cSrcweir tErr=osl_psz_removeFile(pszPath); 2682cdf0e10cSrcweir 2683cdf0e10cSrcweir return tErr; 2684cdf0e10cSrcweir } 2685cdf0e10cSrcweir #endif 2686cdf0e10cSrcweir /***************************************** 2687cdf0e10cSrcweir * osl_psz_moveFile 2688cdf0e10cSrcweir ****************************************/ 2689cdf0e10cSrcweir #if 0 2690cdf0e10cSrcweir static oslFileError osl_psz_moveFile(const sal_Char* pszPath, const sal_Char* pszDestPath) 2691cdf0e10cSrcweir { 2692cdf0e10cSrcweir 2693cdf0e10cSrcweir int nRet = 0; 2694cdf0e10cSrcweir 2695cdf0e10cSrcweir nRet = rename(pszPath,pszDestPath); 2696cdf0e10cSrcweir 2697cdf0e10cSrcweir if ( nRet < 0 ) 2698cdf0e10cSrcweir { 2699cdf0e10cSrcweir nRet=errno; 2700cdf0e10cSrcweir return oslTranslateFileError(OSL_FET_ERROR, nRet); 2701cdf0e10cSrcweir } 2702cdf0e10cSrcweir 2703cdf0e10cSrcweir return osl_File_E_None; 2704cdf0e10cSrcweir } 2705cdf0e10cSrcweir #endif 2706cdf0e10cSrcweir /***************************************** 2707cdf0e10cSrcweir * osl_psz_copyFile 2708cdf0e10cSrcweir ****************************************/ 2709cdf0e10cSrcweir #if 0 2710cdf0e10cSrcweir static oslFileError osl_psz_copyFile( const sal_Char* pszPath, const sal_Char* pszDestPath ) 2711cdf0e10cSrcweir { 2712cdf0e10cSrcweir time_t nAcTime=0; 2713cdf0e10cSrcweir time_t nModTime=0; 2714cdf0e10cSrcweir uid_t nUID=0; 2715cdf0e10cSrcweir gid_t nGID=0; 2716cdf0e10cSrcweir int nRet=0; 2717cdf0e10cSrcweir mode_t nMode=0; 2718cdf0e10cSrcweir struct stat aFileStat; 2719cdf0e10cSrcweir oslFileError tErr=osl_File_E_invalidError; 2720cdf0e10cSrcweir size_t nSourceSize=0; 2721cdf0e10cSrcweir int DestFileExists=1; 2722cdf0e10cSrcweir 2723cdf0e10cSrcweir /* mfe: does the source file really exists? */ 2724cdf0e10cSrcweir nRet = lstat(pszPath,&aFileStat); 2725cdf0e10cSrcweir 2726cdf0e10cSrcweir if ( nRet < 0 ) 2727cdf0e10cSrcweir { 2728cdf0e10cSrcweir nRet=errno; 2729cdf0e10cSrcweir return oslTranslateFileError(OSL_FET_ERROR, nRet); 2730cdf0e10cSrcweir } 2731cdf0e10cSrcweir 2732cdf0e10cSrcweir /* mfe: we do only copy files here! */ 2733cdf0e10cSrcweir if ( S_ISDIR(aFileStat.st_mode) ) 2734cdf0e10cSrcweir { 2735cdf0e10cSrcweir return osl_File_E_ISDIR; 2736cdf0e10cSrcweir } 2737cdf0e10cSrcweir 2738cdf0e10cSrcweir nSourceSize=(size_t)aFileStat.st_size; 2739cdf0e10cSrcweir nMode=aFileStat.st_mode; 2740cdf0e10cSrcweir nAcTime=aFileStat.st_atime; 2741cdf0e10cSrcweir nModTime=aFileStat.st_mtime; 2742cdf0e10cSrcweir nUID=aFileStat.st_uid; 2743cdf0e10cSrcweir nGID=aFileStat.st_gid; 2744cdf0e10cSrcweir 2745cdf0e10cSrcweir nRet = stat(pszDestPath,&aFileStat); 2746cdf0e10cSrcweir if ( nRet < 0 ) 2747cdf0e10cSrcweir { 2748cdf0e10cSrcweir nRet=errno; 2749cdf0e10cSrcweir 2750cdf0e10cSrcweir if ( nRet == ENOENT ) 2751cdf0e10cSrcweir { 2752cdf0e10cSrcweir DestFileExists=0; 2753cdf0e10cSrcweir } 2754cdf0e10cSrcweir /* return oslTranslateFileError(nRet);*/ 2755cdf0e10cSrcweir } 2756cdf0e10cSrcweir 2757cdf0e10cSrcweir /* mfe: the destination file must not be a directory! */ 2758cdf0e10cSrcweir if ( nRet == 0 && S_ISDIR(aFileStat.st_mode) ) 2759cdf0e10cSrcweir { 2760cdf0e10cSrcweir return osl_File_E_ISDIR; 2761cdf0e10cSrcweir } 2762cdf0e10cSrcweir else 2763cdf0e10cSrcweir { 2764cdf0e10cSrcweir /* mfe: file does not exists or is no dir */ 2765cdf0e10cSrcweir } 2766cdf0e10cSrcweir 2767cdf0e10cSrcweir tErr = oslDoCopy(pszPath,pszDestPath,nMode,nSourceSize,DestFileExists); 2768cdf0e10cSrcweir 2769cdf0e10cSrcweir if ( tErr != osl_File_E_None ) 2770cdf0e10cSrcweir { 2771cdf0e10cSrcweir return tErr; 2772cdf0e10cSrcweir } 2773cdf0e10cSrcweir 2774cdf0e10cSrcweir /* 2775cdf0e10cSrcweir * mfe: ignore return code 2776cdf0e10cSrcweir * since only the success of the copy is 2777cdf0e10cSrcweir * important 2778cdf0e10cSrcweir */ 2779cdf0e10cSrcweir oslChangeFileModes(pszDestPath,nMode,nAcTime,nModTime,nUID,nGID); 2780cdf0e10cSrcweir 2781cdf0e10cSrcweir return tErr; 2782cdf0e10cSrcweir } 2783cdf0e10cSrcweir #endif 2784cdf0e10cSrcweir 2785cdf0e10cSrcweir /****************************************************************************** 2786cdf0e10cSrcweir * 2787cdf0e10cSrcweir * Utility Functions 2788cdf0e10cSrcweir * 2789cdf0e10cSrcweir *****************************************************************************/ 2790cdf0e10cSrcweir 2791cdf0e10cSrcweir 2792cdf0e10cSrcweir /***************************************** 2793cdf0e10cSrcweir * oslMakeUStrFromPsz 2794cdf0e10cSrcweir ****************************************/ 2795cdf0e10cSrcweir 2796cdf0e10cSrcweir rtl_uString* oslMakeUStrFromPsz(const sal_Char* pszStr, rtl_uString** ustrValid) 2797cdf0e10cSrcweir { 2798cdf0e10cSrcweir rtl_string2UString( 2799cdf0e10cSrcweir ustrValid, 2800cdf0e10cSrcweir pszStr, 2801cdf0e10cSrcweir rtl_str_getLength( pszStr ), 2802cdf0e10cSrcweir osl_getThreadTextEncoding(), 2803cdf0e10cSrcweir OUSTRING_TO_OSTRING_CVTFLAGS ); 2804cdf0e10cSrcweir OSL_ASSERT(*ustrValid != 0); 2805cdf0e10cSrcweir 2806cdf0e10cSrcweir return *ustrValid; 2807cdf0e10cSrcweir } 2808cdf0e10cSrcweir 2809cdf0e10cSrcweir /***************************************************************************** 2810cdf0e10cSrcweir * UnicodeToText 2811cdf0e10cSrcweir * converting unicode to text manually saves us the penalty of a temporary 2812cdf0e10cSrcweir * rtl_String object. 2813cdf0e10cSrcweir ****************************************************************************/ 2814cdf0e10cSrcweir 2815cdf0e10cSrcweir int UnicodeToText( char * buffer, size_t bufLen, const sal_Unicode * uniText, sal_Int32 uniTextLen ) 2816cdf0e10cSrcweir { 2817cdf0e10cSrcweir rtl_UnicodeToTextConverter hConverter; 2818cdf0e10cSrcweir sal_uInt32 nInfo; 2819cdf0e10cSrcweir sal_Size nSrcChars, nDestBytes; 2820cdf0e10cSrcweir 2821cdf0e10cSrcweir /* stolen from rtl/string.c */ 2822cdf0e10cSrcweir hConverter = rtl_createUnicodeToTextConverter( osl_getThreadTextEncoding() ); 2823cdf0e10cSrcweir 2824cdf0e10cSrcweir nDestBytes = rtl_convertUnicodeToText( hConverter, 0, uniText, uniTextLen, 2825cdf0e10cSrcweir buffer, bufLen, 2826cdf0e10cSrcweir OUSTRING_TO_OSTRING_CVTFLAGS | RTL_UNICODETOTEXT_FLAGS_FLUSH, 2827cdf0e10cSrcweir &nInfo, &nSrcChars ); 2828cdf0e10cSrcweir 2829cdf0e10cSrcweir rtl_destroyUnicodeToTextConverter( hConverter ); 2830cdf0e10cSrcweir 2831cdf0e10cSrcweir if( nInfo & RTL_UNICODETOTEXT_INFO_DESTBUFFERTOSMALL ) 2832cdf0e10cSrcweir { 2833cdf0e10cSrcweir errno = EOVERFLOW; 2834cdf0e10cSrcweir return 0; 2835cdf0e10cSrcweir } 2836cdf0e10cSrcweir 2837cdf0e10cSrcweir /* ensure trailing '\0' */ 2838cdf0e10cSrcweir buffer[nDestBytes] = '\0'; 2839cdf0e10cSrcweir 2840cdf0e10cSrcweir return nDestBytes; 2841cdf0e10cSrcweir } 2842cdf0e10cSrcweir 2843cdf0e10cSrcweir /***************************************************************************** 2844cdf0e10cSrcweir TextToUnicode 2845cdf0e10cSrcweir 2846cdf0e10cSrcweir @param text 2847cdf0e10cSrcweir The text to convert. 2848cdf0e10cSrcweir 2849cdf0e10cSrcweir @param text_buffer_size 2850cdf0e10cSrcweir The number of characters. 2851cdf0e10cSrcweir 2852cdf0e10cSrcweir @param unic_text 2853cdf0e10cSrcweir The unicode buffer. 2854cdf0e10cSrcweir 2855cdf0e10cSrcweir @param unic_text_buffer_size 2856cdf0e10cSrcweir The size in characters of the unicode buffer. 2857cdf0e10cSrcweir 2858cdf0e10cSrcweir ****************************************************************************/ 2859cdf0e10cSrcweir 2860cdf0e10cSrcweir int TextToUnicode( 2861cdf0e10cSrcweir const char* text, 2862cdf0e10cSrcweir size_t text_buffer_size, 2863cdf0e10cSrcweir sal_Unicode* unic_text, 2864cdf0e10cSrcweir sal_Int32 unic_text_buffer_size) 2865cdf0e10cSrcweir { 2866cdf0e10cSrcweir rtl_TextToUnicodeConverter hConverter; 2867cdf0e10cSrcweir sal_uInt32 nInfo; 2868cdf0e10cSrcweir sal_Size nSrcChars; 2869cdf0e10cSrcweir sal_Size nDestBytes; 2870cdf0e10cSrcweir 2871cdf0e10cSrcweir /* stolen from rtl/string.c */ 2872cdf0e10cSrcweir hConverter = rtl_createTextToUnicodeConverter(osl_getThreadTextEncoding()); 2873cdf0e10cSrcweir 2874cdf0e10cSrcweir nDestBytes = rtl_convertTextToUnicode(hConverter, 2875cdf0e10cSrcweir 0, 2876cdf0e10cSrcweir text, text_buffer_size, 2877cdf0e10cSrcweir unic_text, unic_text_buffer_size, 2878cdf0e10cSrcweir OSTRING_TO_OUSTRING_CVTFLAGS | RTL_TEXTTOUNICODE_FLAGS_FLUSH, 2879cdf0e10cSrcweir &nInfo, &nSrcChars); 2880cdf0e10cSrcweir 2881cdf0e10cSrcweir rtl_destroyTextToUnicodeConverter(hConverter); 2882cdf0e10cSrcweir 2883cdf0e10cSrcweir if (nInfo & RTL_TEXTTOUNICODE_INFO_DESTBUFFERTOSMALL) 2884cdf0e10cSrcweir { 2885cdf0e10cSrcweir errno = EOVERFLOW; 2886cdf0e10cSrcweir return 0; 2887cdf0e10cSrcweir } 2888cdf0e10cSrcweir 2889cdf0e10cSrcweir /* ensure trailing '\0' */ 2890cdf0e10cSrcweir unic_text[nDestBytes] = '\0'; 2891cdf0e10cSrcweir 2892cdf0e10cSrcweir return nDestBytes; 2893cdf0e10cSrcweir } 2894cdf0e10cSrcweir 2895cdf0e10cSrcweir /****************************************************************************** 2896cdf0e10cSrcweir * 2897cdf0e10cSrcweir * GENERIC FLOPPY FUNCTIONS 2898cdf0e10cSrcweir * 2899cdf0e10cSrcweir *****************************************************************************/ 2900cdf0e10cSrcweir 2901cdf0e10cSrcweir 2902cdf0e10cSrcweir /***************************************** 2903cdf0e10cSrcweir * osl_unmountVolumeDevice 2904cdf0e10cSrcweir ****************************************/ 2905cdf0e10cSrcweir 2906cdf0e10cSrcweir oslFileError osl_unmountVolumeDevice( oslVolumeDeviceHandle Handle ) 2907cdf0e10cSrcweir { 2908cdf0e10cSrcweir oslFileError tErr = osl_File_E_NOSYS; 2909cdf0e10cSrcweir 2910cdf0e10cSrcweir tErr = osl_unmountFloppy(Handle); 2911cdf0e10cSrcweir 2912cdf0e10cSrcweir /* Perhaps current working directory is set to mount point */ 2913cdf0e10cSrcweir 2914cdf0e10cSrcweir if ( tErr ) 2915cdf0e10cSrcweir { 2916cdf0e10cSrcweir sal_Char *pszHomeDir = getenv("HOME"); 2917cdf0e10cSrcweir 2918cdf0e10cSrcweir if ( pszHomeDir && strlen( pszHomeDir ) && 0 == chdir( pszHomeDir ) ) 2919cdf0e10cSrcweir { 2920cdf0e10cSrcweir /* try again */ 2921cdf0e10cSrcweir 2922cdf0e10cSrcweir tErr = osl_unmountFloppy(Handle); 2923cdf0e10cSrcweir 2924cdf0e10cSrcweir OSL_ENSURE( tErr, "osl_unmountvolumeDevice: CWD was set to volume mount point" ); 2925cdf0e10cSrcweir } 2926cdf0e10cSrcweir } 2927cdf0e10cSrcweir 2928cdf0e10cSrcweir return tErr; 2929cdf0e10cSrcweir } 2930cdf0e10cSrcweir 2931cdf0e10cSrcweir /***************************************** 2932cdf0e10cSrcweir * osl_automountVolumeDevice 2933cdf0e10cSrcweir ****************************************/ 2934cdf0e10cSrcweir 2935cdf0e10cSrcweir oslFileError osl_automountVolumeDevice( oslVolumeDeviceHandle Handle ) 2936cdf0e10cSrcweir { 2937cdf0e10cSrcweir oslFileError tErr = osl_File_E_NOSYS; 2938cdf0e10cSrcweir 2939cdf0e10cSrcweir tErr = osl_mountFloppy(Handle); 2940cdf0e10cSrcweir 2941cdf0e10cSrcweir return tErr; 2942cdf0e10cSrcweir } 2943cdf0e10cSrcweir 2944cdf0e10cSrcweir /***************************************** 2945cdf0e10cSrcweir * osl_getVolumeDeviceMountPath 2946cdf0e10cSrcweir ****************************************/ 2947cdf0e10cSrcweir 2948cdf0e10cSrcweir oslFileError osl_getVolumeDeviceMountPath( oslVolumeDeviceHandle Handle, rtl_uString **pstrPath ) 2949cdf0e10cSrcweir { 2950cdf0e10cSrcweir oslVolumeDeviceHandleImpl* pItem = (oslVolumeDeviceHandleImpl*) Handle; 2951cdf0e10cSrcweir sal_Char Buffer[PATH_MAX]; 2952cdf0e10cSrcweir 2953cdf0e10cSrcweir Buffer[0] = '\0'; 2954cdf0e10cSrcweir 2955cdf0e10cSrcweir if ( pItem == 0 || pstrPath == 0 ) 2956cdf0e10cSrcweir { 2957cdf0e10cSrcweir return osl_File_E_INVAL; 2958cdf0e10cSrcweir } 2959cdf0e10cSrcweir 2960cdf0e10cSrcweir if ( pItem->ident[0] != 'O' || pItem->ident[1] != 'V' || pItem->ident[2] != 'D' || pItem->ident[3] != 'H' ) 2961cdf0e10cSrcweir { 2962cdf0e10cSrcweir return osl_File_E_INVAL; 2963cdf0e10cSrcweir } 2964cdf0e10cSrcweir 2965cdf0e10cSrcweir #ifdef DEBUG_OSL_FILE 2966cdf0e10cSrcweir fprintf(stderr,"Handle is:\n"); 2967cdf0e10cSrcweir osl_printFloppyHandle(pItem); 2968cdf0e10cSrcweir #endif 2969cdf0e10cSrcweir 2970cdf0e10cSrcweir snprintf(Buffer, sizeof(Buffer), "file://%s", pItem->pszMountPoint); 2971cdf0e10cSrcweir 2972cdf0e10cSrcweir #ifdef DEBUG_OSL_FILE 2973cdf0e10cSrcweir fprintf(stderr,"Mount Point is: '%s'\n",Buffer); 2974cdf0e10cSrcweir #endif 2975cdf0e10cSrcweir 2976cdf0e10cSrcweir oslMakeUStrFromPsz(Buffer, pstrPath); 2977cdf0e10cSrcweir 2978cdf0e10cSrcweir return osl_File_E_None; 2979cdf0e10cSrcweir } 2980cdf0e10cSrcweir 2981cdf0e10cSrcweir /***************************************** 2982cdf0e10cSrcweir * osl_acquireVolumeDeviceHandle 2983cdf0e10cSrcweir ****************************************/ 2984cdf0e10cSrcweir 2985cdf0e10cSrcweir oslFileError SAL_CALL osl_acquireVolumeDeviceHandle( oslVolumeDeviceHandle Handle ) 2986cdf0e10cSrcweir { 2987cdf0e10cSrcweir oslVolumeDeviceHandleImpl* pItem =(oslVolumeDeviceHandleImpl*) Handle; 2988cdf0e10cSrcweir 2989cdf0e10cSrcweir if ( pItem == 0 ) 2990cdf0e10cSrcweir { 2991cdf0e10cSrcweir return osl_File_E_INVAL; 2992cdf0e10cSrcweir } 2993cdf0e10cSrcweir 2994cdf0e10cSrcweir if ( pItem->ident[0] != 'O' || pItem->ident[1] != 'V' || pItem->ident[2] != 'D' || pItem->ident[3] != 'H' ) 2995cdf0e10cSrcweir { 2996cdf0e10cSrcweir return osl_File_E_INVAL; 2997cdf0e10cSrcweir } 2998cdf0e10cSrcweir 2999cdf0e10cSrcweir ++pItem->RefCount; 3000cdf0e10cSrcweir 3001cdf0e10cSrcweir return osl_File_E_None; 3002cdf0e10cSrcweir } 3003cdf0e10cSrcweir 3004cdf0e10cSrcweir /***************************************** 3005cdf0e10cSrcweir * osl_releaseVolumeDeviceHandle 3006cdf0e10cSrcweir ****************************************/ 3007cdf0e10cSrcweir 3008cdf0e10cSrcweir oslFileError osl_releaseVolumeDeviceHandle( oslVolumeDeviceHandle Handle ) 3009cdf0e10cSrcweir { 3010cdf0e10cSrcweir oslVolumeDeviceHandleImpl* pItem =(oslVolumeDeviceHandleImpl*) Handle; 3011cdf0e10cSrcweir 3012cdf0e10cSrcweir if ( pItem == 0 ) 3013cdf0e10cSrcweir { 3014cdf0e10cSrcweir return osl_File_E_INVAL; 3015cdf0e10cSrcweir } 3016cdf0e10cSrcweir 3017cdf0e10cSrcweir if ( pItem->ident[0] != 'O' || pItem->ident[1] != 'V' || pItem->ident[2] != 'D' || pItem->ident[3] != 'H' ) 3018cdf0e10cSrcweir { 3019cdf0e10cSrcweir return osl_File_E_INVAL; 3020cdf0e10cSrcweir } 3021cdf0e10cSrcweir 3022cdf0e10cSrcweir --pItem->RefCount; 3023cdf0e10cSrcweir 3024cdf0e10cSrcweir if ( pItem->RefCount == 0 ) 3025cdf0e10cSrcweir { 3026cdf0e10cSrcweir rtl_freeMemory(pItem); 3027cdf0e10cSrcweir } 3028cdf0e10cSrcweir 3029cdf0e10cSrcweir return osl_File_E_None; 3030cdf0e10cSrcweir } 3031cdf0e10cSrcweir 3032cdf0e10cSrcweir /***************************************** 3033cdf0e10cSrcweir * osl_newVolumeDeviceHandleImpl 3034cdf0e10cSrcweir ****************************************/ 3035cdf0e10cSrcweir 3036cdf0e10cSrcweir static oslVolumeDeviceHandleImpl* osl_newVolumeDeviceHandleImpl() 3037cdf0e10cSrcweir { 3038cdf0e10cSrcweir oslVolumeDeviceHandleImpl* pHandle; 3039cdf0e10cSrcweir const size_t nSizeOfHandle = sizeof(oslVolumeDeviceHandleImpl); 3040cdf0e10cSrcweir 3041cdf0e10cSrcweir pHandle = (oslVolumeDeviceHandleImpl*) rtl_allocateMemory (nSizeOfHandle); 3042cdf0e10cSrcweir if (pHandle != NULL) 3043cdf0e10cSrcweir { 3044cdf0e10cSrcweir pHandle->ident[0] = 'O'; 3045cdf0e10cSrcweir pHandle->ident[1] = 'V'; 3046cdf0e10cSrcweir pHandle->ident[2] = 'D'; 3047cdf0e10cSrcweir pHandle->ident[3] = 'H'; 3048cdf0e10cSrcweir pHandle->pszMountPoint[0] = '\0'; 3049cdf0e10cSrcweir pHandle->pszFilePath[0] = '\0'; 3050cdf0e10cSrcweir pHandle->pszDevice[0] = '\0'; 3051cdf0e10cSrcweir pHandle->RefCount = 1; 3052cdf0e10cSrcweir } 3053cdf0e10cSrcweir return pHandle; 3054cdf0e10cSrcweir } 3055cdf0e10cSrcweir 3056cdf0e10cSrcweir /***************************************** 3057cdf0e10cSrcweir * osl_freeVolumeDeviceHandleImpl 3058cdf0e10cSrcweir ****************************************/ 3059cdf0e10cSrcweir 3060cdf0e10cSrcweir static void osl_freeVolumeDeviceHandleImpl (oslVolumeDeviceHandleImpl* pHandle) 3061cdf0e10cSrcweir { 3062cdf0e10cSrcweir if (pHandle != NULL) 3063cdf0e10cSrcweir rtl_freeMemory (pHandle); 3064cdf0e10cSrcweir } 3065cdf0e10cSrcweir 3066cdf0e10cSrcweir 3067cdf0e10cSrcweir /****************************************************************************** 3068cdf0e10cSrcweir * 3069cdf0e10cSrcweir * OS/2 FLOPPY FUNCTIONS 3070cdf0e10cSrcweir * 3071cdf0e10cSrcweir *****************************************************************************/ 3072cdf0e10cSrcweir 3073cdf0e10cSrcweir #if defined(OS2) 3074cdf0e10cSrcweir static oslVolumeDeviceHandle osl_isFloppyDrive(const sal_Char* pszPath) 3075cdf0e10cSrcweir { 3076cdf0e10cSrcweir return NULL; 3077cdf0e10cSrcweir } 3078cdf0e10cSrcweir 3079cdf0e10cSrcweir static oslFileError osl_mountFloppy(oslVolumeDeviceHandle hFloppy) 3080cdf0e10cSrcweir { 3081cdf0e10cSrcweir return osl_File_E_BUSY; 3082cdf0e10cSrcweir } 3083cdf0e10cSrcweir 3084cdf0e10cSrcweir static oslFileError osl_unmountFloppy(oslVolumeDeviceHandle hFloppy) 3085cdf0e10cSrcweir { 3086cdf0e10cSrcweir return osl_File_E_BUSY; 3087cdf0e10cSrcweir } 3088cdf0e10cSrcweir 3089cdf0e10cSrcweir static sal_Bool osl_getFloppyMountEntry(const sal_Char* pszPath, oslVolumeDeviceHandleImpl* pItem) 3090cdf0e10cSrcweir { 3091cdf0e10cSrcweir return sal_False; 3092cdf0e10cSrcweir } 3093cdf0e10cSrcweir 3094cdf0e10cSrcweir static sal_Bool osl_isFloppyMounted(oslVolumeDeviceHandleImpl* pDevice) 3095cdf0e10cSrcweir { 3096cdf0e10cSrcweir return sal_False; 3097cdf0e10cSrcweir } 3098cdf0e10cSrcweir 3099cdf0e10cSrcweir 3100cdf0e10cSrcweir #ifdef DEBUG_OSL_FILE 3101cdf0e10cSrcweir static void osl_printFloppyHandle(oslVolumeDeviceHandleImpl* pItem) 3102cdf0e10cSrcweir { 3103cdf0e10cSrcweir if (pItem == 0 ) 3104cdf0e10cSrcweir { 3105cdf0e10cSrcweir fprintf(stderr,"NULL Handle\n"); 3106cdf0e10cSrcweir return; 3107cdf0e10cSrcweir } 3108cdf0e10cSrcweir if ( pItem->ident[0] != 'O' || pItem->ident[1] != 'V' || pItem->ident[2] != 'D' || pItem->ident[3] != 'H' ) 3109cdf0e10cSrcweir { 3110cdf0e10cSrcweir #ifdef TRACE_OSL_FILE 3111cdf0e10cSrcweir fprintf(stderr,"Invalid Handle]\n"); 3112cdf0e10cSrcweir #endif 3113cdf0e10cSrcweir return; 3114cdf0e10cSrcweir } 3115cdf0e10cSrcweir 3116cdf0e10cSrcweir 3117cdf0e10cSrcweir fprintf(stderr,"MountPoint : '%s'\n",pItem->pszMountPoint); 3118cdf0e10cSrcweir fprintf(stderr,"FilePath : '%s'\n",pItem->pszFilePath); 3119cdf0e10cSrcweir fprintf(stderr,"Device : '%s'\n",pItem->pszDevice); 3120cdf0e10cSrcweir 3121cdf0e10cSrcweir return; 3122cdf0e10cSrcweir } 3123cdf0e10cSrcweir #endif 3124cdf0e10cSrcweir 3125cdf0e10cSrcweir #endif /* OS2 */ 3126