github.com/wlan0/docker@v1.5.0/pkg/mount/flags.go (about)

     1  package mount
     2  
     3  import (
     4  	"strings"
     5  )
     6  
     7  // Parse fstab type mount options into mount() flags
     8  // and device specific data
     9  func parseOptions(options string) (int, string) {
    10  	var (
    11  		flag int
    12  		data []string
    13  	)
    14  
    15  	flags := map[string]struct {
    16  		clear bool
    17  		flag  int
    18  	}{
    19  		"defaults":      {false, 0},
    20  		"ro":            {false, RDONLY},
    21  		"rw":            {true, RDONLY},
    22  		"suid":          {true, NOSUID},
    23  		"nosuid":        {false, NOSUID},
    24  		"dev":           {true, NODEV},
    25  		"nodev":         {false, NODEV},
    26  		"exec":          {true, NOEXEC},
    27  		"noexec":        {false, NOEXEC},
    28  		"sync":          {false, SYNCHRONOUS},
    29  		"async":         {true, SYNCHRONOUS},
    30  		"dirsync":       {false, DIRSYNC},
    31  		"remount":       {false, REMOUNT},
    32  		"mand":          {false, MANDLOCK},
    33  		"nomand":        {true, MANDLOCK},
    34  		"atime":         {true, NOATIME},
    35  		"noatime":       {false, NOATIME},
    36  		"diratime":      {true, NODIRATIME},
    37  		"nodiratime":    {false, NODIRATIME},
    38  		"bind":          {false, BIND},
    39  		"rbind":         {false, RBIND},
    40  		"unbindable":    {false, UNBINDABLE},
    41  		"runbindable":   {false, RUNBINDABLE},
    42  		"private":       {false, PRIVATE},
    43  		"rprivate":      {false, RPRIVATE},
    44  		"shared":        {false, SHARED},
    45  		"rshared":       {false, RSHARED},
    46  		"slave":         {false, SLAVE},
    47  		"rslave":        {false, RSLAVE},
    48  		"relatime":      {false, RELATIME},
    49  		"norelatime":    {true, RELATIME},
    50  		"strictatime":   {false, STRICTATIME},
    51  		"nostrictatime": {true, STRICTATIME},
    52  	}
    53  
    54  	for _, o := range strings.Split(options, ",") {
    55  		// If the option does not exist in the flags table or the flag
    56  		// is not supported on the platform,
    57  		// then it is a data value for a specific fs type
    58  		if f, exists := flags[o]; exists && f.flag != 0 {
    59  			if f.clear {
    60  				flag &= ^f.flag
    61  			} else {
    62  				flag |= f.flag
    63  			}
    64  		} else {
    65  			data = append(data, o)
    66  		}
    67  	}
    68  	return flag, strings.Join(data, ",")
    69  }