Commit d9165153caea9f342410ed3ac87cb68768ebec78

Authored by Simon Glass
Committed by Mike Frysinger
1 parent 7b06b66cd7

sandbox: add flags for open() call

This provides a way for callers to create files for writing. The flags
are translated at runtime, for the ones we support.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>

Showing 2 changed files with 33 additions and 8 deletions Side-by-side Diff

arch/sandbox/cpu/os.c
... ... @@ -58,9 +58,29 @@
58 58 return lseek(fd, offset, whence);
59 59 }
60 60  
61   -int os_open(const char *pathname, int flags)
  61 +int os_open(const char *pathname, int os_flags)
62 62 {
63   - return open(pathname, flags);
  63 + int flags;
  64 +
  65 + switch (os_flags & OS_O_MASK) {
  66 + case OS_O_RDONLY:
  67 + default:
  68 + flags = O_RDONLY;
  69 + break;
  70 +
  71 + case OS_O_WRONLY:
  72 + flags = O_WRONLY;
  73 + break;
  74 +
  75 + case OS_O_RDWR:
  76 + flags = O_RDWR;
  77 + break;
  78 + }
  79 +
  80 + if (os_flags & OS_O_CREAT)
  81 + flags |= O_CREAT;
  82 +
  83 + return open(pathname, flags, 0777);
64 84 }
65 85  
66 86 int os_close(int fd)
1 1 /*
  2 + * Operating System Interface
  3 + *
  4 + * This provides access to useful OS routines for the sandbox architecture.
  5 + * They are kept in a separate file so we can include system headers.
  6 + *
2 7 * Copyright (c) 2011 The Chromium OS Authors.
3 8 * See file CREDITS for list of people who contributed to this
4 9 * project.
... ... @@ -19,12 +24,6 @@
19 24 * MA 02111-1307 USA
20 25 */
21 26  
22   -/*
23   - * Operating System Interface
24   - *
25   - * This provides access to useful OS routines from the sandbox architecture
26   - */
27   -
28 27 #ifndef __OS_H__
29 28 #define __OS_H__
30 29  
... ... @@ -71,6 +70,12 @@
71 70 * \return file descriptor, or -1 on error
72 71 */
73 72 int os_open(const char *pathname, int flags);
  73 +
  74 +#define OS_O_RDONLY 0
  75 +#define OS_O_WRONLY 1
  76 +#define OS_O_RDWR 2
  77 +#define OS_O_MASK 3 /* Mask for read/write flags */
  78 +#define OS_O_CREAT 0100
74 79  
75 80 /**
76 81 * Access to the OS close() system call