diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2018-06-11 22:36:28 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2018-06-11 22:36:28 +0200 |
commit | 8985573ad66c9fb011910a352b8c1427ee08ded3 (patch) | |
tree | 86eaba30b6363eeaba0d196f4e88d85958dc0e40 /lib | |
parent | 57c475b48dcf8e41ddaaa77686ea41adb9049dc5 (diff) | |
parent | ec4dca17bb6a0029466de80754a20fec13d0e111 (diff) | |
download | barebox-8985573ad66c9fb011910a352b8c1427ee08ded3.tar.gz barebox-8985573ad66c9fb011910a352b8c1427ee08ded3.tar.xz |
Merge branch 'for-next/mvebu'
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libfile.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/libfile.c b/lib/libfile.c index b7db22d694..d22519b8f4 100644 --- a/lib/libfile.c +++ b/lib/libfile.c @@ -251,6 +251,39 @@ int write_file(const char *filename, const void *buf, size_t size) EXPORT_SYMBOL(write_file); /** + * write_file_flash - write a buffer to a file backed by flash + * @filename: The filename to write + * @size: The size of the buffer + * + * Functional this is identical to write_file but calls erase() before writing. + * + * Return: 0 for success or negative error value + */ +int write_file_flash(const char *filename, const void *buf, size_t size) +{ + int fd, ret; + + fd = open(filename, O_WRONLY); + if (fd < 0) + return fd; + + ret = erase(fd, size, 0); + if (ret < 0) + goto out_close; + + ret = write_full(fd, buf, size); + +out_close: + close(fd); + + if (ret < 0) + return ret; + + return 0; +} +EXPORT_SYMBOL(write_file_flash); + +/** * copy_file - Copy a file * @src: The source filename * @dst: The destination filename |