* 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
This commit is contained in:
Axel Dörfler 2011-08-10 21:08:00 +00:00
parent 33272012fb
commit d5e36fb599
5 changed files with 52 additions and 55 deletions

View File

@ -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. * Distributed under the terms of the MIT License.
*/ */
#ifndef _FS_ATTR_H #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 int fs_close_attr(int fd);
extern DIR *fs_open_attr_dir(const char *path); 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 DIR *fs_fopen_attr_dir(int fd);
extern int fs_close_attr_dir(DIR *dir); extern int fs_close_attr_dir(DIR *dir);
extern struct dirent *fs_read_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
#endif /* _FS_ATTR_H */ #endif /* _FS_ATTR_H */

View File

@ -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. * Distributed under the terms of the MIT License.
* *
* Copyright 2001-2002, Travis Geiselbrecht. All rights reserved. * 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, ssize_t _user_select(int numfds, fd_set *readSet, fd_set *writeSet,
fd_set *errorSet, bigtime_t timeout, const sigset_t *sigMask); fd_set *errorSet, bigtime_t timeout, const sigset_t *sigMask);
ssize_t _user_poll(struct pollfd *fds, int numfds, bigtime_t timeout); 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, ssize_t _user_read_attr(int fd, const char *attribute, off_t pos,
void *buffer, size_t readBytes); void *buffer, size_t readBytes);
ssize_t _user_write_attr(int fd, const char *attribute, uint32 type, ssize_t _user_write_attr(int fd, const char *attribute, uint32 type,

View File

@ -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, extern ssize_t _kern_poll(struct pollfd *fds, int numFDs,
bigtime_t timeout); 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, extern ssize_t _kern_read_attr(int fd, const char *attribute, off_t pos,
void *buffer, size_t readBytes); void *buffer, size_t readBytes);
extern ssize_t _kern_write_attr(int fd, const char *attribute, uint32 type, 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, extern status_t _kern_memory_advice(void *address, size_t size,
uint32 advice); uint32 advice);
extern status_t _kern_get_memory_properties(team_id teamID, extern status_t _kern_get_memory_properties(team_id teamID,
const void *address, const void *address, uint32* _protected, uint32* _lock);
uint32* _protected,
uint32* _lock);
/* kernel port functions */ /* kernel port functions */
extern port_id _kern_create_port(int32 queue_length, const char *name); extern port_id _kern_create_port(int32 queue_length, const char *name);

View File

@ -5207,9 +5207,7 @@ static int
open_dir_vnode(struct vnode* vnode, bool kernel) open_dir_vnode(struct vnode* vnode, bool kernel)
{ {
void* cookie; void* cookie;
int status; status_t status = FS_CALL(vnode, open_dir, &cookie);
status = FS_CALL(vnode, open_dir, &cookie);
if (status != B_OK) if (status != B_OK)
return status; return status;
@ -5232,18 +5230,17 @@ open_dir_vnode(struct vnode* vnode, bool kernel)
static int static int
open_attr_dir_vnode(struct vnode* vnode, bool kernel) open_attr_dir_vnode(struct vnode* vnode, bool kernel)
{ {
void* cookie;
int status;
if (!HAS_FS_CALL(vnode, open_attr_dir)) if (!HAS_FS_CALL(vnode, open_attr_dir))
return B_NOT_SUPPORTED; 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) if (status != B_OK)
return status; return status;
// directory is opened, create a fd // 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) if (status >= 0)
return status; return status;
@ -5258,14 +5255,12 @@ static int
file_create_entry_ref(dev_t mountID, ino_t directoryID, const char* name, file_create_entry_ref(dev_t mountID, ino_t directoryID, const char* name,
int openMode, int perms, bool kernel) int openMode, int perms, bool kernel)
{ {
struct vnode* directory;
int status;
FUNCTION(("file_create_entry_ref: name = '%s', omode %x, perms %d, " FUNCTION(("file_create_entry_ref: name = '%s', omode %x, perms %d, "
"kernel %d\n", name, openMode, perms, kernel)); "kernel %d\n", name, openMode, perms, kernel));
// get directory to put the new file in // 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) if (status != B_OK)
return status; return status;
@ -5279,15 +5274,14 @@ file_create_entry_ref(dev_t mountID, ino_t directoryID, const char* name,
static int static int
file_create(int fd, char* path, int openMode, int perms, bool kernel) 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, FUNCTION(("file_create: path '%s', omode %x, perms %d, kernel %d\n", path,
openMode, perms, kernel)); openMode, perms, kernel));
// get directory to put the new file in // 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) if (status < 0)
return status; return status;
@ -5577,15 +5571,14 @@ dir_create(int fd, char* path, int perms, bool kernel)
static int static int
dir_open_entry_ref(dev_t mountID, ino_t parentID, const char* name, bool kernel) 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")); FUNCTION(("dir_open_entry_ref()\n"));
if (name && *name == '\0') if (name && name[0] == '\0')
return B_BAD_VALUE; return B_BAD_VALUE;
// get the vnode matching the entry_ref/node_ref // get the vnode matching the entry_ref/node_ref
struct vnode* vnode;
status_t status;
if (name) { if (name) {
status = entry_ref_to_vnode(mountID, parentID, name, true, kernel, status = entry_ref_to_vnode(mountID, parentID, name, true, kernel,
&vnode); &vnode);
@ -6261,15 +6254,13 @@ static status_t
common_path_read_stat(int fd, char* path, bool traverseLeafLink, common_path_read_stat(int fd, char* path, bool traverseLeafLink,
struct stat* stat, bool kernel) 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, FUNCTION(("common_path_read_stat: fd: %d, path '%s', stat %p,\n", fd, path,
stat)); stat));
status = fd_and_path_to_vnode(fd, path, traverseLeafLink, &vnode, NULL, struct vnode* vnode;
kernel); status_t status = fd_and_path_to_vnode(fd, path, traverseLeafLink, &vnode,
if (status < 0) NULL, kernel);
if (status != B_OK)
return status; return status;
status = FS_CALL(vnode, read_stat, stat); status = FS_CALL(vnode, read_stat, stat);
@ -6290,15 +6281,13 @@ static status_t
common_path_write_stat(int fd, char* path, bool traverseLeafLink, common_path_write_stat(int fd, char* path, bool traverseLeafLink,
const struct stat* stat, int statMask, bool kernel) 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, " FUNCTION(("common_write_stat: fd: %d, path '%s', stat %p, stat_mask %d, "
"kernel %d\n", fd, path, stat, statMask, kernel)); "kernel %d\n", fd, path, stat, statMask, kernel));
status = fd_and_path_to_vnode(fd, path, traverseLeafLink, &vnode, NULL, struct vnode* vnode;
kernel); status_t status = fd_and_path_to_vnode(fd, path, traverseLeafLink, &vnode,
if (status < 0) NULL, kernel);
if (status != B_OK)
return status; return status;
if (HAS_FS_CALL(vnode, write_stat)) if (HAS_FS_CALL(vnode, write_stat))
@ -6313,15 +6302,14 @@ common_path_write_stat(int fd, char* path, bool traverseLeafLink,
static int 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, FUNCTION(("attr_dir_open(fd = %d, path = '%s', kernel = %d)\n", fd, path,
kernel)); 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) if (status != B_OK)
return status; return status;
@ -8252,7 +8240,7 @@ _kern_write_stat(int fd, const char* path, bool traverseLeafLink,
int 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); KPath pathBuffer(B_PATH_NAME_LENGTH + 1);
if (pathBuffer.InitCheck() != B_OK) if (pathBuffer.InitCheck() != B_OK)
@ -8261,7 +8249,8 @@ _kern_open_attr_dir(int fd, const char* path)
if (path != NULL) if (path != NULL)
pathBuffer.SetTo(path); 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 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); KPath pathBuffer(B_PATH_NAME_LENGTH + 1);
if (pathBuffer.InitCheck() != B_OK) if (pathBuffer.InitCheck() != B_OK)
@ -9239,7 +9228,7 @@ _user_open_attr_dir(int fd, const char* userPath)
return B_BAD_ADDRESS; return B_BAD_ADDRESS;
} }
return attr_dir_open(fd, userPath ? path : NULL, false); return attr_dir_open(fd, userPath ? path : NULL, traverseLeafLink, false);
} }

View File

@ -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. * Distributed under the terms of the MIT License.
*/ */
@ -21,11 +21,11 @@
static DIR * static DIR *
open_attr_dir(int file, const char *path) open_attr_dir(int file, const char *path, bool traverse)
{ {
DIR *dir; DIR *dir;
int fd = _kern_open_attr_dir(file, path); int fd = _kern_open_attr_dir(file, path, traverse);
if (fd < 0) { if (fd < 0) {
errno = fd; errno = fd;
return NULL; return NULL;
@ -126,14 +126,20 @@ fs_close_attr(int fd)
extern "C" DIR* extern "C" DIR*
fs_open_attr_dir(const char* path) 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* extern "C" DIR*
fs_fopen_attr_dir(int fd) fs_fopen_attr_dir(int fd)
{ {
return open_attr_dir(fd, NULL); return open_attr_dir(fd, NULL, false);
} }