diff --git a/interfaces/kits/cj/src/fsync.cpp b/interfaces/kits/cj/src/fsync.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e6d36ba1bd39fba26b00ee5fcf53dafb5b705d35 --- /dev/null +++ b/interfaces/kits/cj/src/fsync.cpp @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "fsync.h" +#include "file_fs_impl.h" + +#include +#include + + +namespace OHOS { +namespace CJSystemapi { + +using namespace std; + +int FsyncImpl::Fsync(int32_t fd) +{ + LOGI("FS_TEST::FsyncImpl::Fsync start"); + std::unique_ptr fsync_req = { + new uv_fs_t, CommonFunc::FsReqCleanup }; + if (!fsync_req) { + LOGE("Failed to request heap memory."); + return ENOMEM; + } + int ret = uv_fs_fsync(nullptr, fsync_req.get(), fd, nullptr); + if (ret < 0) { + LOGE("Failed to transfer data associated with file descriptor: %{public}d", fd); + return ret; + } + LOGI("FS_TEST::FsyncImpl::Fsync success"); + return ret; +} + +} // namespace CJSystemapi +} // namespace OHOS diff --git a/interfaces/kits/cj/src/fsync.h b/interfaces/kits/cj/src/fsync.h new file mode 100644 index 0000000000000000000000000000000000000000..8a826b443096ed4bd48783b836c12c882b9f9a72 --- /dev/null +++ b/interfaces/kits/cj/src/fsync.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_FILE_FS_FSYNC_H +#define OHOS_FILE_FS_FSYNC_H + +#include + +namespace OHOS { +namespace CJSystemapi { + +class FsyncImpl { +public: + static int Fsync(int32_t fd); +}; + +} +} +#endif //OHOS_FILE_FS_FDATASYNC_H diff --git a/interfaces/kits/cj/src/lseek.cpp b/interfaces/kits/cj/src/lseek.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e8e2cb5b1944bd90ef73414d51407b781097ffd2 --- /dev/null +++ b/interfaces/kits/cj/src/lseek.cpp @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "lseek.h" + +#include "stat_impl.h" +#include "macro.h" +#include "n_error.h" +#include "file_utils.h" +#include "rust_file.h" + +namespace OHOS { +namespace CJSystemapi { +using namespace std; +using namespace OHOS::FileManagement::LibN; + +RetDataI64 LseekImpl::Lseek(int32_t fd, int64_t offset, int pos) +{ + LOGI("FS_TEST:: LseekImpl::Lseek start"); + RetDataI64 ret = { .code = EINVAL, .data = 0 }; + if (fd < 0) { + LOGE("Invalid fd"); + return ret; + } + + SeekPos whence = SeekPos::START; + whence = static_cast(pos); + + int64_t seekRet = ::Lseek(fd, offset, whence); + if (seekRet < 0) { + LOGE("Failed to lseek, error:%{public}d", errno); + ret.code = errno; + return ret; + } + ret.code = SUCCESS_CODE; + ret.data = seekRet; + return ret; +} + +} // CJSystemapi +} // OHOS diff --git a/interfaces/kits/cj/src/lseek.h b/interfaces/kits/cj/src/lseek.h new file mode 100644 index 0000000000000000000000000000000000000000..912ac7ddfbf831655f4ee1ffe7d19644a175ad35 --- /dev/null +++ b/interfaces/kits/cj/src/lseek.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef OHOS_FILE_FS_LSEEK_H +#define OHOS_FILE_FS_LSEEK_H + +#include "cj_common_ffi.h" + +namespace OHOS { +namespace CJSystemapi { + +class LseekImpl { +public: + static RetDataI64 Lseek(int32_t fd, int64_t offset, int pos); +}; + + +} // namespace CJSystemapi +} // namespace OHOS +#endif // OHOS_FILE_FS_LSEEK_H