diff options
author | codeworkx <codeworkx@cyanogenmod.org> | 2013-01-31 14:44:16 +0000 |
---|---|---|
committer | codeworkx <codeworkx@cyanogenmod.org> | 2013-03-03 17:14:54 +0000 |
commit | fc1dcc1c50d2c6745d57dd7905c4e889a51e6af1 (patch) | |
tree | 64c13688a3e17f2b23c5df146e1704d646949275 | |
parent | 3ffe02b6d8cd244242482402632a5c1f356ecf94 (diff) | |
download | system_vold-fc1dcc1c50d2c6745d57dd7905c4e889a51e6af1.zip system_vold-fc1dcc1c50d2c6745d57dd7905c4e889a51e6af1.tar.gz system_vold-fc1dcc1c50d2c6745d57dd7905c4e889a51e6af1.tar.bz2 |
vold: use blkid to detect filesystem type
In preparation for handling ext4 partitions via vold and fuse.
Change-Id: Ibaccded63a7a293ad53f16afb80448ddd493554c
-rw-r--r-- | Android.mk | 12 | ||||
-rw-r--r-- | Volume.cpp | 82 |
2 files changed, 63 insertions, 31 deletions
@@ -23,14 +23,16 @@ common_src_files := \ common_c_includes := \ $(KERNEL_HEADERS) \ system/extras/ext4_utils \ - external/openssl/include + external/openssl/include \ + external/e2fsprogs/lib common_shared_libraries := \ libsysutils \ libcutils \ libdiskconfig \ libhardware_legacy \ - libcrypto + libcrypto \ + libext2_blkid include $(CLEAR_VARS) @@ -54,7 +56,8 @@ LOCAL_C_INCLUDES := $(common_c_includes) LOCAL_SHARED_LIBRARIES := $(common_shared_libraries) -LOCAL_STATIC_LIBRARIES := libfs_mgr +LOCAL_STATIC_LIBRARIES := \ + libfs_mgr LOCAL_MODULE_TAGS := eng tests @@ -94,7 +97,8 @@ endif LOCAL_SHARED_LIBRARIES := $(common_shared_libraries) -LOCAL_STATIC_LIBRARIES := libfs_mgr +LOCAL_STATIC_LIBRARIES := \ + libfs_mgr include $(BUILD_EXECUTABLE) @@ -36,6 +36,8 @@ #include <private/android_filesystem_config.h> +#include <blkid/blkid.h> + #define LOG_TAG "Vold" #include <cutils/log.h> @@ -51,7 +53,6 @@ extern "C" void dos_partition_dec(void const *pp, struct dos_partition *d); extern "C" void dos_partition_enc(void *pp, struct dos_partition *d); - /* * Secure directory - stuff that only root can see */ @@ -185,6 +186,22 @@ dev_t Volume::getShareDevice() { return getDiskDevice(); } +char *getFsType(const char * devicePath) { + char *fstype = NULL; + + SLOGD("Trying to get filesystem type for %s \n", devicePath); + + fstype = blkid_get_tag_value(NULL, "TYPE", devicePath); + if (fstype) { + SLOGD("Found %s filesystem on %s\n", fstype, devicePath); + } else { + SLOGE("None or unknown filesystem on %s\n", devicePath); + return NULL; + } + + return fstype; +} + void Volume::handleVolumeShared() { } @@ -432,6 +449,7 @@ int Volume::mountVol() { for (i = 0; i < n; i++) { char devicePath[255]; + char *fstype = NULL; sprintf(devicePath, "/dev/block/vold/%d:%d", MAJOR(deviceNodes[i]), MINOR(deviceNodes[i])); @@ -441,20 +459,6 @@ int Volume::mountVol() { errno = 0; setState(Volume::State_Checking); - bool isFatFs = true; - if (Fat::check(devicePath)) { - if (errno == ENODATA) { - SLOGW("%s does not contain a FAT filesystem\n", devicePath); - isFatFs = false; - } else { - errno = EIO; - /* Badness - abort the mount */ - SLOGE("%s failed FS checks (%s)", devicePath, strerror(errno)); - setState(Volume::State_Idle); - return -1; - } - } - /* * Mount the device on our internal staging mountpoint so we can * muck with it before exposing it to non priviledged users. @@ -466,20 +470,44 @@ int Volume::mountVol() { // prevented users from writing to it. We don't want that. gid = AID_SDCARD_RW; - if (isFatFs) { - if (Fat::doMount(devicePath, "/mnt/secure/staging", false, false, false, - AID_SYSTEM, gid, 0702, true)) { - SLOGE("%s failed to mount via VFAT (%s)\n", devicePath, strerror(errno)); - continue; - } - } else { - if (Ntfs::doMount(devicePath, "/mnt/secure/staging", false, false, false, - AID_SYSTEM, gid, 0702, true)) { - SLOGE("%s failed to mount via NTFS (%s)\n", devicePath, strerror(errno)); - continue; + fstype = getFsType((const char *)devicePath); + + if (fstype != NULL) { + if (strcmp(fstype, "vfat") == 0) { + + if (Fat::check(devicePath)) { + errno = EIO; + /* Badness - abort the mount */ + SLOGE("%s failed FS checks (%s)", devicePath, strerror(errno)); + setState(Volume::State_Idle); + free(fstype); + return -1; + } + + if (Fat::doMount(devicePath, "/mnt/secure/staging", false, false, false, + AID_SYSTEM, gid, 0702, true)) { + SLOGE("%s failed to mount via VFAT (%s)\n", devicePath, strerror(errno)); + continue; + } + + } else if (strcmp(fstype, "ntfs") == 0) { + + if (Ntfs::doMount(devicePath, "/mnt/secure/staging", false, false, false, + AID_SYSTEM, gid, 0702, true)) { + SLOGE("%s failed to mount via NTFS (%s)\n", devicePath, strerror(errno)); + continue; + } + + } else { + // Unsupported filesystem + errno = ENODATA; + setState(Volume::State_Idle); + free(fstype); + return -1; } - } + free(fstype); + } SLOGI("Device %s, target %s mounted @ /mnt/secure/staging", devicePath, getMountpoint()); protectFromAutorunStupidity(); |