aboutsummaryrefslogtreecommitdiff
path: root/lib/libufs/type.c
diff options
context:
space:
mode:
authorKirk McKusick <mckusick@FreeBSD.org>2018-04-08 06:59:42 +0000
committerKirk McKusick <mckusick@FreeBSD.org>2018-04-08 06:59:42 +0000
commit5613df4f663cb8ca5fad3fc9e563baa83b0cebe1 (patch)
tree17ff635ce50b3b5003aa7247046813ba156fd2b3 /lib/libufs/type.c
parent0e3f58b6612b3b0c03ca1b1c85cfa4e8ab460ebe (diff)
downloadsrc-5613df4f663cb8ca5fad3fc9e563baa83b0cebe1.tar.gz
src-5613df4f663cb8ca5fad3fc9e563baa83b0cebe1.zip
The ufs_disk_write() function is used to upgrade a read-only descriptor
to a read-write descriptor. Do not close the read-only descriptor until the read-write is successfully obtained. Before this fix, a failed upgrade left no usable descriptor with which to work.
Notes
Notes: svn path=/head/; revision=332266
Diffstat (limited to 'lib/libufs/type.c')
-rw-r--r--lib/libufs/type.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/lib/libufs/type.c b/lib/libufs/type.c
index 498b71ab954d..bcbb1914c497 100644
--- a/lib/libufs/type.c
+++ b/lib/libufs/type.c
@@ -60,6 +60,7 @@ ufs_disk_close(struct uufsd *disk)
{
ERROR(disk, NULL);
close(disk->d_fd);
+ disk->d_fd = -1;
if (disk->d_inoblock != NULL) {
free(disk->d_inoblock);
disk->d_inoblock = NULL;
@@ -181,19 +182,21 @@ again: if ((ret = stat(name, &st)) < 0) {
int
ufs_disk_write(struct uufsd *disk)
{
+ int fd;
+
ERROR(disk, NULL);
if (disk->d_mine & MINE_WRITE)
return (0);
- close(disk->d_fd);
-
- disk->d_fd = open(disk->d_name, O_RDWR);
- if (disk->d_fd < 0) {
+ fd = open(disk->d_name, O_RDWR);
+ if (fd < 0) {
ERROR(disk, "failed to open disk for writing");
return (-1);
}
+ close(disk->d_fd);
+ disk->d_fd = fd;
disk->d_mine |= MINE_WRITE;
return (0);