e1b7c1c7ac
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>
179 lines
4.5 KiB
Plaintext
179 lines
4.5 KiB
Plaintext
/*
|
|
* Copyright 2002-2014 Haiku, Inc. All rights reserved.
|
|
* Distributed under the terms of the MIT License.
|
|
*
|
|
* Authors:
|
|
* Tyler Dauwalder
|
|
* John Scipione, jscipione@gmail.com
|
|
* Ingo Weinhold, bonefish@users.sf.net
|
|
*
|
|
* Corresponds to:
|
|
* headers/os/storage/SymLink.h hrev47402
|
|
* src/kits/storage/SymLink.cpp hrev47402
|
|
*/
|
|
|
|
|
|
/*!
|
|
\file SymLink.h
|
|
\ingroup storage
|
|
\ingroup libbe
|
|
\brief Provides the BSymLink class.
|
|
*/
|
|
|
|
|
|
/*!
|
|
\class BSymLink
|
|
\ingroup storage
|
|
\ingroup libbe
|
|
\brief Provides an interface for creating, manipulating, and accessing
|
|
the contents of symbolic links.
|
|
|
|
\since BeOS R3
|
|
*/
|
|
|
|
|
|
/*!
|
|
\fn BSymLink::BSymLink()
|
|
\brief Creates an uninitialized BSymLink object.
|
|
|
|
\since BeOS R3
|
|
*/
|
|
|
|
|
|
/*!
|
|
\fn BSymLink::BSymLink(const BSymLink& other)
|
|
\brief Creates a copy of the supplied BSymLink object.
|
|
|
|
\param other The BSymLink object to be copied.
|
|
|
|
\since BeOS R3
|
|
*/
|
|
|
|
|
|
/*!
|
|
\fn BSymLink::BSymLink(const entry_ref* ref)
|
|
\brief Creates a BSymLink object and initializes it to the symbolic link
|
|
referred to by the supplied entry_ref.
|
|
|
|
\param ref the entry_ref referring to the symbolic link.
|
|
|
|
\since BeOS R3
|
|
*/
|
|
|
|
|
|
/*!
|
|
\fn BSymLink::BSymLink(const BEntry* entry)
|
|
\brief Creates a BSymLink object and initializes it to the symbolic link
|
|
referred to by the supplied BEntry.
|
|
|
|
\param entry The BEntry referring to the symbolic link.
|
|
|
|
\since BeOS R3
|
|
*/
|
|
|
|
|
|
/*!
|
|
\fn BSymLink::BSymLink(const char* path)
|
|
\brief Creates a BSymLink object and initializes it to the symbolic link
|
|
referred to by the supplied path name.
|
|
|
|
\param path The path of the symbolic link.
|
|
|
|
\since BeOS R3
|
|
*/
|
|
|
|
|
|
/*!
|
|
\fn BSymLink::BSymLink(const BDirectory* dir, const char* path)
|
|
\brief Creates a BSymLink object and initializes it to the symbolic link
|
|
referred to by the supplied path name relative to the specified
|
|
BDirectory.
|
|
|
|
\param dir The base BDirectory.
|
|
\param path The path of the symbolic link relative to \a dir.
|
|
|
|
\since BeOS R3
|
|
*/
|
|
|
|
|
|
/*!
|
|
\fn BSymLink::~BSymLink()
|
|
\brief Destroys the object and frees all allocated resources.
|
|
|
|
If the BSymLink was properly initialized, the file descriptor of the
|
|
symbolic link is also closed.
|
|
|
|
\since BeOS R3
|
|
*/
|
|
|
|
|
|
/*!
|
|
\fn ssize_t BSymLink::ReadLink(char* buffer, size_t size)
|
|
\brief Reads the contents of the symbolic link into \a buffer.
|
|
|
|
The string written to the buffer is guaranteed to be \c NULL terminated.
|
|
|
|
This function does not return the number of bytes written into
|
|
the provided buffer. It returns the length of the symlink's
|
|
contents, even if that contents does not fit within the
|
|
provided buffer. If the buffer cannot contain the entire
|
|
contents then it will be truncated to \a size.
|
|
|
|
\param buffer The buffer to read the symlink's contents into.
|
|
\param size The size of \a buffer.
|
|
|
|
\return The length of the symlink's contents or an error code.
|
|
\retval B_BAD_VALUE \a buf was \c NULL or the object didn't refer to a
|
|
symbolic link.
|
|
\retval B_FILE_ERROR The object was not initialized.
|
|
|
|
\since BeOS R3
|
|
*/
|
|
|
|
|
|
/*!
|
|
\fn ssize_t BSymLink::MakeLinkedPath(const char* dirPath, BPath* path)
|
|
\brief Combines a directory path and the contents of this symbolic link to
|
|
form an absolute path.
|
|
|
|
\param dirPath The base directory path to combine with the symbolic link.
|
|
\param path The BPath object to be set to the resulting absolute path.
|
|
|
|
\return The length of the resulting path name or an error code.
|
|
\retval B_BAD_VALUE \a dirPath or \a path was \c NULL or the object didn't
|
|
refer to a symbolic link.
|
|
\retval B_FILE_ERROR The object was not initialized.
|
|
\retval B_NAME_TOO_LONG The resulting path name was too long to fit.
|
|
|
|
\since BeOS R3
|
|
*/
|
|
|
|
|
|
/*!
|
|
\fn ssize_t BSymLink::MakeLinkedPath(const BDirectory* dir, BPath* path)
|
|
\brief Combines a directory path and the contents of this symbolic link to
|
|
form an absolute path.
|
|
|
|
\param dir The base BDirectory object to combine with the symbolic link.
|
|
\param path the BPath object to be set to the resulting absolute path.
|
|
|
|
\return The length of the resulting path name or an error code.
|
|
\retval B_BAD_VALUE \a dir or \a path was \c NULL or the object didn't
|
|
refer to a symbolic link.
|
|
\retval B_FILE_ERROR The object was not initialized.
|
|
\retval B_NAME_TOO_LONG The resulting path name was too long to fit.
|
|
|
|
\since BeOS R3
|
|
*/
|
|
|
|
|
|
/*!
|
|
\fn bool BSymLink::IsAbsolute()
|
|
\brief Returns whether or not the object refers to an absolute path.
|
|
|
|
/return \c true if the object is properly initialized and the symbolic
|
|
link refers to an absolute path, \c false otherwise.
|
|
|
|
\since BeOS R3
|
|
*/
|