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:
parent
1c8afb9a0e
commit
76c3f684b3
@ -60,6 +60,7 @@ ufs_disk_close(struct uufsd *disk)
|
|||||||
{
|
{
|
||||||
ERROR(disk, NULL);
|
ERROR(disk, NULL);
|
||||||
close(disk->d_fd);
|
close(disk->d_fd);
|
||||||
|
disk->d_fd = -1;
|
||||||
if (disk->d_inoblock != NULL) {
|
if (disk->d_inoblock != NULL) {
|
||||||
free(disk->d_inoblock);
|
free(disk->d_inoblock);
|
||||||
disk->d_inoblock = NULL;
|
disk->d_inoblock = NULL;
|
||||||
@ -181,19 +182,21 @@ again: if ((ret = stat(name, &st)) < 0) {
|
|||||||
int
|
int
|
||||||
ufs_disk_write(struct uufsd *disk)
|
ufs_disk_write(struct uufsd *disk)
|
||||||
{
|
{
|
||||||
|
int fd;
|
||||||
|
|
||||||
ERROR(disk, NULL);
|
ERROR(disk, NULL);
|
||||||
|
|
||||||
if (disk->d_mine & MINE_WRITE)
|
if (disk->d_mine & MINE_WRITE)
|
||||||
return (0);
|
return (0);
|
||||||
|
|
||||||
close(disk->d_fd);
|
fd = open(disk->d_name, O_RDWR);
|
||||||
|
if (fd < 0) {
|
||||||
disk->d_fd = open(disk->d_name, O_RDWR);
|
|
||||||
if (disk->d_fd < 0) {
|
|
||||||
ERROR(disk, "failed to open disk for writing");
|
ERROR(disk, "failed to open disk for writing");
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
close(disk->d_fd);
|
||||||
|
disk->d_fd = fd;
|
||||||
disk->d_mine |= MINE_WRITE;
|
disk->d_mine |= MINE_WRITE;
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
|
Loading…
Reference in New Issue
Block a user