Fix for tunefs(8) unable to add a UFS/FFS soft update journal.

The reported bug is UFS: bad file descriptor: soft update journaling
can not be enabled on some FreeBSD-provided disk images – failed
to write updated cg.

The UFS library (libufs(3)) failed to reopen its disk descriptor
when first attempting to update a cylinder group. The error only
occurred when trying to add journaling to a filesystem whose first
cylinder group was too full to hold the journal.

PR:           259090
MFC after:    1 week
Sponsored by: The FreeBSD Foundation
This commit is contained in:
Kirk McKusick 2022-11-12 15:36:07 -08:00
parent 30a6c8a3a8
commit 5c7ba6bdf8

View File

@ -268,6 +268,10 @@ cgwrite1(struct uufsd *disk, int cg)
static char errmsg[BUFSIZ];
if (cg == disk->d_cg.cg_cgx) {
if (ufs_disk_write(disk) == -1) {
ERROR(disk, "failed to open disk for writing");
return (-1);
}
if (cgput(disk->d_fd, &disk->d_fs, &disk->d_cg) == 0)
return (0);
ERROR(disk, NULL);