From 5bd7fc86c307756b0969cfeafa70c8aef41ad63b Mon Sep 17 00:00:00 2001 From: Frank Freihube Date: Fri, 29 Apr 2016 07:56:35 +0200 Subject: [PATCH] make changes configurable through io_semantics() --- core/cfs/cfs-coffee.c | 15 +++++++++++++-- core/cfs/cfs-coffee.h | 9 +++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/core/cfs/cfs-coffee.c b/core/cfs/cfs-coffee.c index 07df6121b..d4d988ae8 100644 --- a/core/cfs/cfs-coffee.c +++ b/core/cfs/cfs-coffee.c @@ -1098,9 +1098,20 @@ cfs_read(int fd, void *buf, unsigned size) fdp = &coffee_fd_set[fd]; file = fdp->file; - while(fdp->offset + size > file->end) { - ((char*)buf)[--size] = 0; + +#if COFFEE_IO_SEMANTICS + if(fdp->io_flags & CFS_COFFEE_IO_FIRM_SIZE) { + while(fdp->offset + size > file->end) { + ((char*)buf)[--size] = 0; + } + } else { +#endif + if(fdp->offset + size > file->end) { + size = file->end - fdp->offset; + } +#if COFFEE_IO_SEMANTICS } +#endif /* If the file is not modified, read directly from the file extent. */ if(!FILE_MODIFIED(file)) { diff --git a/core/cfs/cfs-coffee.h b/core/cfs/cfs-coffee.h index 2c62f2512..96d382980 100644 --- a/core/cfs/cfs-coffee.h +++ b/core/cfs/cfs-coffee.h @@ -63,6 +63,15 @@ */ #define CFS_COFFEE_IO_FIRM_SIZE 0x2 +/** + * Instruct Coffee to set unused bytes in the destination buffer to zero. + * Trailing zeros may cause a wrong file size, this option ensures that + * the corresponding bytes get set, so Coffee does not read unexpected data. + * + * \sa cfs_coffee_set_io_semantics() + */ +#define CFS_COFFEE_IO_ENSURE_READ_LENGTH 0x4 + /** * \file * Header for the Coffee file system.