feat: 增加mount的MS_RDONLY标志的支持
增加mount的MS_RDONLY标志的支持,并修改vfs主要接口相关支持。 1. fatfs lseek接口在分区以MS_RDONLY方式和文件以只读打开时不再能够扩大文件的大小。 2. 直接在镜像中创建storage目录,而不是在挂载根文件系统时创建storage目录。 3. 增加了MS_RDONLY的测试用例。 Close #I3Z1W6 Signed-off-by: Far <yesiyuan2@huawei.com>
This commit is contained in:
parent
9d3e872454
commit
8729f6ee57
|
@ -46,6 +46,7 @@
|
||||||
#include "los_tables.h"
|
#include "los_tables.h"
|
||||||
#include "user_copy.h"
|
#include "user_copy.h"
|
||||||
#include "los_vm_filemap.h"
|
#include "los_vm_filemap.h"
|
||||||
|
#include "los_hash.h"
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
|
@ -53,7 +54,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include "los_hash.h"
|
#include <fcntl.h>
|
||||||
|
|
||||||
|
|
||||||
struct VnodeOps fatfs_vops; /* forward define */
|
struct VnodeOps fatfs_vops; /* forward define */
|
||||||
|
@ -190,7 +191,7 @@ static int fatfs_sync(unsigned long mountflags, FATFS *fs)
|
||||||
{
|
{
|
||||||
#ifdef LOSCFG_FS_FAT_CACHE
|
#ifdef LOSCFG_FS_FAT_CACHE
|
||||||
los_part *part = NULL;
|
los_part *part = NULL;
|
||||||
if (mountflags != MS_NOSYNC) {
|
if (!(mountflags & (MS_NOSYNC | MS_RDONLY))) {
|
||||||
part = get_part((INT)fs->pdrv);
|
part = get_part((INT)fs->pdrv);
|
||||||
if (part == NULL) {
|
if (part == NULL) {
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
|
@ -736,6 +737,7 @@ off64_t fatfs_lseek64(struct file *filep, off64_t offset, int whence)
|
||||||
struct Vnode *vp = filep->f_vnode;
|
struct Vnode *vp = filep->f_vnode;
|
||||||
DIR_FILE *dfp = (DIR_FILE *)vp->data;
|
DIR_FILE *dfp = (DIR_FILE *)vp->data;
|
||||||
FILINFO *finfo = &(dfp->fno);
|
FILINFO *finfo = &(dfp->fno);
|
||||||
|
struct Mount *mount = vp->originMount;
|
||||||
FSIZE_t fpos;
|
FSIZE_t fpos;
|
||||||
FRESULT result;
|
FRESULT result;
|
||||||
int ret;
|
int ret;
|
||||||
|
@ -773,6 +775,17 @@ off64_t fatfs_lseek64(struct file *filep, off64_t offset, int whence)
|
||||||
if (ret == FALSE) {
|
if (ret == FALSE) {
|
||||||
return -EBUSY;
|
return -EBUSY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (fpos > finfo->fsize) {
|
||||||
|
if ((filep->f_oflags & O_ACCMODE) == O_RDONLY) {
|
||||||
|
result = FR_DENIED;
|
||||||
|
goto ERROR_EXIT;
|
||||||
|
}
|
||||||
|
if (mount->mountFlags & MS_RDONLY) {
|
||||||
|
result = FR_WRITE_PROTECTED;
|
||||||
|
goto ERROR_EXIT;
|
||||||
|
}
|
||||||
|
}
|
||||||
fp->obj.sclust = finfo->sclst;
|
fp->obj.sclust = finfo->sclst;
|
||||||
fp->obj.objsize = finfo->fsize;
|
fp->obj.objsize = finfo->fsize;
|
||||||
|
|
||||||
|
|
|
@ -123,7 +123,7 @@ int VfsJffs2Bind(struct Mount *mnt, struct Vnode *blkDriver, const void *data)
|
||||||
|
|
||||||
partNo = p->patitionnum;
|
partNo = p->patitionnum;
|
||||||
|
|
||||||
ret = jffs2_mount(partNo, &rootNode);
|
ret = jffs2_mount(partNo, &rootNode, mnt->mountFlags);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
LOS_MuxUnlock(&g_jffs2FsLock);
|
LOS_MuxUnlock(&g_jffs2FsLock);
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
@ -41,6 +41,8 @@
|
||||||
#include "stdlib.h"
|
#include "stdlib.h"
|
||||||
#include "sys/stat.h"
|
#include "sys/stat.h"
|
||||||
#include "vnode.h"
|
#include "vnode.h"
|
||||||
|
#include "fs/mount.h"
|
||||||
|
#include <fcntl.h>
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Static Functions
|
* Static Functions
|
||||||
|
@ -69,6 +71,11 @@ int chattr(const char *pathname, struct IATTR *attr)
|
||||||
goto errout_with_lock;
|
goto errout_with_lock;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((vnode->originMount) && (vnode->originMount->mountFlags & MS_RDONLY)) {
|
||||||
|
ret = -EROFS;
|
||||||
|
goto errout_with_lock;
|
||||||
|
}
|
||||||
|
|
||||||
/* The way we handle the stat depends on the type of vnode that we
|
/* The way we handle the stat depends on the type of vnode that we
|
||||||
* are dealing with.
|
* are dealing with.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -37,9 +37,11 @@
|
||||||
#include "vfs_config.h"
|
#include "vfs_config.h"
|
||||||
#include "sys/stat.h"
|
#include "sys/stat.h"
|
||||||
#include "vnode.h"
|
#include "vnode.h"
|
||||||
|
#include "fs/mount.h"
|
||||||
#include "string.h"
|
#include "string.h"
|
||||||
#include "stdlib.h"
|
#include "stdlib.h"
|
||||||
#include "utime.h"
|
#include "utime.h"
|
||||||
|
#include <fcntl.h>
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Global Functions
|
* Global Functions
|
||||||
|
@ -79,6 +81,12 @@ int utime(const char *path, const struct utimbuf *ptimes)
|
||||||
goto errout_with_path;
|
goto errout_with_path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((vnode->originMount) && (vnode->originMount->mountFlags & MS_RDONLY)) {
|
||||||
|
VnodeDrop();
|
||||||
|
ret = -EROFS;
|
||||||
|
goto errout_with_path;
|
||||||
|
}
|
||||||
|
|
||||||
if (vnode->vop && vnode->vop->Chattr) {
|
if (vnode->vop && vnode->vop->Chattr) {
|
||||||
if (ptimes == NULL) {
|
if (ptimes == NULL) {
|
||||||
/* get current seconds */
|
/* get current seconds */
|
||||||
|
|
|
@ -156,10 +156,11 @@ STATIC INT32 AddPartitions(CHAR *dev, UINT64 rootAddr, UINT64 rootSize, UINT64 u
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
STATIC INT32 ParseRootArgs(CHAR **dev, CHAR **fstype, UINT64 *rootAddr, UINT64 *rootSize) {
|
STATIC INT32 ParseRootArgs(CHAR **dev, CHAR **fstype, UINT64 *rootAddr, UINT64 *rootSize, UINT32 *mountFlags) {
|
||||||
INT32 ret;
|
INT32 ret;
|
||||||
CHAR *rootAddrStr;
|
CHAR *rootAddrStr;
|
||||||
CHAR *rootSizeStr;
|
CHAR *rootSizeStr;
|
||||||
|
CHAR *rwTag;
|
||||||
|
|
||||||
ret = LOS_GetArgValue("root", dev);
|
ret = LOS_GetArgValue("root", dev);
|
||||||
if (ret != LOS_OK) {
|
if (ret != LOS_OK) {
|
||||||
|
@ -186,6 +187,13 @@ STATIC INT32 ParseRootArgs(CHAR **dev, CHAR **fstype, UINT64 *rootAddr, UINT64 *
|
||||||
} else {
|
} else {
|
||||||
*rootSize = LOS_SizeStrToNum(rootSizeStr);
|
*rootSize = LOS_SizeStrToNum(rootSizeStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ret = LOS_GetArgValue("ro", &rwTag);
|
||||||
|
if (ret == LOS_OK) {
|
||||||
|
*mountFlags = MS_RDONLY;
|
||||||
|
} else {
|
||||||
|
*mountFlags = 0;
|
||||||
|
}
|
||||||
|
|
||||||
return LOS_OK;
|
return LOS_OK;
|
||||||
}
|
}
|
||||||
|
@ -212,12 +220,12 @@ STATIC INT32 ParseUserArgs(UINT64 rootAddr, UINT64 rootSize, UINT64 *userAddr, U
|
||||||
return LOS_OK;
|
return LOS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC INT32 MountPartitions(CHAR *fsType) {
|
STATIC INT32 MountPartitions(CHAR *fsType, UINT32 mountFlags) {
|
||||||
INT32 ret;
|
INT32 ret;
|
||||||
INT32 err;
|
INT32 err;
|
||||||
|
|
||||||
/* Mount rootfs */
|
/* Mount rootfs */
|
||||||
ret = mount(ROOT_DEV_NAME, ROOT_DIR_NAME, fsType, MS_RDONLY, NULL);
|
ret = mount(ROOT_DEV_NAME, ROOT_DIR_NAME, fsType, mountFlags, NULL);
|
||||||
if (ret != LOS_OK) {
|
if (ret != LOS_OK) {
|
||||||
err = get_errno();
|
err = get_errno();
|
||||||
PRINT_ERR("Failed to mount %s, rootDev %s, errno %d: %s\n", ROOT_DIR_NAME, ROOT_DEV_NAME, err, strerror(err));
|
PRINT_ERR("Failed to mount %s, rootDev %s, errno %d: %s\n", ROOT_DIR_NAME, ROOT_DEV_NAME, err, strerror(err));
|
||||||
|
@ -291,8 +299,9 @@ INT32 OsMountRootfs() {
|
||||||
UINT64 rootSize;
|
UINT64 rootSize;
|
||||||
UINT64 userAddr;
|
UINT64 userAddr;
|
||||||
UINT64 userSize;
|
UINT64 userSize;
|
||||||
|
UINT32 mountFlags;
|
||||||
|
|
||||||
ret = ParseRootArgs(&dev, &fstype, &rootAddr, &rootSize);
|
ret = ParseRootArgs(&dev, &fstype, &rootAddr, &rootSize, &mountFlags);
|
||||||
if (ret != LOS_OK) {
|
if (ret != LOS_OK) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -312,7 +321,7 @@ INT32 OsMountRootfs() {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = MountPartitions(fstype);
|
ret = MountPartitions(fstype, mountFlags);
|
||||||
if (ret != LOS_OK) {
|
if (ret != LOS_OK) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -790,6 +790,9 @@ sources_full = [
|
||||||
"jffs/full/It_vfs_test_symlink_002.cpp",
|
"jffs/full/It_vfs_test_symlink_002.cpp",
|
||||||
"jffs/full/It_vfs_test_symlink_003.cpp",
|
"jffs/full/It_vfs_test_symlink_003.cpp",
|
||||||
"jffs/full/It_vfs_test_symlinkat_001.cpp",
|
"jffs/full/It_vfs_test_symlinkat_001.cpp",
|
||||||
|
"jffs/full/It_vfs_test_mount_rdonly_001.cpp",
|
||||||
|
"jffs/full/It_vfs_test_mount_rdonly_002.cpp",
|
||||||
|
"jffs/full/It_vfs_test_mount_rdonly_003.cpp",
|
||||||
]
|
]
|
||||||
|
|
||||||
if (LOSCFG_USER_TEST_LEVEL >= TEST_LEVEL_LOW) {
|
if (LOSCFG_USER_TEST_LEVEL >= TEST_LEVEL_LOW) {
|
||||||
|
|
|
@ -962,6 +962,9 @@ VOID ItFsTestSymlink001(VOID);
|
||||||
VOID ItFsTestSymlink002(VOID);
|
VOID ItFsTestSymlink002(VOID);
|
||||||
VOID ItFsTestSymlink003(VOID);
|
VOID ItFsTestSymlink003(VOID);
|
||||||
VOID ItFsTestSymlinkat001(VOID);
|
VOID ItFsTestSymlinkat001(VOID);
|
||||||
|
VOID ItFsTestMountRdonly001(VOID);
|
||||||
|
VOID ItFsTestMountRdonly002(VOID);
|
||||||
|
VOID ItFsTestMountRdonly003(VOID);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(LOSCFG_USER_TESTSUIT_SHELL)
|
#if defined(LOSCFG_USER_TESTSUIT_SHELL)
|
||||||
|
|
|
@ -0,0 +1,93 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2021-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without modification,
|
||||||
|
* are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||||
|
* conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||||
|
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||||
|
* provided with the distribution.
|
||||||
|
*
|
||||||
|
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||||
|
* to endorse or promote products derived from this software without specific prior written
|
||||||
|
* permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||||
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||||
|
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||||
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||||
|
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||||
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "It_vfs_jffs.h"
|
||||||
|
|
||||||
|
static UINT32 testcase(VOID)
|
||||||
|
{
|
||||||
|
INT32 fd = -1;
|
||||||
|
INT32 ret;
|
||||||
|
CHAR pathname1[JFFS_STANDARD_NAME_LENGTH] = { JFFS_PATH_NAME0 };
|
||||||
|
CHAR pathname2[JFFS_STANDARD_NAME_LENGTH] = { JFFS_PATH_NAME01 };
|
||||||
|
|
||||||
|
fd = creat(pathname1, 0777);
|
||||||
|
ICUNIT_GOTO_NOT_EQUAL(fd, JFFS_IS_ERROR, fd, EXIT);
|
||||||
|
|
||||||
|
ret = close(fd);
|
||||||
|
ICUNIT_GOTO_EQUAL(ret, JFFS_NO_ERROR, ret, EXIT4);
|
||||||
|
|
||||||
|
ret = umount(JFFS_MAIN_DIR0);
|
||||||
|
ICUNIT_GOTO_NOT_EQUAL(ret, JFFS_IS_ERROR, ret, EXIT3);
|
||||||
|
|
||||||
|
ret = mount(JFFS_DEV_PATH0, JFFS_MAIN_DIR0, JFFS_FILESYS_TYPE, MS_RDONLY, NULL);
|
||||||
|
ICUNIT_GOTO_NOT_EQUAL(ret, JFFS_IS_ERROR, ret, EXIT2);
|
||||||
|
|
||||||
|
fd = open(pathname1, O_RDWR);
|
||||||
|
ICUNIT_GOTO_EQUAL(fd, JFFS_IS_ERROR, fd, EXIT4);
|
||||||
|
|
||||||
|
ret = symlink(pathname1, pathname2);
|
||||||
|
ICUNIT_GOTO_EQUAL(ret, JFFS_IS_ERROR, ret, EXIT5);
|
||||||
|
|
||||||
|
ret = rename(pathname1, pathname2);
|
||||||
|
ICUNIT_GOTO_EQUAL(ret, JFFS_IS_ERROR, ret, EXIT5);
|
||||||
|
|
||||||
|
ret = unlink(pathname1);
|
||||||
|
ICUNIT_GOTO_EQUAL(ret, JFFS_IS_ERROR, ret, EXIT3);
|
||||||
|
|
||||||
|
ret = umount(JFFS_MAIN_DIR0);
|
||||||
|
ICUNIT_GOTO_NOT_EQUAL(ret, JFFS_IS_ERROR, ret, EXIT3);
|
||||||
|
|
||||||
|
ret = mount(JFFS_DEV_PATH0, JFFS_MAIN_DIR0, JFFS_FILESYS_TYPE, 0, NULL);
|
||||||
|
ICUNIT_GOTO_NOT_EQUAL(ret, JFFS_IS_ERROR, ret, EXIT2);
|
||||||
|
|
||||||
|
ret = unlink(pathname1);
|
||||||
|
ICUNIT_GOTO_NOT_EQUAL(ret, JFFS_IS_ERROR, ret, EXIT1);
|
||||||
|
|
||||||
|
return JFFS_NO_ERROR;
|
||||||
|
|
||||||
|
EXIT5:
|
||||||
|
unlink(pathname2);
|
||||||
|
goto EXIT3;
|
||||||
|
EXIT4:
|
||||||
|
close(fd);
|
||||||
|
EXIT3:
|
||||||
|
umount(JFFS_MAIN_DIR0);
|
||||||
|
EXIT2:
|
||||||
|
mount(JFFS_DEV_PATH0, JFFS_MAIN_DIR0, JFFS_FILESYS_TYPE, 0, NULL);
|
||||||
|
EXIT1:
|
||||||
|
unlink(pathname1);
|
||||||
|
EXIT:
|
||||||
|
return JFFS_NO_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
VOID ItFsTestMountRdonly001(VOID)
|
||||||
|
{
|
||||||
|
TEST_ADD_CASE("IT_FS_TEST_MOUNT_RDONLY_001", testcase, TEST_VFS, TEST_JFFS, TEST_LEVEL0, TEST_FUNCTION);
|
||||||
|
}
|
|
@ -0,0 +1,79 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2021-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without modification,
|
||||||
|
* are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||||
|
* conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||||
|
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||||
|
* provided with the distribution.
|
||||||
|
*
|
||||||
|
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||||
|
* to endorse or promote products derived from this software without specific prior written
|
||||||
|
* permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||||
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||||
|
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||||
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||||
|
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||||
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "It_vfs_jffs.h"
|
||||||
|
|
||||||
|
static UINT32 testcase(VOID)
|
||||||
|
{
|
||||||
|
INT32 fd = -1;
|
||||||
|
INT32 ret;
|
||||||
|
CHAR pathname1[JFFS_STANDARD_NAME_LENGTH] = { JFFS_PATH_NAME0 };
|
||||||
|
|
||||||
|
ret = umount(JFFS_MAIN_DIR0);
|
||||||
|
ICUNIT_GOTO_NOT_EQUAL(ret, JFFS_IS_ERROR, ret, EXIT);
|
||||||
|
|
||||||
|
ret = mount(JFFS_DEV_PATH0, JFFS_MAIN_DIR0, JFFS_FILESYS_TYPE, MS_RDONLY, NULL);
|
||||||
|
ICUNIT_GOTO_NOT_EQUAL(ret, JFFS_IS_ERROR, ret, EXIT1);
|
||||||
|
|
||||||
|
fd = creat(pathname1, 0755);
|
||||||
|
ICUNIT_GOTO_EQUAL(fd, JFFS_IS_ERROR, fd, EXIT3);
|
||||||
|
|
||||||
|
fd = open(pathname1, O_CREAT | O_RDONLY, 0755);
|
||||||
|
ICUNIT_GOTO_EQUAL(fd, JFFS_IS_ERROR, fd, EXIT3);
|
||||||
|
|
||||||
|
fd = open(pathname1, O_CREAT | O_RDWR, 0755);
|
||||||
|
ICUNIT_GOTO_EQUAL(fd, JFFS_IS_ERROR, fd, EXIT3);
|
||||||
|
|
||||||
|
ret = mkdir(pathname1, 0755);
|
||||||
|
ICUNIT_GOTO_EQUAL(ret, JFFS_IS_ERROR, ret, EXIT2);
|
||||||
|
|
||||||
|
ret = umount(JFFS_MAIN_DIR0);
|
||||||
|
ICUNIT_GOTO_NOT_EQUAL(ret, JFFS_IS_ERROR, ret, EXIT1);
|
||||||
|
|
||||||
|
ret = mount(JFFS_DEV_PATH0, JFFS_MAIN_DIR0, JFFS_FILESYS_TYPE, 0, NULL);
|
||||||
|
ICUNIT_GOTO_NOT_EQUAL(ret, JFFS_IS_ERROR, ret, EXIT1);
|
||||||
|
|
||||||
|
return JFFS_NO_ERROR;
|
||||||
|
|
||||||
|
EXIT3:
|
||||||
|
close(fd);
|
||||||
|
EXIT2:
|
||||||
|
remove(pathname1);
|
||||||
|
EXIT1:
|
||||||
|
umount(JFFS_MAIN_DIR0);
|
||||||
|
mount(JFFS_DEV_PATH0, JFFS_MAIN_DIR0, JFFS_FILESYS_TYPE, 0, NULL);
|
||||||
|
EXIT:
|
||||||
|
return JFFS_NO_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
VOID ItFsTestMountRdonly002(VOID)
|
||||||
|
{
|
||||||
|
TEST_ADD_CASE("IT_FS_TEST_MOUNT_RDONLY_002", testcase, TEST_VFS, TEST_JFFS, TEST_LEVEL0, TEST_FUNCTION);
|
||||||
|
}
|
|
@ -0,0 +1,95 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2021-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without modification,
|
||||||
|
* are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||||
|
* conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||||
|
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||||
|
* provided with the distribution.
|
||||||
|
*
|
||||||
|
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||||
|
* to endorse or promote products derived from this software without specific prior written
|
||||||
|
* permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||||
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||||
|
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||||
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||||
|
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||||
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "It_vfs_jffs.h"
|
||||||
|
|
||||||
|
static UINT32 testcase(VOID)
|
||||||
|
{
|
||||||
|
INT32 fd = -1;
|
||||||
|
INT32 ret;
|
||||||
|
CHAR readbuf[JFFS_STANDARD_NAME_LENGTH] = {0};
|
||||||
|
const CHAR writebuf[JFFS_STANDARD_NAME_LENGTH] = "0123456789";
|
||||||
|
CHAR pathname1[JFFS_STANDARD_NAME_LENGTH] = { JFFS_PATH_NAME0 };
|
||||||
|
|
||||||
|
fd = creat(pathname1, 0777);
|
||||||
|
ICUNIT_GOTO_NOT_EQUAL(fd, JFFS_IS_ERROR, fd, EXIT);
|
||||||
|
|
||||||
|
ret = write(fd, writebuf, strlen(writebuf));
|
||||||
|
ICUNIT_GOTO_EQUAL(ret, strlen(writebuf), ret, EXIT4);
|
||||||
|
|
||||||
|
ret = close(fd);
|
||||||
|
ICUNIT_GOTO_EQUAL(ret, JFFS_NO_ERROR, ret, EXIT4);
|
||||||
|
|
||||||
|
ret = umount(JFFS_MAIN_DIR0);
|
||||||
|
ICUNIT_GOTO_NOT_EQUAL(ret, JFFS_IS_ERROR, ret, EXIT3);
|
||||||
|
|
||||||
|
ret = mount(JFFS_DEV_PATH0, JFFS_MAIN_DIR0, JFFS_FILESYS_TYPE, MS_RDONLY, NULL);
|
||||||
|
ICUNIT_GOTO_NOT_EQUAL(ret, JFFS_IS_ERROR, ret, EXIT2);
|
||||||
|
|
||||||
|
fd = open(pathname1, O_RDWR);
|
||||||
|
ICUNIT_GOTO_EQUAL(fd, JFFS_IS_ERROR, fd, EXIT4);
|
||||||
|
|
||||||
|
fd = open(pathname1, O_RDONLY);
|
||||||
|
ICUNIT_GOTO_NOT_EQUAL(fd, JFFS_IS_ERROR, fd, EXIT4);
|
||||||
|
|
||||||
|
ret = read(fd, readbuf, strlen(writebuf));
|
||||||
|
ICUNIT_GOTO_EQUAL(ret, strlen(writebuf), ret, EXIT4);
|
||||||
|
ICUNIT_GOTO_STRING_EQUAL(readbuf, writebuf, readbuf, EXIT4);
|
||||||
|
|
||||||
|
ret = close(fd);
|
||||||
|
ICUNIT_GOTO_NOT_EQUAL(ret, JFFS_IS_ERROR, ret, EXIT4);
|
||||||
|
|
||||||
|
ret = umount(JFFS_MAIN_DIR0);
|
||||||
|
ICUNIT_GOTO_NOT_EQUAL(ret, JFFS_IS_ERROR, ret, EXIT3);
|
||||||
|
|
||||||
|
ret = mount(JFFS_DEV_PATH0, JFFS_MAIN_DIR0, JFFS_FILESYS_TYPE, 0, NULL);
|
||||||
|
ICUNIT_GOTO_NOT_EQUAL(ret, JFFS_IS_ERROR, ret, EXIT2);
|
||||||
|
|
||||||
|
ret = unlink(pathname1);
|
||||||
|
ICUNIT_GOTO_NOT_EQUAL(ret, JFFS_IS_ERROR, ret, EXIT1);
|
||||||
|
|
||||||
|
return JFFS_NO_ERROR;
|
||||||
|
|
||||||
|
EXIT4:
|
||||||
|
close(fd);
|
||||||
|
EXIT3:
|
||||||
|
umount(JFFS_MAIN_DIR0);
|
||||||
|
EXIT2:
|
||||||
|
mount(JFFS_DEV_PATH0, JFFS_MAIN_DIR0, JFFS_FILESYS_TYPE, 0, NULL);
|
||||||
|
EXIT1:
|
||||||
|
unlink(pathname1);
|
||||||
|
EXIT:
|
||||||
|
return JFFS_NO_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
VOID ItFsTestMountRdonly003(VOID)
|
||||||
|
{
|
||||||
|
TEST_ADD_CASE("IT_FS_TEST_MOUNT_RDONLY_003", testcase, TEST_VFS, TEST_JFFS, TEST_LEVEL0, TEST_FUNCTION);
|
||||||
|
}
|
|
@ -6885,6 +6885,21 @@ HWTEST_F(VfsJffsTest, ItFsTestSymlinkat001, TestSize.Level0)
|
||||||
ItFsTestSymlinkat001();
|
ItFsTestSymlinkat001();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HWTEST_F(VfsJffsTest, ItFsTestMountRdonly001, TestSize.Level0)
|
||||||
|
{
|
||||||
|
ItFsTestMountRdonly001();
|
||||||
|
}
|
||||||
|
|
||||||
|
HWTEST_F(VfsJffsTest, ItFsTestMountRdonly002, TestSize.Level0)
|
||||||
|
{
|
||||||
|
ItFsTestMountRdonly002();
|
||||||
|
}
|
||||||
|
|
||||||
|
HWTEST_F(VfsJffsTest, ItFsTestMountRdonly003, TestSize.Level0)
|
||||||
|
{
|
||||||
|
ItFsTestMountRdonly003();
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
#if defined(LOSCFG_USER_TEST_SMOKE)
|
#if defined(LOSCFG_USER_TEST_SMOKE)
|
||||||
/* *
|
/* *
|
||||||
|
|
Loading…
Reference in New Issue