Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff -ru .system.old/vold.old/DirectVolume.cpp system/vold/DirectVolume.cpp
- --- .system.old/vold.old/DirectVolume.cpp 2013-12-21 13:36:04.000000000 +0100
- +++ system/vold/DirectVolume.cpp 2013-12-22 01:21:55.321891444 +0100
- @@ -31,7 +31,7 @@
- #include "ResponseCode.h"
- #include "cryptfs.h"
- -// #define PARTITION_DEBUG
- +#define PARTITION_DEBUG
- DirectVolume::DirectVolume(VolumeManager *vm, const char *label,
- const char *mount_point, int partIdx) :
- diff -ru .system.old/vold.old/Ext4.cpp system/vold/Ext4.cpp
- --- .system.old/vold.old/Ext4.cpp 2013-12-21 13:36:04.000000000 +0100
- +++ system/vold/Ext4.cpp 2013-12-21 21:47:15.058638366 +0100
- @@ -40,7 +40,8 @@
- #include "Ext4.h"
- -#define MKEXT4FS_PATH "/system/bin/make_ext4fs";
- +static char E2FSCK_PATH[] = "/system/bin/e2fsck";
- +static char MKEXT4FS_PATH[] = "/system/bin/make_ext4fs";
- extern "C" int logwrap(int argc, const char **argv, int background);
- @@ -67,6 +68,50 @@
- return rc;
- }
- +int Ext4::check(const char *fsPath) {
- + bool rw = true;
- + if (access(E2FSCK_PATH, X_OK)) {
- + SLOGW("Skipping fs checks.\n");
- + return 0;
- + }
- +
- + int rc = -1;
- + do {
- + const char *args[5];
- + args[0] = E2FSCK_PATH;
- + args[1] = "-p";
- + args[2] = "-f";
- + args[3] = fsPath;
- + args[4] = NULL;
- +
- + rc = logwrap(4, args, 1);
- +
- + switch(rc) {
- + case 0:
- + SLOGI("EXT4 Filesystem check completed OK.\n");
- + return 0;
- + case 1:
- + SLOGI("EXT4 Filesystem check completed, errors corrected OK.\n");
- + return 0;
- + case 2:
- + SLOGE("EXT4 Filesystem check completed, errors corrected, need reboot.\n");
- + return 0;
- + case 4:
- + SLOGE("EXT4 Filesystem errors left uncorrected.\n");
- + return 0;
- + case 8:
- + SLOGE("E2FSCK Operational error.\n");
- + errno = EIO;
- + return -1;
- + default:
- + SLOGE("EXT4 Filesystem check failed (unknown exit code %d).\n", rc);
- + errno = EIO;
- + return -1;
- + }
- + } while (0);
- + return 0;
- +}
- +
- int Ext4::format(const char *fsPath) {
- int fd;
- const char *args[4];
- diff -ru .system.old/vold.old/Ext4.h system/vold/Ext4.h
- --- .system.old/vold.old/Ext4.h 2013-12-21 13:36:04.000000000 +0100
- +++ system/vold/Ext4.h 2013-12-21 21:47:44.191971531 +0100
- @@ -23,6 +23,7 @@
- public:
- static int doMount(const char *fsPath, const char *mountPoint, bool ro, bool remount,
- bool executable);
- + static int check(const char *fsPath);
- static int format(const char *fsPath);
- };
- diff -ru .system.old/vold.old/Volume.cpp system/vold/Volume.cpp
- --- .system.old/vold.old/Volume.cpp 2013-12-21 13:36:04.000000000 +0100
- +++ system/vold/Volume.cpp 2013-12-22 10:03:00.985029967 +0100
- @@ -43,10 +43,25 @@
- #include "Volume.h"
- #include "VolumeManager.h"
- #include "ResponseCode.h"
- +#include "Ext4.h"
- #include "Fat.h"
- #include "Process.h"
- #include "cryptfs.h"
- +
- +#ifndef FUSE_SDCARD_UID
- +#define FUSE_SDCARD_UID 1023
- +#endif
- +#ifndef FUSE_SDCARD_GID
- +#define FUSE_SDCARD_GID 1023
- +#endif
- +
- +// Stringify defined values
- +#define DO_STRINGIFY(str) #str
- +#define STRINGIFY(str) DO_STRINGIFY(str)
- +
- +static char SDCARD_DAEMON_PATH[] = "/system/bin/sdcard";
- +
- 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);
- @@ -87,6 +102,12 @@
- */
- const char *Volume::LOOPDIR = "/mnt/obb";
- +/*
- + * Path for fuse
- + */
- +const char *Volume::FUSEDIR = "/mnt/obb";
- +
- +
- static const char *stateToStr(int state) {
- if (state == Volume::State_Init)
- return "Initializing";
- @@ -290,6 +311,7 @@
- }
- int Volume::mountVol() {
- + SLOGI("Volume::mountVol called");
- dev_t deviceNodes[4];
- int n, i, rc = 0;
- char errmsg[255];
- @@ -389,6 +411,9 @@
- for (i = 0; i < n; i++) {
- char devicePath[255];
- + bool isUnixFs = false;
- + bool isFAT = false;
- + bool isEXT4 = false;
- sprintf(devicePath, "/dev/block/vold/%d:%d", MAJOR(deviceNodes[i]),
- MINOR(deviceNodes[i]));
- @@ -401,13 +426,36 @@
- if (Fat::check(devicePath)) {
- if (errno == ENODATA) {
- SLOGW("%s does not contain a FAT filesystem\n", devicePath);
- - continue;
- + if (Ext4::check(devicePath)) {
- + // EXT4 failed
- + if (errno == ENODATA) {
- + SLOGW("%s does not contain a EXT4 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;
- + } else {
- + // EXT4 found
- + SLOGI("%s (%s) detected as EXT4 volume\n", devicePath, getLabel());
- + isUnixFs = true;
- + isEXT4 = true;
- + errno = 0;
- + }
- + } else {
- + errno = EIO;
- + /* Badness - abort the mount */
- + SLOGE("%s failed FS checks (%s)", devicePath, strerror(errno));
- + setState(Volume::State_Idle);
- + // FAT failed
- + return -1;
- }
- - errno = EIO;
- - /* Badness - abort the mount */
- - SLOGE("%s failed FS checks (%s)", devicePath, strerror(errno));
- - setState(Volume::State_Idle);
- - return -1;
- + } else {
- + // FAT found
- + isFAT = true;
- + isUnixFs = false;
- }
- /*
- @@ -425,9 +473,21 @@
- // 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));
- +
- +
- + if (isFAT) {
- + 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 (isEXT4) {
- + if (Ext4::doMount(devicePath, "/mnt/secure/staging", false, false, false)) {
- + SLOGE("%s failed to mount via EXT4 (%s)\n", devicePath, strerror(errno));
- + continue;
- + }
- + } else {
- + SLOGE("%s has unknown filesystem\n", devicePath);
- continue;
- }
- @@ -447,12 +507,66 @@
- * Now that the bindmount trickery is done, atomically move the
- * whole subtree to expose it to non priviledged users.
- */
- - if (doMoveMount("/mnt/secure/staging", getMountpoint(), false)) {
- - SLOGE("Failed to move mount (%s)", strerror(errno));
- - umount("/mnt/secure/staging");
- - setState(Volume::State_Idle);
- - return -1;
- + if (isUnixFs) {
- + /*
- + * In case of a unix filesystem we're using the sdcard daemon
- + * to expose the subtree to non privileged users to avoid
- + * permission issues for data created by apps.
- + */
- +
- + const char* label = getLabel();
- + char* fuseSrc = (char*) malloc(strlen(FUSEDIR) + strlen("/") + strlen(label) + 1);
- + sprintf(fuseSrc, "%s/%s", FUSEDIR, label);
- + bool failed = false;
- +
- + // Create fuse dir if not exists
- + if (access(fuseSrc, R_OK | W_OK)) {
- + if (mkdir(fuseSrc, 0775)) {
- + SLOGE("Failed to create %s (%s)", fuseSrc, strerror(errno));
- + failed = true;
- + }
- + }
- +
- + // Move subtree to fuse dir
- + if (!failed && doMoveMount("/mnt/secure/staging", fuseSrc, false)) {
- + SLOGE("Failed to move mount (%s)", strerror(errno));
- + umount("/mnt/secure/staging");
- + failed = true;
- + }
- +
- + // Set owner and group on fuse dir
- + if (!failed && chown(fuseSrc, FUSE_SDCARD_UID, FUSE_SDCARD_GID)) {
- + SLOGE("Failed to set owner/group on %s (%s)", fuseSrc, strerror(errno));
- + failed = true;
- + }
- +
- + // Set permissions (775) on fuse dir
- + if (!failed && chmod(fuseSrc, S_IRWXU|S_IRWXG|S_IROTH|S_IXOTH)) {
- + SLOGE("Failed to set permissions on %s (%s)", fuseSrc, strerror(errno));
- + failed = true;
- + }
- +
- + // Invoke the sdcard daemon to expose it
- + if(!failed && doFuseMount(fuseSrc, getMountpoint())) {
- + SLOGE("Failed to fuse mount (%s) -> (%s)", fuseSrc, getMountpoint());
- + failed = true;
- + }
- +
- + free(fuseSrc);
- +
- + if (failed) {
- + setState(Volume::State_Idle);
- + return -1;
- + }
- + } else {
- + if (doMoveMount("/mnt/secure/staging", getMountpoint(), false)) {
- + SLOGE("Failed to move mount (%s)", strerror(errno));
- + umount("/mnt/secure/staging");
- + setState(Volume::State_Idle);
- + return -1;
- + }
- }
- +
- setState(Volume::State_Mounted);
- mCurrentlyMountedKdev = deviceNodes[i];
- return 0;
- @@ -561,6 +675,27 @@
- return -1;
- }
- +int Volume::doFuseMount(const char *src, const char *dst) {
- + if (access(SDCARD_DAEMON_PATH, X_OK)) {
- + SLOGE("Can't invoke sdcard daemon.\n");
- + return -1;
- + }
- + const char* const args[] = { "sdcard", src, dst, STRINGIFY(FUSE_SDCARD_UID), STRINGIFY(FUSE_SDCARD_GID), NULL };
- + pid_t fusePid;
- +
- + fusePid=fork();
- +
- + if (fusePid == 0) {
- + SLOGW("Invoking sdcard daemon (%s) -> (%s)", src, dst);
- + if (execv(SDCARD_DAEMON_PATH, (char* const*)args) == -1) {
- + SLOGE("Failed to invoke the sdcard daemon!");
- + return -1;
- + }
- + }
- +
- + return 0;
- +}
- +
- int Volume::doUnmount(const char *path, bool force) {
- int retries = 10;
- @@ -597,6 +732,9 @@
- int Volume::unmountVol(bool force, bool revert) {
- int i, rc;
- + const char* label = getLabel();
- + char* fuseSrc = (char*) malloc(strlen(FUSEDIR) + strlen("/") + strlen(label) + 1);
- + sprintf(fuseSrc, "%s/%s", FUSEDIR, label);
- if (getState() != Volume::State_Mounted) {
- SLOGE("Volume %s unmount request when not mounted", getLabel());
- @@ -626,7 +764,7 @@
- SLOGE("Failed to unmount tmpfs on %s (%s)", secure_dir, strerror(errno));
- goto fail_republish;
- }
- -
- +
- /*
- * Finally, unmount the actual block device from the staging dir
- */
- @@ -635,6 +773,16 @@
- goto fail_recreate_bindmount;
- }
- + /*
- + * Unmount the actual block device from fuse dir if exists
- + */
- + if (!access(fuseSrc, R_OK | W_OK)) {
- + if (doUnmount(fuseSrc, force)) {
- + SLOGE("Failed to unmount %s (%s)", fuseSrc, strerror(errno));
- + goto out_nomedia;
- + }
- + }
- +
- SLOGI("%s unmounted sucessfully", getMountpoint());
- /* If this is an encrypted volume, and we've been asked to undo
- @@ -649,6 +797,7 @@
- setState(Volume::State_Idle);
- mCurrentlyMountedKdev = -1;
- + free(fuseSrc);
- return 0;
- /*
- @@ -675,6 +824,7 @@
- out_nomedia:
- setState(Volume::State_NoMedia);
- + free(fuseSrc);
- return -1;
- }
- int Volume::initializeMbr(const char *deviceNode) {
- diff -ru .system.old/vold.old/Volume.h system/vold/Volume.h
- --- .system.old/vold.old/Volume.h 2013-12-21 13:36:04.000000000 +0100
- +++ system/vold/Volume.h 2013-12-21 21:48:33.071971214 +0100
- @@ -46,6 +46,7 @@
- static const char *ASECDIR;
- static const char *LOOPDIR;
- + static const char *FUSEDIR;
- protected:
- char *mLabel;
- @@ -99,6 +100,7 @@
- int createBindMounts();
- int doUnmount(const char *path, bool force);
- int doMoveMount(const char *src, const char *dst, bool force);
- + int doFuseMount(const char *src, const char *dst);
- void protectFromAutorunStupidity();
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement