summaryrefslogtreecommitdiff
path: root/main.cpp (plain)
blob: 6d4abae87ff7e1f9fef055c0ce54621c3e087d74
1/*
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#include "Disk.h"
18#include "VolumeManager.h"
19#include "NetlinkManager.h"
20#include "DroidVold.h"
21
22#define LOG_TAG "droidVold"
23
24#include <android-base/logging.h>
25#include <android-base/stringprintf.h>
26#include <cutils/klog.h>
27#include <cutils/properties.h>
28#include <cutils/sockets.h>
29
30#include <binder/IPCThreadState.h>
31#include <binder/ProcessState.h>
32#include <binder/IServiceManager.h>
33#include <HidlTransportSupport.h>
34
35#include <stdio.h>
36#include <stdlib.h>
37#include <errno.h>
38#include <string.h>
39#include <sys/stat.h>
40#include <sys/types.h>
41#include <getopt.h>
42#include <fcntl.h>
43#include <dirent.h>
44#include <fs_mgr.h>
45
46#include "cutils/klog.h"
47#include "cutils/log.h"
48#include "cutils/properties.h"
49
50static int process_config(VolumeManager *vm, bool* has_adoptable);
51
52static void set_media_poll_time(void);
53
54struct fstab *fstab;
55
56using namespace android;
57using ::android::base::StringPrintf;
58using ::android::hardware::configureRpcThreadpool;
59using ::android::hardware::joinRpcThreadpool;
60using ::vendor::amlogic::hardware::droidvold::V1_0::implementation::DroidVold;
61using ::vendor::amlogic::hardware::droidvold::V1_0::IDroidVold;
62using ::vendor::amlogic::hardware::droidvold::V1_0::Result;
63
64int main(int argc, char** argv) {
65 setenv("ANDROID_LOG_TAGS", "*:v", 1);
66 android::base::InitLogging(argv, android::base::LogdLogger(android::base::SYSTEM));
67
68 LOG(INFO) << "doildVold 1.0 firing up";
69
70 //android::ProcessState::initWithDriver("/dev/hwbinder");
71 configureRpcThreadpool(4, true);
72
73 VolumeManager *vm;
74 NetlinkManager *nm;
75 DroidVold *dv;
76
77 /* Create our singleton managers */
78 if (!(vm = VolumeManager::Instance())) {
79 LOG(ERROR) << "Unable to create VolumeManager";
80 exit(1);
81 }
82
83 if (!(nm = NetlinkManager::Instance())) {
84 LOG(ERROR) << "Unable to create NetlinkManager";
85 exit(1);
86 }
87
88 if (property_get_bool("droidvold.debug", false)) {
89 vm->setDebug(true);
90 }
91
92 if (!(dv= DroidVold::Instance())) {
93 LOG(ERROR) << "Unable to create DroidVold";
94 exit(1);
95 }
96
97 vm->setBroadcaster(dv);
98 nm->setBroadcaster(dv);
99
100 if (vm->start()) {
101 PLOG(ERROR) << "Unable to start VolumeManager";
102 exit(1);
103 }
104
105 bool has_adoptable;
106
107 if (process_config(vm, &has_adoptable)) {
108 PLOG(ERROR) << "Error reading configuration... continuing anyways";
109 }
110
111 if (nm->start()) {
112 PLOG(ERROR) << "Unable to start NetlinkManager";
113 exit(1);
114 }
115
116 sp<IDroidVold> idv = DroidVold::Instance();
117 if (idv == nullptr)
118 ALOGE("Cannot create IDroidVold service");
119 else if (idv->registerAsService() != OK)
120 ALOGE("Cannot register IDroidVold service.");
121 else
122 ALOGI("IDroidVold service created.");
123
124 set_media_poll_time();
125 vm->coldboot("/sys/block");
126
127 /*
128 * This thread is just going to process Binder transactions.
129 */
130 joinRpcThreadpool();
131
132 LOG(ERROR) << "droidVold exiting";
133 exit(0);
134}
135
136static void set_media_poll_time(void) {
137 int fd;
138
139 fd = open ("/sys/module/block/parameters/events_dfl_poll_msecs", O_WRONLY);
140 if (fd >= 0) {
141 write(fd, "2000", 4);
142 close (fd);
143 } else {
144 LOG(ERROR) << "kernel not support media poll uevent!";
145 }
146}
147
148static int process_config(VolumeManager *vm, bool* has_adoptable) {
149 std::string path(android::droidvold::DefaultFstabPath());
150 fstab = fs_mgr_read_fstab(path.c_str());
151 if (!fstab) {
152 PLOG(ERROR) << "Failed to open default fstab " << path;
153 return -1;
154 }
155
156 /* Loop through entries looking for ones that vold manages */
157 *has_adoptable = false;
158 for (int i = 0; i < fstab->num_entries; i++) {
159 if (fs_mgr_is_voldmanaged(&fstab->recs[i])) {
160 if (fs_mgr_is_nonremovable(&fstab->recs[i])) {
161 LOG(WARNING) << "nonremovable no longer supported; ignoring volume";
162 continue;
163 }
164
165 std::string sysPattern(fstab->recs[i].blk_device);
166 std::string nickname(fstab->recs[i].label);
167 int flags = 0;
168
169 if (fs_mgr_is_encryptable(&fstab->recs[i])) {
170 flags |= android::droidvold::Disk::Flags::kAdoptable;
171 *has_adoptable = true;
172 }
173 if (fs_mgr_is_noemulatedsd(&fstab->recs[i])
174 || property_get_bool("vold.debug.default_primary", false)) {
175 flags |= android::droidvold::Disk::Flags::kDefaultPrimary;
176 }
177
178 vm->addDiskSource(std::shared_ptr<VolumeManager::DiskSource>(
179 new VolumeManager::DiskSource(sysPattern, nickname, flags)));
180 }
181 }
182 return 0;
183}
184