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.
This commit is contained in:
mckusick 2018-04-08 06:59:42 +00:00
parent 1c8afb9a0e
commit 76c3f684b3

View File

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