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;
66 static const char _INTERNAL_MOUNT_FLAG[] = "/tmp/osp-compat/mount/internal";
67 static const char _EXTERNAL_MOUNT_FLAG[] = "/tmp/osp-compat/mount/external";
71 char path[_MAX_PATH_LENGTH];
73 bool appPrivilege; // false: root privilege
78 char srcPath[_MAX_PATH_LENGTH];
79 char destPath[_MAX_PATH_LENGTH];
84 char pathName[_MAX_PATH_LENGTH];
87 _FileImpl::_FileImpl(void)
93 , __pFileLockImpl(null)
97 _FileImpl::~_FileImpl(void)
100 if (__pFileLockImpl != null)
102 __pFileLockImpl->__pFileImpl = null;
106 _FileImpl::_FileImpl(const _FileImpl& fileImpl)
113 SysAssertf(false, "_FileImpl class does not support copy constructor.\n");
117 _FileImpl::operator =(const _FileImpl& fileImpl)
119 SysAssertf(false, "_FileImpl class does not support '=' operator.\n");
121 if (&fileImpl == this)
130 _FileImpl::VerifyFileOpenMode(const char* pOpenMode)
132 if (pOpenMode == null)
134 SysLog(NID_IO, "[E_INVALID_ARG] The specified openMode is null.");
138 if (strlen(pOpenMode) > _MAX_FILE_OPENMODE_LENGTH)
140 SysLog(NID_IO, "[E_INVALID_ARG] The specified openMode (%s) is invalid.", pOpenMode);
144 switch (pOpenMode[0])
158 SysLog(NID_IO, "[E_INVALID_ARG] The specified openMode (%s) is invalid.", pOpenMode);
162 switch (pOpenMode[1])
167 if (pOpenMode[2] == '\0' || pOpenMode[2] == 'b')
175 SysLog(NID_IO, "[E_INVALID_ARG] The specified openMode (%s) is invalid.", pOpenMode);
179 if (pOpenMode[2] == '\0')
183 else if (pOpenMode[2] == '+')
191 SysLog(NID_IO, "[E_INVALID_ARG] The specified openMode (%s) is invalid.", pOpenMode);
195 SysLog(NID_IO, "[E_INVALID_ARG] The specified openMode (%s) is invalid.", pOpenMode);
203 _FileImpl::Construct(const String& filePath, const String& openMode, bool createParentDirsToo, const ByteBuffer* pSecretKey)
205 SysAssertf(__pCore == null, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class\n");
206 result r = E_SUCCESS;
208 if (openMode.Contains(L'r') == true)
210 SysTryReturnResult(NID_IO, !createParentDirsToo, E_INVALID_ARG,
211 "The specified createParentDirsToo cannot be used without file creation mode.");
214 if (createParentDirsToo == true)
219 r = filePath.LastIndexOf(L'/', filePath.GetLength() - 1, position);
220 SysTryReturnResult(NID_IO, r != E_OBJ_NOT_FOUND, E_INVALID_ARG, "The specified filePath is invalid.");
221 SysTryReturnResult(NID_IO, !(position == 0), E_INVALID_ARG, "The specified filePath is invalid.");
223 r = filePath.SubString(0, position, dirPath);
224 SysTryReturn(NID_IO, !IsFailed(r), r, r, "[%s] Failed to extract dir path.", GetErrorMessage(r));
226 r = Directory::Create(dirPath, true);
229 if (r == E_FILE_ALREADY_EXIST)
235 SysPropagate(NID_IO, r);
241 unique_ptr<char[]> pOpenMode(_StringConverter::CopyToCharArrayN(openMode));
242 SysTryReturnResult(NID_IO, pOpenMode != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
244 return Construct(filePath, pOpenMode.get(), pSecretKey);
248 _FileImpl::Construct(const String& filePath, const char* pOpenMode, const ByteBuffer* pSecretKey)
250 SysAssertf(__pCore == null, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class\n");
251 result r = E_SUCCESS;
253 bool isValidOpenMode = VerifyFileOpenMode(pOpenMode);
254 SysTryReturnResult(NID_IO, isValidOpenMode == true, E_INVALID_ARG, "The specified openMode is invalid. (%s)", pOpenMode);
256 SysTryReturnResult(NID_IO, VerifyFilePathCompatibility(filePath, _AppInfo::IsOspCompat()) == true,
257 E_INVALID_ARG, " [%ls] is not compatible.", filePath.GetPointer());
259 if (!__truncate && IsFileExist(filePath))
261 r = _SecureIoUtil::CheckSecureFileHeader(filePath, pSecretKey);
262 if (r == E_END_OF_FILE)
264 r = E_IO; //for security error
266 SysTryReturn(NID_IO, !IsFailed(r), r, r, "[%s] Propagated.", GetErrorMessage(r));
269 if (pSecretKey == null)
271 unique_ptr<_NormalFile> pNormalFile(new (std::nothrow) _NormalFile());
272 SysTryReturnResult(NID_IO, pNormalFile, E_OUT_OF_MEMORY, "The memory is insufficient.");
274 r = pNormalFile->Construct(filePath, pOpenMode);
275 SysTryReturn(NID_IO, !IsFailed(r), r , r, "[%s] Propagated.", GetErrorMessage(r));
276 __pCore = pNormalFile.release();
280 unique_ptr<_SecureFile> pSecureFile(new (std::nothrow) _SecureFile(__read, __write, __truncate, __append));
281 SysTryReturnResult(NID_IO, pSecureFile, E_OUT_OF_MEMORY, "The memory is insufficient.");
283 r = pSecureFile->Construct(filePath, pOpenMode, pSecretKey);
284 SysTryReturn(NID_IO, !IsFailed(r), r , r, "[%s] Propagated.", GetErrorMessage(r));
285 __pCore = pSecureFile.release();
292 _FileImpl::ReadN(char** buffer, int& length)
294 result r = E_SUCCESS;
297 _NormalFile* pNormalFile = dynamic_cast< _NormalFile* > (__pCore);
298 if (pNormalFile != null)
300 r = pNormalFile->ReadN(buffer, length);
305 r = E_INVALID_OPERATION;
312 _FileImpl::Read(ByteBuffer& buffer)
314 SysAssertf(__pCore != null, "Not yet constructed. Construct() should be called before use.\n");
315 SysTryReturnResult(NID_IO, __read == true, E_ILLEGAL_ACCESS, "File is not opened for reading.");
316 return __pCore->Read(buffer);
320 _FileImpl::Read(void* buffer, int length)
322 SysAssertf(__pCore != null, "Not yet constructed. Construct() should be called before use.\n");
323 SysTryReturn(NID_IO, __read == true, 0, E_ILLEGAL_ACCESS, "[E_ILLEGAL_ACCESS] File is not opened for reading.");
324 return __pCore->Read(buffer, length);
328 _FileImpl::Read(String& buffer)
330 SysAssertf(__pCore != null, "Not yet constructed. Construct() should be called before use.\n");
331 SysTryReturnResult(NID_IO, __read == true, E_ILLEGAL_ACCESS, "File is not opened for reading.");
332 return __pCore->Read(buffer);
336 _FileImpl::Write(const ByteBuffer& buffer)
338 SysAssertf(__pCore != null, "Not yet constructed. Construct() should be called before use.\n");
339 SysTryReturnResult(NID_IO, __write == true, E_ILLEGAL_ACCESS, "File is not opened for writing.");
340 return __pCore->Write(buffer);
344 _FileImpl::Write(const void* buffer, int length)
346 SysAssertf(__pCore != null, "Not yet constructed. Construct() should be called before use.\n");
347 SysTryReturnResult(NID_IO, __write == true, E_ILLEGAL_ACCESS, "File is not opened for writing.");
348 return __pCore->Write(buffer, length);
352 _FileImpl::Write(const String& buffer)
354 SysAssertf(__pCore != null, "Not yet constructed. Construct() should be called before use.\n");
355 SysTryReturnResult(NID_IO, __write == true, E_ILLEGAL_ACCESS, "File is not opened for writing.");
356 return __pCore->Write(buffer);
360 _FileImpl::Flush(void)
362 SysAssertf(__pCore != null, "Not yet constructed. Construct() should be called before use.\n");
363 return __pCore->Flush();
367 _FileImpl::Tell(void) const
369 SysTryReturnResult(NID_IO, __pCore != null, -1, "File is not constructed! Construct destined file first! ");
370 return __pCore->Tell();
374 _FileImpl::Seek(FileSeekPosition position, long offset)
376 SysAssertf(__pCore != null, "Not yet constructed. Construct() should be called before use.\n");
377 return __pCore->Seek(position, offset);
381 _FileImpl::Truncate(int length)
383 SysAssertf(__pCore != null, "Not yet constructed. Construct() should be called before use.\n");
384 SysTryReturnResult(NID_IO, __write == true, E_ILLEGAL_ACCESS, "File is not opened for writing.");
385 return __pCore->Truncate(length);
389 _FileImpl::GetName(void) const
391 SysAssertf(__pCore != null, "Not yet constructed. Construct() should be called before use.\n");
392 return __pCore->GetName();
396 _FileImpl::GetFilePointer(void) const
398 SysAssertf(__pCore != null, "Not yet constructed. Construct() should be called before use.\n");
399 return __pCore->GetFilePointer();
403 _FileImpl::LockN(FileLockType lockType)
405 SysAssertf(__pCore != null, "Not yet constructed. Construct() should be called before use.\n");
406 return LockN(lockType, FILE_LOCK_MODE_BLOCKING, 0, 0);
410 _FileImpl::LockN(FileLockType lockType, int offset, int length)
412 SysAssertf(__pCore != null, "Not yet constructed. Construct() should be called before use.\n");
413 return LockN(lockType, FILE_LOCK_MODE_BLOCKING, offset, length);
417 _FileImpl::TryToLockN(FileLockType lockType)
419 SysAssertf(__pCore != null, "Not yet constructed. Construct() should be called before use.\n");
420 return LockN(lockType, FILE_LOCK_MODE_NON_BLOCKING, 0, 0);
424 _FileImpl::TryToLockN(FileLockType lockType, int offset, int length)
426 SysAssertf(__pCore != null, "Not yet constructed. Construct() should be called before use.\n");
427 return LockN(lockType, FILE_LOCK_MODE_NON_BLOCKING, offset, length);
431 _FileImpl::LockN(FileLockType lockType, _FileLockMode lockMode, int offset, int length)
433 SysAssertf(__pCore != null, "Not yet constructed. Construct() should be called before use.\n");
434 SysTryReturn(NID_IO, offset >= 0, null, E_INVALID_ARG, "[E_INVALID_ARG] The specified offset is negative.");
435 SysTryReturn(NID_IO, length >= 0, null, E_INVALID_ARG, "[E_INVALID_ARG] The specified length is negative.");
440 case FILE_LOCK_SHARED:
441 SysTryReturn(NID_IO, __read == true, null, E_INVALID_OPERATION, "[E_INVALID_OPERATION] File is not opened for reading.");
442 lock.l_type = F_RDLCK;
444 case FILE_LOCK_EXCLUSIVE:
445 SysTryReturn(NID_IO, __write == true, null, E_INVALID_OPERATION, "[E_INVALID_OPERATION] File is not opened for writing.");
446 lock.l_type = F_WRLCK;
449 SysLogException(NID_IO, E_INVALID_ARG, "[E_INVALID_ARG] The specified lock type is invalid.");
453 int fd = fileno(this->GetFilePointer());
454 int lockCommand = -1;
458 case FILE_LOCK_MODE_BLOCKING:
459 lockCommand = F_SETLKW;
461 case FILE_LOCK_MODE_NON_BLOCKING:
463 lockCommand = F_SETLK;
467 SysLogException(NID_IO, E_INVALID_ARG, "[E_INVALID_ARG] The specified lock mode is invalid.");
471 lock.l_whence = SEEK_SET;
472 lock.l_start = offset;
474 lock.l_pid = getpid();
476 ret = fcntl(fd, lockCommand, &lock);
479 result r = E_SUCCESS;
487 if (lockMode == FILE_LOCK_MODE_BLOCKING)
489 r = E_WOULD_DEADLOCK;
500 if (lockMode == FILE_LOCK_MODE_NON_BLOCKING)
512 r = _NativeError::ConvertNativeErrorToResult(errno, true);
516 SysLogException(NID_IO, r, "[%s] Aquiring file lock of type (%d) is failed, errno: %d (%s)", GetErrorMessage(r), lockType, errno, strerror(errno));
520 unique_ptr<FileLock> pFileLock(_FileLockImpl::CreateFileLockInstanceN(this, lockType, lock.l_start, lock.l_len, lock.l_pid));
521 SysTryReturn(NID_IO, pFileLock != null, null, GetLastResult(), "[%s] Propagating to caller....", GetErrorMessage(GetLastResult()));
522 __pFileLockImpl = _FileLockImpl::GetInstance(*pFileLock);
523 SetLastResult(E_SUCCESS);
524 return pFileLock.release();
528 _FileImpl::Remove(const String& filePath)
530 SysTryReturnResult(NID_IO, VerifyFilePathCompatibility(filePath, _AppInfo::IsOspCompat()) == true,
531 E_INVALID_ARG, " [%ls] is not compatible.", filePath.GetPointer());
532 return _FileUtil::Remove(filePath);
536 _FileImpl::Move(const String& oldFilePath, const String& newFilePath)
538 SysTryReturnResult(NID_IO, VerifyFilePathCompatibility(oldFilePath, _AppInfo::IsOspCompat()) == true,
539 E_INVALID_ARG, " [%ls] is not compatible.", oldFilePath.GetPointer());
541 SysTryReturnResult(NID_IO, VerifyFilePathCompatibility(newFilePath, _AppInfo::IsOspCompat()) == true,
542 E_INVALID_ARG, " [%ls] is not compatible.", newFilePath.GetPointer());
543 return _FileUtil::Move(oldFilePath, newFilePath);
547 _FileImpl::Copy(const String& srcFilePath, const String& destFilePath, bool failIfExist)
549 SysTryReturnResult(NID_IO, VerifyFilePathCompatibility(srcFilePath, _AppInfo::IsOspCompat()) == true,
550 E_INVALID_ARG, " [%ls] is not compatible.", srcFilePath.GetPointer());
552 SysTryReturnResult(NID_IO, VerifyFilePathCompatibility(destFilePath, _AppInfo::IsOspCompat()) == true,
553 E_INVALID_ARG, " [%ls] is not compatible.", destFilePath.GetPointer());
554 return _FileUtil::Copy(srcFilePath, destFilePath, failIfExist);
558 _FileImpl::GetAttributes(const String& filePath, FileAttributes& attribute)
560 SysTryReturnResult(NID_IO, VerifyFilePathCompatibility(filePath, _AppInfo::IsOspCompat()) == true,
561 E_INVALID_ARG, " [%ls] is not compatible.", filePath.GetPointer());
562 return _FileUtil::GetAttributes(filePath, attribute);
566 _FileImpl::GetFileName(const String& filePath)
568 return _FileUtil::GetFileName(filePath);
572 _FileImpl::GetFileExtension(const String& filePath)
574 return _FileUtil::GetFileExtension(filePath);
578 _FileImpl::IsFileExist(const String& filePath)
580 SysTryReturn(NID_IO, VerifyFilePathCompatibility(filePath, _AppInfo::IsOspCompat()) == true,
581 false, E_INVALID_ARG, "[E_INVALID_ARG] The specified filePath (%ls) is invalid.", filePath.GetPointer());
583 return _FileUtil::IsFileExist(filePath);
587 _FileImpl::ConvertToSecureFile(const String& plainFilePath, const String& secureFilePath,
588 const ByteBuffer& key)
590 return _FileUtil::ConvertToSecureFile(plainFilePath, secureFilePath, &key);
594 _FileImpl::IsAppPath(const String& filePath)
596 SysTryReturn(NID_IO, VerifyFilePathCompatibility(filePath, _AppInfo::IsOspCompat()) == true,
597 false, E_INVALID_ARG, "[E_INVALID_ARG] The specified filePath (%ls) is invalid.", filePath.GetPointer());
599 return _FileUtil::IsAppPath(filePath);
603 _FileImpl::IsMediaPath(const String& filePath)
605 SysTryReturn(NID_IO, VerifyFilePathCompatibility(filePath, _AppInfo::IsOspCompat()) == true,
606 false, E_INVALID_ARG, "[E_INVALID_ARG] The specified filePath (%ls) is invalid.", filePath.GetPointer());
608 return _FileUtil::IsMediaPath(filePath);
612 _FileImpl::IsSystemPath(const String& filePath)
614 SysTryReturn(NID_IO, VerifyFilePathCompatibility(filePath, _AppInfo::IsOspCompat()) == true,
615 false, E_INVALID_ARG, "[E_INVALID_ARG] The specified filePath (%ls) is invalid.", filePath.GetPointer());
617 return _FileUtil::IsSystemPath(filePath);
621 _FileImpl::VerifyFilePath(const String& filePath, _FilePathType pathType)
623 return _FileUtil::VerifyFilePath(filePath, pathType);
627 _FileImpl::VerifyFilePathCompatibility(const String& filePath, bool ospCompat)
629 if (ospCompat == true)
631 if (filePath[0] != L'/')
636 int length = filePath.GetLength();
645 _FileImpl::GetInstance(File& file)
647 return file.__pFileImpl;
651 _FileImpl::GetInstance(const File& file)
653 return file.__pFileImpl;
657 _FileImpl::ConvertVirtualToPhysicalPath(const String& virtualPath, String& physicalPath) // for 2.0 app
659 SysTryReturnResult(NID_IO, VerifyFilePathCompatibility(virtualPath, _AppInfo::IsOspCompat()) == true,
660 E_INVALID_ARG, "[E_INVALID_ARG] %ls is not compatible.", virtualPath.GetPointer());
662 const wchar_t* virtualPathPrefix[] =
669 L"/Share/AppControl",
676 L"/Storagecard/Media",
677 //L"/Storagecard/NPKI",
679 result r = E_SUCCESS;
680 int count = sizeof(virtualPathPrefix)/sizeof(wchar_t*);
683 for (i = 0; i < count; i++)
685 SysLog(NID_IO, "[V2P] i: %d, path: %ls", i, virtualPathPrefix[i]);
686 if (virtualPath.StartsWith(virtualPathPrefix[i], 0) == true)
691 SysTryReturnResult(NID_IO, i != count, E_INVALID_ARG, "The path (%ls) is not matched.",
692 virtualPath.GetPointer());
694 int prefixLen = String(virtualPathPrefix[i]).GetLength();
695 if (virtualPath.GetLength() > prefixLen)
699 r = virtualPath.GetCharAt(prefixLen, ch);
700 SysTryReturn(NID_IO, !IsFailed(r), r, r, "[%s] The path (%ls) is not matched.",
701 GetErrorMessage(r), virtualPath.GetPointer());
705 physicalPath.Clear();
706 SysLog(NID_IO, "[E_INVALID_ARG] The path (%ls) is not matched.",
707 virtualPath.GetPointer());
709 return E_INVALID_ARG;
714 virtualPath.SubString(wcslen(virtualPathPrefix[i]), subPath);
716 Tizen::App::App* pApp = Tizen::App::App::GetInstance();
717 SysTryReturnResult(NID_IO, pApp != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
718 String homePath = pApp->GetAppRootPath();
719 String ospCompatSharedPath = _EnvironmentImpl::GetOspCompatSharedPath();
724 physicalPath = homePath + L"data/Share2";
727 physicalPath = homePath + L"data/Share";
730 physicalPath = homePath + L"data";
733 physicalPath = homePath + L"res";
736 physicalPath = ospCompatSharedPath + L"share2";
739 physicalPath = ospCompatSharedPath + L"share/AppControl";
742 physicalPath = ospCompatSharedPath + L"share";
745 physicalPath = Tizen::System::Environment::GetMediaPath();
746 physicalPath.SetLength(physicalPath.GetLength() - 1);
749 physicalPath = Tizen::System::Environment::GetExternalStoragePath();
750 physicalPath.SetLength(physicalPath.GetLength() - 1);
753 SysLog(NID_IO, "[E_INVALID_ARG] The path (%ls) is not matched.",
754 virtualPath.GetPointer());
755 return E_INVALID_ARG;
758 if (subPath.IsEmpty() == false)
760 physicalPath.Append(subPath);
767 _FileImpl::ConvertPhysicalToVirtualPath(const String& physicalPath, String& virtualPath) // for 2.0 app
769 result r = E_SUCCESS;
770 const wchar_t* homeSubDir[] = {
776 const wchar_t* ospHomeSubDir[] = {
778 L"/share/AppControl",
782 int homeSubDirCount = sizeof(homeSubDir)/sizeof(wchar_t*);
783 int ospHomeSubDirCount = sizeof(ospHomeSubDir)/sizeof(wchar_t*);
787 SysLog(NID_IO, "[P2V] physicalPath: %ls", physicalPath.GetPointer());
789 Tizen::App::App* pApp = Tizen::App::App::GetInstance();
790 SysTryReturnResult(NID_IO, pApp != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
791 String homePath = pApp->GetAppRootPath();
792 homePath.SetLength(homePath.GetLength() - 1);
794 String ospCompatSharedPath = _EnvironmentImpl::GetOspCompatSharedPath();
795 ospCompatSharedPath.SetLength(ospCompatSharedPath.GetLength() - 1);
797 String mediaPath = Tizen::System::Environment::GetMediaPath();
798 mediaPath.SetLength(mediaPath.GetLength() - 1);
800 String externalPath = Tizen::System::Environment::GetExternalStoragePath();
801 externalPath.SetLength(externalPath.GetLength() - 1);
803 if (physicalPath.StartsWith(homePath, 0) == true)
805 physicalPath.SubString(homePath.GetLength(), subPath);
807 for (i = 0; i < homeSubDirCount; i++)
809 SysLog(NID_IO, "[P2V] i: %d, path: %ls", i, homeSubDir[i]);
810 if (subPath.StartsWith(homeSubDir[i], 0) == true)
815 SysTryReturnResult(NID_IO, i != homeSubDirCount, E_INVALID_ARG, "The path (%ls) is not matched.",
816 physicalPath.GetPointer());
818 baseDirLen = homePath.GetLength() + String(homeSubDir[i]).GetLength();
823 virtualPath = L"/Home/Share2";
826 virtualPath = L"/Home/Share";
829 virtualPath = L"/Home";
832 virtualPath = L"/Res";
839 else if (physicalPath.StartsWith(ospCompatSharedPath, 0) == true)
841 physicalPath.SubString(ospCompatSharedPath.GetLength(), subPath);
843 for (i = 0; i < ospHomeSubDirCount; i++)
845 SysLog(NID_IO, "[P2V] i: %d, path: %ls", i, ospHomeSubDir[i]);
846 if (subPath.StartsWith(ospHomeSubDir[i], 0) == true)
851 SysTryReturnResult(NID_IO, i != ospHomeSubDirCount, E_INVALID_ARG, "The path (%ls) is not matched.",
852 physicalPath.GetPointer());
854 baseDirLen = ospCompatSharedPath.GetLength() + String(ospHomeSubDir[i]).GetLength();
859 virtualPath = L"/Share2";
862 virtualPath = L"/Share/AppControl";
865 virtualPath = L"/Share";
871 else if (physicalPath.StartsWith(mediaPath, 0) == true)
873 SysLog(NID_IO, "[P2V] media");
874 virtualPath = L"/Media";
875 baseDirLen = mediaPath.GetLength();
877 else if (physicalPath.StartsWith(externalPath, 0) == true)
879 SysLog(NID_IO, "[P2V] external media");
880 virtualPath = L"/Storagecard/Media";
881 baseDirLen = externalPath.GetLength();
885 SysLog(NID_IO, "[E_INVALID_ARG] The path (%ls) is not matched.",
886 physicalPath.GetPointer());
888 return E_INVALID_ARG;
891 if (physicalPath.GetLength() > baseDirLen)
895 r = physicalPath.GetCharAt(baseDirLen, ch);
896 SysTryReturn(NID_IO, !IsFailed(r), r, r, "[%s] The path (%ls) is not matched.",
897 GetErrorMessage(r), physicalPath.GetPointer());
902 SysLog(NID_IO, "[E_INVALID_ARG] The path (%ls) is not matched.",
903 physicalPath.GetPointer());
905 return E_INVALID_ARG;
910 physicalPath.SubString(baseDirLen, subPath);
912 if (subPath.IsEmpty() == false)
914 virtualPath.Append(subPath);