diff options
author | Simon Glass <sjg@chromium.org> | 2013-04-20 08:42:51 +0000 |
---|---|---|
committer | Tom Rini <trini@ti.com> | 2013-05-01 11:17:21 -0400 |
commit | 7eb2c8d573ad932bf67095f11c6b3beba41064f2 (patch) | |
tree | e4f2e0f533ea14d758c09de28c143bbe60c70dbc /fs/sandbox | |
parent | a8f6ab5229fb4cd8299df84c8698e128b5125a8e (diff) | |
download | u-boot-midas-7eb2c8d573ad932bf67095f11c6b3beba41064f2.tar.gz u-boot-midas-7eb2c8d573ad932bf67095f11c6b3beba41064f2.tar.bz2 u-boot-midas-7eb2c8d573ad932bf67095f11c6b3beba41064f2.zip |
sandbox: fs: Add support for saving files to host filesystem
This allows write of files from the host filesystem in sandbox. There is
currently no concept of overwriting the file and removing its existing
contents - all writing is done on top of what is there. This means that
writing 10 bytes to the start of a 1KB file will only update those 10
bytes, not truncate the file to 10 byte slong.
If the file does not exist it is created.
Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'fs/sandbox')
-rw-r--r-- | fs/sandbox/sandboxfs.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/fs/sandbox/sandboxfs.c b/fs/sandbox/sandboxfs.c index 02d26ff851..89769e8ce6 100644 --- a/fs/sandbox/sandboxfs.c +++ b/fs/sandbox/sandboxfs.c @@ -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; +} |