system/vold
Revisión | b8937899cd7af91c16db6a805ef264f203c97a2a (tree) |
---|---|
Tiempo | 2011-08-04 18:25:10 |
Autor | 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: |
@@ -145,22 +145,34 @@ static int process_config(VolumeManager *vm) { | ||
145 | 145 | FILE *fp; |
146 | 146 | int n = 0; |
147 | 147 | char line[255]; |
148 | - | |
149 | - if (!(fp = fopen("/etc/vold.fstab", "r"))) { | |
150 | - const char *sdcard = 0; | |
151 | - if ((fp = fopen("/proc/cmdline", "r"))) { | |
152 | - while (fscanf(fp, "%s", line) > 0) { | |
153 | - if (!strncmp(line, "SDCARD=", 7)) { | |
154 | - sdcard = line + 7; | |
155 | - break; | |
148 | + Volume *vol = 0; | |
149 | + | |
150 | + if ((fp = fopen("/proc/cmdline", "r"))) { | |
151 | + while (fscanf(fp, "%s", line) > 0) { | |
152 | + if (!strncmp(line, "SDCARD=", 7)) { | |
153 | + const char *sdcard = line + 7; | |
154 | + if (*sdcard) { | |
155 | + // FIXME: should not hardcode the label and mount_point | |
156 | + if ((vol = new AutoVolume(vm, "sdcard", "/mnt/sdcard", sdcard))) { | |
157 | + vm->addVolume(vol); | |
158 | + break; | |
159 | + } | |
156 | 160 | } |
157 | 161 | } |
158 | - fclose(fp); | |
159 | 162 | } |
160 | - // FIXME: should not hardcode the label and mount_point | |
161 | - AutoVolume *dv = new AutoVolume(vm, "sdcard", "/mnt/sdcard", sdcard); | |
162 | - vm->addVolume(dv); | |
163 | - return 0; | |
163 | + fclose(fp); | |
164 | + } | |
165 | + | |
166 | + if (!(fp = fopen("/etc/vold.fstab", "r"))) { | |
167 | + // no volume added yet, create a AutoVolume object | |
168 | + // to mount USB/MMC/SD automatically | |
169 | + if (!vol) { | |
170 | + // FIXME: should not hardcode the label and mount_point | |
171 | + vol = new AutoVolume(vm, "sdcard", "/mnt/sdcard"); | |
172 | + if (vol) | |
173 | + vm->addVolume(vol); | |
174 | + } | |
175 | + return vol ? 0 : -ENOMEM; | |
164 | 176 | } |
165 | 177 | |
166 | 178 | while(fgets(line, sizeof(line), fp)) { |
@@ -195,20 +207,28 @@ static int process_config(VolumeManager *vm) { | ||
195 | 207 | SLOGE("Error parsing partition"); |
196 | 208 | goto out_syntax; |
197 | 209 | } |
198 | - if (int idx = (strcmp(part, "auto") ? atoi(part) : -1)) { | |
199 | - dv = new DirectVolume(vm, label, mount_point, idx); | |
200 | - } else { | |
210 | + int idx = (strcmp(part, "auto") ? atoi(part) : -1); | |
211 | + if (!idx) { | |
201 | 212 | SLOGE("Partition must either be 'auto' or 1 based index instead of '%s'", part); |
202 | 213 | goto out_syntax; |
203 | 214 | } |
204 | 215 | |
216 | + const char *sdcard = 0; | |
205 | 217 | while (char *sysfs_path = strtok_r(NULL, delim, &save_ptr)) { |
218 | + if ((sdcard = strncmp(sysfs_path, "SDCARD=", 7) ? 0 : sysfs_path + 7)) | |
219 | + break; | |
220 | + if (!dv) { | |
221 | + dv = new DirectVolume(vm, label, mount_point, idx); | |
222 | + } | |
206 | 223 | if (dv->addPath(sysfs_path)) { |
207 | 224 | SLOGE("Failed to add devpath %s to volume %s", sysfs_path, |
208 | 225 | label); |
209 | 226 | goto out_fail; |
210 | 227 | } |
211 | 228 | } |
229 | + if (!dv) { | |
230 | + dv = new AutoVolume(vm, label, mount_point, sdcard); | |
231 | + } | |
212 | 232 | vm->addVolume(dv); |
213 | 233 | } else if (!strcmp(type, "map_mount")) { |
214 | 234 | } else { |