From d5e36fb599b43a6a9dfb3cf8e95018fe15780219 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Wed, 10 Aug 2011 21:08:00 +0000 Subject: [PATCH] * Introduced new fs_lopen_attr_dir() function that opens the attribute directory of a file without traversing leaf links (just like lstat()). * Minor cleanup. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@42620 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/os/kernel/fs_attr.h | 4 +- headers/private/kernel/vfs.h | 5 ++- headers/private/system/syscalls.h | 9 ++-- src/system/kernel/fs/vfs.cpp | 73 +++++++++++++------------------ src/system/libroot/os/fs_attr.cpp | 16 ++++--- 5 files changed, 52 insertions(+), 55 deletions(-) diff --git a/headers/os/kernel/fs_attr.h b/headers/os/kernel/fs_attr.h index 3f24985f05..d0d6a15dd8 100644 --- a/headers/os/kernel/fs_attr.h +++ b/headers/os/kernel/fs_attr.h @@ -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_fopen_attr(int fd, const char *attribute, uint32 type, 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 @@ extern void fs_rewind_attr_dir(DIR *dir); } #endif + #endif /* _FS_ATTR_H */ diff --git a/headers/private/kernel/vfs.h b/headers/private/kernel/vfs.h index eed16d95df..d3edae5240 100644 --- a/headers/private/kernel/vfs.h +++ b/headers/private/kernel/vfs.h @@ -1,5 +1,5 @@ /* - * Copyright 2002-2009, Axel Dörfler, axeld@pinc-software.de. + * Copyright 2002-2011, Axel Dörfler, axeld@pinc-software.de. * Distributed under the terms of the MIT License. * * Copyright 2001-2002, Travis Geiselbrecht. All rights reserved. @@ -199,7 +199,8 @@ status_t _user_access(int fd, const char *path, int mode, 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, diff --git a/headers/private/system/syscalls.h b/headers/private/system/syscalls.h index 3ef1eba1d0..81cd20c10e 100644 --- a/headers/private/system/syscalls.h +++ b/headers/private/system/syscalls.h @@ -280,7 +280,8 @@ extern ssize_t _kern_select(int numfds, struct fd_set *readSet, 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_sync_memory(void *address, size_t size, int flags); 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); diff --git a/src/system/kernel/fs/vfs.cpp b/src/system/kernel/fs/vfs.cpp index a2bf3f192a..80da3bd3f2 100644 --- a/src/system/kernel/fs/vfs.cpp +++ b/src/system/kernel/fs/vfs.cpp @@ -5207,9 +5207,7 @@ static int 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 @@ open_dir_vnode(struct vnode* vnode, bool kernel) 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 @@ static int 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 @@ file_create_entry_ref(dev_t mountID, ino_t directoryID, const char* name, 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 @@ dir_create(int fd, char* path, int perms, bool kernel) 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 @@ static status_t 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 @@ static status_t 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 @@ common_path_write_stat(int fd, char* path, bool traverseLeafLink, 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 @@ _kern_write_stat(int fd, const char* path, bool traverseLeafLink, 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 @@ _kern_open_attr_dir(int fd, const char* path) 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 @@ _user_write_stat(int fd, const char* userPath, bool traverseLeafLink, 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 @@ _user_open_attr_dir(int fd, const char* userPath) return B_BAD_ADDRESS; } - return attr_dir_open(fd, userPath ? path : NULL, false); + return attr_dir_open(fd, userPath ? path : NULL, traverseLeafLink, false); } diff --git a/src/system/libroot/os/fs_attr.cpp b/src/system/libroot/os/fs_attr.cpp index 93a360cabd..7e906066fc 100644 --- a/src/system/libroot/os/fs_attr.cpp +++ b/src/system/libroot/os/fs_attr.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2002-2009, Axel Dörfler, axeld@pinc-software.de. + * Copyright 2002-2011, Axel Dörfler, axeld@pinc-software.de. * 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 @@ fs_close_attr(int fd) 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); }