Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F169443930
D39026.id118665.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
D39026.id118665.diff
View Options
diff --git a/usr.sbin/makefs/ffs.c b/usr.sbin/makefs/ffs.c
--- a/usr.sbin/makefs/ffs.c
+++ b/usr.sbin/makefs/ffs.c
@@ -94,6 +94,8 @@
#include <sys/statvfs.h>
#endif
+#include <sys/mman.h>
+
#include <ufs/ufs/dinode.h>
#include <ufs/ufs/dir.h>
#include <ufs/ffs/fs.h>
@@ -568,6 +570,13 @@
fs = ffs_mkfs(image, fsopts, tstamp);
fsopts->superblock = (void *)fs;
+#if 0
+ fsopts->mmap = mmap(0, fsopts->size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fsopts->fd, 0);
+ if (fsopts->mmap == MAP_FAILED) {
+ warn("mmap failed");
+ fsopts->mmap = 0;
+ }
+#endif
if (debug & DEBUG_FS_CREATE_IMAGE) {
time_t t;
diff --git a/usr.sbin/makefs/ffs/buf.c b/usr.sbin/makefs/ffs/buf.c
--- a/usr.sbin/makefs/ffs/buf.c
+++ b/usr.sbin/makefs/ffs/buf.c
@@ -75,6 +75,14 @@
printf("%s: blkno %lld offset %lld bcount %ld\n", __func__,
(long long)(*bpp)->b_blkno, (long long) offset,
(*bpp)->b_bcount);
+ if (fs->mmap) {
+ if (offset + (*bpp)->b_bcount > fs->size)
+ err(1, "%s: read %ld (%lld) past the end", __func__,
+ (*bpp)->b_bcount, (long long)offset);
+ /* getblk already set bp->b_data to point in mmap'd buffer */
+ return (0);
+ }
+ /* Fallback */
if (lseek((*bpp)->b_fs->fd, offset, SEEK_SET) == -1)
err(1, "%s: lseek %lld (%lld)", __func__,
(long long)(*bpp)->b_blkno, (long long)offset);
@@ -118,7 +126,8 @@
}
TAILQ_REMOVE(&buftail, bp, b_tailq);
- free(bp->b_data);
+ if (bp->b_fs->mmap == 0)
+ free(bp->b_data);
free(bp);
}
@@ -135,6 +144,14 @@
printf("bwrite: blkno %lld offset %lld bcount %ld\n",
(long long)bp->b_blkno, (long long) offset,
bp->b_bcount);
+ if (fs->mmap) {
+ if (offset + bp->b_bcount > fs->size)
+ err(1, "%s: write %ld (%lld) past the end", __func__,
+ bp->b_bcount, (long long)offset);
+ /* bp->b_data already points to the right place */
+ return (0);
+ }
+ /* Fallback */
if (lseek(bp->b_fs->fd, offset, SEEK_SET) == -1)
return (errno);
rv = write(bp->b_fs->fd, bp->b_data, bp->b_bcount);
@@ -206,9 +223,14 @@
}
bp->b_bcount = size;
if (bp->b_data == NULL || bp->b_bcount > bp->b_bufsize) {
- n = erealloc(bp->b_data, size);
- memset(n, 0, size);
- bp->b_data = n;
+ if (vp->fs->mmap) {
+ bp->b_data = vp->fs->mmap +
+ (off_t)bp->b_blkno * bp->b_fs->sectorsize + bp->b_fs->offset;
+ } else {
+ n = erealloc(bp->b_data, size);
+ memset(n, 0, size);
+ bp->b_data = n;
+ }
bp->b_bufsize = size;
}
diff --git a/usr.sbin/makefs/makefs.h b/usr.sbin/makefs/makefs.h
--- a/usr.sbin/makefs/makefs.h
+++ b/usr.sbin/makefs/makefs.h
@@ -148,6 +148,7 @@
int fd; /* file descriptor of image */
void *superblock; /* superblock */
int onlyspec; /* only add entries in specfile */
+ char *mmap; /* Address, if any, for mmap'd array */
/* global options */
diff --git a/usr.sbin/makefs/msdos.c b/usr.sbin/makefs/msdos.c
--- a/usr.sbin/makefs/msdos.c
+++ b/usr.sbin/makefs/msdos.c
@@ -55,6 +55,7 @@
#include <dirent.h>
#include <util.h>
+#include <sys/mman.h>
#include <mkfs_msdos.h>
#include <fs/msdosfs/bpb.h>
#include "msdos/direntry.h"
@@ -183,6 +184,11 @@
fsopts->fd = open(image, O_RDWR);
vp.fs = fsopts;
+ fsopts->mmap = mmap(0, fsopts->size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fsopts->fd, 0);
+ if (fsopts->mmap == MAP_FAILED) {
+ warn("mmap failed");
+ fsopts->mmap = 0;
+ }
if ((pmp = m_msdosfs_mount(&vp)) == NULL)
err(1, "msdosfs_mount");
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Sep 2, 1:37 PM (14 h, 57 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
37965619
Default Alt Text
D39026.id118665.diff (3 KB)
Attached To
Mode
D39026: makefs: Add a mmap'd buffer cache
Attached
Detach File
Event Timeline
Log In to Comment