2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FIo_FileUtil.cpp
20 * @brief This is the implementation file for _FileUtil class.
27 #include <sys/types.h>
34 #include <unique_ptr.h>
37 #include <FIoDirectory.h>
38 #include <FBaseResult.h>
39 #include <FBaseSysLog.h>
41 #include <FBase_StringConverter.h>
42 #include <FBase_NativeError.h>
43 #include <FApp_AppInfo.h>
44 #include <FIo_FileAttributesImpl.h>
45 #include <FIo_SecureIoUtil.h>
46 #include <FIo_FileImpl.h>
47 #include <FIo_FileUtil.h>
50 using namespace Tizen::Base;
51 using namespace Tizen::App;
53 namespace Tizen { namespace Io
56 static const int _BASE_YEAR = 1900;
57 static const int _MAX_COPY_BYTES = 4096;
58 static const int _MAX_OPENMODE_LENGTH = 3;
60 //Holds app path prefixes
61 static const char* filePathAppPrefix[] =
75 "/Storagecard/DownloadedAppPackages",
83 //Holds Media path prefixes
84 static const char* filePathMediaPrefix[] =
90 //Holds system path prefixes
91 static const char* filePathSystemPrefix[] =
93 "/system/configuration",
98 _FileUtil::Remove(const String& filePath)
100 result r = E_SUCCESS;
101 unique_ptr<char[]> pFilePath(_StringConverter::CopyToCharArrayN(filePath));
102 SysTryReturn(NID_IO, (pFilePath != null), GetLastResult(), GetLastResult(), ("[%s] Invalid file path."),
103 GetErrorMessage(GetLastResult()));
105 if (_FileUtil::IsFileExist(pFilePath.get()) == false)
107 SysLog(NID_IO, "[E_FILE_NOT_FOUND] File(%s) does not exist.", pFilePath.get());
108 return E_FILE_NOT_FOUND;
111 char resolvedPath[PATH_MAX] = {0,};
112 if (realpath(pFilePath.get(), resolvedPath) == null)
117 r = E_ILLEGAL_ACCESS;
132 r = E_FILE_NOT_FOUND;
139 SysLog(NID_IO, "[%s] Failed to produce canonical absolute path (%ls). errno: %d (%s)",
140 GetErrorMessage(r), filePath.GetPointer(), errno, strerror(errno));
145 int ret = unlink(resolvedPath);
154 r = __ConvertNativeErrorToResult(errno);
155 SysLog(NID_IO, "[%s] Failed to unlink(), errno: %d (%s)", GetErrorMessage(r), errno, strerror(errno));
163 _FileUtil::Move(const String& oldFilePath, const String& newFilePath)
165 result r = E_SUCCESS;
168 unique_ptr<char[]> pOldPath(_StringConverter::CopyToCharArrayN(oldFilePath));
169 SysTryReturn(NID_IO, pOldPath != null, GetLastResult(), GetLastResult(),
170 "[%s] Invalid old file path.", GetErrorMessage(GetLastResult()));
172 unique_ptr<char[]> pNewPath(_StringConverter::CopyToCharArrayN(newFilePath));
173 SysTryReturn(NID_IO, pNewPath != null, GetLastResult(), GetLastResult(),
174 "[%s] Invalid new file path.", GetErrorMessage(GetLastResult()));
176 SysTryReturnResult(NID_IO, _FileUtil::IsFileExist(newFilePath) == false, E_FILE_ALREADY_EXIST,
177 "New file already exists.");
179 SysTryReturnResult(NID_IO, _FileUtil::IsFileExist(oldFilePath) == true, E_FILE_NOT_FOUND,
180 "Old filepath not found.");
182 if (stat(pOldPath.get(), &statBuf) < 0)
184 r = __ConvertNativeErrorToResult(errno);
185 SysLogException(NID_IO, r, "[%s] stat() failed, path: %s, errno: %d (%s)", GetErrorMessage(r), pOldPath.get(), errno, strerror(errno));
188 SysTryReturnResult(NID_IO, S_ISDIR(statBuf.st_mode) == false, E_INVALID_ARG,
189 "The old path is a directory.");
191 int ret = rename(pOldPath.get(), pNewPath.get());
192 if (ret != 0 && errno != EXDEV)
194 r = __ConvertNativeErrorToResult(errno);
195 SysLog(NID_IO, "[%s] rename() failed, errno: %d (%s)", GetErrorMessage(r), errno, strerror(errno));
198 else if (errno == EXDEV)
200 r = File::Copy(oldFilePath, newFilePath, true);
201 SysTryReturn(NID_IO, !IsFailed(r), r, r, "[%s] Propagating to caller...", GetErrorMessage(r));
203 r = File::Remove(oldFilePath);
204 SysTryReturn(NID_IO, !IsFailed(r), r, r, "[%s] Propagating to caller...", GetErrorMessage(r));
211 _FileUtil::Copy(const String& srcFilePath, const String& destFilePath, bool failIfExist)
215 ssize_t readBytes = -1;
216 ssize_t writtenBytes = -1;
217 ssize_t remainingBytes = -1;
218 char* pBuffer = null;
219 result r = E_SUCCESS;
221 unique_ptr<char[]> pSrcpath(_StringConverter::CopyToCharArrayN(srcFilePath));
222 SysTryReturn(NID_IO, pSrcpath != null, GetLastResult(), GetLastResult(),
223 "[%s] Invalid source file path.", GetErrorMessage(GetLastResult()));
225 unique_ptr<char[]> pDstpath(_StringConverter::CopyToCharArrayN(destFilePath));
226 SysTryReturn(NID_IO, pDstpath != null, GetLastResult(), GetLastResult(),
227 "[%s] Invalid destination file path.", GetErrorMessage(GetLastResult()));
229 SysTryReturnResult(NID_IO, _FileUtil::IsFileExist(srcFilePath) == true, E_FILE_NOT_FOUND,
230 "Source file(%s) does not exist.", pSrcpath.get());
232 if ((_FileUtil::IsFileExist(destFilePath) == true) && (failIfExist == true))
234 r = E_FILE_ALREADY_EXIST;
235 SysLog(NID_IO, "[E_FILE_ALREADY_EXIST] Destination file already exists.");
239 srcFd = open(pSrcpath.get(), O_RDONLY);
242 r = __ConvertNativeErrorToResult(errno);
243 SysLogException(NID_IO, r, "[%s] Failed to open file (%s).", GetErrorMessage(r), pSrcpath.get());
246 dstFd = open(pDstpath.get(), O_WRONLY | O_CREAT | O_TRUNC, 0644);
249 r = __ConvertNativeErrorToResult(errno);
250 SysLogException(NID_IO, r, "[%s] Failed to open file (%s), errno: %d (%s)",
251 GetErrorMessage(r), pDstpath.get(), errno, strerror(errno));
255 pBuffer = new (std::nothrow) char[_MAX_COPY_BYTES];
256 SysTryCatch(NID_IO, pBuffer != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
262 readBytes = read(srcFd, pBuffer, _MAX_COPY_BYTES);
264 while (readBytes < 0 && errno == EINTR);
267 r = __ConvertNativeErrorToResult(errno);
268 SysLogException(NID_IO, r, "[%s] Failed to read from source file (%s), errno: %d (%s)",
269 GetErrorMessage(r), pSrcpath.get(), errno, strerror(errno));
272 else if (readBytes == 0)
276 remainingBytes = readBytes;
280 writtenBytes = write(dstFd, pBuffer, remainingBytes);
282 while (writtenBytes < 0 && errno == EINTR);
283 if (writtenBytes < 0)
285 r = __ConvertNativeErrorToResult(errno);
286 SysLogException(NID_IO, r, "[%s] Failed to write to destination file (%s), errno: %d (%s)",
287 GetErrorMessage(r), pDstpath.get(), errno, strerror(errno));
290 else if (writtenBytes < remainingBytes)
292 remainingBytes = remainingBytes - writtenBytes;
293 pBuffer = const_cast< char* >(pBuffer) + writtenBytes;
316 _FileUtil::GetAttributes(const String& filePath, FileAttributes& attribute)
319 DateTime modifiedTime;
320 long long fileSize = 0;
321 unsigned long attr = 0;
322 result r = E_SUCCESS;
323 struct tm* pTm = null;
324 String fileName = L"";
327 unique_ptr<char[]> pFilePath(_StringConverter::CopyToCharArrayN(filePath));
328 SysTryReturn(NID_IO, (pFilePath != null), GetLastResult(), GetLastResult(), "[%s] Invalid source file path.",
329 GetErrorMessage(GetLastResult()));
332 if (int ret = stat(pFilePath.get(), &statbuf) == -1)
334 r = __ConvertNativeErrorToResult(errno);
335 SysLogException(NID_IO, r, "[%s] Failed to get file (%s) status.", GetErrorMessage(r), pFilePath.get());
340 fileSize = statbuf.st_size;
343 attr = statbuf.st_mode;
345 // time of last status change
346 pTm = localtime(&statbuf.st_ctime);
347 SysTryReturnResult(NID_IO, pTm != null, E_SYSTEM, "Failed to call localtime() (%s).", strerror(errno));
348 r = dateTime.SetValue(_BASE_YEAR + pTm->tm_year, 1 + pTm->tm_mon, pTm->tm_mday, pTm->tm_hour, pTm->tm_min, pTm->tm_sec);
349 SysTryReturn(NID_IO, (!IsFailed(r)), r, r, "[%s] Failed to set DateTime.", GetErrorMessage(r));
351 // time of last modification
352 pTm = localtime(&statbuf.st_mtime);
353 SysTryReturnResult(NID_IO, pTm != null, E_SYSTEM, "Failed to call localtime() (%s).", strerror(errno));
354 r = modifiedTime.SetValue(_BASE_YEAR + pTm->tm_year, 1 + pTm->tm_mon, pTm->tm_mday, pTm->tm_hour, pTm->tm_min, pTm->tm_sec);
355 SysTryReturn(NID_IO, (!IsFailed(r)), r, r, "[%s] Failed to set DateTime.", GetErrorMessage(r));
357 fileName = _FileUtil::GetFileName(filePath);
358 if (fileName.StartsWith(L".", 0)) // including . and ..
363 _FileAttributesImpl::GetInstance(attribute)->Set(dateTime, modifiedTime, fileSize, attr, hidden);
369 _FileUtil::GetFileName(const String& filePath)
374 result r = filePath.LastIndexOf(L'/', filePath.GetLength() - 1, pos);
375 SysTryReturn(NID_IO, !IsFailed(r), fileName, E_INVALID_ARG, "[E_INVALID_ARG] The file path is invalid.");
377 r = filePath.SubString(pos + 1, fileName);
378 SysTryReturn(NID_IO, !IsFailed(r), fileName, E_INVALID_ARG, "[E_INVALID_ARG] The file path is invalid.");
379 SysTryReturn(NID_IO, fileName.GetLength() > 0 && fileName.GetLength() <= NAME_MAX, fileName, E_INVALID_ARG,
380 "[E_INVALID_ARG] The length of file name is zero or exceeds system limitations.");
382 SetLastResult(E_SUCCESS);
387 _FileUtil::GetFileExtension(const String& filePath)
392 result r = filePath.LastIndexOf(L'/', filePath.GetLength() - 1, pos);
393 SysTryReturn(NID_IO, !IsFailed(r), extName, E_INVALID_ARG, "[E_INVALID_ARG] The file path is invalid.");
396 r = filePath.SubString(pos + 1, fileName);
397 SysTryReturn(NID_IO, !IsFailed(r), extName, E_INVALID_ARG, "[E_INVALID_ARG] The file path is invalid.");
398 SysTryReturn(NID_IO, fileName.GetLength() > 0 && fileName.GetLength() <= NAME_MAX, extName, E_INVALID_ARG,
399 "[E_INVALID_ARG] The length of file name is zero or exceeds system limitations.");
401 r = fileName.LastIndexOf(L'.', fileName.GetLength() - 1, pos);
402 SysTryReturn(NID_IO, !IsFailed(r), extName, E_INVALID_ARG, "[E_INVALID_ARG] The file path is invalid.");
404 r = fileName.SubString(pos + 1, extName);
405 SysTryReturn(NID_IO, !IsFailed(r), extName, E_INVALID_ARG, "[E_INVALID_ARG] The file path is invalid.");
407 SetLastResult(E_SUCCESS);
412 _FileUtil::IsFileExist(const String& filePath)
415 result r = E_SUCCESS;
417 unique_ptr<char[]> pFilePath(_StringConverter::CopyToCharArrayN(filePath));
418 SysTryReturn(NID_IO, (pFilePath != null), false, GetLastResult(), ("[%s] Invalid file path."),
419 GetErrorMessage(GetLastResult()));
421 ret = access(pFilePath.get(), F_OK);
433 r = __ConvertNativeErrorToResult(errno);
439 return (ret == 0) ? true : false;
444 _FileUtil::IsEncrypted(const String& filePath)
446 result r = E_SUCCESS;
447 // TODO: int pathKind;
450 bool encrypted = false;
451 // TODO: bool checkPrivilege = false;
452 byte secureHeader[SECURE_FILE_HEADER_SIZE_V1 + SECURE_IO_LOF_SIZE];
453 byte reservedValue[SECURE_IO_STATIC_BIN_LEN] = {0xCA, 0xFE, 0xBE, 0xBE, 0xDA, 0xEF, 0xEB, 0xEB};
454 char magicNum1[SECURE_IO_MAGIC_NUMBER_SIZE] = {0xCA, 0xFE, 0xBE, 0xBE};
455 char magicNum2[SECURE_IO_MAGIC_NUMBER_SIZE] = {0xDA, 0xEF, 0xEF, 0xEB};
458 unique_ptr<char[]> pFilePath(_StringConverter::CopyToCharArrayN(filePath));
459 SysTryReturn(NID_IO, pFilePath != null, false, E_INVALID_ARG, "[E_INVALID_ARG] CopyToCharArrayN failed!");
461 fileLength = strlen(pFilePath.get());
462 SysTryReturn(NID_IO, fileLength > 0, false, E_INVALID_ARG, "[E_INVALID_ARG] CopyToCharArrayN failed!");
464 if (pFilePath[fileLength - 1] == ('/'))
466 pFilePath[fileLength - 1] = ('\0'); // remove last '/' character if exists.
469 // // TODO: check accessibility to path
470 // r = CheckAccessibilityToPath(pFilePath, &pathKind, 0);
474 // if(pathKind == __PATH_KIND_AUTHORIZED_MMC)
476 // __CheckPrivilege(PRV_INSTALLATION, checkPrivilege);
477 // if(!checkPrivilege)
479 // r = E_ILLEGAL_ACCESS;
483 // else if(pathKind == __PATH_KIND_AUTHORIZED_LINK || pathKind == __PATH_KIND_AUTHORIZED_NPKI ||
484 // pathKind == __PATH_KIND_AUTHORIZED_PRELOADED_MEDIA)
486 // __CheckPrivilege(PRV_PRIVILEGED_IO, checkPrivilege);
487 // if(!checkPrivilege)
489 // r = E_ILLEGAL_ACCESS;
493 // else if (pathKind == __PATH_KIND_APP_DENY)
495 // r = E_ILLEGAL_ACCESS;
499 pFile = fopen(pFilePath.get(), "r");
502 r = __ConvertNativeErrorToResult(errno);
503 SysLog(NID_IO, "[%s] Failed to open file (%s) in openMode (%s), (errno: %d).", GetErrorMessage(r), pFilePath.get(), "r", errno);
507 readItems = fread(secureHeader, 1, SECURE_FILE_HEADER_SIZE_V1 + SECURE_IO_LOF_SIZE, pFile);
509 if (readItems < (SECURE_FILE_HEADER_SIZE_V1 + SECURE_IO_LOF_SIZE))
511 int eof = feof((FILE*)pFile);
519 r = __ConvertNativeErrorToResult(errno);
520 SysLog(NID_IO, "[%s] Failed to open file (%s) in openMode (%s), (errno: %d).", GetErrorMessage(r), pFilePath.get(), "r", errno);
524 if (memcmp(secureHeader, SECURE_FILE_HEADER_STRING, SECURE_FILE_HEADER_STRING_SIZE) == 0 && \
525 memcmp(secureHeader + SECURE_FILE_HEADER_STRING_SIZE, reservedValue, SECURE_IO_STATIC_BIN_LEN) == 0)
529 else if (memcmp(secureHeader, SECURE_REG_HEADER_STRING, SECURE_REG_HEADER_STRING_SIZE) == 0 && \
530 memcmp(secureHeader + SECURE_REG_HEADER_STRING_SIZE, reservedValue, SECURE_IO_STATIC_BIN_LEN) == 0)
534 else if ((memcmp(secureHeader, magicNum1, SECURE_IO_MAGIC_NUMBER_SIZE) == 0) &&
535 (memcmp(secureHeader + SECURE_IO_STATIC_BIN_LEN, magicNum2, SECURE_IO_MAGIC_NUMBER_SIZE) == 0))
559 _FileUtil::IsAppPath(const String& filePath)
561 result r = E_SUCCESS;
563 if (VerifyFilePath(filePath, FILEPATH_TYPE_APP))
565 SetLastResult(E_SUCCESS);
575 _FileUtil::IsMediaPath(const String& filePath)
577 result r = E_SUCCESS;
579 if (VerifyFilePath(filePath, FILEPATH_TYPE_MEDIA))
581 SetLastResult(E_SUCCESS);
591 _FileUtil::IsSystemPath(const String& filePath)
593 result r = E_SUCCESS;
595 if (VerifyFilePath(filePath, FILEPATH_TYPE_SYSTEM))
597 SetLastResult(E_SUCCESS);
607 _FileUtil::VerifyFilePath(const String& filePath, _FilePathType pathType)
609 result r = E_SUCCESS;
611 String absolutePath("");
615 char** ppPathList = null;
616 bool candidateFound = false;
619 //TODO Apply realpath after data caging.
621 //char resolved_path[1024];
622 //char* pFilePath = _StringConverter::CopyToCharArrayN(filePath);
624 //r = GetLastResult();
626 //SysTryCatch(NID_IO, pFilePath != null,
627 // r, r, "[%s] Failed to get file path", GetErrorMessage(r));
630 //SysLog(NID_IO, "convert: %s", pFilePath);
631 //if (realpath(pFilePath, resolved_path) !=0)
633 // r = __ConvertNativeErrorToResult(errno);
634 // SysLog(NID_IO, "convert Error!!! [%s] %s", resolved_path, GetErrorMessage(r));
635 // delete[] pFilePath;
639 //SysLog(NID_IO, "convert result: %s", resolved_path);
640 //absolutePath.Append(resolved_path);
641 //delete[] pFilePath;
643 absolutePath.Append(filePath);
644 // This code does not handle paths without prefix '/' ex: "Home/myfile"
645 // since it depends on cwd.
648 case FILEPATH_TYPE_APP:
649 pathCount = MAX_FILEPATH_APP;
650 ppPathList = const_cast <char**>(filePathAppPrefix);
653 case FILEPATH_TYPE_MEDIA:
654 pathCount = MAX_FILEPATH_MEDIA;
655 ppPathList = const_cast <char**>(filePathMediaPrefix);
658 case FILEPATH_TYPE_SYSTEM:
659 pathCount = MAX_FILEPATH_SYSTEM;
660 ppPathList = const_cast <char**>(filePathSystemPrefix);
668 absolutePath.GetCharAt(absolutePath.GetLength() - 1, ch);
669 if (ch != L'/') // if last char of absolutePath is not '/' then append it to make path parsing easier
671 absolutePath.Append(L'/');
674 for (i = 0; i < pathCount; i++)
677 tmpStr.Append(ppPathList[i]);
679 if (absolutePath.IndexOf(tmpStr, 0, index) == E_SUCCESS)
684 if (absolutePath.GetCharAt(tmpStr.GetLength(), ch) == E_SUCCESS)
686 if (ch == L'/') // validate exact path. paths like /Home123/file.txt is not supported.
688 candidateFound = true;
696 if (candidateFound == true)
718 _FileUtil::ConvertToSecureFile(const String& plainFilePath, const String& secureFilePath, const ByteBuffer* pKey)
720 SysTryReturnResult(NID_IO, plainFilePath.GetLength() > 0 && plainFilePath.GetLength() <= PATH_MAX, E_INVALID_ARG,
721 "Invalid argument was passed. Given file name length is not correct!");
722 SysTryReturnResult(NID_IO, plainFilePath.EndsWith(L"/") == false, E_INVALID_ARG,
723 "Invalid argument was passed. Given file name is not correct! - ends with '/'");
725 SysTryReturnResult(NID_IO, secureFilePath.GetLength() > 0 && secureFilePath.GetLength() <= PATH_MAX, E_INVALID_ARG,
726 "Invalid argument was passed. Given file name length is not correct!");
727 SysTryReturnResult(NID_IO, secureFilePath.EndsWith(L"/") == false, E_INVALID_ARG,
728 "Invalid argument was passed. Given file name is not correct! - ends with '/'");
732 int lastBlockSize = 0;
736 unique_ptr<byte[]> pBuffer(null);
737 result r = E_SUCCESS;
739 if (File::IsFileExist(secureFilePath))
744 r = E_FILE_ALREADY_EXIST;
745 SysLog(NID_IO, "[E_FILE_ALREADY_EXIST] The secure file already exist.");
749 SysLog(NID_IO, "[%s] Propagated.", GetErrorMessage(r));
754 unique_ptr<File> pFile(new (std::nothrow) File());
755 SysTryReturnResult(NID_IO, pFile != null, E_OUT_OF_MEMORY, "Unable to create Io::File");
757 r = pFile->Construct(plainFilePath, L"r", false);
760 if (r == E_MAX_EXCEEDED)
764 SysLog(NID_IO, "[%s] Propagated.", GetErrorMessage(r));
768 r = pFile->Seek(FILESEEKPOSITION_END, 0);
769 SysTryReturn(NID_IO, r == E_SUCCESS , r, r, "[%s] Propagated", GetErrorMessage(r));
771 fileSize = pFile->Tell();
773 r = pFile->Seek(FILESEEKPOSITION_BEGIN, 0);
774 SysTryReturn(NID_IO, r == E_SUCCESS , r, r, "[%s] Propagated", GetErrorMessage(r));
776 unique_ptr<File> pSecureFile(new (std::nothrow) File());
777 SysTryReturnResult(NID_IO, pSecureFile != null, E_OUT_OF_MEMORY,
778 "Unable to create Io::File");
780 r = pSecureFile->Construct(secureFilePath, "w", *pKey);
781 SysTryReturn(NID_IO, r == E_SUCCESS , r, r, "[%s] Propagated", GetErrorMessage(r));
788 lastBlockSize = fileSize % CIPHER_BLOCK_SIZE;
789 if (lastBlockSize == 0)
791 blockCount = fileSize / CIPHER_BLOCK_SIZE;
792 lastBlockSize = CIPHER_BLOCK_SIZE;
796 blockCount = fileSize / CIPHER_BLOCK_SIZE + 1;
799 for(count = 0; count < blockCount; count++)
803 memset(pBuffer.get(), 0, CIPHER_BLOCK_SIZE);
806 if ((count + 1) == blockCount && pBuffer == null)
808 pBuffer.reset(new (std::nothrow) byte[lastBlockSize]);
809 SysTryReturnResult(NID_IO, pBuffer != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
810 memset(pBuffer.get(), 0, lastBlockSize);
811 bufferSize = lastBlockSize;
814 else if ((count + 1) != blockCount && pBuffer == null)
816 pBuffer.reset(new (std::nothrow) byte[CIPHER_BLOCK_SIZE]);
817 SysTryReturnResult(NID_IO, pBuffer != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
818 memset(pBuffer.get(), 0, CIPHER_BLOCK_SIZE);
819 bufferSize = CIPHER_BLOCK_SIZE;
822 readSize = pFile->Read(pBuffer.get(), bufferSize);
826 if (r == E_END_OF_FILE)
830 SysLog(NID_IO, "[%s] Propagated.", GetErrorMessage(r));
834 r = pSecureFile->Write(pBuffer.get(), readSize);
835 SysTryReturn(NID_IO, r == E_SUCCESS , r, r, "[%s] Propagated", GetErrorMessage(r));