genericopenlibs/openenvcore/backend/src/corebackend/posixfs.cpp
changeset 0 e4d67989cc36
child 15 18da5738c9b6
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     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::stat (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)) || (entry.iAtt & KEntryAttDir))
       
   327                 {
       
   328 			    CFileDesc::MapStat(*st, entry.iModified, entry.iAtt);
       
   329                 }
       
   330             else
       
   331                 {
       
   332                 mode_t fileMode = S_IFREG;
       
   333                 TSpecialFileType fileType;
       
   334                 fileType = _SystemSpecialFileBasedFilePath(name, err, aFs);
       
   335                 switch(fileType)
       
   336                     {
       
   337                     case EFileTypeSymLink:
       
   338                         fileMode = S_IFLNK;
       
   339                         break;
       
   340                     case EFileTypeMkFifo:
       
   341                         fileMode = S_IFIFO;
       
   342                         break;
       
   343                     case EFileTypeGeneral:
       
   344                         break;
       
   345                     default:
       
   346                         return MapError(err, anErrno);
       
   347                     }
       
   348                     CFileDesc::MapStat(*st, entry.iModified, entry.iAtt, fileMode);
       
   349                 }
       
   350 			return 0;
       
   351 			}
       
   352 		}
       
   353 	
       
   354 	if(err == KErrPathNotFound )
       
   355 		{
       
   356 	 	anErrno = ENOENT;
       
   357 	 	return -1 ;
       
   358 	 	}
       
   359 	 	
       
   360 	// KErrNotReady, here typically means filesystem not mounted or the mentioned
       
   361 	// drive doesnt exist. As KErrNotReady cannot be directly mapped to the existing
       
   362 	// posix error codes, ENOENT would be the appropriate error to return in this scenario.
       
   363 	if (err == KErrNotReady)
       
   364 		{
       
   365 		anErrno = ENOENT;
       
   366 		return -1;
       
   367 		}
       
   368 			 	
       
   369 	return MapError(err, anErrno);
       
   370 	}
       
   371 	
       
   372 int PosixFilesystem::chmod (RFs& aFs, const wchar_t* name, int perms, int& anErrno)
       
   373 	{
       
   374 	TFullName fullName;
       
   375 	TInt err = 0;
       
   376 	if(!name || *name == L'\0')
       
   377 		{
       
   378 		return MapError(KErrArgument,anErrno);
       
   379 		}
       
   380 	
       
   381 	err = GetFullFile(fullName,(const TText16*)name,aFs);	
       
   382 	TParse path;
       
   383 	path.Set(fullName,NULL,NULL);		
       
   384 	TPtrC pth = path.Path();
       
   385 	TFileName pvtPath;
       
   386 	//the below code is removed from getfullfile and explicitly added here so that creation of private path unnecessarily could be avoided while calling getfullfile()
       
   387 	aFs.PrivatePath(pvtPath);
       
   388 	if (!(pth.CompareF(pvtPath)))
       
   389 		{
       
   390 		TEntry ent; 
       
   391 		TFileName Pvt;
       
   392 		//returns in the format Drive:
       
   393 		TPtrC ptr = path.Drive();
       
   394 		Pvt.Copy(ptr);
       
   395 		Pvt.Append(pvtPath);	
       
   396 		if (aFs.Entry(Pvt , ent) == KErrNotFound) 
       
   397 			{
       
   398 	     	TInt ret = 0;
       
   399 	     	TInt driveNumber;
       
   400 			aFs.CharToDrive((TUint)ptr[0], driveNumber);
       
   401 			//creates the private path
       
   402 			ret = aFs.CreatePrivatePath(driveNumber);
       
   403       		if ((ret == KErrAlreadyExists) || (ret == KErrNone))
       
   404       			{
       
   405       			err = 0;
       
   406       			}
       
   407       		else
       
   408 	      		{
       
   409 	      		err = ret;
       
   410 	      		}
       
   411 			}
       
   412 		}	
       
   413 	if(!err) 
       
   414 		{
       
   415 		switch(perms & (S_IWUSR | S_IRUSR )) 
       
   416 			{
       
   417 			case S_IRUSR | S_IWUSR :
       
   418 			case S_IWUSR :
       
   419 				{
       
   420 				err = aFs.SetAtt(fullName , 0 , KEntryAttReadOnly) ;
       
   421 				break ;
       
   422 				}
       
   423 			case S_IRUSR :
       
   424 				{
       
   425 				err = aFs.SetAtt(fullName , KEntryAttReadOnly , 0 ) ;
       
   426 				break ;	
       
   427 				}
       
   428 			default :
       
   429 				{
       
   430 				err = KErrArgument ;
       
   431 				break ;
       
   432 				}
       
   433 			}
       
   434 		}
       
   435 
       
   436 	// KErrNotReady, here typically means filesystem not mounted or the mentioned
       
   437 	// drive doesnt exist. As KErrNotReady cannot be directly mapped to the existing
       
   438 	// posix error codes, ENOENT would be the appropriate error to return in this scenario.
       
   439 	if (err == KErrNotReady)
       
   440 		{
       
   441 		anErrno = ENOENT;
       
   442 		return -1;
       
   443 		}
       
   444 		
       
   445 	return MapError(err, anErrno);
       
   446 	}
       
   447 
       
   448 int PosixFilesystem::utime (RFs& aFs, const wchar_t* name, const struct utimbuf* filetimes, int& anErrno)
       
   449 	{
       
   450 	TFullName fullName;
       
   451 	TTime iModified(MAKE_TINT64(0x00dcddb3,0x0f2f8000)) ;   // 00:00, Jan 1st 1970
       
   452 	TInt err=GetFullFile(fullName,(const TText16*)name,aFs);
       
   453 	if (!err)
       
   454 		{
       
   455 		if (filetimes==NULL)
       
   456 			{
       
   457 			iModified.UniversalTime();
       
   458 			err=aFs.SetModified(fullName,iModified);
       
   459 			}
       
   460 		else
       
   461 			{
       
   462 			iModified+=(TTimeIntervalSeconds)filetimes->modtime;
       
   463 			err=aFs.SetModified(fullName,iModified);
       
   464 			}
       
   465 		}
       
   466 		
       
   467 	if(err == KErrPathNotFound)
       
   468 		{
       
   469 		anErrno = Find_Error(fullName , aFs) ;
       
   470 		return -1 ;
       
   471 		}	
       
   472 			
       
   473 	// KErrNotReady, here typically means filesystem not mounted or the mentioned
       
   474 	// drive doesnt exist. As KErrNotReady cannot be directly mapped to the existing
       
   475 	// posix error codes, ENOENT would be the appropriate error to return in this scenario.
       
   476 	if (err == KErrNotReady)
       
   477 		{
       
   478 		anErrno = ENOENT;
       
   479 		return -1;
       
   480 		}			
       
   481 		
       
   482 	return MapError(err, anErrno);
       
   483 	}
       
   484 
       
   485 int PosixFilesystem::reg_unlink (RFs& aFs, const wchar_t* name, int& anErrno)
       
   486 	{
       
   487 	TFullName fullName;
       
   488 	TInt err=GetFullFile(fullName, (TText16*)name, aFs);
       
   489 	if (!err)
       
   490 		{
       
   491 		TUint att=0;
       
   492 		err=aFs.Att(fullName, att);
       
   493 	    
       
   494 	    if(!err) 
       
   495 	    	{
       
   496     		if(att & KEntryAttReadOnly) 
       
   497     	 		{
       
   498     	 		err = aFs.SetAtt(fullName , 0 , KEntryAttReadOnly) ;
       
   499     	 		}
       
   500     	 		
       
   501     	 	else if (att & KEntryAttDir)
       
   502     	 		{
       
   503     	 		err = EPERM ;
       
   504     	 		}
       
   505 	    	}
       
   506         if(!err)
       
   507         	{
       
   508         	err = aFs.Delete(fullName) ;
       
   509         	}
       
   510 		}
       
   511 		
       
   512 	// KErrNotReady, here typically means filesystem not mounted or the mentioned
       
   513 	// drive doesnt exist. As KErrNotReady cannot be directly mapped to the existing
       
   514 	// posix error codes, ENOENT would be the appropriate error to return in this scenario.
       
   515 	if (err == KErrNotReady)
       
   516 		{
       
   517 		anErrno = ENOENT;
       
   518 		return -1;
       
   519 		}
       
   520 				
       
   521 	return MapError(err, anErrno);
       
   522 	}
       
   523 
       
   524 int PosixFilesystem::rename (RFs& aFs, const wchar_t* oldname, const wchar_t* newname, int& anErrno)
       
   525 	{
       
   526 	TFileName oldFullName , NewFullName;
       
   527 	TInt path ;
       
   528 	TInt err ;
       
   529 	
       
   530 	err = GetFullFile(oldFullName,(const TText16 *)oldname,aFs);
       
   531 
       
   532 	if(err != KErrNone)
       
   533 		{
       
   534 		return MapError(err , anErrno) ;
       
   535 		}
       
   536 		
       
   537 	err = GetFullFile(NewFullName ,(const TText16 *)newname , aFs) ;
       
   538 	if(err != KErrNone)
       
   539 		{
       
   540 		return MapError(err , anErrno) ;
       
   541 		}
       
   542 	
       
   543 	
       
   544 	err=aFs.Rename(oldFullName,NewFullName);
       
   545 	
       
   546 	if(err)
       
   547 		{
       
   548 		
       
   549 		if(err == KErrPermissionDenied)
       
   550 			{
       
   551 			return MapError(err , anErrno) ;
       
   552 			}
       
   553 		if(err == KErrAccessDenied)
       
   554 			{
       
   555 			return MapError(err , anErrno) ;
       
   556 			}
       
   557 		
       
   558 		 path = Get_PathCombinations(oldFullName, NewFullName  , aFs) ;
       
   559 		 
       
   560 		 switch(path)
       
   561 		 	{
       
   562 		 	case Permission_Denied:
       
   563 		 		{
       
   564 		 		anErrno = EACCES;
       
   565 		 		return -1;
       
   566 		 		}
       
   567 		 	case DirNotEmpty_DirEmpty :
       
   568 		 	case DirEmpty_DirEmpty:
       
   569 		 		{
       
   570 		 	   if(oldFullName.Find(NewFullName) == 0 ) //Renaming parent directory in parent directoy...
       
   571 			     {
       
   572 			     anErrno = EINVAL ;
       
   573 			     return -1 ;
       
   574 			     }
       
   575 	
       
   576 		    if(NewFullName.Find(oldFullName) == 0 ) //Renaming parent directory in parent directoy...
       
   577 			    {
       
   578 			    anErrno = EINVAL ;
       
   579 			     return -1 ;
       
   580 			    }	
       
   581 		 		TParse ParseObj ;
       
   582 		 		
       
   583 		 		err = GetFullPath(ParseObj, (const TText16 *)newname, NULL) ;
       
   584 		 		
       
   585 		 		if(err)
       
   586 		 			{
       
   587 		 			return MapError(err , anErrno) ;
       
   588 		 			}
       
   589 		 			
       
   590 		 		TPtrC NewPrs = ParseObj.DriveAndPath() ;
       
   591                 err= aFs.RmDir(NewPrs) ;
       
   592 		 		
       
   593 		 		if(err )  
       
   594 		 			{
       
   595 					if (err == KErrNotReady)
       
   596 						{
       
   597 						anErrno = ENOENT;
       
   598 						return -1;
       
   599 						}
       
   600 		 		  
       
   601 		 		  	return MapError(err , anErrno) ;
       
   602 		 		  	} 
       
   603 		 		break ;
       
   604 		 		} 
       
   605 		 		
       
   606 		 	
       
   607 		 	case DirEmpty_DirNotEmpty:
       
   608    		 		{
       
   609    		 		anErrno = ENOTEMPTY ;
       
   610 		 		return -1 ;
       
   611 		 		}
       
   612 		 	/*
       
   613 		 	case DirEmpty_File :
       
   614 		 		{
       
   615 		 		anErrno = ENOTDIR ;
       
   616 		 		return -1 ;
       
   617 		 		}
       
   618 		 	*/	
       
   619 		 	
       
   620 		 	case DirNotEmpty_DirNotEmpty :	 		
       
   621 		 		{
       
   622 		 		 anErrno = ENOTEMPTY ;
       
   623 		 		 return -1 ;
       
   624 		 		}
       
   625 		 	/*	
       
   626 		 	case DirNotEmpty_File :
       
   627 		 		{
       
   628 		 		anErrno = ENOTDIR ;
       
   629 		 		return -1 ;
       
   630 		 	    }
       
   631 		 	    
       
   632 		 	 case File_DirEmpty :
       
   633 		 	    {
       
   634 		 	     anErrno = EISDIR ;
       
   635 		 	     return -1 ;
       
   636 		 	    }
       
   637 		 	    
       
   638 		 	 case File_DirNotEmpty :
       
   639 		 	 	{
       
   640 		 	 	anErrno = EISDIR ;
       
   641 		 	 	return -1 ;
       
   642 		 	 	}
       
   643 		 	 	*/
       
   644 		 	 case File_File :
       
   645 		 	    {
       
   646 		 	    // Renaming a link file...?
       
   647 				TSpecialFileType fileType = _SystemSpecialFileBasedFilePath(oldname, err,Backend()->FileSession());
       
   648 				if(fileType == EFileTypeSymLink)
       
   649 				{
       
   650  		 	    	struct SLinkInfo enBuf;
       
   651  					//CFileDescBase *f = NULL;
       
   652  				    
       
   653  				    err = _ReadSysSplFile(oldname, (char*)&enBuf, sizeof(struct SLinkInfo), anErrno, aFs);
       
   654  					
       
   655 					if(err == KErrNone)
       
   656 						{
       
   657  						TFullName Link_File_Ptr;
       
   658  						err = GetFullFile(Link_File_Ptr,(const TText16*)enBuf.iParentPath,aFs);
       
   659  						
       
   660  						if( err != KErrNone)
       
   661  							{
       
   662  							if(KErrPathNotFound == err || KErrNotFound == err)
       
   663  								{
       
   664  									//If the parent file does not exist, remove the link file also
       
   665  								err = _DeleteSystemSpecialFileBasedFilePath(oldname, aFs);
       
   666  								MapError(err, anErrno);
       
   667  								}
       
   668  		 	    			}
       
   669  		 	    		
       
   670  		 	    		if(Link_File_Ptr == NewFullName)   
       
   671  		 	    			{//Renaming same files 
       
   672  		 	    			 return 0;
       
   673  		 	    			}
       
   674  		 	    		}
       
   675  		 	    		
       
   676  		 	    	}
       
   677  		 	    else if(_SystemSpecialFileBasedFilePath(newname, err,Backend()->FileSession()) == EFileTypeSymLink)
       
   678  		 	    	{
       
   679  		 	    	struct SLinkInfo enBuf;
       
   680  					//CFileDescBase *f = NULL;
       
   681  				    
       
   682  				    err = _ReadSysSplFile(newname, (char*)&enBuf, sizeof(struct SLinkInfo), anErrno, aFs);
       
   683 					
       
   684  					if(err == KErrNone)
       
   685  						{
       
   686  						TFullName Link_File_Ptr;
       
   687  						err = GetFullFile(Link_File_Ptr,(const TText16*)enBuf.iParentPath,aFs);
       
   688  						
       
   689  						if( err != KErrNone)
       
   690  							{
       
   691  							if(KErrPathNotFound == err || KErrNotFound == err)
       
   692  								{
       
   693  									//If the parent file does not exist, remove the link file also
       
   694 								err = _DeleteSystemSpecialFileBasedFilePath(oldname, aFs);
       
   695  								MapError(err, anErrno);
       
   696  								}
       
   697  		 	    			}
       
   698 		 	    		if(Link_File_Ptr == oldFullName)   
       
   699  		 	    			{//Renaming same files 
       
   700 		 	    			 return 0;
       
   701  		 	    			}
       
   702  		 	    		}
       
   703  		 	    	}	
       
   704 		 	    TEntry Ent ;
       
   705 				err = aFs.Entry(NewFullName , Ent) ;
       
   706 				
       
   707 				 if(!err) 
       
   708 				 	{
       
   709 				 	if(Ent.IsReadOnly()) 
       
   710 				 		{
       
   711 				 		aFs.SetAtt(NewFullName , 0 , KEntryAttReadOnly) ;
       
   712 				 		}
       
   713 				 	err = aFs.Delete(NewFullName);
       
   714 				 	
       
   715 				 	if(err)
       
   716 				 		{
       
   717 						if (err == KErrNotReady)
       
   718 							{
       
   719 							anErrno = ENOENT;
       
   720 							return -1;
       
   721 							}
       
   722 					 		
       
   723 				 		return MapError(err , anErrno) ;
       
   724 				 		}
       
   725 		 	 	    }
       
   726 		 	 	    
       
   727 				if (err == KErrNotReady)
       
   728 					{
       
   729 					anErrno = ENOENT;
       
   730 					return -1;
       
   731 					}		 	 	    
       
   732 					
       
   733 		 	 	    break ;
       
   734 		 	 	   } 
       
   735 		 	   
       
   736 		 	 case File_Dir :
       
   737 		 	 	{
       
   738 		 	 	anErrno = EISDIR ;
       
   739 		 	 	return -1 ;
       
   740 		 	 	}
       
   741 		 	 	
       
   742 		 	 case Dir_File :
       
   743 		 	 	{
       
   744 		 	 	anErrno = ENOTDIR ;
       
   745 		 	 	return -1 ;
       
   746 		 	    }	
       
   747 		 	 		  
       
   748 		 	  case Invalid_Path_EnotDir :
       
   749 		 	     {
       
   750 		 	     anErrno = ENOTDIR ;
       
   751 		 	     return -1 ;
       
   752 		 	     }  
       
   753 		 	  
       
   754 		 	  case Invalid_Path_Eent :
       
   755 		 	  	{
       
   756 		 	  	anErrno = ENOENT ;
       
   757 		 	  	return -1 ;
       
   758 		 	  	} 
       
   759 		 	     	
       
   760 		 	 default :
       
   761 		 	    {
       
   762 		 	     anErrno = EINVAL ;
       
   763 		 	     return -1 ;
       
   764 		 	     }
       
   765 		 	      
       
   766 			} 	 //End of switch 	    
       
   767 		 	err=aFs.Rename(oldFullName,NewFullName);  
       
   768 			if (err == KErrNotReady)
       
   769 				{
       
   770 				anErrno = ENOENT;
       
   771 				return -1;
       
   772 				}
       
   773 		 	 
       
   774 		 	 return MapError(err , anErrno) ;
       
   775 		}  //End of if 	   	
       
   776 		
       
   777 	return KErrNone;
       
   778 	}
       
   779 
       
   780 TInt PosixFilesystem::ResolvePath(TParse& aResult, const wchar_t* path, TDes* aFilename)
       
   781 	{
       
   782 	return GetFullPath(aResult, (const TText16*)path, aFilename);
       
   783 	}
       
   784 
       
   785 
       
   786 #ifdef __WINS__
       
   787 TInt PosixFilesystem::SetDefaultDir (RFs& /*aFs*/)
       
   788     {
       
   789     // NB. don't do this on WINS because the executable is
       
   790     // something like w:\epoc32\release\wins\deb\mytest.exe (or just mytest.exe or
       
   791     // even ./mytest !!)
       
   792     return KErrNone;
       
   793     }
       
   794 #else
       
   795 TInt PosixFilesystem::SetDefaultDir (RFs& aFs)
       
   796     {
       
   797     TParsePtrC parse(RProcess().FileName());
       
   798     TInt drv = TDriveUnit(parse.Drive());
       
   799     // Create the pvt path in the app launch drive
       
   800     // If this fails, fret not, it could be on the rom
       
   801     TInt err = aFs.CreatePrivatePath(drv);
       
   802     // Try to create the pvt path in the system drive also
       
   803     // Create in the default system drive
       
   804 
       
   805     aFs.CreatePrivatePath(aFs.GetSystemDrive());
       
   806 
       
   807     // Set the session path to the launch drive pvt path
       
   808     return aFs.SetSessionToPrivate(drv);
       
   809     }
       
   810 #endif
       
   811