]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
semihosting: create file in smh_fs_write_at()
authorHeinrich Schuchardt <heinrich.schuchardt@canonical.com>
Fri, 12 May 2023 22:47:03 +0000 (00:47 +0200)
committerTom Rini <trini@konsulko.com>
Wed, 31 May 2023 21:23:01 +0000 (17:23 -0400)
If a file does not exist, it should be created.

Fixes: f676b45151c3 ("fs: Add semihosting filesystem")
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
fs/semihostingfs.c

index 96eb3349a2f84133bb03607703e1f5b417787fca..3592338a6865ec06d64a000b89207c53a7e71dfd 100644 (file)
@@ -57,7 +57,11 @@ static int smh_fs_write_at(const char *filename, loff_t pos, void *buffer,
 {
        long fd, size, ret;
 
+       /* Try to open existing file */
        fd = smh_open(filename, MODE_READ | MODE_BINARY | MODE_PLUS);
+       if (fd < 0)
+               /* Create new file */
+               fd = smh_open(filename, MODE_WRITE | MODE_BINARY);
        if (fd < 0)
                return fd;
        ret = smh_seek(fd, pos);