summaryrefslogtreecommitdiffstats
path: root/core/jni/android_os_FileUtils.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/jni/android_os_FileUtils.cpp')
-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);
}