Changeset View
Changeset View
Standalone View
Standalone View
usr.sbin/makefs/ffs/buf.c
Show First 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | |||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include <string.h> | #include <string.h> | ||||
#include <unistd.h> | #include <unistd.h> | ||||
#include <util.h> | #include <util.h> | ||||
#include "makefs.h" | #include "makefs.h" | ||||
#include "buf.h" | #include "buf.h" | ||||
static TAILQ_HEAD(buftailhead,buf) buftail; | static TAILQ_HEAD(buftailhead, m_buf) buftail; | ||||
int | int | ||||
bread(struct vnode *vp, daddr_t blkno, int size, struct ucred *u1 __unused, | bread(struct m_vnode *vp, daddr_t blkno, int size, struct ucred *u1 __unused, | ||||
struct buf **bpp) | struct m_buf **bpp) | ||||
{ | { | ||||
off_t offset; | off_t offset; | ||||
ssize_t rv; | ssize_t rv; | ||||
fsinfo_t *fs = vp->fs; | fsinfo_t *fs = vp->fs; | ||||
assert (bpp != NULL); | assert (bpp != NULL); | ||||
if (debug & DEBUG_BUF_BREAD) | if (debug & DEBUG_BUF_BREAD) | ||||
Show All 18 Lines | bread(struct m_vnode *vp, daddr_t blkno, int size, struct ucred *u1 __unused, | ||||
else if (rv != (*bpp)->b_bcount) /* short read */ | else if (rv != (*bpp)->b_bcount) /* short read */ | ||||
err(1, "%s: read %ld (%lld) returned %d", __func__, | err(1, "%s: read %ld (%lld) returned %d", __func__, | ||||
(*bpp)->b_bcount, (long long)offset, (int)rv); | (*bpp)->b_bcount, (long long)offset, (int)rv); | ||||
else | else | ||||
return (0); | return (0); | ||||
} | } | ||||
void | void | ||||
brelse(struct buf *bp) | brelse(struct m_buf *bp) | ||||
{ | { | ||||
assert (bp != NULL); | assert (bp != NULL); | ||||
assert (bp->b_data != NULL); | assert (bp->b_data != NULL); | ||||
if (bp->b_lblkno < 0) { | if (bp->b_lblkno < 0) { | ||||
/* | /* | ||||
* XXX don't remove any buffers with negative logical block | * XXX don't remove any buffers with negative logical block | ||||
Show All 13 Lines | brelse(struct m_buf *bp) | ||||
} | } | ||||
TAILQ_REMOVE(&buftail, bp, b_tailq); | TAILQ_REMOVE(&buftail, bp, b_tailq); | ||||
free(bp->b_data); | free(bp->b_data); | ||||
free(bp); | free(bp); | ||||
} | } | ||||
int | int | ||||
bwrite(struct buf *bp) | bwrite(struct m_buf *bp) | ||||
{ | { | ||||
off_t offset; | off_t offset; | ||||
ssize_t rv; | ssize_t rv; | ||||
fsinfo_t *fs = bp->b_fs; | fsinfo_t *fs = bp->b_fs; | ||||
assert (bp != NULL); | assert (bp != NULL); | ||||
offset = bp->b_blkno * fs->sectorsize + fs->offset; | offset = bp->b_blkno * fs->sectorsize + fs->offset; | ||||
if (debug & DEBUG_BUF_BWRITE) | if (debug & DEBUG_BUF_BWRITE) | ||||
Show All 12 Lines | else if (rv == -1) /* write error */ | ||||
return (errno); | return (errno); | ||||
else /* short write ? */ | else /* short write ? */ | ||||
return (EAGAIN); | return (EAGAIN); | ||||
} | } | ||||
void | void | ||||
bcleanup(void) | bcleanup(void) | ||||
{ | { | ||||
struct buf *bp; | struct m_buf *bp; | ||||
/* | /* | ||||
* XXX this really shouldn't be necessary, but i'm curious to | * XXX this really shouldn't be necessary, but i'm curious to | ||||
* know why there's still some buffers lying around that | * know why there's still some buffers lying around that | ||||
* aren't brelse()d | * aren't brelse()d | ||||
*/ | */ | ||||
if (TAILQ_EMPTY(&buftail)) | if (TAILQ_EMPTY(&buftail)) | ||||
return; | return; | ||||
printf("bcleanup: unflushed buffers:\n"); | printf("bcleanup: unflushed buffers:\n"); | ||||
TAILQ_FOREACH(bp, &buftail, b_tailq) { | TAILQ_FOREACH(bp, &buftail, b_tailq) { | ||||
printf("\tlblkno %10lld blkno %10lld count %6ld bufsize %6ld\n", | printf("\tlblkno %10lld blkno %10lld count %6ld bufsize %6ld\n", | ||||
(long long)bp->b_lblkno, (long long)bp->b_blkno, | (long long)bp->b_lblkno, (long long)bp->b_blkno, | ||||
bp->b_bcount, bp->b_bufsize); | bp->b_bcount, bp->b_bufsize); | ||||
} | } | ||||
printf("bcleanup: done\n"); | printf("bcleanup: done\n"); | ||||
} | } | ||||
struct buf * | struct m_buf * | ||||
getblk(struct vnode *vp, daddr_t blkno, int size, int u1 __unused, | getblk(struct m_vnode *vp, daddr_t blkno, int size, int u1 __unused, | ||||
int u2 __unused, int u3 __unused) | int u2 __unused, int u3 __unused) | ||||
{ | { | ||||
static int buftailinitted; | static int buftailinitted; | ||||
struct buf *bp; | struct m_buf *bp; | ||||
void *n; | void *n; | ||||
if (debug & DEBUG_BUF_GETBLK) | if (debug & DEBUG_BUF_GETBLK) | ||||
printf("getblk: blkno %lld size %d\n", (long long)blkno, size); | printf("getblk: blkno %lld size %d\n", (long long)blkno, size); | ||||
bp = NULL; | bp = NULL; | ||||
if (!buftailinitted) { | if (!buftailinitted) { | ||||
if (debug & DEBUG_BUF_GETBLK) | if (debug & DEBUG_BUF_GETBLK) | ||||
Show All 28 Lines |