repart: Re-open file descriptor to partition target after mkfs
The mkfs binary might unlink the path we give it and replace it with a new file so let's make sure that our fd points to any new file rather than the old deleted file. Specifically this fixes erofs partition generation.
This commit is contained in:
committed by
Yu Watanabe
parent
3b25958e64
commit
0122c7d060
@@ -4849,6 +4849,17 @@ static int context_mkfs(Context *context) {
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
/* The mkfs binary we invoked might have removed our temporary file when we're not operating
|
||||
* on a loop device, so let's make sure we open the file again to make sure our file
|
||||
* descriptor points to any potential new file. */
|
||||
|
||||
if (t->fd >= 0 && t->path && !t->loop) {
|
||||
safe_close(t->fd);
|
||||
t->fd = open(t->path, O_RDWR|O_CLOEXEC);
|
||||
if (t->fd < 0)
|
||||
return log_error_errno(errno, "Failed to reopen temporary file: %m");
|
||||
}
|
||||
|
||||
log_info("Successfully formatted future partition %" PRIu64 ".", p->partno);
|
||||
|
||||
/* If we're writing to a loop device, we can now mount the empty filesystem and populate it. */
|
||||
|
||||
Reference in New Issue
Block a user