互联网 医疗网站建设有哪些城市/衡阳seo服务
Utils子系统是OpenHarmony的公共基础库,存放OpenHarmony通用的基础组件。这些基础组件可被OpenHarmony各业务子系统及上层应用所使用。公共基础库在不同平台上提供的能力:
- LiteOS-M内核:KV(key value)存储、文件操作、定时器、Dump系统属性。
- LiteOS-A内核:KV(key value)存储、定时器、JS API(设备查询,数据存储)、Dump系统属性。
本文介绍下移植开发板时如何适配utils子系统之file文件操作部件,并介绍下相关的运行机制原理。系统属性部件syspara_lite包含系统参数特性syspara_lite和token。file文件操作部件定义在utils\native\lite\。源代码目录如下:
utils/native/lite/ # 公共基础库根目录
├── file # 文件接口实现
├── hals # HAL目录
│ └── file # 文件操作硬件抽象层头文件
├── include # 公共基础库对外接口文件
├── js # JS API目录
│ └── builtin
│ ├── common
│ ├── deviceinfokit # 设备信息Kit
│ ├── filekit # 文件Kit
│ └── kvstorekit # KV存储Kit
├── kal # KAL目录
│ └── timer # Timer的KAL实现
├── kv_store # KV存储实现
│ ├── innerkits # KV存储内部接口
│ └── src # KV存储源文件
├── memory
│ └── include # 内存池管理接口
├── os_dump # Dump系统属性
└── timer_task # Timer实现
1、file文件操作部件适配示例
1.1 配置产品解决方案config.json
utils子系统之file文件操作部件的适配示例可以参考vendor\ohemu\qemu_csky_mini_system_demo\config.json,代码片段如下。⑴处用于配置子系统的file部件。⑵处指定在开发板目录中适配目录,这个适配目录下需要创建目录device\qemu\SmartL_E802\adapter\hals\utils\file\。为什么配置这个目录,后文会解析。
{"subsystem": "utils","components": [
⑴ { "component": "file", "features":[] },{ "component": "kv_store", "features":[] }]}],
⑵ "vendor_adapter_dir": "//device/qemu/SmartL_E802/adapter",
1.2 适配hal_file.h文件中的接口
在文件utils\native\lite\hals\file\hal_file.h头文件中,定义了文件操作接口,适配开发板时,如果需要使用utils子系统之file文件操作部件,就要适配这些接口。需要适配的接口如下。HalFileOpen()函数返回值是文件描述符fd,可以被其他带int fd参数的函数使用。
int HalFileOpen(const char* path, int oflag, int mode);int HalFileClose(int fd);int HalFileRead(int fd, char* buf, unsigned int len);int HalFileWrite(int fd, const char* buf, unsigned int len);int HalFileDelete(const char* path);int HalFileStat(const char* path, unsigned int* fileSize);int HalFileSeek(int fd, int offset, unsigned int whence);
文件device\qemu\SmartL_E802\adapter\hals\utils\file\src\hal_file.c可以作为参考示例,演示如何适配上述接口。⑴处的HalFileOpen()函数中,先组装文件路径,"/littlefs"是SmartL_E802开发板设置的LFS文件默认挂载点,关于LFS的适配请参考device\qemu\SmartL_E802\liteos_m\board\fs\fs_init.c。HalFileXXX函数调用的open、close、read、write、unlink、stat、lseek等函数定义在kernel\liteos_m\kal\libc\musl\fs.c或kernel\liteos_m\kal\libc\newlib\porting\src\fs.c,这个取决于使用的是musl C库还是newlib C库。文件系统接口调用链如下所示:UtilsFileXXX(utils\native\lite\file\src\file_impl_hal\file.c)-> HalFileXXXX(device\qemu\SmartL_E802\adapter\hals\utils\file\src\hal_file.c) -> open/read/write/…(kernel\liteos_m\kal\libc\musl\fs.c或kernel\liteos_m\kal\libc\newlib\porting\src\fs.c) -> LOS_XXXX(kernel\liteos_m\components\fs\vfs\los_fs.c) -> Lfs_XXXX(kernel\liteos_m\components\fs\littlefs\lfs_api.c) -> lfs_file_XXX (third_party\littlefs\lfs.c) -> Littlefs*(device\qemu\SmartL_E802\liteos_m\board\fs\littlefs_hal.c)。
int HalFileOpen(const char* path, int oflag, int mode){char tmpPath[LITTLEFS_MAX_LFN_LEN] = {0};
⑴ (void)snprintf_s(tmpPath, LITTLEFS_MAX_LFN_LEN, LITTLEFS_MAX_LFN_LEN, "/littlefs/%s", path);return open(tmpPath, oflag, mode);}int HalFileClose(int fd){return close(fd);}int HalFileRead(int fd, char *buf, unsigned int len){return read(fd, buf, len);}int HalFileWrite(int fd, const char *buf, unsigned int len){return write(fd, buf, len);}int HalFileDelete(const char *path){char tmpPath[LITTLEFS_MAX_LFN_LEN] = {0};(void)snprintf_s(tmpPath, LITTLEFS_MAX_LFN_LEN, LITTLEFS_MAX_LFN_LEN, "/littlefs/%s", path);return unlink(path);}int HalFileStat(const char *path, unsigned int *fileSize){char tmpPath[LITTLEFS_MAX_LFN_LEN] = {0};struct stat halStat ;int ret = 0;(void)snprintf_s(tmpPath, LITTLEFS_MAX_LFN_LEN, LITTLEFS_MAX_LFN_LEN, "/littlefs/%s", path);ret = stat(tmpPath, &halStat);*fileSize = halStat.st_size;return ret;}int HalFileSeek(int fd, int offset, unsigned int whence){return lseek(fd, (off_t)offset, whence);}
2、file文件操作部件代码分析
2.1 部件的头文件
上文已经知道,file文件操作部件代码的头文件为utils\native\lite\include\utils_file.h,用户程序可以使用该头文件中定义的接口。
int UtilsFileOpen(const char* path, int oflag, int mode);int UtilsFileClose(int fd);int UtilsFileRead(int fd, char* buf, unsigned int len);int UtilsFileWrite(int fd, const char* buf, unsigned int len);int UtilsFileDelete(const char* path);int UtilsFileStat(const char* path, unsigned int* fileSize);int UtilsFileSeek(int fd, int offset, unsigned int whence);int UtilsFileCopy(const char* src, const char* dest);int UtilsFileMove(const char* src, const char* dest);
头文件utils\native\lite\hals\file\hal_file.h中定义的接口,需要移植适配时提供实现,具体接口见上文。
2.2 部件的源代码文件
文件utils\native\lite\file\src\file_impl_hal\file.c中实现了UtilsFileXXX接口,代码比较简单,调用需要开发板移植适配的HalFileXXX接口。
int UtilsFileOpen(const char* path, int oflag, int mode)
{return HalFileOpen(path, oflag, mode);
}int UtilsFileClose(int fd)
{return HalFileClose(fd);
}int UtilsFileRead(int fd, char* buf, unsigned int len)
{return HalFileRead(fd, buf, len);
}int UtilsFileWrite(int fd, const char* buf, unsigned int len)
{return HalFileWrite(fd, buf, len);
}int UtilsFileDelete(const char* path)
{return HalFileDelete(path);
}int UtilsFileStat(const char* path, unsigned int* fileSize)
{return HalFileStat(path, fileSize);
}int UtilsFileSeek(int fd, int offset, unsigned int whence)
{return HalFileSeek(fd, offset, whence);
}int UtilsFileCopy(const char* src, const char* dest)
{if ((src == NULL) || (dest == NULL)) {return EC_FAILURE;}int fpSrc = UtilsFileOpen(src, O_RDONLY_FS, 0);if (fpSrc < 0) {return fpSrc;}int fpDest = UtilsFileOpen(dest, O_RDWR_FS | O_CREAT_FS | O_TRUNC_FS, 0);if (fpDest < 0) {UtilsFileClose(fpSrc);return fpDest;}bool copyFailed = true;char* dataBuf = (char *)malloc(BUFFER_SIZE);if (dataBuf == NULL) {goto MALLOC_ERROR;}int nLen = UtilsFileRead(fpSrc, dataBuf, BUFFER_SIZE);while (nLen > 0) {if (UtilsFileWrite(fpDest, dataBuf, nLen) != nLen) {goto EXIT;}nLen = UtilsFileRead(fpSrc, dataBuf, BUFFER_SIZE);}copyFailed = (nLen < 0);EXIT:free(dataBuf);
MALLOC_ERROR:UtilsFileClose(fpSrc);UtilsFileClose(fpDest);if (copyFailed) {UtilsFileDelete(dest);return EC_FAILURE;}return EC_SUCCESS;
}int UtilsFileMove(const char* src, const char* dest)
{int ret = UtilsFileCopy(src, dest);if (ret == EC_SUCCESS) {ret = UtilsFileDelete(src);}return ret;
}
2.3 部件的编译构建
编译构建配置文件utils\native\lite\file\BUILD.gn代码如下,⑴处的配置项ohos_board_adapter_dir为产品解决方案配置文件config.json中定义的开发板适配目录。可以看出来:
- 开发板适配目录必须包含目录hals/utils/file
- 目录hals/utils/file同级的BUILD.gn文件中,构建目标必须为hal_file_static。不能随意命名。
import("//build/lite/config/component/lite_component.gni")static_library("native_file") {sources = [ "src/file_impl_hal/file.c" ]include_dirs = ["//utils/native/lite/include","//utils/native/lite/hals/file",]
⑴ deps = [ "$ohos_board_adapter_dir/hals/utils/file:hal_file_static" ]}lite_component("file") {features = [ ":native_file" ]}
小结
本文介绍了utils子系统之file文件操作部件的移植适配案例,分析了部件源代码。
如果大家想更加深入的学习 OpenHarmony 开发的内容,不妨可以参考以下相关学习文档进行学习,助你快速提升自己:
OpenHarmony 开发环境搭建:https://qr18.cn/CgxrRy
《OpenHarmony源码解析》:https://qr18.cn/CgxrRy
- 搭建开发环境
- Windows 开发环境的搭建
- Ubuntu 开发环境搭建
- Linux 与 Windows 之间的文件共享
- ……
系统架构分析:https://qr18.cn/CgxrRy
- 构建子系统
- 启动流程
- 子系统
- 分布式任务调度子系统
- 分布式通信子系统
- 驱动子系统
- ……
OpenHarmony 设备开发学习手册:https://qr18.cn/CgxrRy
OpenHarmony面试题(内含参考答案):https://qr18.cn/CgxrRy
写在最后
- 如果你觉得这篇内容对你还蛮有帮助,我想邀请你帮我三个小忙:
- 点赞,转发,有你们的 『点赞和评论』,才是我创造的动力。
- 关注小编,同时可以期待后续文章ing🚀,不定期分享原创知识。
- 想要获取更多完整鸿蒙最新学习资源,请移步前往小编:
https://qr21.cn/FV7h05
相关文章:

移植案例与原理 - utils子系统之file文件操作部件
Utils子系统是OpenHarmony的公共基础库,存放OpenHarmony通用的基础组件。这些基础组件可被OpenHarmony各业务子系统及上层应用所使用。公共基础库在不同平台上提供的能力: LiteOS-M内核:KV(key value)存储、文件操作、定时器、Dump系统属性。…...

个股期权有哪些股票?金融新手必须知道!
今天带你了解个股期权有哪些股票?在中国的股票市场中,个股期权是一种衍生品,允许投资者购买或卖出特定股票的期权合约。 个股期权有哪些股票? 个股期权是指在特定时间内,以特定价格买入或卖出特定数量的某只个股的权利…...

平庸的学术工作者
自己进入学术这条路,差不多十年了,回想自己目前的成果,自我评价为平庸。如果将同领域清华的年轻学者打分为 100 分的话,我将自己打分 65。 到目前为止,并不觉得智力因素在管理科学与工程领域的科研中有太大决定作用&a…...

安卓软件自动运行插件的开发源代码介绍!
随着移动互联网的快速发展,安卓操作系统凭借其开放性和灵活性,成为了众多开发者们的首选平台,在安卓应用的开发中,为了实现各种复杂的功能,插件化技术逐渐受到青睐。 其中,自动运行插件作为一种能够实现应…...

小程序餐饮点餐系统,扫码下单点菜,消费端+配送端+收银端+理端
目录 前言: 一、小程序功能有哪些 前端: 管理端: 二、实体店做小程序的好处 方便快捷的点餐和支付体验: 扩大店铺的曝光度和影响力: 优化顾客体验和服务质量: 降低成本和提高效率: 数据…...

说说你这个项目的架构情况吧?
说说你这个项目的架构情况吧? 从整体部署情况上,目前这个项目部署在两台服务器上,每台服务器部署一套应用在里面,如果某个服务挂了也不会影响到我们的整体的服务提供。当然,如果我们的服务器资源宽裕的话,可…...

接口响应时间测试
curl 要使用 curl 测试一个接口的响应时间具体步骤和命令示例: 打开你的终端或命令行工具。 使用 curl 命令并添加 -w(或者 --write-out)参数来输出时间统计信息。 示例命令: curl -o /dev/null -s -w "Time to Connect: %{time_connect}\nTime to Start Transfer: …...

C++ 61 之 函数模版
#include <iostream> #include <string> using namespace std;void swapInt(int &a,int &b){int temp a;a b;b temp; }void swapDou(double& a, double& b){double temp a;a b;b temp; }// T代表通用数据类型,紧接着后面的代码&a…...

甘特图如何画以及具体实例详解
甘特图如何画以及具体实例详解 甘特图是一种常见的项目管理工具又称为横道图、条状图(Bar chart)。是每一位项目经理和PMO必须掌握的项目管理工具。甘特图通过条状图来显示项目、进度和其他时间相关的系统进展的内在关系随着时间进展的情况。但是多项目经理和PMO虽然考了各种证…...

Android SDK版本号与API Level 的对应关系
自从Android 1.5系统以来,谷歌习惯于用甜点为每个版本的移动操作系统命名,而且按字母顺序排列,这个传统始于八年多以前,从早期的Android1.5 C(Cupcake)、Android 1.6 D(Donut)到最近…...

AES加解密工具类
文章目录 前言一、AES加解密工具类总结 前言 当涉及到数据的安全性和保密性时,加密是一种关键的技术手段。AES(Advanced Encryption Standard)是一种广泛使用的对称加密算法,被认为是目前最安全和最常用的加密算法之一。 一、AES…...

Http协议JSON格式
1. 计算机网络 计算机网络是指将地理位置不同的具有独立功能的多台计算机及其外部设备,通过通信线路连接起来,在网络操作系统,网络管理软件及网络通信协议的管理和协调下,实现资源共享和信息传递的计算机系统。 思考:计算机网络…...

【算法与设计】期末总结
文章目录 第一章 概述算法与程序时间复杂性求上界 第二章 递归与分治双递归函数——Ackerman函数分治策略大整数乘法两位两位四位x四位 三位x三位两位x六位 第三章 动态规划矩阵连乘基本要素最优子结构子问题重叠 备忘录 第四章 贪心算法活动安排问题基本要素贪心选择性质最优子…...

odoo报错KeyError: ‘ir.http‘
使用odoo17代码,python3.10.11配好的开发环境,当启动以后,浏览器登录访问的时候,后台报错 ERROR odoo_db odoo.modules.loading: Database odoo_db not initialized, you can force it with -i base File "/opt/odoo/odoo/o…...

每日的影视作品推荐❗❗
每日的影视作品推荐:剧名:《无法抗拒的男友们》主演:王子清、文苡帆 推荐理由:演技出色:王子清和文苡帆的演技非常出色,他们将角色间的情感变化演绎得细腻而真实,让人仿佛身临其境。 情感深刻&a…...

css 文字下划线 text-decoration
背景: 在某些时候需要给文字添加特殊样式。使用 text-decoration: underline; 来为段落文字添加下划线。也有其它文本装饰样式,例如: none:无装饰(去掉装饰)overline:上划线line-through&…...

Java-01-基础篇-04 Java集合-04-HashMap (源码)
目录 一,HashMap 1.1 HashMap 属性分析 1.2 HashMap 构造器 1.3 HashMap 内置的 Node 类 1.4 HashMap 内置的 KeySet 类 1.5 HashMap 内置的 Values 类 1.6 HashMap 内置的 EntrySet 类 1.7 HashMap 内置的 UnsafeHolder 类 1.8 HashMap 相关的迭代器 1.9…...

开源语音合成模型ChatTTS本地部署结合内网穿透实现远程访问
文章目录 前言1. 下载运行ChatTTS模型2. 安装Cpolar工具3. 实现公网访问4. 配置ChatTTS固定公网地址 前言 本篇文章就教大家如何快速地在Windows中本地部署ChatTTS,并且我们还可以结合Cpolar内网穿透实现公网随时随地访问ChatTTS AI语言模型。 最像人声的AI来了&a…...

超多细节—app图标拖动排序实现详解
前言: 最近做了个活动需求大致类似于一个拼图游戏,非常接近于咱们日常app拖动排序的场景。所以想着好好梳理一下,改造改造干脆在此基础上来写一篇实现app拖动排序的文章,跟大家分享下这个大家每天都要接触的场景,到底…...

基于深度学习的文字识别
基于深度学习的文字识别 基于深度学习的文字识别(Optical Character Recognition, OCR)是指利用深度神经网络模型自动识别和提取图像中的文字内容。这一技术在文档数字化、自动化办公、车牌识别、手写识别等多个领域有着广泛的应用。 深度学习OCR的基本…...

Pikachu靶场--文件包含
参考借鉴 Pikachu靶场之文件包含漏洞详解_pikachu文件包含-CSDN博客 文件包含(CTF教程,Web安全渗透入门)__bilibili File Inclusion(local) 查找废弃隐藏文件 随机选一个然后提交查询 URL中出现filenamefile2.php filename是file2.php&…...

get put post delete 区别以及幂等
GET 介绍:GET请求用于从服务器获取资源,通常用于获取数据。它的参数会附加在URL的末尾,可以通过URL参数传递数据。GET请求是幂等的,即多次请求同一个URL得到的结果应该是一样的,不会对服务器端产生影响。 特点…...

ultralytics版本及对应的更新
Ultralytics Ultralytics 是一家专注于计算机视觉和深度学习工具的公司,尤以其开源的 YOLO (You Only Look Once) 系列深受欢迎。目前,Ultralytics 主要管理和开发 YOLOv5 和 YOLOv8。以下是各个版本的概述及其主要更新: YOLOv5 YOLOv5 是…...

在现代编程环境中,Perl 如何与其他流行语言(如 Python、Java 等)进行集成和协作?
在现代编程环境中,Perl 可以与其他流行语言(如 Python、Java 等)进行集成和协作。以下是一些常见的方法: 调用外部程序:Perl 可以使用系统调用来执行其他语言编写的可执行文件。这意味着可以从 Perl 中调用 Python、Ja…...

BEV 中 multi-frame fusion 多侦融合(一)
文章目录 参数设置align_dynamic_thing:为了将动态物体的点云数据从上一帧对齐到当前帧流程旋转函数平移公式filter_points_in_ego:筛选出属于特定实例的点get_intermediate_frame_info: 函数用于获取中间帧的信息,包括点云数据、传感器校准信息、自车姿态、边界框及其对应…...

“Docker操作案例实践“
目录 1. 下载nginx 2. Portainer可视化 1. 下载nginx 步骤: 搜索nginx:docker search nginx;下载镜像:docker pull nginx ;查看镜像:docker images ;后台运行 :docker run -d -na…...

Redis 管道
Redis的消息交互 当我们使用客户端对Redis进行一次操作时,如下图所示,客户端将请求传送给服务器,服务器处理完毕后,再将响应回复给客户端,这要花费一个网络数据包来回的时间。 如果连续执行多条指令,那就会…...

ubuntu20.04安装配置openMVG+openMVS
安装 主要跟着官方教程逐步安装 openMVG https://github.com/openMVG/openMVG/blob/master/BUILD.md openMVS https://github.com/cdcseacave/openMVS/wiki/Building 注意事项 1. 库版本要求 使用版本: openMVS 2.2.0 openMVG Eigen 3.4.0 OpenCV 4.6.0 Ce…...

使用CSS常见问题解答卡片
常见问题解答卡片 效果展示 CSS 知识点 CSS 选择器的使用background 渐变背景色运用CSS 综合知识运用 页面整体布局 <div class"container"><h1>经常问的问题</h1><!-- 这里只是展示一个项目 --><div class"tab"><in…...

Kong AI Gateway 正式 GA !
Kong Gateway 3.7 版本已经重磅上线,我们给 AI Gateway 带来了一系列升级,下面是 AI Gateway 的更新亮点一览。 AI Gateway 正式 GA 在 Kong Gateway 的最新版本 3.7 中,我们正式宣布 Kong AI Gateway 达到了通用可用性(GA&…...