History log of /haiku/src/system/libroot/posix/unistd/link.c
Revision Date Author Comments
# e1b7c1c7 19-Apr-2020 Kyle Ambroff-Kao <kyle@ambroffkao.com>

storage/SymLink: Fix Be API regression in ReadLink

After this patch, "UnitTester BSymLink" passes.

BSymLink::ReadLink() in BeOS would always return the length of the
link unless an error occurred. Before this patch, Haiku instead seemed
to emulate posix readlink() behavior, returning the number of bytes
copied into the output buffer.

BeOS also did not guarantee that the string written into the output
buffer is NULL terminated if the output buffer cannot contain the
entire link contents, but the Haiku implementation does since it is is
a basic safety issue.

This patch fixes this and updates the Haiku API docs to describe the
behavior explicitly.

Fixing this required changing behavior in bfs_read_link, which
required changes in many more places.

docs/user/storage/SymLink.dox:
src/kits/storage/SymLink.cpp:
* Don't return B_BUFFER_OVERFLOW if the provided buffer is not large
enough to hold the link contents.
* Update documentation to clearly describe behavior.

src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp:
* Change bfs_read_link() to always return the link length. This is
called by common_read_link in the VFS, which is called by
_kern_read_link().

src/add-ons/kernel/file_systems/btrfs/kernel_interface.cpp:
src/add-ons/kernel/file_systems/exfat/kernel_interface.cpp:
src/add-ons/kernel/file_systems/ext2/kernel_interface.cpp:
src/add-ons/kernel/file_systems/iso9660/kernel_interface.cpp:
src/add-ons/kernel/file_systems/netfs/client/netfs.cpp:
src/add-ons/kernel/file_systems/nfs/nfs_add_on.c:
src/add-ons/kernel/file_systems/ramfs/kernel_interface.cpp:
src/add-ons/kernel/file_systems/reiserfs/Iterators.cpp:
src/add-ons/kernel/file_systems/reiserfs/Iterators.h:
src/add-ons/kernel/file_systems/reiserfs/Volume.cpp:
src/add-ons/kernel/file_systems/reiserfs/Volume.h:
* Update the implementation of read_link for these filesystems. Some
of them were incorrect, and some had just copied the posix behavior of
bfs from before this patch.
* Use user_memcpy in ext2_read_link()
* Use user_memcpy in nfs fs_read_link()
* Use user_memcpy in reiserfs StreamReader::_ReadIndirectItem and
StreamReader::_ReadDirectItem
* Remove unused method Volume::ReadObject in reiserfs.

src/add-ons/kernel/file_systems/packagefs/nodes/UnpackingLeafNode.cpp:
src/add-ons/kernel/file_systems/packagefs/package_links/PackageLinkSymlink.cpp:
* Update UnpackingLeafNode::ReadSymlink and
PackageSymLink::ReadSymLink() to set the bufferSize out parameter to
the symlink length. Both of these are called by
packagefs_read_symlink.
* Use user_memcpy

src/add-ons/kernel/file_systems/netfs/client/netfs.cpp:
* netfs seems mostly unimplemented. Added a FIXME note for future
implementers so that they know to implement the correct behavior.

src/system/libroot/posix/unistd/link.c:
* readlinkat() was just wrapping _kern_read_link() because before this
patch it had expected posix behavior. But now it does not, so we
need to return the number of bytes written to the output
buffer.

src/build/libroot/fs.cpp:
* Update _kern_read_link() in the compatibility code to emulate the
Haiku behavior on the host system. This is done by using an
intermediate buffer that is guaranteed to fit the link contents and
returning its length. The intermediate buffer is copied into the
output buffer until there is no more room.

src/tests/kits/storage/SymLinkTest.cpp:
* This patch also resolves some test failures similar to those
resolved in ee8cf35f0 which fixed tests for BNode. The tests were
failing because Haiku's error checking is just better.

BeOS allowed constructing a BSymLink with BSymLink(BDirectory*,
const char*) with the entry name of "". The same is true of the
equivilant SetTo() method. The BSymLink object will appear valid
until you attempt to use it by, for example, calling the ReadLink
method, which will return B_BAD_VALUE.

Haiku does a more appropriate thing and returns B_ENTRY_NOT_FOUND,
for this constructor and the equivilant SetTo(BDirectory*, const
char*) method. This patch fixes these test assertions to match Haiku
behavior.

docs/develop/file_systems/overview.txt:
* Add notes for future filesystem driver implementers to call this
mistake when implementing fs_vnode_ops::read_symlink.

docs/user/drivers/fs_interface.dox:
* Fix documentation for fs_vnode_ops::read_symlink

Change-Id: I8bcb8b2a0c9333059c84ace15844c32d4efeed9d
Reviewed-on: https://review.haiku-os.org/c/haiku/+/2502
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
Reviewed-by: Axel Dörfler <axeld@pinc-software.de>


# 89b48deb 18-Jan-2013 Przemysław Buczkowski <przemub@yahoo.pl>

Correct errno return in link() function (bug #8770)

* edited as pointed by Axel


# ae901935 24-Nov-2011 Oliver Tappe <zooey@hirschkaefer.de>

Introduce __set_errno() throughout libroot.

* add errno_private.h, which defines the __set_errno() macro with
and without tracing
* instead of setting errno manually, all libroot's code now invokes
__set_errno(), which makes it much easier to trace changes to errno
* redirect glibc's use of __set_errno() to our own version


# 486fffda 26-Nov-2009 Axel Dörfler <axeld@pinc-software.de>

* Forgot to add linkat(), this really closes #4928 now.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34289 a95241bf-73f2-0310-859d-f6bbb57e9c96


# fb2500da 26-Nov-2009 Axel Dörfler <axeld@pinc-software.de>

* 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


# 6c00aabc 12-Nov-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

Implemented POSIX.1-2008 functions unlinkat(), symlinkat(), mkdirat(),
utimensat(), and futimens().


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34010 a95241bf-73f2-0310-859d-f6bbb57e9c96


# db2b554f 10-Nov-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

Moved the POSIX *at() functions and AT_* macros out of the default namespace
as long as the full set hasn't been implemented. They are guarded by the
B_ENABLE_INCOMPLETE_POSIX_AT_SUPPORT macro until then. Fixes the build.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33990 a95241bf-73f2-0310-859d-f6bbb57e9c96


# b189a201 10-Nov-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

Added readlinkat().


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33978 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 1b32947d 17-Mar-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

* Aligned the semantics of the read_symlink() FS module hook with the
readlink() function. It is no longer required to null-terminate the
string, shall not fail, if the buffer is too small, and shall return
the length of the string actually written into the buffer.
* Adjusted rootfs, devfs, and bfs accordingly. Also adjusted their
read_stat() hooks to return the correct symlink length in st_size.
* Our readlink() does now comply to the standard (and BeOS).
Additionally if the buffer is big enough it is nice to non-conforming
apps and null-terminates it.
* BSymLink::ReadLink() explicitly null-terminates the string now.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24425 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 5af32e75 13-Apr-2005 Axel Dörfler <axeld@pinc-software.de>

Renamed src/kernel to src/system.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@12359 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 89b48debc2e995d1eb430f931cbd12daa4a96e8b 18-Jan-2013 Przemysław Buczkowski <przemub@yahoo.pl>

Correct errno return in link() function (bug #8770)

* edited as pointed by Axel


# ae9019359606f1db67632ef51a77ce70001d3770 24-Nov-2011 Oliver Tappe <zooey@hirschkaefer.de>

Introduce __set_errno() throughout libroot.

* add errno_private.h, which defines the __set_errno() macro with
and without tracing
* instead of setting errno manually, all libroot's code now invokes
__set_errno(), which makes it much easier to trace changes to errno
* redirect glibc's use of __set_errno() to our own version


# 486fffdaaf7f16e65bea9f4fde7d5d3c3726ece8 26-Nov-2009 Axel Dörfler <axeld@pinc-software.de>

* Forgot to add linkat(), this really closes #4928 now.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34289 a95241bf-73f2-0310-859d-f6bbb57e9c96


# fb2500da15e8c574cbb343b8fc536d7094357f54 26-Nov-2009 Axel Dörfler <axeld@pinc-software.de>

* 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


# 6c00aabc9e209639ff2753ba8cc2acf3f1b5ec95 12-Nov-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

Implemented POSIX.1-2008 functions unlinkat(), symlinkat(), mkdirat(),
utimensat(), and futimens().


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34010 a95241bf-73f2-0310-859d-f6bbb57e9c96


# db2b554fa368b03940b495c2f439d4f6e738d282 10-Nov-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

Moved the POSIX *at() functions and AT_* macros out of the default namespace
as long as the full set hasn't been implemented. They are guarded by the
B_ENABLE_INCOMPLETE_POSIX_AT_SUPPORT macro until then. Fixes the build.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33990 a95241bf-73f2-0310-859d-f6bbb57e9c96


# b189a2014e18f45b3bbb3c3d29118d7e5f167084 10-Nov-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

Added readlinkat().


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33978 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 1b32947d3f6c19dc1716a27d50361dcf59c27882 17-Mar-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

* Aligned the semantics of the read_symlink() FS module hook with the
readlink() function. It is no longer required to null-terminate the
string, shall not fail, if the buffer is too small, and shall return
the length of the string actually written into the buffer.
* Adjusted rootfs, devfs, and bfs accordingly. Also adjusted their
read_stat() hooks to return the correct symlink length in st_size.
* Our readlink() does now comply to the standard (and BeOS).
Additionally if the buffer is big enough it is nice to non-conforming
apps and null-terminates it.
* BSymLink::ReadLink() explicitly null-terminates the string now.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24425 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 5af32e752606778be5dd7379f319fe43cb3f6b8c 13-Apr-2005 Axel Dörfler <axeld@pinc-software.de>

Renamed src/kernel to src/system.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@12359 a95241bf-73f2-0310-859d-f6bbb57e9c96