Module Name: src
Committed By: jmcneill
Date: Sat Jun 27 17:22:12 UTC 2020
Modified Files:
src/sys/lib/libsa: bootcfg.c
Log Message:
Support loading boot.cfg from non file-system based devices.
To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/lib/libsa/bootcfg.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/lib/libsa/bootcfg.c
diff -u src/sys/lib/libsa/bootcfg.c:1.4 src/sys/lib/libsa/bootcfg.c:1.5
--- src/sys/lib/libsa/bootcfg.c:1.4 Sun Mar 31 20:08:45 2019
+++ src/sys/lib/libsa/bootcfg.c Sat Jun 27 17:22:12 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: bootcfg.c,v 1.4 2019/03/31 20:08:45 christos Exp $ */
+/* $NetBSD: bootcfg.c,v 1.5 2020/06/27 17:22:12 jmcneill Exp $ */
/*-
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -99,7 +99,7 @@ perform_bootcfg(const char *conf, bootcf
{
char *bc, *c;
int cmenu, cbanner;
- ssize_t len, off;
+ ssize_t len, off, resid;
int fd, err;
struct stat st;
char *next, *key, *value, *v2;
@@ -119,8 +119,8 @@ perform_bootcfg(const char *conf, bootcf
err = fstat(fd, &st);
if (err == -1) {
- close(fd);
- return EIO;
+ /* file descriptor may not be backed by a libsa file-system */
+ st.st_size = maxsz;
}
/* if a maximum size is being requested for the boot.cfg enforce it. */
@@ -146,12 +146,14 @@ perform_bootcfg(const char *conf, bootcf
* the storage anyway.
*/
off = 0;
+ resid = st.st_size;
do {
- len = read(fd, bc + off, 1024);
+ len = read(fd, bc + off, uimin(1024, resid));
if (len <= 0)
break;
off += len;
- } while (len > 0);
+ resid -= len;
+ } while (len > 0 && resid > 0);
bc[off] = '\0';
close(fd);