2 * Copyright (C) 2008 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <sys/types.h>
28 #define LOG_TAG "Vold"
30 #include "cutils/klog.h"
31 #include "cutils/log.h"
32 #include "cutils/properties.h"
34 #include "VolumeManager.h"
35 #include "CommandListener.h"
36 #include "NetlinkManager.h"
37 #include "DirectVolume.h"
40 static int process_config(VolumeManager *vm);
41 static void coldboot(const char *path);
43 #define FSTAB_PREFIX "/fstab."
52 SLOGI("Vold 2.1 (the revenge) firing up");
54 mkdir("/dev/block/vold", 0755);
56 /* For when cryptfs checks and mounts an encrypted filesystem */
59 /* Create our singleton managers */
60 if (!(vm = VolumeManager::Instance())) {
61 SLOGE("Unable to create VolumeManager");
65 if (!(nm = NetlinkManager::Instance())) {
66 SLOGE("Unable to create NetlinkManager");
71 cl = new CommandListener();
72 vm->setBroadcaster((SocketListener *) cl);
73 nm->setBroadcaster((SocketListener *) cl);
76 SLOGE("Unable to start VolumeManager (%s)", strerror(errno));
80 if (process_config(vm)) {
81 SLOGE("Error reading configuration (%s)... continuing anyways", strerror(errno));
85 SLOGE("Unable to start NetlinkManager (%s)", strerror(errno));
89 coldboot("/sys/block");
90 // coldboot("/sys/class/switch");
93 * Now that we're up, we can respond to commands
95 if (cl->startListener()) {
96 SLOGE("Unable to start CommandListener (%s)", strerror(errno));
100 // Eventually we'll become the monitoring thread
105 SLOGI("Vold exiting");
109 static void do_coldboot(DIR *d, int lvl)
116 fd = openat(dfd, "uevent", O_WRONLY);
118 write(fd, "add\n", 4);
122 while((de = readdir(d))) {
125 if (de->d_name[0] == '.')
128 if (de->d_type != DT_DIR && lvl > 0)
131 fd = openat(dfd, de->d_name, O_RDONLY | O_DIRECTORY);
139 do_coldboot(d2, lvl + 1);
145 static void coldboot(const char *path)
147 DIR *d = opendir(path);
154 static int process_config(VolumeManager *vm)
156 char fstab_filename[PROPERTY_VALUE_MAX + sizeof(FSTAB_PREFIX)];
157 char propbuf[PROPERTY_VALUE_MAX];
162 property_get("ro.hardware", propbuf, "");
163 snprintf(fstab_filename, sizeof(fstab_filename), FSTAB_PREFIX"%s", propbuf);
165 fstab = fs_mgr_read_fstab(fstab_filename);
167 SLOGE("failed to open %s\n", fstab_filename);
171 /* Loop through entries looking for ones that vold manages */
172 for (i = 0; i < fstab->num_entries; i++) {
173 if (fs_mgr_is_voldmanaged(&fstab->recs[i])) {
174 DirectVolume *dv = NULL;
177 /* Set any flags that might be set for this volume */
178 if (fs_mgr_is_nonremovable(&fstab->recs[i])) {
179 flags |= VOL_NONREMOVABLE;
181 if (fs_mgr_is_encryptable(&fstab->recs[i])) {
182 flags |= VOL_ENCRYPTABLE;
184 /* Only set this flag if there is not an emulated sd card */
185 if (fs_mgr_is_noemulatedsd(&fstab->recs[i]) &&
186 !strcmp(fstab->recs[i].fs_type, "vfat")) {
187 flags |= VOL_PROVIDES_ASEC;
189 dv = new DirectVolume(vm, &(fstab->recs[i]), flags);
191 if (dv->addPath(fstab->recs[i].blk_device)) {
192 SLOGE("Failed to add devpath %s to volume %s",
193 fstab->recs[i].blk_device, fstab->recs[i].label);