Compare commits
28 Commits
weekly_202
...
weekly_202
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1ae62ebf2e | ||
|
|
25278a02eb | ||
|
|
733b6e6c6c | ||
|
|
6562536db7 | ||
|
|
ddf3dc8237 | ||
|
|
399e7647bb | ||
|
|
f7af2cdf9b | ||
|
|
07091c5a75 | ||
|
|
6633aabf89 | ||
|
|
2a4282f912 | ||
|
|
685688b21c | ||
|
|
67ee38e1e3 | ||
|
|
6cd48f6f90 | ||
|
|
662aefb700 | ||
|
|
83fc93cc84 | ||
|
|
b817c490ba | ||
|
|
705e4c323a | ||
|
|
b7f906ef8a | ||
|
|
f9c59d361f | ||
|
|
fa142daffb | ||
|
|
4bd0e73512 | ||
|
|
0a03a4d875 | ||
|
|
2a70466456 | ||
|
|
b30349d8ed | ||
|
|
59ecf4cae8 | ||
|
|
9038b6522e | ||
|
|
abb83fd23b | ||
|
|
98da8bbdfb |
3
BUILD.gn
3
BUILD.gn
@@ -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)) {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -32,7 +32,6 @@ config FS_FAT
|
||||
default n
|
||||
depends on FS_VFS
|
||||
select SUPPORT_FATFS
|
||||
select KAL_CMSIS
|
||||
help
|
||||
Answer Y to enable LiteOS support fat filesystem.
|
||||
|
||||
|
||||
@@ -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 = {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -30,6 +30,23 @@
|
||||
config FS_VFS
|
||||
bool "Enable FS VFS"
|
||||
default y
|
||||
select POSIX_FS_API
|
||||
|
||||
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
|
||||
|
||||
@@ -62,41 +62,6 @@ extern "C" {
|
||||
#define LOSCFG_FS_FREE_HOOK(ptr) LOS_MemFree((VOID *)OS_SYS_MEM_ADDR, ptr)
|
||||
#endif
|
||||
|
||||
int LOS_Open(const char *path, int flags, ...);
|
||||
int LOS_Close(int fd);
|
||||
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_FsUmount(const char *target);
|
||||
int LOS_FsUmount2(const char *target, int flag);
|
||||
int LOS_FsMount(const char *source, const char *target,
|
||||
const char *fsType, unsigned long mountflags,
|
||||
const void *data);
|
||||
|
||||
int OsFcntl(int fd, int cmd, va_list ap);
|
||||
int OsIoctl(int fd, int req, va_list ap);
|
||||
|
||||
struct PartitionCfg {
|
||||
/* partition low-level read func */
|
||||
int (*readFunc)(int partition, UINT32 *offset, void *buf, UINT32 size);
|
||||
@@ -174,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
|
||||
|
||||
@@ -59,7 +59,7 @@
|
||||
#define CONFIG_NFILE_DESCRIPTORS 256
|
||||
#endif
|
||||
|
||||
#define NR_OPEN_DEFAULT CONFIG_NFILE_DESCRIPTORS
|
||||
#define NR_OPEN_DEFAULT (CONFIG_NFILE_DESCRIPTORS - MIN_START_FD)
|
||||
|
||||
/* time configure */
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
int LOS_FsMount(const char *source, const char *target,
|
||||
STATIC int VfsMountPathCheck(const char *target)
|
||||
{
|
||||
/* target must begin with '/', for example /system, /data, etc. */
|
||||
if ((target == NULL) || (target[0] != '/') || (target[0] == '\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 LOS_FsMount(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 LOS_FsUmount(const char *target)
|
||||
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 LOS_FsUmount(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;
|
||||
}
|
||||
|
||||
@@ -300,18 +361,17 @@ static void CloseFdsInMp(const struct MountPoint *mp)
|
||||
}
|
||||
}
|
||||
|
||||
int LOS_FsUmount2(const char *target, int flag)
|
||||
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 LOS_FsUmount2(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;
|
||||
}
|
||||
|
||||
@@ -52,8 +52,6 @@ extern "C" {
|
||||
extern UINT32 g_fsMutex;
|
||||
|
||||
int OsVfsInit(void);
|
||||
int VfsLock(void);
|
||||
void VfsUnlock(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
|
||||
@@ -35,7 +35,6 @@ choice
|
||||
|
||||
config LIBC_MUSL
|
||||
bool "musl libc"
|
||||
rsource "musl/Kconfig"
|
||||
|
||||
config LIBC_NEWLIB
|
||||
bool "newlibc"
|
||||
|
||||
@@ -28,13 +28,6 @@
|
||||
|
||||
if LIBC_ICCARM
|
||||
|
||||
config LIBC_ICCARM_FS
|
||||
bool "Enable POSIX file system API support"
|
||||
default y
|
||||
depends on FS_VFS
|
||||
help
|
||||
This enables POSIX style file system related APIs.
|
||||
|
||||
config LIBC_ICCARM_MALLOC
|
||||
bool "Enable POSIX malloc/free API support"
|
||||
default y
|
||||
|
||||
@@ -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:
|
||||
@@ -33,10 +33,7 @@ import("//third_party/musl/porting/liteos_m/kernel/musl.gni")
|
||||
module_switch = defined(LOSCFG_LIBC_MUSL)
|
||||
module_name = get_path_info(rebase_path("."), "name")
|
||||
kernel_module(module_name) {
|
||||
sources = [
|
||||
"fs.c",
|
||||
"malloc.c",
|
||||
]
|
||||
sources = [ "malloc.c" ]
|
||||
configs += [ "$LITEOSTOPDIR:warn_config" ]
|
||||
|
||||
deps = [ "//third_party/musl/porting/liteos_m/kernel" ]
|
||||
|
||||
@@ -1,39 +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.
|
||||
|
||||
if LIBC_MUSL
|
||||
|
||||
config LIBC_MUSL_FS
|
||||
bool "Enable POSIX file system API support"
|
||||
default y
|
||||
depends on FS_VFS
|
||||
help
|
||||
This enables POSIX style file system related APIs.
|
||||
|
||||
endif # LIBC_MUSL
|
||||
@@ -1,329 +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
|
||||
|
||||
#include "los_config.h"
|
||||
#include <errno.h>
|
||||
#include <stdarg.h>
|
||||
#include <dirent.h>
|
||||
#include <sys/mount.h>
|
||||
#include <sys/statfs.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#ifdef LOSCFG_LIBC_MUSL_FS
|
||||
#include "los_fs.h"
|
||||
|
||||
int mount(const char *source, const char *target,
|
||||
const char *filesystemtype, unsigned long mountflags,
|
||||
const void *data)
|
||||
{
|
||||
return LOS_FsMount(source, target, filesystemtype, mountflags, data);
|
||||
}
|
||||
|
||||
int umount(const char *target)
|
||||
{
|
||||
return LOS_FsUmount(target);
|
||||
}
|
||||
|
||||
int umount2(const char *target, int flag)
|
||||
{
|
||||
return LOS_FsUmount2(target, flag);
|
||||
}
|
||||
|
||||
int open(const char *path, int oflag, ...)
|
||||
{
|
||||
va_list vaList;
|
||||
va_start(vaList, oflag);
|
||||
int ret;
|
||||
ret = LOS_Open(path, oflag, vaList);
|
||||
va_end(vaList);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int close(int fd)
|
||||
{
|
||||
return LOS_Close(fd);
|
||||
}
|
||||
|
||||
ssize_t read(int fd, void *buf, size_t nbyte)
|
||||
{
|
||||
return LOS_Read(fd, buf, nbyte);
|
||||
}
|
||||
|
||||
ssize_t write(int fd, const void *buf, size_t nbyte)
|
||||
{
|
||||
return LOS_Write(fd, buf, nbyte);
|
||||
}
|
||||
|
||||
off_t lseek(int fd, off_t offset, int whence)
|
||||
{
|
||||
return LOS_Lseek(fd, offset, whence);
|
||||
}
|
||||
|
||||
int unlink(const char *path)
|
||||
{
|
||||
return LOS_Unlink(path);
|
||||
}
|
||||
|
||||
int fstat(int fd, struct stat *buf)
|
||||
{
|
||||
return LOS_Fstat(fd, buf);
|
||||
}
|
||||
|
||||
int stat(const char *path, struct stat *buf)
|
||||
{
|
||||
return LOS_Stat(path, buf);
|
||||
}
|
||||
|
||||
int fsync(int fd)
|
||||
{
|
||||
return LOS_Fsync(fd);
|
||||
}
|
||||
|
||||
int mkdir(const char *path, mode_t mode)
|
||||
{
|
||||
return LOS_Mkdir(path, mode);
|
||||
}
|
||||
|
||||
DIR *opendir(const char *dirName)
|
||||
{
|
||||
return LOS_Opendir(dirName);
|
||||
}
|
||||
|
||||
struct dirent *readdir(DIR *dir)
|
||||
{
|
||||
return LOS_Readdir(dir);
|
||||
}
|
||||
|
||||
int closedir(DIR *dir)
|
||||
{
|
||||
return LOS_Closedir(dir);
|
||||
}
|
||||
|
||||
int rmdir(const char *path)
|
||||
{
|
||||
return LOS_Unlink(path);
|
||||
}
|
||||
|
||||
int rename(const char *oldName, const char *newName)
|
||||
{
|
||||
return LOS_Rename(oldName, newName);
|
||||
}
|
||||
|
||||
int statfs(const char *path, struct statfs *buf)
|
||||
{
|
||||
return LOS_Statfs(path, buf);
|
||||
}
|
||||
|
||||
int ftruncate(int fd, off_t length)
|
||||
{
|
||||
return LOS_Ftruncate(fd, length);
|
||||
}
|
||||
|
||||
ssize_t pread(int fd, void *buf, size_t nbyte, off_t offset)
|
||||
{
|
||||
return LOS_Pread(fd, buf, nbyte, offset);
|
||||
}
|
||||
|
||||
ssize_t pwrite(int fd, const void *buf, size_t nbyte, off_t offset)
|
||||
{
|
||||
return LOS_Pwrite(fd, buf, nbyte, offset);
|
||||
}
|
||||
|
||||
int access(const char *path, int mode)
|
||||
{
|
||||
struct stat st;
|
||||
|
||||
if (stat(path, &st) < 0) {
|
||||
return -1;
|
||||
}
|
||||
if ((st.st_mode & S_IFDIR) || (st.st_mode & S_IFREG)) {
|
||||
return 0;
|
||||
}
|
||||
if ((mode & W_OK) && !(st.st_mode & S_IWRITE)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int fcntl(int fd, int cmd, ...)
|
||||
{
|
||||
int ret;
|
||||
va_list vaList;
|
||||
|
||||
va_start(vaList, cmd);
|
||||
ret = OsFcntl(fd, cmd, vaList);
|
||||
va_end(vaList);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ioctl(int fd, int req, ...)
|
||||
{
|
||||
int ret;
|
||||
va_list vaList;
|
||||
|
||||
va_start(vaList, req);
|
||||
ret = OsIoctl(fd, req, vaList);
|
||||
va_end(vaList);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#else /* #ifdef LOSCFG_FS_VFS */
|
||||
|
||||
int mount(const char *source, const char *target,
|
||||
const char *filesystemtype, unsigned long mountflags,
|
||||
const void *data)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int umount(const char *target)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int umount2(const char *target, int flag)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int open(const char *path, int oflag, ...)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int close(int fd)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
ssize_t read(int fd, void *buf, size_t nbyte)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
ssize_t write(int fd, const void *buf, size_t nbyte)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
off_t lseek(int fd, off_t offset, int whence)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int unlink(const char *path)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int fstat(int fd, struct stat *buf)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int stat(const char *path, struct stat *buf)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int fsync(int fd)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int mkdir(const char *path, mode_t mode)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
DIR *opendir(const char *dirName)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct dirent *readdir(DIR *dir)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int closedir(DIR *dir)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int rmdir(const char *path)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int rename(const char *oldName, const char *newName)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int statfs(const char *path, struct statfs *buf)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int ftruncate(int fd, off_t length)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
ssize_t pread(int fd, void *buf, size_t nbyte, off_t offset)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
ssize_t pwrite(int fd, const void *buf, size_t nbyte, off_t offset)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int access(const char *path, int mode)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int fcntl(int fd, int cmd, ...)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int ioctl(int fd, int req, ...)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
@@ -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:
|
||||
@@ -34,7 +34,6 @@
|
||||
#include "los_config.h"
|
||||
#include "los_memory.h"
|
||||
|
||||
|
||||
void *calloc(size_t nitems, size_t size)
|
||||
{
|
||||
size_t real_size;
|
||||
@@ -107,4 +106,3 @@ void *realloc(void *ptr, size_t size)
|
||||
|
||||
return LOS_MemRealloc(OS_SYS_MEM_ADDR, ptr, size);
|
||||
}
|
||||
|
||||
|
||||
@@ -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:
|
||||
@@ -33,7 +33,6 @@ module_switch = defined(LOSCFG_LIBC_NEWLIB)
|
||||
module_name = get_path_info(rebase_path("."), "name")
|
||||
kernel_module(module_name) {
|
||||
sources = [
|
||||
"porting/src/fs.c",
|
||||
"porting/src/malloc.c",
|
||||
"porting/src/network/htonl.c",
|
||||
"porting/src/network/htons.c",
|
||||
@@ -44,7 +43,7 @@ kernel_module(module_name) {
|
||||
]
|
||||
configs += [ "$LITEOSTOPDIR:warn_config" ]
|
||||
|
||||
if (defined(LOSCFG_LIBC_NEWLIB_FS)) {
|
||||
if (defined(LOSCFG_FS_VFS)) {
|
||||
sources +=
|
||||
[ "//third_party/musl/porting/liteos_m/kernel/src/misc/realpath.c" ]
|
||||
}
|
||||
|
||||
@@ -29,13 +29,6 @@
|
||||
|
||||
if LIBC_NEWLIB
|
||||
|
||||
config LIBC_NEWLIB_FS
|
||||
bool "Enable POSIX file system API support"
|
||||
default y
|
||||
depends on FS_VFS
|
||||
help
|
||||
This enables POSIX style file system related APIs.
|
||||
|
||||
config LIBC_NEWLIB_MALLOC
|
||||
bool "Enable POSIX malloc/free API support"
|
||||
default y
|
||||
|
||||
@@ -1,271 +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.
|
||||
*/
|
||||
#define _GNU_SOURCE
|
||||
|
||||
#include "los_config.h"
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#ifdef LOSCFG_LIBC_NEWLIB_FS
|
||||
#include "los_fs.h"
|
||||
#endif
|
||||
|
||||
#ifdef LOSCFG_LIBC_NEWLIB_FS
|
||||
int mount(const char *source, const char *target,
|
||||
const char *filesystemtype, unsigned long mountflags,
|
||||
const void *data)
|
||||
{
|
||||
return LOS_FsMount(source, target, filesystemtype, mountflags, data);
|
||||
}
|
||||
|
||||
int umount(const char *target)
|
||||
{
|
||||
return LOS_FsUmount(target);
|
||||
}
|
||||
|
||||
int umount2(const char *target, int flag)
|
||||
{
|
||||
return LOS_FsUmount2(target, flag);
|
||||
}
|
||||
|
||||
int _open(const char *path, int oflag, ...)
|
||||
{
|
||||
va_list vaList;
|
||||
va_start(vaList, oflag);
|
||||
int ret;
|
||||
ret = LOS_Open(path, oflag);
|
||||
va_end(vaList);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int _close(int fd)
|
||||
{
|
||||
return LOS_Close(fd);
|
||||
}
|
||||
|
||||
ssize_t _read(int fd, void *buf, size_t nbyte)
|
||||
{
|
||||
return LOS_Read(fd, buf, nbyte);
|
||||
}
|
||||
|
||||
ssize_t _write(int fd, const void *buf, size_t nbyte)
|
||||
{
|
||||
return LOS_Write(fd, buf, nbyte);
|
||||
}
|
||||
|
||||
off_t _lseek(int fd, off_t offset, int whence)
|
||||
{
|
||||
return LOS_Lseek(fd, offset, whence);
|
||||
}
|
||||
|
||||
int _unlink(const char *path)
|
||||
{
|
||||
return LOS_Unlink(path);
|
||||
}
|
||||
|
||||
int _fstat(int fd, struct stat *buf)
|
||||
{
|
||||
return LOS_Fstat(fd, buf);
|
||||
}
|
||||
|
||||
int _stat(const char *path, struct stat *buf)
|
||||
{
|
||||
return LOS_Stat(path, buf);
|
||||
}
|
||||
|
||||
int fsync(int fd)
|
||||
{
|
||||
return LOS_Fsync(fd);
|
||||
}
|
||||
|
||||
int mkdir(const char *path, mode_t mode)
|
||||
{
|
||||
return LOS_Mkdir(path, mode);
|
||||
}
|
||||
|
||||
DIR *opendir(const char *dirName)
|
||||
{
|
||||
return LOS_Opendir(dirName);
|
||||
}
|
||||
|
||||
struct dirent *readdir(DIR *dir)
|
||||
{
|
||||
return LOS_Readdir(dir);
|
||||
}
|
||||
|
||||
int closedir(DIR *dir)
|
||||
{
|
||||
return LOS_Closedir(dir);
|
||||
}
|
||||
|
||||
int rmdir(const char *path)
|
||||
{
|
||||
return LOS_Unlink(path);
|
||||
}
|
||||
|
||||
int rename(const char *oldName, const char *newName)
|
||||
{
|
||||
return LOS_Rename(oldName, newName);
|
||||
}
|
||||
|
||||
int statfs(const char *path, struct statfs *buf)
|
||||
{
|
||||
return LOS_Statfs(path, buf);
|
||||
}
|
||||
|
||||
int ftruncate(int fd, off_t length)
|
||||
{
|
||||
return LOS_Ftruncate(fd, length);
|
||||
}
|
||||
|
||||
int fcntl(int fd, int cmd, ...)
|
||||
{
|
||||
int ret;
|
||||
va_list vaList;
|
||||
|
||||
va_start(vaList, cmd);
|
||||
ret = OsFcntl(fd, cmd, vaList);
|
||||
va_end(vaList);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ioctl(int fd, int req, ...)
|
||||
{
|
||||
int ret;
|
||||
va_list vaList;
|
||||
|
||||
va_start(vaList, req);
|
||||
ret = OsIoctl(fd, req, vaList);
|
||||
va_end(vaList);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ssize_t pread(int fd, void *buf, size_t nbyte, off_t offset)
|
||||
{
|
||||
return LOS_Pread(fd, buf, nbyte, offset);
|
||||
}
|
||||
|
||||
ssize_t pwrite(int fd, const void *buf, size_t nbyte, off_t offset)
|
||||
{
|
||||
return LOS_Pwrite(fd, buf, nbyte, offset);
|
||||
}
|
||||
|
||||
int access(const char *path, int mode)
|
||||
{
|
||||
struct stat st;
|
||||
|
||||
if (stat(path, &st) < 0) {
|
||||
return -1;
|
||||
}
|
||||
if ((st.st_mode & S_IFDIR) || (st.st_mode & S_IFREG)) {
|
||||
return 0;
|
||||
}
|
||||
if ((mode & W_OK) && !(st.st_mode & S_IWRITE)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int remove(const char *filename)
|
||||
{
|
||||
int ret = unlink(filename);
|
||||
if (ret == -EISDIR) {
|
||||
ret = rmdir(filename);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#else /* #ifdef LOSCFG_FS_VFS */
|
||||
|
||||
int _open(const char *path, int oflag, ...)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int _close(int fd)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
ssize_t _read(int fd, void *buf, size_t nbyte)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
ssize_t _write(int fd, const void *buf, size_t nbyte)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
off_t _lseek(int fd, off_t offset, int whence)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int _unlink(const char *path)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int _fstat(int fd, struct stat *buf)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int _stat(const char *path, struct stat *buf)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int access(const char *path, int mode)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int remove(const char *filename)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int fcntl(int fd, int cmd, ...)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int ioctl(int fd, int req, ...)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
@@ -57,4 +57,3 @@ void _exit(int status)
|
||||
while (1) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -73,4 +73,11 @@ config POSIX_SIGNAL_API
|
||||
help
|
||||
Answer Y to enable LiteOS support POSIX Signal API.
|
||||
|
||||
config POSIX_FS_API
|
||||
bool "Enable POSIX FS API"
|
||||
default y
|
||||
depends on FS_VFS
|
||||
help
|
||||
Answer Y to enable LiteOS support POSIX FS API.
|
||||
|
||||
endif # POSIX_API
|
||||
|
||||
@@ -664,7 +664,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 += g_timezone;
|
||||
return seconds;
|
||||
}
|
||||
|
||||
@@ -690,7 +690,7 @@ time_t mktime(struct tm *tmptr)
|
||||
}
|
||||
timeInSeconds = ConvertUtc2Secs(tmptr);
|
||||
/* normalize tm_wday and tm_yday */
|
||||
ConvertSecs2Utc(timeInSeconds, tmptr->__tm_gmtoff, tmptr);
|
||||
ConvertSecs2Utc(timeInSeconds, -g_timezone, tmptr);
|
||||
return timeInSeconds;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user