提交 1d353ad4 编写于 作者: F Far

feat: 增加mount的MS_RDONLY标志的支持

增加mount的MS_RDONLY标志的支持,并修改vfs主要接口相关支持

Close #I3Z1W6
Signed-off-by: NFar <yesiyuan2@huawei.com>
上级 d774692e
......@@ -255,6 +255,7 @@ int mount(const char *source, const char *target,
#endif
mnt = MountAlloc(mountpt_vnode, (struct MountOps*)mops);
mnt->mountFlags = mountflags;
mountpt_vnode->useCount++;
ret = mops->Mount(mnt, device, data);
......@@ -280,7 +281,6 @@ int mount(const char *source, const char *target,
mnt->vnodeBeCovered->flag |= VNODE_FLAG_MOUNT_ORIGIN;
mnt->vnodeCovered->flag |= VNODE_FLAG_MOUNT_NEW;
mnt->ops = mops;
mnt->mountFlags = mountflags;
if (target && (strlen(target) != 0))
{
ret = strcpy_s(mnt->pathName, PATH_MAX, target);
......
......@@ -38,6 +38,7 @@ int do_link(int oldfd, const char *oldpath, int newfd, const char *newpath, int
struct Vnode *new_parent_vnode = NULL;
struct Vnode *new_vnode = NULL;
struct Vnode *old_vnode = NULL;
struct Mount *mount = NULL;
char *fulloldpath = NULL;
char *fullnewpath = NULL;
char *newname = NULL;
......@@ -91,6 +92,13 @@ int do_link(int oldfd, const char *oldpath, int newfd, const char *newpath, int
}
}
mount = old_vnode->originMount;
if ((mount != NULL) && (mount->mountFlags & MS_RDONLY))
{
ret = -EROFS;
goto errout_with_vnode;
}
if (old_vnode->type != VNODE_TYPE_REG && old_vnode->type != VNODE_TYPE_LNK)
{
ret = -EPERM;
......
......@@ -54,6 +54,7 @@ int do_mkdir(int dirfd, const char *pathname, mode_t mode)
{
struct Vnode *parentVnode = NULL;
struct Vnode *vnode = NULL;
struct Mount *mount = NULL;
int ret;
char *fullpath = NULL;
char *relativepath = NULL;
......@@ -109,6 +110,13 @@ int do_mkdir(int dirfd, const char *pathname, mode_t mode)
ret = -ENOENT;
goto errout_with_lock;
}
mount = parentVnode->originMount;
if ((mount != NULL) && (mount->mountFlags & MS_RDONLY))
{
ret = -EROFS;
goto errout_with_lock;
}
parentVnode->useCount++;
if (VfsVnodePermissionCheck(parentVnode, (WRITE_OP | EXEC_OP)))
......
......@@ -177,7 +177,8 @@ int fp_open(int dirfd, const char *path, int oflags, mode_t mode)
goto errout;
}
#ifdef LOSCFG_FS_VFS_BLOCK_DEVICE
if (vnode->type == VNODE_TYPE_BLK) {
if (vnode->type == VNODE_TYPE_BLK)
{
VnodeDrop();
fd = block_proxy(fullpath, oflags);
if (fd < 0)
......@@ -186,8 +187,15 @@ int fp_open(int dirfd, const char *path, int oflags, mode_t mode)
goto errout;
}
return fd;
}
}
#endif
if ((vnode->originMount) && (vnode->originMount->mountFlags & MS_RDONLY) &&
(((oflags & O_ACCMODE) != O_RDONLY) || (oflags & O_TRUNC)))
{
ret = -EROFS;
VnodeDrop();
goto errout;
}
if ((oflags & O_CREAT) && (oflags & O_EXCL))
{
ret = -EEXIST;
......@@ -212,6 +220,12 @@ int fp_open(int dirfd, const char *path, int oflags, mode_t mode)
if ((ret != OK) && (oflags & O_CREAT) && vnode)
{
/* if file not exist, but parent dir of the file is exist */
if ((vnode->originMount) && (vnode->originMount->mountFlags & MS_RDONLY))
{
ret = -EROFS;
VnodeDrop();
goto errout;
}
if (VfsVnodePermissionCheck(vnode, (WRITE_OP | EXEC_OP)))
{
ret = -EACCES;
......
......@@ -58,6 +58,10 @@ static int check_rename_target(struct Vnode *old_vnode, struct Vnode *old_parent
{
return -ENOENT;
}
if ((new_parent_vnode->originMount) && (new_parent_vnode->originMount->mountFlags & MS_RDONLY))
{
return -EROFS;
}
if (old_vnode->type != VNODE_TYPE_DIR && old_vnode->type != VNODE_TYPE_REG)
{
return -EACCES;
......
......@@ -46,16 +46,23 @@
#include "sys/stat.h"
#include "string.h"
#include "limits.h"
#include "fs/mount.h"
/****************************************************************************
* Private Functions
****************************************************************************/
static int check_target(struct Vnode *vnode, char *name) {
static int check_target(struct Vnode *vnode, char *name)
{
if (vnode == NULL)
{
return -ENOENT;
}
if ((vnode->originMount) && (vnode->originMount->mountFlags & MS_RDONLY))
{
return -EROFS;
}
if (vnode->type != VNODE_TYPE_DIR)
{
return -ENOTDIR;
......
......@@ -93,6 +93,7 @@ int do_symlink(const char *target, int newfd, const char *path)
struct Vnode *new_vnode = NULL;
char *fullpath = NULL;
char *newname = NULL;
struct Mount *mount = NULL;
int ret;
if (!path)
......@@ -134,6 +135,12 @@ int do_symlink(const char *target, int newfd, const char *path)
ret = -ENOSYS;
goto errout_with_vnode;
}
mount = parent_vnode->originMount;
if ((mount != NULL) && (mount->mountFlags & MS_RDONLY))
{
ret = -EROFS;
goto errout_with_vnode;
}
parent_vnode->useCount++;
ret = parent_vnode->vop->Symlink(parent_vnode, &new_vnode, (const char *)newname, (const char *)target);
......
......@@ -45,6 +45,7 @@
#include "vnode.h"
#include "stdlib.h"
#include "fs/mount.h"
/****************************************************************************
* Private Functions
......@@ -56,6 +57,11 @@ static int check_target(struct Vnode *vnode)
return -EISDIR;
}
if ((vnode->originMount) && (vnode->originMount->mountFlags & MS_RDONLY))
{
return -EROFS;
}
if (vnode->useCount > 0)
{
return -EBUSY;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册