* Added missing AT_EACCESS.

* Implemented renameat(), faccessat(), fchownat(), fchmodat(), and mkfifoat().
* Added stub for mknodat().
* The kernel backend for faccessat() does not yet differentiate between
  effective and real user/group IDs, though.
* Removed B_ENABLE_INCOMPLETE_POSIX_AT_SUPPORT, as we now support everything
  (more or less). This also closes ticket #4928.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34288 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2009-11-26 16:17:17 +00:00
parent 880de4501c
commit fb2500da15
20 changed files with 136 additions and 122 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2008, Haiku Inc. All Rights Reserved.
* Copyright 2002-2009, Haiku Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _FCNTL_H
@ -62,14 +62,13 @@
/* TODO: currently not implemented additions: */
#define O_TEMPORARY 0x00400000 /* used to avoid writing temporary files to disk */
#ifdef B_ENABLE_INCOMPLETE_POSIX_AT_SUPPORT
#define AT_FDCWD (-1) /* CWD FD for the *at() functions */
#define AT_SYMLINK_NOFOLLOW 0x1 /* fstatat(), fchmodat(), fchownat(),
#define AT_SYMLINK_NOFOLLOW 0x01 /* fstatat(), fchmodat(), fchownat(),
utimensat() */
#define AT_SYMLINK_FOLLOW 0x2 /* linkat() */
#define AT_SYMLINK_FOLLOW 0x02 /* linkat() */
#define AT_REMOVEDIR 0x04 /* unlinkat() */
#endif
#define AT_EACCESS 0x08 /* faccessat() */
/* advisory file locking */
@ -90,9 +89,7 @@ extern int creat(const char *path, mode_t mode);
extern int open(const char *path, int openMode, ...);
/* the third argument is the permissions of the created file when O_CREAT
is passed in oflags */
#ifdef B_ENABLE_INCOMPLETE_POSIX_AT_SUPPORT
extern int openat(int fd, const char *path, int openMode, ...);
#endif
extern int fcntl(int fd, int op, ...);

View File

@ -1,6 +1,7 @@
/*
** Distributed under the terms of the OpenBeOS License.
*/
* Copyright 2004-2009, Haiku Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _STDIO_H_
#define _STDIO_H_
@ -87,6 +88,7 @@ extern int ftrylockfile(FILE *stream);
extern int remove(const char *name);
extern int rename(const char *from, const char *to);
extern int renameat(int fromFD, const char *from, int toFD, const char *to);
/* pipes */
extern FILE *popen(const char *command, const char *mode);

View File

@ -111,23 +111,19 @@ extern "C" {
extern int chmod(const char *path, mode_t mode);
extern int fchmod(int fd, mode_t mode);
extern int fchmodat(int fd, const char *path, mode_t mode, int flag);
extern int stat(const char *path, struct stat *st);
extern int fstat(int fd, struct stat *st);
extern int lstat(const char *path, struct stat *st);
#ifdef B_ENABLE_INCOMPLETE_POSIX_AT_SUPPORT
extern int fstatat(int fd, const char *path, struct stat *st, int flag);
#endif
extern int mkdir(const char *path, mode_t mode);
#ifdef B_ENABLE_INCOMPLETE_POSIX_AT_SUPPORT
extern int mkdirat(int fd, const char *path, mode_t mode);
#endif
extern int mkfifo(const char *path, mode_t mode);
extern int mkfifoat(int fd, const char *path, mode_t mode);
extern mode_t umask(mode_t cmask);
#ifdef B_ENABLE_INCOMPLETE_POSIX_AT_SUPPORT
extern int utimensat(int fd, const char *path,
const struct timespec times[2], int flag);
#endif
extern int futimens(int fd, const struct timespec times[2]);
#ifdef __cplusplus

View File

@ -1,5 +1,5 @@
/*
* Copyright 2004-2008, Haiku Inc. All Rights Reserved.
* Copyright 2004-2009, Haiku Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _UNISTD_H_
@ -124,6 +124,7 @@ extern "C" {
/* file functions */
extern int access(const char *path, int accessMode);
extern int faccessat(int fd, const char *path, int accessMode, int flag);
extern int chdir(const char *path);
extern int fchdir(int fd);
@ -135,20 +136,14 @@ extern int dup2(int fd1, int fd2);
extern int close(int fd);
extern int link(const char *name, const char *new_name);
extern int unlink(const char *name);
#ifdef B_ENABLE_INCOMPLETE_POSIX_AT_SUPPORT
extern int unlinkat(int fd, const char *path, int flag);
#endif
extern int rmdir(const char *path);
extern ssize_t readlink(const char *path, char *buffer, size_t bufferSize);
#ifdef B_ENABLE_INCOMPLETE_POSIX_AT_SUPPORT
extern ssize_t readlinkat(int fd, const char *path, char *buffer,
size_t bufferSize);
#endif
extern int symlink(const char *toPath, const char *symlinkPath);
#ifdef B_ENABLE_INCOMPLETE_POSIX_AT_SUPPORT
extern int symlinkat(const char *toPath, int fd, const char *symlinkPath);
#endif
extern int ftruncate(int fd, off_t newSize);
extern int truncate(const char *path, off_t newSize);
@ -168,8 +163,11 @@ extern int fsync(int fd);
extern int chown(const char *path, uid_t owner, gid_t group);
extern int fchown(int fd, uid_t owner, gid_t group);
extern int lchown(const char *path, uid_t owner, gid_t group);
extern int fchownat(int fd, const char *path, uid_t owner, gid_t group,
int flag);
extern int mknod(const char *name, mode_t mode, dev_t dev);
extern int mknodat(int fd, const char *name, mode_t mode, dev_t dev);
extern int getpagesize(void);
extern int getdtablesize(void);

View File

@ -194,9 +194,10 @@ status_t _user_create_link(const char *path, const char *toPath);
status_t _user_unlink(int fd, const char *path);
status_t _user_rename(int oldFD, const char *oldpath, int newFD,
const char *newpath);
status_t _user_create_fifo(const char *path, mode_t perms);
status_t _user_create_fifo(int fd, const char *path, mode_t perms);
status_t _user_create_pipe(int *fds);
status_t _user_access(const char *path, int mode);
status_t _user_access(int fd, const char *path, int mode,
bool effectiveUserGroup);
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);

View File

@ -243,9 +243,10 @@ extern status_t _kern_create_link(const char *path, const char *toPath);
extern status_t _kern_unlink(int fd, const char *path);
extern status_t _kern_rename(int oldDir, const char *oldpath, int newDir,
const char *newpath);
extern status_t _kern_create_fifo(const char *path, mode_t perms);
extern status_t _kern_create_fifo(int fd, const char *path, mode_t perms);
extern status_t _kern_create_pipe(int *fds);
extern status_t _kern_access(const char *path, int mode);
extern status_t _kern_access(int fd, const char *path, int mode,
bool effectiveUserGroup);
extern ssize_t _kern_select(int numfds, struct fd_set *readSet,
struct fd_set *writeSet, struct fd_set *errorSet,
bigtime_t timeout, const sigset_t *sigMask);

View File

@ -6058,12 +6058,14 @@ common_unlink(int fd, char* path, bool kernel)
static status_t
common_access(char* path, int mode, bool kernel)
common_access(int fd, char* path, int mode, bool effectiveUserGroup, bool kernel)
{
struct vnode* vnode;
status_t status;
status = path_to_vnode(path, true, &vnode, NULL, kernel);
// TODO: honor effectiveUserGroup argument
status = fd_and_path_to_vnode(fd, path, true, &vnode, NULL, kernel);
if (status != B_OK)
return status;
@ -8058,13 +8060,14 @@ _kern_rename(int oldFD, const char* oldPath, int newFD, const char* newPath)
status_t
_kern_access(const char* path, int mode)
_kern_access(int fd, const char* path, int mode, bool effectiveUserGroup)
{
KPath pathBuffer(path, false, B_PATH_NAME_LENGTH + 1);
if (pathBuffer.InitCheck() != B_OK)
return B_NO_MEMORY;
return common_access(pathBuffer.LockBuffer(), mode, true);
return common_access(fd, pathBuffer.LockBuffer(), mode, effectiveUserGroup,
true);
}
@ -8929,7 +8932,7 @@ _user_rename(int oldFD, const char* userOldPath, int newFD,
status_t
_user_create_fifo(const char* userPath, mode_t perms)
_user_create_fifo(int fd, const char* userPath, mode_t perms)
{
KPath pathBuffer(B_PATH_NAME_LENGTH + 1);
if (pathBuffer.InitCheck() != B_OK)
@ -8945,7 +8948,7 @@ _user_create_fifo(const char* userPath, mode_t perms)
// split into directory vnode and filename path
char filename[B_FILE_NAME_LENGTH];
struct vnode* dir;
status_t status = path_to_dir_vnode(path, &dir, filename, false);
status_t status = fd_and_path_to_dir_vnode(fd, path, &dir, filename, false);
if (status != B_OK)
return status;
@ -9024,7 +9027,7 @@ _user_create_pipe(int* userFDs)
status_t
_user_access(const char* userPath, int mode)
_user_access(int fd, const char* userPath, int mode, bool effectiveUserGroup)
{
KPath pathBuffer(B_PATH_NAME_LENGTH + 1);
if (pathBuffer.InitCheck() != B_OK)
@ -9036,7 +9039,7 @@ _user_access(const char* userPath, int mode)
|| user_strlcpy(path, userPath, B_PATH_NAME_LENGTH) < B_OK)
return B_BAD_ADDRESS;
return common_access(path, mode, false);
return common_access(fd, path, mode, effectiveUserGroup, false);
}

View File

@ -7,13 +7,10 @@
*/
#define B_ENABLE_INCOMPLETE_POSIX_AT_SUPPORT 1
// make the *at() functions and AT_* macros visible
#include <errno.h>
#include <fcntl.h>
#include <stdarg.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <syscalls.h>
#include <syscall_utils.h>

View File

@ -1,6 +1,7 @@
SubDir HAIKU_TOP src system libroot posix stdio ;
UsePrivateSystemHeaders ;
UsePrivateHeaders libroot shared ;
MergeObject posix_stdio.o :
__freading.cpp

View File

@ -1,23 +1,25 @@
/*
** Copyright 2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
** Distributed under the terms of the Haiku License.
*/
* Copyright 2004-2009, Axel Dörfler, axeld@pinc-software.de.
* Distributed under the terms of the MIT License.
*/
#include <stdio.h>
#include <syscalls.h>
#include <errno.h>
#include <stdio.h>
#include <syscalls.h>
#include <syscall_utils.h>
int
rename(const char *from, const char *to)
{
int status = _kern_rename(-1, from, -1, to);
if (status < B_OK) {
errno = status;
return -1;
}
return status;
RETURN_AND_SET_ERRNO(_kern_rename(-1, from, -1, to));
}
int
renameat(int fromFD, const char* from, int toFD, const char* to)
{
RETURN_AND_SET_ERRNO(_kern_rename(fromFD, from, toFD, to));
}

View File

@ -1,22 +1,16 @@
/*
* Copyright 2002-2008, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
* Copyright 2002-2009, Axel Dörfler, axeld@pinc-software.de.
* Distributed under the terms of the MIT License.
*/
#include <errno.h>
#include <sys/stat.h>
#include <NodeMonitor.h>
#include <sys/stat.h>
#include <syscalls.h>
#include <errno.h>
#define RETURN_AND_SET_ERRNO(err) \
if (err < 0) { \
errno = err; \
return -1; \
} \
return err;
#include <syscall_utils.h>
int
@ -45,3 +39,17 @@ fchmod(int fd, mode_t mode)
RETURN_AND_SET_ERRNO(status);
}
int
fchmodat(int fd, const char* path, mode_t mode, int flag)
{
struct stat stat;
status_t status;
stat.st_mode = mode;
status = _kern_write_stat(fd, path, (flag & AT_SYMLINK_NOFOLLOW) == 0, &stat,
sizeof(struct stat), B_STAT_MODE);
RETURN_AND_SET_ERRNO(status);
}

View File

@ -4,11 +4,8 @@
*/
#define B_ENABLE_INCOMPLETE_POSIX_AT_SUPPORT 1
// make the *at() functions and AT_* macros visible
#include <sys/stat.h>
#include <errno.h>
#include <sys/stat.h>
#include <syscalls.h>
#include <syscall_utils.h>

View File

@ -1,26 +1,25 @@
/*
** Copyright 2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
** Distributed under the terms of the Haiku License.
*/
/*
* Copyright 2004-2009, Axel Dörfler, axeld@pinc-software.de.
* Distributed under the terms of the MIT License.
*/
#include <sys/stat.h>
#include <syscalls.h>
#include <errno.h>
#include <sys/stat.h>
#define RETURN_AND_SET_ERRNO(err) \
if (err < 0) { \
errno = err; \
return -1; \
} \
return err;
#include <syscalls.h>
#include <syscall_utils.h>
int
mkfifo(const char *path, mode_t mode)
{
status_t error = _kern_create_fifo(path, mode);
RETURN_AND_SET_ERRNO(error);
RETURN_AND_SET_ERRNO(_kern_create_fifo(-1, path, mode));
}
int
mkfifoat(int fd, const char *path, mode_t mode)
{
RETURN_AND_SET_ERRNO(_kern_create_fifo(fd, path, mode));
}

View File

@ -1,19 +1,16 @@
/*
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. All rights reserved.
* Copyright 2002-2008, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
* Copyright 2002-2009, Axel Dörfler, axeld@pinc-software.de.
* Distributed under the terms of the MIT License.
*/
#define B_ENABLE_INCOMPLETE_POSIX_AT_SUPPORT 1
// make the *at() functions and AT_* macros visible
#include <syscalls.h>
#include <sys/stat.h>
#include <errno.h>
#include <sys/stat.h>
#include <compat/sys/stat.h>
#include <syscalls.h>
#include <symbol_versioning.h>
#include <syscall_utils.h>

View File

@ -5,9 +5,6 @@
*/
#define B_ENABLE_INCOMPLETE_POSIX_AT_SUPPORT 1
// make the *at() functions and AT_* macros visible
#include <sys/time.h>
#include <errno.h>

View File

@ -1,26 +1,30 @@
/*
* Copyright 2002-2007, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
* Copyright 2002-2009, Axel Dörfler, axeld@pinc-software.de.
* Distributed under the terms of the MIT License.
*/
#include <unistd.h>
#include <syscalls.h>
#include <errno.h>
#include <unistd.h>
#define RETURN_AND_SET_ERRNO(err) \
if (err < 0) { \
errno = err; \
return -1; \
} \
return err;
#include <syscalls.h>
#include <syscall_utils.h>
int
access(const char* path, int accessMode)
{
status_t status = _kern_access(path, accessMode);
status_t status = _kern_access(-1, path, accessMode, false);
RETURN_AND_SET_ERRNO(status);
}
int
faccessat(int fd, const char* path, int accessMode, int flag)
{
status_t status = _kern_access(fd, path, accessMode,
(flag & AT_EACCESS) != 0);
RETURN_AND_SET_ERRNO(status);
}

View File

@ -1,22 +1,16 @@
/*
* Copyright 2002-2008, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
* Copyright 2002-2009, Axel Dörfler, axeld@pinc-software.de.
* Distributed under the terms of the MIT License.
*/
#include <errno.h>
#include <unistd.h>
#include <NodeMonitor.h>
#include <unistd.h>
#include <syscalls.h>
#include <errno.h>
#define RETURN_AND_SET_ERRNO(err) \
if (err < 0) { \
errno = err; \
return -1; \
} \
return err;
#include <syscall_utils.h>
int
@ -63,3 +57,17 @@ fchown(int fd, uid_t owner, gid_t group)
RETURN_AND_SET_ERRNO(status);
}
int
fchownat(int fd, const char* path, uid_t owner, gid_t group, int flag)
{
struct stat stat;
status_t status;
stat.st_uid = owner;
stat.st_gid = group;
status = _kern_write_stat(fd, path, (flag & AT_SYMLINK_NOFOLLOW) == 0, &stat,
sizeof(struct stat), B_STAT_UID | B_STAT_GID);
RETURN_AND_SET_ERRNO(status);
}

View File

@ -1,14 +1,12 @@
/*
* Copyright 2002-2005, Axel Dörfler, axeld@pinc-software.de.
* Copyright 2002-2009, Axel Dörfler, axeld@pinc-software.de.
* Distributed under the terms of the MIT License.
*/
#define B_ENABLE_INCOMPLETE_POSIX_AT_SUPPORT 1
// make the *at() functions and AT_* macros visible
#include <unistd.h>
#include <errno.h>
#include <unistd.h>
#include <syscalls.h>
#include <syscall_utils.h>

View File

@ -1,17 +1,25 @@
/*
* Copyright 2004, Axel Dörfler, axeld@pinc-software.de.
* Copyright 2004-2009, Axel Dörfler, axeld@pinc-software.de.
* Distributed under the terms of the MIT License.
*/
#include <unistd.h>
#include <errno.h>
#include <unistd.h>
int
mknod(const char *name, mode_t mode, dev_t dev)
{
errno = B_BAD_VALUE;
errno = ENOTSUP;
return -1;
}
int
mknodat(int fd, const char *name, mode_t mode, dev_t dev)
{
errno = ENOTSUP;
return -1;
}

View File

@ -304,7 +304,7 @@ test_executable(const char *name, char *invoker)
return fd;
// see if it's executable at all
status = _kern_access(path, X_OK);
status = _kern_access(-1, path, X_OK, false);
if (status != B_OK)
goto out;