Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/Volume.cpp b/Volume.cpp
- index 0be2e81..6fa185d 100644
- --- a/Volume.cpp
- +++ b/Volume.cpp
- @@ -44,6 +44,7 @@
- #include "VolumeManager.h"
- #include "ResponseCode.h"
- #include "Fat.h"
- +#include "Ext4.h"
- #include "Process.h"
- #include "cryptfs.h"
- @@ -289,6 +290,24 @@ bool Volume::isMountpointMounted(const char *path) {
- return false;
- }
- +int Volume::isFat32(const char *fsPath) {
- + int fd = -1;
- + int isFat = 1;
- + unsigned char bytes[3] = {0};
- +
- + if ((fd = open(fsPath, O_RDONLY)) < 0)
- + goto early_exit;
- +
- + read(fd, bytes, 3);
- + close(fd);
- +
- + if(bytes[0] != 0xeb && bytes[2] != 0x90)
- + isFat = 0;
- +
- + early_exit:
- + return isFat;
- +}
- +
- int Volume::mountVol() {
- dev_t deviceNodes[4];
- int n, i, rc = 0;
- @@ -389,25 +408,30 @@ int Volume::mountVol() {
- for (i = 0; i < n; i++) {
- char devicePath[255];
- + int deviceIsFat32;
- sprintf(devicePath, "/dev/block/vold/%d:%d", MAJOR(deviceNodes[i]),
- MINOR(deviceNodes[i]));
- - SLOGI("%s being considered for volume %s\n", devicePath, getLabel());
- + deviceIsFat32 = Volume::isFat32(devicePath);
- +
- + SLOGI("%s being considered for volume %s, fat32=%d\n", devicePath, getLabel(), deviceIsFat32);
- errno = 0;
- setState(Volume::State_Checking);
- - if (Fat::check(devicePath)) {
- - if (errno == ENODATA) {
- - SLOGW("%s does not contain a FAT filesystem\n", devicePath);
- - continue;
- + if(deviceIsFat32) {
- + if (Fat::check(devicePath)) {
- + if (errno == ENODATA) {
- + SLOGW("%s does not contain a FAT filesystem\n", devicePath);
- + continue;
- + }
- + errno = EIO;
- + /* Badness - abort the mount */
- + SLOGE("%s failed FS checks (%s)", devicePath, strerror(errno));
- + setState(Volume::State_Idle);
- + return -1;
- }
- - errno = EIO;
- - /* Badness - abort the mount */
- - SLOGE("%s failed FS checks (%s)", devicePath, strerror(errno));
- - setState(Volume::State_Idle);
- - return -1;
- }
- /*
- @@ -425,10 +449,19 @@ int Volume::mountVol() {
- // For secondary external storage we keep things locked up.
- gid = AID_MEDIA_RW;
- }
- - 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;
- +
- + if (deviceIsFat32) {
- + 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 { /* assume ext4 */
- + if (Ext4::doMount(devicePath, "/mnt/secure/staging", false, false, false)) {
- + SLOGE("%s failed to mount via Ext4 (%s)\n", devicePath, strerror(errno));
- + continue;
- + }
- }
- SLOGI("Device %s, target %s mounted @ /mnt/secure/staging", devicePath, getMountpoint());
- diff --git a/Volume.h b/Volume.h
- index c717d4d..478f95a 100644
- --- a/Volume.h
- +++ b/Volume.h
- @@ -68,6 +68,7 @@ public:
- int mountVol();
- int unmountVol(bool force, bool revert);
- int formatVol();
- + int isFat32(const char *deviceNode);
- const char *getLabel() { return mLabel; }
- const char *getMountpoint() { return mMountpoint; }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement