parseMountOptions takes fstab style mount options and parses them for use with a standard mount() syscall
(options []string)
| 63 | // parseMountOptions takes fstab style mount options and parses them for |
| 64 | // use with a standard mount() syscall |
| 65 | func parseMountOptions(options []string) (int, string) { |
| 66 | var ( |
| 67 | flag int |
| 68 | data []string |
| 69 | ) |
| 70 | flags := map[string]struct { |
| 71 | clear bool |
| 72 | flag int |
| 73 | }{ |
| 74 | "async": {true, unix.MS_SYNCHRONOUS}, |
| 75 | "atime": {true, unix.MS_NOATIME}, |
| 76 | "bind": {false, unix.MS_BIND}, |
| 77 | "defaults": {false, 0}, |
| 78 | "dev": {true, unix.MS_NODEV}, |
| 79 | "diratime": {true, unix.MS_NODIRATIME}, |
| 80 | "dirsync": {false, unix.MS_DIRSYNC}, |
| 81 | "exec": {true, unix.MS_NOEXEC}, |
| 82 | "mand": {false, unix.MS_MANDLOCK}, |
| 83 | "noatime": {false, unix.MS_NOATIME}, |
| 84 | "nodev": {false, unix.MS_NODEV}, |
| 85 | "nodiratime": {false, unix.MS_NODIRATIME}, |
| 86 | "noexec": {false, unix.MS_NOEXEC}, |
| 87 | "nomand": {true, unix.MS_MANDLOCK}, |
| 88 | "norelatime": {true, unix.MS_RELATIME}, |
| 89 | "nostrictatime": {true, unix.MS_STRICTATIME}, |
| 90 | "nosuid": {false, unix.MS_NOSUID}, |
| 91 | "private": {false, unix.MS_PRIVATE}, |
| 92 | "rbind": {false, unix.MS_BIND | unix.MS_REC}, |
| 93 | "relatime": {false, unix.MS_RELATIME}, |
| 94 | "remount": {false, unix.MS_REMOUNT}, |
| 95 | "ro": {false, unix.MS_RDONLY}, |
| 96 | "rw": {true, unix.MS_RDONLY}, |
| 97 | "shared": {false, unix.MS_SHARED}, |
| 98 | "slave": {false, unix.MS_SLAVE}, |
| 99 | "strictatime": {false, unix.MS_STRICTATIME}, |
| 100 | "suid": {true, unix.MS_NOSUID}, |
| 101 | "sync": {false, unix.MS_SYNCHRONOUS}, |
| 102 | "unbindable": {false, unix.MS_UNBINDABLE}, |
| 103 | } |
| 104 | for _, o := range options { |
| 105 | // If the option does not exist in the flags table or the flag |
| 106 | // is not supported on the platform, |
| 107 | // then it is a data value for a specific fs type |
| 108 | if f, exists := flags[o]; exists && f.flag != 0 { |
| 109 | if f.clear { |
| 110 | flag &^= f.flag |
| 111 | } else { |
| 112 | flag |= f.flag |
| 113 | } |
| 114 | } else { |
| 115 | data = append(data, o) |
| 116 | } |
| 117 | } |
| 118 | return flag, strings.Join(data, ",") |
| 119 | } |
| 120 | |
| 121 | // newCgroup creates a cgroup (ie directory) |
| 122 | // we could use github.com/containerd/cgroups but it has a lot of deps and this is just a sugary mkdir |