diff --git a/interfaces/kits/js/src/common/log.h b/interfaces/kits/js/src/common/log.h index 57ba9edcd5d5f79ff961ab96094a75d76c124977..71aacaf4c5d13918a6f96637647eed59b06c57b6 100644 --- a/interfaces/kits/js/src/common/log.h +++ b/interfaces/kits/js/src/common/log.h @@ -27,7 +27,7 @@ namespace OHOS { namespace DistributedFS { #ifndef FILE_SUBSYSTEM_DEBUG_LOCAL -static constexpr int FILEIO_DOMAIN_ID = 0; +static constexpr int FILEIO_DOMAIN_ID = 0xD004388; static constexpr OHOS::HiviewDFX::HiLogLabel FILEIO_LABEL = { LOG_CORE, FILEIO_DOMAIN_ID, "file_api" }; #ifdef HILOGD diff --git a/interfaces/kits/js/src/mod_fileio/class_dir/dir_n_exporter.cpp b/interfaces/kits/js/src/mod_fileio/class_dir/dir_n_exporter.cpp index b94cfe121c0982eb56f34e726f60741ffa727b6a..7a7fa28eac655ddfea8a8a995444fd66d86f086c 100644 --- a/interfaces/kits/js/src/mod_fileio/class_dir/dir_n_exporter.cpp +++ b/interfaces/kits/js/src/mod_fileio/class_dir/dir_n_exporter.cpp @@ -171,10 +171,31 @@ napi_value DirNExporter::Read(napi_env env, napi_callback_info info) auto cbExec = [arg, dir, dirEntity](napi_env env) -> UniError { struct dirent tmpDirent; lock_guard(dirEntity->lock_); + char dirBuff[DIR_BUFF_LEN]; + (void)memset_s(dirBuff, DIR_BUFF_LEN, 0x00, DIR_BUFF_LEN); + + if (EOK == memcpy_s(dirBuff, DIR_BUFF_LEN, dir, DIR_BUFF_LEN - 1)) { + HILOGE("[0]struct DIR member fd = %{public}02x-%{public}02x-%{public}02x-%{public}02x," + "buf_pos = %{public}02x-%{public}02x-%{public}02x-%{public}02x," + "buf_end = %{public}02x-%{public}02x-%{public}02x-%{public}02x", + dirBuff[8], dirBuff[9], dirBuff[10], dirBuff[11], dirBuff[12], dirBuff[13], dirBuff[14], + dirBuff[15], dirBuff[16], dirBuff[17], dirBuff[18], dirBuff[19]); + } errno = 0; dirent *res = nullptr; do { res = readdir(dir); + if (res != nullptr) { + HILOGE("res filelength = %{public}u, type = %{public}d", res->d_reclen, res->d_type); + } + + if (EOK == memcpy_s(dirBuff, DIR_BUFF_LEN, dir, DIR_BUFF_LEN - 1)) { + HILOGE("struct DIR member fd = %{public}02x-%{public}02x-%{public}02x-%{public}02x," + "buf_pos = %{public}02x-%{public}02x-%{public}02x-%{public}02x," + "buf_end = %{public}02x-%{public}02x-%{public}02x-%{public}02x", + dirBuff[8], dirBuff[9], dirBuff[10], dirBuff[11], dirBuff[12], dirBuff[13], + dirBuff[14], dirBuff[15], dirBuff[16], dirBuff[17], dirBuff[18], dirBuff[19]); + } if (res == nullptr && errno) { return UniError(errno); } else if (res == nullptr) { @@ -205,6 +226,9 @@ napi_value DirNExporter::Read(napi_env env, napi_callback_info info) napi_value DirNExporter::ReadSync(napi_env env, napi_callback_info info) { + char dirBuff[DIR_BUFF_LEN]; + (void)memset_s(dirBuff, DIR_BUFF_LEN, 0x00, DIR_BUFF_LEN); + NFuncArg funcArg(env, info); if (!funcArg.InitArgs(NARG_CNT::ZERO)) { UniError(EINVAL).ThrowErr(env, "Number of arguments unmatched"); @@ -216,6 +240,14 @@ napi_value DirNExporter::ReadSync(napi_env env, napi_callback_info info) UniError(EBADF).ThrowErr(env, "Dir has been closed yet"); return nullptr; } + DIR *dir = dirEntity->dir_.get(); + if (EOK == memcpy_s(dirBuff, DIR_BUFF_LEN, dir, DIR_BUFF_LEN -1)) { + HILOGE("[0]struct DIR member fd = %{public}02x-%{public}02x-%{public}02x-%{public}02x," + "buf_pos = %{public}02x-%{public}02x-%{public}02x-%{public}02x," + "buf_end = %{public}02x-%{public}02x-%{public}02x-%{public}02x", + dirBuff[8], dirBuff[9], dirBuff[10], dirBuff[11], dirBuff[12], dirBuff[13], + dirBuff[14], dirBuff[15], dirBuff[16], dirBuff[17], dirBuff[18], dirBuff[19]); + } struct dirent tmpDirent; { @@ -223,7 +255,19 @@ napi_value DirNExporter::ReadSync(napi_env env, napi_callback_info info) errno = 0; dirent *res = nullptr; do { - res = readdir(dirEntity->dir_.get()); + res = readdir(dir); + if (res != nullptr) { + HILOGE("res filelength = %{public}u, type = %{public}d", res->d_reclen, res->d_type); + } + + if (EOK == memcpy_s(dirBuff, DIR_BUFF_LEN, dir, DIR_BUFF_LEN - 1)) { + HILOGE("struct DIR member fd = %{public}02x-%{public}02x-%{public}02x-%{public}02x," + "buf_pos = %{public}02x-%{public}02x-%{public}02x-%{public}02x," + "buf_end = %{public}02x-%{public}02x-%{public}02x-%{public}02x", + dirBuff[8], dirBuff[9], dirBuff[10], dirBuff[11], dirBuff[12], dirBuff[13], + dirBuff[14], dirBuff[15], dirBuff[16], dirBuff[17], dirBuff[18], dirBuff[19]); + } + if (res == nullptr && errno) { UniError(errno).ThrowErr(env); return nullptr; diff --git a/interfaces/kits/js/src/mod_fileio/class_dir/dir_n_exporter.h b/interfaces/kits/js/src/mod_fileio/class_dir/dir_n_exporter.h index a40ed03d2b542f5ef501fdd4cd3c922bae2d2e2f..f67c114e071d26dc98e08bb6e5848ee6de20aded 100644 --- a/interfaces/kits/js/src/mod_fileio/class_dir/dir_n_exporter.h +++ b/interfaces/kits/js/src/mod_fileio/class_dir/dir_n_exporter.h @@ -42,6 +42,7 @@ public: ~DirNExporter() override; }; const std::string listfileProcedureName = "fileioDirListFile"; +constexpr int DIR_BUFF_LEN = 25; } // namespace ModuleFileIO } // namespace DistributedFS } // namespace OHOS