\fix: M核用例编译问题修复
【背景】M核用例编译问题修复 【修改方案】 1, 添加musl缺失的fcntl 2,删除musl下对fcntl和ioctl的依赖 3,修改fs和vfs种fcntl入参的处理 【影响】 对现有的产品编译不会有影响。 re #I5PKBJ Signed-off-by: wangchen <wangchen240@huawei.com>
This commit is contained in:
parent
b8f8ab5a36
commit
0adbafb9c2
|
@ -44,6 +44,7 @@
|
|||
#include "sys/stat.h"
|
||||
#include "sys/uio.h"
|
||||
#include "unistd.h"
|
||||
#include <stdarg.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
|
@ -83,6 +84,9 @@ 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);
|
||||
|
|
|
@ -582,17 +582,13 @@ static int VfsRename(const char *old, const char *new)
|
|||
return ret;
|
||||
}
|
||||
|
||||
static int VfsIoctl(int fd, int func, ...)
|
||||
static int VfsIoctl(int fd, int func, va_list ap)
|
||||
{
|
||||
va_list ap;
|
||||
unsigned long arg;
|
||||
struct File *file = NULL;
|
||||
int ret = (int)LOS_NOK;
|
||||
|
||||
va_start(ap, func);
|
||||
arg = va_arg(ap, unsigned long);
|
||||
va_end(ap);
|
||||
|
||||
file = VfsAttachFileReady(fd);
|
||||
if (file == NULL) {
|
||||
return ret;
|
||||
|
@ -1143,12 +1139,10 @@ int LOS_Fstat(int fd, struct stat *buf)
|
|||
return ret;
|
||||
}
|
||||
|
||||
int LOS_Fcntl(int fd, int cmd, ...)
|
||||
int OsFcntl(int fd, int cmd, va_list ap)
|
||||
{
|
||||
struct File *filep = NULL;
|
||||
va_list ap;
|
||||
int ret;
|
||||
va_start(ap, cmd);
|
||||
|
||||
if (fd < CONFIG_NFILE_DESCRIPTORS) {
|
||||
filep = VfsAttachFileReady(fd);
|
||||
|
@ -1159,13 +1153,10 @@ int LOS_Fcntl(int fd, int cmd, ...)
|
|||
#ifdef LOSCFG_NET_LWIP_SACK
|
||||
int arg = va_arg(ap, int);
|
||||
ret = lwip_fcntl(fd, (long)cmd, arg);
|
||||
va_end(ap);
|
||||
return ret;
|
||||
#endif /* LOSCFG_NET_LWIP_SACK */
|
||||
}
|
||||
|
||||
va_end(ap);
|
||||
|
||||
if (ret < 0) {
|
||||
VFS_ERRNO_SET(-ret);
|
||||
ret = (int)LOS_NOK;
|
||||
|
@ -1173,11 +1164,21 @@ int LOS_Fcntl(int fd, int cmd, ...)
|
|||
return ret;
|
||||
}
|
||||
|
||||
int LOS_Ioctl(int fd, int req, ...)
|
||||
int LOS_Fcntl(int fd, int cmd, ...)
|
||||
{
|
||||
va_list ap;
|
||||
int ret;
|
||||
va_start(ap, cmd);
|
||||
ret = OsFcntl(fd, cmd, ap);
|
||||
va_end(ap);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int OsIoctl(int fd, int req, va_list ap)
|
||||
{
|
||||
int ret;
|
||||
va_list ap;
|
||||
va_start(ap, req);
|
||||
|
||||
if (fd < CONFIG_NFILE_DESCRIPTORS) {
|
||||
ret = VfsIoctl(fd, req, ap);
|
||||
} else {
|
||||
|
@ -1188,6 +1189,15 @@ int LOS_Ioctl(int fd, int req, ...)
|
|||
#endif /* LOSCFG_NET_LWIP_SACK */
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int LOS_Ioctl(int fd, int req, ...)
|
||||
{
|
||||
int ret;
|
||||
va_list ap;
|
||||
va_start(ap, req);
|
||||
ret = OsIoctl(fd, req, ap);
|
||||
va_end(ap);
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -176,6 +176,28 @@ int access(const char *path, int mode)
|
|||
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,
|
||||
|
@ -295,4 +317,13 @@ 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
|
||||
|
|
|
@ -148,13 +148,25 @@ 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, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, req);
|
||||
int ret;
|
||||
ret = LOS_Ioctl(fd, req, ap);
|
||||
va_end(ap);
|
||||
va_list vaList;
|
||||
|
||||
va_start(vaList, req);
|
||||
ret = OsIoctl(fd, req, vaList);
|
||||
va_end(vaList);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -247,4 +259,13 @@ int remove(const char *filename)
|
|||
return -1;
|
||||
}
|
||||
|
||||
int fcntl(int fd, int cmd, ...)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int ioctl(int fd, int req, ...)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -90,6 +90,7 @@ static BOOL PosixFsFuncTestSuiteTearDown(void)
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
#if (LOSCFG_LIBC_MUSL == 1)
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_FS_DIRNAME_001
|
||||
* @tc.name dirname basic function test
|
||||
|
@ -162,6 +163,7 @@ LITE_TEST_CASE(PosixFsFuncTestSuite, testFsDirname004, Function | MediumTest | L
|
|||
TEST_ASSERT_EQUAL_STRING(".", workDir);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_FS_FOPEN_FCLOSE_001
|
||||
|
@ -1443,7 +1445,7 @@ LITE_TEST_CASE(PosixFsFuncTestSuite, testFsUnlink001, Function | MediumTest | Le
|
|||
char tmpFileName[]= FILE1;
|
||||
|
||||
fd = open(tmpFileName, O_CREAT | O_RDWR, 0777);
|
||||
TEST_ASSERT_TRUE(ret != -1);
|
||||
TEST_ASSERT_TRUE(fd != -1);
|
||||
|
||||
(void)close(fd);
|
||||
|
||||
|
@ -1454,7 +1456,7 @@ LITE_TEST_CASE(PosixFsFuncTestSuite, testFsUnlink001, Function | MediumTest | Le
|
|||
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_FS_STAT_001
|
||||
* @tc.name unlink
|
||||
* @tc.name stat
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PosixFsFuncTestSuite, testFsStat001, Function | MediumTest | Level1)
|
||||
|
@ -1466,7 +1468,7 @@ LITE_TEST_CASE(PosixFsFuncTestSuite, testFsStat001, Function | MediumTest | Leve
|
|||
|
||||
remove(FILE1);
|
||||
fd = open(tmpFileName, O_CREAT | O_RDWR, 0777);
|
||||
TEST_ASSERT_TRUE(ret != -1);
|
||||
TEST_ASSERT_TRUE(fd != -1);
|
||||
|
||||
(void)close(fd);
|
||||
|
||||
|
@ -1477,7 +1479,7 @@ LITE_TEST_CASE(PosixFsFuncTestSuite, testFsStat001, Function | MediumTest | Leve
|
|||
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_FS_STAT_002
|
||||
* @tc.name unlink
|
||||
* @tc.name stat
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PosixFsFuncTestSuite, testFsStat002, Function | MediumTest | Level1)
|
||||
|
@ -1491,7 +1493,7 @@ LITE_TEST_CASE(PosixFsFuncTestSuite, testFsStat002, Function | MediumTest | Leve
|
|||
|
||||
remove(FILE1);
|
||||
fd = open(tmpFileName, O_CREAT | O_RDWR, 0777);
|
||||
TEST_ASSERT_TRUE(ret != -1);
|
||||
TEST_ASSERT_TRUE(fd != -1);
|
||||
|
||||
size = write(fd, writeBuf, sizeof(writeBuf));
|
||||
TEST_ASSERT_TRUE(ret != -1);
|
||||
|
@ -1507,7 +1509,7 @@ LITE_TEST_CASE(PosixFsFuncTestSuite, testFsStat002, Function | MediumTest | Leve
|
|||
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_FS_STAT_003
|
||||
* @tc.name unlink
|
||||
* @tc.name stat
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PosixFsFuncTestSuite, testFsStat003, Function | MediumTest | Level1)
|
||||
|
@ -1521,7 +1523,7 @@ LITE_TEST_CASE(PosixFsFuncTestSuite, testFsStat003, Function | MediumTest | Leve
|
|||
|
||||
(void)memset_s(&buf, sizeof(buf), 0, sizeof(buf));
|
||||
fd = open(tmpFileName, O_CREAT | O_RDWR, 0777);
|
||||
TEST_ASSERT_TRUE(ret != -1);
|
||||
TEST_ASSERT_TRUE(fd != -1);
|
||||
|
||||
size = write(fd, writeBuf, sizeof(writeBuf));
|
||||
TEST_ASSERT_TRUE(ret != -1);
|
||||
|
@ -1541,7 +1543,7 @@ extern off_t lseek(int fd, off_t offset, int whence);
|
|||
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_FS_WRITE_001
|
||||
* @tc.name unlink
|
||||
* @tc.name write
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PosixFsFuncTestSuite, testFsWrite001, Function | MediumTest | Level1)
|
||||
|
@ -1557,7 +1559,7 @@ LITE_TEST_CASE(PosixFsFuncTestSuite, testFsWrite001, Function | MediumTest | Lev
|
|||
}
|
||||
|
||||
fd = open(tmpFileName, O_CREAT | O_RDWR, 0777);
|
||||
TEST_ASSERT_TRUE(ret != -1);
|
||||
TEST_ASSERT_TRUE(fd != -1);
|
||||
|
||||
ret = write(fd, writeBuf, TEST_RW_SIZE);
|
||||
TEST_ASSERT_TRUE(ret != -1);
|
||||
|
@ -1577,7 +1579,7 @@ LITE_TEST_CASE(PosixFsFuncTestSuite, testFsWrite001, Function | MediumTest | Lev
|
|||
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_FS_WRITE_002
|
||||
* @tc.name unlink
|
||||
* @tc.name write
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PosixFsFuncTestSuite, testFsWrite002, Function | MediumTest | Level1)
|
||||
|
@ -1591,7 +1593,7 @@ LITE_TEST_CASE(PosixFsFuncTestSuite, testFsWrite002, Function | MediumTest | Lev
|
|||
|
||||
remove(FILE1);
|
||||
fd = open(tmpFileName, O_CREAT | O_RDWR, 0777);
|
||||
TEST_ASSERT_TRUE(ret != -1);
|
||||
TEST_ASSERT_TRUE(fd != -1);
|
||||
|
||||
for (i = 0; i < TEST_LOOPUP_TIME; i++) {
|
||||
ret = write(fd, writeBuf, sizeof(writeBuf));
|
||||
|
@ -1607,6 +1609,34 @@ LITE_TEST_CASE(PosixFsFuncTestSuite, testFsWrite002, Function | MediumTest | Lev
|
|||
return 0;
|
||||
}
|
||||
|
||||
#if (LOSCFG_LIBC_MUSL == 1)
|
||||
/* *
|
||||
* @tc.number SUB_KERNEL_FS_FCNTL_001
|
||||
* @tc.name fcntl
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PosixFsFuncTestSuite, testFsFcntl001, Function | MediumTest | Level1)
|
||||
{
|
||||
int fd = 0;
|
||||
int flags = 0;
|
||||
char tmpFileName[]= FILE1;
|
||||
|
||||
fd = open(tmpFileName, O_CREAT | O_RDWR, 0777);
|
||||
TEST_ASSERT_TRUE(fd != -1);
|
||||
|
||||
flags = fcntl(fd, F_GETFL);
|
||||
TEST_ASSERT_TRUE(flags == O_CREAT | O_RDWR);
|
||||
|
||||
fcntl(fd, F_SETFL, flags | O_APPEND);
|
||||
flags = fcntl(fd, F_GETFL);
|
||||
TEST_ASSERT_TRUE(flags == O_CREAT | O_RDWR | O_APPEND);
|
||||
|
||||
(void)close(fd);
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
RUN_TEST_SUITE(PosixFsFuncTestSuite);
|
||||
|
||||
void PosixFsFuncTest()
|
||||
|
@ -1621,12 +1651,13 @@ void PosixFsFuncTest()
|
|||
|
||||
RUN_ONE_TESTCASE(testFsWrite001);
|
||||
RUN_ONE_TESTCASE(testFsWrite002);
|
||||
|
||||
#if (LOSCFG_LIBC_MUSL == 1)
|
||||
RUN_ONE_TESTCASE(testFsDirname001);
|
||||
RUN_ONE_TESTCASE(testFsDirname002);
|
||||
RUN_ONE_TESTCASE(testFsDirname003);
|
||||
RUN_ONE_TESTCASE(testFsDirname004);
|
||||
|
||||
RUN_ONE_TESTCASE(testFsFcntl001);
|
||||
#endif
|
||||
RUN_ONE_TESTCASE(testFsReaddir001);
|
||||
RUN_ONE_TESTCASE(testFsReaddir002);
|
||||
|
||||
|
@ -1688,6 +1719,5 @@ void PosixFsFuncTest()
|
|||
RUN_ONE_TESTCASE(testFsFreadFwrite007);
|
||||
RUN_ONE_TESTCASE(testFsFreadFwrite008);
|
||||
RUN_ONE_TESTCASE(testFsFreadFwrite009);
|
||||
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
|
||||
#include "ohos_types.h"
|
||||
#include "posix_test.h"
|
||||
#include "log.h"
|
||||
#include "los_config.h"
|
||||
#include "kernel_test.h"
|
||||
#include <ctype.h>
|
||||
|
|
Loading…
Reference in New Issue