2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
18 * @file FIo_FileImpl.cpp
19 * @brief This is the implementation file for %_FileImpl class.
26 #include <sys/types.h>
27 #include <sys/mount.h>
31 #include <unique_ptr.h>
34 #include <FBaseSysLog.h>
35 #include <FAppPkgPackageInfo.h>
36 #include <FIoDirectory.h>
39 #include <FSysEnvironment.h>
41 #include <FBase_StringConverter.h>
42 #include <FApp_AppInfo.h>
43 #include <FAppPkg_PackageInfoImpl.h>
44 #include <FSys_EnvironmentImpl.h>
45 #include <FBase_NativeError.h>
47 #include "FIo_FileImpl.h"
48 #include "FIo_NormalFile.h"
49 #include "FIo_DirectoryImpl.h"
50 #include "FIo_SecureFile.h"
51 #include "FIo_SecureIoUtil.h"
52 #include "FIo_IFileCore.h"
53 #include "FIo_FileUtil.h"
54 #include "FIo_FileLockImpl.h"
57 using namespace Tizen::Base;
58 using namespace Tizen::App;
59 using namespace Tizen::System;
61 namespace Tizen { namespace Io
64 static const int _MAX_PATH_LENGTH = 128;
65 static const size_t _MAX_FILE_OPENMODE_LENGTH = 3;
69 char path[_MAX_PATH_LENGTH];
71 bool appPrivilege; // false: root privilege
76 char srcPath[_MAX_PATH_LENGTH];
77 char destPath[_MAX_PATH_LENGTH];
82 char pathName[_MAX_PATH_LENGTH];
85 _FileImpl::_FileImpl(void)
91 , __pFileLockImpl(null)
95 _FileImpl::~_FileImpl(void)
98 if (__pFileLockImpl != null)
100 __pFileLockImpl->__pFileImpl = null;
104 _FileImpl::_FileImpl(const _FileImpl& fileImpl)
111 SysAssertf(false, "_FileImpl class does not support copy constructor.\n");
115 _FileImpl::operator =(const _FileImpl& fileImpl)
117 SysAssertf(false, "_FileImpl class does not support '=' operator.\n");
119 if (&fileImpl == this)
128 _FileImpl::VerifyFileOpenMode(const char* pOpenMode)
130 if (pOpenMode == null)
132 SysLog(NID_IO, "[E_INVALID_ARG] The specified openMode is null.");
136 if (strlen(pOpenMode) > _MAX_FILE_OPENMODE_LENGTH)
138 SysLog(NID_IO, "[E_INVALID_ARG] The specified openMode (%s) is invalid.", pOpenMode);
142 switch (pOpenMode[0])
156 SysLog(NID_IO, "[E_INVALID_ARG] The specified openMode (%s) is invalid.", pOpenMode);
160 switch (pOpenMode[1])
165 if (pOpenMode[2] == '\0' || pOpenMode[2] == 'b')
173 SysLog(NID_IO, "[E_INVALID_ARG] The specified openMode (%s) is invalid.", pOpenMode);
177 if (pOpenMode[2] == '\0')
181 else if (pOpenMode[2] == '+')
189 SysLog(NID_IO, "[E_INVALID_ARG] The specified openMode (%s) is invalid.", pOpenMode);
193 SysLog(NID_IO, "[E_INVALID_ARG] The specified openMode (%s) is invalid.", pOpenMode);
201 _FileImpl::Construct(const String& filePath, const String& openMode, bool createParentDirsToo, const ByteBuffer* pSecretKey)
203 SysAssertf(__pCore == null, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class\n");
204 result r = E_SUCCESS;
206 if (openMode.Contains(L'r') == true)
208 SysTryReturnResult(NID_IO, !createParentDirsToo, E_INVALID_ARG,
209 "The specified createParentDirsToo cannot be used without file creation mode.");
212 if (createParentDirsToo == true)
217 r = filePath.LastIndexOf(L'/', filePath.GetLength() - 1, position);
218 SysTryReturnResult(NID_IO, r != E_OBJ_NOT_FOUND, E_INVALID_ARG, "The specified filePath is invalid.");
219 SysTryReturnResult(NID_IO, !(position == 0), E_INVALID_ARG, "The specified filePath is invalid.");
221 r = filePath.SubString(0, position, dirPath);
222 SysTryReturn(NID_IO, !IsFailed(r), r, r, "[%s] Failed to extract dir path.", GetErrorMessage(r));
224 r = Directory::Create(dirPath, true);
227 if (r == E_FILE_ALREADY_EXIST)
233 SysPropagate(NID_IO, r);
239 unique_ptr<char[]> pOpenMode(_StringConverter::CopyToCharArrayN(openMode));
240 SysTryReturnResult(NID_IO, pOpenMode != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
242 return Construct(filePath, pOpenMode.get(), pSecretKey);
246 _FileImpl::Construct(const String& filePath, const char* pOpenMode, const ByteBuffer* pSecretKey)
248 SysAssertf(__pCore == null, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class\n");
249 result r = E_SUCCESS;
251 bool isValidOpenMode = VerifyFileOpenMode(pOpenMode);
252 SysTryReturnResult(NID_IO, isValidOpenMode == true, E_INVALID_ARG, "The specified openMode is invalid. (%s)", pOpenMode);
254 SysTryReturnResult(NID_IO, VerifyFilePathCompatibility(filePath, _AppInfo::IsOspCompat()) == true,
255 E_INVALID_ARG, " [%ls] is not compatible.", filePath.GetPointer());
257 if (!__truncate && IsFileExist(filePath))
259 r = _SecureIoUtil::CheckSecureFileHeader(filePath, pSecretKey);
260 if (r == E_END_OF_FILE)
262 r = E_IO; //for security error
264 SysTryReturn(NID_IO, !IsFailed(r), r, r, "[%s] Propagated.", GetErrorMessage(r));
267 if (pSecretKey == null)
269 unique_ptr<_NormalFile> pNormalFile(new (std::nothrow) _NormalFile());
270 SysTryReturnResult(NID_IO, pNormalFile, E_OUT_OF_MEMORY, "The memory is insufficient.");
272 r = pNormalFile->Construct(filePath, pOpenMode);
273 SysTryReturn(NID_IO, !IsFailed(r), r , r, "[%s] Propagated.", GetErrorMessage(r));
274 __pCore = pNormalFile.release();
278 unique_ptr<_SecureFile> pSecureFile(new (std::nothrow) _SecureFile(__read, __write, __truncate, __append));
279 SysTryReturnResult(NID_IO, pSecureFile, E_OUT_OF_MEMORY, "The memory is insufficient.");
281 r = pSecureFile->Construct(filePath, pOpenMode, pSecretKey);
282 SysTryReturn(NID_IO, !IsFailed(r), r , r, "[%s] Propagated.", GetErrorMessage(r));
283 __pCore = pSecureFile.release();
290 _FileImpl::ReadN(char** buffer, int& length)
292 result r = E_SUCCESS;
295 _NormalFile* pNormalFile = dynamic_cast< _NormalFile* > (__pCore);
296 if (pNormalFile != null)
298 r = pNormalFile->ReadN(buffer, length);
303 r = E_INVALID_OPERATION;
310 _FileImpl::Read(ByteBuffer& buffer)
312 SysAssertf(__pCore != null, "Not yet constructed. Construct() should be called before use.\n");
313 SysTryReturnResult(NID_IO, __read == true, E_ILLEGAL_ACCESS, "File is not opened for reading.");
314 return __pCore->Read(buffer);
318 _FileImpl::Read(void* buffer, int length)
320 SysAssertf(__pCore != null, "Not yet constructed. Construct() should be called before use.\n");
321 SysTryReturn(NID_IO, __read == true, 0, E_ILLEGAL_ACCESS, "[E_ILLEGAL_ACCESS] File is not opened for reading.");
322 return __pCore->Read(buffer, length);
326 _FileImpl::Read(String& buffer)
328 SysAssertf(__pCore != null, "Not yet constructed. Construct() should be called before use.\n");
329 SysTryReturnResult(NID_IO, __read == true, E_ILLEGAL_ACCESS, "File is not opened for reading.");
330 return __pCore->Read(buffer);
334 _FileImpl::Write(const ByteBuffer& buffer)
336 SysAssertf(__pCore != null, "Not yet constructed. Construct() should be called before use.\n");
337 SysTryReturnResult(NID_IO, __write == true, E_ILLEGAL_ACCESS, "File is not opened for writing.");
338 return __pCore->Write(buffer);
342 _FileImpl::Write(const void* buffer, int length)
344 SysAssertf(__pCore != null, "Not yet constructed. Construct() should be called before use.\n");
345 SysTryReturnResult(NID_IO, __write == true, E_ILLEGAL_ACCESS, "File is not opened for writing.");
346 return __pCore->Write(buffer, length);
350 _FileImpl::Write(const String& buffer)
352 SysAssertf(__pCore != null, "Not yet constructed. Construct() should be called before use.\n");
353 SysTryReturnResult(NID_IO, __write == true, E_ILLEGAL_ACCESS, "File is not opened for writing.");
354 return __pCore->Write(buffer);
358 _FileImpl::Flush(void)
360 SysAssertf(__pCore != null, "Not yet constructed. Construct() should be called before use.\n");
361 return __pCore->Flush();
365 _FileImpl::Tell(void) const
367 SysTryReturnResult(NID_IO, __pCore != null, -1, "File is not constructed! Construct destined file first! ");
368 return __pCore->Tell();
372 _FileImpl::Seek(FileSeekPosition position, long offset)
374 SysAssertf(__pCore != null, "Not yet constructed. Construct() should be called before use.\n");
375 return __pCore->Seek(position, offset);
379 _FileImpl::Truncate(int length)
381 SysAssertf(__pCore != null, "Not yet constructed. Construct() should be called before use.\n");
382 SysTryReturnResult(NID_IO, __write == true, E_ILLEGAL_ACCESS, "File is not opened for writing.");
383 return __pCore->Truncate(length);
387 _FileImpl::GetName(void) const
389 SysAssertf(__pCore != null, "Not yet constructed. Construct() should be called before use.\n");
390 return __pCore->GetName();
394 _FileImpl::GetFilePointer(void) const
396 SysAssertf(__pCore != null, "Not yet constructed. Construct() should be called before use.\n");
397 return __pCore->GetFilePointer();
401 _FileImpl::LockN(FileLockType lockType)
403 SysAssertf(__pCore != null, "Not yet constructed. Construct() should be called before use.\n");
404 return LockN(lockType, FILE_LOCK_MODE_BLOCKING, 0, 0);
408 _FileImpl::LockN(FileLockType lockType, int offset, int length)
410 SysAssertf(__pCore != null, "Not yet constructed. Construct() should be called before use.\n");
411 return LockN(lockType, FILE_LOCK_MODE_BLOCKING, offset, length);
415 _FileImpl::TryToLockN(FileLockType lockType)
417 SysAssertf(__pCore != null, "Not yet constructed. Construct() should be called before use.\n");
418 return LockN(lockType, FILE_LOCK_MODE_NON_BLOCKING, 0, 0);
422 _FileImpl::TryToLockN(FileLockType lockType, int offset, int length)
424 SysAssertf(__pCore != null, "Not yet constructed. Construct() should be called before use.\n");
425 return LockN(lockType, FILE_LOCK_MODE_NON_BLOCKING, offset, length);
429 _FileImpl::LockN(FileLockType lockType, _FileLockMode lockMode, int offset, int length)
431 SysAssertf(__pCore != null, "Not yet constructed. Construct() should be called before use.\n");
432 SysTryReturn(NID_IO, offset >= 0, null, E_INVALID_ARG, "[E_INVALID_ARG] The specified offset is negative.");
433 SysTryReturn(NID_IO, length >= 0, null, E_INVALID_ARG, "[E_INVALID_ARG] The specified length is negative.");
438 case FILE_LOCK_SHARED:
439 SysTryReturn(NID_IO, __read == true, null, E_INVALID_OPERATION, "[E_INVALID_OPERATION] File is not opened for reading.");
440 lock.l_type = F_RDLCK;
442 case FILE_LOCK_EXCLUSIVE:
443 SysTryReturn(NID_IO, __write == true, null, E_INVALID_OPERATION, "[E_INVALID_OPERATION] File is not opened for writing.");
444 lock.l_type = F_WRLCK;
447 SysLogException(NID_IO, E_INVALID_ARG, "[E_INVALID_ARG] The specified lock type is invalid.");
451 int fd = fileno(this->GetFilePointer());
452 int lockCommand = -1;
456 case FILE_LOCK_MODE_BLOCKING:
457 lockCommand = F_SETLKW;
459 case FILE_LOCK_MODE_NON_BLOCKING:
461 lockCommand = F_SETLK;
465 SysLogException(NID_IO, E_INVALID_ARG, "[E_INVALID_ARG] The specified lock mode is invalid.");
469 lock.l_whence = SEEK_SET;
470 lock.l_start = offset;
472 lock.l_pid = getpid();
474 ret = fcntl(fd, lockCommand, &lock);
477 result r = E_SUCCESS;
485 if (lockMode == FILE_LOCK_MODE_BLOCKING)
487 r = E_WOULD_DEADLOCK;
498 if (lockMode == FILE_LOCK_MODE_NON_BLOCKING)
510 r = _NativeError::ConvertNativeErrorToResult(errno, true);
514 SysLogException(NID_IO, r, "[%s] Aquiring file lock of type (%d) is failed, errno: %d (%s)", GetErrorMessage(r), lockType, errno, strerror(errno));
518 unique_ptr<FileLock> pFileLock(_FileLockImpl::CreateFileLockInstanceN(this, lockType, lock.l_start, lock.l_len, lock.l_pid));
519 SysTryReturn(NID_IO, pFileLock != null, null, GetLastResult(), "[%s] Propagating to caller....", GetErrorMessage(GetLastResult()));
520 __pFileLockImpl = _FileLockImpl::GetInstance(*pFileLock);
521 SetLastResult(E_SUCCESS);
522 return pFileLock.release();
526 _FileImpl::Remove(const String& filePath)
528 SysTryReturnResult(NID_IO, VerifyFilePathCompatibility(filePath, _AppInfo::IsOspCompat()) == true,
529 E_INVALID_ARG, " [%ls] is not compatible.", filePath.GetPointer());
530 return _FileUtil::Remove(filePath);
534 _FileImpl::Move(const String& oldFilePath, const String& newFilePath)
536 SysTryReturnResult(NID_IO, VerifyFilePathCompatibility(oldFilePath, _AppInfo::IsOspCompat()) == true,
537 E_INVALID_ARG, " [%ls] is not compatible.", oldFilePath.GetPointer());
539 SysTryReturnResult(NID_IO, VerifyFilePathCompatibility(newFilePath, _AppInfo::IsOspCompat()) == true,
540 E_INVALID_ARG, " [%ls] is not compatible.", newFilePath.GetPointer());
541 return _FileUtil::Move(oldFilePath, newFilePath);
545 _FileImpl::Copy(const String& srcFilePath, const String& destFilePath, bool failIfExist)
547 SysTryReturnResult(NID_IO, VerifyFilePathCompatibility(srcFilePath, _AppInfo::IsOspCompat()) == true,
548 E_INVALID_ARG, " [%ls] is not compatible.", srcFilePath.GetPointer());
550 SysTryReturnResult(NID_IO, VerifyFilePathCompatibility(destFilePath, _AppInfo::IsOspCompat()) == true,
551 E_INVALID_ARG, " [%ls] is not compatible.", destFilePath.GetPointer());
552 return _FileUtil::Copy(srcFilePath, destFilePath, failIfExist);
556 _FileImpl::GetAttributes(const String& filePath, FileAttributes& attribute)
558 SysTryReturnResult(NID_IO, VerifyFilePathCompatibility(filePath, _AppInfo::IsOspCompat()) == true,
559 E_INVALID_ARG, " [%ls] is not compatible.", filePath.GetPointer());
560 return _FileUtil::GetAttributes(filePath, attribute);
564 _FileImpl::GetFileName(const String& filePath)
566 return _FileUtil::GetFileName(filePath);
570 _FileImpl::GetFileExtension(const String& filePath)
572 return _FileUtil::GetFileExtension(filePath);
576 _FileImpl::IsFileExist(const String& filePath)
578 SysTryReturn(NID_IO, VerifyFilePathCompatibility(filePath, _AppInfo::IsOspCompat()) == true,
579 false, E_INVALID_ARG, "[E_INVALID_ARG] The specified filePath (%ls) is invalid.", filePath.GetPointer());
581 return _FileUtil::IsFileExist(filePath);
585 _FileImpl::ConvertToSecureFile(const String& plainFilePath, const String& secureFilePath,
586 const ByteBuffer& key)
588 return _FileUtil::ConvertToSecureFile(plainFilePath, secureFilePath, &key);
592 _FileImpl::IsAppPath(const String& filePath)
594 SysTryReturn(NID_IO, VerifyFilePathCompatibility(filePath, _AppInfo::IsOspCompat()) == true,
595 false, E_INVALID_ARG, "[E_INVALID_ARG] The specified filePath (%ls) is invalid.", filePath.GetPointer());
597 return _FileUtil::IsAppPath(filePath);
601 _FileImpl::IsMediaPath(const String& filePath)
603 SysTryReturn(NID_IO, VerifyFilePathCompatibility(filePath, _AppInfo::IsOspCompat()) == true,
604 false, E_INVALID_ARG, "[E_INVALID_ARG] The specified filePath (%ls) is invalid.", filePath.GetPointer());
606 return _FileUtil::IsMediaPath(filePath);
610 _FileImpl::IsSystemPath(const String& filePath)
612 SysTryReturn(NID_IO, VerifyFilePathCompatibility(filePath, _AppInfo::IsOspCompat()) == true,
613 false, E_INVALID_ARG, "[E_INVALID_ARG] The specified filePath (%ls) is invalid.", filePath.GetPointer());
615 return _FileUtil::IsSystemPath(filePath);
619 _FileImpl::VerifyFilePath(const String& filePath, _FilePathType pathType)
621 return _FileUtil::VerifyFilePath(filePath, pathType);
625 _FileImpl::VerifyFilePathCompatibility(const String& filePath, bool ospCompat)
627 if (ospCompat == true)
629 if (filePath[0] != L'/')
634 int length = filePath.GetLength();
643 _FileImpl::GetInstance(File& file)
645 return file.__pFileImpl;
649 _FileImpl::GetInstance(const File& file)
651 return file.__pFileImpl;
655 _FileImpl::ConvertVirtualToPhysicalPath(const String& virtualPath, String& physicalPath) // for 2.0 app
657 SysTryReturnResult(NID_IO, VerifyFilePathCompatibility(virtualPath, _AppInfo::IsOspCompat()) == true,
658 E_INVALID_ARG, "[E_INVALID_ARG] %ls is not compatible.", virtualPath.GetPointer());
660 const wchar_t* virtualPathPrefix[] =
667 L"/Share/AppControl",
674 L"/Storagecard/Media",
675 //L"/Storagecard/NPKI",
677 result r = E_SUCCESS;
678 int count = sizeof(virtualPathPrefix)/sizeof(wchar_t*);
681 for (i = 0; i < count; i++)
683 SysLog(NID_IO, "[V2P] i: %d, path: %ls", i, virtualPathPrefix[i]);
684 if (virtualPath.StartsWith(virtualPathPrefix[i], 0) == true)
689 SysTryReturnResult(NID_IO, i != count, E_INVALID_ARG, "The path (%ls) is not matched.",
690 virtualPath.GetPointer());
692 int prefixLen = String(virtualPathPrefix[i]).GetLength();
693 if (virtualPath.GetLength() > prefixLen)
697 r = virtualPath.GetCharAt(prefixLen, ch);
698 SysTryReturn(NID_IO, !IsFailed(r), r, r, "[%s] The path (%ls) is not matched.",
699 GetErrorMessage(r), virtualPath.GetPointer());
703 physicalPath.Clear();
704 SysLog(NID_IO, "[E_INVALID_ARG] The path (%ls) is not matched.",
705 virtualPath.GetPointer());
707 return E_INVALID_ARG;
712 virtualPath.SubString(wcslen(virtualPathPrefix[i]), subPath);
714 Tizen::App::App* pApp = Tizen::App::App::GetInstance();
715 SysTryReturnResult(NID_IO, pApp != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
716 String homePath = pApp->GetAppRootPath();
717 String ospCompatSharedPath = _EnvironmentImpl::GetOspCompatSharedPath();
722 physicalPath = homePath + L"data/Share2";
725 physicalPath = homePath + L"data/Share";
728 physicalPath = homePath + L"data";
731 physicalPath = homePath + L"res";
734 physicalPath = ospCompatSharedPath + L"share2";
737 physicalPath = ospCompatSharedPath + L"share/AppControl";
740 physicalPath = ospCompatSharedPath + L"share";
743 physicalPath = Tizen::System::Environment::GetMediaPath();
744 physicalPath.SetLength(physicalPath.GetLength() - 1);
747 physicalPath = Tizen::System::Environment::GetExternalStoragePath();
748 physicalPath.SetLength(physicalPath.GetLength() - 1);
751 SysLog(NID_IO, "[E_INVALID_ARG] The path (%ls) is not matched.",
752 virtualPath.GetPointer());
753 return E_INVALID_ARG;
756 if (subPath.IsEmpty() == false)
758 physicalPath.Append(subPath);
765 _FileImpl::ConvertPhysicalToVirtualPath(const String& physicalPath, String& virtualPath) // for 2.0 app
767 result r = E_SUCCESS;
768 const wchar_t* homeSubDir[] = {
774 const wchar_t* ospHomeSubDir[] = {
776 L"/share/AppControl",
780 int homeSubDirCount = sizeof(homeSubDir)/sizeof(wchar_t*);
781 int ospHomeSubDirCount = sizeof(ospHomeSubDir)/sizeof(wchar_t*);
785 SysLog(NID_IO, "[P2V] physicalPath: %ls", physicalPath.GetPointer());
787 Tizen::App::App* pApp = Tizen::App::App::GetInstance();
788 SysTryReturnResult(NID_IO, pApp != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
789 String homePath = pApp->GetAppRootPath();
790 homePath.SetLength(homePath.GetLength() - 1);
792 String ospCompatSharedPath = _EnvironmentImpl::GetOspCompatSharedPath();
793 ospCompatSharedPath.SetLength(ospCompatSharedPath.GetLength() - 1);
795 String mediaPath = Tizen::System::Environment::GetMediaPath();
796 mediaPath.SetLength(mediaPath.GetLength() - 1);
798 String externalPath = Tizen::System::Environment::GetExternalStoragePath();
799 externalPath.SetLength(externalPath.GetLength() - 1);
801 if (physicalPath.StartsWith(homePath, 0) == true)
803 physicalPath.SubString(homePath.GetLength(), subPath);
805 for (i = 0; i < homeSubDirCount; i++)
807 SysLog(NID_IO, "[P2V] i: %d, path: %ls", i, homeSubDir[i]);
808 if (subPath.StartsWith(homeSubDir[i], 0) == true)
813 SysTryReturnResult(NID_IO, i != homeSubDirCount, E_INVALID_ARG, "The path (%ls) is not matched.",
814 physicalPath.GetPointer());
816 baseDirLen = homePath.GetLength() + String(homeSubDir[i]).GetLength();
821 virtualPath = L"/Home/Share2";
824 virtualPath = L"/Home/Share";
827 virtualPath = L"/Home";
830 virtualPath = L"/Res";
837 else if (physicalPath.StartsWith(ospCompatSharedPath, 0) == true)
839 physicalPath.SubString(ospCompatSharedPath.GetLength(), subPath);
841 for (i = 0; i < ospHomeSubDirCount; i++)
843 SysLog(NID_IO, "[P2V] i: %d, path: %ls", i, ospHomeSubDir[i]);
844 if (subPath.StartsWith(ospHomeSubDir[i], 0) == true)
849 SysTryReturnResult(NID_IO, i != ospHomeSubDirCount, E_INVALID_ARG, "The path (%ls) is not matched.",
850 physicalPath.GetPointer());
852 baseDirLen = ospCompatSharedPath.GetLength() + String(ospHomeSubDir[i]).GetLength();
857 virtualPath = L"/Share2";
860 virtualPath = L"/Share/AppControl";
863 virtualPath = L"/Share";
869 else if (physicalPath.StartsWith(mediaPath, 0) == true)
871 SysLog(NID_IO, "[P2V] media");
872 virtualPath = L"/Media";
873 baseDirLen = mediaPath.GetLength();
875 else if (physicalPath.StartsWith(externalPath, 0) == true)
877 SysLog(NID_IO, "[P2V] external media");
878 virtualPath = L"/Storagecard/Media";
879 baseDirLen = externalPath.GetLength();
883 SysLog(NID_IO, "[E_INVALID_ARG] The path (%ls) is not matched.",
884 physicalPath.GetPointer());
886 return E_INVALID_ARG;
889 if (physicalPath.GetLength() > baseDirLen)
893 r = physicalPath.GetCharAt(baseDirLen, ch);
894 SysTryReturn(NID_IO, !IsFailed(r), r, r, "[%s] The path (%ls) is not matched.",
895 GetErrorMessage(r), physicalPath.GetPointer());
900 SysLog(NID_IO, "[E_INVALID_ARG] The path (%ls) is not matched.",
901 physicalPath.GetPointer());
903 return E_INVALID_ARG;
908 physicalPath.SubString(baseDirLen, subPath);
910 if (subPath.IsEmpty() == false)
912 virtualPath.Append(subPath);