[haiku-commits] r42620 - in haiku/trunk: headers/os/kernel headers/private/kernel headers/private/system src/system/kernel/fs src/system/libroot/os

  • From: axeld@xxxxxxxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Wed, 10 Aug 2011 23:08:01 +0200 (CEST)

Author: axeld
Date: 2011-08-10 23:08:00 +0200 (Wed, 10 Aug 2011)
New Revision: 42620
Changeset: https://dev.haiku-os.org/changeset/42620

Modified:
   haiku/trunk/headers/os/kernel/fs_attr.h
   haiku/trunk/headers/private/kernel/vfs.h
   haiku/trunk/headers/private/system/syscalls.h
   haiku/trunk/src/system/kernel/fs/vfs.cpp
   haiku/trunk/src/system/libroot/os/fs_attr.cpp
Log:
* Introduced new fs_lopen_attr_dir() function that opens the attribute
  directory of a file without traversing leaf links (just like lstat()).
* Minor cleanup.


Modified: haiku/trunk/headers/os/kernel/fs_attr.h
===================================================================
--- haiku/trunk/headers/os/kernel/fs_attr.h     2011-08-10 20:53:06 UTC (rev 
42619)
+++ haiku/trunk/headers/os/kernel/fs_attr.h     2011-08-10 21:08:00 UTC (rev 
42620)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2002-2009, Haiku Inc. All Rights Reserved.
+ * Copyright 2002-2011, Haiku Inc. All Rights Reserved.
  * Distributed under the terms of the MIT License.
  */
 #ifndef _FS_ATTR_H
@@ -35,6 +35,7 @@
 extern int             fs_close_attr(int fd);
 
 extern DIR             *fs_open_attr_dir(const char *path);
+extern DIR             *fs_lopen_attr_dir(const char *path);
 extern DIR             *fs_fopen_attr_dir(int fd);
 extern int             fs_close_attr_dir(DIR *dir);
 extern struct dirent *fs_read_attr_dir(DIR *dir);
@@ -44,4 +45,5 @@
 }
 #endif
 
+
 #endif /* _FS_ATTR_H */

Modified: haiku/trunk/headers/private/kernel/vfs.h
===================================================================
--- haiku/trunk/headers/private/kernel/vfs.h    2011-08-10 20:53:06 UTC (rev 
42619)
+++ haiku/trunk/headers/private/kernel/vfs.h    2011-08-10 21:08:00 UTC (rev 
42620)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2002-2009, Axel Dörfler, axeld@xxxxxxxxxxxxxxxxx
+ * Copyright 2002-2011, Axel Dörfler, axeld@xxxxxxxxxxxxxxxxx
  * Distributed under the terms of the MIT License.
  *
  * Copyright 2001-2002, Travis Geiselbrecht. All rights reserved.
@@ -199,7 +199,8 @@
 ssize_t                _user_select(int numfds, fd_set *readSet, fd_set 
*writeSet,
                                fd_set *errorSet, bigtime_t timeout, const 
sigset_t *sigMask);
 ssize_t                _user_poll(struct pollfd *fds, int numfds, bigtime_t 
timeout);
-int                    _user_open_attr_dir(int fd, const char *path);
+int                    _user_open_attr_dir(int fd, const char *path,
+                               bool traverseLeafLink);
 ssize_t                _user_read_attr(int fd, const char *attribute, off_t 
pos,
                                void *buffer, size_t readBytes);
 ssize_t                _user_write_attr(int fd, const char *attribute, uint32 
type,

Modified: haiku/trunk/headers/private/system/syscalls.h
===================================================================
--- haiku/trunk/headers/private/system/syscalls.h       2011-08-10 20:53:06 UTC 
(rev 42619)
+++ haiku/trunk/headers/private/system/syscalls.h       2011-08-10 21:08:00 UTC 
(rev 42620)
@@ -280,7 +280,8 @@
 extern ssize_t         _kern_poll(struct pollfd *fds, int numFDs,
                                                bigtime_t timeout);
 
-extern int                     _kern_open_attr_dir(int fd, const char *path);
+extern int                     _kern_open_attr_dir(int fd, const char *path,
+                                               bool traverseLeafLink);
 extern ssize_t         _kern_read_attr(int fd, const char *attribute, off_t 
pos,
                                                void *buffer, size_t readBytes);
 extern ssize_t         _kern_write_attr(int fd, const char *attribute, uint32 
type,
@@ -435,10 +436,8 @@
 extern status_t                _kern_memory_advice(void *address, size_t size,
                                                uint32 advice);
 
-extern status_t                _kern_get_memory_properties(team_id teamID, 
-                                               const void *address,
-                                               uint32* _protected, 
-                                               uint32* _lock);
+extern status_t                _kern_get_memory_properties(team_id teamID,
+                                               const void *address, uint32* 
_protected, uint32* _lock);
 
 /* kernel port functions */
 extern port_id         _kern_create_port(int32 queue_length, const char *name);

Modified: haiku/trunk/src/system/kernel/fs/vfs.cpp
===================================================================
--- haiku/trunk/src/system/kernel/fs/vfs.cpp    2011-08-10 20:53:06 UTC (rev 
42619)
+++ haiku/trunk/src/system/kernel/fs/vfs.cpp    2011-08-10 21:08:00 UTC (rev 
42620)
@@ -5207,9 +5207,7 @@
 open_dir_vnode(struct vnode* vnode, bool kernel)
 {
        void* cookie;
-       int status;
-
-       status = FS_CALL(vnode, open_dir, &cookie);
+       status_t status = FS_CALL(vnode, open_dir, &cookie);
        if (status != B_OK)
                return status;
 
@@ -5232,18 +5230,17 @@
 static int
 open_attr_dir_vnode(struct vnode* vnode, bool kernel)
 {
-       void* cookie;
-       int status;
-
        if (!HAS_FS_CALL(vnode, open_attr_dir))
                return B_NOT_SUPPORTED;
 
-       status = FS_CALL(vnode, open_attr_dir, &cookie);
+       void* cookie;
+       status_t status = FS_CALL(vnode, open_attr_dir, &cookie);
        if (status != B_OK)
                return status;
 
        // directory is opened, create a fd
-       status = get_new_fd(FDTYPE_ATTR_DIR, NULL, vnode, cookie, O_CLOEXEC, 
kernel);
+       status = get_new_fd(FDTYPE_ATTR_DIR, NULL, vnode, cookie, O_CLOEXEC,
+               kernel);
        if (status >= 0)
                return status;
 
@@ -5258,14 +5255,12 @@
 file_create_entry_ref(dev_t mountID, ino_t directoryID, const char* name,
        int openMode, int perms, bool kernel)
 {
-       struct vnode* directory;
-       int status;
-
        FUNCTION(("file_create_entry_ref: name = '%s', omode %x, perms %d, "
                "kernel %d\n", name, openMode, perms, kernel));
 
        // get directory to put the new file in
-       status = get_vnode(mountID, directoryID, &directory, true, false);
+       struct vnode* directory;
+       status_t status = get_vnode(mountID, directoryID, &directory, true, 
false);
        if (status != B_OK)
                return status;
 
@@ -5279,15 +5274,14 @@
 static int
 file_create(int fd, char* path, int openMode, int perms, bool kernel)
 {
-       char name[B_FILE_NAME_LENGTH];
-       struct vnode* directory;
-       int status;
-
        FUNCTION(("file_create: path '%s', omode %x, perms %d, kernel %d\n", 
path,
                openMode, perms, kernel));
 
        // get directory to put the new file in
-       status = fd_and_path_to_dir_vnode(fd, path, &directory, name, kernel);
+       char name[B_FILE_NAME_LENGTH];
+       struct vnode* directory;
+       status_t status = fd_and_path_to_dir_vnode(fd, path, &directory, name,
+               kernel);
        if (status < 0)
                return status;
 
@@ -5577,15 +5571,14 @@
 static int
 dir_open_entry_ref(dev_t mountID, ino_t parentID, const char* name, bool 
kernel)
 {
-       struct vnode* vnode;
-       int status;
-
        FUNCTION(("dir_open_entry_ref()\n"));
 
-       if (name && *name == '\0')
+       if (name && name[0] == '\0')
                return B_BAD_VALUE;
 
        // get the vnode matching the entry_ref/node_ref
+       struct vnode* vnode;
+       status_t status;
        if (name) {
                status = entry_ref_to_vnode(mountID, parentID, name, true, 
kernel,
                        &vnode);
@@ -6261,15 +6254,13 @@
 common_path_read_stat(int fd, char* path, bool traverseLeafLink,
        struct stat* stat, bool kernel)
 {
-       struct vnode* vnode;
-       status_t status;
-
        FUNCTION(("common_path_read_stat: fd: %d, path '%s', stat %p,\n", fd, 
path,
                stat));
 
-       status = fd_and_path_to_vnode(fd, path, traverseLeafLink, &vnode, NULL,
-               kernel);
-       if (status < 0)
+       struct vnode* vnode;
+       status_t status = fd_and_path_to_vnode(fd, path, traverseLeafLink, 
&vnode,
+               NULL, kernel);
+       if (status != B_OK)
                return status;
 
        status = FS_CALL(vnode, read_stat, stat);
@@ -6290,15 +6281,13 @@
 common_path_write_stat(int fd, char* path, bool traverseLeafLink,
        const struct stat* stat, int statMask, bool kernel)
 {
-       struct vnode* vnode;
-       status_t status;
-
        FUNCTION(("common_write_stat: fd: %d, path '%s', stat %p, stat_mask %d, 
"
                "kernel %d\n", fd, path, stat, statMask, kernel));
 
-       status = fd_and_path_to_vnode(fd, path, traverseLeafLink, &vnode, NULL,
-               kernel);
-       if (status < 0)
+       struct vnode* vnode;
+       status_t status = fd_and_path_to_vnode(fd, path, traverseLeafLink, 
&vnode,
+               NULL, kernel);
+       if (status != B_OK)
                return status;
 
        if (HAS_FS_CALL(vnode, write_stat))
@@ -6313,15 +6302,14 @@
 
 
 static int
-attr_dir_open(int fd, char* path, bool kernel)
+attr_dir_open(int fd, char* path, bool traverseLeafLink, bool kernel)
 {
-       struct vnode* vnode;
-       int status;
-
        FUNCTION(("attr_dir_open(fd = %d, path = '%s', kernel = %d)\n", fd, 
path,
                kernel));
 
-       status = fd_and_path_to_vnode(fd, path, true, &vnode, NULL, kernel);
+       struct vnode* vnode;
+       status_t status = fd_and_path_to_vnode(fd, path, traverseLeafLink, 
&vnode,
+               NULL, kernel);
        if (status != B_OK)
                return status;
 
@@ -8252,7 +8240,7 @@
 
 
 int
-_kern_open_attr_dir(int fd, const char* path)
+_kern_open_attr_dir(int fd, const char* path, bool traverseLeafLink)
 {
        KPath pathBuffer(B_PATH_NAME_LENGTH + 1);
        if (pathBuffer.InitCheck() != B_OK)
@@ -8261,7 +8249,8 @@
        if (path != NULL)
                pathBuffer.SetTo(path);
 
-       return attr_dir_open(fd, path ? pathBuffer.LockBuffer() : NULL, true);
+       return attr_dir_open(fd, path ? pathBuffer.LockBuffer() : NULL,
+               traverseLeafLink, true);
 }
 
 
@@ -9225,7 +9214,7 @@
 
 
 int
-_user_open_attr_dir(int fd, const char* userPath)
+_user_open_attr_dir(int fd, const char* userPath, bool traverseLeafLink)
 {
        KPath pathBuffer(B_PATH_NAME_LENGTH + 1);
        if (pathBuffer.InitCheck() != B_OK)
@@ -9239,7 +9228,7 @@
                        return B_BAD_ADDRESS;
        }
 
-       return attr_dir_open(fd, userPath ? path : NULL, false);
+       return attr_dir_open(fd, userPath ? path : NULL, traverseLeafLink, 
false);
 }
 
 

Modified: haiku/trunk/src/system/libroot/os/fs_attr.cpp
===================================================================
--- haiku/trunk/src/system/libroot/os/fs_attr.cpp       2011-08-10 20:53:06 UTC 
(rev 42619)
+++ haiku/trunk/src/system/libroot/os/fs_attr.cpp       2011-08-10 21:08:00 UTC 
(rev 42620)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2002-2009, Axel Dörfler, axeld@xxxxxxxxxxxxxxxxx
+ * Copyright 2002-2011, Axel Dörfler, axeld@xxxxxxxxxxxxxxxxx
  * Distributed under the terms of the MIT License.
  */
 
@@ -21,11 +21,11 @@
 
 
 static DIR *
-open_attr_dir(int file, const char *path)
+open_attr_dir(int file, const char *path, bool traverse)
 {
        DIR *dir;
 
-       int fd = _kern_open_attr_dir(file, path);
+       int fd = _kern_open_attr_dir(file, path, traverse);
        if (fd < 0) {
                errno = fd;
                return NULL;
@@ -126,14 +126,20 @@
 extern "C" DIR*
 fs_open_attr_dir(const char* path)
 {
-       return open_attr_dir(-1, path);
+       return open_attr_dir(-1, path, true);
 }
 
 
 extern "C" DIR*
+fs_lopen_attr_dir(const char* path)
+{
+       return open_attr_dir(-1, path, false);
+}
+
+extern "C" DIR*
 fs_fopen_attr_dir(int fd)
 {
-       return open_attr_dir(fd, NULL);
+       return open_attr_dir(fd, NULL, false);
 }
 
 


Other related posts:

  • » [haiku-commits] r42620 - in haiku/trunk: headers/os/kernel headers/private/kernel headers/private/system src/system/kernel/fs src/system/libroot/os - axeld