From bd052b6116ff0040615db2090b9a253c889a0992 Mon Sep 17 00:00:00 2001 From: Dan Walsh Date: Tue, 1 Dec 2015 13:39:34 -0500 Subject: [PATCH] This patch adds --tmpfs as a option for mounting tmpfs on directories It will Tar up contents of child directory onto tmpfs if mounted over This patch will use the new PreMount and PostMount hooks to "tar" up the contents of the base image on top of tmpfs mount points. Signed-off-by: Dan Walsh --- mount/flags.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/mount/flags.go b/mount/flags.go index 17dbd7a..4305d15 100644 --- a/mount/flags.go +++ b/mount/flags.go @@ -1,6 +1,7 @@ package mount import ( + "fmt" "strings" ) @@ -67,3 +68,24 @@ func parseOptions(options string) (int, string) { } return flag, strings.Join(data, ",") } + +// ParseTmpfsOptions parse fstab type mount options into flags and data +func ParseTmpfsOptions(options string) (int, string, error) { + flags, data := parseOptions(options) + validFlags := map[string]bool{ + "size": true, + "mode": true, + "uid": true, + "gid": true, + "nr_inodes": true, + "nr_blocks": true, + "mpol": true, + } + for _, o := range strings.Split(data, ",") { + opt := strings.SplitN(o, "=", 2) + if !validFlags[opt[0]] { + return 0, "", fmt.Errorf("Invalid tmpfs option %q", opt) + } + } + return flags, data, nil +}