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