>From f0a0a129f996e63981146d819eba425f85fd1eac Mon Sep 17 00:00:00 2001 From: Sam Thursfield Date: Mon, 1 Jun 2015 12:46:13 +0000 Subject: [PATCH] Add --mount-tmpfs option Allows mounting an in-memory temporary filesystem inside the chroot. --- src/linux-user-chroot.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/linux-user-chroot.c b/src/linux-user-chroot.c index 8b8700d..57089e8 100644 --- a/src/linux-user-chroot.c +++ b/src/linux-user-chroot.c @@ -92,7 +92,8 @@ fatal_errno (const char *message) typedef enum { MOUNT_SPEC_BIND, MOUNT_SPEC_READONLY, - MOUNT_SPEC_PROCFS + MOUNT_SPEC_PROCFS, + MOUNT_SPEC_TMPFS } MountSpecType; typedef struct _MountSpec MountSpec; @@ -242,6 +243,22 @@ main (int argc, bind_mounts = mount; after_mount_arg_index += 2; } + else if (strcmp (arg, "--mount-tmpfs") == 0) + { + MountSpec *mount; + + if ((argc - after_mount_arg_index) < 2) + fatal ("--mount-tmpfs takes one argument"); + + mount = malloc (sizeof (MountSpec)); + mount->type = MOUNT_SPEC_TMPFS; + mount->source = NULL; + mount->dest = argv[after_mount_arg_index+1]; + mount->next = bind_mounts; + + bind_mounts = mount; + after_mount_arg_index += 2; + } else if (strcmp (arg, "--unshare-ipc") == 0) { unshare_ipc = 1; @@ -272,7 +289,7 @@ main (int argc, bind_mounts = reverse_mount_list (bind_mounts); if ((argc - after_mount_arg_index) < 2) - fatal ("usage: %s [--unshare-ipc] [--unshare-pid] [--unshare-net] [--mount-proc DIR] [--mount-readonly DIR] [--mount-bind SOURCE DEST] [--chdir DIR] ROOTDIR PROGRAM ARGS...", argv0); + fatal ("usage: %s [--unshare-ipc] [--unshare-pid] [--unshare-net] [--mount-proc DIR] [--mount-tmpfs DIR] [--mount-readonly DIR] [--mount-bind SOURCE DEST] [--chdir DIR] ROOTDIR PROGRAM ARGS...", argv0); chroot_dir = argv[after_mount_arg_index]; program = argv[after_mount_arg_index+1]; program_argv = argv + after_mount_arg_index + 1; @@ -375,6 +392,12 @@ main (int argc, "proc", MS_MGC_VAL | MS_PRIVATE, NULL) < 0) fatal_errno ("mount (\"proc\")"); } + else if (bind_mount_iter->type == MOUNT_SPEC_TMPFS) + { + if (mount ("none", dest, + "tmpfs", 0, NULL) < 0) + fatal_errno ("mount (\"tmpfs\")"); + } else assert (0); free (dest); -- 1.9.3