Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mount: Support EROFS file-backed mounts #403

Merged
merged 1 commit into from
Dec 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
ruihe774 marked this conversation as resolved.
Show resolved Hide resolved
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
Loading