summaryrefslogtreecommitdiffstats
path: root/lib/libstand/ufs.c
diff options
context:
space:
mode:
authormsmith <msmith@FreeBSD.org>1998-09-26 01:42:40 +0000
committermsmith <msmith@FreeBSD.org>1998-09-26 01:42:40 +0000
commitea783268e73e47b0c3012339d1e278e7045e2305 (patch)
tree622472325886767e4a3905d55b5180ea188a7e99 /lib/libstand/ufs.c
parent73ca5cb35b01711ebbbdbdc1d00d3f320d0a852c (diff)
downloadFreeBSD-src-ea783268e73e47b0c3012339d1e278e7045e2305.zip
FreeBSD-src-ea783268e73e47b0c3012339d1e278e7045e2305.tar.gz
Replace the old and extremely icky Mach/NetBSD allocator with a similarly
compact and much better one donated by Matt Dillon. Implement a simple sbrk() which uses the existing setheap() api. Remove the custom allocator from the UFS code. It wasn't working quite right, and it shouldn't be needed with the new allocator. Fix a serious problem with changing the value of already-existent environment variables. Don't attempt to modify the supposedly-const argument to putenv() Fix an off-by-one sizing error in the zipfs code detected by the new allocator. Submitted by: zmalloc from Matt Dillon <dillon@backplane.com>
Diffstat (limited to 'lib/libstand/ufs.c')
-rw-r--r--lib/libstand/ufs.c60
1 files changed, 14 insertions, 46 deletions
diff --git a/lib/libstand/ufs.c b/lib/libstand/ufs.c
index a32fe06..bd7f8c7 100644
--- a/lib/libstand/ufs.c
+++ b/lib/libstand/ufs.c
@@ -84,7 +84,6 @@ struct fs_ops ufs_fsops = {
"ufs", ufs_open, ufs_close, ufs_read, null_write, ufs_seek, ufs_stat
};
-
/*
* In-core open file.
*/
@@ -113,39 +112,6 @@ static int search_directory(char *, struct open_file *, ino_t *);
static void ffs_oldfscompat(struct fs *);
#endif
-static void *buffers4 = 0;
-static void *buffers8 = 0;
-
-static void *
-getbuf(size_t size)
-{
- void *p = 0;
- if (size == 8192 && buffers8) {
- p = buffers8;
- buffers8 = *(void **) p;
- }
- if (size == 4096 && buffers4) {
- p = buffers4;
- buffers4 = *(void **) p;
- }
- if (!p)
- p = malloc(size);
- return p;
-}
-
-static void
-relbuf(void *p, size_t size)
-{
- if (size == 8192) {
- *(void**) p = buffers8;
- buffers8 = p;
- } else if (size == 4096) {
- *(void**) p = buffers4;
- buffers8 = p;
- } else
- free(p);
-}
-
/*
* Read a new inode into a file structure.
*/
@@ -160,10 +126,13 @@ read_inode(inumber, f)
size_t rsize;
int rc;
+ if (fs == NULL)
+ panic("fs == NULL");
+
/*
* Read inode and save it.
*/
- buf = getbuf(fs->fs_bsize);
+ buf = malloc(fs->fs_bsize);
twiddle();
rc = (f->f_dev->dv_strategy)(f->f_devdata, F_READ,
fsbtodb(fs, ino_to_fsba(fs, inumber)), fs->fs_bsize,
@@ -193,7 +162,7 @@ read_inode(inumber, f)
fp->f_buf_blkno = -1;
}
out:
- relbuf(buf, fs->fs_bsize);
+ free(buf);
return (rc);
}
@@ -273,7 +242,7 @@ block_map(f, file_block, disk_block_p)
if (fp->f_blkno[level] != ind_block_num) {
if (fp->f_blk[level] == (char *)0)
fp->f_blk[level] =
- getbuf(fs->fs_bsize);
+ malloc(fs->fs_bsize);
twiddle();
rc = (f->f_dev->dv_strategy)(f->f_devdata, F_READ,
fsbtodb(fp->f_fs, ind_block_num),
@@ -331,7 +300,7 @@ buf_read_file(f, buf_p, size_p)
return (rc);
if (fp->f_buf == (char *)0)
- fp->f_buf = getbuf(fs->fs_bsize);
+ fp->f_buf = malloc(fs->fs_bsize);
if (disk_block == 0) {
bzero(fp->f_buf, block_size);
@@ -442,7 +411,7 @@ ufs_open(upath, f)
f->f_fsdata = (void *)fp;
/* allocate space and read super block */
- fs = getbuf(SBSIZE);
+ fs = malloc(SBSIZE);
fp->f_fs = fs;
twiddle();
rc = (f->f_dev->dv_strategy)(f->f_devdata, F_READ,
@@ -563,7 +532,7 @@ ufs_open(upath, f)
register struct fs *fs = fp->f_fs;
if (!buf)
- buf = getbuf(fs->fs_bsize);
+ buf = malloc(fs->fs_bsize);
rc = block_map(f, (daddr_t)0, &disk_block);
if (rc)
goto out;
@@ -599,12 +568,12 @@ ufs_open(upath, f)
rc = 0;
out:
if (buf)
- relbuf(buf, fs->fs_bsize);
+ free(buf);
if (path)
free(path);
if (rc) {
if (fp->f_buf)
- relbuf(fp->f_buf, fs->fs_bsize);
+ free(fp->f_buf);
free(fp->f_fs);
free(fp);
}
@@ -616,7 +585,6 @@ ufs_close(f)
struct open_file *f;
{
register struct file *fp = (struct file *)f->f_fsdata;
- struct fs *fs = fp->f_fs;
int level;
f->f_fsdata = (void *)0;
@@ -625,11 +593,11 @@ ufs_close(f)
for (level = 0; level < NIADDR; level++) {
if (fp->f_blk[level])
- relbuf(fp->f_blk[level], fs->fs_bsize);
+ free(fp->f_blk[level]);
}
if (fp->f_buf)
- relbuf(fp->f_buf, fs->fs_bsize);
- relbuf(fp->f_fs, SBSIZE);
+ free(fp->f_buf);
+ free(fp->f_fs);
free(fp);
return (0);
}
OpenPOWER on IntegriCloud