Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 8 Apr 2018 06:59:42 +0000 (UTC)
From:      Kirk McKusick <mckusick@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r332266 - head/lib/libufs
Message-ID:  <201804080659.w386xgPc003946@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mckusick
Date: Sun Apr  8 06:59:42 2018
New Revision: 332266
URL: https://svnweb.freebsd.org/changeset/base/332266

Log:
  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.

Modified:
  head/lib/libufs/type.c

Modified: head/lib/libufs/type.c
==============================================================================
--- head/lib/libufs/type.c	Sun Apr  8 06:52:58 2018	(r332265)
+++ head/lib/libufs/type.c	Sun Apr  8 06:59:42 2018	(r332266)
@@ -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);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201804080659.w386xgPc003946>