]> git.sur5r.net Git - u-boot/blobdiff - fs/sandbox/sandboxfs.c
sandbox: fs: Add support for saving files to host filesystem
[u-boot] / fs / sandbox / sandboxfs.c
index 02d26ff851eeecaf8c9b250155cec855f2a3bee6..89769e8ce680cf5bac206c2dff83e131a6120577 100644 (file)
@@ -48,6 +48,26 @@ long sandbox_fs_read_at(const char *filename, unsigned long pos,
        return size;
 }
 
+long sandbox_fs_write_at(const char *filename, unsigned long pos,
+                        void *buffer, unsigned long towrite)
+{
+       ssize_t size;
+       int fd, ret;
+
+       fd = os_open(filename, OS_O_RDWR | OS_O_CREAT);
+       if (fd < 0)
+               return fd;
+       ret = os_lseek(fd, pos, OS_SEEK_SET);
+       if (ret == -1) {
+               os_close(fd);
+               return ret;
+       }
+       size = os_write(fd, buffer, towrite);
+       os_close(fd);
+
+       return size;
+}
+
 int sandbox_fs_ls(const char *dirname)
 {
        struct os_dirent_node *head, *node;
@@ -81,3 +101,16 @@ int fs_read_sandbox(const char *filename, void *buf, int offset, int len)
 
        return len_read;
 }
+
+int fs_write_sandbox(const char *filename, void *buf, int offset, int len)
+{
+       int len_written;
+
+       len_written = sandbox_fs_write_at(filename, offset, buf, len);
+       if (len_written == -1) {
+               printf("** Unable to write file %s **\n", filename);
+               return -1;
+       }
+
+       return len_written;
+}