[U-Boot] [PATCH v5 7/9] sandbox: Add flags for open() call

Simon Glass sjg at chromium.org
Tue Feb 21 05:41:36 CET 2012


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 at chromium.org>
---
Changes in v3:
- Change open() flags enum to #define

Changes in v4:
- Change space to tab in os.h
- Remove unneeded declaration of struct sandbox_state in os.h

Changes in v5:
- Add belts-and-braces decode of OS_O_... flags

 arch/sandbox/cpu/os.c |   24 ++++++++++++++++++++++--
 include/os.h          |   17 +++++++++++------
 2 files changed, 33 insertions(+), 8 deletions(-)

diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c
index 093e7dc..a5c1c0b 100644
--- a/arch/sandbox/cpu/os.c
+++ b/arch/sandbox/cpu/os.c
@@ -45,9 +45,29 @@ ssize_t os_write(int fd, const void *buf, size_t count)
 	return write(fd, buf, count);
 }
 
-int os_open(const char *pathname, int flags)
+int os_open(const char *pathname, int os_flags)
 {
-	return open(pathname, flags);
+	int flags;
+
+	switch (os_flags & OS_O_MASK) {
+	case OS_O_RDONLY:
+	default:
+		flags = O_RDONLY;
+		break;
+
+	case OS_O_WRONLY:
+		flags = O_WRONLY;
+		break;
+
+	case OS_O_RDWR:
+		flags = O_RDWR;
+		break;
+	}
+
+	if (os_flags & OS_O_CREAT)
+		flags |= O_CREAT;
+
+	return open(pathname, flags, 0777);
 }
 
 int os_close(int fd)
diff --git a/include/os.h b/include/os.h
index f3af4f0..16fb5de 100644
--- a/include/os.h
+++ b/include/os.h
@@ -1,4 +1,9 @@
 /*
+ * Operating System Interface
+ *
+ * This provides access to useful OS routines for the sandbox architecture.
+ * They are kept in a separate file so we can include system headers.
+ *
  * Copyright (c) 2011 The Chromium OS Authors.
  * See file CREDITS for list of people who contributed to this
  * project.
@@ -19,12 +24,6 @@
  * MA 02111-1307 USA
  */
 
-/*
- * Operating System Interface
- *
- * This provides access to useful OS routines from the sandbox architecture
- */
-
 /**
  * Access to the OS read() system call
  *
@@ -45,6 +44,12 @@ ssize_t os_read(int fd, void *buf, size_t count);
  */
 ssize_t os_write(int fd, const void *buf, size_t count);
 
+#define OS_O_RDONLY	0
+#define OS_O_WRONLY	1
+#define OS_O_RDWR	2
+#define OS_O_MASK	3	/* Mask for read/write flags */
+#define OS_O_CREAT	0100
+
 /**
  * Access to the OS open() system call
  *
-- 
1.7.7.3



More information about the U-Boot mailing list