Compare commits

..

30 Commits

Author SHA1 Message Date
openharmony_ci
59fbe91d8b !1009 Fix : OsLs 内存泄漏问题
Merge pull request !1009 from yinjiaming/fix
2023-01-13 08:54:49 +00:00
openharmony_ci
c7088f4d0f !1010 告警清理
Merge pull request !1010 from 乔克叔叔/release
2023-01-13 05:42:29 +00:00
liuwenxin
705bfbdc76 fix:release告警清理
release分支告警清理

close:#I6AD15

Signed-off-by: liuwenxin <liuwenxin11@huawei.com>
2023-01-13 11:34:52 +08:00
yinjiaming
9a4e9677bd fix:修复OsLs函数内存泄漏问题
当d = NULL时,path没有释放,现释放path所指向的内存

close #I6A07U

Signed-off-by: yinjiaming <yinjiaming@huawei.com>
Change-Id: Iee9fd8d2171c6fdcf353a48e7af385bbd1660520
2023-01-12 15:30:19 +08:00
openharmony_ci
6134d4bd22 !989 修复-Werror编译选项产生的告警
Merge pull request !989 from 乔克叔叔/lwx
2023-01-11 07:55:48 +00:00
openharmony_ci
c119b7e9e2 !1006 Fix : statfs函数内部判断错误
Merge pull request !1006 from yinjiaming/fix
2023-01-11 07:37:51 +00:00
openharmony_ci
dbf0498bab !1008 fix: 非gcc形态下FUNC_ALIAS编译错误
Merge pull request !1008 from Zhaotianyu/20230111symbol_fix
2023-01-11 06:49:43 +00:00
arvinzzz
68b142cf78 fix: 修复非gcc形态FUNC_ALIAS编译错误
Signed-off-by: arvinzzz <zhaotianyu9@huawei.com>
Change-Id: I7f199366d8173d9fc504f89b26329ea5f7d1eb9e
2023-01-11 10:45:18 +08:00
openharmony_ci
22b7eb87ca !998 fix: 不同C库下gettimeofday特性规格统一
Merge pull request !998 from Zhaotianyu/20230107gettimeofday
2023-01-11 00:46:21 +00:00
arvinzzz
ed50f7e373 fix: 不同libc下gettimeofday特性规格统一
Signed-off-by: arvinzzz <zhaotianyu9@huawei.com>
Change-Id: Iaaf1fed24101f43c636737294dbe870d2f467b0a
2023-01-10 20:36:34 +08:00
yinjiaming
2f2a0b7a75 fix:修复statfs函数内部判断错误
修复函数调用的是statfs却用stat!=NULL来判断,当文件系统是little_fs时导致死机的问题。

close #I69BXB

Signed-off-by: yinjiaming <yinjiaming@huawei.com>
Change-Id: Ib9784c017f4260433c3f12e352470108ea83ec19
2023-01-10 15:49:01 +08:00
openharmony_ci
1ae62ebf2e !1000 fix:mutex trace中ArchLRGet等接口改变实现方式
Merge pull request !1000 from zhangdengyu/mutexTraceFix
2023-01-10 06:44:48 +00:00
zhangdengyu
25278a02eb fix:mutex trace中ArchLRGet接口改变实现方式
方案描述:
将ArchLRGet接口的实现方式由内联函数修改为宏,
防止产品添加--no_inline等编译选项导致函数无法在调用点展开,
造成由于函数调用过程中函数栈帧的变化带来的LR寄存器中存储的值的变化。

Close #I69D9N

Signed-off-by: zhangdengyu <zhangdengyu2@huawei.com>
Change-Id: If417bc2ec9febf064c63da198faf4ac000d70c52
2023-01-10 14:28:15 +08:00
liuwenxin
52bc16c3db fix:修复-Werror编译选项产生的告警
清理框架定义未使用告警,宏重定义,以及变量定义未使用等告警。

Close #I68RLA

Signed-off-by: liuwenxin <liuwenxin11@huawei.com>
2023-01-10 10:26:22 +08:00
openharmony_ci
733b6e6c6c !988 fix: mktime测试用例不依赖固定时区
Merge pull request !988 from Zhaotianyu/20230104fix_mktime_test
2023-01-04 09:36:32 +00:00
arvinzzz
6562536db7 fix: mktime testcase
Eliminate the effects of different time zones

Signed-off-by: arvinzzz <zhaotianyu9@huawei.com>
Change-Id: I22f0dc7057df642e255bec9a8b663c2b544b107e
2023-01-04 16:39:01 +08:00
openharmony_ci
ddf3dc8237 !985 fix: mktime测试用例配套修改
Merge pull request !985 from Zhaotianyu/20230103fix_mktime_test
2023-01-03 07:45:12 +00:00
arvinzzz
399e7647bb fix: mktime testcase
Signed-off-by: arvinzzz <zhaotianyu9@huawei.com>
Change-Id: I50e0252aa8611e9a269b836c552bfdf33ade8f44
2023-01-03 11:27:26 +08:00
openharmony_ci
f7af2cdf9b !983 修复codecheck告警
Merge pull request !983 from 夏不白/codecheck
2022-12-30 06:19:55 +00:00
xiacong
07091c5a75 fix:修复codecheck告警
1、修复空格、空行使用错误告警;
2、将超过10行的inline函数去除内联符号

fix #I685E3

Signed-off-by: xiacong <xiacong4@huawei.com>
2022-12-30 12:11:01 +08:00
openharmony_ci
6633aabf89 !979 fix: mktime获取的时间缺少时区信息
Merge pull request !979 from Zhaotianyu/20221228mktime_fix
2022-12-29 10:21:38 +00:00
arvinzzz
2a4282f912 fix: The tm struct obtained by mktime lacks timezone information
BREAKING CHANGE:
The tm struct obtained by mktime lacks timezone information
变更API:
time_t mktime(struct tm *tmptr)
原先mktime从入参中获取时区信息进行计算,变更后tm结构体和返回值time_t的计算使用系统g_timezone时区环境变量。

Close I67UIA

Signed-off-by: arvinzzz <zhaotianyu9@huawei.com>
Change-Id: I766cffbff3c1a25bb33cbd245225ee117909af3a
2022-12-29 16:26:08 +08:00
openharmony_ci
685688b21c !977 Fixed compilation problems with niobe407 and neptune100
Merge pull request !977 from 张亚雷/master
2022-12-27 07:21:39 +00:00
mrzhang
67ee38e1e3 fix: Fixed compilation problems with niobe407 and neptune100
Signed-off-by: mrzhang <zhangyalei8@h-partners.com>
2022-12-26 18:25:44 -08:00
openharmony_ci
6cd48f6f90 !965 VfsMpFind接口优化
Merge pull request !965 from Far/vfsmpfind
2022-12-24 03:12:29 +00:00
Far
662aefb700 fix: VfsMpFind optimize
1. provide VfsMpFind which doesn't support mounting recursively;
2. provide a macro to set whether supporting recursive-mount or not.
3. adding path length checking

BREAKING CHANGE:
new config option:
LOSCFG_FS_SUPPORT_MOUNT_TARGET_RECURSIVE

fix #I65XE6
Signed-off-by: Far <yesiyuan2@huawei.com>
Change-Id: I7ae371f0e6fff46db0e2368f905aa22bac864b79
2022-12-24 10:44:11 +08:00
openharmony_ci
83fc93cc84 !974 fix: misc_config中defines未初始化导致编译失败
Merge pull request !974 from Zhaotianyu/20221222misc_config
2022-12-22 07:44:57 +00:00
arvinzzz
b817c490ba fix: 修复misc_config中defines未初始化的错误
Signed-off-by: arvinzzz <zhaotianyu9@huawei.com>
Change-Id: I4eecfc1af2b0cdc39922a8ce299eb8ab6b7c6e8c
2022-12-22 11:28:31 +08:00
openharmony_ci
705e4c323a !973 【重新提交】修复文件系统中不合理的锁操作
Merge pull request !973 from Far/master
2022-12-22 03:10:43 +00:00
Far
b7f906ef8a fix: 修复文件系统不合理的锁操作
1. 移除了fatfs和littlefs中冗余的加锁操作。
2. 增加了配置选项FS_LOCK_TIMEOUT(宏LOSCFG_FS_LOCK_TIMEOUT),提供配置
   文件系统获取锁超时能力。
3. 新增对外接口LOS_FsLock()和LOS_FsUnlock()接口,提供HAL层与文件系统的
   互斥操作。

BREAKING CHANGE:
修复文件系统不合理的锁操作
新增API:
los_fs.h:
int LOS_FsLock(void)
int LOS_FsUnlock(void)
新增配置项:
LOSCFG_FS_LOCK_TIMEOUT(menuconfig FS_LOCK_TIMEOUT)

fix #I66S2J

Signed-off-by: Far <yesiyuan2@huawei.com>
Change-Id: I2ae9b6b5e2c788b2f4a00d9678a0240d00c335eb
2022-12-22 10:41:31 +08:00
49 changed files with 483 additions and 786 deletions

View File

@@ -91,8 +91,9 @@ config("dialect_config") {
}
config("misc_config") {
defines = []
if (!defined(LOSCFG_COMPILER_ICCARM)) {
defines = [ "__LITEOS__" ]
defines += [ "__LITEOS__" ]
defines += [ "__LITEOS_M__" ]
}
if (!defined(LOSCFG_DEBUG_VERSION)) {

View File

@@ -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-2023 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:
@@ -63,12 +63,13 @@ STATIC INLINE UINTPTR ArchMspGet(VOID)
return msp;
}
STATIC INLINE UINTPTR ArchLRGet(VOID)
{
UINTPTR lr;
__asm("mov %0, lr" : "=r" (lr));
return lr;
}
#define ARCH_LR_GET() \
({ \
UINTPTR lr; \
__asm("mov %0, lr" : "=r" (lr)); \
(lr); \
})
#define ArchLRGet ARCH_LR_GET
#elif defined(__CLANG_ARM) || defined(__GNUC__)
STATIC INLINE UINTPTR ArchSpGet(VOID)
{
@@ -91,12 +92,13 @@ STATIC INLINE UINTPTR ArchMspGet(VOID)
return msp;
}
STATIC INLINE UINTPTR ArchLRGet(VOID)
{
UINTPTR lr;
__asm volatile("mov %0, lr" : "=r" (lr));
return lr;
}
#define ARCH_LR_GET() \
({ \
UINTPTR lr; \
__asm volatile("mov %0, lr" : "=r" (lr)); \
(lr); \
})
#define ArchLRGet ARCH_LR_GET
#else
/* Other platforms to be improved */
#endif

View File

@@ -170,7 +170,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsCpupInit()
return LOS_OK;
}
/* The calculation time unit is changed to us to decouple the influence of
/* The calculation time unit is changed to us to decouple the influence of
* system frequency modulation on CPUP
*/
STATIC UINT64 CpupTimeUsGet(VOID)

View File

@@ -60,7 +60,6 @@
#endif /* FS_LOCK_TIMEOUT_SEC */
static UINT8 g_workBuffer[FF_MAX_SS];
static pthread_mutex_t g_fatfsMutex = PTHREAD_MUTEX_INITIALIZER;
static char *g_volPath[FF_VOLUMES] = {FF_VOLUME_STRS};
PARTITION VolToPart[] = {
@@ -70,31 +69,6 @@ PARTITION VolToPart[] = {
{ 0, 0, 4, 0, 0 }
};
static int FsLock(void)
{
int ret = 0;
struct timespec absTimeout = {0};
if (!OsCheckKernelRunning()) {
return ret;
}
ret = clock_gettime(CLOCK_REALTIME, &absTimeout);
if (ret != 0) {
PRINT_ERR("clock gettime err 0x%x!\r\n", errno);
return errno;
}
absTimeout.tv_sec += FS_LOCK_TIMEOUT_SEC;
ret = pthread_mutex_timedlock(&g_fatfsMutex, &absTimeout);
return ret;
}
static void FsUnlock(void)
{
if (!OsCheckKernelRunning()) {
return;
}
(void)pthread_mutex_unlock(&g_fatfsMutex);
}
static int FsChangeDrive(const char *path)
{
INT32 res;
@@ -275,95 +249,69 @@ int FatfsMount(struct MountPoint *mp, unsigned long mountflags,
{
FRESULT res;
FATFS *fs = NULL;
int ret;
ret = FsLock();
if (ret != 0) {
errno = ret;
return (int)LOS_NOK;
}
if (mountflags & MS_REMOUNT) {
ret = Remount(mp, mountflags);
FsUnlock();
return ret;
return Remount(mp, mountflags);
}
char *ldPath = GetLdPath(mp->mDev);
if (ldPath == NULL) {
errno = EFAULT;
ret = (int)LOS_NOK;
goto ERROUT;
return (int)LOS_NOK;
}
fs = (FATFS *)LOSCFG_FS_MALLOC_HOOK(sizeof(FATFS));
if (fs == NULL) {
errno = ENOMEM;
ret = (int)LOS_NOK;
goto ERROUT;
PutLdPath(ldPath);
return (int)LOS_NOK;
}
(void)memset_s(fs, sizeof(FATFS), 0, sizeof(FATFS));
res = f_mount(fs, ldPath, 1);
if (res != FR_OK) {
LOSCFG_FS_FREE_HOOK(fs);
PutLdPath(ldPath);
errno = FatfsErrno(res);
return (int)LOS_NOK;
}
mp->mData = (void *)fs;
res = f_mount((FATFS *)mp->mData, ldPath, 1);
if (res != FR_OK) {
errno = FatfsErrno(res);
ret = (int)LOS_NOK;
goto ERROUT;
}
PutLdPath(ldPath);
FsUnlock();
return (int)LOS_OK;
ERROUT:
LOSCFG_FS_FREE_HOOK(fs);
mp->mData = NULL;
PutLdPath(ldPath);
FsUnlock();
return ret;
}
int FatfsUmount(struct MountPoint *mp)
{
int ret;
int volId;
FRESULT res;
char *ldPath = NULL;
FATFS *fatfs = (FATFS *)mp->mData;
ret = FsLock();
if (ret != 0) {
errno = ret;
return (int)LOS_NOK;
}
char *ldPath = GetLdPath(mp->mDev);
if (ldPath == NULL) {
errno = EFAULT;
ret = (int)LOS_NOK;
goto OUT;
}
/* The volume is not mounted */
if (fatfs->fs_type == 0) {
errno = EINVAL;
ret = (int)LOS_NOK;
goto OUT;
return (int)LOS_NOK;
}
volId = GetPartIdByPartName(mp->mDev);
/* umount is not allowed when a file or directory is opened. */
if (f_checkopenlock(volId) != FR_OK) {
errno = EBUSY;
ret = (int)LOS_NOK;
goto OUT;
return (int)LOS_NOK;
}
ldPath = GetLdPath(mp->mDev);
if (ldPath == NULL) {
errno = EFAULT;
return (int)LOS_NOK;
}
res = f_mount((FATFS *)NULL, ldPath, 0);
if (res != FR_OK) {
errno = FatfsErrno(res);
ret = (int)LOS_NOK;
goto OUT;
PutLdPath(ldPath);
return (int)LOS_NOK;
}
if (fatfs->win != NULL) {
@@ -373,19 +321,15 @@ int FatfsUmount(struct MountPoint *mp)
LOSCFG_FS_FREE_HOOK(mp->mData);
mp->mData = NULL;
ret = (int)LOS_OK;
OUT:
PutLdPath(ldPath);
FsUnlock();
return ret;
return (int)LOS_OK;
}
int FatfsUmount2(struct MountPoint *mp, int flag)
{
int ret;
UINT32 flags;
FRESULT res;
char *ldPath = NULL;
FATFS *fatfs = (FATFS *)mp->mData;
flags = MNT_FORCE | MNT_DETACH | MNT_EXPIRE | UMOUNT_NOFOLLOW;
@@ -394,31 +338,23 @@ int FatfsUmount2(struct MountPoint *mp, int flag)
return (int)LOS_NOK;
}
ret = FsLock();
if (ret != 0) {
errno = ret;
return (int)LOS_NOK;
}
char *ldPath = GetLdPath(mp->mDev);
if (ldPath == NULL) {
errno = EFAULT;
ret = (int)LOS_NOK;
goto OUT;
}
/* The volume is not mounted */
if (fatfs->fs_type == 0) {
errno = EINVAL;
ret = (int)LOS_NOK;
goto OUT;
return (int)LOS_NOK;
}
ldPath = GetLdPath(mp->mDev);
if (ldPath == NULL) {
errno = EFAULT;
return (int)LOS_NOK;
}
res = f_mount((FATFS *)NULL, ldPath, 0);
if (res != FR_OK) {
PutLdPath(ldPath);
errno = FatfsErrno(res);
ret = (int)LOS_NOK;
goto OUT;
return (int)LOS_NOK;
}
if (fatfs->win != NULL) {
@@ -428,12 +364,8 @@ int FatfsUmount2(struct MountPoint *mp, int flag)
LOSCFG_FS_FREE_HOOK(mp->mData);
mp->mData = NULL;
ret = (int)LOS_OK;
OUT:
PutLdPath(ldPath);
FsUnlock();
return ret;
return (int)LOS_OK;
}
int FatfsOpen(struct File *file, const char *path, int oflag)
@@ -456,20 +388,12 @@ int FatfsOpen(struct File *file, const char *path, int oflag)
return (int)LOS_NOK;
}
ret = FsLock();
if (ret != 0) {
errno = ret;
LOSCFG_FS_FREE_HOOK(fp);
return (int)LOS_NOK;
}
ret = FsChangeDrive(path);
if (ret != (int)LOS_OK) {
PRINT_ERR("FAT open ChangeDrive err 0x%x!\r\n", ret);
errno = ENOENT;
ret = (int)LOS_NOK;
LOSCFG_FS_FREE_HOOK(fp);
goto OUT;
return (int)LOS_NOK;
}
res = f_open(fp, path, fmode);
@@ -477,31 +401,20 @@ int FatfsOpen(struct File *file, const char *path, int oflag)
PRINT_ERR("FAT open err 0x%x!\r\n", res);
LOSCFG_FS_FREE_HOOK(fp);
errno = FatfsErrno(res);
ret = (int)LOS_NOK;
goto OUT;
return (int)LOS_NOK;
}
file->fData = (void *)fp;
OUT:
FsUnlock();
return ret;
return (int)LOS_OK;
}
int FatfsClose(struct File *file)
{
FRESULT res;
FIL *fp = (FIL *)file->fData;
int ret;
ret = FsLock();
if (ret != 0) {
errno = ret;
return (int)LOS_NOK;
}
if ((fp == NULL) || (fp->obj.fs == NULL)) {
FsUnlock();
errno = ENOENT;
return (int)LOS_NOK;
}
@@ -509,7 +422,6 @@ int FatfsClose(struct File *file)
res = f_close(fp);
if (res != FR_OK) {
PRINT_ERR("FAT close err 0x%x!\r\n", res);
FsUnlock();
errno = FatfsErrno(res);
return (int)LOS_NOK;
}
@@ -521,7 +433,6 @@ int FatfsClose(struct File *file)
#endif
LOSCFG_FS_FREE_HOOK(file->fData);
file->fData = NULL;
FsUnlock();
return (int)LOS_OK;
}
@@ -531,31 +442,22 @@ ssize_t FatfsRead(struct File *file, char *buf, size_t nbyte)
FRESULT res;
UINT32 lenRead;
FIL *fp = (FIL *)file->fData;
int ret;
if (buf == NULL) {
errno = EFAULT;
return (ssize_t)LOS_NOK;
}
ret = FsLock();
if (ret != 0) {
errno = ret;
return (ssize_t)LOS_NOK;
}
if (fp == NULL) {
FsUnlock();
errno = ENOENT;
return (ssize_t)LOS_NOK;
}
res = f_read(fp, buf, nbyte, &lenRead);
if (res != FR_OK) {
FsUnlock();
errno = FatfsErrno(res);
return (ssize_t)LOS_NOK;
}
FsUnlock();
return (ssize_t)lenRead;
}
@@ -566,22 +468,15 @@ ssize_t FatfsWrite(struct File *file, const char *buf, size_t nbyte)
UINT32 lenWrite;
static BOOL overFlow = FALSE;
FIL *fp = (FIL *)file->fData;
int ret;
if (buf == NULL) {
errno = EFAULT;
return (ssize_t)LOS_NOK;
}
ret = FsLock();
if (ret != 0) {
errno = ret;
return (ssize_t)LOS_NOK;
}
if ((fp ==NULL) || (fp->obj.fs == NULL)) {
if ((fp == NULL) || (fp->obj.fs == NULL)) {
errno = ENOENT;
goto ERROUT;
return (ssize_t)LOS_NOK;
}
res = f_write(fp, buf, nbyte, &lenWrite);
@@ -592,15 +487,10 @@ ssize_t FatfsWrite(struct File *file, const char *buf, size_t nbyte)
if ((res != FR_OK) || (nbyte != lenWrite)) {
errno = FatfsErrno(res);
goto ERROUT;
return (ssize_t)LOS_NOK;
}
FsUnlock();
return (ssize_t)lenWrite;
ERROUT:
FsUnlock();
return (ssize_t)LOS_NOK;
}
off_t FatfsLseek(struct File *file, off_t offset, int whence)
@@ -608,17 +498,10 @@ off_t FatfsLseek(struct File *file, off_t offset, int whence)
FRESULT res;
off_t pos;
FIL *fp = (FIL *)file->fData;
int ret;
ret = FsLock();
if (ret != 0) {
errno = ret;
return (off_t)LOS_NOK;
}
if ((fp == NULL) || (fp->obj.fs == NULL)) {
errno = ENOENT;
goto ERROUT;
return (off_t)LOS_NOK;
}
if (whence == SEEK_SET) {
@@ -629,22 +512,17 @@ off_t FatfsLseek(struct File *file, off_t offset, int whence)
pos = f_size(fp);
} else {
errno = EINVAL;
goto ERROUT;
return (off_t)LOS_NOK;
}
res = f_lseek(fp, offset + pos);
if (res != FR_OK) {
errno = FatfsErrno(res);
goto ERROUT;
return (off_t)LOS_NOK;
}
pos = f_tell(fp);
FsUnlock();
return pos;
ERROUT:
FsUnlock();
return (off_t)LOS_NOK;
}
/* Remove the specified FILE */
@@ -658,39 +536,26 @@ int FatfsUnlink(struct MountPoint *mp, const char *path)
return (int)LOS_NOK;
}
ret = FsLock();
if (ret != 0) {
errno = ret;
return (int)LOS_NOK;
}
if (!mp->mWriteEnable) {
errno = EACCES;
ret = (int)LOS_NOK;
goto OUT;
return (int)LOS_NOK;
}
ret = FsChangeDrive(path);
if (ret != (int)LOS_OK) {
PRINT_ERR("FAT unlink ChangeDrive err 0x%x!\r\n", ret);
errno = ENOENT;
ret = (int)LOS_NOK;
goto OUT;
return (int)LOS_NOK;
}
res = f_unlink(path);
if (res != FR_OK) {
PRINT_ERR("FAT unlink err 0x%x!\r\n", res);
errno = FatfsErrno(res);
ret = (int)LOS_NOK;
goto OUT;
return (int)LOS_NOK;
}
ret = (int)LOS_OK;
OUT:
FsUnlock();
return ret;
return (int)LOS_OK;
}
int FatfsStat(struct MountPoint *mp, const char *path, struct stat *buf)
@@ -704,26 +569,18 @@ int FatfsStat(struct MountPoint *mp, const char *path, struct stat *buf)
return (int)LOS_NOK;
}
ret = FsLock();
if (ret != 0) {
errno = ret;
return (int)LOS_NOK;
}
ret = FsChangeDrive(path);
if (ret != (int)LOS_OK) {
PRINT_ERR("FAT stat ChangeDrive err 0x%x!\r\n", ret);
errno = ENOENT;
ret = (int)LOS_NOK;
goto OUT;
return (int)LOS_NOK;
}
res = f_stat(path, &fileInfo);
if (res != FR_OK) {
PRINT_ERR("FAT stat err 0x%x!\r\n", res);
errno = FatfsErrno(res);
ret = (int)LOS_NOK;
goto OUT;
return (int)LOS_NOK;
}
buf->st_size = fileInfo.fsize;
@@ -740,43 +597,27 @@ int FatfsStat(struct MountPoint *mp, const char *path, struct stat *buf)
buf->st_mode |= S_IFDIR;
}
ret = (int)LOS_OK;
OUT:
FsUnlock();
return ret;
return (int)LOS_OK;
}
/* Synchronize all changes to Flash */
int FatfsSync(struct File *file)
{
int ret;
FRESULT res;
FIL *fp = (FIL *)file->fData;
ret = FsLock();
if (ret != 0) {
errno = ret;
return (int)LOS_NOK;
}
if ((fp == NULL) || (fp->obj.fs == NULL)) {
errno = ENOENT;
ret = (int)LOS_NOK;
goto OUT;
return (int)LOS_NOK;
}
res = f_sync(fp);
if (res != FR_OK) {
errno = FatfsErrno(res);
ret = (int)LOS_NOK;
goto OUT;
return (int)LOS_NOK;
}
ret = (int)LOS_OK;
OUT:
FsUnlock();
return ret;
return (int)LOS_OK;
}
int FatfsMkdir(struct MountPoint *mp, const char *path)
@@ -789,38 +630,26 @@ int FatfsMkdir(struct MountPoint *mp, const char *path)
return (int)LOS_NOK;
}
ret = FsLock();
if (ret != 0) {
errno = ret;
return (int)LOS_NOK;
}
if (!mp->mWriteEnable) {
errno = EACCES;
ret = (int)LOS_NOK;
goto OUT;
return (int)LOS_NOK;
}
ret = FsChangeDrive(path);
if (ret != (int)LOS_OK) {
PRINT_ERR("FAT mkdir ChangeDrive err 0x%x!\r\n", ret);
errno = ENOENT;
ret = (int)LOS_NOK;
goto OUT;
return (int)LOS_NOK;
}
res = f_mkdir(path);
if (res != FR_OK) {
PRINT_ERR("FAT mkdir err 0x%x!\r\n", res);
errno = FatfsErrno(res);
ret = (int)LOS_NOK;
goto OUT;
return (int)LOS_NOK;
}
ret = (int)LOS_OK;
OUT:
FsUnlock();
return ret;
return (int)LOS_OK;
}
int FatfsOpendir(struct Dir *dir, const char *dirName)
@@ -831,47 +660,34 @@ int FatfsOpendir(struct Dir *dir, const char *dirName)
if (dirName == NULL) {
errno = EFAULT;
goto ERROUT;
}
dp = (DIR *)LOSCFG_FS_MALLOC_HOOK(sizeof(DIR));
if (dp == NULL) {
errno = ENOENT;
goto ERROUT;
}
ret = FsLock();
if (ret != 0) {
errno = ret;
goto ERROUT;
return (int)LOS_NOK;
}
ret = FsChangeDrive(dirName);
if (ret != (int)LOS_OK) {
PRINT_ERR("FAT opendir ChangeDrive err 0x%x!\r\n", ret);
errno = ENOENT;
goto ERROUT;
return (int)LOS_NOK;
}
dp = (DIR *)LOSCFG_FS_MALLOC_HOOK(sizeof(DIR));
if (dp == NULL) {
errno = ENOENT;
return (int)LOS_NOK;
}
res = f_opendir(dp, dirName);
if (res != FR_OK) {
PRINT_ERR("FAT opendir err 0x%x!\r\n", res);
LOSCFG_FS_FREE_HOOK(dp);
errno = FatfsErrno(res);
goto ERROUT;
return (int)LOS_NOK;
}
dir->dData = dp;
dir->dOffset = 0;
FsUnlock();
return (int)LOS_OK;
ERROUT:
if (dp != NULL) {
LOSCFG_FS_FREE_HOOK(dp);
}
FsUnlock();
return (int)LOS_NOK;
}
int FatfsReaddir(struct Dir *dir, struct dirent *dent)
@@ -879,7 +695,6 @@ int FatfsReaddir(struct Dir *dir, struct dirent *dent)
FRESULT res;
FILINFO fileInfo = {0};
DIR *dp = NULL;
int ret;
if ((dir == NULL) || (dir->dData == NULL)) {
errno = EBADF;
@@ -887,18 +702,11 @@ int FatfsReaddir(struct Dir *dir, struct dirent *dent)
}
dp = (DIR *)dir->dData;
ret = FsLock();
if (ret != 0) {
errno = ret;
return (int)LOS_NOK;
}
res = f_readdir(dp, &fileInfo);
/* if res not ok or fname is NULL , return NULL */
if ((res != FR_OK) || (fileInfo.fname[0] == 0x0)) {
PRINT_ERR("FAT readdir err 0x%x!\r\n", res);
errno = FatfsErrno(res);
FsUnlock();
return (int)LOS_NOK;
}
@@ -909,7 +717,6 @@ int FatfsReaddir(struct Dir *dir, struct dirent *dent)
} else {
dent->d_type = DT_REG;
}
FsUnlock();
return (int)LOS_OK;
}
@@ -918,7 +725,6 @@ int FatfsClosedir(struct Dir *dir)
{
FRESULT res;
DIR *dp = NULL;
int ret;
if ((dir == NULL) || (dir->dData == NULL)) {
errno = EBADF;
@@ -926,23 +732,15 @@ int FatfsClosedir(struct Dir *dir)
}
dp = dir->dData;
ret = FsLock();
if (ret != 0) {
errno = ret;
return (int)LOS_NOK;
}
res = f_closedir(dp);
if (res != FR_OK) {
PRINT_ERR("FAT closedir err 0x%x!\r\n", res);
FsUnlock();
errno = FatfsErrno(res);
return (int)LOS_NOK;
}
LOSCFG_FS_FREE_HOOK(dir->dData);
dir->dData = NULL;
FsUnlock();
return (int)LOS_OK;
}
@@ -957,38 +755,26 @@ int FatfsRmdir(struct MountPoint *mp, const char *path)
return (int)LOS_NOK;
}
ret = FsLock();
if (ret != 0) {
errno = ret;
return (int)LOS_NOK;
}
if (!mp->mWriteEnable) {
errno = EACCES;
ret = (int)LOS_NOK;
goto OUT;
return (int)LOS_NOK;
}
ret = FsChangeDrive(path);
if (ret != (int)LOS_OK) {
PRINT_ERR("FAT rmdir ChangeDrive err 0x%x!\r\n", ret);
errno = ENOENT;
ret = (int)LOS_NOK;
goto OUT;
return (int)LOS_NOK;
}
res = f_rmdir(path);
if (res != FR_OK) {
PRINT_ERR("FAT rmdir err 0x%x!\r\n", res);
errno = FatfsErrno(res);
ret = (int)LOS_NOK;
goto OUT;
return (int)LOS_NOK;
}
ret = (int)LOS_OK;
OUT:
FsUnlock();
return ret;
return (int)LOS_OK;
}
int FatfsRename(struct MountPoint *mp, const char *oldName, const char *newName)
@@ -1001,38 +787,26 @@ int FatfsRename(struct MountPoint *mp, const char *oldName, const char *newName)
return (int)LOS_NOK;
}
ret = FsLock();
if (ret != 0) {
errno = ret;
return (int)LOS_NOK;
}
if (!mp->mWriteEnable) {
errno = EACCES;
ret = (int)LOS_NOK;
goto OUT;
return (int)LOS_NOK;
}
ret = FsChangeDrive(oldName);
if (ret != (int)LOS_OK) {
PRINT_ERR("FAT f_getfree ChangeDrive err 0x%x!\r\n", ret);
errno = ENOENT;
ret = (int)LOS_NOK;
goto OUT;
return (int)LOS_NOK;
}
res = f_rename(oldName, newName);
if (res != FR_OK) {
PRINT_ERR("FAT frename err 0x%x!\r\n", res);
errno = FatfsErrno(res);
ret = (int)LOS_NOK;
goto OUT;
return (int)LOS_NOK;
}
ret = (int)LOS_OK;
OUT:
FsUnlock();
return ret;
return (int)LOS_OK;
}
int FatfsStatfs(const char *path, struct statfs *buf)
@@ -1047,26 +821,18 @@ int FatfsStatfs(const char *path, struct statfs *buf)
return (int)LOS_NOK;
}
ret = FsLock();
if (ret != 0) {
errno = ret;
return (int)LOS_NOK;
}
ret = FsChangeDrive(path);
if (ret != FR_OK) {
PRINT_ERR("FAT f_getfree ChangeDrive err %d.", ret);
errno = FatfsErrno(FR_INVALID_PARAMETER);
ret = (int)LOS_NOK;
goto OUT;
return (int)LOS_NOK;
}
res = f_getfree(path, &freeClust, &fs);
if (res != FR_OK) {
PRINT_ERR("FAT f_getfree err 0x%x.", res);
errno = FatfsErrno(res);
ret = (int)LOS_NOK;
goto OUT;
return (int)LOS_NOK;
}
buf->f_bfree = freeClust;
buf->f_bavail = freeClust;
@@ -1078,11 +844,7 @@ int FatfsStatfs(const char *path, struct statfs *buf)
buf->f_bsize = FF_MIN_SS * fs->csize;
#endif
ret = (int)LOS_OK;
OUT:
FsUnlock();
return ret;
return (int)LOS_OK;
}
static int DoTruncate(struct File *file, off_t length, UINT32 count)
@@ -1090,7 +852,6 @@ static int DoTruncate(struct File *file, off_t length, UINT32 count)
FRESULT res = FR_OK;
DWORD csz;
FIL *fp = (FIL *)file->fData;
int ret = (int)LOS_OK;
csz = (DWORD)(fp->obj.fs)->csize * SS(fp->obj.fs); /* Cluster size */
if (length > csz * count) {
@@ -1098,8 +859,7 @@ static int DoTruncate(struct File *file, off_t length, UINT32 count)
res = f_expand(fp, 0, (FSIZE_t)(length), FALLOC_FL_KEEP_SIZE);
#else
errno = ENOSYS;
ret = (int)LOS_NOK;
return ret;
return (int)LOS_NOK;
#endif
} else if (length < csz * count) {
res = f_truncate(fp, (FSIZE_t)length);
@@ -1107,14 +867,13 @@ static int DoTruncate(struct File *file, off_t length, UINT32 count)
if (res != FR_OK) {
errno = FatfsErrno(res);
ret = (int)LOS_NOK;
return ret;
return (int)LOS_NOK;
}
fp->obj.objsize = length; /* Set file size to length */
fp->flag |= 0x40; /* Set modified flag */
return ret;
return (int)LOS_OK;
}
int FatfsTruncate(struct File *file, off_t length)
@@ -1123,49 +882,30 @@ int FatfsTruncate(struct File *file, off_t length)
UINT count;
DWORD fclust;
FIL *fp = (FIL *)file->fData;
int ret;
if ((length < 0) || (length > UINT_MAX)) {
errno = EINVAL;
return (int)LOS_NOK;
}
ret = FsLock();
if (ret != 0) {
errno = ret;
return (int)LOS_NOK;
}
if ((fp == NULL) || (fp->obj.fs == NULL)) {
errno = ENOENT;
ret = (int)LOS_NOK;
goto OUT;
return (int)LOS_NOK;
}
res = f_getclustinfo(fp, &fclust, &count);
if (res != FR_OK) {
errno = FatfsErrno(res);
ret = (int)LOS_NOK;
goto OUT;
return (int)LOS_NOK;
}
ret = DoTruncate(file, length, count);
if (ret != FR_OK) {
goto OUT;
}
ret = (int)LOS_OK;
OUT:
FsUnlock();
return ret;
return DoTruncate(file, length, count);
}
int FatfsFdisk(const char *dev, int *partTbl, int arrayNum)
{
int pdrv;
FRESULT res;
int ret;
if ((dev == NULL) || (partTbl == NULL)) {
errno = EFAULT;
@@ -1178,25 +918,13 @@ int FatfsFdisk(const char *dev, int *partTbl, int arrayNum)
return (int)LOS_NOK;
}
ret = FsLock();
if (ret != 0) {
errno = ret;
ret = (int)LOS_NOK;
goto OUT;
}
res = f_fdisk(pdrv, (DWORD const *)partTbl, g_workBuffer);
if (res != FR_OK) {
errno = FatfsErrno(res);
ret = (int)LOS_NOK;
goto OUT;
return (int)LOS_NOK;
}
ret = (int)LOS_OK;
OUT:
FsUnlock();
return ret;
return (int)LOS_OK;
}
int FatfsFormat(const char *partName, void *privData)
@@ -1205,7 +933,6 @@ int FatfsFormat(const char *partName, void *privData)
MKFS_PARM opt = {0};
int option = *(int *)privData;
char *dev = NULL; /* logical driver */
int ret;
if (partName == NULL) {
errno = EFAULT;
@@ -1218,29 +945,17 @@ int FatfsFormat(const char *partName, void *privData)
return (int)LOS_NOK;
}
ret = FsLock();
if (ret != 0) {
errno = ret;
PutLdPath(dev);
return (int)LOS_NOK;
}
opt.fmt = option;
opt.n_sect = 0; /* use default allocation unit size depends on the volume
size. */
res = f_mkfs(dev, &opt, g_workBuffer, FF_MAX_SS);
if (res != FR_OK) {
errno = FatfsErrno(res);
ret = (int)LOS_NOK;
goto OUT;
PutLdPath(dev);
return (int)LOS_NOK;
}
ret = (int)LOS_OK;
OUT:
PutLdPath(dev);
FsUnlock();
return ret;
return (int)LOS_OK;
}
static struct MountOps g_fatfsMnt = {

View File

@@ -41,8 +41,6 @@
#include "securec.h"
#include "los_fs.h"
static pthread_mutex_t g_fsLocalMutex = PTHREAD_MUTEX_INITIALIZER;
static struct PartitionCfg g_partitionCfg;
static struct DeviceDesc *g_lfsDevice = NULL;
@@ -378,7 +376,6 @@ int LfsReaddir(struct Dir *dir, struct dirent *dent)
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;
@@ -387,7 +384,6 @@ int LfsReaddir(struct Dir *dir, struct dirent *dent)
}
dent->d_reclen = lfsInfo.size;
pthread_mutex_unlock(&g_fsLocalMutex);
return LOS_OK;
}
@@ -567,10 +563,7 @@ int LfsClose(struct File *file)
return (int)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 = (int)LOS_NOK;

View File

@@ -34,3 +34,19 @@ config FS_VFS
help
Answer Y to enable LiteOS support VFS.
if FS_VFS
config FS_LOCK_TIMEOUT
int "Filesystem global lock timeout value in tick. -1 for waiting forever"
default -1
help
The timeout value of getting filesystem lock in tick. -1 for waiting forever
config FS_SUPPORT_MOUNT_TARGET_RECURSIVE
bool "Mount target can be recursive"
default n
depends on FS_VFS
help
Answer Y to enable LiteOS support VFS mount recursively. For example, "/system/bin".
endif

View File

@@ -139,6 +139,17 @@ int LOS_PartitionFormat(const char *partName, char *fsType, void *data);
int LOS_FsRegister(const char *fsType, const struct MountOps *fsMops,
const struct FileOps *fsFops, const struct FsManagement *fsMgt);
/*
* @brief Lock the whole filesystem to forbid filesystem access.
*
* @return Return LOS_NOK if error. Return LOS_OK if seccess.
*/
int LOS_FsLock(void);
/*
* @brief Unlock the whole filesystem to allow filesystem access.
*/
void LOS_FsUnlock(void);
#ifdef __cplusplus
#if __cplusplus

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022-2022 Huawei Device Co., Ltd. All rights reserved.
* Copyright (c) 2022-2023 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:
@@ -34,6 +34,7 @@
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stdbool.h>
#include <unistd.h>
#include <sys/uio.h>
#include "errno.h"
@@ -49,14 +50,6 @@
#include "vfs_mount.h"
#include "vfs_operations.h"
#if (LOSCFG_LIBC_NEWLIB == 1)
#define ALIAS_OF(of) __attribute__((alias(#of)))
#define FUNC_ALIAS(real_func, new_alias, args_list, return_type) \
return_type new_alias args_list ALIAS_OF(real_func)
#else
#define FUNC_ALIAS(real_func, new_alias, args_list, return_type)
#endif
#ifdef LOSCFG_NET_LWIP_SACK
#include "lwipopts.h"
#include "lwip/sockets.h"
@@ -100,20 +93,20 @@ int PollQueryFd(int fd, struct PollTable *table)
UINT32 g_fsMutex;
static UINT32 g_dirNum = 0;
int VfsLock(void)
int LOS_FsLock(void)
{
if (!OsCheckKernelRunning()) {
return LOS_OK;
}
if (LOS_MuxPend(g_fsMutex, LOS_WAIT_FOREVER) != LOS_OK) {
PRINT_ERR("VfsLock failed!");
if (LOS_MuxPend(g_fsMutex, (UINT32)LOSCFG_FS_LOCK_TIMEOUT) != LOS_OK) {
PRINT_ERR("LOS_FsLock failed!");
return (int)LOS_NOK;
}
return LOS_OK;
}
void VfsUnlock(void)
void LOS_FsUnlock(void)
{
if (!OsCheckKernelRunning()) {
return;
@@ -211,6 +204,28 @@ static size_t GetCanonicalPath(const char *cwd, const char *path, char *buf, siz
}
#endif
static int VfsPathCheck(const char *path, bool isFile)
{
size_t len;
if ((path == NULL) || (path[0] == '\0')) {
VFS_ERRNO_SET(EINVAL);
return (int)LOS_NOK;
}
len = strlen(path);
if (len >= PATH_MAX) {
VFS_ERRNO_SET(ENAMETOOLONG);
return (int)LOS_NOK;
}
if (isFile && path[len - 1] == '/') {
VFS_ERRNO_SET(EINVAL);
return (int)LOS_NOK;
}
return LOS_OK;
}
static int VfsOpen(const char *path, int flags)
{
size_t len;
@@ -219,12 +234,11 @@ static int VfsOpen(const char *path, int flags)
const char *pathInMp = NULL;
struct MountPoint *mp = NULL;
if ((path == NULL) || (path[strlen(path) - 1] == '/')) {
VFS_ERRNO_SET(EINVAL);
if (VfsPathCheck(path, TRUE) != LOS_OK) {
return fd;
}
if (VfsLock() != LOS_OK) {
if (LOS_FsLock() != LOS_OK) {
VFS_ERRNO_SET(EAGAIN);
return fd;
}
@@ -234,7 +248,7 @@ static int VfsOpen(const char *path, int flags)
(mp->mFs->fsFops == NULL) || (mp->mFs->fsFops->open == NULL)) {
/* path is not in any mountpoint */
VFS_ERRNO_SET(ENOENT);
VfsUnlock();
LOS_FsUnlock();
return fd;
}
@@ -242,14 +256,14 @@ static int VfsOpen(const char *path, int flags)
(flags & (O_CREAT | O_WRONLY | O_RDWR))) {
/* can't create file in read only mp */
VFS_ERRNO_SET(EACCES);
VfsUnlock();
LOS_FsUnlock();
return fd;
}
file = VfsFileGet();
if (file == NULL) {
VFS_ERRNO_SET(ENFILE);
VfsUnlock();
LOS_FsUnlock();
return fd;
}
@@ -258,7 +272,7 @@ static int VfsOpen(const char *path, int flags)
if (file->fullPath == NULL) {
VFS_ERRNO_SET(ENOMEM);
VfsFilePut(file);
VfsUnlock();
LOS_FsUnlock();
return (int)LOS_NOK;
}
(void)strcpy_s((char *)file->fullPath, len, path);
@@ -279,7 +293,7 @@ static int VfsOpen(const char *path, int flags)
VfsFilePut(file);
}
VfsUnlock();
LOS_FsUnlock();
return fd;
}
@@ -294,7 +308,7 @@ static struct File *VfsAttachFile(int fd, UINT32 status)
return NULL;
}
if (VfsLock() != LOS_OK) {
if (LOS_FsLock() != LOS_OK) {
VFS_ERRNO_SET(EFAULT);
return NULL;
}
@@ -302,13 +316,13 @@ static struct File *VfsAttachFile(int fd, UINT32 status)
file = FdToFile(fd);
if ((file == NULL) || (file->fMp == NULL)) {
VFS_ERRNO_SET(EBADF);
VfsUnlock();
LOS_FsUnlock();
return NULL;
}
if (file->fStatus != FILE_STATUS_READY) {
VFS_ERRNO_SET(EBADF);
VfsUnlock();
LOS_FsUnlock();
return NULL;
}
@@ -329,7 +343,7 @@ static struct File *VfsAttachFileWithStatus(int fd, int status)
static void VfsDetachFile(const struct File *file)
{
(void)file;
VfsUnlock();
LOS_FsUnlock();
}
static int VfsClose(int fd)
@@ -539,7 +553,7 @@ int open(const char *path, int flags, ...)
#endif
int ret = VfsOpen(path, flags);
return MapToPosixRet(ret);
return MapToPosixRet(ret);
}
FUNC_ALIAS(open, _open, (const char *path, int flags, ...), int);
@@ -608,7 +622,7 @@ ssize_t read(int fd, void *buff, size_t bytes)
ret = VfsRead(fd, buff, bytes);
}
return MapToPosixRet(ret);
return MapToPosixRet(ret);
}
FUNC_ALIAS(read, _read, (int fd, void *buff, size_t bytes), ssize_t);
@@ -669,12 +683,16 @@ int stat(const char *path, struct stat *stat)
const char *pathInMp = NULL;
int ret = (int)LOS_NOK;
if ((path == NULL) || (stat == NULL)) {
if (VfsPathCheck(path, FALSE) != LOS_OK) {
return MapToPosixRet(ret);
}
if (stat == NULL) {
VFS_ERRNO_SET(EINVAL);
return MapToPosixRet(ret);
}
if (VfsLock() != LOS_OK) {
if (LOS_FsLock() != LOS_OK) {
VFS_ERRNO_SET(EAGAIN);
return MapToPosixRet(ret);
}
@@ -682,7 +700,7 @@ int stat(const char *path, struct stat *stat)
mp = VfsMpFind(path, &pathInMp);
if ((mp == NULL) || (pathInMp == NULL) || (*pathInMp == '\0')) {
VFS_ERRNO_SET(ENOENT);
VfsUnlock();
LOS_FsUnlock();
return MapToPosixRet(ret);
}
@@ -692,7 +710,7 @@ int stat(const char *path, struct stat *stat)
VFS_ERRNO_SET(ENOTSUP);
}
VfsUnlock();
LOS_FsUnlock();
return MapToPosixRet(ret);
}
FUNC_ALIAS(stat, _stat, (const char *path, struct stat *stat), int);
@@ -703,12 +721,16 @@ int statfs(const char *path, struct statfs *buf)
const char *pathInMp = NULL;
int ret = (int)LOS_NOK;
if ((path == NULL) || (buf == NULL)) {
if (VfsPathCheck(path, FALSE) != LOS_OK) {
return MapToPosixRet(ret);
}
if (buf == NULL) {
VFS_ERRNO_SET(EINVAL);
return MapToPosixRet(ret);
}
if (VfsLock() != LOS_OK) {
if (LOS_FsLock() != LOS_OK) {
VFS_ERRNO_SET(EAGAIN);
return MapToPosixRet(ret);
}
@@ -716,17 +738,17 @@ int statfs(const char *path, struct statfs *buf)
mp = VfsMpFind(path, &pathInMp);
if ((mp == NULL) || (pathInMp == NULL) || (*pathInMp == '\0')) {
VFS_ERRNO_SET(ENOENT);
VfsUnlock();
LOS_FsUnlock();
return MapToPosixRet(ret);
}
if (mp->mFs->fsFops->stat != NULL) {
if (mp->mFs->fsMops->statfs != NULL) {
ret = mp->mFs->fsMops->statfs(pathInMp, buf);
} else {
VFS_ERRNO_SET(ENOTSUP);
}
VfsUnlock();
LOS_FsUnlock();
return MapToPosixRet(ret);
}
@@ -736,12 +758,11 @@ int unlink(const char *path)
const char *pathInMp = NULL;
int ret = (int)LOS_NOK;
if (path == NULL) {
VFS_ERRNO_SET(EINVAL);
if (VfsPathCheck(path, FALSE) != LOS_OK) {
return MapToPosixRet(ret);
}
if (VfsLock() != LOS_OK) {
if (LOS_FsLock() != LOS_OK) {
VFS_ERRNO_SET(EAGAIN);
return MapToPosixRet(ret);
}
@@ -750,13 +771,13 @@ int unlink(const char *path)
if ((mp == NULL) || (pathInMp == NULL) || (*pathInMp == '\0') ||
(mp->mFs->fsFops->unlink == NULL)) {
VFS_ERRNO_SET(ENOENT);
VfsUnlock();
LOS_FsUnlock();
return MapToPosixRet(ret);
}
ret = mp->mFs->fsFops->unlink(mp, pathInMp);
VfsUnlock();
LOS_FsUnlock();
return MapToPosixRet(ret);
}
FUNC_ALIAS(unlink, _unlink, (const char *path), int);
@@ -769,12 +790,14 @@ int rename(const char *oldpath, const char *newpath)
const char *pathInMpNew = NULL;
int ret = (int)LOS_NOK;
if ((oldpath == NULL) || (newpath == NULL)) {
VFS_ERRNO_SET(EINVAL);
if (VfsPathCheck(oldpath, FALSE) != LOS_OK) {
return MapToPosixRet(ret);
}
if (VfsPathCheck(newpath, FALSE) != LOS_OK) {
return MapToPosixRet(ret);
}
if (VfsLock() != LOS_OK) {
if (LOS_FsLock() != LOS_OK) {
VFS_ERRNO_SET(EAGAIN);
return MapToPosixRet(ret);
}
@@ -783,27 +806,27 @@ int rename(const char *oldpath, const char *newpath)
if (pathInMpOld == NULL) {
VFS_ERRNO_SET(EINVAL);
VfsUnlock();
LOS_FsUnlock();
return MapToPosixRet(ret);
}
if ((mpOld == NULL) || (*pathInMpOld == '\0') ||
(mpOld->mFs->fsFops->unlink == NULL)) {
VFS_ERRNO_SET(EINVAL);
VfsUnlock();
LOS_FsUnlock();
return MapToPosixRet(ret);
}
mpNew = VfsMpFind(newpath, &pathInMpNew);
if ((mpNew == NULL) || (pathInMpNew == NULL) || (*pathInMpNew == '\0') || (mpNew->mFs->fsFops->unlink == NULL)) {
VFS_ERRNO_SET(EINVAL);
VfsUnlock();
LOS_FsUnlock();
return MapToPosixRet(ret);
}
if (mpOld != mpNew) {
VFS_ERRNO_SET(EXDEV);
VfsUnlock();
LOS_FsUnlock();
return MapToPosixRet(ret);
}
@@ -813,7 +836,7 @@ int rename(const char *oldpath, const char *newpath)
VFS_ERRNO_SET(ENOTSUP);
}
VfsUnlock();
LOS_FsUnlock();
return MapToPosixRet(ret);
}
@@ -850,8 +873,7 @@ DIR *opendir(const char *path)
struct Dir *dir = NULL;
UINT32 ret;
if (path == NULL) {
VFS_ERRNO_SET(EINVAL);
if (VfsPathCheck(path, FALSE) != LOS_OK) {
return NULL;
}
@@ -861,7 +883,7 @@ DIR *opendir(const char *path)
return NULL;
}
if (VfsLock() != LOS_OK) {
if (LOS_FsLock() != LOS_OK) {
VFS_ERRNO_SET(EAGAIN);
LOSCFG_FS_FREE_HOOK(dir);
return NULL;
@@ -869,7 +891,7 @@ DIR *opendir(const char *path)
if (g_dirNum >= LOSCFG_MAX_OPEN_DIRS) {
VFS_ERRNO_SET(ENFILE);
VfsUnlock();
LOS_FsUnlock();
LOSCFG_FS_FREE_HOOK(dir);
return NULL;
}
@@ -877,14 +899,14 @@ DIR *opendir(const char *path)
mp = VfsMpFind(path, &pathInMp);
if ((mp == NULL) || (pathInMp == NULL)) {
VFS_ERRNO_SET(ENOENT);
VfsUnlock();
LOS_FsUnlock();
LOSCFG_FS_FREE_HOOK(dir);
return NULL;
}
if (mp->mFs->fsFops->opendir == NULL) {
VFS_ERRNO_SET(ENOTSUP);
VfsUnlock();
LOS_FsUnlock();
LOSCFG_FS_FREE_HOOK(dir);
return NULL;
}
@@ -901,7 +923,7 @@ DIR *opendir(const char *path)
dir = NULL;
}
VfsUnlock();
LOS_FsUnlock();
return (DIR *)dir;
}
@@ -915,7 +937,7 @@ struct dirent *readdir(DIR *dir)
return NULL;
}
if (VfsLock() != LOS_OK) {
if (LOS_FsLock() != LOS_OK) {
VFS_ERRNO_SET(EAGAIN);
return NULL;
}
@@ -929,7 +951,7 @@ struct dirent *readdir(DIR *dir)
VFS_ERRNO_SET(ENOTSUP);
}
VfsUnlock();
LOS_FsUnlock();
return ret;
}
@@ -947,7 +969,7 @@ int closedir(DIR *dir)
mp = d->dMp;
if (VfsLock() != LOS_OK) {
if (LOS_FsLock() != LOS_OK) {
VFS_ERRNO_SET(EAGAIN);
return MapToPosixRet(ret);
}
@@ -966,7 +988,7 @@ int closedir(DIR *dir)
VFS_ERRNO_SET(EBADF);
}
VfsUnlock();
LOS_FsUnlock();
LOSCFG_FS_FREE_HOOK(d);
d = NULL;
return MapToPosixRet(ret);
@@ -979,12 +1001,11 @@ int mkdir(const char *path, mode_t mode)
int ret = (int)LOS_NOK;
(void)mode;
if (path == NULL) {
VFS_ERRNO_SET(EINVAL);
if (VfsPathCheck(path, FALSE) != LOS_OK) {
return MapToPosixRet(ret);
}
if (VfsLock() != LOS_OK) {
if (LOS_FsLock() != LOS_OK) {
VFS_ERRNO_SET(EAGAIN);
return MapToPosixRet(ret);
}
@@ -992,7 +1013,7 @@ int mkdir(const char *path, mode_t mode)
mp = VfsMpFind(path, &pathInMp);
if ((mp == NULL) || (pathInMp == NULL) || (*pathInMp == '\0')) {
VFS_ERRNO_SET(ENOENT);
VfsUnlock();
LOS_FsUnlock();
return MapToPosixRet(ret);
}
@@ -1002,7 +1023,7 @@ int mkdir(const char *path, mode_t mode)
VFS_ERRNO_SET(ENOTSUP);
}
VfsUnlock();
LOS_FsUnlock();
return MapToPosixRet(ret);
}
@@ -1017,7 +1038,7 @@ int rmdir(const char *path)
return MapToPosixRet(ret);
}
if (VfsLock() != LOS_OK) {
if (LOS_FsLock() != LOS_OK) {
VFS_ERRNO_SET(EAGAIN);
return MapToPosixRet(ret);
}
@@ -1026,13 +1047,13 @@ int rmdir(const char *path)
if ((mp == NULL) || (pathInMp == NULL) || (*pathInMp == '\0') ||
(mp->mFs->fsFops->rmdir == NULL)) {
VFS_ERRNO_SET(ENOENT);
VfsUnlock();
LOS_FsUnlock();
return MapToPosixRet(ret);
}
ret = mp->mFs->fsFops->rmdir(mp, pathInMp);
VfsUnlock();
LOS_FsUnlock();
return MapToPosixRet(ret);
}
@@ -1064,7 +1085,7 @@ int fcntl(int fd, int cmd, ...)
va_start(ap, cmd);
if (fd < CONFIG_NFILE_DESCRIPTORS) {
filep = VfsAttachFileReady(fd);
ret = VfsVfcntl(filep, cmd, ap);
ret = VfsVfcntl(filep, cmd, ap);
VfsDetachFile(filep);
} else {
#ifndef LOSCFG_NET_LWIP_SACK
@@ -1312,31 +1333,31 @@ ssize_t pread(int fd, void *buff, size_t bytes, off_t off)
return 0;
}
if (VfsLock() != LOS_OK) {
if (LOS_FsLock() != LOS_OK) {
VFS_ERRNO_SET(EAGAIN);
return MapToPosixRet((int)ret);
}
savepos = lseek(fd, 0, SEEK_CUR);
if (savepos == (off_t)-1) {
VfsUnlock();
LOS_FsUnlock();
return MapToPosixRet((int)ret);
}
pos = lseek(fd, off, SEEK_SET);
if (pos == (off_t)-1) {
VfsUnlock();
LOS_FsUnlock();
return MapToPosixRet((int)ret);
}
ret = read(fd, buff, bytes);
pos = lseek(fd, savepos, SEEK_SET);
if ((pos == (off_t)-1) && (ret >= 0)) {
VfsUnlock();
LOS_FsUnlock();
return MapToPosixRet((int)LOS_NOK);
}
VfsUnlock();
LOS_FsUnlock();
return MapToPosixRet((int)ret);
}
@@ -1359,31 +1380,31 @@ ssize_t pwrite(int fd, const void *buff, size_t bytes, off_t off)
return 0;
}
if (VfsLock() != LOS_OK) {
if (LOS_FsLock() != LOS_OK) {
VFS_ERRNO_SET(EAGAIN);
return MapToPosixRet((int)ret);
}
savepos = lseek(fd, 0, SEEK_CUR);
if (savepos == (off_t)-1) {
VfsUnlock();
LOS_FsUnlock();
return MapToPosixRet((int)ret);
}
pos = lseek(fd, off, SEEK_SET);
if (pos == (off_t)-1) {
VfsUnlock();
LOS_FsUnlock();
return MapToPosixRet((int)ret);
}
ret = write(fd, buff, bytes);
pos = lseek(fd, savepos, SEEK_SET);
if ((pos == (off_t)-1) && (ret >= 0)) {
VfsUnlock();
LOS_FsUnlock();
return MapToPosixRet((int)LOS_NOK);
}
VfsUnlock();
LOS_FsUnlock();
return MapToPosixRet((int)ret);
}

View File

@@ -41,17 +41,17 @@ struct FsMap *VfsFsMapGet(const char *fsType)
{
struct FsMap *curr = g_fsMap;
(void)VfsLock();
(void)LOS_FsLock();
while (curr != NULL) {
if ((curr->fsType != NULL) && (fsType != NULL) &&
(strcmp(curr->fsType, fsType) == 0)) {
(void)VfsUnlock();
LOS_FsUnlock();
return curr;
}
curr = curr->next;
}
VfsUnlock();
LOS_FsUnlock();
return NULL;
}
@@ -86,11 +86,11 @@ int OsFsRegister(const char *fsType, const struct MountOps *fsMops,
newfs->fsMgt = fsMgt;
newfs->fsRefs = 0;
(void)VfsLock();
(void)LOS_FsLock();
newfs->next = g_fsMap;
g_fsMap = newfs;
VfsUnlock();
LOS_FsUnlock();
return LOS_OK;
}

View File

@@ -33,6 +33,7 @@
#include "vfs_config.h"
#include "stdlib.h"
#include "string.h"
#include "limits.h"
#include "errno.h"
#include "securec.h"
#include "vfs_operations.h"
@@ -62,14 +63,13 @@ static void MpDeleteFromList(struct MountPoint *mp)
}
}
#if (LOSCFG_FS_SUPPORT_MOUNT_TARGET_RECURSIVE == 1)
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;
}
@@ -121,29 +121,85 @@ struct MountPoint *VfsMpFind(const char *path, const char **pathInMp)
next:
mp = mp->mNext;
}
return bestMp;
}
#else
struct MountPoint *VfsMpFind(const char *path, const char **pathInMp)
{
struct MountPoint *mp = g_mountPoints;
const char *iPath = path;
const char *mPath = NULL;
const char *target = NULL;
STATIC struct MountPoint *VfsMountPointInit(const char *target, const char *fsType, unsigned long mountflags)
if (pathInMp != NULL) {
*pathInMp = NULL;
}
while (*iPath == '/') {
++iPath;
}
while ((mp != NULL) && (mp->mPath != NULL)) {
mPath = mp->mPath;
target = iPath;
while (*mPath == '/') {
++mPath;
}
while ((*mPath != '\0') && (*mPath != '/') &&
(*target != '\0') && (*target != '/')) {
if (*mPath != *target) {
break;
}
++mPath;
++target;
}
if (((*mPath == '\0') || (*mPath == '/')) &&
((*target == '\0') || (*target == '/'))) {
if (pathInMp != NULL) {
*pathInMp = path;
}
return mp;
}
mp = mp->mNext;
}
return NULL;
}
#endif
STATIC struct MountPoint *VfsMountPointInit(const char *source, const char *target,
const char *fsType, unsigned long mountflags)
{
struct MountPoint *mp = NULL;
const char *pathInMp = NULL;
struct FsMap *mFs = NULL;
size_t ssize = 0;
size_t tsize;
/* find mp by target, to see if it was mounted */
mp = VfsMpFind(target, &pathInMp);
if (mp != NULL && pathInMp != NULL) {
errno = EINVAL;
return NULL;
}
/* Find fsMap coresponding to the fsType */
mFs = VfsFsMapGet(fsType);
if ((mFs == NULL) || (mFs->fsMops == NULL) || (mFs->fsMops->mount == NULL)) {
errno = ENODEV;
return NULL;
}
mp = (struct MountPoint *)LOSCFG_FS_MALLOC_HOOK(sizeof(struct MountPoint));
if (source != NULL) {
ssize = strlen(source) + 1;
}
tsize = strlen(target) + 1;
mp = (struct MountPoint *)LOSCFG_FS_MALLOC_HOOK(sizeof(struct MountPoint) + ssize + tsize);
if (mp == NULL) {
errno = ENOMEM;
return NULL;
}
@@ -152,7 +208,20 @@ STATIC struct MountPoint *VfsMountPointInit(const char *target, const char *fsTy
mp->mRefs = 0;
mp->mWriteEnable = (mountflags & MS_RDONLY) ? FALSE : TRUE;
mp->mFs->fsRefs++;
mp->mNext = g_mountPoints;
if (source != NULL && strcpy_s((char *)mp + sizeof(struct MountPoint), ssize, source) != EOK) {
LOSCFG_FS_FREE_HOOK(mp);
errno = ENOMEM;
return NULL;
}
if (strcpy_s((char *)mp + sizeof(struct MountPoint) + ssize, tsize, target) != EOK) {
LOSCFG_FS_FREE_HOOK(mp);
errno = ENOMEM;
return NULL;
}
mp->mDev = source ? (char *)mp + sizeof(struct MountPoint) : NULL;
mp->mPath = (char *)mp + sizeof(struct MountPoint) + ssize;
return mp;
}
@@ -178,51 +247,47 @@ STATIC int VfsRemount(const char *source, const char *target,
return mp->mFs->fsMops->mount(mp, mountflags, data);
}
STATIC int VfsMountPathCheck(const char *target)
{
/* target must begin with '/', for example /system, /data, etc. */
if ((target == NULL) || (target[0] != '/')) {
errno = EINVAL;
return (int)LOS_NOK;
}
if (strlen(target) >= PATH_MAX) {
errno = ENAMETOOLONG;
return (int)LOS_NOK;
}
return LOS_OK;
}
int mount(const char *source, const char *target,
const char *fsType, unsigned long mountflags,
const void *data)
{
size_t len;
int ret;
struct MountPoint *mp = NULL;
/* target must begin with '/', for example /system, /data, etc. */
if ((target == NULL) || (target[0] != '/')) {
if (VfsMountPathCheck(target) != LOS_OK) {
return (int)LOS_NOK;
}
(void)VfsLock();
(void)LOS_FsLock();
if (mountflags & MS_REMOUNT) {
ret = VfsRemount(source, target, fsType, mountflags, data);
VfsUnlock();
LOS_FsUnlock();
return ret;
}
mp = VfsMountPointInit(target, fsType, mountflags);
mp = VfsMountPointInit(source, target, fsType, mountflags);
if (mp == NULL) {
VfsUnlock();
LOS_FsUnlock();
return (int)LOS_NOK;
}
if (source != NULL) {
len = strlen(source) + 1;
mp->mDev = LOSCFG_FS_MALLOC_HOOK(len);
if (mp->mDev == NULL) {
LOSCFG_FS_FREE_HOOK(mp);
VfsUnlock();
return (int)LOS_NOK;
}
(void)strcpy_s((char *)mp->mDev, len, source);
}
len = strlen(target) + 1;
mp->mPath = LOSCFG_FS_MALLOC_HOOK(len);
if (mp->mPath == NULL) {
goto errout;
}
(void)strcpy_s((char *)mp->mPath, len, target);
ret = mp->mFs->fsMops->mount(mp, mountflags, data);
if (ret != 0) {
/* errno is set */
@@ -230,30 +295,28 @@ int mount(const char *source, const char *target,
goto errout;
}
mp->mNext = g_mountPoints;
g_mountPoints = mp;
VfsUnlock();
LOS_FsUnlock();
return LOS_OK;
errout:
LOSCFG_FS_FREE_HOOK((void *)mp->mPath);
LOSCFG_FS_FREE_HOOK((void *)mp->mDev);
LOSCFG_FS_FREE_HOOK(mp);
VfsUnlock();
LOS_FsUnlock();
return (int)LOS_NOK;
}
int umount(const char *target)
{
struct MountPoint *mp = NULL;
const char *pathInMp = NULL;
int ret = (int)LOS_NOK;
(void)VfsLock();
if (target == NULL) {
(void)LOS_FsLock();
if (VfsMountPathCheck(target) != LOS_OK) {
goto errout;
}
mp = VfsMpFind(target, &pathInMp);
mp = VfsMpFind(target, NULL);
if ((mp == NULL) || (mp->mRefs != 0)) {
goto errout;
}
@@ -272,16 +335,14 @@ int umount(const char *target)
/* delete mp from mount list */
MpDeleteFromList(mp);
mp->mFs->fsRefs--;
LOSCFG_FS_FREE_HOOK((void *)mp->mPath);
LOSCFG_FS_FREE_HOOK((void *)mp->mDev);
LOSCFG_FS_FREE_HOOK(mp);
VfsUnlock();
LOS_FsUnlock();
return LOS_OK;
errout:
PRINT_ERR("umount2 failed, target %s.\n", target);
VfsUnlock();
LOS_FsUnlock();
return (int)LOS_NOK;
}
@@ -303,15 +364,14 @@ static void CloseFdsInMp(const struct MountPoint *mp)
int umount2(const char *target, int flag)
{
struct MountPoint *mp = NULL;
const char *pathInMp = NULL;
int ret = (int)LOS_NOK;
(void)VfsLock();
if (target == NULL) {
(void)LOS_FsLock();
if (VfsMountPathCheck(target) != LOS_OK) {
goto errout;
}
mp = VfsMpFind(target, &pathInMp);
mp = VfsMpFind(target, NULL);
if ((mp == NULL) || (mp->mRefs != 0) ||
(mp->mFs == NULL) || (mp->mFs->fsMops == NULL) ||
(mp->mFs->fsMops->umount2 == NULL)) {
@@ -332,15 +392,13 @@ int umount2(const char *target, int flag)
/* delete mp from mount list */
MpDeleteFromList(mp);
mp->mFs->fsRefs--;
LOSCFG_FS_FREE_HOOK((void *)mp->mPath);
LOSCFG_FS_FREE_HOOK((void *)mp->mDev);
LOSCFG_FS_FREE_HOOK(mp);
VfsUnlock();
LOS_FsUnlock();
return LOS_OK;
errout:
PRINT_ERR("umount2 failed, target %s.\n", target);
VfsUnlock();
LOS_FsUnlock();
return (int)LOS_NOK;
}

View File

@@ -52,8 +52,6 @@ extern "C" {
extern UINT32 g_fsMutex;
int OsVfsInit(void);
int VfsLock(void);
void VfsUnlock(void);
#ifdef __cplusplus
#if __cplusplus

View File

@@ -181,6 +181,7 @@ VOID OsLs(const CHAR *pathname)
d = opendir(path);
if (d == NULL) {
PRINT_ERR("No such directory = %s\n", path);
free(path);
} else {
PRINTK("Directory %s:\n", path);
do {

View File

@@ -1,5 +1,5 @@
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
# Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved.
# Copyright (c) 2020-2023 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:
@@ -39,7 +39,6 @@ kernel_module(module_name) {
"porting/src/network/ntohl.c",
"porting/src/network/ntohs.c",
"porting/src/other_adapt.c",
"porting/src/time.c",
]
configs += [ "$LITEOSTOPDIR:warn_config" ]

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2022 Huawei Device Co., Ltd. All rights reserved.
* Copyright (c) 2021-2023 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:
@@ -35,6 +35,11 @@
#include <unistd.h>
#include <pthread.h>
/*
* fs adapter interface, such as _read, see component/fs
* time adapter interface, such as _gettimeofday, see posix/src/time.c
*/
int _isatty(int file)
{
return (int)(file <= 2); // 2: stderr

View File

@@ -1,54 +0,0 @@
/*
* Copyright (c) 2021-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_tick.h"
#include <time.h>
#include <sys/time.h>
#define SECS_PER_MIN 60
int _gettimeofday(struct timeval *__tp, void *__tzp)
{
struct timespec ts;
struct timezone *tz = (struct timezone *)__tzp;
if (__tp != NULL) {
if (-1 == clock_gettime(CLOCK_REALTIME, &ts)) {
return -1;
}
__tp->tv_sec = ts.tv_sec;
__tp->tv_usec = ts.tv_nsec / OS_SYS_NS_PER_US;
}
if (tz != NULL) {
tz->tz_minuteswest = _timezone / SECS_PER_MIN;
tz->tz_dsttime = 0;
}
return 0;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022-2022 Huawei Device Co., Ltd. All rights reserved.
* Copyright (c) 2022-2023 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:
@@ -50,7 +50,6 @@
/* accumulative time delta from discontinuous modify */
STATIC struct timespec g_accDeltaFromSet;
#ifndef __USE_NEWLIB__
STATIC const UINT16 g_daysInMonth[2][13] = {
/* Normal years. */
{ 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 },
@@ -59,20 +58,18 @@ STATIC const UINT16 g_daysInMonth[2][13] = {
};
STATIC const UINT8 g_montbl[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
#endif
#ifndef __USE_NEWLIB__
#define g_timezone timezone
#if (LOSCFG_LIBC_NEWLIB == 1)
#define TIMEZONE _timezone
#else
#define g_Timezone _timezone
#endif
#define TIMEZONE timezone
/*
* Time zone information, stored in seconds,
* negative values indicate the east of UTC,
* positive values indicate the west of UTC.
*/
long g_timezone = -8 * 60 * 60; // set default to CST(UTC+8)
long TIMEZONE = -8 * 60 * 60; // set default to CST(UTC+8)
#endif
/*
* store register rtc func
@@ -529,7 +526,6 @@ time_t time(time_t *timer)
}
}
#ifndef __USE_NEWLIB__
/*
* Compute the `struct tm' representation of T,
* offset OFFSET seconds east of UTC,
@@ -621,7 +617,7 @@ struct tm *localtime_r(const time_t *timep, struct tm *result)
errno = EFAULT;
return NULL;
}
if (!ConvertSecs2Utc(*timep, -g_timezone, result)) {
if (!ConvertSecs2Utc(*timep, -TIMEZONE, result)) {
errno = EINVAL;
return NULL;
}
@@ -664,7 +660,7 @@ static time_t ConvertUtc2Secs(struct tm *tm)
seconds += (tm->tm_mday - 1) * SECS_PER_DAY;
seconds += tm->tm_hour * SECS_PER_HOUR + tm->tm_min * SECS_PER_MIN + tm->tm_sec;
seconds -= tm->__tm_gmtoff; // sub time zone to get UTC time
seconds += TIMEZONE;
return seconds;
}
@@ -690,7 +686,7 @@ time_t mktime(struct tm *tmptr)
}
timeInSeconds = ConvertUtc2Secs(tmptr);
/* normalize tm_wday and tm_yday */
ConvertSecs2Utc(timeInSeconds, tmptr->__tm_gmtoff, tmptr);
ConvertSecs2Utc(timeInSeconds, -TIMEZONE, tmptr);
return timeInSeconds;
}
@@ -724,19 +720,19 @@ int gettimeofday(struct timeval *tv, void *ptz)
}
if (tz != NULL) {
INT32 timeZone = 0;
if (g_rtcTimeFunc.RtcGetTimezoneHook != NULL) {
g_rtcTimeFunc.RtcGetTimezoneHook(&timeZone);
tz->tz_minuteswest = timezone / SECS_PER_MIN;
INT32 tempTimezone = 0;
g_rtcTimeFunc.RtcGetTimezoneHook(&tempTimezone);
tz->tz_minuteswest = tempTimezone / SECS_PER_MIN;
} else {
tz->tz_minuteswest = g_timezone / SECS_PER_MIN;
tz->tz_minuteswest = TIMEZONE / SECS_PER_MIN;
}
tz->tz_dsttime = 0;
}
return 0;
}
#endif
FUNC_ALIAS(gettimeofday, _gettimeofday, (struct timeval *tv, void *ptz), int);
int settimeofday(const struct timeval *tv, const struct timezone *tz)
{
@@ -755,14 +751,14 @@ int settimeofday(const struct timeval *tv, const struct timezone *tz)
if (tz != NULL) {
if ((tz->tz_minuteswest >= TIME_ZONE_MIN) &&
(tz->tz_minuteswest <= TIME_ZONE_MAX)) {
g_timezone = tz->tz_minuteswest * SECS_PER_MIN;
TIMEZONE = tz->tz_minuteswest * SECS_PER_MIN;
} else {
errno = EINVAL;
return -1;
}
if (g_rtcTimeFunc.RtcSetTimezoneHook != NULL) {
g_rtcTimeFunc.RtcSetTimezoneHook(g_timezone);
g_rtcTimeFunc.RtcSetTimezoneHook(TIMEZONE);
}
}

View File

@@ -352,15 +352,10 @@ LITE_TEST_CASE(CmsisFuncTestSuite, TestCmsis004, Function | MediumTest | Level1)
ret = strcmp(staticBuff, strbuff);
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
ret = osMessageQueueDelete(msgQueueId);
ICUNIT_ASSERT_EQUAL(ret, osOK, ret);
#endif
return LOS_OK;
EXIT:
ret = osMessageQueueDelete(msgQueueId);
ICUNIT_ASSERT_EQUAL(ret, osOK, ret);
#endif
return LOS_OK;
}

View File

@@ -46,7 +46,7 @@ static VOID TaskF01(VOID)
ICUNIT_ASSERT_EQUAL_VOID(g_testAtomicID03, i, g_testAtomicID03);
ICUNIT_ASSERT_EQUAL_VOID(ret, g_testAtomicID03, ret);
LOS_AtomicAdd(&g_testCount, 1);
LOS_AtomicAdd((Atomic *)(&g_testCount), 1);
}
static UINT32 TestCase(VOID)

View File

@@ -33,7 +33,7 @@
#include "osTest.h"
#include "It_los_event.h"
static VOID TaskF01()
static VOID TaskF01(VOID)
{
UINT32 ret;

View File

@@ -47,6 +47,7 @@ static int g_uwIndex;
#else
#define TEST_MAX_NUMBER_HWI (OS_USER_HWI_MAX - HWI_NUM_INT0)
#define TEST_HWI_COUNT (TEST_MAX_NUMBER_HWI - 2)
#undef HWI_NUM_INT0
#define HWI_NUM_INT0 HWI_NUM_INT1
#endif

View File

@@ -43,6 +43,7 @@ static VOID HwiF01(VOID)
return;
}
#undef HWI_NUM_INT0
#define HWI_NUM_INT0 HWI_NUM_TEST1
static UINT32 Testcase(VOID)
{

View File

@@ -33,7 +33,7 @@
#include "los_timer.h"
#include "los_sched.h"
#define myprintf // printf
#define myprintf printf
#define TEST_LOOP 5
static EVENT_CB_S g_pmTestEvent;
static UINT32 g_taskID1, g_taskID2;

View File

@@ -36,6 +36,15 @@ EVENT_CB_S g_eventCB0;
EVENT_CB_S g_eventCB1;
EVENT_CB_S g_eventCB2;
EVENT_CB_S g_eventCB3;
UINT32 g_swtmrId1;
UINT32 g_swtmrId2;
UINT32 g_swtmrId3;
UINT32 g_swtmrCountA;
UINT32 g_swtmrCountB;
UINT32 g_swtmrCountC;
UINT32 g_uwsTick1;
UINT32 g_uwsTick2;
UINT32 g_uwsTick3;
VOID ItSuiteLosSwtmr(void)
{

View File

@@ -56,17 +56,17 @@ extern EVENT_CB_S g_eventCB3;
extern UINT32 g_idleTaskID;
static UINT32 g_swtmrId1;
static UINT32 g_swtmrId2;
static UINT32 g_swtmrId3;
extern UINT32 g_swtmrId1;
extern UINT32 g_swtmrId2;
extern UINT32 g_swtmrId3;
static UINT32 g_swtmrCountA;
static UINT32 g_swtmrCountB;
static UINT32 g_swtmrCountC;
extern UINT32 g_swtmrCountA;
extern UINT32 g_swtmrCountB;
extern UINT32 g_swtmrCountC;
static UINT32 g_uwsTick1;
static UINT32 g_uwsTick2;
static UINT32 g_uwsTick3;
extern UINT32 g_uwsTick1;
extern UINT32 g_uwsTick2;
extern UINT32 g_uwsTick3;
extern VOID LOS_GetCpuTick(UINT32 *puwCntHi, UINT32 *puwCntLo);
extern VOID ItSuiteLosSwtmr(VOID);

View File

@@ -48,7 +48,7 @@ static VOID Case1(UINT32 arg)
return;
}
static VOID Case2()
static VOID Case2(VOID)
{
UINT32 ret;

View File

@@ -44,7 +44,7 @@ static VOID Case1(UINT32 arg)
return;
}
static VOID Case2()
static VOID Case2(VOID)
{
UINT32 ret;
UINT32 uwloop = 1000;

View File

@@ -41,7 +41,7 @@ static VOID Case1(UINT32 arg)
g_testCount = 30;
}
static VOID Case2()
static VOID Case2(VOID)
{
// 10, Here, assert that g_testCount is equal to this .
ICUNIT_ASSERT_EQUAL_VOID(g_testCount, 10, g_testCount);
@@ -49,7 +49,7 @@ static VOID Case2()
g_testCount = 20;
}
static VOID Case3()
static VOID Case3(VOID)
{
// 10, Set the number to determine whether the process is as expected.
g_testCount = 10;

View File

@@ -51,7 +51,7 @@ EXIT:
LOS_TaskDelete(g_testTaskID01);
}
static VOID Case2()
static VOID Case2(VOID)
{
UINT32 ret;

View File

@@ -50,14 +50,14 @@ static VOID Case1(UINT32 arg)
g_testCount = 10;
}
static VOID Case2()
static VOID Case2(VOID)
{
// 20, Here, assert that g_testCount is equal to this .
ICUNIT_ASSERT_EQUAL_VOID(g_testCount, 20, g_testCount);
g_testCount++;
}
static VOID Case3()
static VOID Case3(VOID)
{
UINT32 index;

View File

@@ -33,7 +33,7 @@
#include "It_los_swtmr.h"
static VOID Case1()
static VOID Case1(VOID)
{
UINT32 ret;
@@ -43,7 +43,7 @@ static VOID Case1()
}
}
static VOID Case2()
static VOID Case2(VOID)
{
UINT32 ret;
@@ -53,7 +53,7 @@ static VOID Case2()
}
}
static VOID Case3()
static VOID Case3(VOID)
{
UINT32 ret;
@@ -64,7 +64,7 @@ static VOID Case3()
}
}
VOID Case4()
static VOID Case4(VOID)
{
UINT32 ret;
@@ -77,7 +77,7 @@ VOID Case4()
}
}
VOID Case5()
static VOID Case5(VOID)
{
UINT32 ret;
@@ -90,7 +90,7 @@ VOID Case5()
}
}
VOID Case6()
static VOID Case6(VOID)
{
UINT32 ret;

View File

@@ -41,6 +41,7 @@ mqd_t g_mqueueId[LOSCFG_BASE_IPC_QUEUE_CONFIG + 1];
SEM_HANDLE_T g_mqueueSem;
mqd_t g_messageQId;
mqd_t g_gqueue;
TSK_HANDLE_T g_mqueueTaskPID;
VOID TestAssertWaitDelay(UINT32 *testCount, UINT32 flag)
{

View File

@@ -57,18 +57,19 @@
#define MQUEUE_PRIORITY_TEST 0
#define MQUEUE_TIMEOUT_TEST 7
#define MQUEUE_PRIORITY_NUM_TEST 3
#define MQUEUE_MAX_NUM_TEST (LOSCFG_BASE_IPC_QUEUE_CONFIG - QUEUE_EXISTED_NUM)
#define MQ_MAX_MSG_NUM 16
#define MQ_MAX_MSG_LEN 64
#undef HWI_NUM_TEST
#define HWI_NUM_TEST 1
#undef HWI_NUM_TEST1
#define HWI_NUM_TEST1 2
#if (LOSCFG_LIBC_NEWLIB == 1)
#define MQ_PRIO_MAX 1
#endif
#undef LOSCFG_BASE_IPC_QUEUE_CONFIG
#define LOSCFG_BASE_IPC_QUEUE_CONFIG 1024
#define LOS_AtomicInc(a) (++*(a))
#define MqueueTaskDelay(tick) (usleep((tick) * 10000))
@@ -91,7 +92,7 @@ typedef UINT32 SEM_HANDLE_T ;
extern SEM_HANDLE_T g_mqueueSem;
static TSK_HANDLE_T g_mqueueTaskPID;
extern TSK_HANDLE_T g_mqueueTaskPID;
extern CHAR g_gqname[MQUEUE_STANDARD_NAME_LENGTH];
extern CHAR g_mqueueName[LOSCFG_BASE_IPC_QUEUE_CONFIG + 1][MQUEUE_STANDARD_NAME_LENGTH];
extern mqd_t g_mqueueId[LOSCFG_BASE_IPC_QUEUE_CONFIG + 1];

View File

@@ -34,8 +34,6 @@ static UINT32 Testcase(VOID)
CHAR qname[MQUEUE_STANDARD_NAME_LENGTH] = "";
const CHAR *msgptr = MQUEUE_SEND_STRING_TEST;
mqd_t queue;
INT32 unresolved = 0;
INT32 failure = 0;
INT32 ret = 0;
ret = snprintf_s(qname, MQUEUE_STANDARD_NAME_LENGTH, MQUEUE_STANDARD_NAME_LENGTH - 1, \

View File

@@ -34,8 +34,6 @@ static UINT32 Testcase(VOID)
CHAR mqname[MQUEUE_STANDARD_NAME_LENGTH], msgrv[MQUEUE_STANDARD_NAME_LENGTH];
mqd_t mqdes;
struct mq_attr attr = {0};
INT32 unresolved = 0;
INT32 failure = 0;
INT32 ret = 0;
ret = snprintf_s(mqname, MQUEUE_STANDARD_NAME_LENGTH, MQUEUE_STANDARD_NAME_LENGTH - 1, \

View File

@@ -35,8 +35,6 @@ static UINT32 Testcase(VOID)
mqd_t mqdes;
CHAR msgrv[MQUEUE_STANDARD_NAME_LENGTH];
struct mq_attr attr = {0};
INT32 unresolved = 0;
INT32 failure = 0;
INT32 ret = 0;
ret = snprintf_s(mqname, MQUEUE_STANDARD_NAME_LENGTH, MQUEUE_STANDARD_NAME_LENGTH - 1, \

View File

@@ -34,8 +34,6 @@ static UINT32 Testcase(VOID)
CHAR mqname[MQUEUE_STANDARD_NAME_LENGTH] = "";
mqd_t mqdes;
struct mq_attr mqstat;
INT32 unresolved = 0;
INT32 failure = 0;
INT32 ret = 0;
ret = snprintf_s(mqname, MQUEUE_STANDARD_NAME_LENGTH, MQUEUE_STANDARD_NAME_LENGTH - 1, \

View File

@@ -34,8 +34,6 @@ static UINT32 Testcase(VOID)
CHAR mqname[MQUEUE_STANDARD_NAME_LENGTH] = "";
mqd_t mqdes;
struct mq_attr mqstat, nmqstat;
INT32 unresolved = 0;
INT32 failure = 0;
INT32 ret = 0;
ret = snprintf_s(mqname, MQUEUE_STANDARD_NAME_LENGTH, MQUEUE_STANDARD_NAME_LENGTH - 1, \

View File

@@ -35,8 +35,6 @@ static UINT32 Testcase(VOID)
mqd_t mqdes;
struct mq_attr mqstat = {0};
struct mq_attr nmqstat = {0};
INT32 unresolved = 0;
INT32 failure = 0;
INT32 ret = 0;
ret = snprintf_s(mqname, MQUEUE_STANDARD_NAME_LENGTH, MQUEUE_STANDARD_NAME_LENGTH - 1, \

View File

@@ -38,23 +38,7 @@
#include "semaphore.h"
#include "unistd.h"
#ifdef LOSCFG_DEBUG_DEADLOCK
#define TEST_MUTEX_INIT \
{ \
{ 0, 0, 0, 0 }, \
{ \
{ 0, 0 }, { 0, 0 }, 0, 0 \
} \
}
#else
#define TEST_MUTEX_INIT \
{ \
{ 0, 0, 0, 0 }, \
{ \
{ 0, 0 }, 0, 0 \
} \
}
#endif
#define TEST_MUTEX_INIT {0}
#define MUTEX_TEST_DEFAULT_PRIO LOSCFG_BASE_CORE_TSK_DEFAULT_PRIO
#define MUTEX_TEST_HIGH_PRIO (MUTEX_TEST_DEFAULT_PRIO - 6)

View File

@@ -42,11 +42,6 @@
#include "mqueue.h"
#include "signal.h"
/* Some routines are part of the XSI Extensions */
#ifndef WITHOUT_XOPEN
#define _XOPEN_SOURCE 600
#endif
#define PTHREAD_IS_ERROR (-1)
#define PTHREAD_PRIORITY_TEST 20
#define PTHREAD_DEFAULT_STACK_SIZE (LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE)
@@ -71,9 +66,6 @@
/* We are testing conformance to IEEE Std 1003.1, 2003 Edition */
#define _POSIX_C_SOURCE 200112L
#define PTHREAD_MUTEX_RECURSIVE 0
#define PTHREAD_MUTEX_ERRORCHECK 0
#define PRIORITY_OTHER (-1)
#define PRIORITY_FIFO 20
#define PRIORITY_RR 20

View File

@@ -102,7 +102,7 @@ char *g_strType[] = {
"FUNCTION", "PRESSURE", "PERFORMANCE"
};
iUINT32 ICunitRunF()
iUINT32 ICunitRunF(void)
{
iUINT32 idx, idx1;
ICUNIT_CASE_S *psubCaseArray;

View File

@@ -231,7 +231,7 @@ void TestCmsis2(void)
}
#endif
VOID TestTaskEntry()
VOID TestTaskEntry(VOID)
{
PRINTF("\t\n --- Test Start --- \n\n");
ICunitInit();

View File

@@ -68,7 +68,10 @@ static_library("posix_test") {
sources += [ "src/fs/posix_fs_func_test.c" ]
}
if (!defined(LOSCFG_COMPILER_ICCARM)) {
cflags = [ "-Wno-error" ]
cflags = [
"-Wno-error",
"-Wno-unused-function",
]
} else {
cflags = [ "--no_warnings" ]
}

View File

@@ -1,56 +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 COMMON_TEST_H
#define COMMON_TEST_H
#define TESTCOUNT_NUM_1 1
#define TESTCOUNT_NUM_2 2
#define TESTCOUNT_NUM_3 3
#define TESTCOUNT_NUM_4 4
#define TESTCOUNT_NUM_5 5
#define DELAY_TICKS_1 1
#define DELAY_TICKS_5 5
#define DELAY_TICKS_10 10
#define TEST_TASK_STACK_SIZE 0x600
#define TASK_LOOP_NUM 0x10000000
#define TEST_TIME 10
#define THREAD_COUNT_MIN 3
#define THREAD_COUNT_MAX 30
#define THREAD_STACK_SPACE_MAX 4096
#ifdef __cplusplus
#if __cplusplus
#endif
#endif /* __cplusplus */
#endif

View File

@@ -42,8 +42,6 @@
#define DELAY_TICKS_5 5
#define DELAY_TICKS_10 10
#define TEST_TASK_STACK_SIZE 0x600
#define TASK_LOOP_NUM 0x10000000
#define TEST_TIME 10
#define THREAD_COUNT_MIN 3
#define THREAD_COUNT_MAX 30

View File

@@ -33,7 +33,6 @@
#include "posix_test.h"
#include <mqueue.h>
#include <fcntl.h>
#include "common_test.h"
#include "kernel_test.h"
#include "log.h"

View File

@@ -34,7 +34,6 @@
#include "hctest.h"
#include "los_config.h"
#include "cmsis_os2.h"
#include "common_test.h"
#include "kernel_test.h"
#include "pthread.h"
#include "log.h"

View File

@@ -29,6 +29,7 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#define _GNU_SOURCE
#include <sys/time.h>
#include <sys/times.h>
#include <time.h>
@@ -45,6 +46,7 @@
#define RET_OK 0
#define SECS_PER_MIN 60
#define SLEEP_ACCURACY 21000 // 20 ms, with 1ms deviation
#define ACCURACY_TEST_LOOPS 3 // loops for accuracy test, than count average value
#define MILLISECONDS_PER_SECOND 1000
@@ -125,13 +127,13 @@ static int CheckValueClose(double target, double actual, double accuracy)
return (pct <= accuracy);
}
static char *TmToStr(const struct tm *stm, char *timeStr, unsigned len)
static char *TmToStr(const struct tm *timePtr, char *timeStr, unsigned len)
{
if (stm == NULL || timeStr == NULL) {
if (timePtr == NULL || timeStr == NULL) {
return "";
}
sprintf_s(timeStr, len, "%ld/%d/%d %02d:%02d:%02d WEEK(%d)", stm->tm_year + TM_BASE_YEAR, stm->tm_mon + 1,
stm->tm_mday, stm->tm_hour, stm->tm_min, stm->tm_sec, stm->tm_wday);
sprintf_s(timeStr, len, "%ld/%d/%d %02d:%02d:%02d WEEK(%d)", timePtr->tm_year + TM_BASE_YEAR, timePtr->tm_mon + 1,
timePtr->tm_mday, timePtr->tm_hour, timePtr->tm_min, timePtr->tm_sec, timePtr->tm_wday);
return timeStr;
}
@@ -195,28 +197,28 @@ LITE_TEST_CASE(PosixTimeFuncTestSuite, testTimeGmtime001, Function | MediumTest
time_t time1 = 18880;
char timeStr[TIME_STR_LEN] = {0};
LOG("\nsizeof(time_t) = %d, sizeof(struct tm) = %d", sizeof(time_t), sizeof(struct tm));
struct tm *stm = gmtime(&time1);
TEST_ASSERT_EQUAL_STRING("1970/1/1 05:14:40 WEEK(4)", TmToStr(stm, timeStr, TIME_STR_LEN));
struct tm *timePtr = gmtime(&time1);
TEST_ASSERT_EQUAL_STRING("1970/1/1 05:14:40 WEEK(4)", TmToStr(timePtr, timeStr, TIME_STR_LEN));
time1 = LONG_MAX;
stm = gmtime(&time1);
LOG("\n LONG_MAX = %lld, cvt result : %s", time1, TmToStr(stm, timeStr, TIME_STR_LEN));
TEST_ASSERT_EQUAL_STRING("2038/1/19 03:14:07 WEEK(2)", TmToStr(stm, timeStr, TIME_STR_LEN));
timePtr = gmtime(&time1);
LOG("\n LONG_MAX = %lld, cvt result : %s", time1, TmToStr(timePtr, timeStr, TIME_STR_LEN));
TEST_ASSERT_EQUAL_STRING("2038/1/19 03:14:07 WEEK(2)", TmToStr(timePtr, timeStr, TIME_STR_LEN));
time1 = LONG_MAX - 1;
stm = gmtime(&time1);
LOG("\n LONG_MAX - 1 = %lld, cvt result : %s", time1, TmToStr(stm, timeStr, TIME_STR_LEN));
TEST_ASSERT_EQUAL_STRING("2038/1/19 03:14:06 WEEK(2)", TmToStr(stm, timeStr, TIME_STR_LEN));
timePtr = gmtime(&time1);
LOG("\n LONG_MAX - 1 = %lld, cvt result : %s", time1, TmToStr(timePtr, timeStr, TIME_STR_LEN));
TEST_ASSERT_EQUAL_STRING("2038/1/19 03:14:06 WEEK(2)", TmToStr(timePtr, timeStr, TIME_STR_LEN));
time1 = LONG_MIN;
stm = gmtime(&time1);
LOG("\n LONG_MIN = %lld, cvt result : %s", time1, TmToStr(stm, timeStr, TIME_STR_LEN));
TEST_ASSERT_EQUAL_STRING("1901/12/13 20:45:52 WEEK(5)", TmToStr(stm, timeStr, TIME_STR_LEN));
timePtr = gmtime(&time1);
LOG("\n LONG_MIN = %lld, cvt result : %s", time1, TmToStr(timePtr, timeStr, TIME_STR_LEN));
TEST_ASSERT_EQUAL_STRING("1901/12/13 20:45:52 WEEK(5)", TmToStr(timePtr, timeStr, TIME_STR_LEN));
time1 = LONG_MIN + 1;
stm = gmtime(&time1);
LOG("\n LONG_MIN + 1 = %lld, cvt result : %s", time1, TmToStr(stm, timeStr, TIME_STR_LEN));
TEST_ASSERT_EQUAL_STRING("1901/12/13 20:45:53 WEEK(5)", TmToStr(stm, timeStr, TIME_STR_LEN));
timePtr = gmtime(&time1);
LOG("\n LONG_MIN + 1 = %lld, cvt result : %s", time1, TmToStr(timePtr, timeStr, TIME_STR_LEN));
TEST_ASSERT_EQUAL_STRING("1901/12/13 20:45:53 WEEK(5)", TmToStr(timePtr, timeStr, TIME_STR_LEN));
return 0;
};
@@ -369,38 +371,47 @@ LITE_TEST_CASE(PosixTimeFuncTestSuite, testTimeLocaltimer002, Function | MediumT
*/
LITE_TEST_CASE(PosixTimeFuncTestSuite, testTimeMktime001, Function | MediumTest | Level1)
{
// default time zone east 8
struct tm timeptr = { 0 };
struct tm testTM = { 0 };
time_t testTime = 18880;
char timeStr[TIME_STR_LEN] = {0};
struct timeval tv;
struct timezone tz;
INIT_TM(timeptr, 2020, 7, 9, 18, 10, 0, 7);
time_t timeRet = mktime(&timeptr);
// get system timezone
int ret = gettimeofday(&tv, &tz);
TEST_ASSERT_EQUAL_INT(0, ret);
long sysTimezone = (long)(-tz.tz_minuteswest) * SECS_PER_MIN;
LOG("\n system timezone = %ld\n", sysTimezone);
INIT_TM(testTM, 2020, 7, 9, 18, 10, 0, 7);
time_t timeRet = mktime(&testTM);
LOG("\n 2020-7-9 18:10:00, mktime Ret = %lld", timeRet);
TEST_ASSERT_EQUAL_INT(1596996600, timeRet);
TEST_ASSERT_EQUAL_INT(sysTimezone, testTM.__tm_gmtoff);
TEST_ASSERT_EQUAL_INT(1596996600 - testTM.__tm_gmtoff, timeRet);
INIT_TM(timeptr, 1970, 0, 1, 8, 0, 0, 0);
timeRet = mktime(&timeptr);
INIT_TM(testTM, 1970, 0, 1, 8, 0, 0, 0);
timeRet = mktime(&testTM);
LOG("\n 1970-1-1 08:00:00, mktime Ret = %lld", timeRet);
TEST_ASSERT_EQUAL_INT(28800, timeRet);
TEST_ASSERT_EQUAL_INT(sysTimezone, testTM.__tm_gmtoff);
TEST_ASSERT_EQUAL_INT(28800 - testTM.__tm_gmtoff, timeRet);
struct tm *stm = localtime(&testTime);
LOG("\n testTime 18880, tm : %s", TmToStr(stm, timeStr, TIME_STR_LEN));
timeRet = mktime(stm);
struct tm *timePtr = localtime(&testTime);
LOG("\n testTime 18880, tm : %s", TmToStr(timePtr, timeStr, TIME_STR_LEN));
timeRet = mktime(timePtr);
TEST_ASSERT_EQUAL_INT(18880, timeRet);
LOG("\n input 18880, mktime Ret = %lld", timeRet);
testTime = LONG_MAX;
stm = localtime(&testTime);
LOG("\n testTime LONG_MAX, tm : %s", TmToStr(stm, timeStr, TIME_STR_LEN));
timeRet = mktime(stm);
timePtr = localtime(&testTime);
LOG("\n testTime LONG_MAX, tm : %s", TmToStr(timePtr, timeStr, TIME_STR_LEN));
timeRet = mktime(timePtr);
TEST_ASSERT_EQUAL_INT(LONG_MAX, timeRet);
LOG("\n input LONG_MAX, mktime Ret = %lld", timeRet);
testTime = 0;
stm = localtime(&testTime);
LOG("\n testTime 0, tm : %s", TmToStr(stm, timeStr, TIME_STR_LEN));
timeRet = mktime(stm);
timePtr = localtime(&testTime);
LOG("\n testTime 0, tm : %s", TmToStr(timePtr, timeStr, TIME_STR_LEN));
timeRet = mktime(timePtr);
TEST_ASSERT_EQUAL_INT(0, timeRet);
LOG("\n input 0, mktime Ret = %lld", timeRet);
return 0;
@@ -413,10 +424,10 @@ LITE_TEST_CASE(PosixTimeFuncTestSuite, testTimeMktime001, Function | MediumTest
*/
LITE_TEST_CASE(PosixTimeFuncTestSuite, testTimeMktime002, Function | MediumTest | Level1)
{
struct tm timeptr = { 0 };
struct tm testTM = { 0 };
LOG("\n sizeof(time_t) = %d", sizeof(time_t));
INIT_TM(timeptr, 1969, 7, 9, 10, 10, 0, 7);
time_t timeRet = mktime(&timeptr);
INIT_TM(testTM, 1969, 7, 9, 10, 10, 0, 7);
time_t timeRet = mktime(&testTM);
LOG("\n 1800-8-9 10:10:00, mktime Ret lld = %lld", timeRet);
#if (LOSCFG_LIBC_MUSL == 1)
TEST_ASSERT_EQUAL_INT(-1, timeRet);

View File

@@ -1,6 +1,6 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved.
* Copyright (c) 2020-2023 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:
@@ -525,8 +525,17 @@ static inline UINT64 __atomic_exchange_8(volatile void *mem, UINT64 val, int mod
free_lock (memP, model);
return ret;
}
#endif
#endif
#endif /* __XTENSA_LX6__ */
#define ALIAS_OF(of) __attribute__((alias(#of)))
#define FUNC_ALIAS(real_func, new_alias, args_list, return_type) \
return_type new_alias args_list ALIAS_OF(real_func)
#else
#define FUNC_ALIAS(real_func, new_alias, args_list, return_type)
#endif /* __GNUC__ */
#ifdef __cplusplus
#if __cplusplus