From a8f3ac42461547cc9fc60e0f4dd8b7d778f6da9e Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Thu, 12 Jul 2018 15:07:45 +0100 Subject: [PATCH] kernel: final pieces needed (I think...) for external buffer support --- Kernel/devio.c | 32 ++++++++++++++++++-------------- Kernel/include/kernel.h | 5 +++-- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/Kernel/devio.c b/Kernel/devio.c index 8052a4d3..3ed6b31e 100644 --- a/Kernel/devio.c +++ b/Kernel/devio.c @@ -151,35 +151,39 @@ int bfree(regptr bufptr bp, uint8_t dirty) } /* - * Allocate a buffer for scratch use by the kernel. This buffer can then - * be freed with tmpfree. - * - * API note: Nothing guarantees a connection between a bufcache entry - * and tmpbuf in future. Always free with tmpfree. + * Allocate an empty _disk cache_ buffer. We use this when dealing with file + * holes. It would be nice if this API could go way and readi just use uzero() */ -void *tmpbuf(void) +bufptr zerobuf(void) { regptr bufptr bp; bp = freebuf(); bp->bf_dev = NO_DEVICE; bp->bf_time = ++bufclock; /* Time stamp it */ - return bp->__bf_data; + blkzero(bp); + return bp; } +#ifndef CONFIG_BLKBUF_EXTERNAL /* - * Allocate an empty _disk cache_ buffer. We use this when dealing with file - * holes. It would be nice if this API could go way and readi just use uzero() + * Allocate a buffer for scratch use by the kernel. This buffer can then + * be freed with tmpfree. * - * This won't be able to use tmpbuf if we split disk and temporary buffers. + * API note: Nothing guarantees a connection between a bufcache entry + * and tmpbuf in future. Always free with tmpfree. */ -void *zerobuf(void) + +void *tmpbuf(void) { - void *b = tmpbuf(); - memset(b, 0, 512); + regptr bufptr bp; - return b; + bp = freebuf(); + bp->bf_dev = NO_DEVICE; + bp->bf_time = ++bufclock; /* Time stamp it */ + return bp->__bf_data; } +#endif /* * Write back a buffer doing the locking outselves. This is called when diff --git a/Kernel/include/kernel.h b/Kernel/include/kernel.h index 505cfe14..5b9611ec 100644 --- a/Kernel/include/kernel.h +++ b/Kernel/include/kernel.h @@ -211,6 +211,7 @@ typedef struct blkbuf { uget((uaddr),(buf)->__bf_data + (off), (len)) #define blkptr(buf, off, len) ((void *)((buf)->__bf_data + (off))) #define blkzero(buf) memset(buf->__bf_data, 0, BLKSIZE) +#define tmpfree(x) brelse((void *)x) #else extern void blktok(void *kaddr, struct blkbuf *buf, uint16_t off, uint16_t len); extern void blkfromk(void *kaddr, struct blkbuf *buf, uint16_t off, uint16_t len); @@ -219,6 +220,7 @@ extern void blkfromu(void *kaddr, struct blkbuf *buf, uint16_t off, uint16_t len /* Worst case is needing to copy over about 64 bytes */ extern void *blkptr(struct blkbuf *buf, uint16_t offset, uint16_t len); extern void blkzero(struct blkbuf *buf); +extern void tmpfree(void *p); #endif /* TODO: consider smaller inodes or clever caching. 2BSD uses small @@ -855,12 +857,11 @@ extern void brelse(bufptr); extern void bawrite(bufptr); extern int bfree(bufptr bp, uint8_t dirty); /* dirty: 0=clean, 1=dirty (write back), 2=dirty+immediate write */ extern void *tmpbuf(void); -extern void *zerobuf(void); +extern bufptr zerobuf(void); extern void bufsync(void); extern bufptr bfind(uint16_t dev, blkno_t blk); extern void bdrop(uint16_t dev); extern bufptr freebuf(void); -#define tmpfree(x) brelse((void *)x) extern void bufinit(void); extern void bufdiscard(bufptr bp); extern void bufdump (void); -- 2.34.1