diff options
-rw-r--r-- | kexec/fs2dt.c | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/kexec/fs2dt.c b/kexec/fs2dt.c index 304f6cb..3b4432d 100644 --- a/kexec/fs2dt.c +++ b/kexec/fs2dt.c @@ -381,8 +381,8 @@ static void putprops(char *fn, struct dirent **nlist, int numlist) { struct dirent *dp; int i = 0, fd; - size_t len; - ssize_t slen; + off_t len; + off_t slen; struct stat statbuf; for (i = 0; i < numlist; i++) { @@ -443,23 +443,27 @@ static void putprops(char *fn, struct dirent **nlist, int numlist) *dt++ = cpu_to_be32(propnum(fn)); pad_structure_block(len); - fd = open(pathname, O_RDONLY); - if (fd == -1) - die("unrecoverable error: could not open \"%s\": %s\n", - pathname, strerror(errno)); + if (len) { + char *buf; - slen = read(fd, dt, len); - if (slen < 0) - die("unrecoverable error: could not read \"%s\": %s\n", - pathname, strerror(errno)); - if ((size_t)slen != len) - die("unrecoverable error: short read from\"%s\"\n", - pathname); + buf = slurp_file_len(pathname, len, &slen); + if (slen != len) + die("unrecoverable error: short read from\"%s\"\n", + pathname); + + memcpy(dt, buf, slen); + free(buf); + } checkprop(fn, dt, len); dt += (len + 3)/4; + fd = open(pathname, O_RDONLY); + if (fd == -1) + die("unrecoverable error: could not open \"%s\": %s\n", + pathname, strerror(errno)); + if (!strcmp(dp->d_name, "reg") && usablemem_rgns.size) add_usable_mem_property(fd, len); add_dyn_reconf_usable_mem_property(dp, fd); |