vfs: use 64bit for file offset and size

Fixes #1246
This commit is contained in:
Alexander Boettcher 2014-09-09 14:32:31 +02:00 committed by Christian Helmuth
parent 289cfa5fcf
commit 8b8c2713ae
30 changed files with 213 additions and 172 deletions

View File

@ -22,6 +22,7 @@ INC_DIR += $(LIBC_DIR)/contrib/gdtoa
# the imported source code to improve build aesthetics
#
CC_WARN =
CC_CXX_OPT += -Wall
#
# Generate position independent code to allow linking of static libc code into

View File

@ -45,11 +45,11 @@ File_descriptor *File_descriptor_allocator::alloc(Plugin *plugin,
int libc_fd)
{
/* we use addresses returned by the allocator as file descriptors */
addr_t addr = (libc_fd == ANY_FD ? ANY_FD : libc_fd);
addr_t addr = (libc_fd <= ANY_FD ? ANY_FD : libc_fd);
/* allocate fresh fd if the default value for 'libc_fd' was specified */
bool alloc_ok = false;
if (addr == ANY_FD)
if (libc_fd <= ANY_FD)
alloc_ok = Allocator_avl_base::alloc(1, reinterpret_cast<void**>(&addr));
else
alloc_ok = (Allocator_avl_base::alloc_addr(1, addr).is_ok());

View File

@ -627,7 +627,7 @@ extern "C" int _open(const char *pathname, int flags, ::mode_t mode)
plugin = plugin_registry()->get_plugin_for_open(resolved_path.base(), flags);
if (!plugin) {
PERR("no plugin found for open(\"%s\", int)", pathname, flags);
PERR("no plugin found for open(\"%s\", %d)", pathname, flags);
return -1;
}

View File

@ -28,7 +28,7 @@ extern "C" int raw_write_str(const char *s);
/*
* Discard external references to 'raw_write_str'
*/
static inline int raw_write_str(const char *s) { }
static inline int raw_write_str(const char *s) { return 0; }
#endif /* LIBC_DEBUG == 1 */

View File

@ -21,7 +21,10 @@
#include <util/misc_math.h>
/* libc includes */
extern "C" {
#include <string.h>
#include <stdlib.h>
}
typedef unsigned long Block_header;
@ -171,14 +174,14 @@ static Genode::Allocator *allocator()
}
extern "C" void *malloc(unsigned size)
extern "C" void *malloc(size_t size)
{
void *addr;
return allocator()->alloc(size, &addr) ? addr : 0;
}
extern "C" void *calloc(unsigned nmemb, unsigned size)
extern "C" void *calloc(size_t nmemb, size_t size)
{
void *addr = malloc(nmemb*size);
Genode::memset(addr, 0, nmemb*size);
@ -194,7 +197,7 @@ extern "C" void free(void *ptr)
}
extern "C" void *realloc(void *ptr, Genode::size_t size)
extern "C" void *realloc(void *ptr, size_t size)
{
if (!ptr)
return malloc(size);

View File

@ -50,13 +50,13 @@ __attribute__((weak))
poll(struct pollfd fds[], nfds_t nfds, int timeout)
{
nfds_t i;
int saved_errno, ret, fd, maxfd = 0;
int ret, fd, maxfd = 0;
fd_set readfds, writefds, exceptfds;
struct timeval tv, *tvp = NULL;
for (i = 0; i < nfds; i++) {
fd = fds[i].fd;
if (fd >= FD_SETSIZE) {
if (fd >= (int)FD_SETSIZE) {
/*errno = EINVAL;*/
return -1;
}

View File

@ -280,7 +280,7 @@ pselect(int nfds, fd_set *readfds, fd_set *writefds,
fd_set *exceptfds, const struct timespec *timeout,
const sigset_t *sigmask)
{
struct timeval tv, *tvp;
struct timeval tv;
sigset_t origmask;
int nready;

View File

@ -42,7 +42,7 @@ extern "C" int __sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp,
* the actual page size.
*/
if (((name[0] == CTL_HW) && (name[1] == HW_PAGESIZE)) ||
(name[0] == CTL_P1003_1B) && (name[1] == CTL_P1003_1B_PAGESIZE)) {
((name[0] == CTL_P1003_1B) && (name[1] == CTL_P1003_1B_PAGESIZE))) {
int result = 4096;
if (oldp) {
if (*oldlenp >= sizeof(result)) {

View File

@ -513,7 +513,7 @@ ssize_t Libc::Vfs_plugin::write(Libc::File_descriptor *fd, const void *buf,
Vfs::Vfs_handle *handle = vfs_handle(fd);
size_t out_count = 0;
Vfs::file_size out_count = 0;
switch (handle->fs().write(handle, (char const *)buf, count, out_count)) {
case Result::WRITE_ERR_AGAIN: errno = EAGAIN; return -1;
@ -537,7 +537,7 @@ ssize_t Libc::Vfs_plugin::read(Libc::File_descriptor *fd, void *buf,
Vfs::Vfs_handle *handle = vfs_handle(fd);
Genode::size_t out_count = 0;
Vfs::file_size out_count = 0;
switch (handle->fs().read(handle, (char *)buf, count, out_count)) {
case Result::READ_ERR_AGAIN: errno = EAGAIN; PERR("A1"); return -1;
@ -852,7 +852,7 @@ ssize_t Libc::Vfs_plugin::readlink(const char *path, char *buf, size_t buf_size)
{
typedef Vfs::Directory_service::Readlink_result Result;
size_t out_len = 0;
Vfs::file_size out_len = 0;
switch (_root_dir.readlink(path, buf, buf_size, out_len)) {
case Result::READLINK_ERR_NO_ENTRY: errno = ENOENT; return -1;

View File

@ -70,14 +70,16 @@ class Jitterentropy_file_system : public Vfs::Single_file_system
** File I/O service interface **
********************************/
Write_result write(Vfs::Vfs_handle *, char const *, Genode::size_t count,
Genode::size_t &count_out) override
Write_result write(Vfs::Vfs_handle *, char const *,
Vfs::file_size count,
Vfs::file_size &count_out) override
{
return WRITE_ERR_IO;
}
Read_result read(Vfs::Vfs_handle *vfs_handle, char *dst, Genode::size_t count,
Genode::size_t &out_count) override
Read_result read(Vfs::Vfs_handle *vfs_handle, char *dst,
Vfs::file_size count,
Vfs::file_size &out_count) override
{
if (!_initialized)
return READ_ERR_IO;

View File

@ -49,7 +49,7 @@ class Vfs::Block_file_system : public Single_file_system
Genode::Allocator_avl _tx_block_alloc;
Block::Connection _block;
size_t _block_size;
Genode::size_t _block_size;
Block::sector_t _block_count;
Block::Session::Operations _block_ops;
Block::Session::Tx::Source *_tx_source;
@ -57,15 +57,16 @@ class Vfs::Block_file_system : public Single_file_system
bool _readable;
bool _writeable;
size_t _block_io(size_t nr, void *buf, size_t sz, bool write, bool bulk = false)
file_size _block_io(file_size nr, void *buf, file_size sz,
bool write, bool bulk = false)
{
Lock::Guard guard(_lock);
Block::Packet_descriptor::Opcode op;
op = write ? Block::Packet_descriptor::WRITE : Block::Packet_descriptor::READ;
size_t packet_size = bulk ? sz : _block_size;
size_t packet_count = bulk ? (sz / _block_size) : 1;
file_size packet_size = bulk ? sz : _block_size;
file_size packet_count = bulk ? (sz / _block_size) : 1;
/* sanity check */
if (packet_count > _block_buffer_count) {
@ -135,7 +136,7 @@ class Vfs::Block_file_system : public Single_file_system
Stat_result stat(char const *path, Stat &out) override
{
Stat_result const result = Single_file_system::stat(path, out);
out.size = _block_size*_block_count;
out.size = _block_count * _block_size;
return result;
}
@ -144,22 +145,22 @@ class Vfs::Block_file_system : public Single_file_system
** File I/O service interface **
********************************/
Write_result write(Vfs_handle *vfs_handle, char const *buf, size_t count,
size_t &out_count) override
Write_result write(Vfs_handle *vfs_handle, char const *buf,
file_size count, file_size &out_count) override
{
if (!_writeable) {
PERR("block device is not writeable");
return WRITE_ERR_INVALID;
}
size_t seek_offset = vfs_handle->seek();
file_size seek_offset = vfs_handle->seek();
size_t written = 0;
file_size written = 0;
while (count > 0) {
size_t displ = 0;
size_t length = 0;
size_t nbytes = 0;
size_t blk_nr = seek_offset / _block_size;
file_size displ = 0;
file_size length = 0;
file_size nbytes = 0;
file_size blk_nr = seek_offset / _block_size;
displ = seek_offset % _block_size;
@ -178,12 +179,12 @@ class Vfs::Block_file_system : public Single_file_system
* blocks at the end.
*/
if (displ == 0 && (count % _block_size) >= 0 && !(count < _block_size)) {
size_t bytes_left = count - (count % _block_size);
file_size bytes_left = count - (count % _block_size);
nbytes = _block_io(blk_nr, (void*)(buf + written),
bytes_left, true, true);
if (nbytes == 0) {
PERR("error while write block:%zu from block device",
PERR("error while write block:%llu from block device",
blk_nr);
return WRITE_ERR_INVALID;
}
@ -202,7 +203,7 @@ class Vfs::Block_file_system : public Single_file_system
* than block size, we also have to read the block first.
*/
if (displ > 0 || length < _block_size) {
PWRN("offset:%zd block_size:%zd displacement:%zd length:%zu",
PWRN("offset:%llu block_size:%zd displacement:%llu length:%llu",
seek_offset, _block_size, displ, length);
_block_io(blk_nr, _block_buffer, _block_size, false);
@ -214,7 +215,7 @@ class Vfs::Block_file_system : public Single_file_system
nbytes = _block_io(blk_nr, _block_buffer, _block_size, true);
if ((unsigned)nbytes != _block_size) {
PERR("error while writing block:%zu from Block_device",
PERR("error while writing block:%llu from Block_device",
blk_nr);
return WRITE_ERR_INVALID;
}
@ -228,22 +229,22 @@ class Vfs::Block_file_system : public Single_file_system
return WRITE_OK;
}
Read_result read(Vfs_handle *vfs_handle, char *dst, size_t count,
size_t &out_count) override
Read_result read(Vfs_handle *vfs_handle, char *dst, file_size count,
file_size &out_count) override
{
if (!_readable) {
PERR("block device is not readable");
return READ_ERR_INVALID;
}
size_t seek_offset = vfs_handle->seek();
file_size seek_offset = vfs_handle->seek();
size_t read = 0;
file_size read = 0;
while (count > 0) {
size_t displ = 0;
size_t length = 0;
size_t nbytes = 0;
size_t blk_nr = seek_offset / _block_size;
file_size displ = 0;
file_size length = 0;
file_size nbytes = 0;
file_size blk_nr = seek_offset / _block_size;
displ = seek_offset % _block_size;
@ -262,11 +263,11 @@ class Vfs::Block_file_system : public Single_file_system
* blocks at the end.
*/
if (displ == 0 && (count % _block_size) >= 0 && !(count < _block_size)) {
size_t bytes_left = count - (count % _block_size);
file_size bytes_left = count - (count % _block_size);
nbytes = _block_io(blk_nr, dst + read, bytes_left, false, true);
if (nbytes == 0) {
PERR("error while reading block:%zu from block device",
PERR("error while reading block:%llu from block device",
blk_nr);
return READ_ERR_INVALID;
}
@ -278,13 +279,13 @@ class Vfs::Block_file_system : public Single_file_system
}
if (displ > 0)
PWRN("offset:%zd is not aligned to block_size:%zu"
" displacement:%zu", seek_offset, _block_size,
PWRN("offset:%llu is not aligned to block_size:%zu"
" displacement:%llu", seek_offset, _block_size,
displ);
nbytes = _block_io(blk_nr, _block_buffer, _block_size, false);
if ((unsigned)nbytes != _block_size) {
PERR("error while reading block:%zu from block device",
PERR("error while reading block:%llu from block device",
blk_nr);
return READ_ERR_INVALID;
}
@ -300,7 +301,7 @@ class Vfs::Block_file_system : public Single_file_system
return READ_OK;
}
Ftruncate_result ftruncate(Vfs_handle *vfs_handle, size_t) override
Ftruncate_result ftruncate(Vfs_handle *vfs_handle, file_size) override
{
return FTRUNCATE_OK;
}

View File

@ -128,7 +128,7 @@ class Vfs::Dir_file_system : public File_system
if (path[0] == '/')
path++;
size_t const name_len = strlen(_name);
Genode::size_t const name_len = strlen(_name);
if (strcmp(path, _name, name_len) != 0)
return 0;
path += name_len;
@ -147,7 +147,7 @@ class Vfs::Dir_file_system : public File_system
/**
* The 'path' is relative to the child file systems.
*/
Dirent_result _dirent_of_file_systems(char const *path, off_t index, Dirent &out)
Dirent_result _dirent_of_file_systems(char const *path, file_offset index, Dirent &out)
{
int base = 0;
for (File_system *fs = _first_file_system; fs; fs = fs->next) {
@ -177,7 +177,7 @@ class Vfs::Dir_file_system : public File_system
return DIRENT_OK;
}
void _dirent_of_this_dir_node(off_t index, Dirent &out)
void _dirent_of_this_dir_node(file_offset index, Dirent &out)
{
if (index == 0) {
strncpy(out.name, _name, sizeof(out.name));
@ -193,9 +193,9 @@ class Vfs::Dir_file_system : public File_system
* Accumulate number of directory entries that match in any of
* our sub file systems.
*/
size_t _sum_dirents_of_file_systems(char const *path)
file_size _sum_dirents_of_file_systems(char const *path)
{
size_t cnt = 0;
file_size cnt = 0;
for (File_system *fs = _first_file_system; fs; fs = fs->next) {
cnt += fs->num_dirent(path);
}
@ -311,7 +311,7 @@ class Vfs::Dir_file_system : public File_system
return STAT_ERR_NO_ENTRY;
}
Dirent_result dirent(char const *path, off_t index, Dirent &out) override
Dirent_result dirent(char const *path, file_offset index, Dirent &out) override
{
if (_is_root())
return _dirent_of_file_systems(path, index, out);
@ -333,7 +333,7 @@ class Vfs::Dir_file_system : public File_system
return _dirent_of_file_systems(path, index, out);
}
size_t num_dirent(char const *path) override
file_size num_dirent(char const *path) override
{
if (_is_root()) {
return _sum_dirents_of_file_systems(path);
@ -447,8 +447,8 @@ class Vfs::Dir_file_system : public File_system
path, unlink_fn);
}
Readlink_result readlink(char const *path, char *buf, size_t buf_size,
size_t &out_len) override
Readlink_result readlink(char const *path, char *buf, file_size buf_size,
file_size &out_len) override
{
auto readlink_fn = [&] (File_system &fs, char const *path)
{
@ -521,17 +521,18 @@ class Vfs::Dir_file_system : public File_system
** File I/O service interface **
********************************/
Write_result write(Vfs_handle *handle, char const *, size_t, size_t &) override
Write_result write(Vfs_handle *handle, char const *, file_size,
file_size &) override
{
return WRITE_ERR_INVALID;
}
Read_result read(Vfs_handle *, char *, size_t, size_t &) override
Read_result read(Vfs_handle *, char *, file_size, file_size &) override
{
return READ_ERR_INVALID;
}
Ftruncate_result ftruncate(Vfs_handle *, size_t) override
Ftruncate_result ftruncate(Vfs_handle *, file_size) override
{
return FTRUNCATE_ERR_NO_PERM;
}

View File

@ -74,7 +74,7 @@ struct Vfs::Directory_service
struct Stat
{
size_t size;
file_size size;
unsigned mode;
unsigned uid;
unsigned gid;
@ -112,7 +112,7 @@ struct Vfs::Directory_service
char name[DIRENT_MAX_NAME_LEN];
};
virtual Dirent_result dirent(char const *path, off_t index, Dirent &) = 0;
virtual Dirent_result dirent(char const *path, file_offset index, Dirent &) = 0;
/************
@ -130,8 +130,8 @@ struct Vfs::Directory_service
enum Readlink_result { READLINK_ERR_NO_ENTRY, READLINK_OK };
virtual Readlink_result readlink(char const *path, char *buf, size_t buf_size,
size_t &out_len) = 0;
virtual Readlink_result readlink(char const *path, char *buf,
file_size buf_size, file_size &out_len) = 0;
/************
@ -169,7 +169,7 @@ struct Vfs::Directory_service
/**
* Return number of directory entries located at given path
*/
virtual size_t num_dirent(char const *path) = 0;
virtual file_size num_dirent(char const *path) = 0;
virtual bool is_directory(char const *path) = 0;

View File

@ -34,8 +34,8 @@ struct Vfs::File_io_service
WRITE_ERR_INTERRUPT, WRITE_OK };
virtual Write_result write(Vfs_handle *vfs_handle,
char const *buf, size_t buf_size,
size_t &out_count) = 0;
char const *buf, file_size buf_size,
file_size &out_count) = 0;
/**********
@ -46,8 +46,8 @@ struct Vfs::File_io_service
READ_ERR_INVALID, READ_ERR_IO,
READ_ERR_INTERRUPT, READ_OK };
virtual Read_result read(Vfs_handle *vfs_handle, char *dst, size_t count,
size_t &out_count) = 0;
virtual Read_result read(Vfs_handle *vfs_handle, char *dst, file_size count,
file_size &out_count) = 0;
/***************
@ -57,7 +57,7 @@ struct Vfs::File_io_service
enum Ftruncate_result { FTRUNCATE_ERR_NO_PERM = NUM_GENERAL_ERRORS,
FTRUNCATE_ERR_INTERRUPT, FTRUNCATE_OK };
virtual Ftruncate_result ftruncate(Vfs_handle *vfs_handle, size_t len) = 0;
virtual Ftruncate_result ftruncate(Vfs_handle *vfs_handle, file_size len) = 0;
/***********

View File

@ -90,13 +90,13 @@ class Vfs::Fs_file_system : public File_system
~Fs_handle_guard() { _fs.close(_handle); }
};
size_t _read(::File_system::Node_handle node_handle, void *buf,
size_t const count, size_t const seek_offset)
file_size _read(::File_system::Node_handle node_handle, void *buf,
file_size const count, file_size const seek_offset)
{
::File_system::Session::Tx::Source &source = *_fs.tx();
size_t const max_packet_size = source.bulk_buffer_size() / 2;
size_t const clipped_count = min(max_packet_size, count);
file_size const max_packet_size = source.bulk_buffer_size() / 2;
file_size const clipped_count = min(max_packet_size, count);
::File_system::Packet_descriptor const
packet_in(source.alloc_packet(clipped_count),
@ -113,7 +113,7 @@ class Vfs::Fs_file_system : public File_system
::File_system::Packet_descriptor const
packet_out = source.get_acked_packet();
size_t const read_num_bytes = min(packet_out.length(), count);
file_size const read_num_bytes = min(packet_out.length(), count);
memcpy(buf, source.packet_content(packet_out), read_num_bytes);
@ -127,12 +127,12 @@ class Vfs::Fs_file_system : public File_system
return read_num_bytes;
}
size_t _write(::File_system::Node_handle node_handle,
const char *buf, size_t count, size_t seek_offset)
file_size _write(::File_system::Node_handle node_handle,
const char *buf, file_size count, file_size seek_offset)
{
::File_system::Session::Tx::Source &source = *_fs.tx();
size_t const max_packet_size = source.bulk_buffer_size() / 2;
file_size const max_packet_size = source.bulk_buffer_size() / 2;
count = min(max_packet_size, count);
::File_system::Packet_descriptor
@ -207,12 +207,13 @@ class Vfs::Fs_file_system : public File_system
local_addr = env()->rm_session()->attach(ds_cap);
::File_system::Session::Tx::Source &source = *_fs.tx();
size_t const max_packet_size = source.bulk_buffer_size() / 2;
file_size const max_packet_size = source.bulk_buffer_size() / 2;
for (size_t seek_offset = 0; seek_offset < status.size;
for (file_size seek_offset = 0; seek_offset < status.size;
seek_offset += max_packet_size) {
size_t const count = min(max_packet_size, status.size - seek_offset);
file_size const count = min(max_packet_size, status.size -
seek_offset);
::File_system::Packet_descriptor
packet(source.alloc_packet(count),
@ -281,7 +282,7 @@ class Vfs::Fs_file_system : public File_system
return STAT_OK;
}
Dirent_result dirent(char const *path, off_t index, Dirent &out) override
Dirent_result dirent(char const *path, file_offset index, Dirent &out) override
{
Lock::Guard guard(_lock);
@ -362,8 +363,8 @@ class Vfs::Fs_file_system : public File_system
return UNLINK_OK;
}
Readlink_result readlink(char const *path, char *buf, size_t buf_size,
size_t &out_len) override
Readlink_result readlink(char const *path, char *buf, file_size buf_size,
file_size &out_len) override
{
/*
* Canonicalize path (i.e., path must start with '/')
@ -477,7 +478,7 @@ class Vfs::Fs_file_system : public File_system
return SYMLINK_ERR_NO_ENTRY;
}
size_t num_dirent(char const *path) override
file_size num_dirent(char const *path) override
{
if (strcmp(path, "") == 0)
path = "/";
@ -581,8 +582,8 @@ class Vfs::Fs_file_system : public File_system
** File I/O service interface **
********************************/
Write_result write(Vfs_handle *vfs_handle, char const *buf, size_t buf_size,
size_t &out_count) override
Write_result write(Vfs_handle *vfs_handle, char const *buf,
file_size buf_size, file_size &out_count) override
{
Lock::Guard guard(_lock);
@ -593,18 +594,18 @@ class Vfs::Fs_file_system : public File_system
return WRITE_OK;
}
Read_result read(Vfs_handle *vfs_handle, char *dst, size_t count,
size_t &out_count) override
Read_result read(Vfs_handle *vfs_handle, char *dst, file_size count,
file_size &out_count) override
{
Lock::Guard guard(_lock);
Fs_vfs_handle const *handle = static_cast<Fs_vfs_handle *>(vfs_handle);
::File_system::Status status = _fs.status(handle->file_handle());
size_t const file_size = status.size;
file_size const size_of_file = status.size;
size_t const file_bytes_left = file_size >= handle->seek()
? file_size - handle->seek() : 0;
file_size const file_bytes_left = size_of_file >= handle->seek()
? size_of_file - handle->seek() : 0;
count = min(count, file_bytes_left);
@ -613,7 +614,7 @@ class Vfs::Fs_file_system : public File_system
return READ_OK;
}
Ftruncate_result ftruncate(Vfs_handle *vfs_handle, size_t len) override
Ftruncate_result ftruncate(Vfs_handle *vfs_handle, file_size len) override
{
Fs_vfs_handle const *handle = static_cast<Fs_vfs_handle *>(vfs_handle);

View File

@ -27,7 +27,7 @@ class Vfs::Inline_file_system : public Single_file_system
private:
char const * const _base;
size_t const _size;
file_size const _size;
public:
@ -57,23 +57,24 @@ class Vfs::Inline_file_system : public Single_file_system
** File I/O service interface **
********************************/
Write_result write(Vfs_handle *, char const *, size_t, size_t &count_out) override
Write_result write(Vfs_handle *, char const *, file_size,
file_size &count_out) override
{
count_out = 0;
return WRITE_ERR_INVALID;
}
Read_result read(Vfs_handle *vfs_handle, char *dst, size_t count,
size_t &out_count) override
Read_result read(Vfs_handle *vfs_handle, char *dst, file_size count,
file_size &out_count) override
{
/* file read limit is the size of the dataspace */
size_t const max_size = _size;
file_size const max_size = _size;
/* current read offset */
size_t const read_offset = vfs_handle->seek();
file_size const read_offset = vfs_handle->seek();
/* maximum read offset, clamped to dataspace size */
size_t const end_offset = min(count + read_offset, max_size);
file_size const end_offset = min(count + read_offset, max_size);
/* source address within the dataspace */
char const *src = _base + read_offset;
@ -85,7 +86,7 @@ class Vfs::Inline_file_system : public Single_file_system
}
/* copy-out bytes from ROM dataspace */
size_t const num_bytes = end_offset - read_offset;
file_size const num_bytes = end_offset - read_offset;
memcpy(dst, src, num_bytes);

View File

@ -40,7 +40,8 @@ class Vfs::Log_file_system : public Single_file_system
** File I/O service interface **
********************************/
Write_result write(Vfs_handle *, char const *src, size_t count, size_t &out_count) override
Write_result write(Vfs_handle *, char const *src, file_size count,
file_size &out_count) override
{
out_count = count;
@ -58,7 +59,8 @@ class Vfs::Log_file_system : public Single_file_system
return WRITE_OK;
}
Read_result read(Vfs_handle *, char *dst, size_t count, size_t &out_count) override
Read_result read(Vfs_handle *, char *, file_size,
file_size &out_count) override
{
out_count = 0;
return READ_OK;

View File

@ -34,21 +34,23 @@ struct Vfs::Null_file_system : Single_file_system
** File I/O service interface **
********************************/
Write_result write(Vfs_handle *handle, char const *, size_t count, size_t &out_count) override
Write_result write(Vfs_handle *handle, char const *, file_size count,
file_size &out_count) override
{
out_count = count;
return WRITE_OK;
}
Read_result read(Vfs_handle *vfs_handle, char *, size_t, size_t &out_count) override
Read_result read(Vfs_handle *vfs_handle, char *, file_size,
file_size &out_count) override
{
out_count = 0;
return READ_OK;
}
Ftruncate_result ftruncate(Vfs_handle *vfs_handle, size_t) override
Ftruncate_result ftruncate(Vfs_handle *vfs_handle, file_size) override
{
return FTRUNCATE_OK;
}

View File

@ -74,23 +74,24 @@ class Vfs::Rom_file_system : public Single_file_system
** File I/O service interface **
********************************/
Write_result write(Vfs_handle *, char const *, size_t, size_t &count_out) override
Write_result write(Vfs_handle *, char const *, file_size,
file_size &count_out) override
{
count_out = 0;
return WRITE_ERR_INVALID;
}
Read_result read(Vfs_handle *vfs_handle, char *dst, size_t count,
size_t &out_count) override
Read_result read(Vfs_handle *vfs_handle, char *dst, file_size count,
file_size &out_count) override
{
/* file read limit is the size of the dataspace */
size_t const max_size = _rom.size();
file_size const max_size = _rom.size();
/* current read offset */
size_t const read_offset = vfs_handle->seek();
file_size const read_offset = vfs_handle->seek();
/* maximum read offset, clamped to dataspace size */
size_t const end_offset = min(count + read_offset, max_size);
file_size const end_offset = min(count + read_offset, max_size);
/* source address within the dataspace */
char const *src = _rom.local_addr<char>() + read_offset;
@ -102,7 +103,7 @@ class Vfs::Rom_file_system : public Single_file_system
}
/* copy-out bytes from ROM dataspace */
size_t const num_bytes = end_offset - read_offset;
file_size const num_bytes = end_offset - read_offset;
memcpy(dst, src, num_bytes);

View File

@ -44,7 +44,8 @@ class Vfs::Rtc_file_system : public Single_file_system
** File I/O service interface **
********************************/
Write_result write(Vfs_handle *, char const *, size_t count, size_t &count_out) override
Write_result write(Vfs_handle *, char const *, file_size,
file_size &) override
{
return WRITE_ERR_IO;
}
@ -55,7 +56,8 @@ class Vfs::Rtc_file_system : public Single_file_system
* On each read the current time is queried and afterwards formated
* as '%Y-%m-%d %H:%M\n'.
*/
Read_result read(Vfs_handle *vfs_handle, char *dst, size_t count, size_t &out_count) override
Read_result read(Vfs_handle *vfs_handle, char *dst, file_size count,
file_size &out_count) override
{
time_t t = _rtc.get_current_time() / 1000000ULL;
@ -67,7 +69,7 @@ class Vfs::Rtc_file_system : public Single_file_system
1 + tm->tm_mon, /* months since January [0-11] */
tm->tm_mday, tm->tm_hour, tm->tm_min);
size_t len = count > sizeof(buf) ? sizeof(buf) : count;
file_size len = count > sizeof(buf) ? sizeof(buf) : count;
Genode::memcpy(dst, buf, len);
out_count = len;

View File

@ -87,7 +87,7 @@ class Vfs::Single_file_system : public File_system
return STAT_OK;
}
Dirent_result dirent(char const *path, off_t index, Dirent &out) override
Dirent_result dirent(char const *path, file_offset index, Dirent &out) override
{
if (!_is_root(path))
return DIRENT_ERR_INVALID_PATH;
@ -106,7 +106,7 @@ class Vfs::Single_file_system : public File_system
return DIRENT_OK;
}
size_t num_dirent(char const *path) override
file_size num_dirent(char const *path) override
{
if (_is_root(path))
return 1;
@ -127,7 +127,8 @@ class Vfs::Single_file_system : public File_system
return path;
}
Open_result open(char const *path, unsigned, Vfs_handle **out_handle) override
Open_result open(char const *path, unsigned,
Vfs_handle **out_handle) override
{
if (!_is_single_file(path))
return OPEN_ERR_UNACCESSIBLE;
@ -141,7 +142,8 @@ class Vfs::Single_file_system : public File_system
return UNLINK_ERR_NO_PERM;
}
Readlink_result readlink(char const *, char *, size_t, size_t &) override
Readlink_result readlink(char const *, char *, file_size,
file_size &) override
{
return READLINK_ERR_NO_ENTRY;
}
@ -166,7 +168,7 @@ class Vfs::Single_file_system : public File_system
** File I/O service interface **
********************************/
Ftruncate_result ftruncate(Vfs_handle *vfs_handle, size_t) override
Ftruncate_result ftruncate(Vfs_handle *vfs_handle, file_size) override
{
return FTRUNCATE_ERR_NO_PERM;
}

View File

@ -38,7 +38,7 @@ class Vfs::Tar_file_system : public File_system
Genode::Rom_connection _rom;
char *_tar_base;
size_t _tar_size;
file_size _tar_size;
class Record
{
@ -81,7 +81,7 @@ class Vfs::Tar_file_system : public File_system
enum { TYPE_FILE = 0, TYPE_HARDLINK = 1,
TYPE_SYMLINK = 2, TYPE_DIR = 5 };
size_t size() const { return _read(_size); }
file_size size() const { return _read(_size); }
unsigned uid() const { return _read(_uid); }
unsigned gid() const { return _read(_gid); }
unsigned mode() const { return _read(_mode); }
@ -186,9 +186,9 @@ class Vfs::Tar_file_system : public File_system
}
size_t num_dirent()
file_size num_dirent()
{
size_t count = 0;
file_size count = 0;
for (Node *child_node = first(); child_node; child_node = child_node->next(), count++) ;
return count;
}
@ -261,7 +261,7 @@ class Vfs::Tar_file_system : public File_system
* and use the location in the record as name
* pointer to save some memory
*/
size_t name_size = strlen(path_element) + 1;
Genode::size_t name_size = strlen(path_element) + 1;
char *name = (char*)env()->heap()->alloc(name_size);
strncpy(name, path_element, name_size);
child_node = new (env()->heap()) Node(name, record);
@ -271,7 +271,7 @@ class Vfs::Tar_file_system : public File_system
PDBG("creating node without record for %s", path_element);
/* create a directory node without record */
size_t name_size = strlen(path_element) + 1;
Genode::size_t name_size = strlen(path_element) + 1;
char *name = (char*)env()->heap()->alloc(name_size);
strncpy(name, path_element, name_size);
child_node = new (env()->heap()) Node(name, 0);
@ -299,13 +299,13 @@ class Vfs::Tar_file_system : public File_system
tar_record_action(record);
size_t file_size = record->size();
file_size size = record->size();
/* some datablocks */ /* one metablock */
block_id = block_id + (file_size / Record::BLOCK_LEN) + 1;
block_id = block_id + (size / Record::BLOCK_LEN) + 1;
/* round up */
if (file_size % Record::BLOCK_LEN != 0) block_id++;
if (size % Record::BLOCK_LEN != 0) block_id++;
/* check for end of tar archive */
if (block_id*Record::BLOCK_LEN >= _tar_size)
@ -325,12 +325,12 @@ class Vfs::Tar_file_system : public File_system
Node &root_node;
bool valid; /* true after first lookup */
char key[256]; /* key used for lookup */
size_t cached_num_dirent; /* cached value */
file_size cached_num_dirent; /* cached value */
Num_dirent_cache(Node &root_node)
: root_node(root_node), valid(false), cached_num_dirent(0) { }
size_t num_dirent(char const *path)
file_size num_dirent(char const *path)
{
Lock::Guard guard(lock);
@ -358,7 +358,7 @@ class Vfs::Tar_file_system : public File_system
_root_node("", 0),
_cached_num_dirent(_root_node)
{
PINF("tar archive '%s' local at %p, size is %zd",
PINF("tar archive '%s' local at %p, size is %llu",
_rom_name.name, _tar_base, _tar_size);
_for_each_tar_record_do(Add_node_action(_root_node));
@ -479,7 +479,7 @@ class Vfs::Tar_file_system : public File_system
return STAT_OK;
}
Dirent_result dirent(char const *path, off_t index, Dirent &out) override
Dirent_result dirent(char const *path, file_offset index, Dirent &out) override
{
Node *node = _root_node.lookup(path);
@ -516,8 +516,8 @@ class Vfs::Tar_file_system : public File_system
Unlink_result unlink(char const *) override { return UNLINK_ERR_NO_PERM; }
Readlink_result readlink(char const *path, char *buf, size_t buf_size,
size_t &out_len) override
Readlink_result readlink(char const *path, char *buf, file_size buf_size,
file_size &out_len) override
{
Node *node = _root_node.lookup(path);
Record const *record = node ? node->record : 0;
@ -525,7 +525,7 @@ class Vfs::Tar_file_system : public File_system
if (!record || (record->type() != Record::TYPE_SYMLINK))
return READLINK_ERR_NO_ENTRY;
size_t const count = min(buf_size, (size_t)100);
file_size const count = min(buf_size, 100ULL);
memcpy(buf, record->linked_name(), count);
@ -549,7 +549,7 @@ class Vfs::Tar_file_system : public File_system
return SYMLINK_ERR_NO_ENTRY;
}
size_t num_dirent(char const *path) override
file_size num_dirent(char const *path) override
{
return _cached_num_dirent.num_dirent(path);
}
@ -602,21 +602,22 @@ class Vfs::Tar_file_system : public File_system
** File I/O service interface **
********************************/
Write_result write(Vfs_handle *, char const *, size_t, size_t &) override
Write_result write(Vfs_handle *, char const *, file_size,
file_size &) override
{
PDBG("called\n");
return WRITE_ERR_INVALID;
}
Read_result read(Vfs_handle *vfs_handle, char *dst, size_t count,
size_t &out_count) override
Read_result read(Vfs_handle *vfs_handle, char *dst, file_size count,
file_size &out_count) override
{
Tar_vfs_handle const *handle = static_cast<Tar_vfs_handle *>(vfs_handle);
size_t const record_size = handle->record()->size();
file_size const record_size = handle->record()->size();
size_t const record_bytes_left = record_size >= handle->seek()
? record_size - handle->seek() : 0;
file_size const record_bytes_left = record_size >= handle->seek()
? record_size - handle->seek() : 0;
count = min(record_bytes_left, count);
@ -628,7 +629,7 @@ class Vfs::Tar_file_system : public File_system
return READ_OK;
}
Ftruncate_result ftruncate(Vfs_handle *handle, size_t) override
Ftruncate_result ftruncate(Vfs_handle *handle, file_size) override
{
PDBG("called\n");
return FTRUNCATE_ERR_NO_PERM;

View File

@ -72,19 +72,21 @@ class Vfs::Terminal_file_system : public Single_file_system
** File I/O service interface **
********************************/
Write_result write(Vfs_handle *, char const *buf, size_t buf_size, size_t &out_count) override
Write_result write(Vfs_handle *, char const *buf, file_size buf_size,
file_size &out_count) override
{
out_count = _terminal.write(buf, buf_size);
return WRITE_OK;
}
Read_result read(Vfs_handle *, char *dst, size_t count, size_t &out_count) override
Read_result read(Vfs_handle *, char *dst, file_size count,
file_size &out_count) override
{
out_count = _terminal.read(dst, count);
return READ_OK;
}
Ftruncate_result ftruncate(Vfs_handle *vfs_handle, size_t) override
Ftruncate_result ftruncate(Vfs_handle *vfs_handle, file_size) override
{
return FTRUNCATE_OK;
}

View File

@ -38,10 +38,10 @@ namespace Vfs {
using Genode::strncpy;
using Genode::strcmp;
using Genode::strlen;
using Genode::off_t;
typedef long long file_offset;
using Genode::memcpy;
using Genode::memset;
using Genode::size_t;
typedef unsigned long long file_size;
using Genode::Lock;
using Genode::List;
using Genode::Xml_node;

View File

@ -27,7 +27,7 @@ class Vfs::Vfs_handle
Directory_service &_ds;
File_io_service &_fs;
int _status_flags;
size_t _seek;
file_size _seek;
public:
@ -48,17 +48,17 @@ class Vfs::Vfs_handle
/**
* Return seek offset in bytes
*/
size_t seek() const { return _seek; }
file_size seek() const { return _seek; }
/**
* Set seek offset in bytes
*/
void seek(off_t seek) { _seek = seek; }
void seek(file_offset seek) { _seek = seek; }
/**
* Advance seek offset by 'incr' bytes
*/
void advance_seek(size_t incr) { _seek += incr; }
void advance_seek(file_size incr) { _seek += incr; }
};
#endif /* _INCLUDE__VFS__VFS_HANDLE_H_ */

View File

@ -34,14 +34,16 @@ struct Vfs::Zero_file_system : Single_file_system
** File I/O service interface **
********************************/
Write_result write(Vfs_handle *, char const *, size_t count, size_t &count_out) override
Write_result write(Vfs_handle *, char const *, file_size count,
file_size &count_out) override
{
count_out = count;
return WRITE_OK;
}
Read_result read(Vfs_handle *vfs_handle, char *dst, size_t count, size_t &out_count) override
Read_result read(Vfs_handle *vfs_handle, char *dst, file_size count,
file_size &out_count) override
{
memset(dst, 0, count);
out_count = count;

View File

@ -689,15 +689,20 @@ bool Noux::Child::syscall(Noux::Session::Syscall sc)
break;
case SYSCALL_READLINK:
{
Vfs::file_size out_count = 0;
_sysio->error.readlink = root_dir()->readlink(_sysio->readlink_in.path,
_sysio->readlink_out.chunk,
min(_sysio->readlink_in.bufsiz,
sizeof(_sysio->readlink_out.chunk)),
_sysio->readlink_out.count);
out_count);
_sysio->readlink_out.count = out_count;
result = (_sysio->error.readlink == Vfs::Directory_service::READLINK_OK);
break;
}
case SYSCALL_RENAME:

View File

@ -177,7 +177,7 @@ namespace Noux {
num = 2000;
}
void buf(void *buf_, size_t len)
void buf(void *buf_, unsigned long long len)
{
size_t chunk;
uint8_t *buf = (uint8_t *)buf_;
@ -222,7 +222,7 @@ namespace Noux {
memset(S, 0, 256);
}
void get(void *_buf, size_t len)
void get(void *_buf, unsigned long long len)
{
buf(_buf, len);
}
@ -250,15 +250,18 @@ namespace Noux {
** File I/O service interface **
********************************/
Write_result write(Vfs::Vfs_handle *, char const *, size_t buf_size, size_t &out_count) override
Write_result write(Vfs::Vfs_handle *, char const *,
Vfs::file_size buf_size,
Vfs::file_size &out_count) override
{
out_count = buf_size;
return WRITE_OK;
}
Read_result read(Vfs::Vfs_handle *vfs_handle, char *dst, size_t count,
size_t &out_count) override
Read_result read(Vfs::Vfs_handle *vfs_handle, char *dst,
Vfs::file_size count,
Vfs::file_size &out_count) override
{
_arc4random.get(dst, count);
out_count = count;
@ -266,7 +269,8 @@ namespace Noux {
return READ_OK;
}
Ftruncate_result ftruncate(Vfs::Vfs_handle *, size_t) override
Ftruncate_result ftruncate(Vfs::Vfs_handle *,
Vfs::file_size) override
{
return FTRUNCATE_OK;
}

View File

@ -49,16 +49,23 @@ namespace Noux {
** File I/O service interface **
********************************/
Write_result write(Vfs::Vfs_handle *, char const *buf, size_t buf_size,
size_t &out_count) override
Write_result write(Vfs::Vfs_handle *, char const *buf,
Vfs::file_size buf_size,
Vfs::file_size &out_count) override
{
buf_size = buf_size > 0xFFFFFFFFULL ? ~0UL : buf_size;
out_count = _terminal->write(buf, buf_size);
return WRITE_OK;
}
Read_result read(Vfs::Vfs_handle *, char *dst, size_t count, size_t &out_count) override
Read_result read(Vfs::Vfs_handle *, char *dst,
Vfs::file_size count,
Vfs::file_size &out_count) override
{
count = count > 0xFFFFFFFFULL ? ~0UL : count;
out_count = _terminal->read(dst, count);
if (_echo)
@ -67,7 +74,8 @@ namespace Noux {
return READ_OK;
}
Ftruncate_result ftruncate(Vfs::Vfs_handle *, size_t) override
Ftruncate_result ftruncate(Vfs::Vfs_handle *,
Vfs::file_size) override
{
return FTRUNCATE_OK;
}

View File

@ -46,12 +46,12 @@ namespace Noux {
bool write(Sysio *sysio, size_t &offset) override
{
size_t out_count = 0;
Vfs::file_size out_count = 0;
sysio->error.write = _fh->fs().write(_fh, sysio->write_in.chunk,
sysio->write_in.count, out_count);
if (sysio->error.write != Vfs::File_io_service::WRITE_OK)
return false;
if (sysio->error.write != Vfs::File_io_service::WRITE_OK)
return false;
_fh->advance_seek(out_count);
@ -65,7 +65,7 @@ namespace Noux {
{
size_t count = min(sysio->read_in.count, sizeof(sysio->read_out.chunk));
size_t out_count = 0;
Vfs::file_size out_count = 0;
sysio->error.read = _fh->fs().read(_fh, sysio->read_out.chunk, count, out_count);