makefs: call brelse from bread

This matches NetBSD and rationalizes makefs with the kernel API.

This reverts commit 370e009188.

Reviewed by:	mckusick
Sponsored by:	The FreeBSD Foundation
Obtained from:	NetBSD 0a62dad69f62, 0c4125e1a19f, cb6a5a3575fd
Differential Revision:	https://reviews.freebsd.org/D39070
This commit is contained in:
Ed Maste 2023-03-13 17:00:20 -04:00
parent 89d197cc99
commit e5551216d8
3 changed files with 15 additions and 12 deletions

View File

@ -1002,7 +1002,6 @@ ffs_write_file(union dinode *din, uint32_t ino, void *buf, fsinfo_t *fsopts)
errno = bwrite(bp);
if (errno != 0)
goto bad_ffs_write_file;
brelse(bp);
if (!isfile)
p += chunk;
}

View File

@ -127,26 +127,31 @@ bwrite(struct m_buf *bp)
{
off_t offset;
ssize_t rv;
size_t bytes;
int e;
fsinfo_t *fs = bp->b_fs;
assert (bp != NULL);
offset = (off_t)bp->b_blkno * fs->sectorsize + fs->offset;
bytes = (size_t)bp->b_bcount;
if (debug & DEBUG_BUF_BWRITE)
printf("%s: blkno %lld offset %lld bcount %ld\n", __func__,
(long long)bp->b_blkno, (long long) offset,
bp->b_bcount);
if (lseek(bp->b_fs->fd, offset, SEEK_SET) == -1)
printf("%s: blkno %lld offset %lld bcount %zu\n", __func__,
(long long)bp->b_blkno, (long long) offset, bytes);
if (lseek(bp->b_fs->fd, offset, SEEK_SET) == -1) {
brelse(bp);
return (errno);
rv = write(bp->b_fs->fd, bp->b_data, bp->b_bcount);
}
rv = write(bp->b_fs->fd, bp->b_data, bytes);
e = errno;
if (debug & DEBUG_BUF_BWRITE)
printf("%s: write %ld (offset %lld) returned %lld\n", __func__,
bp->b_bcount, (long long)offset, (long long)rv);
if (rv == bp->b_bcount)
brelse(bp);
if (rv == (ssize_t)bytes)
return (0);
else if (rv == -1) /* write error */
return (errno);
else /* short write ? */
return (EAGAIN);
if (rv == -1) /* write error */
return (e);
return (EAGAIN);
}
void

View File

@ -500,7 +500,6 @@ msdosfs_wfile(const char *path, struct denode *dep, fsnode *node)
cpsize = MIN((nsize - offs), blsize - on);
memcpy(bp->b_data + on, dat + offs, cpsize);
bwrite(bp);
brelse(bp);
offs += cpsize;
}