libroot_build & fs_shell: Provide _kern_ functions for readv/writev...

..instead of readv_pos/writev_pos. This way, we can be sure that we
are remapping them properly even under Haiku, as well as remove some
potential confusions.

bfs_shell seems to still work fine on a regular build.
This commit is contained in:
Augustin Cavalier 2023-02-14 00:49:52 -05:00
parent 81458ef8a6
commit 5e9fd9f60d
5 changed files with 40 additions and 43 deletions

View File

@ -48,10 +48,6 @@ extern size_t strnlen(const char* string, size_t length);
#if !defined(HAIKU_HOST_PLATFORM_HAIKU)
extern ssize_t read_pos(int fd, off_t pos, void* buffer, size_t count);
extern ssize_t write_pos(int fd, off_t pos, const void* buffer, size_t count);
extern ssize_t readv_pos(int fd, off_t pos, const struct iovec* vec,
int count);
extern ssize_t writev_pos(int fd, off_t pos, const struct iovec* vec,
int count);
#endif

View File

@ -35,7 +35,9 @@ extern "C" {
#define _kern_remove_attr _kernbuild_remove_attr
#define _kern_rename_attr _kernbuild_rename_attr
#define _kern_read _kernbuild_read
#define _kern_readv _kernbuild_readv
#define _kern_write _kernbuild_write
#define _kern_writev _kernbuild_writev
#define _kern_read_dir _kernbuild_read_dir
#define _kern_rewind_dir _kernbuild_rewind_dir
#define _kern_read_stat _kernbuild_read_stat
@ -80,8 +82,12 @@ extern status_t _kern_rename_attr(int fromFile, const char *fromName,
// file descriptor functions
extern ssize_t _kern_read(int fd, off_t pos, void *buffer,
size_t bufferSize);
extern ssize_t _kern_readv(int fd, off_t pos, const struct iovec *vecs,
size_t count);
extern ssize_t _kern_write(int fd, off_t pos, const void *buffer,
size_t bufferSize);
extern ssize_t _kern_writev(int fd, off_t pos, const struct iovec *vecs,
size_t count);
extern ssize_t _kern_read_dir(int fd, struct dirent *buffer,
size_t bufferSize, uint32 maxCount);
extern status_t _kern_rewind_dir(int fd);

View File

@ -1121,18 +1121,12 @@ _kern_unlock_node(int fd)
// #pragma mark -
#if !defined(HAIKU_HOST_PLATFORM_HAIKU)
// read_pos
ssize_t
read_pos(int fd, off_t pos, void *buffer, size_t bufferSize)
{
// seek
off_t result = lseek(fd, pos, SEEK_SET);
if (result < 0)
return errno;
// read
ssize_t bytesRead = haiku_host_platform_read(fd, buffer, bufferSize);
ssize_t bytesRead = _kern_read(fd, pos, buffer, bufferSize);
if (bytesRead < 0) {
errno = bytesRead;
return -1;
@ -1141,7 +1135,6 @@ read_pos(int fd, off_t pos, void *buffer, size_t bufferSize)
return bytesRead;
}
// write_pos
ssize_t
write_pos(int fd, off_t pos, const void *buffer, size_t bufferSize)
{
@ -1158,24 +1151,19 @@ write_pos(int fd, off_t pos, const void *buffer, size_t bufferSize)
return bufferSize;
}
// seek
off_t result = lseek(fd, pos, SEEK_SET);
if (result < 0)
return errno;
// write
ssize_t bytesWritten = haiku_host_platform_write(fd, buffer, bufferSize);
if (bytesWritten < 0) {
errno = bytesWritten;
ssize_t bytesRead = _kern_write(fd, pos, buffer, bufferSize);
if (bytesRead < 0) {
errno = bytesRead;
return -1;
}
return bytesWritten;
return bytesRead;
}
#endif
// readv_pos
ssize_t
readv_pos(int fd, off_t pos, const struct iovec *vec, int count)
_kern_readv(int fd, off_t pos, const struct iovec *vec, size_t count)
{
// seek
off_t result = lseek(fd, pos, SEEK_SET);
@ -1192,9 +1180,9 @@ readv_pos(int fd, off_t pos, const struct iovec *vec, int count)
return bytesRead;
}
// writev_pos
ssize_t
writev_pos(int fd, off_t pos, const struct iovec *vec, int count)
_kern_writev(int fd, off_t pos, const struct iovec *vec, size_t count)
{
// seek
off_t result = lseek(fd, pos, SEEK_SET);
@ -1203,14 +1191,11 @@ writev_pos(int fd, off_t pos, const struct iovec *vec, int count)
// read
ssize_t bytesWritten = haiku_host_platform_writev(fd, vec, count);
if (bytesWritten < 0) {
errno = bytesWritten;
return -1;
}
if (bytesWritten < 0)
return bytesWritten;
return bytesWritten;
}
#endif
// #pragma mark -

View File

@ -18,6 +18,14 @@
#include "partition_support.h"
#if (!defined(__BEOS__) && !defined(__HAIKU__))
// Defined in libroot_build.so.
# define _kern_readv _kernbuild_readv
# define _kern_writev _kernbuild_writev
extern "C" ssize_t _kern_readv(int fd, off_t pos, const struct iovec *vecs, size_t count);
extern "C" ssize_t _kern_writev(int fd, off_t pos, const struct iovec *vecs, size_t count);
#endif
static const int kMaxIOVecs = 1024;
@ -55,14 +63,13 @@ fssh_readv(int fd, const struct fssh_iovec *vector, int count)
#if !defined(HAIKU_HOST_PLATFORM_FREEBSD)
return readv(fd, systemVecs, count);
#else
return readv_pos(fd, lseek(fd, 0, SEEK_CUR), systemVecs, count);
return _kern_readv(fd, lseek(fd, 0, SEEK_CUR), systemVecs, count);
#endif
}
fssh_ssize_t
fssh_readv_pos(int fd, fssh_off_t pos, const struct fssh_iovec *vec,
int count)
fssh_readv_pos(int fd, fssh_off_t pos, const struct fssh_iovec *vec, int count)
{
struct iovec systemVecs[kMaxIOVecs];
if (!prepare_iovecs(vec, count, systemVecs))
@ -72,7 +79,7 @@ fssh_readv_pos(int fd, fssh_off_t pos, const struct fssh_iovec *vec,
if (FSShell::restricted_file_restrict_io(fd, pos, length) < 0)
return -1;
return readv_pos(fd, pos, systemVecs, count);
return _kern_readv(fd, pos, systemVecs, count);
}
@ -91,14 +98,13 @@ fssh_writev(int fd, const struct fssh_iovec *vector, int count)
#if !defined(HAIKU_HOST_PLATFORM_FREEBSD)
return writev(fd, systemVecs, count);
#else
return writev_pos(fd, lseek(fd, 0, SEEK_CUR), systemVecs, count);
return _kern_writev(fd, lseek(fd, 0, SEEK_CUR), systemVecs, count);
#endif
}
fssh_ssize_t
fssh_writev_pos(int fd, fssh_off_t pos, const struct fssh_iovec *vec,
int count)
fssh_writev_pos(int fd, fssh_off_t pos, const struct fssh_iovec *vec, int count)
{
struct iovec systemVecs[kMaxIOVecs];
if (!prepare_iovecs(vec, count, systemVecs))
@ -108,5 +114,5 @@ fssh_writev_pos(int fd, fssh_off_t pos, const struct fssh_iovec *vec,
if (FSShell::restricted_file_restrict_io(fd, pos, length) < 0)
return -1;
return writev_pos(fd, pos, systemVecs, count);
return _kern_writev(fd, pos, systemVecs, count);
}

View File

@ -41,8 +41,12 @@
#if (!defined(__BEOS__) && !defined(__HAIKU__))
// Defined in libroot_build.so.
# define _kern_read _kernbuild_read
# define _kern_write _kernbuild_write
# define _kern_dup _kernbuild_dup
# define _kern_close _kernbuild_close
extern "C" ssize_t _kern_read(int fd, off_t pos, void *buffer, size_t bufferSize);
extern "C" ssize_t _kern_write(int fd, off_t pos, const void *buffer, size_t bufferSize);
extern "C" int _kern_dup(int fd);
extern "C" status_t _kern_close(int fd);
#endif
@ -372,7 +376,7 @@ fssh_read(int fd, void *buffer, fssh_size_t count)
return -1;
return read(fd, buffer, count);
#else
fssh_ssize_t bytesRead = read_pos(fd, fssh_lseek(fd, 0, FSSH_SEEK_CUR),
fssh_ssize_t bytesRead = _kern_read(fd, fssh_lseek(fd, 0, FSSH_SEEK_CUR),
buffer, count);
if (bytesRead > 0)
fssh_lseek(fd, bytesRead, FSSH_SEEK_CUR);
@ -386,7 +390,7 @@ fssh_read_pos(int fd, fssh_off_t pos, void *buffer, fssh_size_t count)
{
if (FSShell::restricted_file_restrict_io(fd, pos, count) < 0)
return -1;
return read_pos(fd, pos, buffer, count);
return _kern_read(fd, pos, buffer, count);
}
@ -413,7 +417,7 @@ fssh_write_pos(int fd, fssh_off_t pos, const void *buffer, fssh_size_t count)
{
if (FSShell::restricted_file_restrict_io(fd, pos, count) < 0)
return -1;
return write_pos(fd, pos, buffer, count);
return _kern_write(fd, pos, buffer, count);
}