Skip to content

Commit

Permalink
mount: Support EROFS file-backed mounts
Browse files Browse the repository at this point in the history
Signed-off-by: Misaki Kasumi <[email protected]>
  • Loading branch information
ruihe774 committed Dec 19, 2024
1 parent 1003b4f commit 695ac22
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions libcomposefs/lcfs-mount.c
Original file line number Diff line number Diff line change
Expand Up @@ -578,34 +578,43 @@ static errint_t lcfs_mount_erofs_ovl(struct lcfs_mount_state_s *state,
char imagemountbuf[] = "/tmp/.composefs.XXXXXX";
char *imagemount;
bool created_tmpdir = false;
char loopname[PATH_MAX];
char source[PATH_MAX];
int errsv;
errint_t err;
int loopfd;

image_flags = lcfs_u32_from_file(header->flags);

loopfd = setup_loopback(state->fd, state->image_path, loopname);
if (loopfd < 0)
return loopfd;

if (options->image_mountdir) {
imagemount = (char *)options->image_mountdir;
} else {
imagemount = mkdtemp(imagemountbuf);
if (imagemount == NULL) {
errsv = errno;
close(loopfd);
return -errsv;
}
created_tmpdir = true;
}

err = lcfs_mount_erofs(loopname, imagemount, image_flags, state);
close(loopfd);
sprintf(source, "/proc/self/fd/%d", state->fd);
err = lcfs_mount_erofs(source, imagemount, image_flags, state);

if (err < 0) {
rmdir(imagemount);
return err;
if (errno == ENOTBLK) {
/* Fallback to use loop device */
loopfd = setup_loopback(state->fd, state->image_path, source);
if (loopfd < 0)
return loopfd;

err = lcfs_mount_erofs(source, imagemount, image_flags, state);

close(loopfd);
}

if (err < 0) {
rmdir(imagemount);
return err;
}
}

/* We use the legacy API to mount overlayfs, because the new API doesn't allow use
Expand Down

0 comments on commit 695ac22

Please sign in to comment.