Hi Cedric, On 2026-10-26T16:37:26, Cedric Hombourger <[email protected]> wrote: > fs: add fs_overwrite() to write without trimming the file > > fs_write() with an offset trims the file at the end of the written > range. Add fs_overwrite() for callers that need to update a part of a > file and keep the rest. > > Add an optional overwrite() operation to struct fstype_info and set it > for FAT. A filesystem without it falls back to write(), so nothing > changes for them. fs_write() and fs_overwrite() share the same code. > > Signed-off-by: Cedric Hombourger <[email protected]> > > fs/fs.c | 25 ++++++++++++++++++++++--- > include/fs.h | 16 ++++++++++++++++ > 2 files changed, 38 insertions(+), 3 deletions(-)
> diff --git a/fs/fs.c b/fs/fs.c > @@ -709,15 +713,18 @@ int fs_read(const char *filename, ulong addr, loff_t > offset, loff_t len, > -int fs_write(const char *filename, ulong addr, loff_t offset, loff_t len, > - loff_t *actwrite) > +static int fs_write_with(bool keep_tail, const char *filename, ulong addr, > + loff_t offset, loff_t len, loff_t *actwrite) fs_read() just above uses _fs_read() with the extra argument at the end. Please can you do the same here, i.e. _fs_write() with keep_tail as the last argument? > diff --git a/include/fs.h b/include/fs.h > @@ -167,6 +167,22 @@ int fs_read(const char *filename, ulong addr, loff_t > offset, loff_t len, > +/** > + * fs_overwrite() - write into a file without cutting off its tail > + * > + * Like fs_write(), but data after the written range stays and the file > + * size only grows. Filesystem drivers without support fall back to > fs_write(). If you keep the fallback (see my reply to the cover letter), the caller cannot rely on the promise in the first sentence. exFAT still trims and ext4 only works at offset 0, so the guarantee really only holds for FAT. Please can you say in this comment which filesystems may still truncate. Please can you also add a C test that writes into the middle of a file on a FAT image and checks the size and the data after the written range. test/dm/host.c already calls fs_write(), so it would make a good starting point. Regards, Simon
