Skip to content

Commit

Permalink
Merge pull request #403 from ruihe774/fb
Browse files Browse the repository at this point in the history
mount: Support EROFS file-backed mounts
  • Loading branch information
cgwalters authored Dec 29, 2024
2 parents 1003b4f + 6f00c0f commit 14ad6b9
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions libcomposefs/lcfs-mount.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ static errint_t setup_loopback(int fd, const char *image_path, char *loopname)
return -errsv;
}

sprintf(loopname, "/dev/loop%ld", devnr);
snprintf(loopname, PATH_MAX, "/dev/loop%ld", devnr);
loopfd = open(loopname, O_RDWR | O_CLOEXEC);
if (loopfd < 0)
return -errno;
Expand Down 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);
snprintf(source, PATH_MAX, "/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 14ad6b9

Please sign in to comment.