diff options
author | Simon Horman <horms@verge.net.au> | 2010-04-01 09:10:56 +1100 |
---|---|---|
committer | Simon Horman <horms@verge.net.au> | 2010-04-01 09:10:56 +1100 |
commit | d3ab86bd6d8b5203c8b6e079355d5a878db24494 (patch) | |
tree | 6d91fe9fe572489773fb795f7194c17799ade79a /kexec/kexec.c | |
parent | 2208c3067904b56855daa8da1e7d96dc7d351fc6 (diff) | |
parent | de5dd4d4036211b0a8e1839ce87984a074eb18f8 (diff) |
Merge branch 'ppc32' of git://git.breakpoint.cc/bigeasy/kexec-tools
Diffstat (limited to 'kexec/kexec.c')
-rw-r--r-- | kexec/kexec.c | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/kexec/kexec.c b/kexec/kexec.c index 16a0ec9..a9a0f3f 100644 --- a/kexec/kexec.c +++ b/kexec/kexec.c @@ -475,7 +475,7 @@ char *slurp_file(const char *filename, off_t *r_size) { int fd; char *buf; - off_t size, progress; + off_t size, progress, err; ssize_t result; struct stat stats; @@ -494,7 +494,26 @@ char *slurp_file(const char *filename, off_t *r_size) die("Cannot stat: %s: %s\n", filename, strerror(errno)); } - size = stats.st_size; + /* + * Seek in case the kernel is a character node like /dev/ubi0_0. + * This does not work on regular files which live in /proc and + * we need this for some /proc/device-tree entries + */ + if (S_ISCHR(stats.st_mode)) { + + size = lseek(fd, 0, SEEK_END); + if (size < 0) + die("Can not seek file %s: %s\n", filename, + strerror(errno)); + + err = lseek(fd, 0, SEEK_SET); + if (err < 0) + die("Can not seek to the begin of file %s: %s\n", + filename, strerror(errno)); + } else { + size = stats.st_size; + } + *r_size = size; buf = xmalloc(size); progress = 0; |