diff options
author | Ramesh Thomas <ramesh.thomas@intel.com> | 2016-08-26 17:56:07 -0700 |
---|---|---|
committer | Anas Nashif <nashif@linux.intel.com> | 2016-09-23 00:06:31 +0000 |
commit | 211db5352d3ae14d91e9de780612ff828fda7965 (patch) | |
tree | 6e8d9153bd13d887dd423813927560b7fca181c2 /include/fs.h | |
parent | 986596bb91786365eba6f5db95418c7135326963 (diff) |
fs: Adds file system API to grow or shrink a file
Adds fs_truncate() function which can be used to change the size
of a file. The name is counter intuitive but that is how the POSIX
version is named. It shrinks as well as grows a file.
Jira: ZEP-635 ZEP-622
Change-Id: If7b8cad17e1b80479a529c60a32c12fb134cd456
Signed-off-by: Ramesh Thomas <ramesh.thomas@intel.com>
Diffstat (limited to 'include/fs.h')
-rw-r--r-- | include/fs.h | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/include/fs.h b/include/fs.h index 4cd8ba34c..d321227e5 100644 --- a/include/fs.h +++ b/include/fs.h @@ -196,6 +196,26 @@ int fs_seek(ZFILE *zfp, off_t offset, int whence); off_t fs_tell(ZFILE *zfp); /** + * @brief Change the size of an open file + * + * Truncates the file to the new length if it is shorter than the current + * size of the file. Expands the file if the new length is greater than the + * current size of the file. The expanded region would be filled with zeroes. + * + * @note In the case of expansion, if the volume got full during the + * expansion process, the function will expand to the maximum possible length + * and returns success. Caller should check if the expanded size matches the + * requested length. + * + * @param zfp Pointer to the file object + * @param length New size of the file in bytes + * + * @retval 0 Success + * @retval -ERRNO errno code if error + */ +int fs_truncate(ZFILE *zfp, off_t length); + +/** * @brief Directory create * * Creates a new directory using specified path. |