blob: fb54fe68d135efa9c8c114848396ced0e3e05d0f [file] [log] [blame]
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -07001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/*
18** mountd main program
19*/
20
21#include "mountd.h"
22
23#include <cutils/config_utils.h>
24#include <cutils/cpu_info.h>
25#include <cutils/properties.h>
26
27#include <sys/mount.h>
28#include <stdio.h>
29#include <stdlib.h>
30#include <string.h>
31#include <unistd.h>
32
33#include <linux/capability.h>
34#include <linux/prctl.h>
35
36#include <private/android_filesystem_config.h>
37
38#ifdef MOUNTD_LOG
39FILE* logFile;
40#endif
41
42
43static void ReadConfigFile(const char* path)
44{
45 cnode* root = config_node("", "");
46 cnode* node;
47
48 config_load_file(root, path);
49 node = root->first_child;
50
51 while (node)
52 {
53 if (strcmp(node->name, "mount") == 0)
54 {
55 const char* block_device = NULL;
56 const char* mount_point = NULL;
57 boolean enable_ums = false;
58 cnode* child = node->first_child;
59
60 while (child)
61 {
62 const char* name = child->name;
63 const char* value = child->value;
64
65 if (strcmp(name, "block_device") == 0)
66 block_device = value;
67 else if (strcmp(name, "mount_point") == 0)
68 mount_point = value;
69 else if (strcmp(name, "enable_ums") == 0 &&
70 strcmp(value, "true") == 0)
71 enable_ums = true;
72
73 child = child->next;
74 }
75
76 // mount point and removable fields are optional
77 if (block_device && mount_point)
78 {
79 AddMountPoint(block_device, mount_point, enable_ums);
80 }
81 }
82
83 node = node->next;
84 }
85}
86
87int main(int argc, char* argv[])
88{
89 const char* configPath = "/system/etc/mountd.conf";
90 int i;
91
92 for (i = 1; i < argc; i++)
93 {
94 const char* arg = argv[i];
95
96 if (strcmp(arg, "-f") == 0)
97 {
98 if (i < argc - 1)
99 configPath = argv[++i];
100 }
101 }
102
103 ReadConfigFile(configPath);
104 StartAutoMounter();
105 return RunServer();
106}