aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEd Maste <emaste@FreeBSD.org>2023-03-13 21:00:20 +0000
committerEd Maste <emaste@FreeBSD.org>2023-04-16 19:45:17 +0000
commite5551216d8e563043248bc7f3cb1c75b2dbd9791 (patch)
tree36d5a99fa35d74d0abee35ced45a1ade048daaf8
parent89d197cc991acfbb6937be0ce5b9255d14b72160 (diff)
downloadsrc-e5551216d8e563043248bc7f3cb1c75b2dbd9791.tar.gz
src-e5551216d8e563043248bc7f3cb1c75b2dbd9791.zip
makefs: call brelse from bread
This matches NetBSD and rationalizes makefs with the kernel API. This reverts commit 370e009188ba90c3290b1479aa06ec98b66e140a. Reviewed by: mckusick Sponsored by: The FreeBSD Foundation Obtained from: NetBSD 0a62dad69f62, 0c4125e1a19f, cb6a5a3575fd Differential Revision: https://reviews.freebsd.org/D39070
-rw-r--r--usr.sbin/makefs/ffs.c1
-rw-r--r--usr.sbin/makefs/ffs/buf.c25
-rw-r--r--usr.sbin/makefs/msdos/msdosfs_vnops.c1
3 files changed, 15 insertions, 12 deletions
diff --git a/usr.sbin/makefs/ffs.c b/usr.sbin/makefs/ffs.c
index cc0f640e3c9c..17682dea2a4b 100644
--- a/usr.sbin/makefs/ffs.c
+++ b/usr.sbin/makefs/ffs.c
@@ -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;
}
diff --git a/usr.sbin/makefs/ffs/buf.c b/usr.sbin/makefs/ffs/buf.c
index fe6eaed93d04..3d03e9866b3b 100644
--- a/usr.sbin/makefs/ffs/buf.c
+++ b/usr.sbin/makefs/ffs/buf.c
@@ -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
diff --git a/usr.sbin/makefs/msdos/msdosfs_vnops.c b/usr.sbin/makefs/msdos/msdosfs_vnops.c
index c04ed6f742a1..5bc9b495c586 100644
--- a/usr.sbin/makefs/msdos/msdosfs_vnops.c
+++ b/usr.sbin/makefs/msdos/msdosfs_vnops.c
@@ -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;
}