Compare commits
79 Commits
weekly_202
...
OpenHarmon
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fcd677feba | ||
|
|
c4fd9be138 | ||
|
|
81249a0384 | ||
|
|
8746f5abe5 | ||
|
|
56565beeb6 | ||
|
|
a77aa7de98 | ||
|
|
db8c284cd1 | ||
|
|
b1daca7f82 | ||
|
|
46546688c9 | ||
|
|
d017af7459 | ||
|
|
4e9f8c71f9 | ||
|
|
e34c4050f9 | ||
|
|
67b579161d | ||
|
|
d5b90399b7 | ||
|
|
1ab2ffcd4a | ||
|
|
ec9f0e47e9 | ||
|
|
8550117b01 | ||
|
|
f29973e995 | ||
|
|
9e0e39f277 | ||
|
|
2f19ba3653 | ||
|
|
fe7191183e | ||
|
|
d84471ff29 | ||
|
|
45654cee93 | ||
|
|
110ee01118 | ||
|
|
b51e7f93d4 | ||
|
|
2d9e476c0b | ||
|
|
9ee49f1bb8 | ||
|
|
befe8ecf9d | ||
|
|
637de91170 | ||
|
|
390a488a97 | ||
|
|
9d3d983376 | ||
|
|
0e2dded346 | ||
|
|
b0393151a6 | ||
|
|
38f8472ddb | ||
|
|
7167ba7578 | ||
|
|
d28c8a0423 | ||
|
|
17daa50fa2 | ||
|
|
57a0002252 | ||
|
|
4f12ab9a2a | ||
|
|
e703376d68 | ||
|
|
8f1dc3a1ff | ||
|
|
9bf8ff9ce5 | ||
|
|
a09d4882c4 | ||
|
|
98a82ba357 | ||
|
|
e7e850a6a6 | ||
|
|
3ad47afec4 | ||
|
|
6f04b5345c | ||
|
|
83b6331aad | ||
|
|
67a5b580f6 | ||
|
|
f5ee192962 | ||
|
|
a42ba7aed6 | ||
|
|
1fc024a158 | ||
|
|
21ee0b2c1d | ||
|
|
b0cfa5e52c | ||
|
|
543732f522 | ||
|
|
dab1a0d62f | ||
|
|
6a8f24ba01 | ||
|
|
40bbb4d6c4 | ||
|
|
90a027090a | ||
|
|
bcd177bbd3 | ||
|
|
cde2b3bd31 | ||
|
|
e3e9b2f5a5 | ||
|
|
536e9b4584 | ||
|
|
632ea10418 | ||
|
|
73b77d11a1 | ||
|
|
9aa32ae743 | ||
|
|
133e87b1b1 | ||
|
|
09034de68a | ||
|
|
867a6edcdc | ||
|
|
3dceae52aa | ||
|
|
43baa4fdc4 | ||
|
|
bedef30658 | ||
|
|
7e284239b3 | ||
|
|
f34b94e98d | ||
|
|
bc33bcd319 | ||
|
|
ae7a374ebb | ||
|
|
fb76350771 | ||
|
|
ea5b2e8ae4 | ||
|
|
c5a3ed4fb1 |
17
Kconfig
17
Kconfig
@@ -1,5 +1,5 @@
|
||||
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification,
|
||||
# are permitted provided that the following conditions are met:
|
||||
@@ -317,7 +317,7 @@ config CPUP_INCLUDE_IRQ
|
||||
help
|
||||
If you wish to include irq usage for cpup.
|
||||
|
||||
config DYNLINK
|
||||
config KERNEL_DYNLINK
|
||||
bool "Enable Dynamic Link Feature"
|
||||
default n
|
||||
depends on KERNEL_EXTKERNEL && ARCH_ARM
|
||||
@@ -369,7 +369,7 @@ config KERNEL_LMK
|
||||
default n
|
||||
depends on KERNEL_EXTKERNEL
|
||||
help
|
||||
Configuration item for low momery killer tailoring.
|
||||
Configuration item for low memory killer tailoring.
|
||||
If you wish to build LiteOS with support for low memory killer.
|
||||
|
||||
config KERNEL_LMK_DEBUG
|
||||
@@ -574,7 +574,7 @@ config MEM_LEAKCHECK
|
||||
depends on DEBUG_VERSION && MEM_DEBUG
|
||||
select KERNEL_BACKTRACE
|
||||
help
|
||||
Answer Y to enable record the LR of Function call stack of Mem operation, it can check the mem leak through the infomations of mem node.
|
||||
Answer Y to enable record the LR of Function call stack of Mem operation, it can check the mem leak through the informations of mem node.
|
||||
config BASE_MEM_NODE_INTEGRITY_CHECK
|
||||
bool "Enable integrity check or not"
|
||||
default n
|
||||
@@ -600,11 +600,11 @@ endmenu
|
||||
|
||||
######################## config options os security #######################
|
||||
menu "Security"
|
||||
osource "security/Kconfig"
|
||||
config SECURE_TRUSTZONE
|
||||
bool "Enable ARM TrustZone"
|
||||
default n
|
||||
depends on ARCH_ARM
|
||||
depends on ARCH_ARM_V8M
|
||||
config SECURE_HEAP_SIZE
|
||||
int "TrustZone Heap Size (bytes)"
|
||||
default 2048
|
||||
@@ -615,6 +615,13 @@ config SECURE_STACK_DEFAULT_SIZE
|
||||
depends on SECURE_TRUSTZONE
|
||||
help
|
||||
The secure stack must be allocated before the task calls non-secure functions.
|
||||
config SECURE
|
||||
bool "Enable Security"
|
||||
default n
|
||||
select MPU_ENABLE
|
||||
config MPU_ENABLE
|
||||
bool "Enable MPU"
|
||||
default n
|
||||
endmenu
|
||||
|
||||
menu "Test"
|
||||
|
||||
@@ -85,11 +85,11 @@ Before setting up the environment for a development board, you must set up the b
|
||||
|
||||
For details about how to obtain the source code, see [Source Code Acquisition](https://gitee.com/openharmony/docs/blob/HEAD/en/device-dev/get-code/sourcecode-acquire.md). This document assumes that the clone directory is `~/openHarmony` after the complete OpenHarmony repository code is obtained.
|
||||
|
||||
### Example projects that are already supported
|
||||
### Example projects
|
||||
|
||||
Qemu simulator: `arm_mps2_an386、esp32、riscv32_virt、SmartL_E802`, For details about how to compile and run, see [qemu guide](https://gitee.com/openharmony/device_qemu)
|
||||
Qemu simulator: `arm_mps2_an386、esp32、riscv32_virt、SmartL_E802`. For details about how to compile and run, see [qemu guide](https://gitee.com/openharmony/device_qemu).
|
||||
|
||||
Bestechnic: `bes2600`, For details about how to compile and run, see [Bestechnic developer guide](https://gitee.com/openharmony/device_soc_bestechnic)
|
||||
Bestechnic: `bes2600`. For details about how to compile and run, see [Bestechnic developer guide](https://gitee.com/openharmony/device_soc_bestechnic).
|
||||
|
||||
### Community Porting Project Links
|
||||
|
||||
@@ -131,4 +131,4 @@ How to contribute a chip based on Liteos-M kernel:
|
||||
|
||||
[Kernel Subsystem](https://gitee.com/openharmony/docs/blob/HEAD/en/readme/kernel-subsystem.md)
|
||||
|
||||
**kernel\_liteos\_m**
|
||||
[kernel\_liteos\_m](https://gitee.com/openharmony/kernel_liteos_m/blob/master/README.md)
|
||||
|
||||
@@ -131,5 +131,5 @@ LiteOS-M内核移植的具体开发板的工程由社区开发者提供,可以
|
||||
|
||||
[内核子系统](https://gitee.com/openharmony/docs/blob/HEAD/zh-cn/readme/%E5%86%85%E6%A0%B8%E5%AD%90%E7%B3%BB%E7%BB%9F.md)
|
||||
|
||||
**kernel\_liteos\_m**
|
||||
[kernel\_liteos\_m](https://gitee.com/openharmony/kernel_liteos_m/blob/master/README_zh.md)
|
||||
|
||||
|
||||
@@ -39,7 +39,8 @@ module_group("arch") {
|
||||
"$board_cpu" == "cortex-m4" || "$board_cpu" == "cortex-m7" ||
|
||||
"$board_cpu" == "cortex-m33" || "$board_cpu" == "cortex-m55") {
|
||||
modules += [ "arm" ]
|
||||
} else if ("$board_cpu" == "ck802" || "$board_cpu" == "e802") {
|
||||
} else if ("$board_cpu" == "ck802" || "$board_cpu" == "e802" ||
|
||||
"$board_cpu" == "ck804ef") {
|
||||
modules += [ "csky" ]
|
||||
} else if ("$board_cpu" == "") {
|
||||
if ("$board_arch" == "rv32imac" || "$board_arch" == "rv32imafdc") {
|
||||
|
||||
@@ -16,12 +16,16 @@ config ARCH_ARM_AARCH32
|
||||
config ARCH_ARM_V7M
|
||||
bool
|
||||
|
||||
config ARCH_ARM_V8M
|
||||
bool
|
||||
|
||||
config ARCH_ARM_V5TE
|
||||
bool
|
||||
|
||||
config ARCH_ARM_VER
|
||||
string
|
||||
default "armv7-m" if ARCH_ARM_V7M
|
||||
default "armv8-m" if ARCH_ARM_V8M
|
||||
default "armv5te" if ARCH_ARM_V5TE
|
||||
|
||||
#
|
||||
@@ -84,23 +88,20 @@ config ARCH_CORTEX_M7
|
||||
select ARCH_ARM_AARCH32
|
||||
select ARCH_FPU_VFP_V4
|
||||
select ARCH_FPU_VFP_D32
|
||||
select ARCH_FPU_VFP_NEON
|
||||
|
||||
config ARCH_CORTEX_M33
|
||||
bool
|
||||
select ARCH_ARM_V7M
|
||||
select ARCH_ARM_V8M
|
||||
select ARCH_ARM_AARCH32
|
||||
select ARCH_FPU_VFP_V4
|
||||
select ARCH_FPU_VFP_D32
|
||||
select ARCH_FPU_VFP_NEON
|
||||
|
||||
config ARCH_CORTEX_M55
|
||||
bool
|
||||
select ARCH_ARM_V7M
|
||||
select ARCH_ARM_V8M
|
||||
select ARCH_ARM_AARCH32
|
||||
select ARCH_FPU_VFP_V4
|
||||
select ARCH_FPU_VFP_D32
|
||||
select ARCH_FPU_VFP_NEON
|
||||
|
||||
config ARCH_ARM9
|
||||
bool
|
||||
|
||||
@@ -76,6 +76,7 @@ LITE_OS_SEC_TEXT_MINOR VOID ArchSysExit(VOID)
|
||||
LITE_OS_SEC_TEXT_INIT VOID *ArchTskStackInit(UINT32 taskID, UINT32 stackSize, VOID *topStack)
|
||||
{
|
||||
TaskContext *context = (TaskContext *)((UINTPTR)topStack + stackSize - sizeof(TaskContext));
|
||||
LosTaskCB *taskCB = OS_TCB_FROM_TID(taskID);
|
||||
|
||||
context->r0 = taskID;
|
||||
context->r1 = 0x01010101L;
|
||||
|
||||
@@ -163,7 +163,6 @@ inline UINT32 ArchIsIntActive(VOID)
|
||||
Output : None
|
||||
Return : None
|
||||
**************************************************************************** */
|
||||
/*lint -e529*/
|
||||
LITE_OS_SEC_TEXT_MINOR VOID HalHwiDefaultHandler(VOID)
|
||||
{
|
||||
PRINT_ERR("%s irqnum:%u\n", __FUNCTION__, HwiNumGet());
|
||||
|
||||
0
arch/arm/cortex-m3/keil/los_atomic.S
Executable file → Normal file
0
arch/arm/cortex-m3/keil/los_atomic.S
Executable file → Normal file
@@ -190,7 +190,7 @@ _hwiActiveCheck
|
||||
CMP R3, #0
|
||||
BEQ _hwiActiveCheckNext
|
||||
|
||||
; exc occured in IRQ
|
||||
; exc occurred in IRQ
|
||||
ORR R0, R0, #FLAG_HWI_ACTIVE
|
||||
RBIT R2, R3
|
||||
CLZ R2, R2
|
||||
@@ -228,19 +228,19 @@ _hwiActiveCheckNext
|
||||
AND R2, R2,R3
|
||||
CMP R2,#0
|
||||
BNE _ExcInMSP
|
||||
; exc occured in Task or Init or exc
|
||||
; exc occurred in Task or Init or exc
|
||||
; reserved for register info from task stack
|
||||
|
||||
LDR R2, =g_taskScheduled
|
||||
LDR R2, [R2]
|
||||
TST R2, #1 ; OS_FLG_BGD_ACTIVE
|
||||
BEQ _ExcInMSP ; if exc occured in Init then branch
|
||||
BEQ _ExcInMSP ; if exc occurred in Init then branch
|
||||
|
||||
|
||||
CMP LR, #0xFFFFFFED ;auto push floating registers
|
||||
BNE _NoFloatInPsp
|
||||
|
||||
; exc occured in Task
|
||||
; exc occurred in Task
|
||||
MOV R2, R13
|
||||
SUB R13, #96 ; add 8 Bytes reg(for STMFD)
|
||||
|
||||
|
||||
@@ -40,14 +40,12 @@
|
||||
#include "los_memory.h"
|
||||
#include "los_membox.h"
|
||||
|
||||
/*lint -save -e40 -e522 -e533*/
|
||||
UINT32 g_intCount = 0;
|
||||
|
||||
/*lint -restore*/
|
||||
#ifdef __ICCARM__
|
||||
#pragma location = ".data.vector"
|
||||
#elif defined(__CC_ARM) || defined(__GNUC__)
|
||||
#pragma data_alignment=LOSCFG_ARCH_HWI_VECTOR_ALIGN
|
||||
#pragma data_alignment = LOSCFG_ARCH_HWI_VECTOR_ALIGN
|
||||
LITE_OS_SEC_VEC
|
||||
#endif
|
||||
/* *
|
||||
@@ -198,7 +196,6 @@ inline UINT32 ArchIsIntActive(VOID)
|
||||
Output : None
|
||||
Return : None
|
||||
**************************************************************************** */
|
||||
/*lint -e529*/
|
||||
LITE_OS_SEC_TEXT_MINOR VOID HalHwiDefaultHandler(VOID)
|
||||
{
|
||||
PRINT_ERR("%s irqnum:%u\n", __FUNCTION__, HwiNumGet());
|
||||
@@ -602,7 +599,7 @@ LITE_OS_SEC_TEXT_INIT VOID HalHwiInit(VOID)
|
||||
|
||||
/* Enable USGFAULT, BUSFAULT, MEMFAULT */
|
||||
*(volatile UINT32 *)OS_NVIC_SHCSR |= (USGFAULT | BUSFAULT | MEMFAULT);
|
||||
|
||||
|
||||
/* Enable DIV 0 and unaligned exception */
|
||||
#ifdef LOSCFG_ARCH_UNALIGNED_EXC
|
||||
*(volatile UINT32 *)OS_NVIC_CCR |= (DIV0FAULT | UNALIGNFAULT);
|
||||
|
||||
0
arch/arm/cortex-m33/gcc/NTZ/los_arch_atomic.h
Executable file → Normal file
0
arch/arm/cortex-m33/gcc/NTZ/los_arch_atomic.h
Executable file → Normal file
0
arch/arm/cortex-m33/gcc/NTZ/los_arch_context.h
Executable file → Normal file
0
arch/arm/cortex-m33/gcc/NTZ/los_arch_context.h
Executable file → Normal file
0
arch/arm/cortex-m33/gcc/NTZ/los_arch_interrupt.h
Executable file → Normal file
0
arch/arm/cortex-m33/gcc/NTZ/los_arch_interrupt.h
Executable file → Normal file
8
arch/arm/cortex-m33/gcc/NTZ/los_exc.S
Executable file → Normal file
8
arch/arm/cortex-m33/gcc/NTZ/los_exc.S
Executable file → Normal file
@@ -263,7 +263,7 @@ _hwiActiveCheck:
|
||||
CMP R3, #0
|
||||
BEQ _hwiActiveCheckNext
|
||||
|
||||
// exc occured in IRQ
|
||||
// exc occurred in IRQ
|
||||
ORR R0, R0, #FLAG_HWI_ACTIVE
|
||||
RBIT R2, R3
|
||||
CLZ R2, R2
|
||||
@@ -316,19 +316,19 @@ _hwiActiveCheckNext:
|
||||
AND R2, R2,R3
|
||||
CMP R2,#0
|
||||
BNE _ExcInMSP
|
||||
// exc occured in Task or Init or exc
|
||||
// exc occurred in Task or Init or exc
|
||||
// reserved for register info from task stack
|
||||
|
||||
LDR R2, =g_taskScheduled
|
||||
LDR R2, [R2]
|
||||
TST R2, #1 // OS_FLG_BGD_ACTIVE
|
||||
BEQ _ExcInMSP // if exc occured in Init then branch
|
||||
BEQ _ExcInMSP // if exc occurred in Init then branch
|
||||
|
||||
|
||||
CMP LR, #0xFFFFFFED //auto push floating registers
|
||||
BNE _NoFloatInPsp
|
||||
|
||||
// exc occured in Task
|
||||
// exc occurred in Task
|
||||
MOV R2, R13
|
||||
SUB R13, #96 // add 8 Bytes reg(for STMFD)
|
||||
|
||||
|
||||
5
arch/arm/cortex-m33/gcc/NTZ/los_interrupt.c
Executable file → Normal file
5
arch/arm/cortex-m33/gcc/NTZ/los_interrupt.c
Executable file → Normal file
@@ -41,10 +41,8 @@
|
||||
#include "los_membox.h"
|
||||
|
||||
#define DEF_HANDLER_START_INDEX 2
|
||||
/*lint -save -e40 -e522 -e533*/
|
||||
UINT32 g_intCount = 0;
|
||||
|
||||
/*lint -restore*/
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
@@ -189,7 +187,6 @@ inline UINT32 ArchIsIntActive(VOID)
|
||||
Output : None
|
||||
Return : None
|
||||
**************************************************************************** */
|
||||
/*lint -e529*/
|
||||
LITE_OS_SEC_TEXT_MINOR VOID HalHwiDefaultHandler(VOID)
|
||||
{
|
||||
PRINT_ERR("%s irqnum:%u\n", __FUNCTION__, HwiNumGet());
|
||||
@@ -593,7 +590,7 @@ LITE_OS_SEC_TEXT_INIT VOID HalHwiInit(VOID)
|
||||
|
||||
/* Enable USGFAULT, BUSFAULT, MEMFAULT */
|
||||
*(volatile UINT32 *)OS_NVIC_SHCSR |= (USGFAULT | BUSFAULT | MEMFAULT);
|
||||
|
||||
|
||||
/* Enable DIV 0 and unaligned exception */
|
||||
#ifdef LOSCFG_ARCH_UNALIGNED_EXC
|
||||
*(volatile UINT32 *)OS_NVIC_CCR |= (DIV0FAULT | UNALIGNFAULT);
|
||||
|
||||
0
arch/arm/cortex-m33/gcc/NTZ/los_timer.c
Executable file → Normal file
0
arch/arm/cortex-m33/gcc/NTZ/los_timer.c
Executable file → Normal file
0
arch/arm/cortex-m33/gcc/TZ/non_secure/los_arch_atomic.h
Executable file → Normal file
0
arch/arm/cortex-m33/gcc/TZ/non_secure/los_arch_atomic.h
Executable file → Normal file
0
arch/arm/cortex-m33/gcc/TZ/non_secure/los_arch_context.h
Executable file → Normal file
0
arch/arm/cortex-m33/gcc/TZ/non_secure/los_arch_context.h
Executable file → Normal file
0
arch/arm/cortex-m33/gcc/TZ/non_secure/los_arch_interrupt.h
Executable file → Normal file
0
arch/arm/cortex-m33/gcc/TZ/non_secure/los_arch_interrupt.h
Executable file → Normal file
8
arch/arm/cortex-m33/gcc/TZ/non_secure/los_exc.S
Executable file → Normal file
8
arch/arm/cortex-m33/gcc/TZ/non_secure/los_exc.S
Executable file → Normal file
@@ -247,7 +247,7 @@ _hwiActiveCheck:
|
||||
CMP R3, #0
|
||||
BEQ _hwiActiveCheckNext
|
||||
|
||||
// exc occured in IRQ
|
||||
// exc occurred in IRQ
|
||||
ORR R0, R0, #FLAG_HWI_ACTIVE
|
||||
RBIT R2, R3
|
||||
CLZ R2, R2
|
||||
@@ -300,19 +300,19 @@ _hwiActiveCheckNext:
|
||||
AND R2, R2,R3
|
||||
CMP R2,#0
|
||||
BNE _ExcInMSP
|
||||
// exc occured in Task or Init or exc
|
||||
// exc occurred in Task or Init or exc
|
||||
// reserved for register info from task stack
|
||||
|
||||
LDR R2, =g_taskScheduled
|
||||
LDR R2, [R2]
|
||||
TST R2, #1 // OS_FLG_BGD_ACTIVE
|
||||
BEQ _ExcInMSP // if exc occured in Init then branch
|
||||
BEQ _ExcInMSP // if exc occurred in Init then branch
|
||||
|
||||
|
||||
CMP LR, #0xFFFFFFED //auto push floating registers
|
||||
BNE _NoFloatInPsp
|
||||
|
||||
// exc occured in Task
|
||||
// exc occurred in Task
|
||||
MOV R2, R13
|
||||
SUB R13, #96 // add 8 Bytes reg(for STMFD)
|
||||
|
||||
|
||||
5
arch/arm/cortex-m33/gcc/TZ/non_secure/los_interrupt.c
Executable file → Normal file
5
arch/arm/cortex-m33/gcc/TZ/non_secure/los_interrupt.c
Executable file → Normal file
@@ -41,11 +41,8 @@
|
||||
#include "los_membox.h"
|
||||
|
||||
#define DEF_HANDLER_START_INDEX 2
|
||||
/*lint -save -e40 -e522 -e533*/
|
||||
UINT32 g_intCount = 0;
|
||||
|
||||
/*lint -restore*/
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Hardware interrupt form mapping handling function array.
|
||||
@@ -593,7 +590,7 @@ LITE_OS_SEC_TEXT_INIT VOID HalHwiInit(VOID)
|
||||
|
||||
/* Enable USGFAULT, BUSFAULT, MEMFAULT */
|
||||
*(volatile UINT32 *)OS_NVIC_SHCSR |= (USGFAULT | BUSFAULT | MEMFAULT);
|
||||
|
||||
|
||||
/* Enable DIV 0 and unaligned exception */
|
||||
#ifdef LOSCFG_ARCH_UNALIGNED_EXC
|
||||
*(volatile UINT32 *)OS_NVIC_CCR |= (DIV0FAULT | UNALIGNFAULT);
|
||||
|
||||
0
arch/arm/cortex-m33/gcc/TZ/non_secure/los_timer.c
Executable file → Normal file
0
arch/arm/cortex-m33/gcc/TZ/non_secure/los_timer.c
Executable file → Normal file
0
arch/arm/cortex-m33/gcc/TZ/non_secure/los_trustzone.c
Executable file → Normal file
0
arch/arm/cortex-m33/gcc/TZ/non_secure/los_trustzone.c
Executable file → Normal file
0
arch/arm/cortex-m33/gcc/TZ/non_secure/los_trustzone.h
Executable file → Normal file
0
arch/arm/cortex-m33/gcc/TZ/non_secure/los_trustzone.h
Executable file → Normal file
0
arch/arm/cortex-m33/gcc/TZ/secure/los_secure_context.c
Executable file → Normal file
0
arch/arm/cortex-m33/gcc/TZ/secure/los_secure_context.c
Executable file → Normal file
0
arch/arm/cortex-m33/gcc/TZ/secure/los_secure_context.h
Executable file → Normal file
0
arch/arm/cortex-m33/gcc/TZ/secure/los_secure_context.h
Executable file → Normal file
0
arch/arm/cortex-m33/gcc/TZ/secure/los_secure_context_asm.S
Executable file → Normal file
0
arch/arm/cortex-m33/gcc/TZ/secure/los_secure_context_asm.S
Executable file → Normal file
0
arch/arm/cortex-m33/gcc/TZ/secure/los_secure_heap.c
Executable file → Normal file
0
arch/arm/cortex-m33/gcc/TZ/secure/los_secure_heap.c
Executable file → Normal file
0
arch/arm/cortex-m33/gcc/TZ/secure/los_secure_heap.h
Executable file → Normal file
0
arch/arm/cortex-m33/gcc/TZ/secure/los_secure_heap.h
Executable file → Normal file
0
arch/arm/cortex-m33/gcc/TZ/secure/los_secure_macros.h
Executable file → Normal file
0
arch/arm/cortex-m33/gcc/TZ/secure/los_secure_macros.h
Executable file → Normal file
@@ -56,8 +56,8 @@ FLAG_ADDR_VALID EQU 0x10000
|
||||
FLAG_HWI_ACTIVE EQU 0x20000
|
||||
FLAG_NO_FLOAT EQU 0x10000000
|
||||
|
||||
OS_NVIC_FSR EQU 0xE000ED28 ;include BusFault/MemFault/UsageFault State Regeister
|
||||
OS_NVIC_HFSR EQU 0xE000ED2C ;HardFault State Regeister
|
||||
OS_NVIC_FSR EQU 0xE000ED28 ;include BusFault/MemFault/UsageFault State Register
|
||||
OS_NVIC_HFSR EQU 0xE000ED2C ;HardFault State Register
|
||||
OS_NVIC_BFAR EQU 0xE000ED38
|
||||
OS_NVIC_MMAR EQU 0xE000ED34
|
||||
OS_NVIC_ACT_BASE EQU 0xE000E300
|
||||
@@ -190,7 +190,7 @@ _hwiActiveCheck
|
||||
CMP R3, #0
|
||||
BEQ _hwiActiveCheckNext
|
||||
|
||||
; exc occured in IRQ
|
||||
; exc occurred in IRQ
|
||||
ORR R0, R0, #FLAG_HWI_ACTIVE
|
||||
RBIT R2, R3
|
||||
CLZ R2, R2
|
||||
@@ -228,19 +228,19 @@ _hwiActiveCheckNext
|
||||
AND R2, R2,R3
|
||||
CMP R2,#0
|
||||
BNE _ExcInMSP
|
||||
; exc occured in Task or Init or exc
|
||||
; exc occurred in Task or Init or exc
|
||||
; reserved for register info from task stack
|
||||
|
||||
LDR R2, =g_taskScheduled
|
||||
LDR R2, [R2]
|
||||
TST R2, #1 ; OS_FLG_BGD_ACTIVE
|
||||
BEQ _ExcInMSP ; if exc occured in Init then branch
|
||||
BEQ _ExcInMSP ; if exc occurred in Init then branch
|
||||
|
||||
|
||||
CMP LR, #0xFFFFFFED ;auto push floating registers
|
||||
BNE _NoFloatInPsp
|
||||
|
||||
; exc occured in Task
|
||||
; exc occurred in Task
|
||||
MOV R2, R13
|
||||
SUB R13, #96 ; add 8 Bytes reg(for STMFD)
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ UINT32 g_intCount = 0;
|
||||
|
||||
/*lint -restore*/
|
||||
#pragma location = ".data.vector"
|
||||
#pragma data_alignment=LOSCFG_ARCH_HWI_VECTOR_ALIGN
|
||||
#pragma data_alignment = LOSCFG_ARCH_HWI_VECTOR_ALIGN
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* hardware interrupt form mapping handling function array.
|
||||
|
||||
@@ -55,8 +55,8 @@ FLAG_ADDR_VALID EQU 0x10000
|
||||
FLAG_HWI_ACTIVE EQU 0x20000
|
||||
FLAG_NO_FLOAT EQU 0x10000000
|
||||
|
||||
OS_NVIC_FSR EQU 0xE000ED28 ;include BusFault/MemFault/UsageFault State Regeister
|
||||
OS_NVIC_HFSR EQU 0xE000ED2C ;HardFault State Regeister
|
||||
OS_NVIC_FSR EQU 0xE000ED28 ;include BusFault/MemFault/UsageFault State Register
|
||||
OS_NVIC_HFSR EQU 0xE000ED2C ;HardFault State Register
|
||||
OS_NVIC_BFAR EQU 0xE000ED38
|
||||
OS_NVIC_MMAR EQU 0xE000ED34
|
||||
OS_NVIC_ACT_BASE EQU 0xE000E300
|
||||
@@ -179,7 +179,7 @@ _hwiActiveCheck
|
||||
CMP R3, #0
|
||||
BEQ _hwiActiveCheckNext
|
||||
|
||||
; exc occured in IRQ
|
||||
; exc occurred in IRQ
|
||||
ORR R0, R0, #FLAG_HWI_ACTIVE
|
||||
RBIT R2, R3
|
||||
CLZ R2, R2
|
||||
@@ -217,19 +217,19 @@ _hwiActiveCheckNext
|
||||
AND R2, R2,R3
|
||||
CMP R2,#0
|
||||
BNE _ExcInMSP
|
||||
; exc occured in Task or Init or exc
|
||||
; exc occurred in Task or Init or exc
|
||||
; reserved for register info from task stack
|
||||
|
||||
LDR R2, =g_taskScheduled
|
||||
LDR R2, [R2]
|
||||
TST R2, #1 ; OS_FLG_BGD_ACTIVE
|
||||
BEQ _ExcInMSP ; if exc occured in Init then branch
|
||||
BEQ _ExcInMSP ; if exc occurred in Init then branch
|
||||
|
||||
|
||||
CMP LR, #0xFFFFFFED ;auto push floating registers
|
||||
BNE _NoFloatInPsp
|
||||
|
||||
; exc occured in Task
|
||||
; exc occurred in Task
|
||||
MOV R2, R13
|
||||
SUB R13, #96 ; add 8 Bytes reg(for STMFD)
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ UINT32 g_intCount = 0;
|
||||
|
||||
/*lint -restore*/
|
||||
#pragma location = ".data.vector"
|
||||
#pragma data_alignment=LOSCFG_ARCH_HWI_VECTOR_ALIGN
|
||||
#pragma data_alignment = LOSCFG_ARCH_HWI_VECTOR_ALIGN
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* hardware interrupt form mapping handling function array.
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
#include "los_config.h"
|
||||
#include "los_list.h"
|
||||
|
||||
#pragma data_alignment=0x4
|
||||
#pragma data_alignment = 0x4
|
||||
STATIC UINT8 g_secureHeap[LOSCFG_SECURE_HEAP_SIZE] = {0};
|
||||
STATIC LOS_DL_LIST g_secureHeapFreeList = {NULL, NULL};
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
@@ -121,6 +121,29 @@ typedef struct TagTskContext {
|
||||
*/
|
||||
extern VOID HalStartToRun(VOID);
|
||||
|
||||
#if (LOSCFG_SECURE == 1)
|
||||
/**
|
||||
* @ingroup los_config
|
||||
* @brief: User Task Stack Initialize.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to init a user task stack.
|
||||
*
|
||||
* @attention:
|
||||
* <ul><li>None.</li></ul>
|
||||
*
|
||||
* @param: context [IN] Task context.
|
||||
* @param: taskEntry [IN] Task entry function address.
|
||||
* @param: stack [IN] Task stack address.
|
||||
*
|
||||
* @retval None.
|
||||
*
|
||||
* @par Dependency: <ul><li>los_config.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern VOID HalUserTaskStackInit(TaskContext *context, UINTPTR taskEntry, UINTPTR stack);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
|
||||
@@ -148,6 +148,15 @@ VOID *ArchSignalContextInit(VOID *stackPointer, VOID *stackTop, UINTPTR sigHandl
|
||||
return (VOID *)context;
|
||||
}
|
||||
|
||||
#if (LOSCFG_SECURE == 1)
|
||||
VOID HalUserTaskStackInit(TaskContext *context, UINTPTR taskEntry, UINTPTR stack)
|
||||
{
|
||||
context->uwR0 = stack;
|
||||
context->uwPC = (UINT32)taskEntry;
|
||||
context->uwxPSR = 0x01000000L; /* Thumb flag, always set 1 */
|
||||
}
|
||||
#endif
|
||||
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 ArchStartSchedule(VOID)
|
||||
{
|
||||
(VOID)LOS_IntLock();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
@@ -40,6 +40,12 @@
|
||||
.equ OS_NVIC_PENDSV_PRI, 0xF0F00000
|
||||
.equ OS_NVIC_PENDSVSET, 0x10000000
|
||||
.equ OS_TASK_STATUS_RUNNING, 0x0010
|
||||
.equ OS_CONTROL_FPCA_ENABLE, 0x4
|
||||
.equ OS_CONTROL_KERNEL_MODE, 0x2
|
||||
#if (LOSCFG_SECURE == 1)
|
||||
.equ OS_CONTROL_USER_MODE, 0x3
|
||||
.equ OS_TASK_FLAG_USER_TASK, 0x0200
|
||||
#endif
|
||||
|
||||
.section .text
|
||||
.thumb
|
||||
@@ -63,7 +69,7 @@ HalStartToRun:
|
||||
ldr r5, =OS_NVIC_PENDSV_PRI
|
||||
str r5, [r4]
|
||||
|
||||
mov r0, #2
|
||||
mov r0, #OS_CONTROL_KERNEL_MODE
|
||||
msr CONTROL, r0
|
||||
|
||||
ldr r1, =g_losTask
|
||||
@@ -141,7 +147,7 @@ ArchTaskSchedule:
|
||||
bx lr
|
||||
dsb
|
||||
isb
|
||||
.fnend
|
||||
.fnend
|
||||
|
||||
.type HalPendSV, %function
|
||||
.global HalPendSV
|
||||
@@ -194,6 +200,14 @@ SignalContextRestore:
|
||||
vldmia r1!, {d8-d15}
|
||||
|
||||
__DisabledFPU2:
|
||||
#if (LOSCFG_SECURE == 1)
|
||||
ldrh r7, [r0, #4]
|
||||
tst r7, #OS_TASK_FLAG_USER_TASK
|
||||
ite eq
|
||||
moveq r3, #OS_CONTROL_KERNEL_MODE
|
||||
movne r3, #OS_CONTROL_USER_MODE
|
||||
msr CONTROL, r3
|
||||
#endif
|
||||
ldmfd r1!, {r4-r12}
|
||||
msr psp, r1
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
@@ -57,15 +57,15 @@
|
||||
|
||||
.equ FLAG_ADDR_VALID, 0x10000
|
||||
.equ FLAG_HWI_ACTIVE, 0x20000
|
||||
.equ FLAG_NO_FLOAT, 0x10000000
|
||||
.equ FLAG_NO_FLOAT, 0x10000000
|
||||
|
||||
.equ OS_NVIC_FSR , 0xE000ED28 //include BusFault/MemFault/UsageFault State Register
|
||||
.equ OS_NVIC_HFSR , 0xE000ED2C //HardFault State Register
|
||||
.equ OS_NVIC_BFAR , 0xE000ED38
|
||||
.equ OS_NVIC_MMAR , 0xE000ED34
|
||||
.equ OS_NVIC_ACT_BASE , 0xE000E300
|
||||
.equ OS_NVIC_SHCSRS , 0xE000ED24
|
||||
.equ OS_NVIC_SHCSR_MASK , 0xC00
|
||||
.equ OS_NVIC_FSR, 0xE000ED28 //include BusFault/MemFault/UsageFault State Register
|
||||
.equ OS_NVIC_HFSR, 0xE000ED2C //HardFault State Register
|
||||
.equ OS_NVIC_BFAR, 0xE000ED38
|
||||
.equ OS_NVIC_MMAR, 0xE000ED34
|
||||
.equ OS_NVIC_ACT_BASE, 0xE000E300
|
||||
.equ OS_NVIC_SHCSRS, 0xE000ED24
|
||||
.equ OS_NVIC_SHCSR_MASK, 0xC00
|
||||
|
||||
.type HalExcNMI, %function
|
||||
.global HalExcNMI
|
||||
@@ -155,10 +155,25 @@ HalExcSvcCall:
|
||||
.cantunwind
|
||||
TST LR, #0x4
|
||||
ITE EQ
|
||||
MRSEQ R0, MSP
|
||||
MRSNE R0, PSP
|
||||
LDR R1, [R0,#24]
|
||||
LDRB R0, [R1,#-2]
|
||||
MRSEQ R1, MSP
|
||||
BNE _svcCallFromPsp
|
||||
B _svcCall
|
||||
_svcCallFromPsp:
|
||||
#ifdef LOSCFG_SECURE
|
||||
PUSH {R0-R12, LR}
|
||||
MOV R0, SP
|
||||
CPSIE I
|
||||
BL OsSyscallHandle
|
||||
CPSID I
|
||||
MRS R12, PSP
|
||||
STM R12, {R0-R1}
|
||||
POP {R0-R12, LR}
|
||||
BX LR
|
||||
#endif
|
||||
MRS R1, PSP
|
||||
_svcCall:
|
||||
LDR R0, [R1,#24]
|
||||
LDRB R0, [R0,#-2]
|
||||
MOV R1, #0
|
||||
B osExcDispatch
|
||||
.fnend
|
||||
@@ -263,7 +278,7 @@ _hwiActiveCheck:
|
||||
CMP R3, #0
|
||||
BEQ _hwiActiveCheckNext
|
||||
|
||||
// exc occured in IRQ
|
||||
// exc occurred in IRQ
|
||||
ORR R0, R0, #FLAG_HWI_ACTIVE
|
||||
RBIT R2, R3
|
||||
CLZ R2, R2
|
||||
@@ -284,7 +299,7 @@ _ExcInMSP:
|
||||
PUSH {R4-R12} // store message-->exc: {R4-R12}
|
||||
VPUSH {D8-D15} // FPU
|
||||
B _handleEntry
|
||||
.fnend
|
||||
.fnend
|
||||
|
||||
.type _NoFloatInMsp, %function
|
||||
.global _NoFloatInMsp
|
||||
@@ -298,7 +313,7 @@ _NoFloatInMsp:
|
||||
PUSH {R4-R12} // store message-->exc: {R4-R12}
|
||||
ORR R0, R0, #FLAG_NO_FLOAT
|
||||
B _handleEntry
|
||||
.fnend
|
||||
.fnend
|
||||
|
||||
.type _hwiActiveCheckNext, %function
|
||||
.global _hwiActiveCheckNext
|
||||
@@ -316,19 +331,19 @@ _hwiActiveCheckNext:
|
||||
AND R2, R2,R3
|
||||
CMP R2,#0
|
||||
BNE _ExcInMSP
|
||||
// exc occured in Task or Init or exc
|
||||
// exc occurred in Task or Init or exc
|
||||
// reserved for register info from task stack
|
||||
|
||||
LDR R2, =g_taskScheduled
|
||||
LDR R2, [R2]
|
||||
TST R2, #1 // OS_FLG_BGD_ACTIVE
|
||||
BEQ _ExcInMSP // if exc occured in Init then branch
|
||||
BEQ _ExcInMSP // if exc occurred in Init then branch
|
||||
|
||||
|
||||
CMP LR, #0xFFFFFFED //auto push floating registers
|
||||
BNE _NoFloatInPsp
|
||||
|
||||
// exc occured in Task
|
||||
// exc occurred in Task
|
||||
MOV R2, R13
|
||||
SUB R13, #96 // add 8 Bytes reg(for STMFD)
|
||||
|
||||
@@ -347,7 +362,7 @@ _hwiActiveCheckNext:
|
||||
VSTMDB R2!, {D8-D15} // FPU
|
||||
STMFD R2!, {R4-R11}
|
||||
B _handleEntry
|
||||
.fnend
|
||||
.fnend
|
||||
|
||||
.type _NoFloatInPsp, %function
|
||||
.global _NoFloatInPsp
|
||||
@@ -367,7 +382,7 @@ _NoFloatInPsp:
|
||||
LDMFD R3, {R4-R11} // R4-R11 store PSP reg(auto push when exc in task)
|
||||
STMFD R2!, {R4-R11}
|
||||
ORR R0, R0, #FLAG_NO_FLOAT
|
||||
.fnend
|
||||
.fnend
|
||||
|
||||
.type _handleEntry, %function
|
||||
.global _handleEntry
|
||||
@@ -380,4 +395,4 @@ _handleEntry:
|
||||
B HalExcHandleEntry
|
||||
|
||||
NOP
|
||||
.fnend
|
||||
.fnend
|
||||
|
||||
@@ -40,11 +40,8 @@
|
||||
#include "los_memory.h"
|
||||
#include "los_membox.h"
|
||||
|
||||
/*lint -save -e40 -e522 -e533*/
|
||||
UINT32 g_intCount = 0;
|
||||
|
||||
/*lint -restore*/
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Hardware interrupt form mapping handling function array.
|
||||
@@ -193,7 +190,6 @@ inline UINT32 ArchIsIntActive(VOID)
|
||||
Output : None
|
||||
Return : None
|
||||
**************************************************************************** */
|
||||
/*lint -e529*/
|
||||
LITE_OS_SEC_TEXT_MINOR VOID HalHwiDefaultHandler(VOID)
|
||||
{
|
||||
PRINT_ERR("%s irqnum:%u\n", __FUNCTION__, HwiNumGet());
|
||||
@@ -607,7 +603,7 @@ LITE_OS_SEC_TEXT_INIT VOID HalHwiInit(VOID)
|
||||
|
||||
/* Enable USGFAULT, BUSFAULT, MEMFAULT */
|
||||
*(volatile UINT32 *)OS_NVIC_SHCSR |= (USGFAULT | BUSFAULT | MEMFAULT);
|
||||
|
||||
|
||||
/* Enable DIV 0 and unaligned exception */
|
||||
#ifdef LOSCFG_ARCH_UNALIGNED_EXC
|
||||
*(volatile UINT32 *)OS_NVIC_CCR |= (DIV0FAULT | UNALIGNFAULT);
|
||||
|
||||
@@ -190,7 +190,7 @@ _hwiActiveCheck
|
||||
CMP R3, #0
|
||||
BEQ _hwiActiveCheckNext
|
||||
|
||||
; exc occured in IRQ
|
||||
; exc occurred in IRQ
|
||||
ORR R0, R0, #FLAG_HWI_ACTIVE
|
||||
RBIT R2, R3
|
||||
CLZ R2, R2
|
||||
@@ -228,19 +228,19 @@ _hwiActiveCheckNext
|
||||
AND R2, R2,R3
|
||||
CMP R2,#0
|
||||
BNE _ExcInMSP
|
||||
; exc occured in Task or Init or exc
|
||||
; exc occurred in Task or Init or exc
|
||||
; reserved for register info from task stack
|
||||
|
||||
LDR R2, =g_taskScheduled
|
||||
LDR R2, [R2]
|
||||
TST R2, #1 ; OS_FLG_BGD_ACTIVE
|
||||
BEQ _ExcInMSP ; if exc occured in Init then branch
|
||||
BEQ _ExcInMSP ; if exc occurred in Init then branch
|
||||
|
||||
|
||||
CMP LR, #0xFFFFFFED ;auto push floating registers
|
||||
BNE _NoFloatInPsp
|
||||
|
||||
; exc occured in Task
|
||||
; exc occurred in Task
|
||||
MOV R2, R13
|
||||
SUB R13, #96 ; add 8 Bytes reg(for STMFD)
|
||||
|
||||
|
||||
@@ -41,13 +41,11 @@
|
||||
#include "los_memory.h"
|
||||
#include "los_membox.h"
|
||||
|
||||
/*lint -save -e40 -e522 -e533*/
|
||||
UINT32 g_intCount = 0;
|
||||
|
||||
/*lint -restore*/
|
||||
#ifdef __ICCARM__
|
||||
#pragma location = ".data.vector"
|
||||
#pragma data_alignment=LOSCFG_ARCH_HWI_VECTOR_ALIGN
|
||||
#pragma data_alignment = LOSCFG_ARCH_HWI_VECTOR_ALIGN
|
||||
#elif defined(__CC_ARM) || defined(__GNUC__)
|
||||
LITE_OS_SEC_VEC
|
||||
#endif
|
||||
@@ -603,7 +601,7 @@ LITE_OS_SEC_TEXT_INIT VOID HalHwiInit(VOID)
|
||||
|
||||
/* Enable USGFAULT, BUSFAULT, MEMFAULT */
|
||||
*(volatile UINT32 *)OS_NVIC_SHCSR |= (USGFAULT | BUSFAULT | MEMFAULT);
|
||||
|
||||
|
||||
/* Enable DIV 0 and unaligned exception */
|
||||
#ifdef LOSCFG_ARCH_UNALIGNED_EXC
|
||||
*(volatile UINT32 *)OS_NVIC_CCR |= (DIV0FAULT | UNALIGNFAULT);
|
||||
|
||||
0
arch/arm/cortex-m55/gcc/BUILD.gn
Executable file → Normal file
0
arch/arm/cortex-m55/gcc/BUILD.gn
Executable file → Normal file
0
arch/arm/cortex-m55/gcc/NTZ/BUILD.gn
Executable file → Normal file
0
arch/arm/cortex-m55/gcc/NTZ/BUILD.gn
Executable file → Normal file
0
arch/arm/cortex-m55/gcc/NTZ/los_arch_atomic.h
Executable file → Normal file
0
arch/arm/cortex-m55/gcc/NTZ/los_arch_atomic.h
Executable file → Normal file
0
arch/arm/cortex-m55/gcc/NTZ/los_arch_context.h
Executable file → Normal file
0
arch/arm/cortex-m55/gcc/NTZ/los_arch_context.h
Executable file → Normal file
0
arch/arm/cortex-m55/gcc/NTZ/los_arch_interrupt.h
Executable file → Normal file
0
arch/arm/cortex-m55/gcc/NTZ/los_arch_interrupt.h
Executable file → Normal file
0
arch/arm/cortex-m55/gcc/NTZ/los_arch_timer.h
Executable file → Normal file
0
arch/arm/cortex-m55/gcc/NTZ/los_arch_timer.h
Executable file → Normal file
0
arch/arm/cortex-m55/gcc/NTZ/los_context.c
Executable file → Normal file
0
arch/arm/cortex-m55/gcc/NTZ/los_context.c
Executable file → Normal file
0
arch/arm/cortex-m55/gcc/NTZ/los_dispatch.S
Executable file → Normal file
0
arch/arm/cortex-m55/gcc/NTZ/los_dispatch.S
Executable file → Normal file
8
arch/arm/cortex-m55/gcc/NTZ/los_exc.S
Executable file → Normal file
8
arch/arm/cortex-m55/gcc/NTZ/los_exc.S
Executable file → Normal file
@@ -260,7 +260,7 @@ _hwiActiveCheck:
|
||||
CMP R3, #0
|
||||
BEQ _hwiActiveCheckNext
|
||||
|
||||
// exc occured in IRQ
|
||||
// exc occurred in IRQ
|
||||
ORR R0, R0, #FLAG_HWI_ACTIVE
|
||||
RBIT R2, R3
|
||||
CLZ R2, R2
|
||||
@@ -313,19 +313,19 @@ _hwiActiveCheckNext:
|
||||
AND R2, R2, R3
|
||||
CMP R2, #0
|
||||
BNE _ExcInMSP
|
||||
// exc occured in Task or Init or exc
|
||||
// exc occurred in Task or Init or exc
|
||||
// reserved for register info from task stack
|
||||
|
||||
LDR R2, =g_taskScheduled
|
||||
LDR R2, [R2]
|
||||
TST R2, #1 // OS_FLG_BGD_ACTIVE
|
||||
BEQ _ExcInMSP // if exc occured in Init then branch
|
||||
BEQ _ExcInMSP // if exc occurred in Init then branch
|
||||
|
||||
|
||||
CMP LR, #0xFFFFFFED //auto push floating registers
|
||||
BNE _NoFloatInPsp
|
||||
|
||||
// exc occured in Task
|
||||
// exc occurred in Task
|
||||
MOV R2, R13
|
||||
SUB R13, #96 // add 8 Bytes reg(for STMFD)
|
||||
|
||||
|
||||
3
arch/arm/cortex-m55/gcc/NTZ/los_interrupt.c
Executable file → Normal file
3
arch/arm/cortex-m55/gcc/NTZ/los_interrupt.c
Executable file → Normal file
@@ -40,10 +40,8 @@
|
||||
#include "los_membox.h"
|
||||
|
||||
#define DEF_HANDLER_START_INDEX 2
|
||||
/*lint -save -e40 -e522 -e533*/
|
||||
UINT32 g_intCount = 0;
|
||||
|
||||
/*lint -restore*/
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
@@ -193,7 +191,6 @@ inline UINT32 ArchIsIntActive(VOID)
|
||||
Output : None
|
||||
Return : None
|
||||
**************************************************************************** */
|
||||
/*lint -e529*/
|
||||
LITE_OS_SEC_TEXT_MINOR VOID HalHwiDefaultHandler(VOID)
|
||||
{
|
||||
PRINT_ERR("%s irqnum:%u\n", __FUNCTION__, HwiNumGet());
|
||||
|
||||
0
arch/arm/cortex-m55/gcc/NTZ/los_timer.c
Executable file → Normal file
0
arch/arm/cortex-m55/gcc/NTZ/los_timer.c
Executable file → Normal file
@@ -137,7 +137,7 @@ ArchTaskSchedule:
|
||||
dsb
|
||||
isb
|
||||
bx lr
|
||||
.fnend
|
||||
.fnend
|
||||
|
||||
.type HalPendSV, %function
|
||||
.global HalPendSV
|
||||
@@ -178,7 +178,7 @@ TaskContextSwitch:
|
||||
str r0, [r5]
|
||||
ldr r1, [r0]
|
||||
|
||||
SignalContextRestore:
|
||||
SignalContextRestore:
|
||||
#if ((defined(__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
|
||||
(defined(__FPU_USED) && (__FPU_USED == 1U)))
|
||||
vldmia r1!, {d8-d15}
|
||||
|
||||
@@ -29,9 +29,9 @@
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
.syntax unified
|
||||
.arch armv7e-m
|
||||
.thumb
|
||||
.syntax unified
|
||||
.arch armv7e-m
|
||||
.thumb
|
||||
.fpu fpv5-d16
|
||||
.section .text
|
||||
|
||||
@@ -263,7 +263,7 @@ _hwiActiveCheck:
|
||||
CMP R3, #0
|
||||
BEQ _hwiActiveCheckNext
|
||||
|
||||
// exc occured in IRQ
|
||||
// exc occurred in IRQ
|
||||
ORR R0, R0, #FLAG_HWI_ACTIVE
|
||||
RBIT R2, R3
|
||||
CLZ R2, R2
|
||||
@@ -284,7 +284,7 @@ _ExcInMSP:
|
||||
PUSH {R4-R12} // store message-->exc: {R4-R12}
|
||||
VPUSH {D8-D15}
|
||||
B _handleEntry
|
||||
.fnend
|
||||
.fnend
|
||||
|
||||
.type _NoFloatInMsp, %function
|
||||
.global _NoFloatInMsp
|
||||
@@ -298,7 +298,7 @@ _NoFloatInMsp:
|
||||
PUSH {R4-R12} // store message-->exc: {R4-R12}
|
||||
ORR R0, R0, #FLAG_NO_FLOAT
|
||||
B _handleEntry
|
||||
.fnend
|
||||
.fnend
|
||||
|
||||
.type _hwiActiveCheckNext, %function
|
||||
.global _hwiActiveCheckNext
|
||||
@@ -316,19 +316,19 @@ _hwiActiveCheckNext:
|
||||
AND R2, R2,R3
|
||||
CMP R2,#0
|
||||
BNE _ExcInMSP
|
||||
// exc occured in Task or Init or exc
|
||||
// exc occurred in Task or Init or exc
|
||||
// reserved for register info from task stack
|
||||
|
||||
LDR R2, =g_taskScheduled
|
||||
LDR R2, [R2]
|
||||
TST R2, #1 // OS_FLG_BGD_ACTIVE
|
||||
BEQ _ExcInMSP // if exc occured in Init then branch
|
||||
BEQ _ExcInMSP // if exc occurred in Init then branch
|
||||
|
||||
|
||||
CMP LR, #0xFFFFFFED //auto push floating registers
|
||||
BNE _NoFloatInPsp
|
||||
|
||||
// exc occured in Task
|
||||
// exc occurred in Task
|
||||
MOV R2, R13
|
||||
SUB R13, #96 // add 8 Bytes reg(for STMFD)
|
||||
|
||||
@@ -347,7 +347,7 @@ _hwiActiveCheckNext:
|
||||
VSTMDB R2!, {D8-D15}
|
||||
STMFD R2!, {R4-R11}
|
||||
B _handleEntry
|
||||
.fnend
|
||||
.fnend
|
||||
|
||||
.type _NoFloatInPsp, %function
|
||||
.global _NoFloatInPsp
|
||||
@@ -367,7 +367,7 @@ _NoFloatInPsp:
|
||||
LDMFD R3, {R4-R11} // R4-R11 store PSP reg(auto push when exc in task)
|
||||
STMFD R2!, {R4-R11}
|
||||
ORR R0, R0, #FLAG_NO_FLOAT
|
||||
.fnend
|
||||
.fnend
|
||||
|
||||
.type _handleEntry, %function
|
||||
.global _handleEntry
|
||||
@@ -380,5 +380,5 @@ _handleEntry:
|
||||
B HalExcHandleEntry
|
||||
|
||||
NOP
|
||||
.fnend
|
||||
.fnend
|
||||
|
||||
|
||||
@@ -40,11 +40,8 @@
|
||||
#include "los_memory.h"
|
||||
#include "los_membox.h"
|
||||
|
||||
/*lint -save -e40 -e522 -e533*/
|
||||
UINT32 g_intCount = 0;
|
||||
|
||||
/*lint -restore*/
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Hardware interrupt form mapping handling function array.
|
||||
@@ -188,7 +185,6 @@ inline UINT32 ArchIsIntActive(VOID)
|
||||
Output : None
|
||||
Return : None
|
||||
**************************************************************************** */
|
||||
/*lint -e529*/
|
||||
LITE_OS_SEC_TEXT_MINOR VOID HalHwiDefaultHandler(VOID)
|
||||
{
|
||||
PRINT_ERR("%s irqnum:%u\n", __FUNCTION__, HwiNumGet());
|
||||
@@ -592,7 +588,7 @@ LITE_OS_SEC_TEXT_INIT VOID HalHwiInit(VOID)
|
||||
|
||||
/* Enable USGFAULT, BUSFAULT, MEMFAULT */
|
||||
*(volatile UINT32 *)OS_NVIC_SHCSR |= (USGFAULT | BUSFAULT | MEMFAULT);
|
||||
|
||||
|
||||
/* Enable DIV 0 and unaligned exception */
|
||||
#ifdef LOSCFG_ARCH_UNALIGNED_EXC
|
||||
*(volatile UINT32 *)OS_NVIC_CCR |= (DIV0FAULT | UNALIGNFAULT);
|
||||
|
||||
@@ -190,7 +190,7 @@ _hwiActiveCheck
|
||||
CMP R3, #0
|
||||
BEQ _hwiActiveCheckNext
|
||||
|
||||
; exc occured in IRQ
|
||||
; exc occurred in IRQ
|
||||
ORR R0, R0, #FLAG_HWI_ACTIVE
|
||||
RBIT R2, R3
|
||||
CLZ R2, R2
|
||||
@@ -228,19 +228,19 @@ _hwiActiveCheckNext
|
||||
AND R2, R2,R3
|
||||
CMP R2,#0
|
||||
BNE _ExcInMSP
|
||||
; exc occured in Task or Init or exc
|
||||
; exc occurred in Task or Init or exc
|
||||
; reserved for register info from task stack
|
||||
|
||||
LDR R2, =g_taskScheduled
|
||||
LDR R2, [R2]
|
||||
TST R2, #1 ; OS_FLG_BGD_ACTIVE
|
||||
BEQ _ExcInMSP ; if exc occured in Init then branch
|
||||
BEQ _ExcInMSP ; if exc occurred in Init then branch
|
||||
|
||||
|
||||
CMP LR, #0xFFFFFFED ;auto push floating registers
|
||||
BNE _NoFloatInPsp
|
||||
|
||||
; exc occured in Task
|
||||
; exc occurred in Task
|
||||
MOV R2, R13
|
||||
SUB R13, #96 ; add 8 Bytes reg(for STMFD)
|
||||
|
||||
|
||||
@@ -41,12 +41,10 @@
|
||||
#include "los_memory.h"
|
||||
#include "los_membox.h"
|
||||
|
||||
/*lint -save -e40 -e522 -e533*/
|
||||
UINT32 g_intCount = 0;
|
||||
|
||||
/*lint -restore*/
|
||||
#pragma location = ".data.vector"
|
||||
#pragma data_alignment=LOSCFG_ARCH_HWI_VECTOR_ALIGN
|
||||
#pragma data_alignment = LOSCFG_ARCH_HWI_VECTOR_ALIGN
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Hardware interrupt form mapping handling function array.
|
||||
@@ -599,7 +597,7 @@ LITE_OS_SEC_TEXT_INIT VOID HalHwiInit(VOID)
|
||||
|
||||
/* Enable USGFAULT, BUSFAULT, MEMFAULT */
|
||||
*(volatile UINT32 *)OS_NVIC_SHCSR |= (USGFAULT | BUSFAULT | MEMFAULT);
|
||||
|
||||
|
||||
/* Enable DIV 0 and unaligned exception */
|
||||
*(volatile UINT32 *)OS_NVIC_CCR |= (DIV0FAULT | UNALIGNFAULT);
|
||||
|
||||
|
||||
0
arch/csky/v2/gcc/BUILD.gn
Executable file → Normal file
0
arch/csky/v2/gcc/BUILD.gn
Executable file → Normal file
@@ -59,13 +59,33 @@ typedef struct TagTskContext {
|
||||
UINT32 R12;
|
||||
UINT32 R13;
|
||||
UINT32 R15;
|
||||
#ifdef CPU_CK804
|
||||
UINT32 R16;
|
||||
UINT32 R17;
|
||||
UINT32 R18;
|
||||
UINT32 R19;
|
||||
UINT32 R20;
|
||||
UINT32 R21;
|
||||
UINT32 R22;
|
||||
UINT32 R23;
|
||||
UINT32 R24;
|
||||
UINT32 R25;
|
||||
UINT32 R26;
|
||||
UINT32 R27;
|
||||
UINT32 R28;
|
||||
UINT32 R29;
|
||||
UINT32 R30;
|
||||
UINT32 R31;
|
||||
#endif
|
||||
UINT32 EPSR;
|
||||
UINT32 EPC;
|
||||
} TaskContext;
|
||||
|
||||
VOID HalStartToRun(VOID);
|
||||
VOID HalTaskContextSwitch(VOID);
|
||||
#ifndef CPU_CK804
|
||||
VOID HalIrqEndCheckNeedSched(VOID);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
|
||||
@@ -82,7 +82,7 @@ typedef VOID (**HWI_VECTOR_FUNC)(VOID);
|
||||
* @ingroup los_arch_interrupt
|
||||
* Count of interrupts.
|
||||
*/
|
||||
extern UINT32 g_intCount;
|
||||
extern volatile UINT32 g_intCount;
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
|
||||
@@ -38,7 +38,9 @@
|
||||
#include "los_interrupt.h"
|
||||
#include "los_debug.h"
|
||||
|
||||
#ifndef CPU_CK804
|
||||
STATIC UINT32 g_sysNeedSched = FALSE;
|
||||
#endif
|
||||
|
||||
/* ****************************************************************************
|
||||
Function : ArchInit
|
||||
@@ -93,8 +95,29 @@ LITE_OS_SEC_TEXT_INIT VOID *ArchTskStackInit(UINT32 taskID, UINT32 stackSize, VO
|
||||
context->R11 = 0x11111111L;
|
||||
context->R12 = 0x12121212L;
|
||||
context->R13 = 0x13131313L;
|
||||
#ifdef CPU_CK804
|
||||
context->R15 = (UINT32)ArchSysExit;
|
||||
context->R16 = 0x16161616L;
|
||||
context->R17 = 0x17171717L;
|
||||
context->R18 = 0x18181818L;
|
||||
context->R19 = 0x19191919L;
|
||||
context->R20 = 0x20202020L;
|
||||
context->R21 = 0x21212121L;
|
||||
context->R22 = 0x22222222L;
|
||||
context->R23 = 0x23232323L;
|
||||
context->R24 = 0x24242424L;
|
||||
context->R25 = 0x25252525L;
|
||||
context->R26 = 0x26262626L;
|
||||
context->R27 = 0x27272727L;
|
||||
context->R28 = 0x28282828L;
|
||||
context->R29 = 0x29292929L;
|
||||
context->R30 = 0x30303030L;
|
||||
context->R31 = 0x31313131L;
|
||||
context->EPSR = 0x80000340L;
|
||||
#else
|
||||
context->R15 = (UINT32)ArchSysExit;
|
||||
context->EPSR = 0xe0000144L;
|
||||
#endif
|
||||
context->EPC = (UINT32)OsTaskEntry;
|
||||
return (VOID *)context;
|
||||
}
|
||||
@@ -107,6 +130,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 ArchStartSchedule(VOID)
|
||||
return LOS_OK; /* never return */
|
||||
}
|
||||
|
||||
#ifndef CPU_CK804
|
||||
VOID HalIrqEndCheckNeedSched(VOID)
|
||||
{
|
||||
if (g_sysNeedSched && g_taskScheduled && LOS_CHECK_SCHEDULE) {
|
||||
@@ -132,3 +156,10 @@ VOID ArchTaskSchedule(VOID)
|
||||
LOS_IntRestore(intSave);
|
||||
return;
|
||||
}
|
||||
#else
|
||||
VOID ArchTaskSchedule(VOID)
|
||||
{
|
||||
HalTaskContextSwitch();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -32,6 +32,89 @@
|
||||
#define OS_TASK_STATUS_RUNNING 0x0010
|
||||
#define VIC_TSPDR 0XE000EC08
|
||||
|
||||
#ifdef CPU_CK804
|
||||
.section .text
|
||||
.align 2
|
||||
.type HalStartToRun, %function
|
||||
.global HalStartToRun
|
||||
HalStartToRun:
|
||||
lrw r1, g_losTask
|
||||
lrw r2, g_losTask + 4
|
||||
|
||||
ldw r0, (r2)
|
||||
|
||||
st.w r0, (r1)
|
||||
st.w r0, (r2)
|
||||
|
||||
ldw sp, (r0)
|
||||
|
||||
ldw r0, (sp, 128)
|
||||
mtcr r0, epc
|
||||
ldw r0, (sp, 124)
|
||||
mtcr r0, epsr
|
||||
ldw r15, (sp, 56)
|
||||
ldm r0-r13, (sp)
|
||||
addi sp, 60
|
||||
ldm r16-r31, (sp)
|
||||
addi sp, 72
|
||||
|
||||
rte
|
||||
|
||||
.align 2
|
||||
.type HalTaskContextSwitch, %function
|
||||
.global HalTaskContextSwitch
|
||||
HalTaskContextSwitch:
|
||||
lrw r0, VIC_TSPDR
|
||||
bgeni r1, 0
|
||||
stw r1, (r0)
|
||||
nop
|
||||
nop
|
||||
nop
|
||||
rts
|
||||
|
||||
.align 2
|
||||
.type tspend_handler, %function
|
||||
.global tspend_handler
|
||||
tspend_handler:
|
||||
|
||||
subi sp, 132
|
||||
stm r0-r13, (sp)
|
||||
stw r15, (sp, 56)
|
||||
addi r0, sp, 60
|
||||
stm r16-r31, (r0)
|
||||
mfcr r1, epsr
|
||||
stw r1, (sp, 124)
|
||||
mfcr r1, epc
|
||||
stw r1, (sp, 128)
|
||||
|
||||
jbsr OsSchedTaskSwitch
|
||||
bez r0, ret_con
|
||||
|
||||
lrw r2, g_losTask
|
||||
ldw r0, (r2)
|
||||
stw sp, (r0)
|
||||
|
||||
lrw r3, g_losTask + 4
|
||||
ldw r0, (r3)
|
||||
stw r0, (r2)
|
||||
|
||||
ldw sp, (r0)
|
||||
|
||||
ret_con:
|
||||
ldw r0, (sp, 128)
|
||||
mtcr r0, epc
|
||||
ldw r0, (sp, 124)
|
||||
mtcr r0, epsr
|
||||
ldw r15, (sp, 56)
|
||||
ldm r0-r13, (sp)
|
||||
addi sp, 60
|
||||
ldm r16-r31, (sp)
|
||||
|
||||
addi sp, 72
|
||||
|
||||
rte
|
||||
|
||||
#else
|
||||
.section .text
|
||||
.align 2
|
||||
.type HalStartToRun, %function
|
||||
@@ -87,3 +170,4 @@ HalTaskContextSwitch:
|
||||
|
||||
rte
|
||||
|
||||
#endif
|
||||
|
||||
@@ -32,6 +32,57 @@
|
||||
.import HalExcHandleEntry
|
||||
.extern g_trapStackBase
|
||||
|
||||
#ifdef CPU_CK804
|
||||
.section .text
|
||||
.align 2
|
||||
.global HandleEntry
|
||||
HandleEntry:
|
||||
mov r10, sp
|
||||
lrw r14, g_trapStackBase
|
||||
|
||||
stm r0-r15, (sp)
|
||||
stw r10, (sp, 56)
|
||||
addi r0, sp, 64
|
||||
stm r16-r31, (r0)
|
||||
mfcr r0, epsr
|
||||
stw r0, (sp, 128)
|
||||
mfcr r0, epc
|
||||
stw r0, (sp, 132)
|
||||
mov r0, sp
|
||||
|
||||
mfcr r1, epc
|
||||
|
||||
mov sp, r10
|
||||
lrw r2, HalExcHandleEntry
|
||||
jmp r2
|
||||
|
||||
.section .text
|
||||
.align 2
|
||||
.global IrqEntry
|
||||
IrqEntry:
|
||||
psrset ee
|
||||
subi sp, 136
|
||||
stm r0-r15, (sp)
|
||||
addi r0, sp, 64
|
||||
stm r16-r31, (r0)
|
||||
mfcr r0, epsr
|
||||
stw r0, (sp, 128)
|
||||
mfcr r0, epc
|
||||
stw r0, (sp, 132)
|
||||
|
||||
jbsr HalInterrupt
|
||||
|
||||
ldw r0, (sp, 132)
|
||||
mtcr r0, epc
|
||||
ldw r0, (sp, 128)
|
||||
bseti r0, r0, 6
|
||||
mtcr r0, epsr
|
||||
ldm r0-r15, (sp)
|
||||
addi sp, 64
|
||||
ldm r16-r31, (sp)
|
||||
addi sp, 72
|
||||
rte
|
||||
#else
|
||||
.section .text
|
||||
.align 2
|
||||
.global HandleEntry
|
||||
@@ -75,3 +126,4 @@ IrqEntry:
|
||||
ldm r0-r15, (sp)
|
||||
addi sp, 72
|
||||
rte
|
||||
#endif
|
||||
@@ -52,13 +52,12 @@
|
||||
#define MASK_8_BITS 0xFF
|
||||
#define MASK_32_BITS 0xFFFFFFFF
|
||||
#define BYTES_OF_128_INT 4
|
||||
#define TIM_INT_NUM 1
|
||||
|
||||
#define OS_USER_HWI_MIN 0
|
||||
#define OS_USER_HWI_MAX (LOSCFG_PLATFORM_HWI_LIMIT - 1)
|
||||
#define HWI_ALIGNSIZE 0x400
|
||||
|
||||
UINT32 g_intCount = 0;
|
||||
UINT32 volatile g_intCount = 0;
|
||||
CHAR g_trapStackBase[OS_TRAP_STACK_SIZE];
|
||||
|
||||
VIC_TYPE *VIC_REG = (VIC_TYPE *)VIC_REG_BASE;
|
||||
@@ -334,7 +333,9 @@ LITE_OS_SEC_TEXT VOID HalInterrupt(VOID)
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
g_intCount--;
|
||||
#ifndef CPU_CK804
|
||||
HalIrqEndCheckNeedSched();
|
||||
#endif
|
||||
LOS_IntRestore(intSave);
|
||||
}
|
||||
|
||||
@@ -586,6 +587,10 @@ WEAK VOID __stack_chk_fail(VOID)
|
||||
__builtin_return_address(0));
|
||||
}
|
||||
|
||||
WEAK void HalHwiHandleReInit(UINT32 hwiFormAddr)
|
||||
{
|
||||
}
|
||||
|
||||
/* ****************************************************************************
|
||||
Function : HalHwiInit
|
||||
Description : initialization of the hardware interrupt
|
||||
@@ -604,6 +609,7 @@ LITE_OS_SEC_TEXT_INIT VOID HalHwiInit(VOID)
|
||||
for (i = OS_SYS_VECTOR_CNT; i < (LOSCFG_PLATFORM_HWI_LIMIT + OS_SYS_VECTOR_CNT); i++) {
|
||||
g_hwiForm[i] = (HWI_PROC_FUNC)IrqEntry;
|
||||
}
|
||||
HalHwiHandleReInit((UINT32)&g_hwiForm);
|
||||
|
||||
HalSetVbr((UINT32)&g_hwiForm);
|
||||
for (int i = 0; i < BYTES_OF_128_INT; i++) {
|
||||
|
||||
@@ -50,7 +50,11 @@ typedef struct {
|
||||
#define CORETIM_SOURCE (1UL << 2)
|
||||
#define CORETIM_MODE (1UL << 16)
|
||||
|
||||
#ifdef CPU_CK804
|
||||
#define TIM_INT_NUM 25
|
||||
#else
|
||||
#define TIM_INT_NUM 1
|
||||
#endif
|
||||
|
||||
STATIC UINT32 SysTickStart(HWI_PROC_FUNC handler);
|
||||
STATIC UINT64 SysTickReload(UINT64 nextResponseTime);
|
||||
|
||||
0
arch/include/los_atomic.h
Executable file → Normal file
0
arch/include/los_atomic.h
Executable file → Normal file
@@ -179,7 +179,6 @@ exc_entry:
|
||||
csrr a0, mcause
|
||||
mv a1, sp
|
||||
/*
|
||||
* TODO: Call the exception handler function
|
||||
* By default, the function template is provided in
|
||||
* system_Device.c, you can adjust it as you want
|
||||
*/
|
||||
|
||||
@@ -105,7 +105,7 @@
|
||||
* Based on the types of the four 8-bit arithmetic operations, the SIMD 8-bit add/subtract instructions
|
||||
* can be classified into 2 main categories: Addition (four 8-bit addition), and Subtraction (four 8-bit
|
||||
* subtraction).
|
||||
* Based on the way of how an overflow condition is handled for singed or unsigned operation, the
|
||||
* Based on the way of how an overflow condition is handled for signed or unsigned operation, the
|
||||
* SIMD 8-bit add/subtract instructions can be classified into 5 groups: Wrap-around (dropping
|
||||
* overflow), Signed Halving (keeping overflow by dropping 1 LSB bit), Unsigned Halving, Signed
|
||||
* Saturation (clipping overflow), and Unsigned Saturation.
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
#define _LOS_ARCH_ATOMIC_H
|
||||
|
||||
#include "los_compiler.h"
|
||||
#include "los_interrupt.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
|
||||
@@ -332,7 +332,7 @@ VOID HalExcEntry(const LosExcContext *excBufAddr)
|
||||
ExcInfoDisplay(excBufAddr);
|
||||
|
||||
if (LOS_TaskIsRunning()) {
|
||||
PRINTK("----------------All Task infomation ------------\n");
|
||||
PRINTK("----------------All Task information ------------\n");
|
||||
OsGetAllTskInfo();
|
||||
}
|
||||
|
||||
|
||||
17
arch_spec.md
17
arch_spec.md
@@ -48,7 +48,9 @@
|
||||
│ ├── lms --- Lite memory sanitizer functions
|
||||
│ ├── net --- Networking functions
|
||||
│ ├── power --- Power management
|
||||
│ ├── security --- Security isolation
|
||||
│ ├── shell --- Shell function
|
||||
│ ├── signal --- Signal support
|
||||
│ ├── fs --- File systems
|
||||
│ └── trace --- Trace tool
|
||||
├── drivers --- driver Kconfig
|
||||
@@ -71,14 +73,13 @@
|
||||
│ │ └── los_tick.h --- Tick
|
||||
│ └── src
|
||||
├── targets
|
||||
│ └── targets
|
||||
│ └── riscv_nuclei_demo_soc_gcc
|
||||
│ │ ├── GCC --- Compilation config
|
||||
│ │ ├── OS_CONFIG --- Board config
|
||||
│ │ ├── SoC --- SOC codes
|
||||
│ │ └── Src --- Application codes
|
||||
│ └── riscv_nuclei_gd32vf103_soc_gcc
|
||||
│ └── riscv_sifive_fe310_gcc
|
||||
│ └── riscv_nuclei_demo_soc_gcc
|
||||
│ │ ├── GCC --- Compilation config
|
||||
│ │ ├── OS_CONFIG --- Board config
|
||||
│ │ ├── SoC --- SOC codes
|
||||
│ │ └── Src --- Application codes
|
||||
│ └── riscv_nuclei_gd32vf103_soc_gcc
|
||||
│ └── riscv_sifive_fe310_gcc
|
||||
├── testsuites --- Kernel testsuites
|
||||
├── tools --- Kernel tools
|
||||
└── utils
|
||||
|
||||
@@ -48,7 +48,9 @@
|
||||
│ ├── lms --- Lite memory sanitizer 机制
|
||||
│ ├── net --- Network功能
|
||||
│ ├── power --- 低功耗管理
|
||||
│ ├── security --- 安全隔离
|
||||
│ ├── shell --- shell功能
|
||||
│ ├── signal --- signal支持
|
||||
│ └── trace --- trace 工具
|
||||
├── drivers --- 驱动框架Kconfig
|
||||
├── kal --- 内核抽象层,提供内核对外接口,当前支持CMSIS接口和部分POSIX接口
|
||||
@@ -70,14 +72,13 @@
|
||||
│ │ └── los_tick.h --- Tick时钟
|
||||
└── src
|
||||
├── targets
|
||||
│ └── targets
|
||||
│ └── riscv_nuclei_demo_soc_gcc
|
||||
│ │ ├── GCC --- 编译相关
|
||||
│ │ ├── OS_CONFIG --- 开发板配置功能开关和配置参数
|
||||
│ │ ├── SoC --- SOC相关代码
|
||||
│ │ └── Src --- Application相关代码
|
||||
│ └── riscv_nuclei_gd32vf103_soc_gcc
|
||||
│ └── riscv_sifive_fe310_gcc
|
||||
│ └── riscv_nuclei_demo_soc_gcc
|
||||
│ │ ├── GCC --- 编译相关
|
||||
│ │ ├── OS_CONFIG --- 开发板配置功能开关和配置参数
|
||||
│ │ ├── SoC --- SOC相关代码
|
||||
│ │ └── Src --- Application相关代码
|
||||
│ └── riscv_nuclei_gd32vf103_soc_gcc
|
||||
│ └── riscv_sifive_fe310_gcc
|
||||
├── testsuites --- 内核测试用例
|
||||
├── tools --- 内核工具
|
||||
└── utils
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification,
|
||||
# are permitted provided that the following conditions are met:
|
||||
@@ -41,6 +41,7 @@ group("components") {
|
||||
"lms",
|
||||
"net",
|
||||
"power",
|
||||
"security",
|
||||
"shell",
|
||||
"signal",
|
||||
"trace",
|
||||
@@ -57,6 +58,7 @@ config("public") {
|
||||
"fs:public",
|
||||
"net:public",
|
||||
"power:public",
|
||||
"security:public",
|
||||
"shell:public",
|
||||
"trace:public",
|
||||
"lmk:public",
|
||||
|
||||
@@ -52,8 +52,8 @@ extern "C" {
|
||||
#define CODE_SECTION_NAME ".text"
|
||||
/* The default C stack section name is CSTACK */
|
||||
#define CSTACK_SECTION_NAME "CSTACK"
|
||||
#pragma section=CODE_SECTION_NAME
|
||||
#pragma section=CSTACK_SECTION_NAME
|
||||
#pragma section = CODE_SECTION_NAME
|
||||
#pragma section = CSTACK_SECTION_NAME
|
||||
|
||||
/* Default only one code section. In fact, there may be more than one.
|
||||
You can define more than one and redefine the OsStackDataIsCodeAddr function
|
||||
|
||||
@@ -82,7 +82,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsCpupInit()
|
||||
|
||||
/*****************************************************************************
|
||||
Function : OsTskCycleStart
|
||||
Description: start task to get cycles count in current task begining
|
||||
Description: start task to get cycles count in current task beginning
|
||||
Input : None
|
||||
Return : None
|
||||
*****************************************************************************/
|
||||
|
||||
21
components/dynlink/los_dynlink.c
Executable file → Normal file
21
components/dynlink/los_dynlink.c
Executable file → Normal file
@@ -73,8 +73,8 @@ const SymInfo symTableEnd __attribute__((section(".table.end"))) = {
|
||||
.name = "end",
|
||||
.addr = 0
|
||||
};
|
||||
#pragma section=".TABLE.START"
|
||||
#pragma section=".table.end"
|
||||
#pragma section = ".TABLE.START"
|
||||
#pragma section = ".table.end"
|
||||
#elif defined(__CLANG_ARM) || defined(__GNUC__)
|
||||
/**
|
||||
* Place instructions below in rodata segment of .ld linker file:
|
||||
@@ -796,13 +796,13 @@ VOID *LOS_SoLoad(const CHAR *fileName, VOID *pool)
|
||||
return dso;
|
||||
|
||||
ERR2:
|
||||
LOS_MemFree(dso->pool, (VOID *)dso->loadBase);
|
||||
(VOID)LOS_MemFree(dso->pool, (VOID *)dso->loadBase);
|
||||
ERR1:
|
||||
close(dso->fd);
|
||||
(VOID)LOS_MuxPost(g_dynlinkMux);
|
||||
LOS_MemFree(OS_SYS_MEM_ADDR, dso->dlInfo->elfPhdr);
|
||||
LOS_MemFree(OS_SYS_MEM_ADDR, dso->dlInfo);
|
||||
LOS_MemFree(OS_SYS_MEM_ADDR, dso);
|
||||
(VOID)LOS_MemFree(OS_SYS_MEM_ADDR, dso->dlInfo->elfPhdr);
|
||||
(VOID)LOS_MemFree(OS_SYS_MEM_ADDR, dso->dlInfo);
|
||||
(VOID)LOS_MemFree(OS_SYS_MEM_ADDR, dso);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -902,9 +902,12 @@ INT32 LOS_SoUnload(VOID *handle)
|
||||
LOS_ListDelete(&dso->dsoNode);
|
||||
(VOID)LOS_MuxPost(g_dynlinkMux);
|
||||
|
||||
LOS_MemFree(dso->pool, (VOID *)dso->loadBase);
|
||||
LOS_MemFree(OS_SYS_MEM_ADDR, dso->dlInfo);
|
||||
LOS_MemFree(OS_SYS_MEM_ADDR, dso);
|
||||
(VOID)LOS_MemFree(dso->pool, (VOID *)dso->loadBase);
|
||||
if (dso->dlInfo != NULL) {
|
||||
(VOID)LOS_MemFree(OS_SYS_MEM_ADDR, dso->dlInfo->elfPhdr);
|
||||
}
|
||||
(VOID)LOS_MemFree(OS_SYS_MEM_ADDR, dso->dlInfo);
|
||||
(VOID)LOS_MemFree(OS_SYS_MEM_ADDR, dso);
|
||||
|
||||
return LOS_OK;
|
||||
ERR:
|
||||
|
||||
2
components/dynlink/los_dynlink.h
Executable file → Normal file
2
components/dynlink/los_dynlink.h
Executable file → Normal file
@@ -169,7 +169,7 @@ VOID *LOS_SoLoad(const CHAR *fileName, VOID *pool);
|
||||
VOID *LOS_FindSym(VOID *handle, const CHAR *name);
|
||||
|
||||
/*
|
||||
* @brief Decrement the reference count on the loaded shared library refered to by handle.
|
||||
* @brief Decrement the reference count on the loaded shared library referred to by handle.
|
||||
* If the reference count drops to zero, then the library is unloaded.
|
||||
*
|
||||
* This function validates that the handle is valid.
|
||||
|
||||
@@ -55,7 +55,7 @@ STATIC ExcInfoArray g_excArray[OS_EXC_TYPE_MAX];
|
||||
|
||||
STATIC UINT32 OsExcSaveIntStatus(UINT32 type, VOID *arg)
|
||||
{
|
||||
UINT32 ret;
|
||||
errno_t ret;
|
||||
UINTPTR excContentEnd = (UINTPTR)MAX_INT_INFO_SIZE + (UINTPTR)g_excContent;
|
||||
|
||||
(VOID)arg;
|
||||
@@ -92,6 +92,9 @@ STATIC UINT32 OsExcSaveIntStatus(UINT32 type, VOID *arg)
|
||||
/* save IRQ Priority reg group */
|
||||
ret = memcpy_s(g_excContent, excContentEnd - (UINTPTR)g_excContent,
|
||||
(const VOID *)OS_NVIC_PRI_BASE, OS_NVIC_INT_PRI_SIZE);
|
||||
if (ret != EOK) {
|
||||
return LOS_NOK;
|
||||
}
|
||||
g_excContent = (UINT8 *)g_excContent + OS_NVIC_INT_PRI_SIZE;
|
||||
|
||||
/* save Exception Priority reg group */
|
||||
@@ -294,5 +297,3 @@ VOID OsExcMsgDumpInit(VOID)
|
||||
(VOID)LOS_RegExcHook(EXC_INTERRUPT, (ExcHookFn)OsExcMsgDump);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -36,39 +36,3 @@ config FS_FAT
|
||||
help
|
||||
Answer Y to enable LiteOS support fat filesystem.
|
||||
|
||||
config FS_FAT_CACHE
|
||||
bool "Enable FAT Cache"
|
||||
default y
|
||||
depends on FS_FAT
|
||||
help
|
||||
Answer Y to enable LiteOS fat filesystem support cache.
|
||||
|
||||
config FS_FAT_CACHE_SYNC_THREAD
|
||||
bool "Enable FAT Cache Sync Thread"
|
||||
default n
|
||||
depends on FS_FAT_CACHE
|
||||
help
|
||||
Answer Y to enable LiteOS fat filesystem support cache sync thread.
|
||||
|
||||
config FS_FAT_CHINESE
|
||||
bool "Enable Chinese"
|
||||
default y
|
||||
depends on FS_FAT
|
||||
help
|
||||
Answer Y to enable LiteOS fat filesystem support Chinese.
|
||||
|
||||
config FS_FAT_VIRTUAL_PARTITION
|
||||
bool "Enabel Virtual Partition"
|
||||
default n
|
||||
depends on FS_FAT
|
||||
|
||||
config FS_FAT_VOLUMES
|
||||
int
|
||||
depends on FS_FAT
|
||||
default 32 if PLATFORM_HI3731
|
||||
default 16
|
||||
|
||||
config FS_FAT_DISK
|
||||
bool "Enable partinfo for storage device"
|
||||
depends on FS_FAT
|
||||
default y
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -32,14 +32,7 @@
|
||||
#ifndef _FATFS_H
|
||||
#define _FATFS_H
|
||||
|
||||
#include "dirent.h"
|
||||
#include "fatfs_conf.h"
|
||||
#include "fcntl.h"
|
||||
#include "fs_config.h"
|
||||
#include "sys/mount.h"
|
||||
#include "sys/stat.h"
|
||||
#include "sys/statfs.h"
|
||||
#include "unistd.h"
|
||||
#include "ff.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
@@ -47,58 +40,7 @@ extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
int fatfs_mount(const char *source, const char *target,
|
||||
const char *filesystemtype, unsigned long mountflags,
|
||||
const void *data);
|
||||
int fatfs_umount(const char *target);
|
||||
int fatfs_umount2(const char *target, int flag);
|
||||
int fatfs_open(const char *path, int oflag, ...);
|
||||
int fatfs_close(int fd);
|
||||
ssize_t fatfs_read(int fd, void *buf, size_t nbyte);
|
||||
ssize_t fatfs_write(int fd, const void *buf, size_t nbyte);
|
||||
off_t fatfs_lseek(int fd, off_t offset, int whence);
|
||||
int fatfs_unlink(const char *path);
|
||||
int fatfs_fstat(int fd, struct stat *buf);
|
||||
int fatfs_stat(const char *path, struct stat *buf);
|
||||
int fatfs_fsync(int fd);
|
||||
int fatfs_mkdir(const char *path, mode_t mode);
|
||||
DIR *fatfs_opendir(const char *dirName);
|
||||
struct dirent *fatfs_readdir(DIR *dir);
|
||||
int fatfs_closedir(DIR *dir);
|
||||
int fatfs_rmdir(const char *path);
|
||||
int fatfs_rename(const char *oldName, const char *newName);
|
||||
int fatfs_statfs(const char *path, struct statfs *buf);
|
||||
int fatfs_ftruncate(int fd, off_t length);
|
||||
ssize_t fatfs_pread(int fd, void *buf, size_t nbyte, off_t offset);
|
||||
ssize_t fatfs_pwrite(int fd, const void *buf, size_t nbyte, off_t offset);
|
||||
|
||||
/**
|
||||
* @brief divide a physical drive (SD card, U disk, and MMC card), this function is OHOS-specific
|
||||
* @param pdrv physical drive number.
|
||||
* @param partTbl list of partition size to create on the drive.
|
||||
* -- item is <= 100: specifies the partition size in percentage of the entire drive space.
|
||||
* -- item is > 100: specifies number of sectors.
|
||||
* @return fdisk result
|
||||
* @retval -1 fdisk error
|
||||
* @retval 0 fdisk successful
|
||||
*/
|
||||
int fatfs_fdisk(int pdrv, const unsigned int *partTbl);
|
||||
|
||||
/**
|
||||
* @brief format FAT device (SD card, U disk, and MMC card), this function is OHOS-specific
|
||||
* @param dev device name.
|
||||
* @param sectors sectors per cluster, can be 0 OR power of 2. The sector size for standard FAT volumes is 512 bytes.
|
||||
* -- sector number is 0 OR >128: automatically choose the appropriate cluster size.
|
||||
* -- sector number is 1 ~ 128: cluster size = sectors per cluster * 512B.
|
||||
* @param option file system type.
|
||||
* -- FMT_FAT
|
||||
* -- FMT_FAT32
|
||||
* -- FMT_ANY
|
||||
* @return format result
|
||||
* @retval -1 format error
|
||||
* @retval 0 format successful
|
||||
*/
|
||||
int fatfs_format(const char *dev, int sectors, int option);
|
||||
void FatFsInit(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
|
||||
@@ -34,7 +34,7 @@ module_switch = defined(LOSCFG_FS_LITTLEFS)
|
||||
module_name = get_path_info(rebase_path("."), "name")
|
||||
kernel_module(module_name) {
|
||||
configs += [ "$LITEOSTOPDIR:warn_config" ]
|
||||
sources = LITTLEFS_SRC_FILES_FOR_KERNEL_MODULE + [ "lfs_api.c" ]
|
||||
sources = LITTLEFS_SRC_FILES_FOR_KERNEL_MODULE + [ "lfs_adapter.c" ]
|
||||
}
|
||||
|
||||
config("public") {
|
||||
|
||||
596
components/fs/littlefs/lfs_adapter.c
Normal file
596
components/fs/littlefs/lfs_adapter.c
Normal file
@@ -0,0 +1,596 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#define _GNU_SOURCE 1
|
||||
#include "lfs_adapter.h"
|
||||
#include "los_config.h"
|
||||
#include "vfs_files.h"
|
||||
#include "vfs_operations.h"
|
||||
#include "vfs_partition.h"
|
||||
#include "vfs_maps.h"
|
||||
#include "vfs_mount.h"
|
||||
#include "securec.h"
|
||||
|
||||
struct dirent g_nameValue;
|
||||
static pthread_mutex_t g_FslocalMutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
static int ConvertFlagToLfsOpenFlag (int oflags)
|
||||
{
|
||||
int lfsOpenFlag = 0;
|
||||
|
||||
if (oflags & O_CREAT) {
|
||||
lfsOpenFlag |= LFS_O_CREAT;
|
||||
}
|
||||
|
||||
if (oflags & O_EXCL) {
|
||||
lfsOpenFlag |= LFS_O_EXCL;
|
||||
}
|
||||
|
||||
if (oflags & O_TRUNC) {
|
||||
lfsOpenFlag |= LFS_O_TRUNC;
|
||||
}
|
||||
|
||||
if (oflags & O_APPEND) {
|
||||
lfsOpenFlag |= LFS_O_APPEND;
|
||||
}
|
||||
|
||||
if (oflags & O_RDWR) {
|
||||
lfsOpenFlag |= LFS_O_RDWR;
|
||||
}
|
||||
|
||||
if (oflags & O_WRONLY) {
|
||||
lfsOpenFlag |= LFS_O_WRONLY;
|
||||
}
|
||||
|
||||
if (oflags == O_RDONLY) {
|
||||
lfsOpenFlag |= LFS_O_RDONLY;
|
||||
}
|
||||
|
||||
return lfsOpenFlag;
|
||||
}
|
||||
|
||||
static int LittlefsErrno(int result)
|
||||
{
|
||||
return (result < 0) ? -result : result;
|
||||
}
|
||||
|
||||
int LfsMount(struct MountPoint *mp, unsigned long mountflags, const void *data)
|
||||
{
|
||||
int ret;
|
||||
lfs_t *mountHdl = NULL;
|
||||
|
||||
if ((mp == NULL) || (mp->mPath == NULL) || (data == NULL)) {
|
||||
errno = EFAULT;
|
||||
ret = LOS_NOK;
|
||||
goto errout;
|
||||
}
|
||||
|
||||
mountHdl = (lfs_t *)malloc(sizeof(lfs_t));
|
||||
if (mountHdl == NULL) {
|
||||
errno = ENODEV;
|
||||
ret = LOS_NOK;
|
||||
goto errout;
|
||||
}
|
||||
(void)memset_s(mountHdl, sizeof(lfs_t), 0, sizeof(lfs_t));
|
||||
mp->mData = (void *)mountHdl;
|
||||
|
||||
ret = lfs_mount((lfs_t *)mp->mData, (struct lfs_config *)data);
|
||||
if (ret != 0) {
|
||||
ret = lfs_format((lfs_t *)mp->mData, (struct lfs_config*)data);
|
||||
if (ret == 0) {
|
||||
ret = lfs_mount((lfs_t *)mp->mData, (struct lfs_config*)data);
|
||||
}
|
||||
}
|
||||
|
||||
if (ret != 0) {
|
||||
free(mountHdl);
|
||||
errno = LittlefsErrno(ret);
|
||||
ret = LOS_NOK;
|
||||
}
|
||||
|
||||
errout:
|
||||
return ret;
|
||||
}
|
||||
|
||||
int LfsUmount(struct MountPoint *mp)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (mp == NULL) {
|
||||
errno = EFAULT;
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
if (mp->mData == NULL) {
|
||||
errno = ENOENT;
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
ret = lfs_unmount((lfs_t *)mp->mData);
|
||||
if (ret != 0) {
|
||||
errno = LittlefsErrno(ret);
|
||||
ret = LOS_NOK;
|
||||
}
|
||||
|
||||
free(mp->mData);
|
||||
mp->mData = NULL;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int LfsUnlink(struct MountPoint *mp, const char *fileName)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if ((mp == NULL) || (fileName == NULL)) {
|
||||
errno = EFAULT;
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
if (mp->mData == NULL) {
|
||||
errno = ENOENT;
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
ret = lfs_remove((lfs_t *)mp->mData, fileName);
|
||||
if (ret != 0) {
|
||||
errno = LittlefsErrno(ret);
|
||||
ret = LOS_NOK;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int LfsMkdir(struct MountPoint *mp, const char *dirName)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if ((dirName == NULL) || (mp == NULL)) {
|
||||
errno = EFAULT;
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
if (mp->mData == NULL) {
|
||||
errno = ENOENT;
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
lfs_t *lfs = (lfs_t *)mp->mData;
|
||||
|
||||
ret = lfs_mkdir(lfs, dirName);
|
||||
if (ret != 0) {
|
||||
errno = LittlefsErrno(ret);
|
||||
ret = LOS_NOK;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int LfsRmdir(struct MountPoint *mp, const char *dirName)
|
||||
{
|
||||
int ret;
|
||||
lfs_t *lfs = NULL;
|
||||
|
||||
if (mp == NULL) {
|
||||
errno = EFAULT;
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
if (mp->mData == NULL) {
|
||||
errno = ENOENT;
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
lfs = (lfs_t *)mp->mData;
|
||||
|
||||
if (dirName == NULL) {
|
||||
errno = EFAULT;
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
ret = lfs_remove(lfs, dirName);
|
||||
if (ret != 0) {
|
||||
errno = LittlefsErrno(ret);
|
||||
ret = LOS_NOK;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int LfsOpendir(struct Dir *dir, const char *dirName)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if ((dir == NULL) || (dir->dMp == NULL) || (dir->dMp->mData == NULL)) {
|
||||
errno = EFAULT;
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
lfs_t *lfs = (lfs_t *)dir->dMp->mData;
|
||||
lfs_dir_t *dirInfo = (lfs_dir_t *)malloc(sizeof(lfs_dir_t));
|
||||
if (dirInfo == NULL) {
|
||||
errno = ENOMEM;
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
(void)memset_s(dirInfo, sizeof(lfs_dir_t), 0, sizeof(lfs_dir_t));
|
||||
ret = lfs_dir_open(lfs, dirInfo, dirName);
|
||||
if (ret != 0) {
|
||||
free(dirInfo);
|
||||
errno = LittlefsErrno(ret);
|
||||
goto errout;
|
||||
}
|
||||
|
||||
dir->dData = dirInfo;
|
||||
dir->dOffset = 0;
|
||||
|
||||
return LOS_OK;
|
||||
|
||||
errout:
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
int LfsReaddir(struct Dir *dir, struct dirent *dent)
|
||||
{
|
||||
int ret;
|
||||
struct lfs_info lfsInfo;
|
||||
|
||||
if ((dir == NULL) || (dir->dMp == NULL) || (dir->dMp->mData == NULL) ||
|
||||
(dent == NULL)) {
|
||||
errno = EFAULT;
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
if (dir->dData == NULL) {
|
||||
errno = EBADF;
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
lfs_t *lfs = (lfs_t *)dir->dMp->mData;
|
||||
lfs_dir_t *dirInfo = (lfs_dir_t *)dir->dData;
|
||||
|
||||
ret = lfs_dir_read(lfs, dirInfo, &lfsInfo);
|
||||
if (ret == TRUE) {
|
||||
pthread_mutex_lock(&g_FslocalMutex);
|
||||
(void)strncpy_s(dent->d_name, sizeof(dent->d_name), lfsInfo.name, strlen(lfsInfo.name) + 1);
|
||||
if (lfsInfo.type == LFS_TYPE_DIR) {
|
||||
dent->d_type = DT_DIR;
|
||||
} else if (lfsInfo.type == LFS_TYPE_REG) {
|
||||
dent->d_type = DT_REG;
|
||||
}
|
||||
|
||||
dent->d_reclen = lfsInfo.size;
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
if (ret != 0) {
|
||||
errno = LittlefsErrno(ret);
|
||||
}
|
||||
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
int LfsClosedir(struct Dir *dir)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if ((dir == NULL) || (dir->dMp == NULL) || (dir->dMp->mData == NULL)) {
|
||||
errno = EFAULT;
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
if (dir->dData == NULL) {
|
||||
errno = EBADF;
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
lfs_t *lfs = (lfs_t *)dir->dMp->mData;
|
||||
lfs_dir_t *dirInfo = (lfs_dir_t *)dir->dData;
|
||||
|
||||
ret = lfs_dir_close(lfs, dirInfo);
|
||||
if (ret != 0) {
|
||||
errno = LittlefsErrno(ret);
|
||||
ret = LOS_NOK;
|
||||
}
|
||||
|
||||
free(dirInfo);
|
||||
dir->dData = NULL;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int LfsOpen(struct File *file, const char *pathName, int openFlag)
|
||||
{
|
||||
int ret;
|
||||
lfs_file_t *lfsHandle = NULL;
|
||||
|
||||
if ((pathName == NULL) || (file == NULL) || (file->fMp == NULL) ||
|
||||
(file->fMp->mData == NULL)) {
|
||||
errno = EFAULT;
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
lfsHandle = (lfs_file_t *)malloc(sizeof(lfs_file_t));
|
||||
if (lfsHandle == NULL) {
|
||||
errno = ENOMEM;
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
int lfsOpenFlag = ConvertFlagToLfsOpenFlag(openFlag);
|
||||
ret = lfs_file_open((lfs_t *)file->fMp->mData, lfsHandle, pathName, lfsOpenFlag);
|
||||
if (ret != 0) {
|
||||
free(lfsHandle);
|
||||
errno = LittlefsErrno(ret);
|
||||
goto errout;
|
||||
}
|
||||
|
||||
file->fData = (void *)lfsHandle;
|
||||
return ret;
|
||||
|
||||
errout:
|
||||
return INVALID_FD;
|
||||
}
|
||||
|
||||
int LfsRead(struct File *file, char *buf, size_t len)
|
||||
{
|
||||
int ret;
|
||||
struct MountPoint *mp = NULL;
|
||||
lfs_file_t *lfsHandle = NULL;
|
||||
|
||||
if (buf == NULL) {
|
||||
errno = EFAULT;
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
if ((file == NULL) || (file->fData == NULL)) {
|
||||
errno = EBADF;
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
lfsHandle = (lfs_file_t *)file->fData;
|
||||
mp = file->fMp;
|
||||
if ((mp == NULL) || (mp->mData == NULL)) {
|
||||
errno = EFAULT;
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
ret = lfs_file_read((lfs_t *)mp->mData, lfsHandle, buf, len);
|
||||
if (ret < 0) {
|
||||
errno = LittlefsErrno(ret);
|
||||
ret = LOS_NOK;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int LfsWrite(struct File *file, const char *buf, size_t len)
|
||||
{
|
||||
int ret;
|
||||
struct MountPoint *mp = NULL;
|
||||
lfs_file_t *lfsHandle = NULL;
|
||||
|
||||
if (buf == NULL) {
|
||||
errno = EFAULT;
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
if ((file == NULL) || (file->fData == NULL)) {
|
||||
errno = EBADF;
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
lfsHandle = (lfs_file_t *)file->fData;
|
||||
mp = file->fMp;
|
||||
if ((mp == NULL) || (mp->mData == NULL)) {
|
||||
errno = EFAULT;
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
ret = lfs_file_write((lfs_t *)mp->mData, lfsHandle, buf, len);
|
||||
if (ret < 0) {
|
||||
errno = LittlefsErrno(ret);
|
||||
ret = LOS_NOK;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
off_t LfsSeek(struct File *file, off_t offset, int whence)
|
||||
{
|
||||
off_t ret;
|
||||
struct MountPoint *mp = NULL;
|
||||
lfs_file_t *lfsHandle = NULL;
|
||||
|
||||
if ((file == NULL) || (file->fData == NULL)) {
|
||||
errno = EBADF;
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
lfsHandle = (lfs_file_t *)file->fData;
|
||||
mp = file->fMp;
|
||||
if ((mp == NULL) || (mp->mData == NULL)) {
|
||||
errno = EFAULT;
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
ret = (off_t)lfs_file_seek((lfs_t *)mp->mData, lfsHandle, offset, whence);
|
||||
if (ret < 0) {
|
||||
errno = LittlefsErrno(ret);
|
||||
ret = LOS_NOK;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int LfsClose(struct File *file)
|
||||
{
|
||||
INT32 ret;
|
||||
struct MountPoint *mp = NULL;
|
||||
lfs_file_t *lfsHandle = NULL;
|
||||
|
||||
if ((file == NULL) || (file->fData == NULL)) {
|
||||
errno = EBADF;
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
lfsHandle = (lfs_file_t *)file->fData;
|
||||
mp = file->fMp;
|
||||
if ((mp == NULL) || (mp->mData == NULL)) {
|
||||
errno = EFAULT;
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&g_FslocalMutex);
|
||||
ret = lfs_file_close((lfs_t *)mp->mData, lfsHandle);
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
|
||||
if (ret != 0) {
|
||||
errno = LittlefsErrno(ret);
|
||||
ret = LOS_NOK;
|
||||
}
|
||||
|
||||
free(file->fData);
|
||||
file->fData = NULL;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int LfsRename(struct MountPoint *mp, const char *oldName, const char *newName)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if ((mp == NULL) || (oldName == NULL) || (newName == NULL)) {
|
||||
errno = EFAULT;
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
if (mp->mData == NULL) {
|
||||
errno = ENOENT;
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
ret = lfs_rename((lfs_t *)mp->mData, oldName, newName);
|
||||
if (ret != 0) {
|
||||
errno = LittlefsErrno(ret);
|
||||
ret = LOS_NOK;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int LfsStat(struct MountPoint *mp, const char *path, struct stat *buf)
|
||||
{
|
||||
int ret;
|
||||
struct lfs_info info;
|
||||
|
||||
if ((mp == NULL) || (path == NULL) || (buf == NULL)) {
|
||||
errno = EFAULT;
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
if (mp->mData == NULL) {
|
||||
errno = ENOENT;
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
ret = lfs_stat((lfs_t *)mp->mData, path, &info);
|
||||
if (ret == 0) {
|
||||
buf->st_size = info.size;
|
||||
if (info.type == LFS_TYPE_REG) {
|
||||
buf->st_mode = S_IFREG;
|
||||
} else {
|
||||
buf->st_mode = S_IFDIR;
|
||||
}
|
||||
} else {
|
||||
errno = LittlefsErrno(ret);
|
||||
ret = LOS_NOK;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int LfsSync(struct File *file)
|
||||
{
|
||||
int ret;
|
||||
struct MountPoint *mp = NULL;
|
||||
|
||||
if ((file == NULL) || (file->fData == NULL)) {
|
||||
errno = EBADF;
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
if ((file->fMp == NULL) || (file->fMp->mData == NULL)) {
|
||||
errno = EFAULT;
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
mp = file->fMp;
|
||||
ret = lfs_file_sync((lfs_t *)mp->mData, (lfs_file_t *)file->fData);
|
||||
if (ret != 0) {
|
||||
errno = LittlefsErrno(ret);
|
||||
ret = LOS_NOK;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static struct MountOps g_lfsMnt = {
|
||||
.mount = LfsMount,
|
||||
.umount = LfsUmount,
|
||||
.umount2 = NULL,
|
||||
.statfs = NULL,
|
||||
};
|
||||
|
||||
static struct FileOps g_lfsFops = {
|
||||
.open = LfsOpen,
|
||||
.close = LfsClose,
|
||||
.read = LfsRead,
|
||||
.write = LfsWrite,
|
||||
.lseek = LfsSeek,
|
||||
.stat = LfsStat,
|
||||
.truncate = NULL,
|
||||
.unlink = LfsUnlink,
|
||||
.rename = LfsRename,
|
||||
.ioctl = NULL, /* not support */
|
||||
.sync = LfsSync,
|
||||
.rmdir = LfsRmdir,
|
||||
.opendir = LfsOpendir,
|
||||
.readdir = LfsReaddir,
|
||||
.closedir = LfsClosedir,
|
||||
.mkdir = LfsMkdir,
|
||||
};
|
||||
|
||||
static struct FsManagement g_lfsMgt = {
|
||||
.fdisk = NULL,
|
||||
.format = NULL,
|
||||
};
|
||||
|
||||
void LfsInit(void)
|
||||
{
|
||||
(void)OsFsRegister("littlefs", &g_lfsMnt, &g_lfsFops, &g_lfsMgt);
|
||||
}
|
||||
@@ -29,15 +29,15 @@
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _LFS_API_H_
|
||||
#define _LFS_API_H_
|
||||
#ifndef _LFS_ADAPTER_H_
|
||||
#define _LFS_ADAPTER_H_
|
||||
|
||||
#include "fcntl.h"
|
||||
#include "sys/stat.h"
|
||||
|
||||
#include "dirent.h"
|
||||
#include "errno.h"
|
||||
#include "fs_operations.h"
|
||||
#include "vfs_operations.h"
|
||||
#include "lfs.h"
|
||||
#include "lfs_conf.h"
|
||||
#include "lfs_util.h"
|
||||
@@ -46,59 +46,5 @@
|
||||
|
||||
#define INVALID_FD (-1)
|
||||
|
||||
#ifndef VFS_ERROR
|
||||
#define VFS_ERROR (-1)
|
||||
#endif
|
||||
|
||||
#ifndef VFS_OK
|
||||
#define VFS_OK 0
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
uint8_t useFlag;
|
||||
const char *pathName;
|
||||
lfs_t *lfsHandle;
|
||||
lfs_file_t file;
|
||||
} LittleFsHandleStruct;
|
||||
|
||||
struct FileOpInfo {
|
||||
uint8_t useFlag;
|
||||
const struct FileOps *fsVops;
|
||||
char *dirName;
|
||||
lfs_t lfsInfo;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
uint8_t useFlag;
|
||||
char *dirName;
|
||||
lfs_t *lfsHandle;
|
||||
lfs_dir_t dir;
|
||||
} FileDirInfo;
|
||||
|
||||
LittleFsHandleStruct *GetFreeFd(int *fd);
|
||||
|
||||
int LfsMount(const char *source, const char *target, const char *fileSystemType, unsigned long mountflags,
|
||||
const void *data);
|
||||
|
||||
int LfsUmount(const char *target);
|
||||
int LfsUnlink(const char *fileName);
|
||||
int LfsMkdir(const char *dirName, mode_t mode);
|
||||
int LfsRmdir(const char *dirName);
|
||||
DIR *LfsOpendir(const char *dirName);
|
||||
struct dirent *LfsReaddir(DIR *dir);
|
||||
int LfsClosedir(DIR *dir);
|
||||
int LfsOpen(const char *pathName, int openFlag, ...);
|
||||
int LfsRead(int fd, void *buf, unsigned int len);
|
||||
int LfsWrite(int fd, const void *buf, unsigned int len);
|
||||
off_t LfsSeek(int fd, off_t offset, int whence);
|
||||
int LfsClose(int fd);
|
||||
int LfsRename(const char *oldName, const char *newName);
|
||||
int LfsStat(const char *path, struct stat *buf);
|
||||
int LfsFsync(int fd);
|
||||
int LfsFstat(int fd, struct stat *buf);
|
||||
int SetDefaultMountPath(int pathNameIndex, const char* target);
|
||||
int LfsPread(int fd, void *buf, size_t nbyte, off_t offset);
|
||||
int LfsPwrite(int fd, const void *buf, size_t nbyte, off_t offset);
|
||||
|
||||
#endif /* _LFS_API_H_ */
|
||||
|
||||
void LfsInit(void);
|
||||
#endif /* _LFS_ADAPTER_H_ */
|
||||
@@ -1,891 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#define _GNU_SOURCE 1
|
||||
#include "lfs_api.h"
|
||||
#include "los_config.h"
|
||||
#include "securec.h"
|
||||
|
||||
lfs_t g_lfs;
|
||||
FileDirInfo g_lfsDir[LFS_MAX_OPEN_DIRS] = {0};
|
||||
|
||||
struct FileOpInfo g_fsOp[LOSCFG_LFS_MAX_MOUNT_SIZE] = {0};
|
||||
static LittleFsHandleStruct g_handle[LOSCFG_LFS_MAX_OPEN_FILES] = {0};
|
||||
struct dirent g_nameValue;
|
||||
static pthread_mutex_t g_FslocalMutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
static const char *g_littlefsMntName[LOSCFG_LFS_MAX_MOUNT_SIZE] = {"/a"};
|
||||
|
||||
LittleFsHandleStruct *LfsAllocFd(const char *fileName, int *fd)
|
||||
{
|
||||
pthread_mutex_lock(&g_FslocalMutex);
|
||||
for (int i = 0; i < LOSCFG_LFS_MAX_OPEN_FILES; i++) {
|
||||
if (g_handle[i].useFlag == 0) {
|
||||
*fd = i;
|
||||
g_handle[i].useFlag = 1;
|
||||
g_handle[i].pathName = strdup(fileName);
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
return &(g_handle[i]);
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
*fd = INVALID_FD;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void LfsFreeFd(int fd)
|
||||
{
|
||||
pthread_mutex_lock(&g_FslocalMutex);
|
||||
g_handle[fd].useFlag = 0;
|
||||
if (g_handle[fd].pathName != NULL) {
|
||||
free((void *)g_handle[fd].pathName);
|
||||
g_handle[fd].pathName = NULL;
|
||||
}
|
||||
|
||||
if (g_handle[fd].lfsHandle != NULL) {
|
||||
g_handle[fd].lfsHandle = NULL;
|
||||
}
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
}
|
||||
|
||||
BOOL CheckFileIsOpen(const char *fileName)
|
||||
{
|
||||
pthread_mutex_lock(&g_FslocalMutex);
|
||||
for (int i = 0; i < LOSCFG_LFS_MAX_OPEN_FILES; i++) {
|
||||
if (g_handle[i].useFlag == 1) {
|
||||
if (strcmp(g_handle[i].pathName, fileName) == 0) {
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static BOOL LfsFdIsValid(int fd)
|
||||
{
|
||||
if (fd >= LOSCFG_LFS_MAX_OPEN_FILES || fd < 0) {
|
||||
return FALSE;
|
||||
}
|
||||
if (g_handle[fd].lfsHandle == NULL) {
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
FileDirInfo *GetFreeDir(const char *dirName)
|
||||
{
|
||||
pthread_mutex_lock(&g_FslocalMutex);
|
||||
for (int i = 0; i < LFS_MAX_OPEN_DIRS; i++) {
|
||||
if (g_lfsDir[i].useFlag == 0) {
|
||||
g_lfsDir[i].useFlag = 1;
|
||||
g_lfsDir[i].dirName = strdup(dirName);
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
return &(g_lfsDir[i]);
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void FreeDirInfo(const char *dirName)
|
||||
{
|
||||
pthread_mutex_lock(&g_FslocalMutex);
|
||||
for (int i = 0; i < LFS_MAX_OPEN_DIRS; i++) {
|
||||
if (g_lfsDir[i].useFlag == 1 && strcmp(g_lfsDir[i].dirName, dirName) == 0) {
|
||||
g_lfsDir[i].useFlag = 0;
|
||||
if (g_lfsDir[i].dirName) {
|
||||
free(g_lfsDir[i].dirName);
|
||||
g_lfsDir[i].dirName = NULL;
|
||||
}
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
}
|
||||
|
||||
BOOL CheckDirIsOpen(const char *dirName)
|
||||
{
|
||||
pthread_mutex_lock(&g_FslocalMutex);
|
||||
for (int i = 0; i < LFS_MAX_OPEN_DIRS; i++) {
|
||||
if (g_lfsDir[i].useFlag == 1) {
|
||||
if (strcmp(g_lfsDir[i].dirName, dirName) == 0) {
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
int GetFirstLevelPathLen(const char *pathName)
|
||||
{
|
||||
int len = 1;
|
||||
for (int i = 1; i < strlen(pathName) + 1; i++) {
|
||||
if (pathName[i] == '/') {
|
||||
break;
|
||||
}
|
||||
len++;
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
BOOL CheckPathIsMounted(const char *pathName, struct FileOpInfo **fileOpInfo)
|
||||
{
|
||||
char tmpName[LITTLEFS_MAX_LFN_LEN] = {0};
|
||||
int len = GetFirstLevelPathLen(pathName);
|
||||
|
||||
pthread_mutex_lock(&g_FslocalMutex);
|
||||
for (int i = 0; i < LOSCFG_LFS_MAX_MOUNT_SIZE; i++) {
|
||||
if (g_fsOp[i].useFlag == 1) {
|
||||
(void)strncpy_s(tmpName, LITTLEFS_MAX_LFN_LEN, pathName, len);
|
||||
if (strcmp(tmpName, g_fsOp[i].dirName) == 0) {
|
||||
*fileOpInfo = &(g_fsOp[i]);
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
struct FileOpInfo *AllocMountRes(const char* target, const struct FileOps *fileOps)
|
||||
{
|
||||
pthread_mutex_lock(&g_FslocalMutex);
|
||||
for (int i = 0; i < LOSCFG_LFS_MAX_MOUNT_SIZE; i++) {
|
||||
if (g_fsOp[i].useFlag == 0 && strcmp(target, g_littlefsMntName[i]) == 0) {
|
||||
g_fsOp[i].useFlag = 1;
|
||||
g_fsOp[i].fsVops = fileOps;
|
||||
g_fsOp[i].dirName = strdup(target);
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
return &(g_fsOp[i]);
|
||||
}
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int SetDefaultMountPath(int pathNameIndex, const char* target)
|
||||
{
|
||||
if (pathNameIndex >= LOSCFG_LFS_MAX_MOUNT_SIZE) {
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&g_FslocalMutex);
|
||||
g_littlefsMntName[pathNameIndex] = strdup(target);
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
return VFS_OK;
|
||||
}
|
||||
|
||||
struct FileOpInfo *GetMountRes(const char *target, int *mountIndex)
|
||||
{
|
||||
pthread_mutex_lock(&g_FslocalMutex);
|
||||
for (int i = 0; i < LOSCFG_LFS_MAX_MOUNT_SIZE; i++) {
|
||||
if (g_fsOp[i].useFlag == 1) {
|
||||
if (g_fsOp[i].dirName && strcmp(target, g_fsOp[i].dirName) == 0) {
|
||||
*mountIndex = i;
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
return &(g_fsOp[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int FreeMountResByIndex(int mountIndex)
|
||||
{
|
||||
if (mountIndex < 0 || mountIndex >= LOSCFG_LFS_MAX_MOUNT_SIZE) {
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&g_FslocalMutex);
|
||||
if (g_fsOp[mountIndex].useFlag == 1 && g_fsOp[mountIndex].dirName != NULL) {
|
||||
g_fsOp[mountIndex].useFlag = 0;
|
||||
free(g_fsOp[mountIndex].dirName);
|
||||
g_fsOp[mountIndex].dirName = NULL;
|
||||
}
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
|
||||
return VFS_OK;
|
||||
}
|
||||
|
||||
int FreeMountRes(const char *target)
|
||||
{
|
||||
pthread_mutex_lock(&g_FslocalMutex);
|
||||
for (int i = 0; i < LOSCFG_LFS_MAX_MOUNT_SIZE; i++) {
|
||||
if (g_fsOp[i].useFlag == 1) {
|
||||
if (g_fsOp[i].dirName && strcmp(target, g_fsOp[i].dirName) == 0) {
|
||||
g_fsOp[i].useFlag = 0;
|
||||
free(g_fsOp[i].dirName);
|
||||
g_fsOp[i].dirName = NULL;
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
return VFS_OK;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
static int ConvertFlagToLfsOpenFlag (int oflags)
|
||||
{
|
||||
int lfsOpenFlag = 0;
|
||||
|
||||
if (oflags & O_CREAT) {
|
||||
lfsOpenFlag |= LFS_O_CREAT;
|
||||
}
|
||||
|
||||
if (oflags & O_EXCL) {
|
||||
lfsOpenFlag |= LFS_O_EXCL;
|
||||
}
|
||||
|
||||
if (oflags & O_TRUNC) {
|
||||
lfsOpenFlag |= LFS_O_TRUNC;
|
||||
}
|
||||
|
||||
if (oflags & O_APPEND) {
|
||||
lfsOpenFlag |= LFS_O_APPEND;
|
||||
}
|
||||
|
||||
if (oflags & O_RDWR) {
|
||||
lfsOpenFlag |= LFS_O_RDWR;
|
||||
}
|
||||
|
||||
if (oflags & O_WRONLY) {
|
||||
lfsOpenFlag |= LFS_O_WRONLY;
|
||||
}
|
||||
|
||||
if (oflags == O_RDONLY) {
|
||||
lfsOpenFlag |= LFS_O_RDONLY;
|
||||
}
|
||||
|
||||
return lfsOpenFlag;
|
||||
}
|
||||
|
||||
static int LittlefsErrno(int result)
|
||||
{
|
||||
return (result < 0) ? -result : result;
|
||||
}
|
||||
|
||||
const struct MountOps g_lfsMnt = {
|
||||
.Mount = LfsMount,
|
||||
.Umount = LfsUmount,
|
||||
};
|
||||
|
||||
const struct FileOps g_lfsFops = {
|
||||
.Mkdir = LfsMkdir,
|
||||
.Unlink = LfsUnlink,
|
||||
.Rmdir = LfsRmdir,
|
||||
.Opendir = LfsOpendir,
|
||||
.Readdir = LfsReaddir,
|
||||
.Closedir = LfsClosedir,
|
||||
.Open = LfsOpen,
|
||||
.Close = LfsClose,
|
||||
.Write = LfsWrite,
|
||||
.Read = LfsRead,
|
||||
.Seek = LfsSeek,
|
||||
.Rename = LfsRename,
|
||||
.Getattr = LfsStat,
|
||||
.Fsync = LfsFsync,
|
||||
.Fstat = LfsFstat,
|
||||
.Pread = LfsPread,
|
||||
.Pwrite = LfsPwrite,
|
||||
};
|
||||
|
||||
int LfsMount(const char *source, const char *target, const char *fileSystemType, unsigned long mountflags,
|
||||
const void *data)
|
||||
{
|
||||
int ret;
|
||||
struct FileOpInfo *fileOpInfo = NULL;
|
||||
|
||||
if (target == NULL || fileSystemType == NULL || data == NULL) {
|
||||
errno = EFAULT;
|
||||
ret = VFS_ERROR;
|
||||
goto errout;
|
||||
}
|
||||
|
||||
if (strcmp(fileSystemType, "littlefs") != 0) {
|
||||
errno = ENODEV;
|
||||
ret = VFS_ERROR;
|
||||
goto errout;
|
||||
}
|
||||
|
||||
if (CheckPathIsMounted(target, &fileOpInfo)) {
|
||||
errno = EBUSY;
|
||||
ret = VFS_ERROR;
|
||||
goto errout;
|
||||
}
|
||||
|
||||
// select free mount resource
|
||||
fileOpInfo = AllocMountRes(target, &g_lfsFops);
|
||||
if (fileOpInfo == NULL) {
|
||||
errno = ENODEV;
|
||||
ret = VFS_ERROR;
|
||||
goto errout;
|
||||
}
|
||||
|
||||
ret = lfs_mount(&(fileOpInfo->lfsInfo), (struct lfs_config*)data);
|
||||
if (ret != 0) {
|
||||
ret = lfs_format(&(fileOpInfo->lfsInfo), (struct lfs_config*)data);
|
||||
if (ret == 0) {
|
||||
ret = lfs_mount(&(fileOpInfo->lfsInfo), (struct lfs_config*)data);
|
||||
}
|
||||
}
|
||||
|
||||
if (ret != 0) {
|
||||
errno = LittlefsErrno(ret);
|
||||
ret = VFS_ERROR;
|
||||
}
|
||||
|
||||
errout:
|
||||
return ret;
|
||||
}
|
||||
|
||||
int LfsUmount(const char *target)
|
||||
{
|
||||
int ret;
|
||||
int mountIndex = -1;
|
||||
struct FileOpInfo *fileOpInfo = NULL;
|
||||
|
||||
if (target == NULL) {
|
||||
errno = EFAULT;
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
fileOpInfo = GetMountRes(target, &mountIndex);
|
||||
if (fileOpInfo == NULL) {
|
||||
errno = ENOENT;
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
ret = lfs_unmount(&(fileOpInfo->lfsInfo));
|
||||
if (ret != 0) {
|
||||
errno = LittlefsErrno(ret);
|
||||
ret = VFS_ERROR;
|
||||
}
|
||||
|
||||
(void)FreeMountResByIndex(mountIndex);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int LfsUnlink(const char *fileName)
|
||||
{
|
||||
int ret;
|
||||
struct FileOpInfo *fileOpInfo = NULL;
|
||||
|
||||
if (fileName == NULL) {
|
||||
errno = EFAULT;
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
if (CheckPathIsMounted(fileName, &fileOpInfo) == FALSE || fileOpInfo == NULL) {
|
||||
errno = ENOENT;
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
ret = lfs_remove(&(fileOpInfo->lfsInfo), fileName);
|
||||
if (ret != 0) {
|
||||
errno = LittlefsErrno(ret);
|
||||
ret = VFS_ERROR;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int LfsMkdir(const char *dirName, mode_t mode)
|
||||
{
|
||||
int ret;
|
||||
struct FileOpInfo *fileOpInfo = NULL;
|
||||
|
||||
if (dirName == NULL) {
|
||||
errno = EFAULT;
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
if (CheckPathIsMounted(dirName, &fileOpInfo) == FALSE || fileOpInfo == NULL) {
|
||||
errno = ENOENT;
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
ret = lfs_mkdir(&(fileOpInfo->lfsInfo), dirName);
|
||||
if (ret != 0) {
|
||||
errno = LittlefsErrno(ret);
|
||||
ret = VFS_ERROR;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int LfsRmdir(const char *dirName)
|
||||
{
|
||||
int ret;
|
||||
|
||||
struct FileOpInfo *fileOpInfo = NULL;
|
||||
|
||||
if (dirName == NULL) {
|
||||
errno = EFAULT;
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
if (CheckPathIsMounted(dirName, &fileOpInfo) == FALSE || fileOpInfo == NULL) {
|
||||
errno = ENOENT;
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
ret = lfs_remove(&(fileOpInfo->lfsInfo), dirName);
|
||||
if (ret != 0) {
|
||||
errno = LittlefsErrno(ret);
|
||||
ret = VFS_ERROR;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
DIR *LfsOpendir(const char *dirName)
|
||||
{
|
||||
int ret;
|
||||
struct FileOpInfo *fileOpInfo = NULL;
|
||||
|
||||
if (dirName == NULL) {
|
||||
errno = EFAULT;
|
||||
goto errout;
|
||||
}
|
||||
|
||||
if (CheckPathIsMounted(dirName, &fileOpInfo) == FALSE || fileOpInfo == NULL) {
|
||||
errno = ENOENT;
|
||||
goto errout;
|
||||
}
|
||||
|
||||
if (CheckDirIsOpen(dirName)) {
|
||||
errno = EBUSY;
|
||||
goto errout;
|
||||
}
|
||||
|
||||
FileDirInfo *dirInfo = GetFreeDir(dirName);
|
||||
if (dirInfo == NULL) {
|
||||
errno = ENFILE;
|
||||
goto errout;
|
||||
}
|
||||
|
||||
ret = lfs_dir_open(&(fileOpInfo->lfsInfo), (lfs_dir_t *)(&(dirInfo->dir)), dirName);
|
||||
|
||||
if (ret != 0) {
|
||||
FreeDirInfo(dirName);
|
||||
errno = LittlefsErrno(ret);
|
||||
goto errout;
|
||||
}
|
||||
|
||||
dirInfo->lfsHandle = &(fileOpInfo->lfsInfo);
|
||||
|
||||
return (DIR *)dirInfo;
|
||||
|
||||
errout:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct dirent *LfsReaddir(DIR *dir)
|
||||
{
|
||||
int ret;
|
||||
struct lfs_info lfsInfo;
|
||||
|
||||
FileDirInfo *dirInfo = (FileDirInfo *)dir;
|
||||
|
||||
if (dirInfo == NULL || dirInfo->lfsHandle == NULL) {
|
||||
errno = EBADF;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ret = lfs_dir_read(dirInfo->lfsHandle, (lfs_dir_t *)(&(dirInfo->dir)), &lfsInfo);
|
||||
if (ret == TRUE) {
|
||||
pthread_mutex_lock(&g_FslocalMutex);
|
||||
(void)strncpy_s(g_nameValue.d_name, sizeof(g_nameValue.d_name), lfsInfo.name, strlen(lfsInfo.name) + 1);
|
||||
if (lfsInfo.type == LFS_TYPE_DIR) {
|
||||
g_nameValue.d_type = DT_DIR;
|
||||
} else if (lfsInfo.type == LFS_TYPE_REG) {
|
||||
g_nameValue.d_type = DT_REG;
|
||||
}
|
||||
|
||||
g_nameValue.d_reclen = lfsInfo.size;
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
|
||||
return &g_nameValue;
|
||||
}
|
||||
|
||||
if (ret != 0) {
|
||||
errno = LittlefsErrno(ret);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int LfsClosedir(DIR *dir)
|
||||
{
|
||||
int ret;
|
||||
FileDirInfo *dirInfo = (FileDirInfo *)dir;
|
||||
|
||||
if (dirInfo == NULL || dirInfo->lfsHandle == NULL) {
|
||||
errno = EBADF;
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
ret = lfs_dir_close(dirInfo->lfsHandle, (lfs_dir_t *)(&(dirInfo->dir)));
|
||||
|
||||
FreeDirInfo(dirInfo->dirName);
|
||||
|
||||
if (ret != 0) {
|
||||
errno = LittlefsErrno(ret);
|
||||
ret = VFS_ERROR;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int LfsOpen(const char *pathName, int openFlag, ...)
|
||||
{
|
||||
int fd = INVALID_FD;
|
||||
int err = INVALID_FD;
|
||||
|
||||
struct FileOpInfo *fileOpInfo = NULL;
|
||||
|
||||
if (pathName == NULL) {
|
||||
errno = EFAULT;
|
||||
goto errout;
|
||||
}
|
||||
|
||||
if (CheckPathIsMounted(pathName, &fileOpInfo) == FALSE || fileOpInfo == NULL) {
|
||||
errno = ENOENT;
|
||||
goto errout;
|
||||
}
|
||||
// if file is already open, return invalid fd
|
||||
if (CheckFileIsOpen(pathName)) {
|
||||
errno = EBUSY;
|
||||
goto errout;
|
||||
}
|
||||
|
||||
LittleFsHandleStruct *fsHandle = LfsAllocFd(pathName, &fd);
|
||||
if (fd == INVALID_FD) {
|
||||
errno = ENFILE;
|
||||
goto errout;
|
||||
}
|
||||
|
||||
int lfsOpenFlag = ConvertFlagToLfsOpenFlag(openFlag);
|
||||
err = lfs_file_open(&(fileOpInfo->lfsInfo), &(fsHandle->file), pathName, lfsOpenFlag);
|
||||
if (err != 0) {
|
||||
LfsFreeFd(fd);
|
||||
errno = LittlefsErrno(err);
|
||||
goto errout;
|
||||
}
|
||||
|
||||
g_handle[fd].lfsHandle = &(fileOpInfo->lfsInfo);
|
||||
return fd;
|
||||
|
||||
errout:
|
||||
return INVALID_FD;
|
||||
}
|
||||
|
||||
int LfsRead(int fd, void *buf, unsigned int len)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (buf == NULL) {
|
||||
errno = EFAULT;
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
if (LfsFdIsValid(fd) == FALSE) {
|
||||
errno = EBADF;
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
ret = lfs_file_read(g_handle[fd].lfsHandle, &(g_handle[fd].file), buf, len);
|
||||
if (ret < 0) {
|
||||
errno = LittlefsErrno(ret);
|
||||
ret = VFS_ERROR;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int LfsWrite(int fd, const void *buf, unsigned int len)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (buf == NULL) {
|
||||
errno = EFAULT;
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
if (LfsFdIsValid(fd) == FALSE) {
|
||||
errno = EBADF;
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
ret = lfs_file_write(g_handle[fd].lfsHandle, &(g_handle[fd].file), buf, len);
|
||||
if (ret < 0) {
|
||||
errno = LittlefsErrno(ret);
|
||||
ret = VFS_ERROR;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
off_t LfsSeek(int fd, off_t offset, int whence)
|
||||
{
|
||||
off_t ret;
|
||||
|
||||
if (LfsFdIsValid(fd) == FALSE) {
|
||||
errno = EBADF;
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
ret = (off_t)lfs_file_seek(g_handle[fd].lfsHandle, &(g_handle[fd].file), offset, whence);
|
||||
if (ret < 0) {
|
||||
errno = LittlefsErrno(ret);
|
||||
ret = VFS_ERROR;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int LfsClose(int fd)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (LfsFdIsValid(fd) == FALSE) {
|
||||
errno = EBADF;
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&g_FslocalMutex);
|
||||
ret = lfs_file_close(g_handle[fd].lfsHandle, &(g_handle[fd].file));
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
|
||||
LfsFreeFd(fd);
|
||||
|
||||
if (ret != 0) {
|
||||
errno = LittlefsErrno(ret);
|
||||
ret = VFS_ERROR;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int LfsRename(const char *oldName, const char *newName)
|
||||
{
|
||||
int ret;
|
||||
struct FileOpInfo *fileOpInfo = NULL;
|
||||
|
||||
if (oldName == NULL || newName == NULL) {
|
||||
errno = EFAULT;
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
if (CheckPathIsMounted(oldName, &fileOpInfo) == FALSE || fileOpInfo == NULL) {
|
||||
errno = ENOENT;
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
ret = lfs_rename(&(fileOpInfo->lfsInfo), oldName, newName);
|
||||
if (ret != 0) {
|
||||
errno = LittlefsErrno(ret);
|
||||
ret = VFS_ERROR;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int LfsStat(const char *path, struct stat *buf)
|
||||
{
|
||||
int ret;
|
||||
struct lfs_info info;
|
||||
struct FileOpInfo *fileOpInfo = NULL;
|
||||
|
||||
if (path == NULL || buf == NULL) {
|
||||
errno = EFAULT;
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
if (CheckPathIsMounted(path, &fileOpInfo) == FALSE || fileOpInfo == NULL) {
|
||||
errno = ENOENT;
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
ret = lfs_stat(&(fileOpInfo->lfsInfo), path, &info);
|
||||
if (ret == 0) {
|
||||
buf->st_size = info.size;
|
||||
if (info.type == LFS_TYPE_REG) {
|
||||
buf->st_mode = S_IFREG;
|
||||
} else {
|
||||
buf->st_mode = S_IFDIR;
|
||||
}
|
||||
} else {
|
||||
errno = LittlefsErrno(ret);
|
||||
ret = VFS_ERROR;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int LfsFsync(int fd)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (LfsFdIsValid(fd) == FALSE) {
|
||||
errno = EBADF;
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
ret = lfs_file_sync(g_handle[fd].lfsHandle, &(g_handle[fd].file));
|
||||
if (ret != 0) {
|
||||
errno = LittlefsErrno(ret);
|
||||
ret = VFS_ERROR;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int LfsFstat(int fd, struct stat *buf)
|
||||
{
|
||||
int ret;
|
||||
struct lfs_info info;
|
||||
|
||||
if (buf == NULL) {
|
||||
errno = EFAULT;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
|
||||
if (LfsFdIsValid(fd) == FALSE) {
|
||||
errno = EBADF;
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
ret = lfs_stat(g_handle[fd].lfsHandle, g_handle[fd].pathName, &info);
|
||||
if (ret == 0) {
|
||||
buf->st_size = info.size;
|
||||
if (info.type == LFS_TYPE_REG) {
|
||||
buf->st_mode = S_IFREG;
|
||||
} else {
|
||||
buf->st_mode = S_IFDIR;
|
||||
}
|
||||
} else {
|
||||
errno = LittlefsErrno(ret);
|
||||
ret = VFS_ERROR;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int LfsPread(int fd, void *buf, size_t nbyte, off_t offset)
|
||||
{
|
||||
int ret;
|
||||
off_t savepos, pos;
|
||||
|
||||
if (buf == NULL) {
|
||||
errno = EFAULT;
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
if (LfsFdIsValid(fd) == FALSE) {
|
||||
errno = EBADF;
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
savepos = (off_t)lfs_file_seek(g_handle[fd].lfsHandle, &(g_handle[fd].file), 0, SEEK_CUR);
|
||||
if (savepos == (off_t)-1) {
|
||||
errno = LittlefsErrno(savepos);
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
pos = (off_t)lfs_file_seek(g_handle[fd].lfsHandle, &(g_handle[fd].file), offset, SEEK_SET);
|
||||
if (pos == (off_t)-1) {
|
||||
errno = LittlefsErrno(pos);
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
ret = lfs_file_read(g_handle[fd].lfsHandle, &(g_handle[fd].file), buf, nbyte);
|
||||
if (ret < 0) {
|
||||
errno = LittlefsErrno(ret);
|
||||
ret = VFS_ERROR;
|
||||
}
|
||||
|
||||
pos = (off_t)lfs_file_seek(g_handle[fd].lfsHandle, &(g_handle[fd].file), savepos, SEEK_SET);
|
||||
if ((pos == (off_t)-1) && (ret >= 0)) {
|
||||
errno = LittlefsErrno(pos);
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int LfsPwrite(int fd, const void *buf, size_t nbyte, off_t offset)
|
||||
{
|
||||
int ret;
|
||||
off_t savepos, pos;
|
||||
|
||||
if (buf == NULL) {
|
||||
errno = EFAULT;
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
if (LfsFdIsValid(fd) == FALSE) {
|
||||
errno = EBADF;
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
savepos = (off_t)lfs_file_seek(g_handle[fd].lfsHandle, &(g_handle[fd].file), 0, SEEK_CUR);
|
||||
if (savepos == (off_t)-1) {
|
||||
errno = LittlefsErrno(savepos);
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
pos = (off_t)lfs_file_seek(g_handle[fd].lfsHandle, &(g_handle[fd].file), offset, SEEK_SET);
|
||||
if (pos == (off_t)-1) {
|
||||
errno = LittlefsErrno(pos);
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
ret = lfs_file_write(g_handle[fd].lfsHandle, &(g_handle[fd].file), buf, nbyte);
|
||||
if (ret < 0) {
|
||||
errno = LittlefsErrno(ret);
|
||||
ret = VFS_ERROR;
|
||||
}
|
||||
|
||||
pos = (off_t)lfs_file_seek(g_handle[fd].lfsHandle, &(g_handle[fd].file), savepos, SEEK_SET);
|
||||
if ((pos == (off_t)-1) && (ret >= 0)) {
|
||||
errno = LittlefsErrno(pos);
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2022-2022 Huawei Device Co., Ltd. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification,
|
||||
# are permitted provided that the following conditions are met:
|
||||
@@ -32,7 +31,26 @@ import("//kernel/liteos_m/liteos.gni")
|
||||
module_switch = defined(LOSCFG_FS_VFS)
|
||||
module_name = get_path_info(rebase_path("."), "name")
|
||||
kernel_module(module_name) {
|
||||
sources = [ "los_fs.c" ]
|
||||
sources = [
|
||||
"vfs_files.c",
|
||||
"vfs_fs.c",
|
||||
"vfs_init.c",
|
||||
"vfs_maps.c",
|
||||
"vfs_mount.c",
|
||||
"vfs_partition.c",
|
||||
]
|
||||
|
||||
include_dirs = [
|
||||
"//kernel/liteos_m/kernel/arch/include",
|
||||
"//kernel/liteos_m/kernel/include",
|
||||
"//kernel/liteos_m/utils",
|
||||
"../",
|
||||
".",
|
||||
]
|
||||
|
||||
deps = [ "//kernel/liteos_m/kal" ]
|
||||
configs += [ "$LITEOSTOPDIR:warn_config" ]
|
||||
cflags = [ "-Wno-parentheses" ]
|
||||
}
|
||||
|
||||
config("public") {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification,
|
||||
# are permitted provided that the following conditions are met:
|
||||
@@ -30,5 +30,6 @@
|
||||
config FS_VFS
|
||||
bool "Enable FS VFS"
|
||||
default y
|
||||
|
||||
help
|
||||
Answer Y to enable LiteOS support VFS.
|
||||
|
||||
@@ -1,82 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _FS_OPERATIONS_H_
|
||||
#define _FS_OPERATIONS_H_
|
||||
|
||||
#include "fcntl.h"
|
||||
#include "dirent.h"
|
||||
#include "unistd.h"
|
||||
#include "sys/mount.h"
|
||||
#include "sys/stat.h"
|
||||
#include "sys/statfs.h"
|
||||
|
||||
#define FS_SUCCESS 0
|
||||
#define FS_FAILURE (-1)
|
||||
#define MAX_FILESYSTEM_LEN 2
|
||||
|
||||
struct MountOps {
|
||||
int (*Mount)(const char *source, const char *target, const char *filesystemtype, unsigned long mountflags,
|
||||
const void *data);
|
||||
int (*Umount)(const char* target);
|
||||
int (*Umount2)(const char* target, int flag);
|
||||
int (*Statfs)(const char *path, struct statfs *buf);
|
||||
};
|
||||
|
||||
struct FsMap {
|
||||
const char *fileSystemtype;
|
||||
const struct MountOps *fsMops;
|
||||
const struct FileOps *fsFops;
|
||||
};
|
||||
|
||||
struct FileOps {
|
||||
int (*Open)(const char *path, int openFlag, ...);
|
||||
int (*Close)(int fd);
|
||||
int (*Unlink)(const char *fileName);
|
||||
int (*Rmdir)(const char *dirName);
|
||||
int (*Mkdir)(const char *dirName, mode_t mode);
|
||||
struct dirent *(*Readdir)(DIR *dir);
|
||||
DIR *(*Opendir)(const char *dirName);
|
||||
int (*Closedir)(DIR *dir);
|
||||
int (*Read)(int fd, void *buf, size_t len);
|
||||
int (*Write)(int fd, const void *buf, size_t len);
|
||||
off_t (*Seek)(int fd, off_t offset, int whence);
|
||||
int (*Getattr)(const char *path, struct stat *buf);
|
||||
int (*Rename)(const char *oldName, const char *newName);
|
||||
int (*Fsync)(int fd);
|
||||
int (*Fstat)(int fd, struct stat *buf);
|
||||
int (*Stat)(const char *path, struct stat *buf);
|
||||
int (*Ftruncate)(int fd, off_t length);
|
||||
int (*Pread)(int fd, void *buf, size_t nbyte, off_t offset);
|
||||
int (*Pwrite)(int fd, const void *buf, size_t nbyte, off_t offset);
|
||||
};
|
||||
|
||||
#endif /* _FS_OPERATIONS_H_ */
|
||||
@@ -1,649 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "los_fs.h"
|
||||
#include "los_config.h"
|
||||
#include "fs_operations.h"
|
||||
#if (LOSCFG_SUPPORT_FATFS == 1)
|
||||
#include "fatfs.h"
|
||||
#endif
|
||||
#include "dirent.h"
|
||||
#include "errno.h"
|
||||
#include "fcntl.h"
|
||||
#include "securec.h"
|
||||
#include "stdio.h"
|
||||
#include "stdlib.h"
|
||||
#include "string.h"
|
||||
#include "sys/mount.h"
|
||||
#include "sys/statfs.h"
|
||||
#include "sys/stat.h"
|
||||
#include "unistd.h"
|
||||
|
||||
#ifdef LOSCFG_NET_LWIP_SACK
|
||||
#define _BSD_SOURCE
|
||||
#include "lwip/sockets.h"
|
||||
#endif
|
||||
|
||||
#include "vfs_config.h"
|
||||
|
||||
#ifdef LOSCFG_RANDOM_DEV
|
||||
#include "hks_client.h"
|
||||
#define RANDOM_DEV_FD CONFIG_NFILE_DESCRIPTORS + CONFIG_NSOCKET_DESCRIPTORS
|
||||
#define RANDOM_DEV_PATH "/dev/random"
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_POSIX_PIPE_API == 1)
|
||||
#include "pipe_impl.h"
|
||||
#ifdef LOSCFG_RANDOM_DEV
|
||||
#define PIPE_DEV_FD (RANDOM_DEV_FD + 1)
|
||||
#else
|
||||
#define PIPE_DEV_FD (CONFIG_NFILE_DESCRIPTORS + CONFIG_NSOCKET_DESCRIPTORS)
|
||||
#endif
|
||||
|
||||
int PollQueryFd(int fd, struct PollTable *table)
|
||||
{
|
||||
if (fd >= PIPE_DEV_FD) {
|
||||
return PipePoll(fd, table);
|
||||
}
|
||||
|
||||
return -ENODEV;
|
||||
}
|
||||
#endif
|
||||
|
||||
#define FREE_AND_SET_NULL(ptr) do { \
|
||||
free(ptr); \
|
||||
ptr = NULL; \
|
||||
} while (0)
|
||||
|
||||
#ifdef LOSCFG_RANDOM_DEV
|
||||
/**
|
||||
* @brief Get canonical form of a given path based on cwd(Current working directory).
|
||||
*
|
||||
* @param cwd Indicates the current working directory.
|
||||
* @param path Indicates the path to be canonicalization.
|
||||
* @param buf Indicates the pointer to the buffer where the result will be return.
|
||||
* @param bufSize Indicates the size of the buffer.
|
||||
* @return Returns the length of the canonical path.
|
||||
*
|
||||
* @attention if path is an absolute path, cwd is ignored. if cwd if not specified, it is assumed to be root('/').
|
||||
* if the buffer is not big enough the result will be truncated, but the return value will always be the
|
||||
* length of the canonical path.
|
||||
*/
|
||||
static size_t GetCanonicalPath(const char *cwd, const char *path, char *buf, size_t bufSize)
|
||||
{
|
||||
size_t offset;
|
||||
if (!path) {
|
||||
path = "";
|
||||
}
|
||||
|
||||
if (!cwd || path[0] == '/') {
|
||||
cwd = "";
|
||||
}
|
||||
|
||||
offset = strlen("///") + 1; // three '/' and one '\0'
|
||||
size_t tmpLen = strlen(cwd) + strlen(path) + offset;
|
||||
char *tmpBuf = (char *)malloc(tmpLen);
|
||||
if (tmpBuf == NULL) {
|
||||
return FS_SUCCESS;
|
||||
}
|
||||
|
||||
if (-1 == sprintf_s(tmpBuf, tmpLen, "/%s/%s/", cwd, path)) {
|
||||
free(tmpBuf);
|
||||
return FS_SUCCESS;
|
||||
}
|
||||
|
||||
char *p;
|
||||
/* replace /./ to / */
|
||||
offset = strlen("/./") - 1;
|
||||
while ((p = strstr(tmpBuf, "/./")) != NULL) {
|
||||
if (EOK != memmove_s(p, tmpLen - (p - tmpBuf), p + offset, tmpLen - (p - tmpBuf) - offset)) {
|
||||
free(tmpBuf);
|
||||
return FS_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
/* replace // to / */
|
||||
while ((p = strstr(tmpBuf, "//")) != NULL) {
|
||||
if (EOK != memmove_s(p, tmpLen - (p - tmpBuf), p + 1, tmpLen - (p - tmpBuf) - 1)) {
|
||||
free(tmpBuf);
|
||||
return FS_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
/* handle /../ (e.g., replace /aa/bb/../ to /aa/) */
|
||||
offset = strlen("/../") - 1;
|
||||
while ((p = strstr(tmpBuf, "/../")) != NULL) {
|
||||
char *start = p;
|
||||
while (start > tmpBuf && *(start - 1) != '/') {
|
||||
--start;
|
||||
}
|
||||
if (EOK != memmove_s(start, tmpLen - (start - tmpBuf), p + offset, tmpLen - (p - tmpBuf) - offset)) {
|
||||
free(tmpBuf);
|
||||
return FS_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
size_t totalLen = strlen(tmpBuf);
|
||||
/* strip the last / */
|
||||
if (totalLen > 1 && tmpBuf[totalLen - 1] == '/') {
|
||||
tmpBuf[--totalLen] = 0;
|
||||
}
|
||||
|
||||
if (!buf || bufSize == 0) {
|
||||
free(tmpBuf);
|
||||
return totalLen;
|
||||
}
|
||||
|
||||
if (EOK != memcpy_s(buf, bufSize, tmpBuf, (((totalLen + 1) > bufSize) ? bufSize : (totalLen + 1)))) {
|
||||
free(tmpBuf);
|
||||
return FS_SUCCESS;
|
||||
}
|
||||
|
||||
buf[bufSize - 1] = 0;
|
||||
free(tmpBuf);
|
||||
return totalLen;
|
||||
}
|
||||
#endif
|
||||
|
||||
static struct FsMap g_fsmap[MAX_FILESYSTEM_LEN] = {0};
|
||||
static struct FsMap *g_fs = NULL;
|
||||
|
||||
static void InitMountInfo(void)
|
||||
{
|
||||
#if (LOSCFG_SUPPORT_FATFS == 1)
|
||||
extern struct MountOps g_fatfsMnt;
|
||||
extern struct FileOps g_fatfsFops;
|
||||
g_fsmap[0].fileSystemtype = strdup("fat");
|
||||
g_fsmap[0].fsMops = &g_fatfsMnt;
|
||||
g_fsmap[0].fsFops = &g_fatfsFops;
|
||||
#endif
|
||||
#if (LOSCFG_SUPPORT_LITTLEFS == 1)
|
||||
extern struct MountOps g_lfsMnt;
|
||||
extern struct FileOps g_lfsFops;
|
||||
g_fsmap[1].fileSystemtype = strdup("littlefs");
|
||||
g_fsmap[1].fsMops = &g_lfsMnt;
|
||||
g_fsmap[1].fsFops = &g_lfsFops;
|
||||
#endif
|
||||
}
|
||||
|
||||
static struct FsMap *MountFindfs(const char *fileSystemtype)
|
||||
{
|
||||
struct FsMap *m = NULL;
|
||||
|
||||
for (int i = 0; i < MAX_FILESYSTEM_LEN; i++) {
|
||||
m = &(g_fsmap[i]);
|
||||
if (m->fileSystemtype && strcmp(fileSystemtype, m->fileSystemtype) == 0) {
|
||||
return m;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int LOS_FsMount(const char *source, const char *target,
|
||||
const char *filesystemtype, unsigned long mountflags,
|
||||
const void *data)
|
||||
{
|
||||
static int initFlag = 0;
|
||||
|
||||
if (initFlag == 0) {
|
||||
InitMountInfo();
|
||||
initFlag = 1;
|
||||
}
|
||||
|
||||
g_fs = MountFindfs(filesystemtype);
|
||||
if (g_fs == NULL) {
|
||||
errno = ENODEV;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
|
||||
if (g_fs->fsMops == NULL || g_fs->fsMops->Mount == NULL) {
|
||||
errno = ENOSYS;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
|
||||
return g_fs->fsMops->Mount(source, target, filesystemtype, mountflags, data);
|
||||
}
|
||||
|
||||
int LOS_FsUmount(const char *target)
|
||||
{
|
||||
if (g_fs == NULL) {
|
||||
errno = ENODEV;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
if (g_fs->fsMops == NULL || g_fs->fsMops->Umount == NULL) {
|
||||
errno = ENOSYS;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
return g_fs->fsMops->Umount(target);
|
||||
}
|
||||
|
||||
int LOS_FsUmount2(const char *target, int flag)
|
||||
{
|
||||
if (g_fs == NULL) {
|
||||
errno = ENODEV;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
if (g_fs->fsMops == NULL || g_fs->fsMops->Umount2 == NULL) {
|
||||
errno = ENOSYS;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
return g_fs->fsMops->Umount2(target, flag);
|
||||
}
|
||||
|
||||
int LOS_Open(const char *path, int oflag, ...)
|
||||
{
|
||||
#ifdef LOSCFG_RANDOM_DEV
|
||||
unsigned flags = O_RDONLY | O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_LARGEFILE | O_TRUNC | O_EXCL | O_DIRECTORY;
|
||||
if ((unsigned)oflag & ~flags) {
|
||||
errno = EINVAL;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
|
||||
size_t pathLen = strlen(path) + 1;
|
||||
char *canonicalPath = (char *)malloc(pathLen);
|
||||
if (!canonicalPath) {
|
||||
errno = ENOMEM;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
if (GetCanonicalPath(NULL, path, canonicalPath, pathLen) == 0) {
|
||||
FREE_AND_SET_NULL(canonicalPath);
|
||||
errno = ENOMEM;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(canonicalPath, RANDOM_DEV_PATH) == 0) {
|
||||
FREE_AND_SET_NULL(canonicalPath);
|
||||
if ((O_ACCMODE & (unsigned)oflag) != O_RDONLY) {
|
||||
errno = EPERM;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
if ((unsigned)oflag & O_DIRECTORY) {
|
||||
errno = ENOTDIR;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
return RANDOM_DEV_FD;
|
||||
}
|
||||
if (strcmp(canonicalPath, "/") == 0 || strcmp(canonicalPath, "/dev") == 0) {
|
||||
FREE_AND_SET_NULL(canonicalPath);
|
||||
if ((unsigned)oflag & O_DIRECTORY) {
|
||||
errno = EPERM;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
errno = EISDIR;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
FREE_AND_SET_NULL(canonicalPath);
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_POSIX_PIPE_API == 1)
|
||||
if ((path != NULL) && !strncmp(path, PIPE_DEV_PATH, strlen(PIPE_DEV_PATH))) {
|
||||
return PipeOpen(path, oflag, PIPE_DEV_FD);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (g_fs == NULL) {
|
||||
errno = ENODEV;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
if (g_fs->fsFops == NULL || g_fs->fsFops->Open == NULL) {
|
||||
errno = ENOSYS;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
return g_fs->fsFops->Open(path, oflag);
|
||||
}
|
||||
|
||||
int LOS_Close(int fd)
|
||||
{
|
||||
#ifdef LOSCFG_RANDOM_DEV
|
||||
if (fd == RANDOM_DEV_FD) {
|
||||
return FS_SUCCESS;
|
||||
}
|
||||
#endif
|
||||
#ifdef LOSCFG_NET_LWIP_SACK
|
||||
if (fd >= CONFIG_NFILE_DESCRIPTORS && fd < (CONFIG_NFILE_DESCRIPTORS + CONFIG_NSOCKET_DESCRIPTORS)) {
|
||||
return closesocket(fd);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_POSIX_PIPE_API == 1)
|
||||
if (fd >= PIPE_DEV_FD) {
|
||||
return PipeClose(fd);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (g_fs == NULL) {
|
||||
errno = ENODEV;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
if (g_fs->fsFops == NULL || g_fs->fsFops->Close == NULL) {
|
||||
errno = ENOSYS;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
return g_fs->fsFops->Close(fd);
|
||||
}
|
||||
|
||||
ssize_t LOS_Read(int fd, void *buf, size_t nbyte)
|
||||
{
|
||||
#ifdef LOSCFG_RANDOM_DEV
|
||||
if (fd == RANDOM_DEV_FD) {
|
||||
if (nbyte == 0) {
|
||||
return FS_SUCCESS;
|
||||
}
|
||||
if (buf == NULL) {
|
||||
errno = EINVAL;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
if (nbyte > 1024) { /* 1024, max random_size */
|
||||
nbyte = 1024; /* hks_generate_random: random_size must <= 1024 */
|
||||
}
|
||||
struct hks_blob key = {HKS_BLOB_TYPE_RAW, (uint8_t *)buf, nbyte};
|
||||
if (hks_generate_random(&key) != 0) {
|
||||
errno = EIO;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
return (ssize_t)nbyte;
|
||||
}
|
||||
#endif
|
||||
#ifdef LOSCFG_NET_LWIP_SACK
|
||||
if (fd >= CONFIG_NFILE_DESCRIPTORS && fd < (CONFIG_NFILE_DESCRIPTORS + CONFIG_NSOCKET_DESCRIPTORS)) {
|
||||
return recv(fd, buf, nbyte, 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_POSIX_PIPE_API == 1)
|
||||
if (fd >= PIPE_DEV_FD) {
|
||||
return PipeRead(fd, buf, nbyte);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (g_fs == NULL) {
|
||||
errno = ENODEV;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
if (g_fs->fsFops == NULL || g_fs->fsFops->Read == NULL) {
|
||||
errno = ENOSYS;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
return g_fs->fsFops->Read(fd, buf, nbyte);
|
||||
}
|
||||
|
||||
ssize_t LOS_Write(int fd, const void *buf, size_t nbyte)
|
||||
{
|
||||
#ifdef LOSCFG_RANDOM_DEV
|
||||
if (fd == RANDOM_DEV_FD) {
|
||||
errno = EBADF; /* "/dev/random" is readonly */
|
||||
return FS_FAILURE;
|
||||
}
|
||||
#endif
|
||||
#ifdef LOSCFG_NET_LWIP_SACK
|
||||
if (fd >= CONFIG_NFILE_DESCRIPTORS && fd < (CONFIG_NFILE_DESCRIPTORS + CONFIG_NSOCKET_DESCRIPTORS)) {
|
||||
return send(fd, buf, nbyte, 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_POSIX_PIPE_API == 1)
|
||||
if (fd >= PIPE_DEV_FD) {
|
||||
return PipeWrite(fd, buf, nbyte);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (g_fs == NULL) {
|
||||
errno = ENODEV;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
if (g_fs->fsFops == NULL || g_fs->fsFops->Write == NULL) {
|
||||
errno = ENOSYS;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
return g_fs->fsFops->Write(fd, buf, nbyte);
|
||||
}
|
||||
|
||||
off_t LOS_Lseek(int fd, off_t offset, int whence)
|
||||
{
|
||||
if (g_fs == NULL) {
|
||||
errno = ENODEV;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
if (g_fs->fsFops == NULL || g_fs->fsFops->Seek == NULL) {
|
||||
errno = ENOSYS;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
return g_fs->fsFops->Seek(fd, offset, whence);
|
||||
}
|
||||
|
||||
int LOS_Unlink(const char *path)
|
||||
{
|
||||
if (g_fs == NULL) {
|
||||
errno = ENODEV;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
if (g_fs->fsFops == NULL || g_fs->fsFops->Unlink == NULL) {
|
||||
errno = ENOSYS;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
return g_fs->fsFops->Unlink(path);
|
||||
}
|
||||
|
||||
int LOS_Fstat(int fd, struct stat *buf)
|
||||
{
|
||||
if (g_fs == NULL) {
|
||||
errno = ENODEV;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
if (g_fs->fsFops == NULL || g_fs->fsFops->Fstat == NULL) {
|
||||
errno = ENOSYS;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
return g_fs->fsFops->Fstat(fd, buf);
|
||||
}
|
||||
|
||||
int LOS_Stat(const char *path, struct stat *buf)
|
||||
{
|
||||
if (g_fs == NULL) {
|
||||
errno = ENODEV;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
if (g_fs->fsFops == NULL || g_fs->fsFops->Getattr == NULL) {
|
||||
errno = ENOSYS;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
return g_fs->fsFops->Getattr(path, buf);
|
||||
}
|
||||
|
||||
int LOS_Fsync(int fd)
|
||||
{
|
||||
if (g_fs == NULL) {
|
||||
errno = ENODEV;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
if (g_fs->fsFops == NULL || g_fs->fsFops->Fsync == NULL) {
|
||||
errno = ENOSYS;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
return g_fs->fsFops->Fsync(fd);
|
||||
}
|
||||
|
||||
int LOS_Mkdir(const char *path, mode_t mode)
|
||||
{
|
||||
if (g_fs == NULL) {
|
||||
errno = ENODEV;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
if (g_fs->fsFops == NULL || g_fs->fsFops->Mkdir == NULL) {
|
||||
errno = ENOSYS;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
return g_fs->fsFops->Mkdir(path, mode);
|
||||
}
|
||||
|
||||
DIR *LOS_Opendir(const char *dirName)
|
||||
{
|
||||
if (g_fs == NULL) {
|
||||
errno = ENODEV;
|
||||
return NULL;
|
||||
}
|
||||
if (g_fs->fsFops == NULL || g_fs->fsFops->Opendir == NULL) {
|
||||
errno = ENOSYS;
|
||||
return NULL;
|
||||
}
|
||||
return g_fs->fsFops->Opendir(dirName);
|
||||
}
|
||||
|
||||
struct dirent *LOS_Readdir(DIR *dir)
|
||||
{
|
||||
if (g_fs == NULL) {
|
||||
errno = ENODEV;
|
||||
return NULL;
|
||||
}
|
||||
if (g_fs->fsFops == NULL || g_fs->fsFops->Readdir == NULL) {
|
||||
errno = ENOSYS;
|
||||
return NULL;
|
||||
}
|
||||
return g_fs->fsFops->Readdir(dir);
|
||||
}
|
||||
|
||||
int LOS_Closedir(DIR *dir)
|
||||
{
|
||||
if (g_fs == NULL) {
|
||||
errno = ENODEV;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
if (g_fs->fsFops == NULL || g_fs->fsFops->Closedir == NULL) {
|
||||
errno = ENOSYS;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
return g_fs->fsFops->Closedir(dir);
|
||||
}
|
||||
|
||||
int LOS_Rmdir(const char *path)
|
||||
{
|
||||
if (g_fs == NULL) {
|
||||
errno = ENODEV;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
if (g_fs->fsFops == NULL || g_fs->fsFops->Rmdir == NULL) {
|
||||
errno = ENOSYS;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
return g_fs->fsFops->Rmdir(path);
|
||||
}
|
||||
|
||||
int LOS_Rename(const char *oldName, const char *newName)
|
||||
{
|
||||
if (g_fs == NULL) {
|
||||
errno = ENODEV;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
if (g_fs->fsFops == NULL || g_fs->fsFops->Rename == NULL) {
|
||||
errno = ENOSYS;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
return g_fs->fsFops->Rename(oldName, newName);
|
||||
}
|
||||
|
||||
int LOS_Statfs(const char *path, struct statfs *buf)
|
||||
{
|
||||
if (g_fs == NULL) {
|
||||
errno = ENODEV;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
if (g_fs->fsMops == NULL || g_fs->fsMops->Statfs == NULL) {
|
||||
errno = ENOSYS;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
return g_fs->fsMops->Statfs(path, buf);
|
||||
}
|
||||
|
||||
int LOS_Ftruncate(int fd, off_t length)
|
||||
{
|
||||
if (g_fs == NULL) {
|
||||
errno = ENODEV;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
if (g_fs->fsFops == NULL || g_fs->fsFops->Ftruncate == NULL) {
|
||||
errno = ENOSYS;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
return g_fs->fsFops->Ftruncate(fd, length);
|
||||
}
|
||||
|
||||
ssize_t LOS_Pread(int fd, void *buf, size_t nbyte, off_t offset)
|
||||
{
|
||||
#ifdef LOSCFG_RANDOM_DEV
|
||||
if (fd == RANDOM_DEV_FD) {
|
||||
if (nbyte == 0) {
|
||||
return FS_SUCCESS;
|
||||
}
|
||||
if (buf == NULL) {
|
||||
errno = EINVAL;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
if (nbyte > 1024) { /* 1024, max random_size */
|
||||
nbyte = 1024; /* hks_generate_random: random_size must <= 1024 */
|
||||
}
|
||||
struct hks_blob key = {HKS_BLOB_TYPE_RAW, (uint8_t *)buf, nbyte};
|
||||
if (hks_generate_random(&key) != 0) {
|
||||
errno = EIO;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
return (ssize_t)nbyte;
|
||||
}
|
||||
#endif
|
||||
if (g_fs == NULL) {
|
||||
errno = ENODEV;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
if (g_fs->fsFops == NULL || g_fs->fsFops->Pread == NULL) {
|
||||
errno = ENOSYS;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
return g_fs->fsFops->Pread(fd, buf, nbyte, offset);
|
||||
}
|
||||
|
||||
ssize_t LOS_Pwrite(int fd, const void *buf, size_t nbyte, off_t offset)
|
||||
{
|
||||
#ifdef LOSCFG_RANDOM_DEV
|
||||
if (fd == RANDOM_DEV_FD) {
|
||||
errno = EBADF; /* "/dev/random" is readonly */
|
||||
return FS_FAILURE;
|
||||
}
|
||||
#endif
|
||||
if (g_fs == NULL) {
|
||||
errno = ENODEV;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
if (g_fs->fsFops == NULL || g_fs->fsFops->Pwrite == NULL) {
|
||||
errno = ENOSYS;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
return g_fs->fsFops->Pwrite(fd, buf, nbyte, offset);
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
@@ -30,18 +30,19 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup los_vfs fs
|
||||
* @defgroup los_fs fs
|
||||
* @ingroup kernel
|
||||
*/
|
||||
|
||||
#ifndef _LOS_VFS_H_
|
||||
#define _LOS_VFS_H_
|
||||
#ifndef _LOS_FS_H_
|
||||
#define _LOS_FS_H_
|
||||
|
||||
#include "los_config.h"
|
||||
#include "dirent.h"
|
||||
#include "sys/mount.h"
|
||||
#include "sys/statfs.h"
|
||||
#include "sys/stat.h"
|
||||
#include "sys/uio.h"
|
||||
#include "unistd.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
@@ -50,51 +51,72 @@ extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
int LOS_Open(const char *path, int oflag, ...);
|
||||
|
||||
int LOS_Open(const char *path, int flags, ...);
|
||||
int LOS_Close(int fd);
|
||||
|
||||
ssize_t LOS_Read(int fd, void *buf, size_t nbyte);
|
||||
|
||||
ssize_t LOS_Write(int fd, const void *buf, size_t nbyte);
|
||||
|
||||
off_t LOS_Lseek(int fd, off_t offset, int whence);
|
||||
|
||||
int LOS_Unlink(const char *path);
|
||||
|
||||
int LOS_Fstat(int fd, struct stat *buf);
|
||||
|
||||
int LOS_Stat(const char *path, struct stat *buf);
|
||||
|
||||
int LOS_Fsync(int fd);
|
||||
|
||||
int LOS_Mkdir(const char *path, mode_t mode);
|
||||
|
||||
DIR *LOS_Opendir(const char *dirName);
|
||||
|
||||
struct dirent *LOS_Readdir(DIR *dir);
|
||||
|
||||
int LOS_Closedir(DIR *dir);
|
||||
|
||||
int LOS_Rmdir(const char *path);
|
||||
|
||||
int LOS_Rename(const char *oldName, const char *newName);
|
||||
|
||||
ssize_t LOS_Read(int fd, void *buff, size_t bytes);
|
||||
ssize_t LOS_Write(int fd, const void *buff, size_t bytes);
|
||||
off_t LOS_Lseek(int fd, off_t off, int whence);
|
||||
int LOS_Stat(const char *path, struct stat *stat);
|
||||
int LOS_Statfs(const char *path, struct statfs *buf);
|
||||
|
||||
int LOS_Unlink(const char *path);
|
||||
int LOS_Rename(const char *oldpath, const char *newpath);
|
||||
int LOS_Fsync(int fd);
|
||||
DIR *LOS_Opendir(const char *path);
|
||||
struct dirent *LOS_Readdir(DIR *dir);
|
||||
int LOS_Closedir(DIR *dir);
|
||||
int LOS_Mkdir(const char *path, mode_t mode);
|
||||
int LOS_Rmdir(const char *path);
|
||||
int LOS_Lstat(const char *path, struct stat *buffer);
|
||||
int LOS_Fstat(int fd, struct stat *buf);
|
||||
int LOS_Fcntl(int fd, int cmd, ...);
|
||||
int LOS_Ioctl(int fd, int req, ...);
|
||||
ssize_t LOS_Readv(int fd, const struct iovec *iovBuf, int iovcnt);
|
||||
ssize_t LOS_Writev(int fd, const struct iovec *iovBuf, int iovcnt);
|
||||
ssize_t LOS_Pread(int fd, void *buff, size_t bytes, off_t off);
|
||||
ssize_t LOS_Pwrite(int fd, const void *buff, size_t bytes, off_t off);
|
||||
int LOS_Isatty(int fd);
|
||||
int LOS_Access(const char *path, int amode);
|
||||
int LOS_Ftruncate(int fd, off_t length);
|
||||
|
||||
int LOS_FsUmount2(const char *target, int flag);
|
||||
|
||||
int LOS_FsUmount(const char *target);
|
||||
|
||||
int LOS_FsUmount2(const char *target, int flag);
|
||||
int LOS_FsMount(const char *source, const char *target,
|
||||
const char *filesystemtype, unsigned long mountflags,
|
||||
const char *fsType, unsigned long mountflags,
|
||||
const void *data);
|
||||
/*
|
||||
* @brief Divide the device into partitions.
|
||||
*
|
||||
* @param dev Device name, which customized by caller, it is recommended to
|
||||
* name it as: "emmc0", "emmc1", "flash0", etc. The name is combined with
|
||||
* "device_type" + "device_id", and the last character is device_id.
|
||||
* device_id >= 0 && device_id <= 9.
|
||||
* @param fsType Filesystem type.
|
||||
* @param lengthArray List of partition size. For example:
|
||||
* [0x10000000, 0x2000000], 256M and 512M partitions will be created and
|
||||
* left all will not allocated.
|
||||
* @param partNum Length of 'lengthArray'.
|
||||
*
|
||||
* @return Return LOS_NOK if error. Return LOS_OK if success.
|
||||
* Partition naming rules:
|
||||
* In the current vfs, after successfully calling the 'fdisk' hook,
|
||||
* "partNum" partitions will be created.
|
||||
* The partition naming rules is:
|
||||
* The name is a combination of: 'deviceName'+'p'+'partitionId',
|
||||
* such as "emmc0p0", "emmc0p1", "emmc0p2"...
|
||||
*/
|
||||
int LOS_DiskPartition(const char *dev, const char *fsType, int *lengthArray,
|
||||
int partnum);
|
||||
|
||||
ssize_t LOS_Pread(int fd, void *buf, size_t nbyte, off_t offset);
|
||||
|
||||
ssize_t LOS_Pwrite(int fd, const void *buf, size_t nbyte, off_t offset);
|
||||
/*
|
||||
* @brief Format a partition.
|
||||
*
|
||||
* @param partName PartitionName, following the rule of fdisk hook.
|
||||
* @param data For FatFs, the data indicates a pointer to a byte which
|
||||
* specifies combination of FAT type flags, FM_FAT, FM_FAT32, FM_EXFAT and
|
||||
* bitwise-or of these three, FM_ANY.
|
||||
*
|
||||
* @return Return LOS_NOK if error. Return LOS_OK if success.
|
||||
*/
|
||||
int LOS_PartitionFormat(const char *partName, char *fsType, void *data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
@@ -102,4 +124,4 @@ extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_FS_H_ */
|
||||
#endif /* _LOS_FS_H_ */
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
@@ -32,54 +32,8 @@
|
||||
#ifndef _VFS_CONFIG_H_
|
||||
#define _VFS_CONFIG_H_
|
||||
|
||||
#define PATH_MAX 256
|
||||
#define CONFIG_DISABLE_MQUEUE // disable posix mqueue inode configure
|
||||
|
||||
/* file system configur */
|
||||
|
||||
#define CONFIG_FS_WRITABLE // enable file system can be written
|
||||
#define CONFIG_FS_READABLE // enable file system can be read
|
||||
#define CONFIG_DEBUG_FS // enable vfs debug function
|
||||
|
||||
|
||||
/* fatfs cache configur */
|
||||
/* config block size for fat file system, only can be 0,32,64,128,256,512,1024 */
|
||||
#define CONFIG_FS_FAT_SECTOR_PER_BLOCK 64
|
||||
|
||||
/* config block num for fat file system */
|
||||
#define CONFIG_FS_FAT_READ_NUMS 7
|
||||
#define CONFIG_FS_FAT_BLOCK_NUMS 28
|
||||
|
||||
#ifdef LOSCFG_FS_FAT_CACHE_SYNC_THREAD
|
||||
|
||||
/* config the priority of sync task */
|
||||
|
||||
#define CONFIG_FS_FAT_SYNC_THREAD_PRIO 10
|
||||
|
||||
/* config dirty ratio of bcache for fat file system */
|
||||
|
||||
#define CONFIG_FS_FAT_DIRTY_RATIO 60
|
||||
|
||||
/* config time interval of sync thread for fat file system, in milliseconds */
|
||||
|
||||
#define CONFIG_FS_FAT_SYNC_INTERVAL 5000
|
||||
#endif
|
||||
|
||||
#define CONFIG_FS_FLASH_BLOCK_NUM 1
|
||||
|
||||
#define CONFIG_FS_MAX_LNK_CNT 40
|
||||
|
||||
/* nfs configure */
|
||||
|
||||
#define CONFIG_NFS_MACHINE_NAME "IPC" // nfs device name is IPC
|
||||
#define CONFIG_NFS_MACHINE_NAME_SIZE 3 // size of nfs machine name
|
||||
|
||||
|
||||
/* file descriptors configure */
|
||||
|
||||
#define CONFIG_NFILE_STREAMS 1 // enable file stream
|
||||
#define CONFIG_STDIO_BUFFER_SIZE 0
|
||||
#define CONFIG_NUNGET_CHARS 0
|
||||
#define MIN_START_FD 3 // 0,1,2 are used for stdin,stdout,stderr respectively
|
||||
|
||||
/* net configure */
|
||||
@@ -87,12 +41,8 @@
|
||||
#ifdef LOSCFG_NET_LWIP_SACK // enable socket and net function
|
||||
#include "lwip/lwipopts.h"
|
||||
#define CONFIG_NSOCKET_DESCRIPTORS LWIP_CONFIG_NUM_SOCKETS // max numbers of socket descriptor
|
||||
#define CONFIG_NET_SENDFILE 1 // enable sendfile function
|
||||
#define CONFIG_NET_TCP 1 // enable sendfile and send function
|
||||
#else
|
||||
#define CONFIG_NSOCKET_DESCRIPTORS 0
|
||||
#define CONFIG_NET_SENDFILE 0 // disable sendfile function
|
||||
#define CONFIG_NET_TCP 0 // disable sendfile and send function
|
||||
#endif
|
||||
|
||||
/* max numbers of other descriptors except socket descriptors */
|
||||
|
||||
98
components/fs/vfs/vfs_files.c
Normal file
98
components/fs/vfs/vfs_files.c
Normal file
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* Copyright (c) 2022-2022 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include "vfs_files.h"
|
||||
#include "errno.h"
|
||||
#include "stdio.h"
|
||||
#include "stdlib.h"
|
||||
#include "string.h"
|
||||
#include "los_config.h"
|
||||
#include "vfs_config.h"
|
||||
#include "vfs_mount.h"
|
||||
#include "vfs_operations.h"
|
||||
|
||||
static struct File g_files[NR_OPEN_DEFAULT];
|
||||
|
||||
int FileToFd(struct File *file)
|
||||
{
|
||||
if (file == NULL) {
|
||||
return LOS_NOK;
|
||||
}
|
||||
return file - g_files + MIN_START_FD;
|
||||
}
|
||||
|
||||
struct File *FdToFile(int fd)
|
||||
{
|
||||
if ((fd < MIN_START_FD) || (fd >= CONFIG_NFILE_DESCRIPTORS)) {
|
||||
return NULL;
|
||||
}
|
||||
return &g_files[fd - MIN_START_FD];
|
||||
}
|
||||
|
||||
struct File *VfsFileGet(void)
|
||||
{
|
||||
int i;
|
||||
/* protected by g_fsMutex */
|
||||
for (i = 0; i < NR_OPEN_DEFAULT; i++) {
|
||||
if (g_files[i].fStatus == FILE_STATUS_NOT_USED) {
|
||||
g_files[i].fStatus = FILE_STATUS_INITING;
|
||||
return &g_files[i];
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct File *VfsFileGetSpec(int fd)
|
||||
{
|
||||
if ((fd < MIN_START_FD) || (fd >= CONFIG_NFILE_DESCRIPTORS)) {
|
||||
return NULL;
|
||||
}
|
||||
if (g_files[fd - MIN_START_FD].fStatus == FILE_STATUS_NOT_USED) {
|
||||
g_files[fd - MIN_START_FD].fStatus = FILE_STATUS_INITING;
|
||||
return &g_files[fd - MIN_START_FD];
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void VfsFilePut(struct File *file)
|
||||
{
|
||||
if (file == NULL) {
|
||||
return;
|
||||
}
|
||||
file->fFlags = 0;
|
||||
file->fFops = NULL;
|
||||
file->fData = NULL;
|
||||
file->fMp = NULL;
|
||||
file->fOffset = 0;
|
||||
file->fOwner = -1;
|
||||
file->fullPath = NULL;
|
||||
file->fStatus = FILE_STATUS_NOT_USED;
|
||||
}
|
||||
104
components/fs/vfs/vfs_files.h
Normal file
104
components/fs/vfs/vfs_files.h
Normal file
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* Copyright (c) 2022-2022 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _VFS_FILES_H_
|
||||
#define _VFS_FILES_H_
|
||||
|
||||
#include "dirent.h"
|
||||
#include "sys/stat.h"
|
||||
#include "unistd.h"
|
||||
#include "los_compiler.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#define FILE_STATUS_NOT_USED 0
|
||||
#define FILE_STATUS_INITING 1
|
||||
#define FILE_STATUS_READY 2
|
||||
#define FILE_STATUS_CLOSING 3
|
||||
|
||||
struct FileOps;
|
||||
struct File;
|
||||
struct Dir;
|
||||
struct MountPoint;
|
||||
|
||||
struct FileOps {
|
||||
int (*open)(struct File *, const char *, int);
|
||||
int (*close)(struct File *);
|
||||
ssize_t (*read)(struct File *, char *, size_t);
|
||||
ssize_t (*write)(struct File *, const char *, size_t);
|
||||
off_t (*lseek)(struct File *, off_t, int);
|
||||
int (*stat)(struct MountPoint *, const char *, struct stat *);
|
||||
int (*truncate)(struct File *, off_t);
|
||||
int (*unlink)(struct MountPoint *, const char *);
|
||||
int (*rename)(struct MountPoint *, const char *, const char *);
|
||||
int (*ioctl)(struct File *, int, unsigned long);
|
||||
int (*sync)(struct File *);
|
||||
int (*opendir)(struct Dir *, const char *);
|
||||
int (*readdir)(struct Dir *, struct dirent *);
|
||||
int (*closedir)(struct Dir *);
|
||||
int (*mkdir)(struct MountPoint *, const char *);
|
||||
int (*rmdir)(struct MountPoint *, const char *);
|
||||
};
|
||||
|
||||
struct File {
|
||||
const struct FileOps *fFops;
|
||||
UINT32 fFlags;
|
||||
UINT32 fStatus;
|
||||
off_t fOffset;
|
||||
INT32 fOwner;
|
||||
struct MountPoint *fMp;
|
||||
void *fData; /* file system opreations handle, fatfs FIL, etc. */
|
||||
const char *fullPath;
|
||||
};
|
||||
|
||||
struct Dir {
|
||||
struct MountPoint *dMp;
|
||||
struct dirent dDent;
|
||||
off_t dOffset;
|
||||
void *dData;
|
||||
};
|
||||
|
||||
int FileToFd(struct File *file);
|
||||
struct File *FdToFile(int fd);
|
||||
struct File *VfsFileGet(void);
|
||||
struct File *VfsFileGetSpec(int fd);
|
||||
void VfsFilePut(struct File *file);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _VFS_FILES_H_ */
|
||||
1398
components/fs/vfs/vfs_fs.c
Normal file
1398
components/fs/vfs/vfs_fs.c
Normal file
File diff suppressed because it is too large
Load Diff
54
components/fs/vfs/vfs_init.c
Normal file
54
components/fs/vfs/vfs_init.c
Normal file
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (c) 2022-2022 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include "stdlib.h"
|
||||
#include "vfs_operations.h"
|
||||
#if (LOSCFG_SUPPORT_LITTLEFS == 1)
|
||||
#include "lfs_adapter.h"
|
||||
#endif
|
||||
#if (LOSCFG_SUPPORT_FATFS == 1)
|
||||
#include "fatfs.h"
|
||||
#endif
|
||||
#include "los_compiler.h"
|
||||
#include "los_mux.h"
|
||||
|
||||
int OsVfsInit(void)
|
||||
{
|
||||
if (LOS_MuxCreate(&g_fsMutex) != LOS_OK) {
|
||||
return LOS_NOK;
|
||||
}
|
||||
#if (LOSCFG_SUPPORT_FATFS == 1)
|
||||
FatFsInit();
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_SUPPORT_LITTLEFS == 1)
|
||||
LfsInit();
|
||||
#endif
|
||||
return LOS_OK;
|
||||
}
|
||||
87
components/fs/vfs/vfs_maps.c
Normal file
87
components/fs/vfs/vfs_maps.c
Normal file
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright (c) 2022-2022 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. *
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "vfs_maps.h"
|
||||
#include "vfs_operations.h"
|
||||
#include <stdlib.h>
|
||||
#include "securec.h"
|
||||
#include "los_debug.h"
|
||||
#include "los_compiler.h"
|
||||
|
||||
struct FsMap *g_fsMap = NULL;
|
||||
|
||||
struct FsMap *VfsFsMapGet(const char *fsType)
|
||||
{
|
||||
struct FsMap *curr = g_fsMap;
|
||||
|
||||
(void)VfsLock();
|
||||
while (curr != NULL) {
|
||||
if ((curr->fsType != NULL) && (fsType != NULL) &&
|
||||
(strcmp(curr->fsType, fsType) == 0)) {
|
||||
(void)VfsUnlock();
|
||||
return curr;
|
||||
}
|
||||
curr = curr->next;
|
||||
}
|
||||
|
||||
VfsUnlock();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int OsFsRegister(const char *fsType, struct MountOps *fsMops,
|
||||
struct FileOps *fsFops, struct FsManagement *fsMgt)
|
||||
{
|
||||
if ((fsMops == NULL) || (fsFops == NULL)) {
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
struct FsMap *newfs = (struct FsMap *)malloc(sizeof(struct FsMap));
|
||||
if (newfs == NULL) {
|
||||
PRINT_ERR("Fs register malloc failed, fsType %s.\n", fsType);
|
||||
return LOS_NOK;
|
||||
}
|
||||
(void)memset_s(newfs, sizeof(struct FsMap), 0, sizeof(struct FsMap));
|
||||
|
||||
newfs->fsType = strdup(fsType);
|
||||
if (newfs->fsType == NULL) {
|
||||
free(newfs);
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
newfs->fsMops = fsMops;
|
||||
newfs->fsFops = fsFops;
|
||||
newfs->fsMgt = fsMgt;
|
||||
newfs->fsRefs = 0;
|
||||
|
||||
(void)VfsLock();
|
||||
newfs->next = g_fsMap;
|
||||
g_fsMap = newfs;
|
||||
|
||||
VfsUnlock();
|
||||
return LOS_OK;
|
||||
}
|
||||
69
components/fs/vfs/vfs_maps.h
Normal file
69
components/fs/vfs/vfs_maps.h
Normal file
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright (c) 2022-2022 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _VFS_MAPS_H_
|
||||
#define _VFS_MAPS_H_
|
||||
|
||||
#include "los_compiler.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
struct MountOps;
|
||||
|
||||
struct FsManagement {
|
||||
int (*fdisk)(const char *dev, int *lengthArray, int partNum);
|
||||
int (*format)(const char *partName, void *data);
|
||||
};
|
||||
|
||||
|
||||
struct FsMap {
|
||||
const char *fsType;
|
||||
const struct MountOps *fsMops;
|
||||
const struct FileOps *fsFops;
|
||||
const struct FsManagement *fsMgt;
|
||||
UINT32 fsRefs;
|
||||
struct FsMap *next;
|
||||
};
|
||||
|
||||
int OsFsRegister(const char *fsType, struct MountOps *fsMops,
|
||||
struct FileOps *fsFops, struct FsManagement *fsMgt);
|
||||
struct FsMap *VfsFsMapGet(const char *fsType);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _VFS_MAPS_H_ */
|
||||
294
components/fs/vfs/vfs_mount.c
Normal file
294
components/fs/vfs/vfs_mount.c
Normal file
@@ -0,0 +1,294 @@
|
||||
/*
|
||||
* Copyright (c) 2022-2022 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include "vfs_mount.h"
|
||||
#include "vfs_files.h"
|
||||
#include "vfs_maps.h"
|
||||
#include "vfs_config.h"
|
||||
#include "stdlib.h"
|
||||
#include "string.h"
|
||||
#include "vfs_operations.h"
|
||||
#include "los_compiler.h"
|
||||
#include "los_debug.h"
|
||||
#include "los_fs.h"
|
||||
#include "los_mux.h"
|
||||
|
||||
struct MountPoint *g_mountPoints = NULL;
|
||||
|
||||
static void MpDeleteFromList(struct MountPoint *mp)
|
||||
{
|
||||
struct MountPoint *prev = NULL;
|
||||
|
||||
/* delete mp from mount list */
|
||||
if (g_mountPoints == mp) {
|
||||
g_mountPoints = mp->mNext;
|
||||
} else {
|
||||
for (prev = g_mountPoints; prev != NULL; prev = prev->mNext) {
|
||||
if (prev->mNext != mp) {
|
||||
continue;
|
||||
}
|
||||
|
||||
prev->mNext = mp->mNext;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct MountPoint *VfsMpFind(const char *path, const char **pathInMp)
|
||||
{
|
||||
struct MountPoint *mp = g_mountPoints;
|
||||
struct MountPoint *bestMp = NULL;
|
||||
int bestMatches = 0;
|
||||
if (path == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
if (pathInMp != NULL) {
|
||||
*pathInMp = NULL;
|
||||
}
|
||||
while ((mp != NULL) && (mp->mPath != NULL)) {
|
||||
const char *mPath = mp->mPath;
|
||||
const char *iPath = path;
|
||||
const char *t = NULL;
|
||||
int matches = 0;
|
||||
do {
|
||||
while ((*mPath == '/') && (*(mPath + 1) != '/')) {
|
||||
mPath++;
|
||||
}
|
||||
while ((*iPath == '/') && (*(iPath + 1) != '/')) {
|
||||
iPath++;
|
||||
}
|
||||
|
||||
t = strchr(mPath, '/');
|
||||
if (t == NULL) {
|
||||
t = strchr(mPath, '\0');
|
||||
}
|
||||
if ((t == mPath) || (t == NULL)) {
|
||||
break;
|
||||
}
|
||||
if (strncmp(mPath, iPath, (size_t)(t - mPath)) != 0) {
|
||||
goto next; /* this mount point do not match, check next */
|
||||
}
|
||||
|
||||
iPath += (t - mPath);
|
||||
if ((*iPath != '\0') && (*iPath != '/')) {
|
||||
goto next;
|
||||
}
|
||||
|
||||
matches += (t - mPath);
|
||||
mPath += (t - mPath);
|
||||
} while (*mPath != '\0');
|
||||
|
||||
if (matches > bestMatches) {
|
||||
bestMatches = matches;
|
||||
bestMp = mp;
|
||||
|
||||
while ((*iPath == '/') && (*(iPath + 1) != '/')) {
|
||||
iPath++;
|
||||
}
|
||||
|
||||
if (pathInMp != NULL) {
|
||||
*pathInMp = path;
|
||||
}
|
||||
}
|
||||
next:
|
||||
mp = mp->mNext;
|
||||
}
|
||||
return bestMp;
|
||||
}
|
||||
|
||||
int LOS_FsMount(const char *source, const char *target,
|
||||
const char *fsType, unsigned long mountflags,
|
||||
const void *data)
|
||||
{
|
||||
int ret;
|
||||
struct MountPoint *mp = NULL;
|
||||
const char *pathInMp = NULL;
|
||||
|
||||
/* target must begin with '/', for example /system, /data, etc. */
|
||||
if ((target == NULL) || (target[0] != '/')) {
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
(void)VfsLock();
|
||||
/* find mp by target, to see if it was mounted */
|
||||
mp = VfsMpFind(target, &pathInMp);
|
||||
if (mp != NULL && pathInMp != NULL) {
|
||||
goto errout;
|
||||
}
|
||||
|
||||
/* Find fsMap coresponding to the fsType */
|
||||
struct FsMap *mFs = VfsFsMapGet(fsType);
|
||||
if ((mFs == NULL) || (mFs->fsMops == NULL) ||
|
||||
(mFs->fsMops->mount == NULL)) {
|
||||
goto errout;
|
||||
}
|
||||
|
||||
mp = (struct MountPoint *)malloc(sizeof(struct MountPoint));
|
||||
if (mp == NULL) {
|
||||
goto errout;
|
||||
}
|
||||
|
||||
mp->mFs = mFs;
|
||||
mp->mDev = NULL;
|
||||
if (source != NULL) {
|
||||
mp->mDev = strdup(source);
|
||||
if (mp->mDev == NULL) {
|
||||
goto errout;
|
||||
}
|
||||
}
|
||||
|
||||
mp->mPath = strdup(target);
|
||||
if (mp->mPath == NULL) {
|
||||
goto errout;
|
||||
}
|
||||
|
||||
ret = mp->mFs->fsMops->mount(mp, mountflags, data);
|
||||
if (ret != 0) {
|
||||
/* errno is set */
|
||||
PRINT_ERR("mount failed, target %s.\n", target);
|
||||
goto errout;
|
||||
}
|
||||
mp->mRefs = 0;
|
||||
mp->mWriteEnable = (mountflags & MS_RDONLY) ? FALSE : TRUE;
|
||||
mp->mFs->fsRefs++;
|
||||
mp->mNext = g_mountPoints;
|
||||
g_mountPoints = mp;
|
||||
VfsUnlock();
|
||||
return LOS_OK;
|
||||
|
||||
errout:
|
||||
free((void *)mp->mPath);
|
||||
free((void *)mp->mDev);
|
||||
free(mp);
|
||||
VfsUnlock();
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
int LOS_FsUmount(const char *target)
|
||||
{
|
||||
struct MountPoint *mp = NULL;
|
||||
const char *pathInMp = NULL;
|
||||
int ret = LOS_NOK;
|
||||
|
||||
(void)VfsLock();
|
||||
if (target == NULL) {
|
||||
goto errout;
|
||||
}
|
||||
|
||||
mp = VfsMpFind(target, &pathInMp);
|
||||
if ((mp == NULL) || (mp->mRefs != 0)) {
|
||||
goto errout;
|
||||
}
|
||||
|
||||
if ((mp->mFs == NULL) || (mp->mFs->fsMops == NULL) ||
|
||||
(mp->mFs->fsMops->umount == NULL)) {
|
||||
goto errout;
|
||||
}
|
||||
|
||||
ret = mp->mFs->fsMops->umount(mp);
|
||||
if (ret != 0) {
|
||||
/* errno is set */
|
||||
goto errout;
|
||||
}
|
||||
|
||||
/* delete mp from mount list */
|
||||
MpDeleteFromList(mp);
|
||||
mp->mFs->fsRefs--;
|
||||
free((void *)mp->mPath);
|
||||
free((void *)mp->mDev);
|
||||
free(mp);
|
||||
|
||||
VfsUnlock();
|
||||
return LOS_OK;
|
||||
|
||||
errout:
|
||||
PRINT_ERR("umount2 failed, target %s.\n", target);
|
||||
VfsUnlock();
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
static void CloseFdsInMp(struct MountPoint *mp)
|
||||
{
|
||||
for (int fd = 0; fd < NR_OPEN_DEFAULT; fd++) {
|
||||
struct File *f = FdToFile(fd);
|
||||
if (f == NULL) {
|
||||
continue;
|
||||
}
|
||||
if ((f->fMp == mp) &&
|
||||
(f->fFops != NULL) &&
|
||||
(f->fFops->close != NULL)) {
|
||||
(void)f->fFops->close(f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int LOS_FsUmount2(const char *target, int flag)
|
||||
{
|
||||
struct MountPoint *mp = NULL;
|
||||
const char *pathInMp = NULL;
|
||||
int ret = LOS_NOK;
|
||||
|
||||
(void)VfsLock();
|
||||
if (target == NULL) {
|
||||
goto errout;
|
||||
}
|
||||
|
||||
mp = VfsMpFind(target, &pathInMp);
|
||||
if ((mp == NULL) || (mp->mRefs != 0) ||
|
||||
(mp->mFs == NULL) || (mp->mFs->fsMops == NULL) ||
|
||||
(mp->mFs->fsMops->umount2 == NULL)) {
|
||||
goto errout;
|
||||
}
|
||||
|
||||
/* Close all files under the mount point */
|
||||
if ((UINT32)flag & MNT_FORCE) {
|
||||
CloseFdsInMp(mp);
|
||||
}
|
||||
|
||||
ret = mp->mFs->fsMops->umount2(mp, flag);
|
||||
if (ret != 0) {
|
||||
/* errno is set */
|
||||
goto errout;
|
||||
}
|
||||
|
||||
/* delete mp from mount list */
|
||||
MpDeleteFromList(mp);
|
||||
mp->mFs->fsRefs--;
|
||||
free((void *)mp->mPath);
|
||||
free((void *)mp->mDev);
|
||||
free(mp);
|
||||
|
||||
VfsUnlock();
|
||||
return LOS_OK;
|
||||
|
||||
errout:
|
||||
PRINT_ERR("umount2 failed, target %s.\n", target);
|
||||
VfsUnlock();
|
||||
return LOS_NOK;
|
||||
}
|
||||
76
components/fs/vfs/vfs_mount.h
Normal file
76
components/fs/vfs/vfs_mount.h
Normal file
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright (c) 2022-2022 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _VFS_MOUNT_H_
|
||||
#define _VFS_MOUNT_H_
|
||||
|
||||
#include "sys/statfs.h"
|
||||
#include "los_compiler.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
struct FsMap;
|
||||
struct MountPoint;
|
||||
|
||||
struct MountOps {
|
||||
int (*mount)(struct MountPoint *mp, unsigned long mountflags,
|
||||
const void *data);
|
||||
int (*umount)(struct MountPoint *mp);
|
||||
int (*umount2)(struct MountPoint *mp, int flag);
|
||||
int (*statfs)(const char *path, struct statfs *buf);
|
||||
};
|
||||
|
||||
struct MountPoint {
|
||||
struct FsMap *mFs; /* file system info */
|
||||
struct MountPoint *mNext; /* point to next mount point */
|
||||
const char *mPath; /* target path, /system, /usr, etc. */
|
||||
const char *mDev; /* device, "emmc0p0", "emmc0p1", etc. */
|
||||
UINT32 mRefs; /* reference to mount point */
|
||||
void *mData; /* specific file system handle */
|
||||
BOOL mWriteEnable; /* writable flag */
|
||||
};
|
||||
|
||||
extern struct MountPoint *g_mountPoints;
|
||||
#define LOS_MP_FOR_EACH_ENTRY(prev) \
|
||||
for (prev = g_mountPoints; prev != NULL; prev = prev->mNext)
|
||||
|
||||
struct MountPoint *VfsMpFind(const char *path, const char **pathInMp);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _VFS_MOUNT_H_ */
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user