31
|
1 |
/*
|
|
2 |
* Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
#include <fcntl.h>
|
|
20 |
#include <sys/errno.h>
|
|
21 |
#include <sys/stat.h>
|
|
22 |
#include <string.h>
|
|
23 |
#include <errno.h>
|
|
24 |
#include <utime.h>
|
|
25 |
#include "sysif.h"
|
|
26 |
#include "fdesc.h"
|
|
27 |
#include "ltime.h"
|
|
28 |
#include "lposix.h"
|
|
29 |
#include "systemspecialfilercg.h"
|
|
30 |
#include "link.h"
|
|
31 |
|
|
32 |
|
|
33 |
wchar_t * PosixFilesystem::getcwd (RFs& aFs, wchar_t* buf, unsigned long len, int& anErrno)
|
|
34 |
{
|
|
35 |
TFullName name;
|
|
36 |
TInt err = aFs.SessionPath(name);
|
|
37 |
if (!err)
|
|
38 |
{
|
|
39 |
TPtr16 pathdes((TText16 *)buf, len);
|
|
40 |
if (pathdes.MaxLength() >= (name.Length() + 1)) //+1 to allow for the null terminator
|
|
41 |
{
|
|
42 |
pathdes.Copy(name);
|
|
43 |
pathdes.ZeroTerminate();
|
|
44 |
return buf;
|
|
45 |
}
|
|
46 |
else
|
|
47 |
{
|
|
48 |
err = ERANGE; //out of range
|
|
49 |
}
|
|
50 |
}
|
|
51 |
MapError(err, anErrno);
|
|
52 |
return 0;
|
|
53 |
}
|
|
54 |
|
|
55 |
int PosixFilesystem::chdir (RFs& aFs, const wchar_t* aPath, int& anErrno)
|
|
56 |
{
|
|
57 |
TParse name;
|
|
58 |
TInt err=GetFullPath(name, (const TText16 *)aPath, NULL);
|
|
59 |
if (!err)
|
|
60 |
{
|
|
61 |
TPtrC path=name.DriveAndPath();
|
|
62 |
TUint att=0;
|
|
63 |
if (path.Length()==3) // Bug in F32 - the root directory has no attributes
|
|
64 |
att=KEntryAttDir;
|
|
65 |
else
|
|
66 |
err=aFs.Att(path, att);
|
|
67 |
|
|
68 |
if(err == KErrPathNotFound)
|
|
69 |
{
|
|
70 |
anErrno = Find_Error(aPath, aFs);
|
|
71 |
return -1;
|
|
72 |
}
|
|
73 |
|
|
74 |
// KErrNotReady, here typically means filesystem not mounted or the mentioned
|
|
75 |
// drive doesnt exist. As KErrNotReady cannot be directly mapped to the existing
|
|
76 |
// posix error codes, ENOENT would be the appropriate error to return in this scenario.
|
|
77 |
if (err == KErrNotReady)
|
|
78 |
{
|
|
79 |
anErrno = ENOENT;
|
|
80 |
return -1;
|
|
81 |
}
|
|
82 |
|
|
83 |
if (!err)
|
|
84 |
{
|
|
85 |
if (att&KEntryAttDir)
|
|
86 |
{
|
|
87 |
err = aFs.SetSessionPath(path);
|
|
88 |
//Cache the new session path in the backend
|
|
89 |
if(err == KErrNone)
|
|
90 |
{
|
|
91 |
err = Backend()->SaveSessionPath(path);
|
|
92 |
}
|
|
93 |
}
|
|
94 |
else
|
|
95 |
err=ENOTDIR;
|
|
96 |
}
|
|
97 |
}
|
|
98 |
return MapError(err,anErrno);
|
|
99 |
}
|
|
100 |
|
|
101 |
int PosixFilesystem::rmdir (RFs& aFs, const wchar_t* aPath, int& anErrno)
|
|
102 |
{
|
|
103 |
TParse name;
|
|
104 |
TInt err=GetFullPath(name, (const TText16 *)aPath, NULL);
|
|
105 |
if (!err)
|
|
106 |
{
|
|
107 |
TPtrC path=name.DriveAndPath();
|
|
108 |
TUint att=0;
|
|
109 |
if (path.Length()==3)
|
|
110 |
err=EPERM; // no, you may not remove the root directory
|
|
111 |
else
|
|
112 |
err=aFs.Att(path, att);
|
|
113 |
if(err == KErrPathNotFound)
|
|
114 |
{
|
|
115 |
TFileName val = name.DriveAndPath();
|
|
116 |
val.ZeroTerminate();
|
|
117 |
// find_error() with parameter TFileName is called only because to avoid getfullfile()
|
|
118 |
anErrno = Find_Error(val , aFs) ;
|
|
119 |
return -1 ;
|
|
120 |
}
|
|
121 |
|
|
122 |
// KErrNotReady, here typically means filesystem not mounted or the mentioned
|
|
123 |
// drive doesnt exist. As KErrNotReady cannot be directly mapped to the existing
|
|
124 |
// posix error codes, ENOENT would be the appropriate error to return in this scenario.
|
|
125 |
if (err == KErrNotReady)
|
|
126 |
{
|
|
127 |
anErrno = ENOENT;
|
|
128 |
return -1;
|
|
129 |
}
|
|
130 |
|
|
131 |
if (!err)
|
|
132 |
if (att&KEntryAttDir)
|
|
133 |
{
|
|
134 |
err=aFs.RmDir(path);
|
|
135 |
if (err==KErrInUse)
|
|
136 |
err=ENOTEMPTY; // i.e. directory not empty
|
|
137 |
}
|
|
138 |
else
|
|
139 |
err=ENOTDIR;
|
|
140 |
}
|
|
141 |
|
|
142 |
return MapError(err,anErrno);
|
|
143 |
}
|
|
144 |
|
|
145 |
int PosixFilesystem::mkdir (RFs& aFs, const wchar_t* aPath, int perms, int& anErrno)
|
|
146 |
{
|
|
147 |
TParse name;
|
|
148 |
TInt err = 0;
|
|
149 |
|
|
150 |
|
|
151 |
switch(perms & (S_IWUSR | S_IRUSR ))
|
|
152 |
{
|
|
153 |
case S_IRUSR | S_IWUSR :
|
|
154 |
case S_IWUSR :
|
|
155 |
case S_IRUSR :
|
|
156 |
{
|
|
157 |
break ;
|
|
158 |
}
|
|
159 |
default :
|
|
160 |
{
|
|
161 |
err = KErrArgument ;
|
|
162 |
return MapError(err,anErrno);
|
|
163 |
}
|
|
164 |
}
|
|
165 |
|
|
166 |
err = GetFullPath(name, (const TText16 *)aPath, NULL);
|
|
167 |
|
|
168 |
if (!err)
|
|
169 |
{
|
|
170 |
TFileName pvtPath;
|
|
171 |
TPtrC path=name.DriveAndPath();
|
|
172 |
TPtrC pth=name.Path();
|
|
173 |
aFs.PrivatePath(pvtPath);
|
|
174 |
|
|
175 |
//Checks for the presence of Private Path, if present then creates only the private path
|
|
176 |
if (pth.FindF(pvtPath) == 0)
|
|
177 |
{
|
|
178 |
TEntry ent;
|
|
179 |
TInt ret;
|
|
180 |
//returns in the format Drive:
|
|
181 |
TPtrC ptr = name.Drive();
|
|
182 |
TFileName drvandpath;
|
|
183 |
drvandpath.Copy(ptr);
|
|
184 |
drvandpath.Append(pvtPath);
|
|
185 |
ret = aFs.Entry(drvandpath , ent);
|
|
186 |
if ( ret == KErrNotFound)
|
|
187 |
{
|
|
188 |
TInt driveNumber;
|
|
189 |
aFs.CharToDrive((TUint)ptr[0], driveNumber);
|
|
190 |
//creates the private path
|
|
191 |
TInt val;
|
|
192 |
val = aFs.CreatePrivatePath(driveNumber);
|
|
193 |
if(val != KErrNone)
|
|
194 |
{
|
|
195 |
if (val == KErrNotReady)
|
|
196 |
{
|
|
197 |
anErrno = ENOENT;
|
|
198 |
return -1;
|
|
199 |
}
|
|
200 |
return MapError(val,anErrno);
|
|
201 |
}
|
|
202 |
}
|
|
203 |
else
|
|
204 |
{
|
|
205 |
if(ret == KErrNone)
|
|
206 |
{
|
|
207 |
if(pvtPath.Length() == pth.Length())
|
|
208 |
{
|
|
209 |
anErrno = EEXIST ;
|
|
210 |
return -1 ;
|
|
211 |
}
|
|
212 |
}
|
|
213 |
else
|
|
214 |
{
|
|
215 |
if (ret == KErrNotReady)
|
|
216 |
{
|
|
217 |
anErrno = ENOENT;
|
|
218 |
return -1;
|
|
219 |
}
|
|
220 |
return MapError ( ret , anErrno) ;
|
|
221 |
}
|
|
222 |
}
|
|
223 |
//Creates the directory inside the private path
|
|
224 |
if(pvtPath.Length() != pth.Length())
|
|
225 |
{
|
|
226 |
err=aFs.MkDir(path);
|
|
227 |
}
|
|
228 |
}
|
|
229 |
else
|
|
230 |
{
|
|
231 |
err=aFs.MkDir(path);
|
|
232 |
}
|
|
233 |
|
|
234 |
//if entry is a existing file and is present then symbian returns KErrAccessDenied
|
|
235 |
if(err == KErrAccessDenied)
|
|
236 |
{
|
|
237 |
TEntry Ent ;
|
|
238 |
if((aFs.Entry(path , Ent )) != KErrNone)
|
|
239 |
{
|
|
240 |
return MapError ( err , anErrno) ;
|
|
241 |
}
|
|
242 |
anErrno = EEXIST ;
|
|
243 |
return -1 ;
|
|
244 |
}
|
|
245 |
|
|
246 |
if (err == KErrPathNotFound)
|
|
247 |
{
|
|
248 |
anErrno = Find_Error(aPath , aFs) ;
|
|
249 |
return -1 ;
|
|
250 |
}
|
|
251 |
|
|
252 |
// KErrNotReady, here typically means filesystem not mounted or the mentioned
|
|
253 |
// drive doesnt exist. As KErrNotReady cannot be directly mapped to the existing
|
|
254 |
// posix error codes, ENOENT would be the appropriate error to return in this scenario.
|
|
255 |
if (err == KErrNotReady)
|
|
256 |
{
|
|
257 |
anErrno = ENOENT;
|
|
258 |
return -1;
|
|
259 |
}
|
|
260 |
|
|
261 |
if (!err)
|
|
262 |
{
|
|
263 |
if ((perms&S_IWUSR)==0)
|
|
264 |
err=aFs.SetAtt(path,KEntryAttReadOnly,0);
|
|
265 |
}
|
|
266 |
}
|
|
267 |
|
|
268 |
return MapError(err,anErrno);
|
|
269 |
}
|
|
270 |
|
|
271 |
int PosixFilesystem::statbackend (RFs& aFs, const wchar_t* name, struct stat *st, int& anErrno)
|
|
272 |
{
|
|
273 |
TFullName fullName;
|
|
274 |
TInt err=0;
|
|
275 |
if(!name || *name == L'\0') //st is NULL check can also be added
|
|
276 |
{
|
|
277 |
err = KErrArgument;
|
|
278 |
}
|
|
279 |
else
|
|
280 |
{
|
|
281 |
err = GetFullFile(fullName,(const TText16*)name,aFs);
|
|
282 |
}
|
|
283 |
|
|
284 |
if (!err)
|
|
285 |
{
|
|
286 |
TEntry entry;
|
|
287 |
if (fullName.Length()==3)
|
|
288 |
{
|
|
289 |
TDriveList aList;
|
|
290 |
aFs.DriveList(aList);
|
|
291 |
|
|
292 |
if(0 != aList[(dev_t)TDriveUnit(fullName)])
|
|
293 |
{
|
|
294 |
entry.iAtt=KEntryAttDir;
|
|
295 |
entry.iModified=TTime(0);
|
|
296 |
TDriveInfo info;
|
|
297 |
if( (err = aFs.Drive(info,(dev_t)TDriveUnit(fullName))) == KErrNone)
|
|
298 |
{
|
|
299 |
if(info.iType == EMediaNotPresent)
|
|
300 |
{
|
|
301 |
err = KErrNotReady;
|
|
302 |
}
|
|
303 |
}
|
|
304 |
}
|
|
305 |
else
|
|
306 |
{
|
|
307 |
err = KErrNotReady;
|
|
308 |
}
|
|
309 |
}
|
|
310 |
else
|
|
311 |
{
|
|
312 |
err=aFs.Entry(fullName,entry);
|
|
313 |
}
|
|
314 |
|
|
315 |
if (!err)
|
|
316 |
{
|
|
317 |
memset(st,0,sizeof(struct stat));
|
|
318 |
|
|
319 |
#if defined(SYMBIAN_OE_LARGE_FILE_SUPPORT) && !defined(SYMBIAN_OE_NO_LFS)
|
|
320 |
st->st_size = entry.FileSize();
|
|
321 |
#else
|
|
322 |
st->st_size = entry.iSize;
|
|
323 |
#endif /* SYMBIAN_OE_LARGE_FILE_SUPPORT && !SYMBIAN_OE_NO_LFS */
|
|
324 |
|
|
325 |
st->st_dev = st->st_rdev = (dev_t)TDriveUnit(fullName);
|
|
326 |
if( ( (entry.iAtt & (KEntryAttHidden | KEntryAttSystem)) != (KEntryAttHidden | KEntryAttSystem) )
|
|
327 |
|| (entry.iAtt & KEntryAttDir))
|
|
328 |
{
|
|
329 |
CFileDesc::MapStat(*st, entry.iModified, entry.iAtt);
|
|
330 |
}
|
|
331 |
else
|
|
332 |
{
|
|
333 |
mode_t fileMode = S_IFREG;
|
|
334 |
TSpecialFileType fileType;
|
|
335 |
fileType = _SystemSpecialFileBasedFilePath(name, err, aFs);
|
|
336 |
switch(fileType)
|
|
337 |
{
|
|
338 |
case EFileTypeSymLink:
|
|
339 |
fileMode = S_IFLNK;
|
|
340 |
break;
|
|
341 |
case EFileTypeMkFifo:
|
|
342 |
fileMode = S_IFIFO;
|
|
343 |
break;
|
|
344 |
case EFileTypeGeneral:
|
|
345 |
break;
|
|
346 |
default:
|
|
347 |
return MapError(err, anErrno);
|
|
348 |
}
|
|
349 |
CFileDesc::MapStat(*st, entry.iModified, entry.iAtt, fileMode);
|
|
350 |
}
|
|
351 |
return 0;
|
|
352 |
}
|
|
353 |
}
|
|
354 |
|
|
355 |
if(err == KErrPathNotFound )
|
|
356 |
{
|
|
357 |
anErrno = ENOENT;
|
|
358 |
return -1 ;
|
|
359 |
}
|
|
360 |
|
|
361 |
// KErrNotReady, here typically means filesystem not mounted or the mentioned
|
|
362 |
// drive doesnt exist. As KErrNotReady cannot be directly mapped to the existing
|
|
363 |
// posix error codes, ENOENT would be the appropriate error to return in this scenario.
|
|
364 |
if (err == KErrNotReady)
|
|
365 |
{
|
|
366 |
anErrno = ENOENT;
|
|
367 |
return -1;
|
|
368 |
}
|
|
369 |
|
|
370 |
return MapError(err, anErrno);
|
|
371 |
}
|
|
372 |
|
|
373 |
int PosixFilesystem::chmod (RFs& aFs, const wchar_t* name, int perms, int& anErrno)
|
|
374 |
{
|
|
375 |
TFullName fullName;
|
|
376 |
TInt err = 0;
|
|
377 |
if(!name || *name == L'\0')
|
|
378 |
{
|
|
379 |
return MapError(KErrArgument,anErrno);
|
|
380 |
}
|
|
381 |
|
|
382 |
err = GetFullFile(fullName,(const TText16*)name,aFs);
|
|
383 |
TParse path;
|
|
384 |
path.Set(fullName,NULL,NULL);
|
|
385 |
TPtrC pth = path.Path();
|
|
386 |
TFileName pvtPath;
|
|
387 |
//the below code is removed from getfullfile and explicitly added here so that creation of private path unnecessarily could be avoided while calling getfullfile()
|
|
388 |
aFs.PrivatePath(pvtPath);
|
|
389 |
if (!(pth.CompareF(pvtPath)))
|
|
390 |
{
|
|
391 |
TEntry ent;
|
|
392 |
TFileName Pvt;
|
|
393 |
//returns in the format Drive:
|
|
394 |
TPtrC ptr = path.Drive();
|
|
395 |
Pvt.Copy(ptr);
|
|
396 |
Pvt.Append(pvtPath);
|
|
397 |
if (aFs.Entry(Pvt , ent) == KErrNotFound)
|
|
398 |
{
|
|
399 |
TInt ret = 0;
|
|
400 |
TInt driveNumber;
|
|
401 |
aFs.CharToDrive((TUint)ptr[0], driveNumber);
|
|
402 |
//creates the private path
|
|
403 |
ret = aFs.CreatePrivatePath(driveNumber);
|
|
404 |
if ((ret == KErrAlreadyExists) || (ret == KErrNone))
|
|
405 |
{
|
|
406 |
err = 0;
|
|
407 |
}
|
|
408 |
else
|
|
409 |
{
|
|
410 |
err = ret;
|
|
411 |
}
|
|
412 |
}
|
|
413 |
}
|
|
414 |
if(!err)
|
|
415 |
{
|
|
416 |
switch(perms & (S_IWUSR | S_IRUSR ))
|
|
417 |
{
|
|
418 |
case S_IRUSR | S_IWUSR :
|
|
419 |
case S_IWUSR :
|
|
420 |
{
|
|
421 |
err = aFs.SetAtt(fullName , 0 , KEntryAttReadOnly) ;
|
|
422 |
break ;
|
|
423 |
}
|
|
424 |
case S_IRUSR :
|
|
425 |
{
|
|
426 |
err = aFs.SetAtt(fullName , KEntryAttReadOnly , 0 ) ;
|
|
427 |
break ;
|
|
428 |
}
|
|
429 |
default :
|
|
430 |
{
|
|
431 |
err = KErrArgument ;
|
|
432 |
break ;
|
|
433 |
}
|
|
434 |
}
|
|
435 |
}
|
|
436 |
|
|
437 |
// KErrNotReady, here typically means filesystem not mounted or the mentioned
|
|
438 |
// drive doesnt exist. As KErrNotReady cannot be directly mapped to the existing
|
|
439 |
// posix error codes, ENOENT would be the appropriate error to return in this scenario.
|
|
440 |
if (err == KErrNotReady)
|
|
441 |
{
|
|
442 |
anErrno = ENOENT;
|
|
443 |
return -1;
|
|
444 |
}
|
|
445 |
|
|
446 |
return MapError(err, anErrno);
|
|
447 |
}
|
|
448 |
|
|
449 |
int PosixFilesystem::utime (RFs& aFs, const wchar_t* name, const struct utimbuf* filetimes, int& anErrno)
|
|
450 |
{
|
|
451 |
TFullName fullName;
|
|
452 |
TTime iModified(MAKE_TINT64(0x00dcddb3,0x0f2f8000)) ; // 00:00, Jan 1st 1970
|
|
453 |
TInt err=GetFullFile(fullName,(const TText16*)name,aFs);
|
|
454 |
if (!err)
|
|
455 |
{
|
|
456 |
if (filetimes==NULL)
|
|
457 |
{
|
|
458 |
iModified.UniversalTime();
|
|
459 |
err=aFs.SetModified(fullName,iModified);
|
|
460 |
}
|
|
461 |
else
|
|
462 |
{
|
|
463 |
iModified+=(TTimeIntervalSeconds)filetimes->modtime;
|
|
464 |
err=aFs.SetModified(fullName,iModified);
|
|
465 |
}
|
|
466 |
}
|
|
467 |
|
|
468 |
if(err == KErrPathNotFound)
|
|
469 |
{
|
|
470 |
anErrno = Find_Error(fullName , aFs) ;
|
|
471 |
return -1 ;
|
|
472 |
}
|
|
473 |
|
|
474 |
// KErrNotReady, here typically means filesystem not mounted or the mentioned
|
|
475 |
// drive doesnt exist. As KErrNotReady cannot be directly mapped to the existing
|
|
476 |
// posix error codes, ENOENT would be the appropriate error to return in this scenario.
|
|
477 |
if (err == KErrNotReady)
|
|
478 |
{
|
|
479 |
anErrno = ENOENT;
|
|
480 |
return -1;
|
|
481 |
}
|
|
482 |
|
|
483 |
return MapError(err, anErrno);
|
|
484 |
}
|
|
485 |
|
|
486 |
int PosixFilesystem::reg_unlink (RFs& aFs, const wchar_t* name, int& anErrno)
|
|
487 |
{
|
|
488 |
TFullName fullName;
|
|
489 |
TInt err=GetFullFile(fullName, (TText16*)name, aFs);
|
|
490 |
if (!err)
|
|
491 |
{
|
|
492 |
TUint att=0;
|
|
493 |
err=aFs.Att(fullName, att);
|
|
494 |
|
|
495 |
if(!err)
|
|
496 |
{
|
|
497 |
if(att & KEntryAttReadOnly)
|
|
498 |
{
|
|
499 |
err = aFs.SetAtt(fullName , 0 , KEntryAttReadOnly) ;
|
|
500 |
}
|
|
501 |
|
|
502 |
else if (att & KEntryAttDir)
|
|
503 |
{
|
|
504 |
err = EPERM ;
|
|
505 |
}
|
|
506 |
}
|
|
507 |
if(!err)
|
|
508 |
{
|
|
509 |
err = aFs.Delete(fullName) ;
|
|
510 |
}
|
|
511 |
}
|
|
512 |
|
|
513 |
// KErrNotReady, here typically means filesystem not mounted or the mentioned
|
|
514 |
// drive doesnt exist. As KErrNotReady cannot be directly mapped to the existing
|
|
515 |
// posix error codes, ENOENT would be the appropriate error to return in this scenario.
|
|
516 |
if (err == KErrNotReady)
|
|
517 |
{
|
|
518 |
anErrno = ENOENT;
|
|
519 |
return -1;
|
|
520 |
}
|
|
521 |
|
|
522 |
return MapError(err, anErrno);
|
|
523 |
}
|
|
524 |
|
|
525 |
int PosixFilesystem::rename (RFs& aFs, const wchar_t* oldname, const wchar_t* newname, int& anErrno)
|
|
526 |
{
|
|
527 |
TFileName oldFullName , NewFullName;
|
|
528 |
TInt path ;
|
|
529 |
TInt err ;
|
|
530 |
|
|
531 |
err = GetFullFile(oldFullName,(const TText16 *)oldname,aFs);
|
|
532 |
|
|
533 |
if(err != KErrNone)
|
|
534 |
{
|
|
535 |
return MapError(err , anErrno) ;
|
|
536 |
}
|
|
537 |
|
|
538 |
err = GetFullFile(NewFullName ,(const TText16 *)newname , aFs) ;
|
|
539 |
if(err != KErrNone)
|
|
540 |
{
|
|
541 |
return MapError(err , anErrno) ;
|
|
542 |
}
|
|
543 |
|
|
544 |
|
|
545 |
err=aFs.Rename(oldFullName,NewFullName);
|
|
546 |
|
|
547 |
if(err)
|
|
548 |
{
|
|
549 |
|
|
550 |
if(err == KErrPermissionDenied)
|
|
551 |
{
|
|
552 |
return MapError(err , anErrno) ;
|
|
553 |
}
|
|
554 |
if(err == KErrAccessDenied)
|
|
555 |
{
|
|
556 |
return MapError(err , anErrno) ;
|
|
557 |
}
|
|
558 |
|
|
559 |
path = Get_PathCombinations(oldFullName, NewFullName , aFs) ;
|
|
560 |
|
|
561 |
switch(path)
|
|
562 |
{
|
|
563 |
case Permission_Denied:
|
|
564 |
{
|
|
565 |
anErrno = EACCES;
|
|
566 |
return -1;
|
|
567 |
}
|
|
568 |
case DirNotEmpty_DirEmpty :
|
|
569 |
case DirEmpty_DirEmpty:
|
|
570 |
{
|
|
571 |
if(oldFullName.Find(NewFullName) == 0 ) //Renaming parent directory in parent directoy...
|
|
572 |
{
|
|
573 |
anErrno = EINVAL ;
|
|
574 |
return -1 ;
|
|
575 |
}
|
|
576 |
|
|
577 |
if(NewFullName.Find(oldFullName) == 0 ) //Renaming parent directory in parent directoy...
|
|
578 |
{
|
|
579 |
anErrno = EINVAL ;
|
|
580 |
return -1 ;
|
|
581 |
}
|
|
582 |
TParse ParseObj ;
|
|
583 |
|
|
584 |
err = GetFullPath(ParseObj, (const TText16 *)newname, NULL) ;
|
|
585 |
|
|
586 |
if(err)
|
|
587 |
{
|
|
588 |
return MapError(err , anErrno) ;
|
|
589 |
}
|
|
590 |
|
|
591 |
TPtrC NewPrs = ParseObj.DriveAndPath() ;
|
|
592 |
err= aFs.RmDir(NewPrs) ;
|
|
593 |
|
|
594 |
if(err )
|
|
595 |
{
|
|
596 |
if (err == KErrNotReady)
|
|
597 |
{
|
|
598 |
anErrno = ENOENT;
|
|
599 |
return -1;
|
|
600 |
}
|
|
601 |
|
|
602 |
return MapError(err , anErrno) ;
|
|
603 |
}
|
|
604 |
break ;
|
|
605 |
}
|
|
606 |
|
|
607 |
|
|
608 |
case DirEmpty_DirNotEmpty:
|
|
609 |
{
|
|
610 |
anErrno = ENOTEMPTY ;
|
|
611 |
return -1 ;
|
|
612 |
}
|
|
613 |
/*
|
|
614 |
case DirEmpty_File :
|
|
615 |
{
|
|
616 |
anErrno = ENOTDIR ;
|
|
617 |
return -1 ;
|
|
618 |
}
|
|
619 |
*/
|
|
620 |
|
|
621 |
case DirNotEmpty_DirNotEmpty :
|
|
622 |
{
|
|
623 |
anErrno = ENOTEMPTY ;
|
|
624 |
return -1 ;
|
|
625 |
}
|
|
626 |
/*
|
|
627 |
case DirNotEmpty_File :
|
|
628 |
{
|
|
629 |
anErrno = ENOTDIR ;
|
|
630 |
return -1 ;
|
|
631 |
}
|
|
632 |
|
|
633 |
case File_DirEmpty :
|
|
634 |
{
|
|
635 |
anErrno = EISDIR ;
|
|
636 |
return -1 ;
|
|
637 |
}
|
|
638 |
|
|
639 |
case File_DirNotEmpty :
|
|
640 |
{
|
|
641 |
anErrno = EISDIR ;
|
|
642 |
return -1 ;
|
|
643 |
}
|
|
644 |
*/
|
|
645 |
case File_File :
|
|
646 |
{
|
|
647 |
// Renaming a link file...?
|
|
648 |
TSpecialFileType fileType = _SystemSpecialFileBasedFilePath(oldname, err,Backend()->FileSession());
|
|
649 |
if(fileType == EFileTypeSymLink)
|
|
650 |
{
|
|
651 |
struct SLinkInfo enBuf;
|
|
652 |
//CFileDescBase *f = NULL;
|
|
653 |
|
|
654 |
err = _ReadSysSplFile(oldname, (char*)&enBuf, sizeof(struct SLinkInfo), anErrno, aFs);
|
|
655 |
|
|
656 |
if(err == KErrNone)
|
|
657 |
{
|
|
658 |
TFullName Link_File_Ptr;
|
|
659 |
err = GetFullFile(Link_File_Ptr,(const TText16*)enBuf.iParentPath,aFs);
|
|
660 |
|
|
661 |
if( err != KErrNone)
|
|
662 |
{
|
|
663 |
if(KErrPathNotFound == err || KErrNotFound == err)
|
|
664 |
{
|
|
665 |
//If the parent file does not exist, remove the link file also
|
|
666 |
err = _DeleteSystemSpecialFileBasedFilePath(oldname, aFs);
|
|
667 |
MapError(err, anErrno);
|
|
668 |
}
|
|
669 |
}
|
|
670 |
|
|
671 |
if(Link_File_Ptr == NewFullName)
|
|
672 |
{//Renaming same files
|
|
673 |
return 0;
|
|
674 |
}
|
|
675 |
}
|
|
676 |
|
|
677 |
}
|
|
678 |
else if(_SystemSpecialFileBasedFilePath(newname, err,Backend()->FileSession()) == EFileTypeSymLink)
|
|
679 |
{
|
|
680 |
struct SLinkInfo enBuf;
|
|
681 |
//CFileDescBase *f = NULL;
|
|
682 |
|
|
683 |
err = _ReadSysSplFile(newname, (char*)&enBuf, sizeof(struct SLinkInfo), anErrno, aFs);
|
|
684 |
|
|
685 |
if(err == KErrNone)
|
|
686 |
{
|
|
687 |
TFullName Link_File_Ptr;
|
|
688 |
err = GetFullFile(Link_File_Ptr,(const TText16*)enBuf.iParentPath,aFs);
|
|
689 |
|
|
690 |
if( err != KErrNone)
|
|
691 |
{
|
|
692 |
if(KErrPathNotFound == err || KErrNotFound == err)
|
|
693 |
{
|
|
694 |
//If the parent file does not exist, remove the link file also
|
|
695 |
err = _DeleteSystemSpecialFileBasedFilePath(oldname, aFs);
|
|
696 |
MapError(err, anErrno);
|
|
697 |
}
|
|
698 |
}
|
|
699 |
if(Link_File_Ptr == oldFullName)
|
|
700 |
{//Renaming same files
|
|
701 |
return 0;
|
|
702 |
}
|
|
703 |
}
|
|
704 |
}
|
|
705 |
TEntry Ent ;
|
|
706 |
err = aFs.Entry(NewFullName , Ent) ;
|
|
707 |
|
|
708 |
if(!err)
|
|
709 |
{
|
|
710 |
if(Ent.IsReadOnly())
|
|
711 |
{
|
|
712 |
aFs.SetAtt(NewFullName , 0 , KEntryAttReadOnly) ;
|
|
713 |
}
|
|
714 |
err = aFs.Delete(NewFullName);
|
|
715 |
|
|
716 |
if(err)
|
|
717 |
{
|
|
718 |
if (err == KErrNotReady)
|
|
719 |
{
|
|
720 |
anErrno = ENOENT;
|
|
721 |
return -1;
|
|
722 |
}
|
|
723 |
|
|
724 |
return MapError(err , anErrno) ;
|
|
725 |
}
|
|
726 |
}
|
|
727 |
|
|
728 |
if (err == KErrNotReady)
|
|
729 |
{
|
|
730 |
anErrno = ENOENT;
|
|
731 |
return -1;
|
|
732 |
}
|
|
733 |
|
|
734 |
break ;
|
|
735 |
}
|
|
736 |
|
|
737 |
case File_Dir :
|
|
738 |
{
|
|
739 |
anErrno = EISDIR ;
|
|
740 |
return -1 ;
|
|
741 |
}
|
|
742 |
|
|
743 |
case Dir_File :
|
|
744 |
{
|
|
745 |
anErrno = ENOTDIR ;
|
|
746 |
return -1 ;
|
|
747 |
}
|
|
748 |
|
|
749 |
case Invalid_Path_EnotDir :
|
|
750 |
{
|
|
751 |
anErrno = ENOTDIR ;
|
|
752 |
return -1 ;
|
|
753 |
}
|
|
754 |
|
|
755 |
case Invalid_Path_Eent :
|
|
756 |
{
|
|
757 |
anErrno = ENOENT ;
|
|
758 |
return -1 ;
|
|
759 |
}
|
|
760 |
|
|
761 |
default :
|
|
762 |
{
|
|
763 |
anErrno = EINVAL ;
|
|
764 |
return -1 ;
|
|
765 |
}
|
|
766 |
|
|
767 |
} //End of switch
|
|
768 |
err=aFs.Rename(oldFullName,NewFullName);
|
|
769 |
if (err == KErrNotReady)
|
|
770 |
{
|
|
771 |
anErrno = ENOENT;
|
|
772 |
return -1;
|
|
773 |
}
|
|
774 |
|
|
775 |
return MapError(err , anErrno) ;
|
|
776 |
} //End of if
|
|
777 |
|
|
778 |
return KErrNone;
|
|
779 |
}
|
|
780 |
|
|
781 |
TInt PosixFilesystem::ResolvePath(TParse& aResult, const wchar_t* path, TDes* aFilename)
|
|
782 |
{
|
|
783 |
return GetFullPath(aResult, (const TText16*)path, aFilename);
|
|
784 |
}
|
|
785 |
|
|
786 |
|
|
787 |
#ifdef __WINS__
|
|
788 |
TInt PosixFilesystem::SetDefaultDir (RFs& /*aFs*/)
|
|
789 |
{
|
|
790 |
// NB. don't do this on WINS because the executable is
|
|
791 |
// something like w:\epoc32\release\wins\deb\mytest.exe (or just mytest.exe or
|
|
792 |
// even ./mytest !!)
|
|
793 |
return KErrNone;
|
|
794 |
}
|
|
795 |
#else
|
|
796 |
TInt PosixFilesystem::SetDefaultDir (RFs& aFs)
|
|
797 |
{
|
|
798 |
TParsePtrC parse(RProcess().FileName());
|
|
799 |
TInt drv = TDriveUnit(parse.Drive());
|
|
800 |
// Create the pvt path in the app launch drive
|
|
801 |
// If this fails, fret not, it could be on the rom
|
|
802 |
TInt err = aFs.CreatePrivatePath(drv);
|
|
803 |
// Try to create the pvt path in the system drive also
|
|
804 |
// Create in the default system drive
|
|
805 |
|
|
806 |
aFs.CreatePrivatePath(aFs.GetSystemDrive());
|
|
807 |
|
|
808 |
// Set the session path to the launch drive pvt path
|
|
809 |
return aFs.SetSessionToPrivate(drv);
|
|
810 |
}
|
|
811 |
#endif
|
|
812 |
|