~ubuntu-branches/ubuntu/trusty/util-linux/trusty-proposed

« back to all changes in this revision

Viewing changes to shlibs/mount/src/optmap.c

  • Committer: Package Import Robot
  • Author(s): LaMont Jones
  • Date: 2011-11-03 15:38:23 UTC
  • mto: (4.5.5 sid) (1.6.4)
  • mto: This revision was merged to the branch mainline in revision 85.
  • Revision ID: package-import@ubuntu.com-20111103153823-10sx16jprzxlhkqf
ImportĀ upstreamĀ versionĀ 2.20.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright (C) 2010 Karel Zak <kzak@redhat.com>
3
 
 *
4
 
 * This file may be redistributed under the terms of the
5
 
 * GNU Lesser General Public License.
6
 
 */
7
 
 
8
 
/**
9
 
 * SECTION: optmap
10
 
 * @title: Option maps
11
 
 * @short_description: description for mount options
12
 
 *
13
 
 * The mount(2) linux syscall uses two arguments for mount options:
14
 
 *
15
 
 *      @mountflags: (see MS_* macros in linux/fs.h)
16
 
 *
17
 
 *      @mountdata: (usully a comma separated string of options)
18
 
 *
19
 
 * The libmount uses options-map(s) to describe mount options.
20
 
 *
21
 
 * The option description (map entry) includes:
22
 
 *
23
 
 *      @name: and argument name
24
 
 *
25
 
 *      @id: (in the map unique identifier or a mountflags, e.g MS_RDONLY)
26
 
 *
27
 
 *      @mask: (MNT_INVERT, MNT_NOMTAB)
28
 
 *
29
 
 * The option argument value is defined by:
30
 
 *
31
 
 *      "="   -- required argument, e.g "comment="
32
 
 *
33
 
 *      "[=]" -- optional argument, e.g. "loop[=]"
34
 
 *
35
 
 * Example:
36
 
 *
37
 
 * <informalexample>
38
 
 *   <programlisting>
39
 
 *     #define MY_MS_FOO   (1 << 1)
40
 
 *     #define MY_MS_BAR   (1 << 2)
41
 
 *
42
 
 *     libmnt_optmap myoptions[] = {
43
 
 *       { "foo",   MY_MS_FOO },
44
 
 *       { "nofoo", MY_MS_FOO | MNT_INVERT },
45
 
 *       { "bar=",  MY_MS_BAR },
46
 
 *       { NULL }
47
 
 *     };
48
 
 *   </programlisting>
49
 
 * </informalexample>
50
 
 *
51
 
 * The libmount defines two basic built-in options maps:
52
 
 *
53
 
 *      @MNT_LINUX_MAP: fs-independent kernel mount options (usually MS_* flags)
54
 
 *
55
 
 *      @MNT_USERSPACE_MAP: userspace specific mount options (e.g. "user", "loop")
56
 
 *
57
 
 * For more details about option map struct see "struct mnt_optmap" in
58
 
 * mount/mount.h.
59
 
 */
60
 
#include <string.h>
61
 
#include <stdlib.h>
62
 
#include <ctype.h>
63
 
#include <errno.h>
64
 
 
65
 
#include "nls.h"
66
 
#include "mountP.h"
67
 
 
68
 
/*
69
 
 * fs-independent mount flags (built-in MNT_LINUX_MAP)
70
 
 */
71
 
static const struct libmnt_optmap linux_flags_map[] =
72
 
{
73
 
   { "ro",       MS_RDONLY },                 /* read-only */
74
 
   { "rw",       MS_RDONLY, MNT_INVERT },     /* read-write */
75
 
   { "exec",     MS_NOEXEC, MNT_INVERT },     /* permit execution of binaries */
76
 
   { "noexec",   MS_NOEXEC },                 /* don't execute binaries */
77
 
   { "suid",     MS_NOSUID, MNT_INVERT },     /* honor suid executables */
78
 
   { "nosuid",   MS_NOSUID },                 /* don't honor suid executables */
79
 
   { "dev",      MS_NODEV, MNT_INVERT },      /* interpret device files  */
80
 
   { "nodev",    MS_NODEV },                  /* don't interpret devices */
81
 
 
82
 
   { "sync",     MS_SYNCHRONOUS },            /* synchronous I/O */
83
 
   { "async",    MS_SYNCHRONOUS, MNT_INVERT },/* asynchronous I/O */
84
 
 
85
 
   { "dirsync",  MS_DIRSYNC },                /* synchronous directory modifications */
86
 
   { "remount",  MS_REMOUNT, MNT_NOMTAB },    /* alter flags of mounted FS */
87
 
   { "bind",     MS_BIND },                   /* Remount part of tree elsewhere */
88
 
   { "rbind",    MS_BIND | MS_REC },          /* Idem, plus mounted subtrees */
89
 
#ifdef MS_NOSUB
90
 
   { "sub",      MS_NOSUB, MNT_INVERT },      /* allow submounts */
91
 
   { "nosub",    MS_NOSUB },                  /* don't allow submounts */
92
 
#endif
93
 
#ifdef MS_SILENT
94
 
   { "quiet",    MS_SILENT },                 /* be quiet  */
95
 
   { "loud",     MS_SILENT, MNT_INVERT },     /* print out messages. */
96
 
#endif
97
 
#ifdef MS_MANDLOCK
98
 
   { "mand",     MS_MANDLOCK },               /* Allow mandatory locks on this FS */
99
 
   { "nomand",   MS_MANDLOCK, MNT_INVERT },   /* Forbid mandatory locks on this FS */
100
 
#endif
101
 
#ifdef MS_NOATIME
102
 
   { "atime",    MS_NOATIME, MNT_INVERT },    /* Update access time */
103
 
   { "noatime",  MS_NOATIME },                /* Do not update access time */
104
 
#endif
105
 
#ifdef MS_I_VERSION
106
 
   { "iversion", MS_I_VERSION },              /* Update inode I_version time */
107
 
   { "noiversion", MS_I_VERSION,  MNT_INVERT},/* Don't update inode I_version time */
108
 
#endif
109
 
#ifdef MS_NODIRATIME
110
 
   { "diratime", MS_NODIRATIME, MNT_INVERT }, /* Update dir access times */
111
 
   { "nodiratime", MS_NODIRATIME },           /* Do not update dir access times */
112
 
#endif
113
 
#ifdef MS_RELATIME
114
 
   { "relatime", MS_RELATIME },               /* Update access times relative to mtime/ctime */
115
 
   { "norelatime", MS_RELATIME, MNT_INVERT }, /* Update access time without regard to mtime/ctime */
116
 
#endif
117
 
#ifdef MS_STRICTATIME
118
 
   { "strictatime", MS_STRICTATIME },         /* Strict atime semantics */
119
 
   { "nostrictatime", MS_STRICTATIME, MNT_INVERT }, /* kernel default atime */
120
 
#endif
121
 
   { NULL, 0, 0 }
122
 
};
123
 
 
124
 
/*
125
 
 * userspace mount option (built-in MNT_USERSPACE_MAP)
126
 
 *
127
 
 * TODO: offset=, sizelimit=, encryption=, vfs=
128
 
 */
129
 
static const struct libmnt_optmap userspace_opts_map[] =
130
 
{
131
 
   { "defaults", 0, 0 },               /* default options */
132
 
 
133
 
   { "auto",    MNT_MS_NOAUTO, MNT_INVERT | MNT_NOMTAB },  /* Can be mounted using -a */
134
 
   { "noauto",  MNT_MS_NOAUTO, MNT_NOMTAB },               /* Can  only be mounted explicitly */
135
 
 
136
 
   { "user[=]", MNT_MS_USER },                           /* Allow ordinary user to mount (mtab) */
137
 
   { "nouser",  MNT_MS_USER, MNT_INVERT | MNT_NOMTAB },    /* Forbid ordinary user to mount */
138
 
 
139
 
   { "users",   MNT_MS_USERS, MNT_NOMTAB },                /* Allow ordinary users to mount */
140
 
   { "nousers", MNT_MS_USERS, MNT_INVERT | MNT_NOMTAB },   /* Forbid ordinary users to mount */
141
 
 
142
 
   { "owner",   MNT_MS_OWNER, MNT_NOMTAB },                /* Let the owner of the device mount */
143
 
   { "noowner", MNT_MS_OWNER, MNT_INVERT | MNT_NOMTAB },   /* Device owner has no special privs */
144
 
 
145
 
   { "group",   MNT_MS_GROUP, MNT_NOMTAB },                /* Let the group of the device mount */
146
 
   { "nogroup", MNT_MS_GROUP, MNT_INVERT | MNT_NOMTAB },   /* Device group has no special privs */
147
 
 
148
 
   { "_netdev", MNT_MS_NETDEV },                           /* Device requires network */
149
 
 
150
 
   { "comment=", MNT_MS_COMMENT, MNT_NOMTAB },           /* fstab comment only */
151
 
 
152
 
   { "loop[=]", MNT_MS_LOOP },                           /* use the loop device */
153
 
 
154
 
   { "nofail",  MNT_MS_NOFAIL, MNT_NOMTAB },               /* Do not fail if ENOENT on dev */
155
 
 
156
 
   { "uhelper=", MNT_MS_UHELPER },                         /* /sbin/umount.<helper> */
157
 
 
158
 
   { NULL, 0, 0 }
159
 
};
160
 
 
161
 
/**
162
 
 * mnt_get_builtin_map:
163
 
 * @id: map id -- MNT_LINUX_MAP or MNT_USERSPACE_MAP
164
 
 *
165
 
 * MNT_LINUX_MAP - Linux kernel fs-independent mount options
166
 
 *                 (usually MS_* flags, see linux/fs.h)
167
 
 *
168
 
 * MNT_USERSPACE_MAP - userpace mount(8) specific mount options
169
 
 *                     (e.g user=, _netdev, ...)
170
 
 *
171
 
 * Returns: static built-in libmount map.
172
 
 */
173
 
const struct libmnt_optmap *mnt_get_builtin_optmap(int id)
174
 
{
175
 
        assert(id);
176
 
 
177
 
        if (id == MNT_LINUX_MAP)
178
 
                return linux_flags_map;
179
 
        else if (id == MNT_USERSPACE_MAP)
180
 
                return userspace_opts_map;
181
 
        return NULL;
182
 
}
183
 
 
184
 
/*
185
 
 * Lookups for the @name in @maps and returns a map and in @mapent
186
 
 * returns the map entry
187
 
 */
188
 
const struct libmnt_optmap *mnt_optmap_get_entry(
189
 
                                struct libmnt_optmap const **maps,
190
 
                                int nmaps,
191
 
                                const char *name,
192
 
                                size_t namelen,
193
 
                                const struct libmnt_optmap **mapent)
194
 
{
195
 
        int i;
196
 
 
197
 
        assert(maps);
198
 
        assert(nmaps);
199
 
        assert(name);
200
 
        assert(namelen);
201
 
 
202
 
        if (mapent)
203
 
                *mapent = NULL;
204
 
 
205
 
        for (i = 0; i < nmaps; i++) {
206
 
                const struct libmnt_optmap *map = maps[i];
207
 
                const struct libmnt_optmap *ent;
208
 
                const char *p;
209
 
 
210
 
                for (ent = map; ent && ent->name; ent++) {
211
 
                        if (strncmp(ent->name, name, namelen))
212
 
                                continue;
213
 
                        p = ent->name + namelen;
214
 
                        if (*p == '\0' || *p == '=' || *p == '[') {
215
 
                                if (mapent)
216
 
                                        *mapent = ent;
217
 
                                return map;
218
 
                        }
219
 
                }
220
 
        }
221
 
        return NULL;
222
 
}
223