1565d668cSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3565d668cSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4565d668cSAndrew Rist * or more contributor license agreements. See the NOTICE file 5565d668cSAndrew Rist * distributed with this work for additional information 6565d668cSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7565d668cSAndrew Rist * to you under the Apache License, Version 2.0 (the 8565d668cSAndrew Rist * "License"); you may not use this file except in compliance 9565d668cSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11565d668cSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13565d668cSAndrew Rist * Unless required by applicable law or agreed to in writing, 14565d668cSAndrew Rist * software distributed under the License is distributed on an 15565d668cSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16565d668cSAndrew Rist * KIND, either express or implied. See the License for the 17565d668cSAndrew Rist * specific language governing permissions and limitations 18565d668cSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20565d668cSAndrew Rist *************************************************************/ 21565d668cSAndrew Rist 22565d668cSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir /** @HTML */ 25cdf0e10cSrcweir 26cdf0e10cSrcweir #ifndef _OSL_FILE_HXX_ 27cdf0e10cSrcweir #define _OSL_FILE_HXX_ 28cdf0e10cSrcweir 29cdf0e10cSrcweir #ifdef __cplusplus 30cdf0e10cSrcweir 31cdf0e10cSrcweir #include <osl/time.h> 32cdf0e10cSrcweir # include <rtl/memory.h> 33cdf0e10cSrcweir # include <rtl/ustring.hxx> 34cdf0e10cSrcweir 35cdf0e10cSrcweir #include <osl/file.h> 36cdf0e10cSrcweir # include <rtl/byteseq.hxx> 37cdf0e10cSrcweir 38cdf0e10cSrcweir #include <stdio.h> 39cdf0e10cSrcweir 40cdf0e10cSrcweir namespace osl 41cdf0e10cSrcweir { 42cdf0e10cSrcweir 43cdf0e10cSrcweir 44cdf0e10cSrcweir // ----------------------------------------------------------------------------- 45cdf0e10cSrcweir /** Base class for all File System specific objects. 46cdf0e10cSrcweir 47cdf0e10cSrcweir @see Directory 48cdf0e10cSrcweir @see DirectoryItem 49cdf0e10cSrcweir @see File 50cdf0e10cSrcweir */ 51cdf0e10cSrcweir 52cdf0e10cSrcweir class FileBase 53cdf0e10cSrcweir { 54cdf0e10cSrcweir public: 55cdf0e10cSrcweir 56cdf0e10cSrcweir enum RC { 57cdf0e10cSrcweir E_None = osl_File_E_None, 58cdf0e10cSrcweir E_PERM = osl_File_E_PERM, 59cdf0e10cSrcweir E_NOENT = osl_File_E_NOENT, 60cdf0e10cSrcweir E_SRCH = osl_File_E_SRCH, 61cdf0e10cSrcweir E_INTR = osl_File_E_INTR, 62cdf0e10cSrcweir E_IO = osl_File_E_IO, 63cdf0e10cSrcweir E_NXIO = osl_File_E_NXIO, 64cdf0e10cSrcweir E_2BIG = osl_File_E_2BIG, 65cdf0e10cSrcweir E_NOEXEC = osl_File_E_NOEXEC, 66cdf0e10cSrcweir E_BADF = osl_File_E_BADF, 67cdf0e10cSrcweir E_CHILD = osl_File_E_CHILD, 68cdf0e10cSrcweir E_AGAIN = osl_File_E_AGAIN, 69cdf0e10cSrcweir E_NOMEM = osl_File_E_NOMEM, 70cdf0e10cSrcweir E_ACCES = osl_File_E_ACCES, 71cdf0e10cSrcweir E_FAULT = osl_File_E_FAULT, 72cdf0e10cSrcweir E_BUSY = osl_File_E_BUSY, 73cdf0e10cSrcweir E_EXIST = osl_File_E_EXIST, 74cdf0e10cSrcweir E_XDEV = osl_File_E_XDEV, 75cdf0e10cSrcweir E_NODEV = osl_File_E_NODEV, 76cdf0e10cSrcweir E_NOTDIR = osl_File_E_NOTDIR, 77cdf0e10cSrcweir E_ISDIR = osl_File_E_ISDIR, 78cdf0e10cSrcweir E_INVAL = osl_File_E_INVAL, 79cdf0e10cSrcweir E_NFILE = osl_File_E_NFILE, 80cdf0e10cSrcweir E_MFILE = osl_File_E_MFILE, 81cdf0e10cSrcweir E_NOTTY = osl_File_E_NOTTY, 82cdf0e10cSrcweir E_FBIG = osl_File_E_FBIG, 83cdf0e10cSrcweir E_NOSPC = osl_File_E_NOSPC, 84cdf0e10cSrcweir E_SPIPE = osl_File_E_SPIPE, 85cdf0e10cSrcweir E_ROFS = osl_File_E_ROFS, 86cdf0e10cSrcweir E_MLINK = osl_File_E_MLINK, 87cdf0e10cSrcweir E_PIPE = osl_File_E_PIPE, 88cdf0e10cSrcweir E_DOM = osl_File_E_DOM, 89cdf0e10cSrcweir E_RANGE = osl_File_E_RANGE, 90cdf0e10cSrcweir E_DEADLK = osl_File_E_DEADLK, 91cdf0e10cSrcweir E_NAMETOOLONG = osl_File_E_NAMETOOLONG, 92cdf0e10cSrcweir E_NOLCK = osl_File_E_NOLCK, 93cdf0e10cSrcweir E_NOSYS = osl_File_E_NOSYS, 94cdf0e10cSrcweir E_NOTEMPTY = osl_File_E_NOTEMPTY, 95cdf0e10cSrcweir E_LOOP = osl_File_E_LOOP, 96cdf0e10cSrcweir E_ILSEQ = osl_File_E_ILSEQ, 97cdf0e10cSrcweir E_NOLINK = osl_File_E_NOLINK, 98cdf0e10cSrcweir E_MULTIHOP = osl_File_E_MULTIHOP, 99cdf0e10cSrcweir E_USERS = osl_File_E_USERS, 100cdf0e10cSrcweir E_OVERFLOW = osl_File_E_OVERFLOW, 101cdf0e10cSrcweir E_NOTREADY = osl_File_E_NOTREADY, 102*9c0df323SAndrea Pescetti E_LOCKED = osl_File_E_LOCKED, 103cdf0e10cSrcweir E_invalidError = osl_File_E_invalidError, /* unmapped error: always last entry in enum! */ 104cdf0e10cSrcweir E_TIMEDOUT = osl_File_E_TIMEDOUT, 105cdf0e10cSrcweir E_NETWORK = osl_File_E_NETWORK 106cdf0e10cSrcweir }; 107cdf0e10cSrcweir 108cdf0e10cSrcweir 109cdf0e10cSrcweir public: 110cdf0e10cSrcweir 111cdf0e10cSrcweir /** Determine a valid unused canonical name for a requested name. 112cdf0e10cSrcweir 113cdf0e10cSrcweir Determines a valid unused canonical name for a requested name. 114cdf0e10cSrcweir Depending on the Operating System and the File System the illegal characters are replaced by valid ones. 115cdf0e10cSrcweir If a file or directory with the requested name already exists a new name is generated following 116cdf0e10cSrcweir the common rules on the actual Operating System and File System. 117cdf0e10cSrcweir 118cdf0e10cSrcweir @param ustrRequestedURL [in] 119cdf0e10cSrcweir Requested name of a file or directory. 120cdf0e10cSrcweir 121cdf0e10cSrcweir @param pustrValidURL [out] 122cdf0e10cSrcweir On success receives a name which is unused and valid on the actual Operating System and 123cdf0e10cSrcweir File System. 124cdf0e10cSrcweir 125cdf0e10cSrcweir @return 126cdf0e10cSrcweir E_None on success 127cdf0e10cSrcweir E_INVAL the format of the parameters was not valid 128cdf0e10cSrcweir 129cdf0e10cSrcweir @see DirectoryItem::getFileStatus() 130cdf0e10cSrcweir */ 131cdf0e10cSrcweir 132cdf0e10cSrcweir static inline RC getCanonicalName( const ::rtl::OUString& ustrRequestedURL, ::rtl::OUString& ustrValidURL ) 133cdf0e10cSrcweir { 134cdf0e10cSrcweir return (RC) osl_getCanonicalName( ustrRequestedURL.pData, &ustrValidURL.pData ); 135cdf0e10cSrcweir } 136cdf0e10cSrcweir 137cdf0e10cSrcweir /** Convert a path relative to a given directory into an full qualified file URL. 138cdf0e10cSrcweir 139cdf0e10cSrcweir Convert a path relative to a given directory into an full qualified file URL. 140cdf0e10cSrcweir The function resolves symbolic links if possible and path ellipses, so on success 141cdf0e10cSrcweir the resulting absolute path is fully resolved. 142cdf0e10cSrcweir 143cdf0e10cSrcweir @param ustrBaseDirectoryURL [in] 144cdf0e10cSrcweir Base directory URL to which the relative path is related to. 145cdf0e10cSrcweir 146cdf0e10cSrcweir @param ustrRelativeFileURL [in] 147cdf0e10cSrcweir An URL of a file or directory relative to the directory path specified by ustrBaseDirectoryURL 148cdf0e10cSrcweir or an absolute path. 149cdf0e10cSrcweir If ustrRelativeFileURL denotes an absolute path ustrBaseDirectoryURL will be ignored. 150cdf0e10cSrcweir 151cdf0e10cSrcweir @param ustrAbsoluteFileURL [out] 152cdf0e10cSrcweir On success it receives the full qualified absoulte file URL. 153cdf0e10cSrcweir 154cdf0e10cSrcweir @return 155cdf0e10cSrcweir E_None on success 156cdf0e10cSrcweir E_INVAL the format of the parameters was not valid 157cdf0e10cSrcweir E_NOMEM not enough memory for allocating structures 158cdf0e10cSrcweir E_NOTDIR not a directory 159cdf0e10cSrcweir E_ACCES permission denied 160cdf0e10cSrcweir E_NOENT no such file or directory 161cdf0e10cSrcweir E_NAMETOOLONG file name too long 162cdf0e10cSrcweir E_OVERFLOW value too large for defined data type 163cdf0e10cSrcweir E_FAULT bad address 164cdf0e10cSrcweir E_INTR function call was interrupted 165cdf0e10cSrcweir E_LOOP too many symbolic links encountered 166cdf0e10cSrcweir E_MULTIHOP multihop attempted 167cdf0e10cSrcweir E_NOLINK link has been severed 168cdf0e10cSrcweir 169cdf0e10cSrcweir @see DirectoryItem::getFileStatus() 170cdf0e10cSrcweir */ 171cdf0e10cSrcweir 172cdf0e10cSrcweir static inline RC getAbsoluteFileURL( const ::rtl::OUString& ustrBaseDirectoryURL, const ::rtl::OUString& ustrRelativeFileURL, ::rtl::OUString& ustrAbsoluteFileURL ) 173cdf0e10cSrcweir { 174cdf0e10cSrcweir return (RC) osl_getAbsoluteFileURL( ustrBaseDirectoryURL.pData, ustrRelativeFileURL.pData, &ustrAbsoluteFileURL.pData ); 175cdf0e10cSrcweir } 176cdf0e10cSrcweir 177cdf0e10cSrcweir /** Convert a file URL into a system dependend path. 178cdf0e10cSrcweir 179cdf0e10cSrcweir @param ustrFileURL [in] 180cdf0e10cSrcweir A File URL. 181cdf0e10cSrcweir 182cdf0e10cSrcweir @param ustrSystemPath [out] 183cdf0e10cSrcweir On success it receives the system path. 184cdf0e10cSrcweir 185cdf0e10cSrcweir @return 186cdf0e10cSrcweir E_None on success 187cdf0e10cSrcweir E_INVAL the format of the parameters was not valid 188cdf0e10cSrcweir 189cdf0e10cSrcweir @see getFileURLFromSystemPath() 190cdf0e10cSrcweir */ 191cdf0e10cSrcweir 192cdf0e10cSrcweir static inline RC getSystemPathFromFileURL( const ::rtl::OUString& ustrFileURL, ::rtl::OUString& ustrSystemPath ) 193cdf0e10cSrcweir { 194cdf0e10cSrcweir return (RC) osl_getSystemPathFromFileURL( ustrFileURL.pData, &ustrSystemPath.pData ); 195cdf0e10cSrcweir } 196cdf0e10cSrcweir 197cdf0e10cSrcweir /** Convert a system dependend path into a file URL. 198cdf0e10cSrcweir 199cdf0e10cSrcweir @param ustrSystemPath [in] 200cdf0e10cSrcweir A System dependent path of a file or directory. 201cdf0e10cSrcweir 202cdf0e10cSrcweir @param ustrFileURL [out] 203cdf0e10cSrcweir On success it receives the file URL. 204cdf0e10cSrcweir 205cdf0e10cSrcweir @return 206cdf0e10cSrcweir E_None on success 207cdf0e10cSrcweir E_INVAL the format of the parameters was not valid 208cdf0e10cSrcweir 209cdf0e10cSrcweir @see getSystemPathFromFileURL() 210cdf0e10cSrcweir */ 211cdf0e10cSrcweir 212cdf0e10cSrcweir static inline RC getFileURLFromSystemPath( const ::rtl::OUString& ustrSystemPath, ::rtl::OUString& ustrFileURL ) 213cdf0e10cSrcweir { 214cdf0e10cSrcweir return (RC) osl_getFileURLFromSystemPath( ustrSystemPath.pData, &ustrFileURL.pData ); 215cdf0e10cSrcweir } 216cdf0e10cSrcweir 217cdf0e10cSrcweir /** Searche a full qualified system path or a file URL. 218cdf0e10cSrcweir 219cdf0e10cSrcweir @param ustrFileName [in] 220cdf0e10cSrcweir A system dependent path, a file URL, a file or relative directory 221cdf0e10cSrcweir 222cdf0e10cSrcweir @param ustrSearchPath [in] 223cdf0e10cSrcweir A list of system paths, in which a given file has to be searched. The Notation of a path list is 224cdf0e10cSrcweir system dependend, e.g. on UNIX system "/usr/bin:/bin" and on Windows "C:\BIN;C:\BATCH". 225cdf0e10cSrcweir These paths are only for the search of a file or a relative path, otherwise it will be ignored. 226cdf0e10cSrcweir If ustrSearchPath is NULL or while using the search path the search failed, the function searches for 227cdf0e10cSrcweir a matching file in all system directories and in the directories listed in the PATH environment 228cdf0e10cSrcweir variable. 229cdf0e10cSrcweir The value of an environment variable should be used (e.g. LD_LIBRARY_PATH) if the caller is not 230cdf0e10cSrcweir aware of the Operating System and so doesn't know which path list delimiter to use. 231cdf0e10cSrcweir 232cdf0e10cSrcweir @param ustrFileURL [out] 233cdf0e10cSrcweir On success it receives the full qualified file URL. 234cdf0e10cSrcweir 235cdf0e10cSrcweir @return 236cdf0e10cSrcweir E_None on success 237cdf0e10cSrcweir E_INVAL the format of the parameters was not valid 238cdf0e10cSrcweir E_NOTDIR not a directory 239cdf0e10cSrcweir E_NOENT no such file or directory not found 240cdf0e10cSrcweir 241cdf0e10cSrcweir @see getFileURLFromSystemPath() 242cdf0e10cSrcweir @see getSystemPathFromFileURL() 243cdf0e10cSrcweir */ 244cdf0e10cSrcweir 245cdf0e10cSrcweir static inline RC searchFileURL( const ::rtl::OUString& ustrFileName, const ::rtl::OUString& ustrSearchPath, ::rtl::OUString& ustrFileURL ) 246cdf0e10cSrcweir { 247cdf0e10cSrcweir return (RC) osl_searchFileURL( ustrFileName.pData, ustrSearchPath.pData, &ustrFileURL.pData ); 248cdf0e10cSrcweir } 249cdf0e10cSrcweir 250cdf0e10cSrcweir /** Retrieves the file URL of the system's temporary directory path. 251cdf0e10cSrcweir 252cdf0e10cSrcweir @param ustrTempDirURL[out] 253cdf0e10cSrcweir On success receives the URL of system's temporary directory path. 254cdf0e10cSrcweir 255cdf0e10cSrcweir @return 256cdf0e10cSrcweir E_None on success 257cdf0e10cSrcweir E_NOENT no such file or directory not found 258cdf0e10cSrcweir */ 259cdf0e10cSrcweir 260cdf0e10cSrcweir static inline RC getTempDirURL( ::rtl::OUString& ustrTempDirURL ) 261cdf0e10cSrcweir { 262cdf0e10cSrcweir return (RC) osl_getTempDirURL( &ustrTempDirURL.pData ); 263cdf0e10cSrcweir } 264cdf0e10cSrcweir 265cdf0e10cSrcweir /** Creates a temporary file in the directory provided by the caller or the 266cdf0e10cSrcweir directory returned by getTempDirURL. 267cdf0e10cSrcweir Under UNIX Operating Systems the file will be created with read and write 268cdf0e10cSrcweir access for the user exclusively. 269cdf0e10cSrcweir If the caller requests only a handle to the open file but not the name of 270cdf0e10cSrcweir it, the file will be automatically removed on close else the caller is 271cdf0e10cSrcweir responsible for removing the file on success.<br><br> 272cdf0e10cSrcweir 273cdf0e10cSrcweir @param pustrDirectoryURL [in] 274cdf0e10cSrcweir Specifies the full qualified URL where the temporary file should be created. 275cdf0e10cSrcweir If pustrDirectoryURL is 0 the path returned by osl_getTempDirURL will be used. 276cdf0e10cSrcweir 277cdf0e10cSrcweir @param pHandle [out] 278cdf0e10cSrcweir On success receives a handle to the open file. 279cdf0e10cSrcweir If pHandle is 0 the file will be closed on return, in this case 280cdf0e10cSrcweir pustrTempFileURL must not be 0. 281cdf0e10cSrcweir 282cdf0e10cSrcweir @param pustrTempFileURL [out] 283cdf0e10cSrcweir On success receives the full qualified URL of the temporary file. 284cdf0e10cSrcweir If pustrTempFileURL is 0 the file will be automatically removed 285cdf0e10cSrcweir on close, in this case pHandle must not be 0. 286cdf0e10cSrcweir If pustrTempFileURL is not 0 the caller receives the name of the 287cdf0e10cSrcweir created file and is responsible for removing the file. 288cdf0e10cSrcweir 289cdf0e10cSrcweir @descr 290cdf0e10cSrcweir Description of the different pHandle, ppustrTempFileURL parameter combinations. 291cdf0e10cSrcweir pHandle is 0 and pustrTempDirURL is 0 - this combination is invalid<br> 292cdf0e10cSrcweir pHandle is not 0 and pustrTempDirURL is 0 - a handle to the open file 293cdf0e10cSrcweir will be returned on success and the file will be automatically removed on close<br> 294cdf0e10cSrcweir pHandle is 0 and pustrTempDirURL is not 0 - the name of the file will be 295cdf0e10cSrcweir returned, the caller is responsible for opening, closing and removing the file.<br> 296cdf0e10cSrcweir pHandle is not 0 and pustrTempDirURL is not 0 - a handle to the open file as well as 297cdf0e10cSrcweir the file name will be returned, the caller is responsible for closing and removing 298cdf0e10cSrcweir the file.<br> 299cdf0e10cSrcweir 300cdf0e10cSrcweir @return 301cdf0e10cSrcweir E_None on success 302cdf0e10cSrcweir E_INVAL the format of the parameter is invalid 303cdf0e10cSrcweir E_NOMEM not enough memory for allocating structures 304cdf0e10cSrcweir E_ACCES Permission denied 305cdf0e10cSrcweir E_NOENT No such file or directory 306cdf0e10cSrcweir E_NOTDIR Not a directory 307cdf0e10cSrcweir E_ROFS Read-only file system 308cdf0e10cSrcweir E_NOSPC No space left on device 309cdf0e10cSrcweir E_DQUOT Quota exceeded 310cdf0e10cSrcweir 311cdf0e10cSrcweir @see getTempDirURL() 312cdf0e10cSrcweir */ 313cdf0e10cSrcweir 314cdf0e10cSrcweir static inline RC createTempFile( 315cdf0e10cSrcweir ::rtl::OUString* pustrDirectoryURL, 316cdf0e10cSrcweir oslFileHandle* pHandle, 317cdf0e10cSrcweir ::rtl::OUString* pustrTempFileURL) 318cdf0e10cSrcweir { 319cdf0e10cSrcweir rtl_uString* pustr_dir_url = pustrDirectoryURL ? pustrDirectoryURL->pData : 0; 320cdf0e10cSrcweir rtl_uString** ppustr_tmp_file_url = pustrTempFileURL ? &pustrTempFileURL->pData : 0; 321cdf0e10cSrcweir 322cdf0e10cSrcweir return (RC) osl_createTempFile(pustr_dir_url, pHandle, ppustr_tmp_file_url); 323cdf0e10cSrcweir } 324cdf0e10cSrcweir }; 325cdf0e10cSrcweir 326cdf0e10cSrcweir 327cdf0e10cSrcweir // ----------------------------------------------------------------------------- 328cdf0e10cSrcweir /** The VolumeDevice class. 329cdf0e10cSrcweir 330cdf0e10cSrcweir @see VolumeInfo 331cdf0e10cSrcweir */ 332cdf0e10cSrcweir #ifdef OS2 333cdf0e10cSrcweir class VolumeInfo; 334cdf0e10cSrcweir #endif 335cdf0e10cSrcweir 336cdf0e10cSrcweir class VolumeDevice : public FileBase 337cdf0e10cSrcweir { 338cdf0e10cSrcweir #ifdef OS2 339cdf0e10cSrcweir public: 340cdf0e10cSrcweir #endif 341cdf0e10cSrcweir oslVolumeDeviceHandle _aHandle; 342cdf0e10cSrcweir 343cdf0e10cSrcweir public: 344cdf0e10cSrcweir 345cdf0e10cSrcweir /** Constructor. 346cdf0e10cSrcweir */ 347cdf0e10cSrcweir 348cdf0e10cSrcweir VolumeDevice() : _aHandle( NULL ) 349cdf0e10cSrcweir { 350cdf0e10cSrcweir } 351cdf0e10cSrcweir 352cdf0e10cSrcweir /** Copy constructor. 353cdf0e10cSrcweir 354cdf0e10cSrcweir @param rDevice 355cdf0e10cSrcweir The other volume device. 356cdf0e10cSrcweir */ 357cdf0e10cSrcweir 358cdf0e10cSrcweir VolumeDevice( const VolumeDevice & rDevice ) 359cdf0e10cSrcweir { 360cdf0e10cSrcweir _aHandle = rDevice._aHandle; 361cdf0e10cSrcweir if ( _aHandle ) 362cdf0e10cSrcweir osl_acquireVolumeDeviceHandle( _aHandle ); 363cdf0e10cSrcweir } 364cdf0e10cSrcweir 365cdf0e10cSrcweir /** Destructor. 366cdf0e10cSrcweir */ 367cdf0e10cSrcweir 368cdf0e10cSrcweir ~VolumeDevice() 369cdf0e10cSrcweir { 370cdf0e10cSrcweir if ( _aHandle ) 371cdf0e10cSrcweir osl_releaseVolumeDeviceHandle( _aHandle ); 372cdf0e10cSrcweir } 373cdf0e10cSrcweir 374cdf0e10cSrcweir /** Assignment operator. 375cdf0e10cSrcweir 376cdf0e10cSrcweir @param rDevice 377cdf0e10cSrcweir The other volume device. 378cdf0e10cSrcweir */ 379cdf0e10cSrcweir 380cdf0e10cSrcweir inline VolumeDevice & operator =( const VolumeDevice & rDevice ) 381cdf0e10cSrcweir { 382cdf0e10cSrcweir oslVolumeDeviceHandle newHandle = rDevice._aHandle; 383cdf0e10cSrcweir 384cdf0e10cSrcweir if ( newHandle ) 385cdf0e10cSrcweir osl_acquireVolumeDeviceHandle( newHandle ); 386cdf0e10cSrcweir 387cdf0e10cSrcweir if ( _aHandle ) 388cdf0e10cSrcweir osl_releaseVolumeDeviceHandle( _aHandle ); 389cdf0e10cSrcweir 390cdf0e10cSrcweir _aHandle = newHandle; 391cdf0e10cSrcweir 392cdf0e10cSrcweir return *this; 393cdf0e10cSrcweir } 394cdf0e10cSrcweir 395cdf0e10cSrcweir /** Automount a volume device. 396cdf0e10cSrcweir 397cdf0e10cSrcweir @return 398cdf0e10cSrcweir E_None on success 399cdf0e10cSrcweir 400cdf0e10cSrcweir @todo 401cdf0e10cSrcweir specify all error codes that may be returned 402cdf0e10cSrcweir */ 403cdf0e10cSrcweir 404cdf0e10cSrcweir inline RC automount() 405cdf0e10cSrcweir { 406cdf0e10cSrcweir return (RC)osl_automountVolumeDevice( _aHandle ); 407cdf0e10cSrcweir } 408cdf0e10cSrcweir 409cdf0e10cSrcweir /** Unmount a volume device. 410cdf0e10cSrcweir 411cdf0e10cSrcweir @return 412cdf0e10cSrcweir E_None on success 413cdf0e10cSrcweir 414cdf0e10cSrcweir @todo 415cdf0e10cSrcweir specify all error codes that may be returned 416cdf0e10cSrcweir */ 417cdf0e10cSrcweir 418cdf0e10cSrcweir inline RC unmount() 419cdf0e10cSrcweir { 420cdf0e10cSrcweir return (RC)osl_unmountVolumeDevice( _aHandle ); 421cdf0e10cSrcweir } 422cdf0e10cSrcweir 423cdf0e10cSrcweir /** Get the full qualified URL where a device is mounted to. 424cdf0e10cSrcweir 425cdf0e10cSrcweir @return 426cdf0e10cSrcweir The full qualified URL where the device is mounted to. 427cdf0e10cSrcweir */ 428cdf0e10cSrcweir inline rtl::OUString getMountPath() 429cdf0e10cSrcweir { 430cdf0e10cSrcweir rtl::OUString aPath; 431cdf0e10cSrcweir osl_getVolumeDeviceMountPath( _aHandle, &aPath.pData ); 432cdf0e10cSrcweir return aPath; 433cdf0e10cSrcweir } 434cdf0e10cSrcweir 435cdf0e10cSrcweir friend class VolumeInfo; 436cdf0e10cSrcweir }; 437cdf0e10cSrcweir 438cdf0e10cSrcweir // ----------------------------------------------------------------------------- 439cdf0e10cSrcweir 440cdf0e10cSrcweir #define VolumeInfoMask_Attributes osl_VolumeInfo_Mask_Attributes 441cdf0e10cSrcweir #define VolumeInfoMask_TotalSpace osl_VolumeInfo_Mask_TotalSpace 442cdf0e10cSrcweir #define VolumeInfoMask_UsedSpace osl_VolumeInfo_Mask_UsedSpace 443cdf0e10cSrcweir #define VolumeInfoMask_FreeSpace osl_VolumeInfo_Mask_FreeSpace 444cdf0e10cSrcweir #define VolumeInfoMask_MaxNameLength osl_VolumeInfo_Mask_MaxNameLength 445cdf0e10cSrcweir #define VolumeInfoMask_MaxPathLength osl_VolumeInfo_Mask_MaxPathLength 446cdf0e10cSrcweir #define VolumeInfoMask_FileSystemName osl_VolumeInfo_Mask_FileSystemName 447cdf0e10cSrcweir #define VolumeInfoMask_FileSystemCaseHandling osl_VolumeInfo_Mask_FileSystemCaseHandling 448cdf0e10cSrcweir 449cdf0e10cSrcweir class Directory; 450cdf0e10cSrcweir 451cdf0e10cSrcweir /** The VolumeInfo class. 452cdf0e10cSrcweir 453cdf0e10cSrcweir Neither copy nor assignment is allowed for this class. 454cdf0e10cSrcweir 455cdf0e10cSrcweir @see Directory::getVolumeInfo 456cdf0e10cSrcweir */ 457cdf0e10cSrcweir 458cdf0e10cSrcweir 459cdf0e10cSrcweir class VolumeInfo 460cdf0e10cSrcweir { 461cdf0e10cSrcweir oslVolumeInfo _aInfo; 462cdf0e10cSrcweir sal_uInt32 _nMask; 463cdf0e10cSrcweir VolumeDevice _aDevice; 464cdf0e10cSrcweir 465cdf0e10cSrcweir /** Copy constructor. 466cdf0e10cSrcweir */ 467cdf0e10cSrcweir 468cdf0e10cSrcweir VolumeInfo( VolumeInfo& ); 469cdf0e10cSrcweir 470cdf0e10cSrcweir /** Assginment operator. 471cdf0e10cSrcweir */ 472cdf0e10cSrcweir 473cdf0e10cSrcweir VolumeInfo& operator = ( VolumeInfo& ); 474cdf0e10cSrcweir 475cdf0e10cSrcweir public: 476cdf0e10cSrcweir 477cdf0e10cSrcweir /** Constructor. 478cdf0e10cSrcweir 479cdf0e10cSrcweir @param nMask 48086e1cf34SPedro Giffuni Set of flaggs describing the demanded information. 481cdf0e10cSrcweir */ 482cdf0e10cSrcweir 483cdf0e10cSrcweir VolumeInfo( sal_uInt32 nMask ): _nMask( nMask ) 484cdf0e10cSrcweir { 485cdf0e10cSrcweir _aInfo.uStructSize = sizeof( oslVolumeInfo ); 486cdf0e10cSrcweir rtl_fillMemory( &_aInfo.uValidFields, sizeof( oslVolumeInfo ) - sizeof( sal_uInt32 ), 0 ); 487cdf0e10cSrcweir _aInfo.pDeviceHandle = &_aDevice._aHandle; 488cdf0e10cSrcweir } 489cdf0e10cSrcweir 490cdf0e10cSrcweir /** Destructor. 491cdf0e10cSrcweir */ 492cdf0e10cSrcweir 493cdf0e10cSrcweir ~VolumeInfo() 494cdf0e10cSrcweir { 495cdf0e10cSrcweir if( _aInfo.ustrFileSystemName ) 496cdf0e10cSrcweir rtl_uString_release( _aInfo.ustrFileSystemName ); 497cdf0e10cSrcweir } 498cdf0e10cSrcweir 499cdf0e10cSrcweir /** Check if specified fields are valid. 500cdf0e10cSrcweir 501cdf0e10cSrcweir @param nMask 502cdf0e10cSrcweir Set of flags for the fields to check. 503cdf0e10cSrcweir 504cdf0e10cSrcweir @return sal_True if all fields are valid else sal_False. 505cdf0e10cSrcweir */ 506cdf0e10cSrcweir 507cdf0e10cSrcweir inline sal_Bool isValid( sal_uInt32 nMask ) const 508cdf0e10cSrcweir { 509cdf0e10cSrcweir return ( nMask & _aInfo.uValidFields ) == nMask; 510cdf0e10cSrcweir } 511cdf0e10cSrcweir 512cdf0e10cSrcweir /** Check the remote flag. 513cdf0e10cSrcweir 514cdf0e10cSrcweir @return 515cdf0e10cSrcweir sal_True if Attributes are valid and the volume is remote else sal_False. 516cdf0e10cSrcweir */ 517cdf0e10cSrcweir 518cdf0e10cSrcweir inline sal_Bool getRemoteFlag() const 519cdf0e10cSrcweir { 520cdf0e10cSrcweir return 0 != (_aInfo.uAttributes & osl_Volume_Attribute_Remote); 521cdf0e10cSrcweir } 522cdf0e10cSrcweir 523cdf0e10cSrcweir /** Check the removeable flag. 524cdf0e10cSrcweir 525cdf0e10cSrcweir @return 526cdf0e10cSrcweir sal_True if attributes are valid and the volume is removable else sal_False. 527cdf0e10cSrcweir */ 528cdf0e10cSrcweir 529cdf0e10cSrcweir inline sal_Bool getRemoveableFlag() const 530cdf0e10cSrcweir { 531cdf0e10cSrcweir return 0 != (_aInfo.uAttributes & osl_Volume_Attribute_Removeable); 532cdf0e10cSrcweir } 533cdf0e10cSrcweir 534cdf0e10cSrcweir /** Check the compact disc flag. 535cdf0e10cSrcweir 536cdf0e10cSrcweir @return 537cdf0e10cSrcweir sal_True if attributes are valid and the volume is a CDROM else sal_False. 538cdf0e10cSrcweir */ 539cdf0e10cSrcweir 540cdf0e10cSrcweir inline sal_Bool getCompactDiscFlag() const 541cdf0e10cSrcweir { 542cdf0e10cSrcweir return 0 != (_aInfo.uAttributes & osl_Volume_Attribute_CompactDisc); 543cdf0e10cSrcweir } 544cdf0e10cSrcweir 545cdf0e10cSrcweir /** Check the floppy disc flag. 546cdf0e10cSrcweir 547cdf0e10cSrcweir @return 548cdf0e10cSrcweir sal_True if attributes are valid and the volume is a floppy disk else sal_False. 549cdf0e10cSrcweir */ 550cdf0e10cSrcweir 551cdf0e10cSrcweir inline sal_Bool getFloppyDiskFlag() const 552cdf0e10cSrcweir { 553cdf0e10cSrcweir return 0 != (_aInfo.uAttributes & osl_Volume_Attribute_FloppyDisk); 554cdf0e10cSrcweir } 555cdf0e10cSrcweir 556cdf0e10cSrcweir /** Check the fixed disk flag. 557cdf0e10cSrcweir 558cdf0e10cSrcweir @return 559cdf0e10cSrcweir sal_True if attributes are valid and the volume is a fixed disk else sal_False. 560cdf0e10cSrcweir */ 561cdf0e10cSrcweir 562cdf0e10cSrcweir inline sal_Bool getFixedDiskFlag() const 563cdf0e10cSrcweir { 564cdf0e10cSrcweir return 0 != (_aInfo.uAttributes & osl_Volume_Attribute_FixedDisk); 565cdf0e10cSrcweir } 566cdf0e10cSrcweir 567cdf0e10cSrcweir /** Check the RAM disk flag. 568cdf0e10cSrcweir 569cdf0e10cSrcweir @return 570cdf0e10cSrcweir sal_True if attributes are valid and the volume is a RAM disk else sal_False. 571cdf0e10cSrcweir */ 572cdf0e10cSrcweir 573cdf0e10cSrcweir inline sal_Bool getRAMDiskFlag() const 574cdf0e10cSrcweir { 575cdf0e10cSrcweir return 0 != (_aInfo.uAttributes & osl_Volume_Attribute_RAMDisk); 576cdf0e10cSrcweir } 577cdf0e10cSrcweir 578cdf0e10cSrcweir /** Determine the total space of a volume device. 579cdf0e10cSrcweir 580cdf0e10cSrcweir @return 581cdf0e10cSrcweir The total diskspace of this volume if this information is valid, 582cdf0e10cSrcweir 0 otherwise. 583cdf0e10cSrcweir */ 584cdf0e10cSrcweir 585cdf0e10cSrcweir inline sal_uInt64 getTotalSpace() const 586cdf0e10cSrcweir { 587cdf0e10cSrcweir return _aInfo.uTotalSpace; 588cdf0e10cSrcweir } 589cdf0e10cSrcweir 590cdf0e10cSrcweir /** Determine the free space of a volume device. 591cdf0e10cSrcweir 592cdf0e10cSrcweir @return 593cdf0e10cSrcweir The free diskspace of this volume if this information is valid, 594cdf0e10cSrcweir 0 otherwise. 595cdf0e10cSrcweir */ 596cdf0e10cSrcweir 597cdf0e10cSrcweir inline sal_uInt64 getFreeSpace() const 598cdf0e10cSrcweir { 599cdf0e10cSrcweir return _aInfo.uFreeSpace; 600cdf0e10cSrcweir } 601cdf0e10cSrcweir 602cdf0e10cSrcweir /** Determine the used space of a volume device. 603cdf0e10cSrcweir 604cdf0e10cSrcweir @return 605cdf0e10cSrcweir The used diskspace of this volume if this information is valid, 606cdf0e10cSrcweir 0 otherwise. 607cdf0e10cSrcweir */ 608cdf0e10cSrcweir 609cdf0e10cSrcweir inline sal_uInt64 getUsedSpace() const 610cdf0e10cSrcweir { 611cdf0e10cSrcweir return _aInfo.uUsedSpace; 612cdf0e10cSrcweir } 613cdf0e10cSrcweir 614cdf0e10cSrcweir /** Determine the maximal length of a file name. 615cdf0e10cSrcweir 616cdf0e10cSrcweir @return 617cdf0e10cSrcweir The maximal length of a file name if this information is valid, 618cdf0e10cSrcweir 0 otherwise. 619cdf0e10cSrcweir */ 620cdf0e10cSrcweir 621cdf0e10cSrcweir inline sal_uInt32 getMaxNameLength() const 622cdf0e10cSrcweir { 623cdf0e10cSrcweir return _aInfo.uMaxNameLength; 624cdf0e10cSrcweir } 625cdf0e10cSrcweir 626cdf0e10cSrcweir /** Determine the maximal length of a path name. 627cdf0e10cSrcweir 628cdf0e10cSrcweir @return 629cdf0e10cSrcweir The maximal length of a path if this information is valid, 630cdf0e10cSrcweir 0 otherwise. 631cdf0e10cSrcweir */ 632cdf0e10cSrcweir 633cdf0e10cSrcweir inline sal_uInt32 getMaxPathLength() const 634cdf0e10cSrcweir { 635cdf0e10cSrcweir return _aInfo.uMaxPathLength; 636cdf0e10cSrcweir } 637cdf0e10cSrcweir 638cdf0e10cSrcweir /** Determine the name of the volume device's File System. 639cdf0e10cSrcweir 640cdf0e10cSrcweir @return 641cdf0e10cSrcweir The name of the volume's fielsystem if this information is valid, 642cdf0e10cSrcweir otherwise an empty string. 643cdf0e10cSrcweir */ 644cdf0e10cSrcweir 645cdf0e10cSrcweir inline ::rtl::OUString getFileSystemName() const 646cdf0e10cSrcweir { 647cdf0e10cSrcweir return _aInfo.ustrFileSystemName ? ::rtl::OUString( _aInfo.ustrFileSystemName ) : ::rtl::OUString(); 648cdf0e10cSrcweir } 649cdf0e10cSrcweir 650cdf0e10cSrcweir 651cdf0e10cSrcweir /** Get the volume device handle. 652cdf0e10cSrcweir 653cdf0e10cSrcweir @return 654cdf0e10cSrcweir The device handle of the volume if this information is valid, 655cdf0e10cSrcweir otherwise returns NULL; 656cdf0e10cSrcweir */ 657cdf0e10cSrcweir 658cdf0e10cSrcweir inline VolumeDevice getDeviceHandle() const 659cdf0e10cSrcweir { 660cdf0e10cSrcweir return _aDevice; 661cdf0e10cSrcweir } 662cdf0e10cSrcweir 663cdf0e10cSrcweir /** Return whether the file system is case sensitive or 664cdf0e10cSrcweir case insensitive 665cdf0e10cSrcweir 666cdf0e10cSrcweir @return 667cdf0e10cSrcweir true if the file system is case sensitive false otherwise 668cdf0e10cSrcweir */ 669cdf0e10cSrcweir bool isCaseSensitiveFileSystem() const 670cdf0e10cSrcweir { 671cdf0e10cSrcweir return (_aInfo.uAttributes & osl_Volume_Attribute_Case_Sensitive); 672cdf0e10cSrcweir } 673cdf0e10cSrcweir 674cdf0e10cSrcweir /** Return whether the file system preserves the case of 675cdf0e10cSrcweir file and directory names or not 676cdf0e10cSrcweir 677cdf0e10cSrcweir @return 678cdf0e10cSrcweir true if the file system preserves the case of file and 679cdf0e10cSrcweir directory names false otherwise 680cdf0e10cSrcweir */ 681cdf0e10cSrcweir bool isCasePreservingFileSystem() const 682cdf0e10cSrcweir { 683cdf0e10cSrcweir return (_aInfo.uAttributes & osl_Volume_Attribute_Case_Is_Preserved); 684cdf0e10cSrcweir } 685cdf0e10cSrcweir 686cdf0e10cSrcweir friend class Directory; 687cdf0e10cSrcweir }; 688cdf0e10cSrcweir 689cdf0e10cSrcweir // ----------------------------------------------------------------------------- 690cdf0e10cSrcweir 691cdf0e10cSrcweir #define FileStatusMask_Type osl_FileStatus_Mask_Type 692cdf0e10cSrcweir #define FileStatusMask_Attributes osl_FileStatus_Mask_Attributes 693cdf0e10cSrcweir #define FileStatusMask_CreationTime osl_FileStatus_Mask_CreationTime 694cdf0e10cSrcweir #define FileStatusMask_AccessTime osl_FileStatus_Mask_AccessTime 695cdf0e10cSrcweir #define FileStatusMask_ModifyTime osl_FileStatus_Mask_ModifyTime 696cdf0e10cSrcweir #define FileStatusMask_FileSize osl_FileStatus_Mask_FileSize 697cdf0e10cSrcweir #define FileStatusMask_FileName osl_FileStatus_Mask_FileName 698cdf0e10cSrcweir #define FileStatusMask_FileURL osl_FileStatus_Mask_FileURL 699cdf0e10cSrcweir #define FileStatusMask_LinkTargetURL osl_FileStatus_Mask_LinkTargetURL 700cdf0e10cSrcweir #define FileStatusMask_All osl_FileStatus_Mask_All 701cdf0e10cSrcweir #define FileStatusMask_Validate osl_FileStatus_Mask_Validate 702cdf0e10cSrcweir 703cdf0e10cSrcweir #define Attribute_ReadOnly osl_File_Attribute_ReadOnly 704cdf0e10cSrcweir #define Attribute_Hidden osl_File_Attribute_Hidden 705cdf0e10cSrcweir #define Attribute_Executable osl_File_Attribute_Executable 706cdf0e10cSrcweir #define Attribute_GrpWrite osl_File_Attribute_GrpWrite 707cdf0e10cSrcweir #define Attribute_GrpRead osl_File_Attribute_GrpRead 708cdf0e10cSrcweir #define Attribute_GrpExe osl_File_Attribute_GrpExe 709cdf0e10cSrcweir #define Attribute_OwnWrite osl_File_Attribute_OwnWrite 710cdf0e10cSrcweir #define Attribute_OwnRead osl_File_Attribute_OwnRead 711cdf0e10cSrcweir #define Attribute_OwnExe osl_File_Attribute_OwnExe 712cdf0e10cSrcweir #define Attribute_OthWrite osl_File_Attribute_OthWrite 713cdf0e10cSrcweir #define Attribute_OthRead osl_File_Attribute_OthRead 714cdf0e10cSrcweir #define Attribute_OthExe osl_File_Attribute_OthExe 715cdf0e10cSrcweir 716cdf0e10cSrcweir class DirectoryItem; 717cdf0e10cSrcweir 718cdf0e10cSrcweir /** The FileStatus class. 719cdf0e10cSrcweir 720cdf0e10cSrcweir @see DirectoryItem::getFileStatus 721cdf0e10cSrcweir */ 722cdf0e10cSrcweir 723cdf0e10cSrcweir class FileStatus 724cdf0e10cSrcweir { 725cdf0e10cSrcweir oslFileStatus _aStatus; 726cdf0e10cSrcweir sal_uInt32 _nMask; 727cdf0e10cSrcweir 728cdf0e10cSrcweir /** Copy constructor. 729cdf0e10cSrcweir */ 730cdf0e10cSrcweir 731cdf0e10cSrcweir FileStatus( FileStatus& ); 732cdf0e10cSrcweir 733cdf0e10cSrcweir /** Assignment operator. 734cdf0e10cSrcweir */ 735cdf0e10cSrcweir 736cdf0e10cSrcweir FileStatus& operator = ( FileStatus& ); 737cdf0e10cSrcweir 738cdf0e10cSrcweir public: 739cdf0e10cSrcweir 740cdf0e10cSrcweir enum Type { 741cdf0e10cSrcweir Directory = osl_File_Type_Directory, 742cdf0e10cSrcweir Volume = osl_File_Type_Volume, 743cdf0e10cSrcweir Regular = osl_File_Type_Regular, 744cdf0e10cSrcweir Fifo = osl_File_Type_Fifo, 745cdf0e10cSrcweir Socket = osl_File_Type_Socket, 746cdf0e10cSrcweir Link = osl_File_Type_Link, 747cdf0e10cSrcweir Special = osl_File_Type_Special, 748cdf0e10cSrcweir Unknown = osl_File_Type_Unknown 749cdf0e10cSrcweir }; 750cdf0e10cSrcweir 751cdf0e10cSrcweir /** Constructor. 752cdf0e10cSrcweir 753cdf0e10cSrcweir @param nMask 75486e1cf34SPedro Giffuni Set of flaggs describing the demanded information. 755cdf0e10cSrcweir */ 756cdf0e10cSrcweir 757cdf0e10cSrcweir FileStatus( sal_uInt32 nMask ): _nMask( nMask ) 758cdf0e10cSrcweir { 759cdf0e10cSrcweir _aStatus.uStructSize = sizeof( oslFileStatus ); 760cdf0e10cSrcweir rtl_fillMemory( &_aStatus.uValidFields, sizeof( oslFileStatus ) - sizeof( sal_uInt32 ), 0 ); 761cdf0e10cSrcweir } 762cdf0e10cSrcweir 763cdf0e10cSrcweir /** Destructor. 764cdf0e10cSrcweir */ 765cdf0e10cSrcweir 766cdf0e10cSrcweir ~FileStatus() 767cdf0e10cSrcweir { 768cdf0e10cSrcweir if ( _aStatus.ustrFileURL ) 769cdf0e10cSrcweir rtl_uString_release( _aStatus.ustrFileURL ); 770cdf0e10cSrcweir if ( _aStatus.ustrLinkTargetURL ) 771cdf0e10cSrcweir rtl_uString_release( _aStatus.ustrLinkTargetURL ); 772cdf0e10cSrcweir if ( _aStatus.ustrFileName ) 773cdf0e10cSrcweir rtl_uString_release( _aStatus.ustrFileName ); 774cdf0e10cSrcweir } 775cdf0e10cSrcweir 776cdf0e10cSrcweir /** Check if specified fields are valid. 777cdf0e10cSrcweir 778cdf0e10cSrcweir @param nMask 779cdf0e10cSrcweir Set of flags for the fields to check. 780cdf0e10cSrcweir 781cdf0e10cSrcweir @return 782cdf0e10cSrcweir sal_True if all fields are valid else sal_False. 783cdf0e10cSrcweir */ 784cdf0e10cSrcweir 785cdf0e10cSrcweir inline sal_Bool isValid( sal_uInt32 nMask ) const 786cdf0e10cSrcweir { 787cdf0e10cSrcweir return ( nMask & _aStatus.uValidFields ) == nMask; 788cdf0e10cSrcweir } 789cdf0e10cSrcweir 790cdf0e10cSrcweir /** Get the file type. 791cdf0e10cSrcweir 792cdf0e10cSrcweir @return 793cdf0e10cSrcweir The file type if this information is valid, Unknown otherwise. 794cdf0e10cSrcweir */ 795cdf0e10cSrcweir inline Type getFileType() const 796cdf0e10cSrcweir { 797cdf0e10cSrcweir return (_aStatus.uValidFields & FileStatusMask_Type) ? (Type) _aStatus.eType : Unknown; 798cdf0e10cSrcweir } 799cdf0e10cSrcweir 800cdf0e10cSrcweir /** Get the file attributes. 801cdf0e10cSrcweir 802cdf0e10cSrcweir @return 803cdf0e10cSrcweir The set of attribute flags of this file. 804cdf0e10cSrcweir */ 805cdf0e10cSrcweir 806cdf0e10cSrcweir inline sal_uInt64 getAttributes() const 807cdf0e10cSrcweir { 808cdf0e10cSrcweir return _aStatus.uAttributes; 809cdf0e10cSrcweir } 810cdf0e10cSrcweir 811cdf0e10cSrcweir /** Get the creation time of this file. 812cdf0e10cSrcweir 813cdf0e10cSrcweir @return 814cdf0e10cSrcweir The creation time if this information is valid, 815cdf0e10cSrcweir an uninitialized TimeValue otherwise. 816cdf0e10cSrcweir */ 817cdf0e10cSrcweir 818cdf0e10cSrcweir inline TimeValue getCreationTime() const 819cdf0e10cSrcweir { 820cdf0e10cSrcweir return _aStatus.aCreationTime; 821cdf0e10cSrcweir } 822cdf0e10cSrcweir 823cdf0e10cSrcweir /** Get the file access time. 824cdf0e10cSrcweir 825cdf0e10cSrcweir @return 826cdf0e10cSrcweir The last access time if this information is valid, 827cdf0e10cSrcweir an uninitialized TimeValue otherwise. 828cdf0e10cSrcweir */ 829cdf0e10cSrcweir 830cdf0e10cSrcweir inline TimeValue getAccessTime() const 831cdf0e10cSrcweir { 832cdf0e10cSrcweir return _aStatus.aAccessTime; 833cdf0e10cSrcweir } 834cdf0e10cSrcweir 835cdf0e10cSrcweir /** Get the file modification time. 836cdf0e10cSrcweir 837cdf0e10cSrcweir @return 838cdf0e10cSrcweir The last modified time if this information is valid, 839cdf0e10cSrcweir an uninitialized TimeValue otherwise. 840cdf0e10cSrcweir */ 841cdf0e10cSrcweir 842cdf0e10cSrcweir inline TimeValue getModifyTime() const 843cdf0e10cSrcweir { 844cdf0e10cSrcweir return _aStatus.aModifyTime; 845cdf0e10cSrcweir } 846cdf0e10cSrcweir 847cdf0e10cSrcweir /** Get the size of the file. 848cdf0e10cSrcweir 849cdf0e10cSrcweir @return 850cdf0e10cSrcweir The actual file size if this information is valid, 0 otherwise. 851cdf0e10cSrcweir */ 852cdf0e10cSrcweir 853cdf0e10cSrcweir inline sal_uInt64 getFileSize() const 854cdf0e10cSrcweir { 855cdf0e10cSrcweir return _aStatus.uFileSize; 856cdf0e10cSrcweir } 857cdf0e10cSrcweir 858cdf0e10cSrcweir /** Get the file name. 859cdf0e10cSrcweir 860cdf0e10cSrcweir @return 861cdf0e10cSrcweir The file name if this information is valid, an empty string otherwise. 862cdf0e10cSrcweir */ 863cdf0e10cSrcweir 864cdf0e10cSrcweir inline ::rtl::OUString getFileName() const 865cdf0e10cSrcweir { 866cdf0e10cSrcweir return _aStatus.ustrFileName ? ::rtl::OUString(_aStatus.ustrFileName) : ::rtl::OUString(); 867cdf0e10cSrcweir } 868cdf0e10cSrcweir 869cdf0e10cSrcweir 870cdf0e10cSrcweir /** Get the URL of the file. 871cdf0e10cSrcweir 872cdf0e10cSrcweir @return 873cdf0e10cSrcweir The full qualified URL of the file if this information is valid, an empty string otherwise. 874cdf0e10cSrcweir */ 875cdf0e10cSrcweir 876cdf0e10cSrcweir inline ::rtl::OUString getFileURL() const 877cdf0e10cSrcweir { 878cdf0e10cSrcweir return _aStatus.ustrFileURL ? ::rtl::OUString(_aStatus.ustrFileURL) : ::rtl::OUString(); 879cdf0e10cSrcweir } 880cdf0e10cSrcweir 881cdf0e10cSrcweir /** Get the link target URL. 882cdf0e10cSrcweir 883cdf0e10cSrcweir @return 884cdf0e10cSrcweir The link target URL if this information is valid, an empty string otherwise. 885cdf0e10cSrcweir */ 886cdf0e10cSrcweir 887cdf0e10cSrcweir inline ::rtl::OUString getLinkTargetURL() const 888cdf0e10cSrcweir { 889cdf0e10cSrcweir return _aStatus.ustrLinkTargetURL ? ::rtl::OUString(_aStatus.ustrLinkTargetURL) : ::rtl::OUString(); 890cdf0e10cSrcweir } 891cdf0e10cSrcweir 892cdf0e10cSrcweir friend class DirectoryItem; 893cdf0e10cSrcweir }; 894cdf0e10cSrcweir 895cdf0e10cSrcweir 896cdf0e10cSrcweir // ----------------------------------------------------------------------------- 897cdf0e10cSrcweir /** The file class object provides access to file contents and attributes. 898cdf0e10cSrcweir 899cdf0e10cSrcweir @see Directory 900cdf0e10cSrcweir @see DirectoryItem 901cdf0e10cSrcweir */ 902cdf0e10cSrcweir 903cdf0e10cSrcweir class File: public FileBase 904cdf0e10cSrcweir { 905cdf0e10cSrcweir oslFileHandle _pData; 906cdf0e10cSrcweir ::rtl::OUString _aPath; 907cdf0e10cSrcweir 908cdf0e10cSrcweir /** Copy constructor. 909cdf0e10cSrcweir */ 910cdf0e10cSrcweir 911cdf0e10cSrcweir File( File& ); 912cdf0e10cSrcweir 913cdf0e10cSrcweir /** Assginment operator. 914cdf0e10cSrcweir */ 915cdf0e10cSrcweir 916cdf0e10cSrcweir File& operator = ( File& ); 917cdf0e10cSrcweir 918cdf0e10cSrcweir public: 919cdf0e10cSrcweir 920cdf0e10cSrcweir /** Constructor. 921cdf0e10cSrcweir 922cdf0e10cSrcweir @param ustrFileURL [in] 923cdf0e10cSrcweir The full qualified URL of the file. Relative paths are not allowed. 924cdf0e10cSrcweir */ 925cdf0e10cSrcweir 926cdf0e10cSrcweir File( const ::rtl::OUString& ustrFileURL ): _pData( 0 ), _aPath( ustrFileURL ) {} 927cdf0e10cSrcweir 928cdf0e10cSrcweir /** Destructor 929cdf0e10cSrcweir */ 930cdf0e10cSrcweir 931cdf0e10cSrcweir inline ~File() 932cdf0e10cSrcweir { 933cdf0e10cSrcweir close(); 934cdf0e10cSrcweir } 935cdf0e10cSrcweir 936cdf0e10cSrcweir #define OpenFlag_Read osl_File_OpenFlag_Read 937cdf0e10cSrcweir #define OpenFlag_Write osl_File_OpenFlag_Write 938cdf0e10cSrcweir #define OpenFlag_Create osl_File_OpenFlag_Create 939cdf0e10cSrcweir #define OpenFlag_NoLock osl_File_OpenFlag_NoLock 940cdf0e10cSrcweir 941cdf0e10cSrcweir /** Open a regular file. 942cdf0e10cSrcweir 943cdf0e10cSrcweir Open a file. Only regular files can be openend. 944cdf0e10cSrcweir 945cdf0e10cSrcweir @param uFlags [in] 946cdf0e10cSrcweir Specifies the open mode. 947cdf0e10cSrcweir 948cdf0e10cSrcweir @return 949cdf0e10cSrcweir E_None on success 950cdf0e10cSrcweir E_NOMEM not enough memory for allocating structures 951cdf0e10cSrcweir E_INVAL the format of the parameters was not valid 952cdf0e10cSrcweir E_NAMETOOLONG pathname was too long 953cdf0e10cSrcweir E_NOENT no such file or directory 954cdf0e10cSrcweir E_ACCES permission denied 955cdf0e10cSrcweir E_AGAIN a write lock could not be established 956cdf0e10cSrcweir E_NOTDIR not a directory 957cdf0e10cSrcweir E_NXIO no such device or address 958cdf0e10cSrcweir E_NODEV no such device 959cdf0e10cSrcweir E_ROFS read-only file system 960cdf0e10cSrcweir E_TXTBSY text file busy 961cdf0e10cSrcweir E_FAULT bad address 962cdf0e10cSrcweir E_LOOP too many symbolic links encountered 963cdf0e10cSrcweir E_NOSPC no space left on device 964cdf0e10cSrcweir E_ISDIR is a directory 965cdf0e10cSrcweir E_MFILE too many open files used by the process 966cdf0e10cSrcweir E_NFILE too many open files in the system 967cdf0e10cSrcweir E_DQUOT quota exceeded 968cdf0e10cSrcweir E_EXIST file exists 969cdf0e10cSrcweir E_INTR function call was interrupted 970cdf0e10cSrcweir E_IO on I/O errors 971cdf0e10cSrcweir E_MULTIHOP multihop attempted 972cdf0e10cSrcweir E_NOLINK link has been severed 973cdf0e10cSrcweir E_EOVERFLOW value too large for defined data type 974cdf0e10cSrcweir 975cdf0e10cSrcweir @see close() 976cdf0e10cSrcweir @see setPos() 977cdf0e10cSrcweir @see getPos() 978cdf0e10cSrcweir @see read() 979cdf0e10cSrcweir @see write() 980cdf0e10cSrcweir @see getSize() 981cdf0e10cSrcweir @see setSize() 982cdf0e10cSrcweir */ 983cdf0e10cSrcweir 984cdf0e10cSrcweir inline RC open( sal_uInt32 uFlags ) 985cdf0e10cSrcweir { 986cdf0e10cSrcweir return (RC) osl_openFile( _aPath.pData, &_pData, uFlags ); 987cdf0e10cSrcweir } 988cdf0e10cSrcweir 989cdf0e10cSrcweir /** Close an open file. 990cdf0e10cSrcweir 991cdf0e10cSrcweir @return 992cdf0e10cSrcweir E_None on success 993cdf0e10cSrcweir E_INVAL the format of the parameters was not valid 994cdf0e10cSrcweir E_BADF Bad file 995cdf0e10cSrcweir E_INTR function call was interrupted 996cdf0e10cSrcweir E_NOLINK link has been severed 997cdf0e10cSrcweir E_NOSPC no space left on device 998cdf0e10cSrcweir E_IO on I/O errors 999cdf0e10cSrcweir 1000cdf0e10cSrcweir @see open() 1001cdf0e10cSrcweir */ 1002cdf0e10cSrcweir 1003cdf0e10cSrcweir inline RC close() 1004cdf0e10cSrcweir { 1005cdf0e10cSrcweir oslFileError Error = osl_File_E_BADF; 1006cdf0e10cSrcweir 1007cdf0e10cSrcweir if( _pData ) 1008cdf0e10cSrcweir { 1009cdf0e10cSrcweir Error=osl_closeFile( _pData ); 1010cdf0e10cSrcweir _pData = NULL; 1011cdf0e10cSrcweir } 1012cdf0e10cSrcweir 1013cdf0e10cSrcweir return (RC) Error; 1014cdf0e10cSrcweir } 1015cdf0e10cSrcweir 1016cdf0e10cSrcweir 1017cdf0e10cSrcweir #define Pos_Absolut osl_Pos_Absolut 1018cdf0e10cSrcweir #define Pos_Current osl_Pos_Current 1019cdf0e10cSrcweir #define Pos_End osl_Pos_End 1020cdf0e10cSrcweir 1021cdf0e10cSrcweir /** Set the internal position pointer of an open file. 1022cdf0e10cSrcweir 1023cdf0e10cSrcweir @param uHow [in] 1024cdf0e10cSrcweir Distance to move the internal position pointer (from uPos). 1025cdf0e10cSrcweir 1026cdf0e10cSrcweir @param uPos [in] 1027cdf0e10cSrcweir Absolute position from the beginning of the file. 1028cdf0e10cSrcweir 1029cdf0e10cSrcweir @return 1030cdf0e10cSrcweir E_None on success 1031cdf0e10cSrcweir E_INVAL the format of the parameters was not valid 1032cdf0e10cSrcweir E_OVERFLOW the resulting file offset would be a value which cannot be represented correctly for regular files 1033cdf0e10cSrcweir 1034cdf0e10cSrcweir @see open() 1035cdf0e10cSrcweir @see getPos() 1036cdf0e10cSrcweir */ 1037cdf0e10cSrcweir 1038cdf0e10cSrcweir inline RC setPos( sal_uInt32 uHow, sal_Int64 uPos ) 1039cdf0e10cSrcweir { 1040cdf0e10cSrcweir return (RC) osl_setFilePos( _pData, uHow, uPos ); 1041cdf0e10cSrcweir } 1042cdf0e10cSrcweir 1043cdf0e10cSrcweir /** Retrieve the current position of the internal pointer of an open file. 1044cdf0e10cSrcweir 1045cdf0e10cSrcweir @param uPos [out] 1046cdf0e10cSrcweir On success receives the current position of the file pointer. 1047cdf0e10cSrcweir 1048cdf0e10cSrcweir @return 1049cdf0e10cSrcweir E_None on success 1050cdf0e10cSrcweir E_INVAL the format of the parameters was not valid 1051cdf0e10cSrcweir E_OVERFLOW the resulting file offset would be a value which cannot be represented correctly for regular files 1052cdf0e10cSrcweir 1053cdf0e10cSrcweir @see open() 1054cdf0e10cSrcweir @see setPos() 1055cdf0e10cSrcweir @see read() 1056cdf0e10cSrcweir @see write() 1057cdf0e10cSrcweir */ 1058cdf0e10cSrcweir 1059cdf0e10cSrcweir inline RC getPos( sal_uInt64& uPos ) 1060cdf0e10cSrcweir { 1061cdf0e10cSrcweir return (RC) osl_getFilePos( _pData, &uPos ); 1062cdf0e10cSrcweir } 1063cdf0e10cSrcweir 1064cdf0e10cSrcweir /** Test if the end of a file is reached. 1065cdf0e10cSrcweir 1066cdf0e10cSrcweir @param pIsEOF [out] 1067cdf0e10cSrcweir Points to a variable that receives the end-of-file status. 1068cdf0e10cSrcweir 1069cdf0e10cSrcweir @return 1070cdf0e10cSrcweir E_None on success 1071cdf0e10cSrcweir E_INVAL the format of the parameters was not valid 1072cdf0e10cSrcweir E_INTR function call was interrupted 1073cdf0e10cSrcweir E_IO on I/O errors 1074cdf0e10cSrcweir E_ISDIR is a directory 1075cdf0e10cSrcweir E_BADF bad file 1076cdf0e10cSrcweir E_FAULT bad address 1077cdf0e10cSrcweir E_AGAIN operation would block 1078cdf0e10cSrcweir E_NOLINK link has been severed 1079cdf0e10cSrcweir 1080cdf0e10cSrcweir @see open() 1081cdf0e10cSrcweir @see read() 1082cdf0e10cSrcweir @see readLine() 1083cdf0e10cSrcweir @see setPos() 1084cdf0e10cSrcweir */ 1085cdf0e10cSrcweir 1086cdf0e10cSrcweir inline RC isEndOfFile( sal_Bool *pIsEOF ) 1087cdf0e10cSrcweir { 1088cdf0e10cSrcweir return (RC) osl_isEndOfFile( _pData, pIsEOF ); 1089cdf0e10cSrcweir } 1090cdf0e10cSrcweir 1091cdf0e10cSrcweir /** Set the file size of an open file. 1092cdf0e10cSrcweir 1093cdf0e10cSrcweir Sets the file size of an open file. The file can be truncated or enlarged by the function. 1094cdf0e10cSrcweir The position of the file pointer is not affeced by this function. 1095cdf0e10cSrcweir 1096cdf0e10cSrcweir @param uSize [in] 1097cdf0e10cSrcweir New size in bytes. 1098cdf0e10cSrcweir 1099cdf0e10cSrcweir @return 1100cdf0e10cSrcweir E_None on success 1101cdf0e10cSrcweir E_INVAL the format of the parameters was not valid 1102cdf0e10cSrcweir E_OVERFLOW the resulting file offset would be a value which cannot be represented correctly for regular files 1103cdf0e10cSrcweir 1104cdf0e10cSrcweir @see open() 1105cdf0e10cSrcweir @see setPos() 1106cdf0e10cSrcweir @see getStatus() 1107cdf0e10cSrcweir */ 1108cdf0e10cSrcweir 1109cdf0e10cSrcweir inline RC setSize( sal_uInt64 uSize ) 1110cdf0e10cSrcweir { 1111cdf0e10cSrcweir return (RC) osl_setFileSize( _pData, uSize ); 1112cdf0e10cSrcweir } 1113cdf0e10cSrcweir 1114cdf0e10cSrcweir /** Get the file size of an open file. 1115cdf0e10cSrcweir 1116cdf0e10cSrcweir Gets the file size of an open file. 1117cdf0e10cSrcweir The position of the file pointer is not affeced by this function. 1118cdf0e10cSrcweir 1119cdf0e10cSrcweir @param rSize [out] 1120cdf0e10cSrcweir Current size in bytes. 1121cdf0e10cSrcweir 1122cdf0e10cSrcweir @return 1123cdf0e10cSrcweir E_None on success 1124cdf0e10cSrcweir E_INVAL the format of the parameters was not valid 1125cdf0e10cSrcweir E_OVERFLOW the resulting file offset would be a value which cannot be represented correctly for regular files 1126cdf0e10cSrcweir 1127cdf0e10cSrcweir @see open() 1128cdf0e10cSrcweir @see setPos() 1129cdf0e10cSrcweir @see getSize() 1130cdf0e10cSrcweir @see setSize() 1131cdf0e10cSrcweir @see getStatus() 1132cdf0e10cSrcweir */ 1133cdf0e10cSrcweir 1134cdf0e10cSrcweir inline RC getSize( sal_uInt64 &rSize ) 1135cdf0e10cSrcweir { 1136cdf0e10cSrcweir return (RC) osl_getFileSize( _pData, &rSize ); 1137cdf0e10cSrcweir } 1138cdf0e10cSrcweir 1139cdf0e10cSrcweir /** Read a number of bytes from a file. 1140cdf0e10cSrcweir 1141cdf0e10cSrcweir Reads a number of bytes from a file. The internal file pointer is 1142cdf0e10cSrcweir increased by the number of bytes read. 1143cdf0e10cSrcweir 1144cdf0e10cSrcweir @param pBuffer [out] 1145cdf0e10cSrcweir Points to a buffer which receives data. The buffer must be large enough 1146cdf0e10cSrcweir to hold uBytesRequested bytes. 1147cdf0e10cSrcweir 1148cdf0e10cSrcweir @param uBytesRequested [in] 1149cdf0e10cSrcweir Number of bytes which should be retrieved. 1150cdf0e10cSrcweir 1151cdf0e10cSrcweir @param rBytesRead [out] 1152cdf0e10cSrcweir On success the number of bytes which have actually been retrieved. 1153cdf0e10cSrcweir 1154cdf0e10cSrcweir @return 1155cdf0e10cSrcweir E_None on success 1156cdf0e10cSrcweir E_INVAL the format of the parameters was not valid 1157cdf0e10cSrcweir E_INTR function call was interrupted 1158cdf0e10cSrcweir E_IO on I/O errors 1159cdf0e10cSrcweir E_ISDIR is a directory 1160cdf0e10cSrcweir E_BADF bad file 1161cdf0e10cSrcweir E_FAULT bad address 1162cdf0e10cSrcweir E_AGAIN operation would block 1163cdf0e10cSrcweir E_NOLINK link has been severed 1164cdf0e10cSrcweir 1165cdf0e10cSrcweir @see open() 1166cdf0e10cSrcweir @see write() 1167cdf0e10cSrcweir @see readLine() 1168cdf0e10cSrcweir @see setPos() 1169cdf0e10cSrcweir */ 1170cdf0e10cSrcweir 1171cdf0e10cSrcweir inline RC read( void *pBuffer, sal_uInt64 uBytesRequested, sal_uInt64& rBytesRead ) 1172cdf0e10cSrcweir { 1173cdf0e10cSrcweir return (RC) osl_readFile( _pData, pBuffer, uBytesRequested, &rBytesRead ); 1174cdf0e10cSrcweir } 1175cdf0e10cSrcweir 1176cdf0e10cSrcweir /** Write a number of bytes to a file. 1177cdf0e10cSrcweir 1178cdf0e10cSrcweir Writes a number of bytes to a file. 1179cdf0e10cSrcweir The internal file pointer is increased by the number of bytes read. 1180cdf0e10cSrcweir 1181cdf0e10cSrcweir @param pBuffer [in] 1182cdf0e10cSrcweir Points to a buffer which contains the data. 1183cdf0e10cSrcweir 1184cdf0e10cSrcweir @param uBytesToWrite [in] 1185cdf0e10cSrcweir Number of bytes which should be written. 1186cdf0e10cSrcweir 1187cdf0e10cSrcweir @param rBytesWritten [out] 1188cdf0e10cSrcweir On success the number of bytes which have actually been written. 1189cdf0e10cSrcweir 1190cdf0e10cSrcweir @return 1191cdf0e10cSrcweir E_None on success 1192cdf0e10cSrcweir E_INVAL the format of the parameters was not valid 1193cdf0e10cSrcweir E_FBIG file too large 1194cdf0e10cSrcweir E_DQUOT quota exceeded 1195cdf0e10cSrcweir E_AGAIN operation would block 1196cdf0e10cSrcweir E_BADF bad file 1197cdf0e10cSrcweir E_FAULT bad address 1198cdf0e10cSrcweir E_INTR function call was interrupted 1199cdf0e10cSrcweir E_IO on I/O errosr 1200cdf0e10cSrcweir E_NOLCK no record locks available 1201cdf0e10cSrcweir E_NOLINK link has been severed 1202cdf0e10cSrcweir E_NOSPC no space left on device 1203cdf0e10cSrcweir E_NXIO no such device or address 1204cdf0e10cSrcweir 1205cdf0e10cSrcweir @see open() 1206cdf0e10cSrcweir @see read() 1207cdf0e10cSrcweir @see setPos() 1208cdf0e10cSrcweir */ 1209cdf0e10cSrcweir 1210cdf0e10cSrcweir inline RC write(const void *pBuffer, sal_uInt64 uBytesToWrite, sal_uInt64& rBytesWritten) 1211cdf0e10cSrcweir { 1212cdf0e10cSrcweir return (RC) osl_writeFile( _pData, pBuffer, uBytesToWrite, &rBytesWritten ); 1213cdf0e10cSrcweir } 1214cdf0e10cSrcweir 1215cdf0e10cSrcweir 1216cdf0e10cSrcweir /** Read a line from a file. 1217cdf0e10cSrcweir 1218cdf0e10cSrcweir Reads a line from a file. The new line delimiter is NOT returned! 1219cdf0e10cSrcweir 1220cdf0e10cSrcweir @param aSeq [in/out] 1221cdf0e10cSrcweir A reference to a ::rtl::ByteSequence that will hold the line read on success. 1222cdf0e10cSrcweir 1223cdf0e10cSrcweir @return 1224cdf0e10cSrcweir E_None on success 1225cdf0e10cSrcweir E_INVAL the format of the parameters was not valid 1226cdf0e10cSrcweir E_INTR function call was interrupted 1227cdf0e10cSrcweir E_IO on I/O errors 1228cdf0e10cSrcweir E_ISDIR is a directory 1229cdf0e10cSrcweir E_BADF bad file 1230cdf0e10cSrcweir E_FAULT bad address 1231cdf0e10cSrcweir E_AGAIN operation would block 1232cdf0e10cSrcweir E_NOLINK link has been severed 1233cdf0e10cSrcweir 1234cdf0e10cSrcweir @see open() 1235cdf0e10cSrcweir @see read() 1236cdf0e10cSrcweir @see write() 1237cdf0e10cSrcweir @see setPos() 1238cdf0e10cSrcweir */ 1239cdf0e10cSrcweir 1240cdf0e10cSrcweir inline RC readLine( ::rtl::ByteSequence& aSeq ) 1241cdf0e10cSrcweir { 1242cdf0e10cSrcweir return (RC) osl_readLine( _pData, reinterpret_cast<sal_Sequence**>(&aSeq) ); 1243cdf0e10cSrcweir } 1244cdf0e10cSrcweir 1245cdf0e10cSrcweir /** Synchronize the memory representation of a file with that on the physical medium. 1246cdf0e10cSrcweir 1247cdf0e10cSrcweir The function ensures that all modified data and attributes of the file associated with 1248cdf0e10cSrcweir the given file handle have been written to the physical medium. 1249cdf0e10cSrcweir In case the hard disk has a write cache enabled, the data may not really be on 1250cdf0e10cSrcweir permanent storage when osl_syncFile returns. 1251cdf0e10cSrcweir 1252cdf0e10cSrcweir @return 1253cdf0e10cSrcweir <dl> 1254cdf0e10cSrcweir <dt>E_None</dt> 1255cdf0e10cSrcweir <dd>On success</dd> 1256cdf0e10cSrcweir <dt>E_INVAL</dt> 1257cdf0e10cSrcweir <dd>The value of the input parameter is invalid</dd> 1258cdf0e10cSrcweir </dl> 1259cdf0e10cSrcweir <br><p><strong>In addition to these error codes others may occur as well, for instance:</strong></p><br> 1260cdf0e10cSrcweir <dt>E_BADF</dt> 1261cdf0e10cSrcweir <dd>The file is not open for writing</dd> 1262cdf0e10cSrcweir <dt>E_IO</dt> 1263cdf0e10cSrcweir <dd>An I/O error occurred</dd> 1264cdf0e10cSrcweir <dt>E_NOSPC</dt> 1265cdf0e10cSrcweir <dd>There is no enough space on the target device</dd> 1266cdf0e10cSrcweir <dt>E_ROFS</dt> 1267cdf0e10cSrcweir <dd>The file is located on a read only file system</dd> 1268cdf0e10cSrcweir <dt>E_TIMEDOUT</dt> 1269cdf0e10cSrcweir <dd>A remote connection timed out. This may happen when a file is on a remote location</dd> 1270cdf0e10cSrcweir </dl> 1271cdf0e10cSrcweir 1272cdf0e10cSrcweir @see osl_syncFile() 1273cdf0e10cSrcweir @see open() 1274cdf0e10cSrcweir @see write() 1275cdf0e10cSrcweir */ 1276cdf0e10cSrcweir inline RC sync() const 1277cdf0e10cSrcweir { 1278cdf0e10cSrcweir OSL_PRECOND(_pData, "File::sync(): File not open"); 1279cdf0e10cSrcweir return (RC)osl_syncFile(_pData); 1280cdf0e10cSrcweir } 1281cdf0e10cSrcweir 1282cdf0e10cSrcweir /** Copy a file to a new destination. 1283cdf0e10cSrcweir 1284cdf0e10cSrcweir Copies a file to a new destination. Copies only files not directories. 1285cdf0e10cSrcweir No assumptions should be made about preserving attributes or file time. 1286cdf0e10cSrcweir 1287cdf0e10cSrcweir @param ustrSourceFileURL [in] 1288cdf0e10cSrcweir Full qualified URL of the source file. 1289cdf0e10cSrcweir 1290cdf0e10cSrcweir @param ustrDestFileURL [in] 1291cdf0e10cSrcweir Full qualified URL of the destination file. A directory is NOT a valid destination file! 1292cdf0e10cSrcweir 1293cdf0e10cSrcweir @return 1294cdf0e10cSrcweir E_None on success 1295cdf0e10cSrcweir E_INVAL the format of the parameters was not valid 1296cdf0e10cSrcweir E_NOMEM not enough memory for allocating structures 1297cdf0e10cSrcweir E_ACCES permission denied 1298cdf0e10cSrcweir E_PERM operation not permitted 1299cdf0e10cSrcweir E_NAMETOOLONG file name too long 1300cdf0e10cSrcweir E_NOENT no such file or directory 1301cdf0e10cSrcweir E_ISDIR is a directory 1302cdf0e10cSrcweir E_ROFS read-only file system 1303cdf0e10cSrcweir 1304cdf0e10cSrcweir @see move() 1305cdf0e10cSrcweir @see remove() 1306cdf0e10cSrcweir */ 1307cdf0e10cSrcweir 1308cdf0e10cSrcweir inline static RC copy( const ::rtl::OUString& ustrSourceFileURL, const ::rtl::OUString& ustrDestFileURL ) 1309cdf0e10cSrcweir { 1310cdf0e10cSrcweir return (RC) osl_copyFile( ustrSourceFileURL.pData, ustrDestFileURL.pData ); 1311cdf0e10cSrcweir } 1312cdf0e10cSrcweir 1313cdf0e10cSrcweir /** Move a file or directory to a new destination or renames it. 1314cdf0e10cSrcweir 1315cdf0e10cSrcweir Moves a file or directory to a new destination or renames it. 1316cdf0e10cSrcweir File time and attributes are preserved. 1317cdf0e10cSrcweir 1318cdf0e10cSrcweir @param ustrSourceFileURL [in] 1319cdf0e10cSrcweir Full qualified URL of the source file. 1320cdf0e10cSrcweir 1321cdf0e10cSrcweir @param ustrDestFileURL [in] 1322cdf0e10cSrcweir Full qualified URL of the destination file. An existing directory is NOT a valid destination ! 1323cdf0e10cSrcweir 1324cdf0e10cSrcweir @return 1325cdf0e10cSrcweir E_None on success 1326cdf0e10cSrcweir E_INVAL the format of the parameters was not valid 1327cdf0e10cSrcweir E_NOMEM not enough memory for allocating structures 1328cdf0e10cSrcweir E_ACCES permission denied 1329cdf0e10cSrcweir E_PERM operation not permitted 1330cdf0e10cSrcweir E_NAMETOOLONG file name too long 1331cdf0e10cSrcweir E_NOENT no such file or directory 1332cdf0e10cSrcweir E_ROFS read-only file system 1333cdf0e10cSrcweir 1334cdf0e10cSrcweir @see copy() 1335cdf0e10cSrcweir */ 1336cdf0e10cSrcweir 1337cdf0e10cSrcweir inline static RC move( const ::rtl::OUString& ustrSourceFileURL, const ::rtl::OUString& ustrDestFileURL ) 1338cdf0e10cSrcweir { 1339cdf0e10cSrcweir return (RC) osl_moveFile( ustrSourceFileURL.pData, ustrDestFileURL.pData ); 1340cdf0e10cSrcweir } 1341cdf0e10cSrcweir 1342cdf0e10cSrcweir /** Remove a regular file. 1343cdf0e10cSrcweir 1344cdf0e10cSrcweir @param ustrFileURL [in] 1345cdf0e10cSrcweir Full qualified URL of the file to remove. 1346cdf0e10cSrcweir 1347cdf0e10cSrcweir @return 1348cdf0e10cSrcweir E_None on success 1349cdf0e10cSrcweir E_INVAL the format of the parameters was not valid 1350cdf0e10cSrcweir E_NOMEM not enough memory for allocating structures 1351cdf0e10cSrcweir E_ACCES permission denied 1352cdf0e10cSrcweir E_PERM operation not permitted 1353cdf0e10cSrcweir E_NAMETOOLONG file name too long 1354cdf0e10cSrcweir E_NOENT no such file or directory 1355cdf0e10cSrcweir E_ISDIR is a directory 1356cdf0e10cSrcweir E_ROFS read-only file system 1357cdf0e10cSrcweir E_FAULT bad address 1358cdf0e10cSrcweir E_LOOP too many symbolic links encountered 1359cdf0e10cSrcweir E_IO on I/O errors 1360cdf0e10cSrcweir E_BUSY device or resource busy 1361cdf0e10cSrcweir E_INTR function call was interrupted 1362cdf0e10cSrcweir E_LOOP too many symbolic links encountered 1363cdf0e10cSrcweir E_MULTIHOP multihop attempted 1364cdf0e10cSrcweir E_NOLINK link has been severed 1365cdf0e10cSrcweir E_TXTBSY text file busy 1366cdf0e10cSrcweir 1367cdf0e10cSrcweir @see open() 1368cdf0e10cSrcweir */ 1369cdf0e10cSrcweir 1370cdf0e10cSrcweir inline static RC remove( const ::rtl::OUString& ustrFileURL ) 1371cdf0e10cSrcweir { 1372cdf0e10cSrcweir return (RC) osl_removeFile( ustrFileURL.pData ); 1373cdf0e10cSrcweir } 1374cdf0e10cSrcweir 1375cdf0e10cSrcweir /** Set file attributes. 1376cdf0e10cSrcweir 1377cdf0e10cSrcweir @param ustrFileURL [in] 1378cdf0e10cSrcweir The full qualified file URL. 1379cdf0e10cSrcweir 1380cdf0e10cSrcweir @param uAttributes [in] 1381cdf0e10cSrcweir Attributes of the file to be set. 1382cdf0e10cSrcweir 1383cdf0e10cSrcweir @return 1384cdf0e10cSrcweir E_None on success 1385cdf0e10cSrcweir E_INVAL the format of the parameters was not valid 1386cdf0e10cSrcweir 1387cdf0e10cSrcweir @see FileStatus 1388cdf0e10cSrcweir */ 1389cdf0e10cSrcweir 1390cdf0e10cSrcweir inline static RC setAttributes( const ::rtl::OUString& ustrFileURL, sal_uInt64 uAttributes ) 1391cdf0e10cSrcweir { 1392cdf0e10cSrcweir return (RC) osl_setFileAttributes( ustrFileURL.pData, uAttributes ); 1393cdf0e10cSrcweir } 1394cdf0e10cSrcweir 1395cdf0e10cSrcweir /** Set the file time. 1396cdf0e10cSrcweir 1397cdf0e10cSrcweir @param ustrFileURL [in] 1398cdf0e10cSrcweir The full qualified URL of the file. 1399cdf0e10cSrcweir 1400cdf0e10cSrcweir @param rCreationTime [in] 1401cdf0e10cSrcweir Creation time of the given file. 1402cdf0e10cSrcweir 1403cdf0e10cSrcweir @param rLastAccessTime [in] 1404cdf0e10cSrcweir Time of the last access of the given file. 1405cdf0e10cSrcweir 1406cdf0e10cSrcweir @param rLastWriteTime [in] 1407cdf0e10cSrcweir Time of the last modifying of the given file. 1408cdf0e10cSrcweir 1409cdf0e10cSrcweir @return 1410cdf0e10cSrcweir E_None on success 1411cdf0e10cSrcweir E_INVAL the format of the parameters was not valid 1412cdf0e10cSrcweir E_NOENT no such file or directory not found 1413cdf0e10cSrcweir 1414cdf0e10cSrcweir @see FileStatus 1415cdf0e10cSrcweir */ 1416cdf0e10cSrcweir 1417cdf0e10cSrcweir inline static RC setTime( 1418cdf0e10cSrcweir const ::rtl::OUString& ustrFileURL, 1419cdf0e10cSrcweir const TimeValue& rCreationTime, 1420cdf0e10cSrcweir const TimeValue& rLastAccessTime, 1421cdf0e10cSrcweir const TimeValue& rLastWriteTime ) 1422cdf0e10cSrcweir { 1423cdf0e10cSrcweir return (RC) osl_setFileTime( 1424cdf0e10cSrcweir ustrFileURL.pData, 1425cdf0e10cSrcweir &rCreationTime, 1426cdf0e10cSrcweir &rLastAccessTime, 1427cdf0e10cSrcweir &rLastWriteTime ); 1428cdf0e10cSrcweir } 1429cdf0e10cSrcweir 1430cdf0e10cSrcweir friend class DirectoryItem; 1431cdf0e10cSrcweir }; 1432cdf0e10cSrcweir 1433cdf0e10cSrcweir // ----------------------------------------------------------------------------- 1434cdf0e10cSrcweir /** The directory item class object provides access to file status information. 1435cdf0e10cSrcweir 1436cdf0e10cSrcweir @see FileStatus 1437cdf0e10cSrcweir */ 1438cdf0e10cSrcweir 1439cdf0e10cSrcweir class DirectoryItem: public FileBase 1440cdf0e10cSrcweir { 1441cdf0e10cSrcweir oslDirectoryItem _pData; 1442cdf0e10cSrcweir 1443cdf0e10cSrcweir public: 1444cdf0e10cSrcweir 1445cdf0e10cSrcweir /** Constructor. 1446cdf0e10cSrcweir */ 1447cdf0e10cSrcweir 1448cdf0e10cSrcweir DirectoryItem(): _pData( NULL ) 1449cdf0e10cSrcweir { 1450cdf0e10cSrcweir } 1451cdf0e10cSrcweir 1452cdf0e10cSrcweir /** Copy constructor. 1453cdf0e10cSrcweir */ 1454cdf0e10cSrcweir 1455cdf0e10cSrcweir DirectoryItem( const DirectoryItem& rItem ): _pData( rItem._pData) 1456cdf0e10cSrcweir { 1457cdf0e10cSrcweir if( _pData ) 1458cdf0e10cSrcweir osl_acquireDirectoryItem( _pData ); 1459cdf0e10cSrcweir } 1460cdf0e10cSrcweir 1461cdf0e10cSrcweir /** Destructor. 1462cdf0e10cSrcweir */ 1463cdf0e10cSrcweir 1464cdf0e10cSrcweir ~DirectoryItem() 1465cdf0e10cSrcweir { 1466cdf0e10cSrcweir if( _pData ) 1467cdf0e10cSrcweir osl_releaseDirectoryItem( _pData ); 1468cdf0e10cSrcweir } 1469cdf0e10cSrcweir 1470cdf0e10cSrcweir /** Assignment operator. 1471cdf0e10cSrcweir */ 1472cdf0e10cSrcweir 1473cdf0e10cSrcweir DirectoryItem& operator=(const DirectoryItem& rItem ) 1474cdf0e10cSrcweir { 1475cdf0e10cSrcweir if (&rItem != this) 1476cdf0e10cSrcweir { 1477cdf0e10cSrcweir if( _pData ) 1478cdf0e10cSrcweir osl_releaseDirectoryItem( _pData ); 1479cdf0e10cSrcweir 1480cdf0e10cSrcweir _pData = rItem._pData; 1481cdf0e10cSrcweir 1482cdf0e10cSrcweir if( _pData ) 1483cdf0e10cSrcweir osl_acquireDirectoryItem( _pData ); 1484cdf0e10cSrcweir } 1485cdf0e10cSrcweir return *this; 1486cdf0e10cSrcweir } 1487cdf0e10cSrcweir 1488cdf0e10cSrcweir /** Check for validity of this instance. 1489cdf0e10cSrcweir 1490cdf0e10cSrcweir @return 1491cdf0e10cSrcweir sal_True if object is valid directory item else sal_False. 1492cdf0e10cSrcweir */ 1493cdf0e10cSrcweir 1494cdf0e10cSrcweir inline sal_Bool is() 1495cdf0e10cSrcweir { 1496cdf0e10cSrcweir return _pData != NULL; 1497cdf0e10cSrcweir } 1498cdf0e10cSrcweir 1499cdf0e10cSrcweir /** Retrieve a single directory item. 1500cdf0e10cSrcweir 1501cdf0e10cSrcweir Retrieves a single directory item. The returned handle has an initial refcount of 1. 1502cdf0e10cSrcweir Due to performance issues it is not recommended to use this function while 1503cdf0e10cSrcweir enumerating the contents of a directory. In this case use osl_getNextDirectoryItem() instead. 1504cdf0e10cSrcweir 1505cdf0e10cSrcweir @param ustrFileURL [in] 1506cdf0e10cSrcweir An absolute file URL. 1507cdf0e10cSrcweir 1508cdf0e10cSrcweir @param rItem [out] 1509cdf0e10cSrcweir On success it receives a handle which can be used for subsequent calls to osl_getFileStatus(). 1510cdf0e10cSrcweir The handle has to be released by a call to osl_releaseDirectoryItem(). 1511cdf0e10cSrcweir 1512cdf0e10cSrcweir @return 1513cdf0e10cSrcweir E_None on success 1514cdf0e10cSrcweir E_INVAL the format of the parameters was not valid 1515cdf0e10cSrcweir E_NOMEM not enough memory for allocating structures 1516cdf0e10cSrcweir E_ACCES permission denied 1517cdf0e10cSrcweir E_MFILE too many open files used by the process 1518cdf0e10cSrcweir E_NFILE too many open files in the system 1519cdf0e10cSrcweir E_NOENT no such file or directory 1520cdf0e10cSrcweir E_LOOP too many symbolic links encountered 1521cdf0e10cSrcweir E_NAMETOOLONG the file name is too long 1522cdf0e10cSrcweir E_NOTDIR a component of the path prefix of path is not a directory 1523cdf0e10cSrcweir E_IO on I/O errors 1524cdf0e10cSrcweir E_MULTIHOP multihop attempted 1525cdf0e10cSrcweir E_NOLINK link has been severed 1526cdf0e10cSrcweir E_FAULT bad address 1527cdf0e10cSrcweir E_INTR the function call was interrupted 1528cdf0e10cSrcweir 1529cdf0e10cSrcweir @see FileStatus 1530cdf0e10cSrcweir @see Directory::getNextItem() 1531cdf0e10cSrcweir */ 1532cdf0e10cSrcweir 1533cdf0e10cSrcweir static inline RC get( const ::rtl::OUString& ustrFileURL, DirectoryItem& rItem ) 1534cdf0e10cSrcweir { 1535cdf0e10cSrcweir if( rItem._pData) 1536cdf0e10cSrcweir { 1537cdf0e10cSrcweir osl_releaseDirectoryItem( rItem._pData ); 1538cdf0e10cSrcweir rItem._pData = NULL; 1539cdf0e10cSrcweir } 1540cdf0e10cSrcweir 1541cdf0e10cSrcweir return (RC) osl_getDirectoryItem( ustrFileURL.pData, &rItem._pData ); 1542cdf0e10cSrcweir } 1543cdf0e10cSrcweir 1544cdf0e10cSrcweir /** Retrieve information about a single file or directory. 1545cdf0e10cSrcweir 1546cdf0e10cSrcweir @param rStatus [in|out] 1547cdf0e10cSrcweir Reference to a class which receives the information of the file or directory 1548cdf0e10cSrcweir represented by this directory item. 1549cdf0e10cSrcweir 1550cdf0e10cSrcweir @return 1551cdf0e10cSrcweir E_None on success 1552cdf0e10cSrcweir E_NOMEM not enough memory for allocating structures 1553cdf0e10cSrcweir E_INVAL the format of the parameters was not valid 1554cdf0e10cSrcweir E_LOOP too many symbolic links encountered 1555cdf0e10cSrcweir E_ACCES permission denied 1556cdf0e10cSrcweir E_NOENT no such file or directory 1557cdf0e10cSrcweir E_NAMETOOLONG file name too long 1558cdf0e10cSrcweir E_BADF invalid oslDirectoryItem parameter 1559cdf0e10cSrcweir E_FAULT bad address 1560cdf0e10cSrcweir E_OVERFLOW value too large for defined data type 1561cdf0e10cSrcweir E_INTR function call was interrupted 1562cdf0e10cSrcweir E_NOLINK link has been severed 1563cdf0e10cSrcweir E_MULTIHOP components of path require hopping to multiple remote machines and the file system does not allow it 1564cdf0e10cSrcweir E_MFILE too many open files used by the process 1565cdf0e10cSrcweir E_NFILE too many open files in the system 1566cdf0e10cSrcweir E_NOSPC no space left on device 1567cdf0e10cSrcweir E_NXIO no such device or address 1568cdf0e10cSrcweir E_IO on I/O errors 1569cdf0e10cSrcweir E_NOSYS function not implemented 1570cdf0e10cSrcweir 1571cdf0e10cSrcweir @see get() 1572cdf0e10cSrcweir @see Directory::getNextItem() 1573cdf0e10cSrcweir @see FileStatus 1574cdf0e10cSrcweir */ 1575cdf0e10cSrcweir 1576cdf0e10cSrcweir inline RC getFileStatus( FileStatus& rStatus ) 1577cdf0e10cSrcweir { 1578cdf0e10cSrcweir return (RC) osl_getFileStatus( _pData, &rStatus._aStatus, rStatus._nMask ); 1579cdf0e10cSrcweir } 1580cdf0e10cSrcweir 1581cdf0e10cSrcweir friend class Directory; 1582cdf0e10cSrcweir }; 1583cdf0e10cSrcweir 1584cdf0e10cSrcweir //########################################### 1585cdf0e10cSrcweir 1586cdf0e10cSrcweir /** Base class for observers of directory creation notifications. 1587cdf0e10cSrcweir 1588cdf0e10cSrcweir Clients which uses the method createDirectoryPath of the class 1589cdf0e10cSrcweir Directory may want to be informed about the directories that 1590cdf0e10cSrcweir have been created. This may be accomplished by deriving from 1591cdf0e10cSrcweir this base class and overwriting the virtual function 1592cdf0e10cSrcweir DirectoryCreated. 1593cdf0e10cSrcweir 1594cdf0e10cSrcweir @see Directory::createPath 1595cdf0e10cSrcweir */ 1596cdf0e10cSrcweir class DirectoryCreationObserver 1597cdf0e10cSrcweir { 1598cdf0e10cSrcweir public: 15997659be9aSHerbert Dürr virtual ~DirectoryCreationObserver() {} 1600cdf0e10cSrcweir 1601cdf0e10cSrcweir /** This method will be called when a new directory has been 1602cdf0e10cSrcweir created and needs to be overwritten by derived classes. 1603cdf0e10cSrcweir You must not delete the directory that was just created 1604cdf0e10cSrcweir otherwise you will run into an endless loop. 1605cdf0e10cSrcweir 1606cdf0e10cSrcweir @param aDirectoryUrl 1607cdf0e10cSrcweir [in]The absolute file URL of the directory that was just created by 1608cdf0e10cSrcweir ::osl::Directory::createPath. 1609cdf0e10cSrcweir */ 1610cdf0e10cSrcweir virtual void DirectoryCreated(const rtl::OUString& aDirectoryUrl) = 0; 1611cdf0e10cSrcweir }; 1612cdf0e10cSrcweir 1613cdf0e10cSrcweir //########################################### 1614cdf0e10cSrcweir // This just an internal helper function for 1615cdf0e10cSrcweir // private use. 1616cdf0e10cSrcweir extern "C" inline void SAL_CALL onDirectoryCreated(void* pData, rtl_uString* aDirectoryUrl) 1617cdf0e10cSrcweir { 1618cdf0e10cSrcweir (static_cast<DirectoryCreationObserver*>(pData))->DirectoryCreated(aDirectoryUrl); 1619cdf0e10cSrcweir } 1620cdf0e10cSrcweir 1621cdf0e10cSrcweir /** The directory class object provides a enumeration of DirectoryItems. 1622cdf0e10cSrcweir 1623cdf0e10cSrcweir @see DirectoryItem 1624cdf0e10cSrcweir @see File 1625cdf0e10cSrcweir */ 1626cdf0e10cSrcweir 1627cdf0e10cSrcweir class Directory: public FileBase 1628cdf0e10cSrcweir { 1629cdf0e10cSrcweir oslDirectory _pData; 1630cdf0e10cSrcweir ::rtl::OUString _aPath; 1631cdf0e10cSrcweir 1632cdf0e10cSrcweir /** Copy constructor. 1633cdf0e10cSrcweir */ 1634cdf0e10cSrcweir 1635cdf0e10cSrcweir Directory( Directory& ); 1636cdf0e10cSrcweir 1637cdf0e10cSrcweir /** Assignment operator. 1638cdf0e10cSrcweir */ 1639cdf0e10cSrcweir 1640cdf0e10cSrcweir Directory& operator = ( Directory& ); 1641cdf0e10cSrcweir 1642cdf0e10cSrcweir public: 1643cdf0e10cSrcweir 1644cdf0e10cSrcweir /** Constructor. 1645cdf0e10cSrcweir 1646cdf0e10cSrcweir @param strPath [in] 1647cdf0e10cSrcweir The full qualified URL of the directory. 1648cdf0e10cSrcweir Relative URLs are not allowed. 1649cdf0e10cSrcweir */ 1650cdf0e10cSrcweir 1651cdf0e10cSrcweir Directory( const ::rtl::OUString& strPath ): _pData( 0 ), _aPath( strPath ) 1652cdf0e10cSrcweir { 1653cdf0e10cSrcweir } 1654cdf0e10cSrcweir 1655cdf0e10cSrcweir /** Destructor. 1656cdf0e10cSrcweir */ 1657cdf0e10cSrcweir 1658cdf0e10cSrcweir ~Directory() 1659cdf0e10cSrcweir { 1660cdf0e10cSrcweir close(); 1661cdf0e10cSrcweir } 1662cdf0e10cSrcweir 1663cdf0e10cSrcweir /** Open a directory for enumerating its contents. 1664cdf0e10cSrcweir 1665cdf0e10cSrcweir @return 1666cdf0e10cSrcweir E_None on success 1667cdf0e10cSrcweir E_INVAL the format of the parameters was not valid 1668cdf0e10cSrcweir E_NOENT the specified path doesn't exist 1669cdf0e10cSrcweir E_NOTDIR the specified path is not an directory 1670cdf0e10cSrcweir E_NOMEM not enough memory for allocating structures 1671cdf0e10cSrcweir E_ACCES permission denied 1672cdf0e10cSrcweir E_MFILE too many open files used by the process 1673cdf0e10cSrcweir E_NFILE too many open files in the system 1674cdf0e10cSrcweir E_NAMETOOLONG File name too long 1675cdf0e10cSrcweir E_LOOP Too many symbolic links encountered 1676cdf0e10cSrcweir 1677cdf0e10cSrcweir @see getNextItem() 1678cdf0e10cSrcweir @see close() 1679cdf0e10cSrcweir */ 1680cdf0e10cSrcweir 1681cdf0e10cSrcweir inline RC open() 1682cdf0e10cSrcweir { 1683cdf0e10cSrcweir return (RC) osl_openDirectory( _aPath.pData, &_pData ); 1684cdf0e10cSrcweir } 1685cdf0e10cSrcweir 1686cdf0e10cSrcweir /** Query if directory is open. 1687cdf0e10cSrcweir 1688cdf0e10cSrcweir Query if directory is open and so item enumeration is valid. 1689cdf0e10cSrcweir 1690cdf0e10cSrcweir @return 1691cdf0e10cSrcweir sal_True if the directory is open else sal_False. 1692cdf0e10cSrcweir 1693cdf0e10cSrcweir @see open() 1694cdf0e10cSrcweir @see close() 1695cdf0e10cSrcweir */ 1696cdf0e10cSrcweir 16977659be9aSHerbert Dürr inline sal_Bool isOpen() { return _pData != NULL; } 1698cdf0e10cSrcweir 1699cdf0e10cSrcweir /** Close a directory. 1700cdf0e10cSrcweir 1701cdf0e10cSrcweir @return 1702cdf0e10cSrcweir E_None on success 1703cdf0e10cSrcweir E_INVAL the format of the parameters was not valid 1704cdf0e10cSrcweir E_NOMEM not enough memory for allocating structures 1705cdf0e10cSrcweir E_BADF invalid oslDirectory parameter 1706cdf0e10cSrcweir E_INTR the function call was interrupted 1707cdf0e10cSrcweir 1708cdf0e10cSrcweir @see open() 1709cdf0e10cSrcweir */ 1710cdf0e10cSrcweir 1711cdf0e10cSrcweir inline RC close() 1712cdf0e10cSrcweir { 1713cdf0e10cSrcweir oslFileError Error = osl_File_E_BADF; 1714cdf0e10cSrcweir 1715cdf0e10cSrcweir if( _pData ) 1716cdf0e10cSrcweir { 1717cdf0e10cSrcweir Error=osl_closeDirectory( _pData ); 1718cdf0e10cSrcweir _pData = NULL; 1719cdf0e10cSrcweir } 1720cdf0e10cSrcweir 1721cdf0e10cSrcweir return (RC) Error; 1722cdf0e10cSrcweir } 1723cdf0e10cSrcweir 1724cdf0e10cSrcweir 1725cdf0e10cSrcweir /** Resets the directory item enumeration to the beginning. 1726cdf0e10cSrcweir 1727cdf0e10cSrcweir @return 1728cdf0e10cSrcweir E_None on success 1729cdf0e10cSrcweir E_INVAL the format of the parameters was not valid 1730cdf0e10cSrcweir E_NOENT the specified path doesn't exist 1731cdf0e10cSrcweir E_NOTDIR the specified path is not an directory 1732cdf0e10cSrcweir E_NOMEM not enough memory for allocating structures 1733cdf0e10cSrcweir E_ACCES permission denied 1734cdf0e10cSrcweir E_MFILE too many open files used by the process 1735cdf0e10cSrcweir E_NFILE too many open files in the system 1736cdf0e10cSrcweir E_NAMETOOLONG File name too long 1737cdf0e10cSrcweir E_LOOP Too many symbolic links encountered 1738cdf0e10cSrcweir 1739cdf0e10cSrcweir @see open() 1740cdf0e10cSrcweir */ 1741cdf0e10cSrcweir 1742cdf0e10cSrcweir inline RC reset() 1743cdf0e10cSrcweir { 1744cdf0e10cSrcweir close(); 1745cdf0e10cSrcweir return open(); 1746cdf0e10cSrcweir } 1747cdf0e10cSrcweir 1748cdf0e10cSrcweir /** Retrieve the next item of a previously opened directory. 1749cdf0e10cSrcweir 1750cdf0e10cSrcweir Retrieves the next item of a previously opened directory. 1751cdf0e10cSrcweir 1752cdf0e10cSrcweir @param rItem [out] 1753cdf0e10cSrcweir On success a valid DirectoryItem. 1754cdf0e10cSrcweir 1755cdf0e10cSrcweir @param nHint [in] 1756cdf0e10cSrcweir With this parameter the caller can tell the implementation that (s)he 1757cdf0e10cSrcweir is going to call this function uHint times afterwards. This enables the implementation to 1758cdf0e10cSrcweir get the information for more than one file and cache it until the next calls. 1759cdf0e10cSrcweir 1760cdf0e10cSrcweir @return 1761cdf0e10cSrcweir E_None on success 1762cdf0e10cSrcweir E_INVAL the format of the parameters was not valid 1763cdf0e10cSrcweir E_NOMEM not enough memory for allocating structures 1764cdf0e10cSrcweir E_NOENT no more entries in this directory 1765cdf0e10cSrcweir E_BADF invalid oslDirectory parameter 1766cdf0e10cSrcweir E_OVERFLOW the value too large for defined data type 1767cdf0e10cSrcweir 1768cdf0e10cSrcweir @see DirectoryItem 1769cdf0e10cSrcweir */ 1770cdf0e10cSrcweir 1771cdf0e10cSrcweir inline RC getNextItem( DirectoryItem& rItem, sal_uInt32 nHint = 0 ) 1772cdf0e10cSrcweir { 1773cdf0e10cSrcweir if( rItem._pData ) 1774cdf0e10cSrcweir { 1775cdf0e10cSrcweir osl_releaseDirectoryItem( rItem._pData ); 1776cdf0e10cSrcweir rItem._pData = 0; 1777cdf0e10cSrcweir } 1778cdf0e10cSrcweir return ( RC) osl_getNextDirectoryItem( _pData, &rItem._pData, nHint ); 1779cdf0e10cSrcweir } 1780cdf0e10cSrcweir 1781cdf0e10cSrcweir 1782cdf0e10cSrcweir /** Retrieve information about a volume. 1783cdf0e10cSrcweir 1784cdf0e10cSrcweir Retrieves information about a volume. A volume can either be a mount point, a network 1785cdf0e10cSrcweir resource or a drive depending on Operating System and File System. 1786cdf0e10cSrcweir 1787cdf0e10cSrcweir @param ustrDirectoryURL [in] 1788cdf0e10cSrcweir Full qualified URL of the volume 1789cdf0e10cSrcweir 1790cdf0e10cSrcweir @param rInfo [out] 1791cdf0e10cSrcweir On success it receives information about the volume. 1792cdf0e10cSrcweir 1793cdf0e10cSrcweir @return 1794cdf0e10cSrcweir E_None on success 1795cdf0e10cSrcweir E_NOMEM not enough memory for allocating structures 1796cdf0e10cSrcweir E_INVAL the format of the parameters was not valid 1797cdf0e10cSrcweir E_NOTDIR not a directory 1798cdf0e10cSrcweir E_NAMETOOLONG file name too long 1799cdf0e10cSrcweir E_NOENT no such file or directory 1800cdf0e10cSrcweir E_ACCES permission denied 1801cdf0e10cSrcweir E_LOOP too many symbolic links encountered 1802cdf0e10cSrcweir E_FAULT Bad address 1803cdf0e10cSrcweir E_IO on I/O errors 1804cdf0e10cSrcweir E_NOSYS function not implemented 1805cdf0e10cSrcweir E_MULTIHOP multihop attempted 1806cdf0e10cSrcweir E_NOLINK link has been severed 1807cdf0e10cSrcweir E_INTR function call was interrupted 1808cdf0e10cSrcweir 1809cdf0e10cSrcweir @see FileStatus 1810cdf0e10cSrcweir @see VolumeInfo 1811cdf0e10cSrcweir */ 1812cdf0e10cSrcweir 1813cdf0e10cSrcweir inline static RC getVolumeInfo( const ::rtl::OUString& ustrDirectoryURL, VolumeInfo& rInfo ) 1814cdf0e10cSrcweir { 1815cdf0e10cSrcweir return (RC) osl_getVolumeInformation( ustrDirectoryURL.pData, &rInfo._aInfo, rInfo._nMask ); 1816cdf0e10cSrcweir } 1817cdf0e10cSrcweir 1818cdf0e10cSrcweir /** Create a directory. 1819cdf0e10cSrcweir 1820cdf0e10cSrcweir @param ustrDirectoryURL [in] 1821cdf0e10cSrcweir Full qualified URL of the directory to create. 1822cdf0e10cSrcweir 1823cdf0e10cSrcweir @return 1824cdf0e10cSrcweir E_None on success 1825cdf0e10cSrcweir E_INVAL the format of the parameters was not valid 1826cdf0e10cSrcweir E_NOMEM not enough memory for allocating structures 1827cdf0e10cSrcweir E_EXIST file exists 1828cdf0e10cSrcweir E_ACCES permission denied 1829cdf0e10cSrcweir E_NAMETOOLONG file name too long 1830cdf0e10cSrcweir E_NOENT no such file or directory 1831cdf0e10cSrcweir E_NOTDIR not a directory 1832cdf0e10cSrcweir E_ROFS read-only file system 1833cdf0e10cSrcweir E_NOSPC no space left on device 1834cdf0e10cSrcweir E_DQUOT quota exceeded 1835cdf0e10cSrcweir E_LOOP too many symbolic links encountered 1836cdf0e10cSrcweir E_FAULT bad address 1837cdf0e10cSrcweir E_IO on I/O errors 1838cdf0e10cSrcweir E_MLINK too many links 1839cdf0e10cSrcweir E_MULTIHOP multihop attempted 1840cdf0e10cSrcweir E_NOLINK link has been severed 1841cdf0e10cSrcweir 1842cdf0e10cSrcweir @see remove() 1843cdf0e10cSrcweir */ 1844cdf0e10cSrcweir 1845cdf0e10cSrcweir inline static RC create( const ::rtl::OUString& ustrDirectoryURL ) 1846cdf0e10cSrcweir { 1847cdf0e10cSrcweir return (RC) osl_createDirectory( ustrDirectoryURL.pData ); 1848cdf0e10cSrcweir } 1849cdf0e10cSrcweir 1850cdf0e10cSrcweir /** Remove an empty directory. 1851cdf0e10cSrcweir 1852cdf0e10cSrcweir @param ustrDirectoryURL [in] 1853cdf0e10cSrcweir Full qualified URL of the directory. 1854cdf0e10cSrcweir 1855cdf0e10cSrcweir @return 1856cdf0e10cSrcweir E_None on success 1857cdf0e10cSrcweir E_INVAL the format of the parameters was not valid 1858cdf0e10cSrcweir E_NOMEM not enough memory for allocating structures 1859cdf0e10cSrcweir E_PERM operation not permitted 1860cdf0e10cSrcweir E_ACCES permission denied 1861cdf0e10cSrcweir E_NOENT no such file or directory 1862cdf0e10cSrcweir E_NOTDIR not a directory 1863cdf0e10cSrcweir E_NOTEMPTY directory not empty 1864cdf0e10cSrcweir E_FAULT bad address 1865cdf0e10cSrcweir E_NAMETOOLONG file name too long 1866cdf0e10cSrcweir E_BUSY device or resource busy 1867cdf0e10cSrcweir E_ROFS read-only file system 1868cdf0e10cSrcweir E_LOOP too many symbolic links encountered 1869cdf0e10cSrcweir E_BUSY device or resource busy 1870cdf0e10cSrcweir E_EXIST file exists 1871cdf0e10cSrcweir E_IO on I/O errors 1872cdf0e10cSrcweir E_MULTIHOP multihop attempted 1873cdf0e10cSrcweir E_NOLINK link has been severed 1874cdf0e10cSrcweir 1875cdf0e10cSrcweir @see create() 1876cdf0e10cSrcweir */ 1877cdf0e10cSrcweir 1878cdf0e10cSrcweir inline static RC remove( const ::rtl::OUString& ustrDirectoryURL ) 1879cdf0e10cSrcweir { 1880cdf0e10cSrcweir return (RC) osl_removeDirectory( ustrDirectoryURL.pData ); 1881cdf0e10cSrcweir } 1882cdf0e10cSrcweir 1883cdf0e10cSrcweir /** Create a directory path. 1884cdf0e10cSrcweir 1885cdf0e10cSrcweir The osl_createDirectoryPath function creates a specified directory path. 1886cdf0e10cSrcweir All nonexisting sub directories will be created. 1887cdf0e10cSrcweir <p><strong>PLEASE NOTE:</strong> You cannot rely on getting the error code 1888cdf0e10cSrcweir E_EXIST for existing directories. Programming against this error code is 1889cdf0e10cSrcweir in general a strong indication of a wrong usage of osl_createDirectoryPath.</p> 1890cdf0e10cSrcweir 1891cdf0e10cSrcweir @param aDirectoryUrl 1892cdf0e10cSrcweir [in] The absolute file URL of the directory path to create. 1893cdf0e10cSrcweir A relative file URL will not be accepted. 1894cdf0e10cSrcweir 1895cdf0e10cSrcweir @param aDirectoryCreationObserver 1896cdf0e10cSrcweir [in] Pointer to an instance of type DirectoryCreationObserver that will 1897cdf0e10cSrcweir be informed about the creation of a directory. The value of this 1898cdf0e10cSrcweir parameter may be NULL, in this case notifications will not be sent. 1899cdf0e10cSrcweir 1900cdf0e10cSrcweir @return 1901cdf0e10cSrcweir <dl> 1902cdf0e10cSrcweir <dt>E_None</dt> 1903cdf0e10cSrcweir <dd>On success</dd> 1904cdf0e10cSrcweir <dt>E_INVAL</dt> 1905cdf0e10cSrcweir <dd>The format of the parameters was not valid</dd> 1906cdf0e10cSrcweir <dt>E_ACCES</dt> 1907cdf0e10cSrcweir <dd>Permission denied</dd> 1908cdf0e10cSrcweir <dt>E_EXIST</dt> 1909cdf0e10cSrcweir <dd>The final node of the specified directory path already exist</dd> 1910cdf0e10cSrcweir <dt>E_NAMETOOLONG</dt> 1911cdf0e10cSrcweir <dd>The name of the specified directory path exceeds the maximum allowed length</dd> 1912cdf0e10cSrcweir <dt>E_NOTDIR</dt> 1913cdf0e10cSrcweir <dd>A component of the specified directory path already exist as file in any part of the directory path</dd> 1914cdf0e10cSrcweir <dt>E_ROFS</dt> 1915cdf0e10cSrcweir <dd>Read-only file system</dd> 1916cdf0e10cSrcweir <dt>E_NOSPC</dt> 1917cdf0e10cSrcweir <dd>No space left on device</dd> 1918cdf0e10cSrcweir <dt>E_DQUOT</dt> 1919cdf0e10cSrcweir <dd>Quota exceeded</dd> 1920cdf0e10cSrcweir <dt>E_FAULT</dt> 1921cdf0e10cSrcweir <dd>Bad address</dd> 1922cdf0e10cSrcweir <dt>E_IO</dt> 1923cdf0e10cSrcweir <dd>I/O error</dd> 1924cdf0e10cSrcweir <dt>E_LOOP</dt> 1925cdf0e10cSrcweir <dd>Too many symbolic links encountered</dd> 1926cdf0e10cSrcweir <dt>E_NOLINK</dt> 1927cdf0e10cSrcweir <dd>Link has been severed</dd> 1928cdf0e10cSrcweir <dt>E_invalidError</dt> 1929cdf0e10cSrcweir <dd>An unknown error occurred</dd> 1930cdf0e10cSrcweir </dl> 1931cdf0e10cSrcweir 1932cdf0e10cSrcweir @see DirectoryCreationObserver 1933cdf0e10cSrcweir @see create 1934cdf0e10cSrcweir */ 1935cdf0e10cSrcweir static RC createPath( 1936cdf0e10cSrcweir const ::rtl::OUString& aDirectoryUrl, 1937cdf0e10cSrcweir DirectoryCreationObserver* aDirectoryCreationObserver = NULL) 1938cdf0e10cSrcweir { 1939cdf0e10cSrcweir return (RC)osl_createDirectoryPath( 1940cdf0e10cSrcweir aDirectoryUrl.pData, 1941cdf0e10cSrcweir (aDirectoryCreationObserver) ? onDirectoryCreated : NULL, 1942cdf0e10cSrcweir aDirectoryCreationObserver); 1943cdf0e10cSrcweir } 1944cdf0e10cSrcweir }; 1945cdf0e10cSrcweir 1946cdf0e10cSrcweir } /* namespace osl */ 1947cdf0e10cSrcweir 1948cdf0e10cSrcweir #endif /* __cplusplus */ 1949cdf0e10cSrcweir #endif /* _OSL_FILE_HXX_ */ 1950cdf0e10cSrcweir 1951