From: Stefan Lengfeld <contact@stefanchrist.eu>
To: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Barebox List <barebox@lists.infradead.org>
Subject: Re: [PATCH 4/7] libfile: implement a function to cache a file
Date: Wed, 24 Jan 2018 20:23:51 +0100 [thread overview]
Message-ID: <20180124192351.GB521@porty> (raw)
In-Reply-To: <20180124074534.7966-5-s.hauer@pengutronix.de>
Hi Sascha,
On Wed, Jan 24, 2018 at 08:45:31AM +0100, Sascha Hauer wrote:
> Due to the nature of TFTP which can't lseek and due to the silliness
> of our filesystem implementation which can't cache accesses we have to
> manually cache files on TFTP filesystems sometimes. Make it easier
> for them by providing a cache_file() function which copies the file
> from TFTP to RAM.
>
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> ---
> include/libfile.h | 2 ++
> lib/libfile.c | 27 +++++++++++++++++++++++++++
> 2 files changed, 29 insertions(+)
>
> diff --git a/include/libfile.h b/include/libfile.h
> index 6dbb81a241..beec7cff79 100644
> --- a/include/libfile.h
> +++ b/include/libfile.h
> @@ -28,4 +28,6 @@ int unlink_recursive(const char *path, char **failedpath);
>
> char *make_temp(const char *template);
>
> +int cache_file(const char *path, char **newpath);
> +
> #endif /* __LIBFILE_H */
> diff --git a/lib/libfile.c b/lib/libfile.c
> index 79054eb5ac..738ff1287d 100644
> --- a/lib/libfile.c
> +++ b/lib/libfile.c
> @@ -512,3 +512,30 @@ char *make_temp(const char *template)
>
> return name;
> }
> +
> +/**
> + * cache_file - Cache a file in /tmp
> + * @path: The file to cache
> + * @newpath: The return path where the file is copied to
> + *
> + * This function copies a given file to /tmp and returns its name in @newpath.
Maybe add an additional note here that the caller is responsible for
freeing the string returned in @newpath when the function exists
successfully. The string is allocated by the make_temp() function.
> + *
> + * Return: 0 for success, negative error code otherwise.
> + */
> +int cache_file(const char *path, char **newpath)
> +{
> + char *npath;
> + int ret;
> +
> + npath = make_temp("filecache-");
No dash suffix needed in "filecache-". The make_temp() function already
adds a dash separator.
Kind regards,
Stefan
> +
> + ret = copy_file(path, npath, 0);
> + if (ret) {
> + free(npath);
> + return ret;
> + }
> +
> + *newpath = npath;
> +
> + return 0;
> +}
> --
> 2.11.0
>
>
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
>
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2018-01-24 19:24 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-24 7:45 [PATCH 0/7] Make TFTP detection more convenient Sascha Hauer
2018-01-24 7:45 ` [PATCH 1/7] startup: create /tmp Sascha Hauer
2018-01-24 7:45 ` [PATCH 2/7] fs: implement is_tftp_fs() Sascha Hauer
2018-01-24 19:12 ` Stefan Lengfeld
2018-01-25 7:46 ` Sascha Hauer
2018-01-24 7:45 ` [PATCH 3/7] libfile: implement make_temp Sascha Hauer
2018-01-24 7:45 ` [PATCH 4/7] libfile: implement a function to cache a file Sascha Hauer
2018-01-24 19:23 ` Stefan Lengfeld [this message]
2018-01-24 7:45 ` [PATCH 5/7] uimage: Use is_tftp_fs() and cache_file() to ease TFTP workaround Sascha Hauer
2018-01-24 19:39 ` Stefan Lengfeld
2018-01-24 7:45 ` [PATCH 6/7] fs/uimagefs: " Sascha Hauer
2018-01-24 19:56 ` Stefan Lengfeld
2018-01-24 7:45 ` [PATCH 7/7] fs: remove now unused function can_lseek_backward() Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180124192351.GB521@porty \
--to=contact@stefanchrist.eu \
--cc=barebox@lists.infradead.org \
--cc=s.hauer@pengutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox