-
Notifications
You must be signed in to change notification settings - Fork 2
/
0001-vold-switchable-pair.patch
115 lines (101 loc) · 3.88 KB
/
0001-vold-switchable-pair.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
From 8a4f1fb196fa5160485eb246035f1dd5691bd620 Mon Sep 17 00:00:00 2001
From: Ricardo Cerqueira <cyanogenmod@cerqueira.org>
Date: Fri, 19 Aug 2011 18:42:27 +0100
Subject: [PATCH] vold: Allow pre-configured device pairs to switch mountpoints
The use-case for this are devices with internal extended storage
(pseudo-SDCard emmc) and an actual microSD card reader.
In CM, we choose to use the microSD as primary storage, and leave
the internal partition mostly unused; some users usually come up with
imaginative and data-destroying ways of working around that.
This allows us to specify a pair of mountpoints which can be
switched from a user preference. For this vold.fstab:
-----
dev_mount sdcard /mnt/sdcard ...<path-to-microSD-sysfs>
dev_mount emmc /mnt/emmc ...<path-to-emmc-partition>
-----
We can add to build.prop:
"ro.vold.switchablepair=/mnt/sdcard,/mnt/emmc"
A persistent toggle (persist.sys.vold.switchexternal), controllable
through CMParts, can be presented to the user to allow choosing
something other than our default as primary storage.
Updated to 4.4 by @Dazzozo.
Change-Id: I9559fa442c833e3168287d820b7b8347736abb15
---
DirectVolume.cpp | 38 ++++++++++++++++++++++++++++++++++++++
DirectVolume.h | 4 ++--
2 files changed, 40 insertions(+), 2 deletions(-)
diff --git a/DirectVolume.cpp b/DirectVolume.cpp
index 57dc555..b176d15 100644
--- a/DirectVolume.cpp
+++ b/DirectVolume.cpp
@@ -24,6 +24,7 @@
#define LOG_TAG "DirectVolume"
#include <cutils/log.h>
+#include <cutils/properties.h>
#include <sysutils/NetlinkEvent.h>
#include "DirectVolume.h"
@@ -35,6 +36,7 @@
DirectVolume::DirectVolume(VolumeManager *vm, const fstab_rec* rec, int flags) :
Volume(vm, rec, flags) {
+ char switchable[PROPERTY_VALUE_MAX];
mPaths = new PathCollection();
for (int i = 0; i < MAX_PARTITIONS; i++)
mPartMinors[i] = -1;
@@ -62,6 +64,42 @@ DirectVolume::DirectVolume(VolumeManager *vm, const fstab_rec* rec, int flags) :
mMountpoint = strdup(mount);
snprintf(mount, PATH_MAX, "%s/%s", Volume::FUSE_DIR, rec->label);
mFuseMountpoint = strdup(mount);
+
+ property_get("persist.sys.vold.switchexternal", switchable, "0");
+ if (!strcmp(switchable,"1")) {
+ char *first, *second = NULL;
+ char label[PATH_MAX];
+ const char *delim = ",";
+ int lblidx = strlen(Volume::FUSE_DIR) + 1;
+ bool swap = true;
+
+ property_get("ro.vold.switchablepair", switchable, "");
+
+ if (!(first = strtok(switchable, delim))) {
+ SLOGE("Mount switch requested, but no switchable mountpoints found");
+ swap = false;
+ } else if (!(second = strtok(NULL, delim))) {
+ SLOGE("Mount switch requested, but bad switchable mountpoints found");
+ swap = false;
+ }
+
+ if (swap) {
+ free(mMountpoint);
+ free(mFuseMountpoint);
+
+ if (!strcmp(mount,first)) {
+ mFuseMountpoint = strdup(second);
+ strcpy(label, second+lblidx);
+ snprintf(second, PATH_MAX, "%s/%s", Volume::MEDIA_DIR, label);
+ mMountpoint = strdup(second);
+ } else if (!strcmp(mount,second)) {
+ mFuseMountpoint = strdup(first);
+ strcpy(label, first+lblidx);
+ snprintf(first, PATH_MAX, "%s/%s", Volume::MEDIA_DIR, label);
+ mMountpoint = strdup(first);
+ }
+ }
+ }
#endif
setState(Volume::State_NoMedia);
diff --git a/DirectVolume.h b/DirectVolume.h
index 396ac91..8b6e9a8 100644
--- a/DirectVolume.h
+++ b/DirectVolume.h
@@ -31,8 +31,8 @@ class DirectVolume : public Volume {
public:
static const int MAX_PARTITIONS = VOLD_MAX_PARTITIONS;
protected:
- const char* mMountpoint;
- const char* mFuseMountpoint;
+ char* mMountpoint;
+ char* mFuseMountpoint;
PathCollection *mPaths;
int mDiskMajor;
--
1.8.1.2