summaryrefslogtreecommitdiffstatsabout
path: root/SylixOS
diff options
context:
space:
mode:
authorHanhui <hanhui@acoinfo.com>2021-01-23 11:34:55 (GMT)
committer Hanhui <hanhui@acoinfo.com>2021-01-23 11:34:55 (GMT)
commit21a4b2dccdabee1a9c754343080068124d566ae8 (patch)
treee9c119d04909302491d55bffeedfc77b9cbbcbce /SylixOS
parent4962a37449232b3174c3549786ace420d4a42b2f (diff)
downloadlibsylixos-21a4b2dccdabee1a9c754343080068124d566ae8.zip
libsylixos-21a4b2dccdabee1a9c754343080068124d566ae8.tar.gz
libsylixos-21a4b2dccdabee1a9c754343080068124d566ae8.tar.bz2
Improved I/O system stability.
Diffstat (limited to 'SylixOS')
-rw-r--r--SylixOS/arch/arm64/arm64_atomic.h12
-rw-r--r--SylixOS/arch/csky/common/cskyContextAsm.S5
-rw-r--r--SylixOS/fs/tpsFs/tpsfs.c68
-rw-r--r--SylixOS/fs/tpsFs/tpsfs_inode.c4
-rw-r--r--SylixOS/fs/tpsFs/tpsfs_trans.c6
-rw-r--r--SylixOS/system/ioLib/ioFdNode.c8
-rw-r--r--SylixOS/system/ioLib/ioFile.c11
-rw-r--r--SylixOS/system/ioLib/ioInterface.c25
-rw-r--r--SylixOS/system/ioLib/ioLockF.c28
-rw-r--r--SylixOS/system/ioLib/ioStat.c7
-rw-r--r--SylixOS/system/ioLib/ioSymlink.c15
11 files changed, 160 insertions, 29 deletions
diff --git a/SylixOS/arch/arm64/arm64_atomic.h b/SylixOS/arch/arm64/arm64_atomic.h
index 08e7198..642c434 100644
--- a/SylixOS/arch/arm64/arm64_atomic.h
+++ b/SylixOS/arch/arm64/arm64_atomic.h
@@ -87,13 +87,13 @@ static LW_INLINE INT archAtomicCas (atomic_t *v, INT iOld, INT iNew)
"1: ldxr %w[oldval], %[v] \n"
" eor %w[tmp], %w[oldval], %w[old] \n"
" cbnz %w[tmp], 2f \n"
- " stlxr %w[tmp], %w[new], %[v] \n"
+ " stlxr %w[tmp], %w[newval], %[v] \n"
" cbnz %w[tmp], 1b \n"
" dmb ish \n"
"2:"
: [tmp] "=&r" (lTemp), [oldval] "=&r" (lOldVal),
[v] "+Q" (v->counter)
- : [old] "Lr" (lOld), [new] "r" (lNew)
+ : [old] "Lr" (lOld), [newval] "r" (lNew)
: "memory");
return ((INT)lOldVal);
@@ -110,13 +110,13 @@ static LW_INLINE addr_t archAtomicAddrCas (volatile addr_t *p, addr_t ulOld, a
"1: ldxr %[oldval], %[v] \n"
" eor %[tmp], %[oldval], %[old] \n"
" cbnz %[tmp], 2f \n"
- " stlxr %w[tmp], %[new], %[v] \n"
+ " stlxr %w[tmp], %[newval], %[v] \n"
" cbnz %w[tmp], 1b \n"
" dmb ish \n"
"2:"
: [tmp] "=&r" (ulTemp), [oldval] "=&r" (ulOldVal),
[v] "+Q" (*p)
- : [old] "Lr" (ulOld), [new] "r" (ulNew)
+ : [old] "Lr" (ulOld), [newval] "r" (ulNew)
: "memory");
return (ulOldVal);
@@ -185,13 +185,13 @@ static LW_INLINE INT64 archAtomic64Cas (atomic64_t *v, INT64 i64Old, INT64 i
"1: ldxr %[oldval], %[v] \n"
" eor %[tmp], %[oldval], %[old] \n"
" cbnz %[tmp], 2f \n"
- " stlxr %w[tmp], %[new], %[v] \n"
+ " stlxr %w[tmp], %[newval], %[v] \n"
" cbnz %w[tmp], 1b \n"
" dmb ish \n"
"2:"
: [tmp] "=&r" (i64Temp), [oldval] "=&r" (i64OldVal),
[v] "+Q" (v->counter)
- : [old] "Lr" (i64Old), [new] "r" (i64New)
+ : [old] "Lr" (i64Old), [newval] "r" (i64New)
: "memory");
return (i64OldVal);
diff --git a/SylixOS/arch/csky/common/cskyContextAsm.S b/SylixOS/arch/csky/common/cskyContextAsm.S
index 9b16815..1a5e9a4 100644
--- a/SylixOS/arch/csky/common/cskyContextAsm.S
+++ b/SylixOS/arch/csky/common/cskyContextAsm.S
@@ -171,8 +171,13 @@ FUNC_DEF(archTaskCtxCopy)
ADDI A0 , (8 * ARCH_REG_SIZE)
ADDI A1 , (8 * ARCH_REG_SIZE)
+#if !defined(__SYLIXOS_CSKY_ARCH_CK860__)
LDM R18-R23 , (A1)
STM R18-R23 , (A0)
+#else
+ LDM R18-R21 , (A1)
+ STM R18-R21 , (A0)
+#endif
RTS
FUNC_END(archTaskCtxCopy)
diff --git a/SylixOS/fs/tpsFs/tpsfs.c b/SylixOS/fs/tpsFs/tpsfs.c
index 4e8f0b5..de86ce1 100644
--- a/SylixOS/fs/tpsFs/tpsfs.c
+++ b/SylixOS/fs/tpsFs/tpsfs.c
@@ -37,6 +37,23 @@
#include "tpsfs_dir.h"
#include "tpsfs.h"
/*********************************************************************************************************
+** 函数名称: __tpsfsCheckInode
+** 功能描述: 检查inode有效性
+** 输 入 : pinode inode指针
+** 输 出 : BOOL
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+static BOOL __tpsfsCheckInode (PTPS_INODE pinode)
+{
+ if (pinode->IND_bDeleted || (pinode->IND_uiMagic != TPS_MAGIC_INODE) ||
+ (pinode->IND_uiOpenCnt == 0) || (pinode->IND_uiRefCnt == 0)) {
+ return (LW_FALSE);
+ }
+
+ return (LW_TRUE);
+}
+/*********************************************************************************************************
** 函数名称: __tpsFsCheckFileName
** 功能描述: 检查文件名操作
** 输 入 : pcName 文件名
@@ -741,6 +758,10 @@ errno_t tpsFsRead (PTPS_INODE pinode,
return (EINVAL);
}
+ if (!__tpsfsCheckInode(pinode)) {
+ return (EINVAL);
+ }
+
if (pinode->IND_psb->SB_uiFlags & TPS_TRANS_FAULT) { /* 事务处理出错 */
return (EIO);
}
@@ -786,6 +807,10 @@ errno_t tpsFsWrite (PTPS_INODE pinode,
return (EINVAL);
}
+ if (!__tpsfsCheckInode(pinode)) {
+ return (EINVAL);
+ }
+
if (pinode->IND_psb->SB_uiFlags & TPS_TRANS_FAULT) { /* 事务处理出错 */
return (EIO);
}
@@ -835,6 +860,13 @@ errno_t tpsFsClose (PTPS_INODE pinode)
return (EINVAL);
}
+ if (!__tpsfsCheckInode(pinode)) {
+ if (pinode->IND_uiOpenCnt > 0) {
+ tpsFsCloseInode(pinode);
+ }
+ return (EINVAL);
+ }
+
if (pinode->IND_psb->SB_uiFlags & TPS_TRANS_FAULT) { /* 事务处理出错 */
return (EIO);
}
@@ -872,6 +904,10 @@ errno_t tpsFsFlushHead (PTPS_INODE pinode)
return (EINVAL);
}
+ if (!__tpsfsCheckInode(pinode)) {
+ return (EINVAL);
+ }
+
if (pinode->IND_psb->SB_uiFlags & TPS_TRANS_FAULT) { /* 事务处理出错 */
return (EIO);
}
@@ -911,6 +947,10 @@ errno_t tpsFsTrunc (PTPS_INODE pinode, TPS_SIZE_T szNewSize)
return (EINVAL);
}
+ if (!__tpsfsCheckInode(pinode)) {
+ return (EINVAL);
+ }
+
if (pinode->IND_psb->SB_uiFlags & TPS_TRANS_FAULT) { /* 事务处理出错 */
return (EIO);
}
@@ -992,6 +1032,10 @@ errno_t tpsFsReadDir (PTPS_INODE pinodeDir, BOOL bInHash, TPS_OFF_T off, PTPS_E
return (EINVAL);
}
+ if (!__tpsfsCheckInode(pinodeDir)) {
+ return (EINVAL);
+ }
+
if (pinodeDir->IND_psb->SB_uiFlags & TPS_TRANS_FAULT) { /* 事务处理出错 */
return (EIO);
}
@@ -1020,6 +1064,10 @@ errno_t tpsFsSync (PTPS_INODE pinode)
return (EINVAL);
}
+ if (!__tpsfsCheckInode(pinode)) {
+ return (EINVAL);
+ }
+
if (pinode->IND_psb->SB_uiFlags & TPS_TRANS_FAULT) { /* 事务处理出错 */
return (EIO);
}
@@ -1196,6 +1244,10 @@ TPS_SIZE_T tpsFsGetSize (PTPS_INODE pinode)
return (0);
}
+ if (!__tpsfsCheckInode(pinode)) {
+ return (0);
+ }
+
return (pinode->IND_szData);
}
/*********************************************************************************************************
@@ -1212,6 +1264,10 @@ INT tpsFsGetmod (PTPS_INODE pinode)
return (0);
}
+ if (!__tpsfsCheckInode(pinode)) {
+ return (0);
+ }
+
return (pinode->IND_iMode);
}
/*********************************************************************************************************
@@ -1229,6 +1285,10 @@ errno_t tpsFsChmod (PTPS_INODE pinode, INT iMode)
return (EINVAL);
}
+ if (!__tpsfsCheckInode(pinode)) {
+ return (EINVAL);
+ }
+
if (pinode->IND_psb->SB_uiFlags & TPS_TRANS_FAULT) { /* 事务处理出错 */
return (EIO);
}
@@ -1258,6 +1318,10 @@ errno_t tpsFsChown (PTPS_INODE pinode, uid_t uid, gid_t gid)
return (EINVAL);
}
+ if (!__tpsfsCheckInode(pinode)) {
+ return (EINVAL);
+ }
+
if (pinode->IND_psb->SB_uiFlags & TPS_TRANS_FAULT) { /* 事务处理出错 */
return (EIO);
}
@@ -1283,6 +1347,10 @@ errno_t tpsFsChtime (PTPS_INODE pinode, struct utimbuf *utim)
return (EINVAL);
}
+ if (!__tpsfsCheckInode(pinode)) {
+ return (EINVAL);
+ }
+
if (pinode->IND_psb->SB_uiFlags & TPS_TRANS_FAULT) { /* 事务处理出错 */
return (EIO);
}
diff --git a/SylixOS/fs/tpsFs/tpsfs_inode.c b/SylixOS/fs/tpsFs/tpsfs_inode.c
index 618d6ec..36d6355 100644
--- a/SylixOS/fs/tpsFs/tpsfs_inode.c
+++ b/SylixOS/fs/tpsFs/tpsfs_inode.c
@@ -488,6 +488,7 @@ TPS_RESULT tpsFsCloseInode (PTPS_INODE pinode)
ppinodeIter = &((*ppinodeIter)->IND_pnext);
}
+ pinode->IND_uiMagic = 0; /* 设置无效掩码防止上层野指针 */
for (i = 0; i < TPS_BN_POOL_SIZE; i++) { /* 释放节点缓冲池 */
if (pinode->IND_pBNPool[i] != LW_NULL) {
TPS_FREE(pinode->IND_pBNPool[i]);
@@ -610,7 +611,8 @@ TPS_RESULT tpsFsInodeDelRef (PTPS_TRANS ptrans, PTPS_INODE pinode)
ppinodeIter = &((*ppinodeIter)->IND_pnext);
}
- pinode->IND_bDeleted = LW_TRUE;
+ pinode->IND_uiMagic = 0; /* 无效掩码防止操作已删除文件 */
+ pinode->IND_bDeleted = LW_TRUE;
}
pucBuff = pinode->IND_pucBuff;
diff --git a/SylixOS/fs/tpsFs/tpsfs_trans.c b/SylixOS/fs/tpsFs/tpsfs_trans.c
index 473c006..22d3699 100644
--- a/SylixOS/fs/tpsFs/tpsfs_trans.c
+++ b/SylixOS/fs/tpsFs/tpsfs_trans.c
@@ -170,6 +170,12 @@ PTPS_TRANS tpsFsTransAllocAndInit (PTPS_SUPER_BLOCK psb)
return (LW_NULL);
}
+ if ((ptrans->TRANS_iStatus != TPS_TRANS_STATUS_COMPLETE) &&
+ (ptrans->TRANS_pdata->TD_uiSecAreaCnt > 0)) { /* 上个事务未完成,进入异常态 */
+ psb->SB_uiFlags |= TPS_TRANS_FAULT;
+ return (LW_NULL);
+ }
+
ptrans->TRANS_ui64SerialNum = ptranssb->TSP_ui64SerialNum;
ptrans->TRANS_uiDataSecNum = ptranssb->TSP_ui64DataCurSec;
ptrans->TRANS_uiDataSecCnt = 0;
diff --git a/SylixOS/system/ioLib/ioFdNode.c b/SylixOS/system/ioLib/ioFdNode.c
index 330a682..890d80a 100644
--- a/SylixOS/system/ioLib/ioFdNode.c
+++ b/SylixOS/system/ioLib/ioFdNode.c
@@ -94,9 +94,11 @@ PLW_FD_NODE API_IosFdNodeAdd (LW_LIST_LINE_HEADER *pplineHeader,
}
lib_bzero(pfdnode, sizeof(LW_FD_NODE));
- pfdnode->FDNODE_ulSem = API_SemaphoreBCreate("fd_node_lock", LW_TRUE,
+ pfdnode->FDNODE_ulSem = API_SemaphoreMCreate("fd_node_lock", LW_PRIO_DEF_CEILING,
LW_OPTION_OBJECT_GLOBAL |
- LW_OPTION_WAIT_PRIORITY, LW_NULL);
+ LW_OPTION_WAIT_PRIORITY |
+ LW_OPTION_DELETE_SAFE |
+ LW_OPTION_INHERIT_PRIORITY, LW_NULL);
if (pfdnode->FDNODE_ulSem == LW_OBJECT_HANDLE_INVALID) {
__SHEAP_FREE(pfdnode);
return (LW_NULL);
@@ -158,7 +160,7 @@ INT API_IosFdNodeDec (LW_LIST_LINE_HEADER *pplineHeader,
_List_Line_Del(&pfdnode->FDNODE_lineManage,
pplineHeader);
- API_SemaphoreBDelete(&pfdnode->FDNODE_ulSem);
+ API_SemaphoreMDelete(&pfdnode->FDNODE_ulSem);
if (bRemove) {
*bRemove = pfdnode->FDNODE_bRemove;
diff --git a/SylixOS/system/ioLib/ioFile.c b/SylixOS/system/ioLib/ioFile.c
index e23bb00..a523cc3 100644
--- a/SylixOS/system/ioLib/ioFile.c
+++ b/SylixOS/system/ioLib/ioFile.c
@@ -1346,6 +1346,8 @@ INT API_IosFdRefDec (INT iFd)
MONITOR_EVT_INT1(MONITOR_EVENT_ID_IO, MONITOR_EVENT_IO_CLOSE, iFd, LW_NULL);
+ LW_THREAD_SAFE(); /* 进入安全状态, 防止关闭过程 */
+ /* 当前任务被删除 */
if (pfdentry->FDENTRY_ulCounter == 0) { /* 没有描述符引用此 fd_entry */
if (pfdentry->FDENTRY_state == FDSTAT_SYNC) {
pfdentry->FDENTRY_state = FDSTAT_REQCLOSE;
@@ -1367,7 +1369,9 @@ INT API_IosFdRefDec (INT iFd)
_FdLockfClearFdEntry(pfdentry, __PROC_GET_PID_CUR()); /* 回收记录锁 */
}
-
+
+ LW_THREAD_UNSAFE(); /* 退出安全状态 */
+
} else {
_IosUnlock(); /* 退出 IO 临界区 */
}
@@ -1414,6 +1418,9 @@ INT API_IosFdEntryReclaim (PLW_FD_ENTRY pfdentry, ULONG ulRefDec, pid_t pid)
} else if (bCallFunc) {
pfdentry->FDENTRY_state = FDSTAT_CLOSING; /* 准备调用驱动 close 函数 */
}
+
+ LW_THREAD_SAFE(); /* 进入安全状态, 防止关闭过程 */
+ /* 当前任务被删除 */
_IosUnlock(); /* 退出 IO 临界区 */
_FdLockfClearFdEntry(pfdentry, pid); /* 回收指定进程创建的记录锁 */
@@ -1426,6 +1433,8 @@ INT API_IosFdEntryReclaim (PLW_FD_ENTRY pfdentry, ULONG ulRefDec, pid_t pid)
_IosFileClose(pfdentry);
}
_IosFileDelete(pfdentry);
+
+ LW_THREAD_UNSAFE(); /* 退出安全状态 */
}
return (iErrCode);
diff --git a/SylixOS/system/ioLib/ioInterface.c b/SylixOS/system/ioLib/ioInterface.c
index 42c265f..7c1960d 100644
--- a/SylixOS/system/ioLib/ioInterface.c
+++ b/SylixOS/system/ioLib/ioInterface.c
@@ -118,7 +118,8 @@ static INT _IoOpen (PCHAR pcName,
PLW_IO_ENV pioeDef;
REGISTER LONG lValue;
- REGISTER INT iFd = (PX_ERROR);
+ REGISTER INT iFd = PX_ERROR;
+ BOOL bSafe = LW_FALSE;
CHAR cFullFileName[MAX_FILENAME_LENGTH];
@@ -163,6 +164,9 @@ static INT _IoOpen (PCHAR pcName,
goto __error_handle;
}
+ LW_THREAD_SAFE(); /* 进入安全状态, 防止打开过程 */
+ bSafe = LW_TRUE; /* 当前任务被删除 */
+
iFd = iosFdNew(pdevhdrHdr, cFullFileName, PX_ERROR, iFlag); /* 此时就确定了文件描述符名 */
if (iFd == PX_ERROR) {
_DebugHandle(__ERRORMESSAGE_LEVEL, "file can not create.\r\n");
@@ -205,7 +209,7 @@ static INT _IoOpen (PCHAR pcName,
goto __error_handle;
}
}
-
+ /* 设置文件描述符 */
if (iosFdSet(iFd, pdevhdrHdr, lValue, iFlag, FDSTAT_OK) != ERROR_NONE) {
_DebugHandle(__ERRORMESSAGE_LEVEL, "file can not config.\r\n");
ulError = API_GetLastError();
@@ -213,6 +217,9 @@ static INT _IoOpen (PCHAR pcName,
goto __error_handle;
}
+ LW_THREAD_UNSAFE(); /* 退出安全状态 */
+ bSafe = LW_FALSE;
+
if (iLinkCount) { /* 内部存在符号链接 */
if (iosFdRealName(iFd, cFullFileName)) {
_DebugHandle(__ERRORMESSAGE_LEVEL, "file can not set real name.\r\n");
@@ -256,11 +263,8 @@ static INT _IoOpen (PCHAR pcName,
return (iFd);
__error_handle:
- if ((iErrLevel > 2) && (iFlag & O_CREAT)) {
- /*
- * 这里目前不应该删除这个文件.
- * iosDelete(pdevhdrHdr, cFullFileName);
- */
+ if (bSafe) {
+ LW_THREAD_UNSAFE();
}
if (iErrLevel > 1) {
iosFdFree(iFd);
@@ -489,8 +493,11 @@ INT rename (CPCHAR pcOldName, CPCHAR pcNewName)
return (PX_ERROR);
}
+ LW_THREAD_SAFE(); /* 进入安全状态, 防止打开过程 */
+ /* 当前任务被删除 */
pfdentry = _IosFileNew(pdevhdrHdr, cFullFileName); /* 创建一个临时的 fd_entry */
if (pfdentry == LW_NULL) {
+ LW_THREAD_UNSAFE(); /* 退出安全状态 */
close(iFd);
return (PX_ERROR);
}
@@ -504,6 +511,7 @@ INT rename (CPCHAR pcOldName, CPCHAR pcNewName)
} else {
if (iLinkCount++ > _S_iIoMaxLinkLevels) { /* 链接文件层数太多 */
_IosFileDelete(pfdentry);
+ LW_THREAD_UNSAFE(); /* 退出安全状态 */
close(iFd);
_ErrorHandle(ELOOP);
return (PX_ERROR);
@@ -515,6 +523,7 @@ INT rename (CPCHAR pcOldName, CPCHAR pcNewName)
*/
if (ioFullFileNameGet(cFullFileName, &pdevhdrHdr, cFullFileName) != ERROR_NONE) {
_IosFileDelete(pfdentry);
+ LW_THREAD_UNSAFE(); /* 退出安全状态 */
close(iFd);
_ErrorHandle(EXDEV);
return (PX_ERROR);
@@ -528,6 +537,8 @@ INT rename (CPCHAR pcOldName, CPCHAR pcNewName)
_IosFileDelete(pfdentry); /* 删除临时的 fd_entry */
+ LW_THREAD_UNSAFE(); /* 退出安全状态 */
+
if (_PathBuildLink(cFullFileName, MAX_FILENAME_LENGTH,
LW_NULL, LW_NULL,
pdevhdrHdr->DEVHDR_pcName, cFullFileName) < ERROR_NONE) {
diff --git a/SylixOS/system/ioLib/ioLockF.c b/SylixOS/system/ioLib/ioLockF.c
index aeb8c53..8245a54 100644
--- a/SylixOS/system/ioLib/ioLockF.c
+++ b/SylixOS/system/ioLib/ioLockF.c
@@ -78,6 +78,11 @@ typedef struct {
typedef LW_LOCKF_CLEANUP *PLW_LOCKF_CLEANUP;
static LW_LOCKF_CLEANUP _G_lfcTable[LW_CFG_MAX_THREADS];
/*********************************************************************************************************
+ fdnode lock / unlock
+*********************************************************************************************************/
+#define FDNODE_LOCK(pfdnode) API_SemaphoreMPend((pfdnode)->FDNODE_ulSem, LW_OPTION_WAIT_INFINITE)
+#define FDNODE_UNLOCK(pfdnode) API_SemaphoreMPost((pfdnode)->FDNODE_ulSem)
+/*********************************************************************************************************
** 函数名称: __fdLockfPrint
** 功能描述: 打印一个 lock file 节点.
** 输 入 : pcMsg 前缀信息
@@ -329,8 +334,9 @@ VOID __fdLockfCleanupHook (PLW_CLASS_TCB ptcbDel)
return;
}
- if (API_SemaphoreBPend(plfc->LFC_pfdnode->FDNODE_ulSem, LW_OPTION_WAIT_INFINITE)) {
+ if (FDNODE_LOCK(plfc->LFC_pfdnode)) {
goto __out;
+
} else {
/*
* Is blocking ?
@@ -338,7 +344,7 @@ VOID __fdLockfCleanupHook (PLW_CLASS_TCB ptcbDel)
if ((pfdlockfBlock = plfc->LFC_pfdlockf->FDLOCK_pfdlockNext) != LW_NULL) {
__fdLockfUnblock(plfc->LFC_pfdlockf, pfdlockfBlock, plfc->LFC_pfdnode);
}
- API_SemaphoreBPost(plfc->LFC_pfdnode->FDNODE_ulSem);
+ FDNODE_UNLOCK(plfc->LFC_pfdnode);
}
__out:
@@ -774,7 +780,7 @@ static INT __fdLockfSetLock (PLW_FD_LOCKF pfdlockfLock,
*/
__fdLockfCleanupSet(pfdlockfLock, *ppfdlockfSpare, pfdnode);
- API_SemaphoreBPost(pfdnode->FDNODE_ulSem);
+ FDNODE_UNLOCK(pfdnode);
__THREAD_CANCEL_POINT(); /* 测试取消点 */
@@ -785,7 +791,7 @@ static INT __fdLockfSetLock (PLW_FD_LOCKF pfdlockfLock,
*/
__fdLockfCleanupSet(LW_NULL, LW_NULL, LW_NULL);
- if (API_SemaphoreBPend(pfdnode->FDNODE_ulSem, LW_OPTION_WAIT_INFINITE)) {
+ if (FDNODE_LOCK(pfdnode)) {
__fdLockfDelete(pfdlockfLock);
return (EBADF);
}
@@ -1039,7 +1045,7 @@ static INT __fdLockfAdvLock (PLW_FD_NODE pfdnode,
return (ENOLCK);
}
- API_SemaphoreBPend(pfdnode->FDNODE_ulSem, LW_OPTION_WAIT_INFINITE);
+ FDNODE_LOCK(pfdnode);
/*
* Avoid the common case of unlocking when inode has no locks.
@@ -1089,7 +1095,7 @@ static INT __fdLockfAdvLock (PLW_FD_NODE pfdnode,
}
__lock_done:
- API_SemaphoreBPost(pfdnode->FDNODE_ulSem);
+ FDNODE_UNLOCK(pfdnode);
__fdLockfDelete(pfdlockfLock);
__fdLockfDelete(pfdlockfSpare);
@@ -1108,7 +1114,7 @@ static VOID __fdLockAbortAdvLocks (PLW_FD_NODE pfdnode)
PLW_FD_LOCKF pfdlockf, pfdlockfDel, pfdlockfBlock;
PLW_LIST_LINE plineTmp;
- API_SemaphoreBPend(pfdnode->FDNODE_ulSem, LW_OPTION_WAIT_INFINITE);
+ FDNODE_LOCK(pfdnode);
pfdlockf = pfdnode->FDNODE_pfdlockHead;
while (pfdlockf) {
@@ -1130,7 +1136,7 @@ static VOID __fdLockAbortAdvLocks (PLW_FD_NODE pfdnode)
pfdnode->FDNODE_pfdlockHead = LW_NULL;
- API_SemaphoreBPost(pfdnode->FDNODE_ulSem);
+ FDNODE_UNLOCK(pfdnode);
}
/*********************************************************************************************************
** 函数名称: _FdLockfIoctl
@@ -1291,12 +1297,12 @@ INT _FdLockfClearFdEntry (PLW_FD_ENTRY pfdentry, pid_t pid)
return (PX_ERROR);
}
- API_SemaphoreBPend(pfdnode->FDNODE_ulSem, LW_OPTION_WAIT_INFINITE);
+ FDNODE_LOCK(pfdnode);
if (pfdnode->FDNODE_pfdlockHead == LW_NULL) { /* no lock in fd_node */
- API_SemaphoreBPost(pfdnode->FDNODE_ulSem);
+ FDNODE_UNLOCK(pfdnode);
return (ERROR_NONE); /* 不存在任何记录锁 */
}
- API_SemaphoreBPost(pfdnode->FDNODE_ulSem);
+ FDNODE_UNLOCK(pfdnode);
return (_FdLockfProc(pfdentry, LOCK_UN, pid)); /* 移除与本进程相关的锁 */
}
diff --git a/SylixOS/system/ioLib/ioStat.c b/SylixOS/system/ioLib/ioStat.c
index aca7ef5..0d425b9 100644
--- a/SylixOS/system/ioLib/ioStat.c
+++ b/SylixOS/system/ioLib/ioStat.c
@@ -298,8 +298,11 @@ INT lstat (CPCHAR pcName, struct stat *pstat)
}
lib_strlcpy(pcLastTimeName, cFullFileName, MAX_FILENAME_LENGTH);
+ LW_THREAD_SAFE(); /* 进入安全状态, 防止打开过程 */
+ /* 当前任务被删除 */
pfdentry = _IosFileNew(pdevhdrHdr, cFullFileName); /* 创建一个临时的 fd_entry */
if (pfdentry == LW_NULL) {
+ LW_THREAD_UNSAFE(); /* 退出安全状态 */
__SHEAP_FREE(pcLastTimeName);
return (PX_ERROR);
}
@@ -312,6 +315,7 @@ INT lstat (CPCHAR pcName, struct stat *pstat)
} else {
if (iLinkCount++ > _S_iIoMaxLinkLevels) { /* 链接文件层数太多 */
_IosFileDelete(pfdentry);
+ LW_THREAD_UNSAFE(); /* 退出安全状态 */
__SHEAP_FREE(pcLastTimeName);
_ErrorHandle(ELOOP);
return (PX_ERROR);
@@ -323,6 +327,7 @@ INT lstat (CPCHAR pcName, struct stat *pstat)
*/
if (ioFullFileNameGet(cFullFileName, &pdevhdrHdr, cFullFileName) != ERROR_NONE) {
_IosFileDelete(pfdentry);
+ LW_THREAD_UNSAFE(); /* 退出安全状态 */
__SHEAP_FREE(pcLastTimeName);
_ErrorHandle(EXDEV);
return (PX_ERROR);
@@ -337,6 +342,8 @@ INT lstat (CPCHAR pcName, struct stat *pstat)
_IosFileDelete(pfdentry); /* 删除临时的 fd_entry */
+ LW_THREAD_UNSAFE(); /* 退出安全状态 */
+
iError = API_IosLstat(pdevhdrHdr, pcLastTimeName, pstat);
__SHEAP_FREE(pcLastTimeName);
diff --git a/SylixOS/system/ioLib/ioSymlink.c b/SylixOS/system/ioLib/ioSymlink.c
index 546d9da..e014ebd 100644
--- a/SylixOS/system/ioLib/ioSymlink.c
+++ b/SylixOS/system/ioLib/ioSymlink.c
@@ -71,8 +71,11 @@ INT symlink (CPCHAR pcLinkDst, CPCHAR pcSymPath)
return (PX_ERROR);
}
+ LW_THREAD_SAFE(); /* 进入安全状态, 防止打开过程 */
+ /* 当前任务被删除 */
pfdentry = _IosFileNew(pdevhdrHdr, cFullFileName); /* 创建一个临时的 fd_entry */
if (pfdentry == LW_NULL) {
+ LW_THREAD_UNSAFE(); /* 退出安全状态 */
return (PX_ERROR);
}
@@ -80,6 +83,7 @@ INT symlink (CPCHAR pcLinkDst, CPCHAR pcSymPath)
lValue = iosOpen(pdevhdrHdr, cFullFileName, O_RDONLY, 0);
if (lValue == FOLLOW_LINK_FILE) { /* 已经存在连接文件 */
_IosFileDelete(pfdentry);
+ LW_THREAD_UNSAFE(); /* 退出安全状态 */
_ErrorHandle(EEXIST);
return (PX_ERROR);
@@ -89,6 +93,7 @@ INT symlink (CPCHAR pcLinkDst, CPCHAR pcSymPath)
} else {
if (iLinkCount++ > _S_iIoMaxLinkLevels) { /* 链接文件层数太多 */
_IosFileDelete(pfdentry);
+ LW_THREAD_UNSAFE(); /* 退出安全状态 */
_ErrorHandle(ELOOP);
return (PX_ERROR);
}
@@ -99,6 +104,7 @@ INT symlink (CPCHAR pcLinkDst, CPCHAR pcSymPath)
*/
if (ioFullFileNameGet(cFullFileName, &pdevhdrHdr, cFullFileName) != ERROR_NONE) {
_IosFileDelete(pfdentry);
+ LW_THREAD_UNSAFE(); /* 退出安全状态 */
_ErrorHandle(EXDEV);
return (PX_ERROR);
}
@@ -111,6 +117,8 @@ INT symlink (CPCHAR pcLinkDst, CPCHAR pcSymPath)
_IosFileDelete(pfdentry); /* 删除临时的 fd_entry */
+ LW_THREAD_UNSAFE(); /* 退出安全状态 */
+
iRet = iosSymlink(pdevhdrHdr, cFullFileName, pcLinkDst);
if (iRet == ERROR_NONE) {
@@ -171,8 +179,11 @@ ssize_t readlink (CPCHAR pcSymPath, PCHAR pcLinkDst, size_t stMaxSize)
}
lib_strlcpy(pcLastTimeName, cFullFileName, MAX_FILENAME_LENGTH);
+ LW_THREAD_SAFE(); /* 进入安全状态, 防止打开过程 */
+ /* 当前任务被删除 */
pfdentry = _IosFileNew(pdevhdrHdr, cFullFileName); /* 创建一个临时的 fd_entry */
if (pfdentry == LW_NULL) {
+ LW_THREAD_UNSAFE(); /* 退出安全状态 */
__SHEAP_FREE(pcLastTimeName);
return (PX_ERROR);
}
@@ -185,6 +196,7 @@ ssize_t readlink (CPCHAR pcSymPath, PCHAR pcLinkDst, size_t stMaxSize)
} else {
if (iLinkCount++ > _S_iIoMaxLinkLevels) { /* 链接文件层数太多 */
_IosFileDelete(pfdentry);
+ LW_THREAD_UNSAFE(); /* 退出安全状态 */
__SHEAP_FREE(pcLastTimeName);
_ErrorHandle(ELOOP);
return (PX_ERROR);
@@ -196,6 +208,7 @@ ssize_t readlink (CPCHAR pcSymPath, PCHAR pcLinkDst, size_t stMaxSize)
*/
if (ioFullFileNameGet(cFullFileName, &pdevhdrHdr, cFullFileName) != ERROR_NONE) {
_IosFileDelete(pfdentry);
+ LW_THREAD_UNSAFE(); /* 退出安全状态 */
__SHEAP_FREE(pcLastTimeName);
_ErrorHandle(EXDEV);
return (PX_ERROR);
@@ -210,6 +223,8 @@ ssize_t readlink (CPCHAR pcSymPath, PCHAR pcLinkDst, size_t stMaxSize)
_IosFileDelete(pfdentry); /* 删除临时的 fd_entry */
+ LW_THREAD_UNSAFE(); /* 退出安全状态 */
+
sstRet = iosReadlink(pdevhdrHdr, pcLastTimeName, pcLinkDst, stMaxSize);
__SHEAP_FREE(pcLastTimeName);