diff options
-rw-r--r-- | fs/fs.c | 18 | ||||
-rw-r--r-- | fs/tftp.c | 5 | ||||
-rw-r--r-- | include/fs.h | 2 |
3 files changed, 24 insertions, 1 deletions
@@ -38,10 +38,21 @@ void *read_file(const char *filename, size_t *size) int fd; struct stat s; void *buf = NULL; + const char *tmpfile = "/.read_file_tmp"; + int ret; +again: if (stat(filename, &s)) return NULL; + if (s.st_size == FILESIZE_MAX) { + ret = copy_file(filename, tmpfile, 0); + if (ret) + return NULL; + filename = tmpfile; + goto again; + } + buf = xzalloc(s.st_size + 1); fd = open(filename, O_RDONLY); @@ -56,12 +67,19 @@ void *read_file(const char *filename, size_t *size) if (size) *size = s.st_size; + if (filename == tmpfile) + unlink(tmpfile); + return buf; err_out1: close(fd); err_out: free(buf); + + if (filename == tmpfile) + unlink(tmpfile); + return NULL; } @@ -598,7 +598,10 @@ static int tftp_stat(struct device_d *dev, const char *filename, struct stat *s) return PTR_ERR(priv); s->st_mode = S_IFREG | S_IRWXU | S_IRWXG | S_IRWXO; - s->st_size = priv->filesize; + if (priv->filesize) + s->st_size = priv->filesize; + else + s->st_size = FILESIZE_MAX; tftp_do_close(priv); diff --git a/include/fs.h b/include/fs.h index 7c4e46175a..22c07467da 100644 --- a/include/fs.h +++ b/include/fs.h @@ -149,6 +149,8 @@ int protect(int fd, size_t count, unsigned long offset, int prot); int protect_file(const char *file, int prot); void *memmap(int fd, int flags); +#define FILESIZE_MAX ((loff_t)-1) + #define PROT_READ 1 #define PROT_WRITE 2 |