summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYuanQY <yuanqingyun@gmail.com>2013-07-15 17:56:35 +0800
committerGerrit Code Review <gerrit@cyanogenmod.org>2013-07-23 18:26:53 +0000
commitba6f1b71370892f1196eda84a8d8f145bbd6b2cd (patch)
treef3069097efeab7ab99b28d77b87f5b53eeb9fad3
parent07c4f0552d199ec0fd07ef275872eb184434a246 (diff)
downloadframeworks_base-ba6f1b71370892f1196eda84a8d8f145bbd6b2cd.zip
frameworks_base-ba6f1b71370892f1196eda84a8d8f145bbd6b2cd.tar.gz
frameworks_base-ba6f1b71370892f1196eda84a8d8f145bbd6b2cd.tar.bz2
android_os_FileUtils_getVolumeUUID: Fix the incorrect logical for call blkid_get_tag_value.
There are two problems in here. 1. For the function blkid_get_tag_value third parameter is should be the device, not the mount pointer, in the MediaPrivader.attachVolume, it will pass the mount path to call this function. 2. The UUID for device is hex, so call atoi is not right. I think call strtol is better than atoi. Change-Id: I76598a0993f08add3e9c7541cbc082d8d85e9af4
-rw-r--r--core/jni/android_os_FileUtils.cpp50
1 files changed, 40 insertions, 10 deletions
diff --git a/core/jni/android_os_FileUtils.cpp b/core/jni/android_os_FileUtils.cpp
index b624a0d..e088a68 100644
--- a/core/jni/android_os_FileUtils.cpp
+++ b/core/jni/android_os_FileUtils.cpp
@@ -69,28 +69,58 @@ jint android_os_FileUtils_getVolumeUUID(JNIEnv* env, jobject clazz, jstring path
const char *pathStr = env->GetStringUTFChars(path, NULL);
ALOGD("Trying to get UUID for %s \n", pathStr);
- uuid = blkid_get_tag_value(NULL, "UUID", pathStr);
+ char device[256];
+ char mount_path[256];
+ char rest[256];
+ FILE *fp;
+ char line[1024];
+ bool findDevice = false;
+ if (!(fp = fopen("/proc/mounts", "r"))) {
+ SLOGE("Error opening /proc/mounts (%s)", strerror(errno));
+ return false;
+ }
+
+ while(fgets(line, sizeof(line), fp)) {
+ line[strlen(line)-1] = '\0';
+ sscanf(line, "%255s %255s %255s\n", device, mount_path, rest);
+ if (!strcmp(mount_path, pathStr)) {
+ findDevice = true;
+ break;
+ }
+ }
+
+ fclose(fp);
+
+ if (findDevice) {
+ uuid = blkid_get_tag_value(NULL, "UUID", device);
+ } else {
+ uuid = blkid_get_tag_value(NULL, "UUID", pathStr);
+ }
if (uuid) {
ALOGD("UUID for %s is %s\n", pathStr, uuid);
- String8 s8uuid = (String8)uuid;
- size_t len = s8uuid.length();
- String8 result;
+ int len = strlen(uuid);
+ char result[len];
if (len > 0) {
- for (int i = 0; i > len; i++)
+ char * pCur = uuid;
+ int length = 0;
+ while (*pCur!='\0' && length < len)
{
- if (strncmp((const char *)s8uuid[i], (const char *)"-", 1) != 0) {
- result.append((const char *)s8uuid[i]);
+ if ((*pCur) != '-') {
+ result[length] = (*pCur);
}
+ pCur++;
+ length++;
}
- len = 0;
+ result[length] = '\0';
}
- len = result.length();
+ len = strlen(result);
if (len > 0) {
- return atoi(s8uuid);
+ char *pEnd = NULL;
+ return (int)strtol(result, &pEnd, 16);
} else {
ALOGE("Couldn't get UUID for %s\n", pathStr);
}