system/vold
Révision | eac9c08a5392535f9eafb65c922344e4ccc29466 (tree) |
---|---|
l'heure | 2010-12-16 16:18:13 |
Auteur | Chih-Wei Huang <cwhuang@linu...> |
Commiter | Chih-Wei Huang |
vold: extend the syntax of vold.fstab
Now vold.fstab can accept the following:
dev_mount sdcard /mnt/sdcard auto <devpath> // use normal DirectVolume
dev_mount sdcard /mnt/sdcard auto SDCARD=dev_node // use AutoVolume for specified device node
dev_mount sdcard /mnt/sdcard auto // use AutoVolume to mount USB/MMC/SD automatically
@@ -22,7 +22,7 @@ | ||
22 | 22 | |
23 | 23 | class AutoVolume : public DirectVolume { |
24 | 24 | public: |
25 | - AutoVolume(VolumeManager *vm, const char *label, const char *mount_point, const char *part_name); | |
25 | + AutoVolume(VolumeManager *vm, const char *label, const char *mount_point, const char *part_name = 0); | |
26 | 26 | virtual ~AutoVolume(); |
27 | 27 | |
28 | 28 | protected: |
@@ -171,22 +171,34 @@ static int process_config(VolumeManager *vm) { | ||
171 | 171 | FILE *fp; |
172 | 172 | int n = 0; |
173 | 173 | char line[255]; |
174 | - | |
175 | - if (!(fp = fopen("/etc/vold.fstab", "r"))) { | |
176 | - const char *sdcard = 0; | |
177 | - if ((fp = fopen("/proc/cmdline", "r"))) { | |
178 | - while (fscanf(fp, "%s", line) > 0) { | |
179 | - if (!strncmp(line, "SDCARD=", 7)) { | |
180 | - sdcard = line + 7; | |
181 | - break; | |
174 | + Volume *vol = 0; | |
175 | + | |
176 | + if ((fp = fopen("/proc/cmdline", "r"))) { | |
177 | + while (fscanf(fp, "%s", line) > 0) { | |
178 | + if (!strncmp(line, "SDCARD=", 7)) { | |
179 | + const char *sdcard = line + 7; | |
180 | + if (*sdcard) { | |
181 | + // FIXME: should not hardcode the label and mount_point | |
182 | + if ((vol = new AutoVolume(vm, "sdcard", "/mnt/sdcard", sdcard))) { | |
183 | + vm->addVolume(vol); | |
184 | + break; | |
185 | + } | |
182 | 186 | } |
183 | 187 | } |
184 | - fclose(fp); | |
185 | 188 | } |
186 | - // FIXME: should not hardcode the label and mount_point | |
187 | - AutoVolume *dv = new AutoVolume(vm, "sdcard", "/mnt/sdcard", sdcard); | |
188 | - vm->addVolume(dv); | |
189 | - return 0; | |
189 | + fclose(fp); | |
190 | + } | |
191 | + | |
192 | + if (!(fp = fopen("/etc/vold.fstab", "r"))) { | |
193 | + // no volume added yet, create a AutoVolume object | |
194 | + // to mount USB/MMC/SD automatically | |
195 | + if (!vol) { | |
196 | + // FIXME: should not hardcode the label and mount_point | |
197 | + vol = new AutoVolume(vm, "sdcard", "/mnt/sdcard"); | |
198 | + if (vol) | |
199 | + vm->addVolume(vol); | |
200 | + } | |
201 | + return vol ? 0 : -ENOMEM; | |
190 | 202 | } |
191 | 203 | |
192 | 204 | while(fgets(line, sizeof(line), fp)) { |
@@ -221,20 +233,28 @@ static int process_config(VolumeManager *vm) { | ||
221 | 233 | SLOGE("Error parsing partition"); |
222 | 234 | goto out_syntax; |
223 | 235 | } |
224 | - if (int idx = (strcmp(part, "auto") ? atoi(part) : -1)) { | |
225 | - dv = new DirectVolume(vm, label, mount_point, idx); | |
226 | - } else { | |
236 | + int idx = (strcmp(part, "auto") ? atoi(part) : -1); | |
237 | + if (!idx) { | |
227 | 238 | SLOGE("Partition must either be 'auto' or 1 based index instead of '%s'", part); |
228 | 239 | goto out_syntax; |
229 | 240 | } |
230 | 241 | |
242 | + const char *sdcard = 0; | |
231 | 243 | while (char *sysfs_path = strtok_r(NULL, delim, &save_ptr)) { |
244 | + if ((sdcard = strncmp(sysfs_path, "SDCARD=", 7) ? 0 : sysfs_path + 7)) | |
245 | + break; | |
246 | + if (!dv) { | |
247 | + dv = new DirectVolume(vm, label, mount_point, idx); | |
248 | + } | |
232 | 249 | if (dv->addPath(sysfs_path)) { |
233 | 250 | SLOGE("Failed to add devpath %s to volume %s", sysfs_path, |
234 | 251 | label); |
235 | 252 | goto out_fail; |
236 | 253 | } |
237 | 254 | } |
255 | + if (!dv) { | |
256 | + dv = new AutoVolume(vm, label, mount_point, sdcard); | |
257 | + } | |
238 | 258 | vm->addVolume(dv); |
239 | 259 | } else if (!strcmp(type, "map_mount")) { |
240 | 260 | } else { |