Telling O_WRONLY and O_RDWR apart

Sami Tikka <[email protected]>
Newsgroups gmane.linux.dazuko.devel
Organization F-Secure Corporation
Message-ID <[email protected]>
Hi! I noticed that dazuko 2.0.6 running on Linux 2.6 cannot tell if file
was opened O_WRONLY or O_RDWR, they are both reported as O_WRONLY.

I guess the problem happened because the open flags are not bit masks
like the MAY_* flags passed to inode_permission callback.

The patch below seems to correct open flag reporting.

--- orig/dazuko_linux26.c
+++ mod/dazuko_linux26.c
@@ -734,15 +734,22 @@
        }
        else
        {
-               /* mask == 0 is passed in when a file is created */
-               if (mask == 0 || (mask & (MAY_WRITE|MAY_APPEND)) != 0)
+               if (mask == MAY_READ)
                {
-                       event_p.flags |= O_WRONLY;
+                       event_p.flags = O_RDONLY;
                        event_p.set_flags = 1;
-               }
-               if ((mask & MAY_READ) != 0)
+               }
+               /* mask == 0 is passed in when a file is created */
+               else if (mask == 0 || (mask & (MAY_WRITE|MAY_APPEND)) != 0)
                {
-                       event_p.flags |= O_RDONLY;
+                       if ((mask & MAY_READ) != 0)
+                       {
+                               event_p.flags = O_RDWR;
+                       }
+                       else
+                       {
+                               event_p.flags = O_WRONLY;
+                       }
                        event_p.set_flags = 1;
                }
        }



-- 
Sami Tikka                          tel: +358 9 2520 5115
Senior Software Engineer            fax: +358 9 2520 5013
F-Secure Corporation                http://www.F-Secure.com/
Be Sure.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.