summaryrefslogtreecommitdiff
path: root/stand
diff options
context:
space:
mode:
authorSimon J. Gerraty <sjg@FreeBSD.org>2020-04-07 16:56:34 +0000
committerSimon J. Gerraty <sjg@FreeBSD.org>2020-04-07 16:56:34 +0000
commit723f9041769c9b7310bd16d4a9a2d8e8eeca350f (patch)
tree2bd06c140c5113a0af7f2e20ba7c1bb75d6fb4ab /stand
parentb30c6ac9f9222ee574d54075e73581f8d141033f (diff)
downloadsrc-test2-723f9041769c9b7310bd16d4a9a2d8e8eeca350f.tar.gz
src-test2-723f9041769c9b7310bd16d4a9a2d8e8eeca350f.zip
Notes
Diffstat (limited to 'stand')
-rw-r--r--stand/libsa/pkgfs.c47
-rw-r--r--stand/libsa/tftp.c11
2 files changed, 39 insertions, 19 deletions
diff --git a/stand/libsa/pkgfs.c b/stand/libsa/pkgfs.c
index df87a7035153..d4794963b2c1 100644
--- a/stand/libsa/pkgfs.c
+++ b/stand/libsa/pkgfs.c
@@ -60,7 +60,7 @@ struct fs_ops pkgfs_fsops = {
};
#define PKG_BUFSIZE 512
-#define PKG_MAXCACHESZ 16384
+#define PKG_MAXCACHESZ (16384 * 3)
#define PKG_FILEEXT ".tgz"
@@ -132,6 +132,7 @@ struct package
static struct package *package = NULL;
static int new_package(int, struct package **);
+static int cache_data(struct tarfile *tf, int);
void
pkgfs_cleanup(void)
@@ -282,6 +283,9 @@ pkg_read(struct open_file *f, void *buf, size_t size, size_t *res)
return (EBADF);
}
+ if (tf->tf_cachesz == 0)
+ cache_data(tf, 1);
+
fp = tf->tf_fp;
p = buf;
sz = 0;
@@ -311,16 +315,6 @@ pkg_read(struct open_file *f, void *buf, size_t size, size_t *res)
fp += sz;
p += sz;
size -= sz;
-
- if (tf->tf_cachesz != 0)
- continue;
-
- tf->tf_cachesz = (sz <= PKG_MAXCACHESZ) ? sz : PKG_MAXCACHESZ;
- tf->tf_cache = malloc(tf->tf_cachesz);
- if (tf->tf_cache != NULL)
- memcpy(tf->tf_cache, buf, tf->tf_cachesz);
- else
- tf->tf_cachesz = 0;
}
tf->tf_fp = fp;
@@ -484,8 +478,20 @@ get_zipped(struct package *pkg, void *buf, size_t bufsz)
return (0);
}
+/**
+ * @brief
+ * cache data of a tarfile
+ *
+ * @param[in] tf
+ * tarfile pointer
+ *
+ * @param[in] force
+ * If file size > PKG_MAXCACHESZ, cache that much
+ *
+ * @return 0, -1 (errno set to error value)
+ */
static int
-cache_data(struct tarfile *tf)
+cache_data(struct tarfile *tf, int force)
{
struct package *pkg;
size_t sz;
@@ -503,21 +509,28 @@ cache_data(struct tarfile *tf)
return (-1);
}
+ if (tf->tf_cachesz > 0) {
+ DBG(("%s: data already cached\n", __func__));
+ errno = EINVAL;
+ return (-1);
+ }
+
if (tf->tf_ofs != pkg->pkg_ofs) {
- DBG(("%s: caching after partial read of file %s?\n",
+ DBG(("%s: caching after force read of file %s?\n",
__func__, tf->tf_hdr.ut_name));
errno = EINVAL;
return (-1);
}
/* We don't cache everything... */
- if (tf->tf_size > PKG_MAXCACHESZ) {
- errno = ENOMEM;
+ if (tf->tf_size > PKG_MAXCACHESZ && !force) {
+ errno = ENOBUFS;
return (-1);
}
+ sz = tf->tf_size < PKG_MAXCACHESZ ? tf->tf_size : PKG_MAXCACHESZ;
/* All files are padded to a multiple of 512 bytes. */
- sz = (tf->tf_size + 0x1ff) & ~0x1ff;
+ sz = (sz + 0x1ff) & ~0x1ff;
tf->tf_cache = malloc(sz);
if (tf->tf_cache == NULL) {
@@ -741,7 +754,7 @@ scan_tarfile(struct package *pkg, struct tarfile *last)
if (ofs != pkg->pkg_ofs) {
if (last != NULL && pkg->pkg_ofs == last->tf_ofs) {
- if (cache_data(last) == -1)
+ if (cache_data(last, 0) == -1)
return (NULL);
} else {
sz = ofs - pkg->pkg_ofs;
diff --git a/stand/libsa/tftp.c b/stand/libsa/tftp.c
index 5d5a3000b2af..3892f2aad86a 100644
--- a/stand/libsa/tftp.c
+++ b/stand/libsa/tftp.c
@@ -100,11 +100,13 @@ static int is_open = 0;
* Jumbo frames in the future.
*/
#define TFTP_MAX_BLKSIZE 9008
+#define TFTP_TRIES 2
struct tftp_handle {
struct iodesc *iodesc;
int currblock; /* contents of lastdata */
- int islastblock; /* flag */
+ int islastblock:1; /* flag */
+ int tries:4; /* number of read attempts */
int validsize;
int off;
char *path; /* saved for re-requests */
@@ -530,7 +532,12 @@ tftp_read(struct open_file *f, void *addr, size_t size,
#ifdef TFTP_DEBUG
printf("tftp: read error\n");
#endif
- return (rc);
+ if (tftpfile->tries > TFTP_TRIES) {
+ return (rc);
+ } else {
+ tftpfile->tries++;
+ tftp_makereq(tftpfile);
+ }
}
if (tftpfile->islastblock)
break;