Removing zeroing of trailing space in attribute buffers

This was provided as a courtesy to hopefully make custom attributes more
easy to use, however the zeroing turned out to be a bit complicated when
syncing custom attributes across multiple open files.

Implicitly zeroing trailing buffer space is also inconsistent with the
other APIs in the filesystem, such as lfs_file_read, so this commit
removes the behavior.

If you need to handle differently sized custom attributes, you can
either pre-zero the custom attribute buffers, or use lfs_getattr to find
the on-disk size of custom attributes explicitly.
This commit is contained in:
Christopher Haster
2020-12-16 21:30:12 -06:00
parent b19a51c044
commit 026833214a
4 changed files with 40 additions and 56 deletions

14
lfs.h
View File

@@ -300,10 +300,9 @@ struct lfs_file_config {
// write occurs atomically with update to the file's contents.
//
// Custom attributes are uniquely identified by an 8-bit type and limited
// to LFS_ATTR_MAX bytes. When read, if the stored attribute is smaller
// than the buffer, it will be padded with zeros. If the stored attribute
// is larger, then it will be silently truncated. If the attribute is not
// found, it will be created implicitly.
// to LFS_ATTR_MAX bytes. If the stored attribute is larger than the
// provided buffer, it will be silently truncated. If no attribute is
// found, and the file is open for writing, it will be created implicitly.
struct lfs_attr *attrs;
// Number of custom attributes in the list
@@ -471,10 +470,9 @@ int lfs_stat(lfs_t *lfs, const char *path, struct lfs_info *info);
// Get a custom attribute
//
// Custom attributes are uniquely identified by an 8-bit type and limited
// to LFS_ATTR_MAX bytes. When read, if the stored attribute is smaller than
// the buffer, it will be padded with zeros. If the stored attribute is larger,
// then it will be silently truncated. If no attribute is found, the error
// LFS_ERR_NOATTR is returned and the buffer is filled with zeros.
// to LFS_ATTR_MAX bytes. If the stored attribute is larger than the
// provided buffer, it will be silently truncated. If no attribute is found,
// the error LFS_ERR_NOATTR is returned and the buffer is filled with zeros.
//
// Returns the size of the attribute, or a negative error code on failure.
// Note, the returned size is the size of the attribute on disk, irrespective