Decouple the ohos code of drivers based on th Pegasus architecture.

Signed-off-by: zk <longzhuokun1@huawei.com>
This commit is contained in:
longzhuokun
2022-11-14 15:45:23 +08:00
parent 03c7da58c0
commit 822f77bd73
4 changed files with 156 additions and 1 deletions
+9 -1
View File
@@ -19,7 +19,15 @@ static_library("native_file") {
"//commonlibrary/utils_lite/include",
"//commonlibrary/utils_lite/hals/file",
]
deps = [ "$ohos_board_adapter_dir/hals/utils/file:hal_file_static" ]
BOARD_DRIVER_HAL_FILE_PATH =
rebase_path("//${ohos_board_adapter_dir}/hals/utils/file")
cmd = "if [ -f ${BOARD_DRIVER_HAL_FILE_PATH}/BUILD.gn ]; then echo true; else echo false; fi"
BOARD_DRIVER_HAL_FILE_PATH_EXISTS =
exec_script("//build/lite/run_shell_cmd.py", [ cmd ], "value")
if (BOARD_DRIVER_HAL_FILE_PATH_EXISTS) {
deps = [ "$ohos_board_adapter_dir/hals/utils/file:hal_file_static" ]
}
deps += [ "//commonlibrary/utils_lite/hals/file:static_hal_file" ]
}
lite_component("file") {
+24
View File
@@ -0,0 +1,24 @@
# Copyright (c) 2022 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.
import("//build/ohos.gni")
ohos_static_library("static_hal_file") {
sources = [ "hal_file.c" ]
include_dirs = [
"//utils/native/lite/include",
"//utils/native/lite/hals/file",
"//commonlibrary/utils_lite/hals/file",
]
}
+63
View File
@@ -0,0 +1,63 @@
/* Copyright (c) 2022 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.
*/
/*
* @addtogroup Filesystem
* @{
*
* @brief 提供文件操作基本能力
*/
/*
* @file fs.h
*
* @brief 文件系统对外接口和数据结构
*/
#ifndef FS_H
#define FS_H
#include "fcntl.h"
#include "stdint.h"
#include "sys/mount.h"
#include "sys/stat.h"
#include "sys/statfs.h"
#include "unistd.h"
#include "dirent.h"
#include "errno.h"
#include "stdio.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif
#endif /* End of #ifdef __cplusplus */
/*
* @brief 获取分区剩余空间大小.
* @param path 分区路径.
* @param totalSize 分区总空间.
* @param freeSize 分区剩余可用空间.
* @return 返回FR_OK表示成功,否则返回失败错误码.
*/
int32_t FS_GetPartitionSize(const char *path, uint32_t *totalSize, uint32_t *freeSize);
#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif /* End of #ifdef __cplusplus */
#endif /* End of #ifndef FS_H */
/** @} */
+60
View File
@@ -0,0 +1,60 @@
/* Copyright (c) 2022 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 "hal_file.h"
#include "fcntl.h"
#include "fs.h"
__attribute__((weak)) int HalFileOpen(const char *path, int oflag, int mode)
{
(void)mode;
return open(path, oflag);
}
__attribute__((weak)) int HalFileClose(int fd)
{
return close(fd);
}
__attribute__((weak)) int HalFileRead(int fd, char *buf, unsigned int len)
{
return read(fd, buf, len);
}
__attribute__((weak)) int HalFileWrite(int fd, const char *buf, unsigned int len)
{
return write(fd, buf, len);
}
__attribute__((weak)) int HalFileDelete(const char *path)
{
return unlink(path);
}
__attribute__((weak)) int HalFileStat(const char *path, unsigned int *fileSize)
{
struct stat info = { 0 };
int ret = stat(path, &info);
if (ret < 0) {
return ret;
} else {
return info.st_size;
}
}
__attribute__((weak)) int HalFileSeek(int fd, int offset, unsigned int whence)
{
return lseek(fd, offset, whence);
}