~mirabilos/klibc/master

« back to all changes in this revision

Viewing changes to utils/mount_opts.c

  • Committer: H. Peter Anvin
  • Date: 2006-05-01 00:56:02 UTC
  • Revision ID: git-v1:5dea5e01daaaff0685016f23b5cb46240f28e792
[klibc] Reorganize the standalone klibc tree to match the in-kernel tree

Right now, it's harder than it should to apply and test patches using
the standalone klibc tree.  Reorganize the standalone tree to match
the in-kernel tree.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * mount_opts.c, by rmk
3
 
 *
4
 
 * Decode mount options.
5
 
 */
6
 
#include <sys/mount.h>
7
 
#include <stdlib.h>
8
 
#include <string.h>
9
 
 
10
 
#include "mount_opts.h"
11
 
 
12
 
#define ARRAY_SIZE(x)   (sizeof(x) / sizeof(x[0]))
13
 
 
14
 
static const struct mount_opts options[] = {
15
 
        /* name         mask            set             noset           */
16
 
        { "async",      MS_SYNCHRONOUS, 0,              MS_SYNCHRONOUS  },
17
 
        { "atime",      MS_NOATIME,     0,              MS_NOATIME      },
18
 
        { "bind",       MS_TYPE,        MS_BIND,        0,              },
19
 
        { "dev",        MS_NODEV,       0,              MS_NODEV        },
20
 
        { "diratime",   MS_NODIRATIME,  0,              MS_NODIRATIME   },
21
 
        { "dirsync",    MS_DIRSYNC,     MS_DIRSYNC,     0               },
22
 
        { "exec",       MS_NOEXEC,      0,              MS_NOEXEC       },
23
 
        { "move",       MS_TYPE,        MS_MOVE,        0               },
24
 
        { "recurse",    MS_REC,         MS_REC,         0               },
25
 
        { "remount",    MS_TYPE,        MS_REMOUNT,     0               },
26
 
        { "ro",         MS_RDONLY,      MS_RDONLY,      0               },
27
 
        { "rw",         MS_RDONLY,      0,              MS_RDONLY       },
28
 
        { "suid",       MS_NOSUID,      0,              MS_NOSUID       },
29
 
        { "sync",       MS_SYNCHRONOUS, MS_SYNCHRONOUS, 0               },
30
 
        { "verbose",    MS_VERBOSE,     MS_VERBOSE,     0               },
31
 
};
32
 
 
33
 
static void add_extra_option(struct extra_opts *extra, char *s)
34
 
{
35
 
        int len = strlen(s);
36
 
        int newlen = extra->used_size + len;
37
 
 
38
 
        if (extra->str)
39
 
               len++;                   /* +1 for ',' */
40
 
 
41
 
        if (newlen >= extra->alloc_size) {
42
 
                char *new;
43
 
 
44
 
                new = realloc(extra->str, newlen + 1);  /* +1 for NUL */
45
 
                if (!new)
46
 
                        return;
47
 
 
48
 
                extra->str = new;
49
 
                extra->end = extra->str + extra->used_size;
50
 
                extra->alloc_size = newlen;
51
 
        }
52
 
 
53
 
        if (extra->used_size) {
54
 
                *extra->end = ',';
55
 
                extra->end++;
56
 
        }
57
 
        strcpy(extra->end, s);
58
 
        extra->used_size += len;
59
 
 
60
 
}
61
 
 
62
 
unsigned long
63
 
parse_mount_options(char *arg, unsigned long rwflag, struct extra_opts *extra)
64
 
{
65
 
        char *s;
66
 
 
67
 
        while ((s = strsep(&arg, ",")) != NULL) {
68
 
                char *opt = s;
69
 
                unsigned int i;
70
 
                int res, no = s[0] == 'n' && s[1] == 'o';
71
 
 
72
 
                if (no)
73
 
                        s += 2;
74
 
 
75
 
                for (i = 0, res = 1; i < ARRAY_SIZE(options); i++) {
76
 
                        res = strcmp(s, options[i].str);
77
 
 
78
 
                        if (res == 0) {
79
 
                                rwflag &= ~options[i].rwmask;
80
 
                                if (no)
81
 
                                        rwflag |= options[i].rwnoset;
82
 
                                else
83
 
                                        rwflag |= options[i].rwset;
84
 
                        }
85
 
                        if (res <= 0)
86
 
                                break;
87
 
                }
88
 
 
89
 
                if (res != 0 && s[0])
90
 
                        add_extra_option(extra, opt);
91
 
        }
92
 
 
93
 
        return rwflag;
94
 
}