Advertisement
Guest User

Untitled

a guest
Jun 30th, 2013
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.73 KB | None | 0 0
  1. diff --git a/Volume.cpp b/Volume.cpp
  2. index 0be2e81..6fa185d 100644
  3. --- a/Volume.cpp
  4. +++ b/Volume.cpp
  5. @@ -44,6 +44,7 @@
  6. #include "VolumeManager.h"
  7. #include "ResponseCode.h"
  8. #include "Fat.h"
  9. +#include "Ext4.h"
  10. #include "Process.h"
  11. #include "cryptfs.h"
  12.  
  13. @@ -289,6 +290,24 @@ bool Volume::isMountpointMounted(const char *path) {
  14. return false;
  15. }
  16.  
  17. +int Volume::isFat32(const char *fsPath) {
  18. + int fd = -1;
  19. + int isFat = 1;
  20. + unsigned char bytes[3] = {0};
  21. +
  22. + if ((fd = open(fsPath, O_RDONLY)) < 0)
  23. + goto early_exit;
  24. +
  25. + read(fd, bytes, 3);
  26. + close(fd);
  27. +
  28. + if(bytes[0] != 0xeb && bytes[2] != 0x90)
  29. + isFat = 0;
  30. +
  31. + early_exit:
  32. + return isFat;
  33. +}
  34. +
  35. int Volume::mountVol() {
  36. dev_t deviceNodes[4];
  37. int n, i, rc = 0;
  38. @@ -389,25 +408,30 @@ int Volume::mountVol() {
  39.  
  40. for (i = 0; i < n; i++) {
  41. char devicePath[255];
  42. + int deviceIsFat32;
  43.  
  44. sprintf(devicePath, "/dev/block/vold/%d:%d", MAJOR(deviceNodes[i]),
  45. MINOR(deviceNodes[i]));
  46.  
  47. - SLOGI("%s being considered for volume %s\n", devicePath, getLabel());
  48. + deviceIsFat32 = Volume::isFat32(devicePath);
  49. +
  50. + SLOGI("%s being considered for volume %s, fat32=%d\n", devicePath, getLabel(), deviceIsFat32);
  51.  
  52. errno = 0;
  53. setState(Volume::State_Checking);
  54.  
  55. - if (Fat::check(devicePath)) {
  56. - if (errno == ENODATA) {
  57. - SLOGW("%s does not contain a FAT filesystem\n", devicePath);
  58. - continue;
  59. + if(deviceIsFat32) {
  60. + if (Fat::check(devicePath)) {
  61. + if (errno == ENODATA) {
  62. + SLOGW("%s does not contain a FAT filesystem\n", devicePath);
  63. + continue;
  64. + }
  65. + errno = EIO;
  66. + /* Badness - abort the mount */
  67. + SLOGE("%s failed FS checks (%s)", devicePath, strerror(errno));
  68. + setState(Volume::State_Idle);
  69. + return -1;
  70. }
  71. - errno = EIO;
  72. - /* Badness - abort the mount */
  73. - SLOGE("%s failed FS checks (%s)", devicePath, strerror(errno));
  74. - setState(Volume::State_Idle);
  75. - return -1;
  76. }
  77.  
  78. /*
  79. @@ -425,10 +449,19 @@ int Volume::mountVol() {
  80. // For secondary external storage we keep things locked up.
  81. gid = AID_MEDIA_RW;
  82. }
  83. - if (Fat::doMount(devicePath, "/mnt/secure/staging", false, false, false,
  84. - AID_SYSTEM, gid, 0702, true)) {
  85. - SLOGE("%s failed to mount via VFAT (%s)\n", devicePath, strerror(errno));
  86. - continue;
  87. +
  88. + if (deviceIsFat32) {
  89. + if (Fat::doMount(devicePath, "/mnt/secure/staging", false, false, false,
  90. + AID_SYSTEM, gid, 0702, true)) {
  91. + SLOGE("%s failed to mount via VFAT (%s)\n", devicePath, strerror(errno));
  92. + continue;
  93. + }
  94. + }
  95. + else { /* assume ext4 */
  96. + if (Ext4::doMount(devicePath, "/mnt/secure/staging", false, false, false)) {
  97. + SLOGE("%s failed to mount via Ext4 (%s)\n", devicePath, strerror(errno));
  98. + continue;
  99. + }
  100. }
  101.  
  102. SLOGI("Device %s, target %s mounted @ /mnt/secure/staging", devicePath, getMountpoint());
  103. diff --git a/Volume.h b/Volume.h
  104. index c717d4d..478f95a 100644
  105. --- a/Volume.h
  106. +++ b/Volume.h
  107. @@ -68,6 +68,7 @@ public:
  108. int mountVol();
  109. int unmountVol(bool force, bool revert);
  110. int formatVol();
  111. + int isFat32(const char *deviceNode);
  112.  
  113. const char *getLabel() { return mLabel; }
  114. const char *getMountpoint() { return mMountpoint; }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement