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);