diff --git a/headers/posix/fcntl.h b/headers/posix/fcntl.h index b0ccda8304..7c995a011b 100644 --- a/headers/posix/fcntl.h +++ b/headers/posix/fcntl.h @@ -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, ...); diff --git a/headers/posix/stdio.h b/headers/posix/stdio.h index ca3b95199b..a688cfb759 100644 --- a/headers/posix/stdio.h +++ b/headers/posix/stdio.h @@ -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); diff --git a/headers/posix/sys/stat.h b/headers/posix/sys/stat.h index 42fdebf74c..054236f0ef 100644 --- a/headers/posix/sys/stat.h +++ b/headers/posix/sys/stat.h @@ -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 diff --git a/headers/posix/unistd.h b/headers/posix/unistd.h index 7b2e178659..67d64260f5 100644 --- a/headers/posix/unistd.h +++ b/headers/posix/unistd.h @@ -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); diff --git a/headers/private/kernel/vfs.h b/headers/private/kernel/vfs.h index 76483a0244..446165004d 100644 --- a/headers/private/kernel/vfs.h +++ b/headers/private/kernel/vfs.h @@ -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); diff --git a/headers/private/system/syscalls.h b/headers/private/system/syscalls.h index d83764594b..7f708b85f3 100644 --- a/headers/private/system/syscalls.h +++ b/headers/private/system/syscalls.h @@ -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); diff --git a/src/system/kernel/fs/vfs.cpp b/src/system/kernel/fs/vfs.cpp index 1f1144da32..83925da2dd 100644 --- a/src/system/kernel/fs/vfs.cpp +++ b/src/system/kernel/fs/vfs.cpp @@ -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); } diff --git a/src/system/libroot/posix/fcntl.cpp b/src/system/libroot/posix/fcntl.cpp index 23aeebccf3..22c330ed0e 100644 --- a/src/system/libroot/posix/fcntl.cpp +++ b/src/system/libroot/posix/fcntl.cpp @@ -7,13 +7,10 @@ */ -#define B_ENABLE_INCOMPLETE_POSIX_AT_SUPPORT 1 - // make the *at() functions and AT_* macros visible - +#include +#include #include #include -#include -#include #include #include diff --git a/src/system/libroot/posix/stdio/Jamfile b/src/system/libroot/posix/stdio/Jamfile index 1289b74ca3..c43f38af02 100644 --- a/src/system/libroot/posix/stdio/Jamfile +++ b/src/system/libroot/posix/stdio/Jamfile @@ -1,6 +1,7 @@ SubDir HAIKU_TOP src system libroot posix stdio ; UsePrivateSystemHeaders ; +UsePrivateHeaders libroot shared ; MergeObject posix_stdio.o : __freading.cpp diff --git a/src/system/libroot/posix/stdio/rename.c b/src/system/libroot/posix/stdio/rename.c index 6e73cc789b..050e6a7177 100644 --- a/src/system/libroot/posix/stdio/rename.c +++ b/src/system/libroot/posix/stdio/rename.c @@ -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 -#include #include +#include + +#include +#include 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)); +} diff --git a/src/system/libroot/posix/sys/chmod.c b/src/system/libroot/posix/sys/chmod.c index 661baabe02..9f36ef5971 100644 --- a/src/system/libroot/posix/sys/chmod.c +++ b/src/system/libroot/posix/sys/chmod.c @@ -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 +#include + #include -#include #include -#include - - -#define RETURN_AND_SET_ERRNO(err) \ - if (err < 0) { \ - errno = err; \ - return -1; \ - } \ - return err; +#include 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); +} diff --git a/src/system/libroot/posix/sys/mkdir.c b/src/system/libroot/posix/sys/mkdir.c index 8bcfe4163a..4b5994da3d 100644 --- a/src/system/libroot/posix/sys/mkdir.c +++ b/src/system/libroot/posix/sys/mkdir.c @@ -4,11 +4,8 @@ */ -#define B_ENABLE_INCOMPLETE_POSIX_AT_SUPPORT 1 - // make the *at() functions and AT_* macros visible - -#include #include +#include #include #include diff --git a/src/system/libroot/posix/sys/mkfifo.c b/src/system/libroot/posix/sys/mkfifo.c index fc7a0af759..e18a111f26 100644 --- a/src/system/libroot/posix/sys/mkfifo.c +++ b/src/system/libroot/posix/sys/mkfifo.c @@ -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 -#include #include +#include - -#define RETURN_AND_SET_ERRNO(err) \ - if (err < 0) { \ - errno = err; \ - return -1; \ - } \ - return err; +#include +#include 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)); } diff --git a/src/system/libroot/posix/sys/stat.c b/src/system/libroot/posix/sys/stat.c index de266a1727..d0387322c7 100644 --- a/src/system/libroot/posix/sys/stat.c +++ b/src/system/libroot/posix/sys/stat.c @@ -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 - -#include #include +#include #include +#include #include #include diff --git a/src/system/libroot/posix/sys/utimes.c b/src/system/libroot/posix/sys/utimes.c index 9cbd20c612..c9d6d430bf 100644 --- a/src/system/libroot/posix/sys/utimes.c +++ b/src/system/libroot/posix/sys/utimes.c @@ -5,9 +5,6 @@ */ -#define B_ENABLE_INCOMPLETE_POSIX_AT_SUPPORT 1 - // make the *at() functions and AT_* macros visible - #include #include diff --git a/src/system/libroot/posix/unistd/access.c b/src/system/libroot/posix/unistd/access.c index ced8f8393e..a9ca6c11d6 100644 --- a/src/system/libroot/posix/unistd/access.c +++ b/src/system/libroot/posix/unistd/access.c @@ -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 -#include #include +#include - -#define RETURN_AND_SET_ERRNO(err) \ - if (err < 0) { \ - errno = err; \ - return -1; \ - } \ - return err; +#include +#include 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); } diff --git a/src/system/libroot/posix/unistd/chown.c b/src/system/libroot/posix/unistd/chown.c index 72daa93703..787ea42315 100644 --- a/src/system/libroot/posix/unistd/chown.c +++ b/src/system/libroot/posix/unistd/chown.c @@ -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 +#include + #include -#include #include -#include - - -#define RETURN_AND_SET_ERRNO(err) \ - if (err < 0) { \ - errno = err; \ - return -1; \ - } \ - return err; +#include 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); +} diff --git a/src/system/libroot/posix/unistd/link.c b/src/system/libroot/posix/unistd/link.c index 58e18049a1..2a04c7c74f 100644 --- a/src/system/libroot/posix/unistd/link.c +++ b/src/system/libroot/posix/unistd/link.c @@ -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 #include +#include + #include #include diff --git a/src/system/libroot/posix/unistd/mknod.c b/src/system/libroot/posix/unistd/mknod.c index 6426280da8..b00c6d4ec5 100644 --- a/src/system/libroot/posix/unistd/mknod.c +++ b/src/system/libroot/posix/unistd/mknod.c @@ -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 #include +#include 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; } diff --git a/src/system/runtime_loader/runtime_loader.cpp b/src/system/runtime_loader/runtime_loader.cpp index 87188eaafe..00d95964ea 100644 --- a/src/system/runtime_loader/runtime_loader.cpp +++ b/src/system/runtime_loader/runtime_loader.cpp @@ -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;