diff mbox

[U-Boot,v2,7/8] sandbox: Add flags for open() call

Message ID 1326242752-9981-7-git-send-email-sjg@chromium.org
State Superseded, archived
Delegated to: Mike Frysinger
Headers show

Commit Message

Simon Glass Jan. 11, 2012, 12:45 a.m. UTC
This provides a way for callers to create files for writing. We define
flags which mirror the POSIX values.

Another approach would be to translate the flags at runtime. Perhaps we can
leave to whoever wants to port this to another OS?

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 arch/sandbox/cpu/os.c |    2 +-
 include/os.h          |   18 +++++++++++++-----
 2 files changed, 14 insertions(+), 6 deletions(-)

Comments

Mike Frysinger Jan. 15, 2012, 4:19 a.m. UTC | #1
On Tuesday 10 January 2012 19:45:51 Simon Glass wrote:
> This provides a way for callers to create files for writing. We define
> flags which mirror the POSIX values.
> 
> Another approach would be to translate the flags at runtime. Perhaps we can
> leave to whoever wants to port this to another OS?

some of the flags differ between Linux/arches, so i think we'll have to do it 
now :/

> +enum {
> +	OS_O_RDONLY,
> +	OS_O_WRONLY,
> +	OS_O_RDWR,
> +	OS_O_CREAT	= 0100,
> +};

the flags are bit based, so an enum won't work i don't think
-mike
Simon Glass Jan. 15, 2012, 4:36 a.m. UTC | #2
Hi Mike,

On Sat, Jan 14, 2012 at 8:19 PM, Mike Frysinger <vapier@gentoo.org> wrote:
> On Tuesday 10 January 2012 19:45:51 Simon Glass wrote:
>> This provides a way for callers to create files for writing. We define
>> flags which mirror the POSIX values.
>>
>> Another approach would be to translate the flags at runtime. Perhaps we can
>> leave to whoever wants to port this to another OS?
>
> some of the flags differ between Linux/arches, so i think we'll have to do it
> now :/
>
>> +enum {
>> +     OS_O_RDONLY,
>> +     OS_O_WRONLY,
>> +     OS_O_RDWR,
>> +     OS_O_CREAT      = 0100,
>> +};
>
> the flags are bit based, so an enum won't work i don't think

Mostly, but in /usr/include/bits/fcntl.h:

#define O_RDONLY	     00
#define O_WRONLY	     01
#define O_RDWR		     02
#define O_CREAT		   0100	/* not fcntl */

Regards,
Simon

Regards,
Simon

> -mike
Mike Frysinger Jan. 15, 2012, 4:44 a.m. UTC | #3
On Saturday 14 January 2012 23:36:40 Simon Glass wrote:
> On Sat, Jan 14, 2012 at 8:19 PM, Mike Frysinger wrote:
> > On Tuesday 10 January 2012 19:45:51 Simon Glass wrote:
> >> +enum {
> >> +     OS_O_RDONLY,
> >> +     OS_O_WRONLY,
> >> +     OS_O_RDWR,
> >> +     OS_O_CREAT      = 0100,
> >> +};
> > 
> > the flags are bit based, so an enum won't work i don't think
> 
> Mostly, but in /usr/include/bits/fcntl.h:
> 
> #define O_RDONLY	     00
> #define O_WRONLY	     01
> #define O_RDWR		     02
> #define O_CREAT		   0100	/* not fcntl */

what i mean is that people don't do bitwise operations with enums.  so to open 
a few for writing and create it, you have to do:
	open(..., O_CREAT|O_WRONLY)

which is just weird with enums
-mike
Simon Glass Jan. 15, 2012, 4:48 a.m. UTC | #4
Hi Mike,

On Sat, Jan 14, 2012 at 8:44 PM, Mike Frysinger <vapier@gentoo.org> wrote:
> On Saturday 14 January 2012 23:36:40 Simon Glass wrote:
>> On Sat, Jan 14, 2012 at 8:19 PM, Mike Frysinger wrote:
>> > On Tuesday 10 January 2012 19:45:51 Simon Glass wrote:
>> >> +enum {
>> >> +     OS_O_RDONLY,
>> >> +     OS_O_WRONLY,
>> >> +     OS_O_RDWR,
>> >> +     OS_O_CREAT      = 0100,
>> >> +};
>> >
>> > the flags are bit based, so an enum won't work i don't think
>>
>> Mostly, but in /usr/include/bits/fcntl.h:
>>
>> #define O_RDONLY           00
>> #define O_WRONLY           01
>> #define O_RDWR                     02
>> #define O_CREAT                  0100 /* not fcntl */
>
> what i mean is that people don't do bitwise operations with enums.  so to open
> a few for writing and create it, you have to do:
>        open(..., O_CREAT|O_WRONLY)
>
> which is just weird with enums

OK I see. I have a higher tolerance to enums than most people and
debuggers like them. I will change these to #define.

Regards,
Simon

> -mike
diff mbox

Patch

diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c
index 093e7dc..9f93f83 100644
--- a/arch/sandbox/cpu/os.c
+++ b/arch/sandbox/cpu/os.c
@@ -47,7 +47,7 @@  ssize_t os_write(int fd, const void *buf, size_t count)
 
 int os_open(const char *pathname, int flags)
 {
-	return open(pathname, flags);
+	return open(pathname, flags, 0777);
 }
 
 int os_close(int fd)
diff --git a/include/os.h b/include/os.h
index f3af4f0..66e60f8 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,11 +24,7 @@ 
  * MA 02111-1307 USA
  */
 
-/*
- * Operating System Interface
- *
- * This provides access to useful OS routines from the sandbox architecture
- */
+struct sandbox_state;
 
 /**
  * Access to the OS read() system call
@@ -45,6 +46,13 @@  ssize_t os_read(int fd, void *buf, size_t count);
  */
 ssize_t os_write(int fd, const void *buf, size_t count);
 
+enum {
+	OS_O_RDONLY,
+	OS_O_WRONLY,
+	OS_O_RDWR,
+	OS_O_CREAT	= 0100,
+};
+
 /**
  * Access to the OS open() system call
  *