History log of /haiku/src/add-ons/kernel/file_systems/exfat/kernel_interface.cpp
Revision Date Author Comments
# 4133750c 27-Jan-2023 Augustin Cavalier <waddlesplash@gmail.com>

exfat & xfs: Adapt to use next_dirent and shared open_mode_to_access.


# cf5f513b 27-Apr-2022 Jérôme Duval <jerome.duval@gmail.com>

file_systems: add entry_cache_(add/missing) in btrfs,ext2,exfat lookup methods.

Change-Id: I77857421a65f371bc885f1d4eb66ef2ab4376e56
Reviewed-on: https://review.haiku-os.org/c/haiku/+/5252
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
Reviewed-by: waddlesplash <waddlesplash@gmail.com>


# 711e2dc0 01-Dec-2021 Augustin Cavalier <waddlesplash@gmail.com>

Adjust all struct dirent creations (again), this time to use offsetof().

The dirent struct is not packed, so offsetof(dirent, d_name) != sizeof(dirent).
Thus in order not to waste the alignment bytes (which are significant,
on x86_64 at least, sizeof(dirent)==32, but offsetof(...)=26.)

This is also the most portable way to handle things, and should
work just fine in cross-platform code that has a non-zero-sized d_name.


# 9d242fb9 18-Nov-2021 Augustin Cavalier <waddlesplash@gmail.com>

file_systems & Tracker: Do not assume sizeof(dirent) contains 1 byte for the name.

At present, it does, but that is an oddity we have preserved from BeOS
that the next commit is going to remove. (This commit thus wastes 1 byte
without the following one.)

Most changes are pretty straightforward: only a +1 is needed,
and a few removed from sizing calculations. Some filesystems like UDF
originally passed back the length with the \0 included, so they have
been adjusted further. UFS2 had some other sizing problems which are also
corrected in this commit.


# 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>


# 72bfb144 17-Jul-2019 Adrien Destugues <pulkomandy@pulkomandy.tk>

PVS V1028: cast result of operation instead of operands

If an overflow occurs before the cast, we can't fix it. If we cast
first, we can rely on integer promotion to make the result use the
appropriate size.

Change-Id: I7462e28422456c07f179f94d39c10c408d9bec36
Reviewed-on: https://review.haiku-os.org/c/1623
Reviewed-by: waddlesplash <waddlesplash@gmail.com>


# 6f7fc220 07-Mar-2016 Axel Dörfler <axeld@pinc-software.de>

NodeMonitor: Added B_WATCH_CHILDREN flag.

* Added a directory argument for notify_{stat/attribute}_changed().
* This allows to watch only a directory, and get the notifications for
all of its files, not just add/remove entry notifications.


# ebd3bcdb 12-Feb-2014 John Scipione <jscipione@gmail.com>

exfat: handle 4-byte UTF-16 surrogate pairs

... in filenames. Replace the existing Unicode conversion functions
with UTF conversion functions from js that he relicensed MIT for us.

Put the UTF conversion functions in a private but shared code location
so that they can be accessed throughout the kernel.

Right now we only provide functions to convert between UTF-8 and UTF-16.
At some point we should also add functions to convert between UTF-8 and
UTF-32 and UTF-16 and UTF-32 but these aren't needed by exfat.

Remove the old Unicode conversion functions from exfat as they assumed
UCS-2 characters and don't work with UTF-16 used by exfat.

Rename most variables with the term length with code unit where code units
are intended. The term length, when used, means length in bytes while code
units represent either a full 2-byte UTF-16 character or half a 4-byte
surrogate pair.


# 3472fc55 06-Feb-2014 John Scipione <jscipione@gmail.com>

exfat: style fix param/variable renaming

Pass the partition size into the default name, not the device size,
this makes the variable names match the comment.

There is no functional change here, the variable names got renamed
to make it more clear what's happening. We want show the partition
size, not the device size, and we want to error if the device size is less
than the partition size, not if the partition size is less than the device size.


# dae266a8 05-Feb-2014 John Scipione <jscipione@gmail.com>

exfat: fix problems with hrev46820

* Set the size of the volume name member var to B_FILE_NAME_LENGTH which is the
max width of a volume name according to the BeBook and the Support Kit code. We'll
deal with trying to stuff the volume name back into the exfat volume label later.
* Rename volume_name() to get_volume_name()
* Pass the name string length into get_volume_name() and use it to avoid buffer overrun.
* Fill name with a blank string if volume has no label.
* Don't memset the name with zeros before doing the conversion from Unicode to UTF-8,
the conversion function will make sure the result is NUL-terminated if it returns B_OK.
* Also check the return value of the Unicode conversion function and return an error if it fails.
* Add get_default_volume_name() method to Utility.cpp which is used to fill out the default
volume name in the case volume name is blank. e.g. 32GiB ExFAT Volume. This now
applies to both the volume name and mount point.
* Use non-metric prefixes for default volume name, e.g. MiB, GiB, TiB
* For an unset volume name fill the volume name with an empty string.
* Remove the leading underscore from _name and _partition parameters
* Replace size constants with sizeof() calls
* Remove Axel from the copyright statement in Utility.cpp, he had nothing to do with it,
add Jérôme (aka korli) because he wrote the code for get_default_volume_name()
(was in Volumes.cpp)
* Remove some trailing spaces from encodings.cpp

Thanks Axel.


# 762b846c 04-Feb-2014 John Scipione <jscipione@gmail.com>

exfat: Set the mountpoint to same as volume name

Fixes #10501

* update copyright headers, attribute to Haiku, Inc. add authors
* volume_name gets filled out by a utility function in Utility.cpp
* update exfat_entry
- rename name_label to just label
- adjust volume_label to have 11 uint16 chars plus 8 uint8 reserved
- add guid partition info
* Added a couple new entry type defines
* fName is 34 bytes long which fits the 11 3-byte UTF-8 chars and a \0


# aeb03a8f 04-Feb-2014 John Scipione <jscipione@gmail.com>

exfat: style fixes only


# 3f5d1e78 06-May-2013 Jérôme Duval <jerome.duval@gmail.com>

exfat: fixes 64 bit warnings


# ee668d24 04-May-2013 Jerome Duval <jerome.duval@gmail.com>

exfat: Return more than a single dirent at a time in exfat_read_dir().

* similar to what mmlr did in hrev45575 for bfs.
* DirectoryIterator could try to read past the end of the directory.
* replaced a dprintf with a TRACE() statement.


# f53ec236 02-Mar-2011 Jérôme Duval <korli@users.berlios.de>

changed ioctl hook return code when the opcode isn't supported.


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


# e74e90ae 09-Feb-2011 Jérôme Duval <korli@users.berlios.de>

* Implemented a read-only exFAT file system, tested with a 4GB image.


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


# ebd3bcdb9be2d6a57fc5b3270dcb49a9e1894d11 12-Feb-2014 John Scipione <jscipione@gmail.com>

exfat: handle 4-byte UTF-16 surrogate pairs

... in filenames. Replace the existing Unicode conversion functions
with UTF conversion functions from js that he relicensed MIT for us.

Put the UTF conversion functions in a private but shared code location
so that they can be accessed throughout the kernel.

Right now we only provide functions to convert between UTF-8 and UTF-16.
At some point we should also add functions to convert between UTF-8 and
UTF-32 and UTF-16 and UTF-32 but these aren't needed by exfat.

Remove the old Unicode conversion functions from exfat as they assumed
UCS-2 characters and don't work with UTF-16 used by exfat.

Rename most variables with the term length with code unit where code units
are intended. The term length, when used, means length in bytes while code
units represent either a full 2-byte UTF-16 character or half a 4-byte
surrogate pair.


# 3472fc553eb5a8e2d9ff40c9a33f083b6f303081 06-Feb-2014 John Scipione <jscipione@gmail.com>

exfat: style fix param/variable renaming

Pass the partition size into the default name, not the device size,
this makes the variable names match the comment.

There is no functional change here, the variable names got renamed
to make it more clear what's happening. We want show the partition
size, not the device size, and we want to error if the device size is less
than the partition size, not if the partition size is less than the device size.


# dae266a8a4141d0c1059685b78bb9bd5b27c8389 05-Feb-2014 John Scipione <jscipione@gmail.com>

exfat: fix problems with hrev46820

* Set the size of the volume name member var to B_FILE_NAME_LENGTH which is the
max width of a volume name according to the BeBook and the Support Kit code. We'll
deal with trying to stuff the volume name back into the exfat volume label later.
* Rename volume_name() to get_volume_name()
* Pass the name string length into get_volume_name() and use it to avoid buffer overrun.
* Fill name with a blank string if volume has no label.
* Don't memset the name with zeros before doing the conversion from Unicode to UTF-8,
the conversion function will make sure the result is NUL-terminated if it returns B_OK.
* Also check the return value of the Unicode conversion function and return an error if it fails.
* Add get_default_volume_name() method to Utility.cpp which is used to fill out the default
volume name in the case volume name is blank. e.g. 32GiB ExFAT Volume. This now
applies to both the volume name and mount point.
* Use non-metric prefixes for default volume name, e.g. MiB, GiB, TiB
* For an unset volume name fill the volume name with an empty string.
* Remove the leading underscore from _name and _partition parameters
* Replace size constants with sizeof() calls
* Remove Axel from the copyright statement in Utility.cpp, he had nothing to do with it,
add Jérôme (aka korli) because he wrote the code for get_default_volume_name()
(was in Volumes.cpp)
* Remove some trailing spaces from encodings.cpp

Thanks Axel.


# 762b846cf8ba678f31a854a85e68003d2071be8d 04-Feb-2014 John Scipione <jscipione@gmail.com>

exfat: Set the mountpoint to same as volume name

Fixes #10501

* update copyright headers, attribute to Haiku, Inc. add authors
* volume_name gets filled out by a utility function in Utility.cpp
* update exfat_entry
- rename name_label to just label
- adjust volume_label to have 11 uint16 chars plus 8 uint8 reserved
- add guid partition info
* Added a couple new entry type defines
* fName is 34 bytes long which fits the 11 3-byte UTF-8 chars and a \0


# aeb03a8f68bad446e3f1178fa9ea8cb3c9e460ab 04-Feb-2014 John Scipione <jscipione@gmail.com>

exfat: style fixes only


# 3f5d1e78252bb593cf5b430f37c3d18d779afab1 06-May-2013 Jérôme Duval <jerome.duval@gmail.com>

exfat: fixes 64 bit warnings


# ee668d24e34a6da029d2f188118c023929f97391 04-May-2013 Jerome Duval <jerome.duval@gmail.com>

exfat: Return more than a single dirent at a time in exfat_read_dir().

* similar to what mmlr did in hrev45575 for bfs.
* DirectoryIterator could try to read past the end of the directory.
* replaced a dprintf with a TRACE() statement.


# f53ec236e22695929663822b4050b3cfe9a10c09 02-Mar-2011 Jérôme Duval <korli@users.berlios.de>

changed ioctl hook return code when the opcode isn't supported.


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


# e74e90aef91f844d4d3654504cd0776c26a454e5 09-Feb-2011 Jérôme Duval <korli@users.berlios.de>

* Implemented a read-only exFAT file system, tested with a 4GB image.


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