Skip to content
Snippets Groups Projects
Commit 823abc56 authored by Avi Kivity's avatar Avi Kivity
Browse files

vfs: fix flags conversion on open()


The vfs converts the read/write flags from 0/1/2 (read-only/write-only/rw) to
bit fields which are more easily testable.  But in doing so it corrupts the
other flags.

Fix FFLAGS and OFLAGS to preserve those other flags.  The test for a file
that is not readable or writable is dropped, since it is impossible to fail.

Signed-off-by: default avatarAvi Kivity <avi@cloudius-systems.com>
parent cf5619f0
No related branches found
No related tags found
No related merge requests found
......@@ -65,9 +65,7 @@ sys_open(char *path, int flags, mode_t mode, struct file *fp)
DPRINTF(VFSDB_SYSCALL, ("sys_open: path=%s flags=%x mode=%x\n",
path, flags, mode));
flags = FFLAGS(flags);
if ((flags & (FREAD | FWRITE)) == 0)
return EINVAL;
flags = fflags(flags);
if (flags & O_CREAT) {
error = namei(path, &dp);
if (error == ENOENT) {
......
......@@ -9,6 +9,7 @@
#define OSV_FCNTL_H
#include <sys/cdefs.h>
#include <fcntl.h>
__BEGIN_DECLS
......@@ -20,8 +21,19 @@ __BEGIN_DECLS
#define FWRITE 0x00000002
/* convert from open() flags to/from fflags; convert O_RD/WR to FREAD/FWRITE */
#define FFLAGS(oflags) ((oflags) + 1)
#define OFLAGS(fflags) ((fflags) - 1)
static inline int fflags(int oflags)
{
int rw = oflags & O_ACCMODE;
oflags &= ~O_ACCMODE;
return (rw + 1) | oflags;
}
static inline int oflags(int fflags)
{
int rw = fflags & (FREAD|FWRITE);
fflags &= ~(FREAD|FWRITE);
return (rw - 1) | fflags;
}
__END_DECLS
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment