关闭

Android 5.1 vold模块ntfs扩展

标签: android机顶盒
1497人阅读 评论(1) 收藏 举报
分类:

准备

需要下载ntfs-3g驱动包,并做相应修改,这个网上已经可以下载到修改好的包,本文最后也会附加。

为什么要移植

在Android原生代码中,只支持了FAT格式的挂载,并未支持NTFS格式的存储设备挂载。一般来说,在手机上并不需要实现这种功能,但是在机顶盒上,USB挂载却是必须的。那为了达到这种目的,一种比较便捷的解决办法就是移植现有的驱动以支持当前的系统,NTFS-3G在Android上无疑是一个可以使用的方案。
【疑问】如果我们不移植,有没有办法使用NTFS功能?其实也是可以的,或者说部分可以,我们在源码中进入Kernel目录下去执行Make menuconfig(海思平台在:Hi3796MV100-2015-2-3-CP058\device\hisilicon\bigfish\sdk\source\kernel\linux-3.10.y,Broadcom平台:kernel位于源码根目录下android\kernel\private\97xxx-bcm\linux),
make menuconfig界面如下:
这里写图片描述
继续:
这里写图片描述
把这些功能打开:
这里写图片描述
然后打开ntfs支持选项,重新编译内核,会生成一个ko文件,将编译的内核文件重新烧写到盒子中,在进入到device目录下去使用Mount命令手动挂在插入的usb节点同样可以达到挂在上的目的,但是这个也只能说试试而已,实际离开串口调试没法用。

移植

我们将下载的这个驱动源码放到Android系统源码的external目录下(Broadcom\android\external\ntfs-3g),然后执行mm编译会生成ntfs-3g和ntfsfix两个bin文件,我们把它拷贝到/system/bin下并修改相应权限重启机顶盒,即可以使用该功能(只是有了驱动基础,具体要实现当U盘挂载,仍然需要修改系统源码,主要是VOLD模块,后面说明)。

1.在Broadcom\android-5.1\system\vold添加Ntfs.h

#ifndef _NTFS_H
#define _NTFS_H

#include <unistd.h>

class Ntfs {
public:
    static int check(const char *fsPath);
    static int doMount(const char *fsPath, const char *mountPoint, bool ro,
                       bool remount, int ownerUid, int ownerGid, int permMask,
                       bool createLost);
    static int format(const char *fsPath, unsigned int numSectors);
};

#endif

2.接着实现头文件:

#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>

#include <sys/types.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/mman.h>
#include <sys/mount.h>

#include <linux/kdev_t.h>

#define LOG_TAG "Vold"

#include <cutils/log.h>
#include <cutils/properties.h>
#include <logwrap/logwrap.h>
#include "Ntfs.h"

extern "C" int logwrap(int argc, const char **argv, int background);
extern "C" int mount(const char *, const char *, const char *, unsigned long, const void *);

#define NTFS_3G_PATH "/system/bin/ntfs-3g"

int Ntfs::check(const char *fsPath) {

    // no NTFS file system check is performed, always return true
    SLOGI("Ntfs filesystem: Skipping fs checks\n");
    return 0;

}

int Ntfs::doMount(const char *fsPath, const char *mountPoint,
                 bool ro, bool remount, int ownerUid, int ownerGid,
                 int permMask, bool createLost) {
    int rc;
    unsigned long flags;
    char mountData[255];

    flags = MS_NODEV | MS_NOEXEC | MS_NOSUID | MS_DIRSYNC;

    flags |= (ro ? MS_RDONLY : 0);
    flags |= (remount ? MS_REMOUNT : 0);
#if 0
    /*
     * Note: This is a temporary hack. If the sampling profiler is enabled,
     * we make the SD card world-writable so any process can write snapshots.
     *
     * TODO: Remove this code once we have a drop box in system_server.
     */
    char value[PROPERTY_VALUE_MAX];
    property_get("persist.sampling_profiler", value, "");
    if (value[0] == '1') {
        SLOGW("The SD card is world-writable because the"
            " 'persist.sampling_profiler' system property is set to '1'.");
        permMask = 0;
    }

    sprintf(mountData,
            "uid=%d,gid=%d,fmask=%o,dmask=%o,nls=utf8",
            ownerUid, ownerGid, permMask, permMask);

    rc = mount(fsPath, mountPoint, "ntfs", flags, "");

#else   
    SLOGE("mount ntfs block by ntfs-3g", fsPath);
    sprintf(mountData,
                "uid=%d,gid=%d,fmask=%o,dmask=%o,nls=utf8",
                ownerUid, ownerGid, permMask, permMask);
    const char* args[16];       
    args[0] = NTFS_3G_PATH;
    args[1] = fsPath;
    args[2] = mountPoint;
    args[3] = "-o";
    args[4] = mountData;
    args[5] = NULL;
    rc = logwrap(5, args, 1);
#endif

    if(rc) {
        SLOGE("%s appears to be a read only filesystem - retrying mount RO", fsPath);
        flags |= MS_RDONLY;
        rc = mount(fsPath, mountPoint, "ntfs", flags, "");
    }

    return rc;
}

int Ntfs::format(const char *fsPath, unsigned int numSectors) {

    SLOGE("Format ntfs filesystem not supported\n");
    errno = EIO;
    return -1;
}

在上面的代码中,我们指定了ntfs-3g支持文件的目录:#define NTFS_3G_PATH "/system/bin/ntfs-3g"这个在前面已经说过了。
3.在Volume.cpp中添加:#include "Ntfs.h"
修改挂载和卸载的几个函数:

int Volume::mountVol(const char* devName) {//modify by dongqiang add param
    dev_t deviceNodes[4];
    int n, i, rc = 0;
    char errmsg[255];

    int flags = getFlags();
    bool providesAsec = (flags & VOL_PROVIDES_ASEC) != 0;

    // TODO: handle "bind" style mounts, for emulated storage

    char decrypt_state[PROPERTY_VALUE_MAX];
    char crypto_state[PROPERTY_VALUE_MAX];
    char encrypt_progress[PROPERTY_VALUE_MAX];

    property_get("vold.decrypt", decrypt_state, "");
    property_get("vold.encrypt_progress", encrypt_progress, "");

    /* Don't try to mount the volumes if we have not yet entered the disk password
     * or are in the process of encrypting.
     */
    if ((getState() == Volume::State_NoMedia) ||
        ((!strcmp(decrypt_state, "1") || encrypt_progress[0]) && providesAsec)) {
        snprintf(errmsg, sizeof(errmsg),
                 "Volume %s %s mount failed - no media",
                 getLabel(), getFuseMountpoint());
        mVm->getBroadcaster()->sendBroadcast(
                                         ResponseCode::VolumeMountFailedNoMedia,
                                         errmsg, false);
        errno = ENODEV;
        return -1;
    } else if (getState() != Volume::State_Idle) {
        errno = EBUSY;
        if (getState() == Volume::State_Pending) {
            mRetryMount = true;
        }
        return -1;
    }

    n = getDeviceNodes((dev_t *) &deviceNodes, 4);

    if (!n) {
        SLOGE("Failed to get device nodes (%s)\n", strerror(errno));
        return -1;
    }

    /* If we're running encrypted, and the volume is marked as encryptable and nonremovable,
     * and also marked as providing Asec storage, then we need to decrypt
     * that partition, and update the volume object to point to it's new decrypted
     * block device
     */
    property_get("ro.crypto.state", crypto_state, "");
    if (providesAsec &&
        ((flags & (VOL_NONREMOVABLE | VOL_ENCRYPTABLE))==(VOL_NONREMOVABLE | VOL_ENCRYPTABLE)) &&
        !strcmp(crypto_state, "encrypted") && !isDecrypted()) {
       char new_sys_path[MAXPATHLEN];
       char nodepath[256];
       int new_major, new_minor;

       if (n != 1) {
           /* We only expect one device node returned when mounting encryptable volumes */
           SLOGE("Too many device nodes returned when mounting %s\n", getMountpoint());
           return -1;
       }

       if (cryptfs_setup_volume(getLabel(), MAJOR(deviceNodes[0]), MINOR(deviceNodes[0]),
                                new_sys_path, sizeof(new_sys_path),
                                &new_major, &new_minor)) {
           SLOGE("Cannot setup encryption mapping for %s\n", getMountpoint());
           return -1;
       }
       /* We now have the new sysfs path for the decrypted block device, and the
        * majore and minor numbers for it.  So, create the device, update the
        * path to the new sysfs path, and continue.
        */
        snprintf(nodepath,
                 sizeof(nodepath), "/dev/block/vold/%d:%d",
                 new_major, new_minor);

        if (createDeviceNode(nodepath, new_major , new_minor)) {
            SLOGE("Error making device node '%s' (%s)", nodepath,
                                                       strerror(errno));
        }

        // Todo: Either create sys filename from nodepath, or pass in bogus path so
        //       vold ignores state changes on this internal device.
        updateDeviceInfo(nodepath, new_major , new_minor);

        /* Get the device nodes again, because they just changed */
        n = getDeviceNodes((dev_t *) &deviceNodes, 4);
        if (!n) {
            SLOGE("Failed to get device nodes (%s)\n", strerror(errno));
            return -1;
        }
    }

    char finalPath[32] = {0x00};//add by dongqiang 
    for (i = 0; i < n; i++) {
        char devicePath[255];
        sprintf(devicePath, "/dev/block/vold/%d:%d", /*major(deviceNodes[i])*/g_major,
                /*minor(deviceNodes[i])*/g_minor);//modify by dongqiang

//add by dongqiang begin 
        const char * path_prefix = "/mnt/media_rw/";
        const size_t len = strlen(path_prefix) + strlen(devName);
        char * path = new char[len+1];
        strcpy(path, path_prefix);
        strcat(path, devName);
        int errCode = mkdir(path, 0777);

        if(g_major == 179) {
            rmdir(path);
        }

        memset(finalPath, 0x00, sizeof(finalPath));
        if(strstr(devicePath, "179") != NULL) {
            strcpy(finalPath, "/mnt/media_rw/sdcard1/");
        } else {
            strcpy(finalPath, path);
        }
        delete(path);

//add by dongqiang end

        SLOGI("%s being considered for volume %s\n", devicePath, getLabel());
        SLOGI("current mountpoint is %s, fuseMountPoint is %s", getMountpoint(), getFuseMountpoint());

        errno = 0;
        setState(Volume::State_Checking);
//add by dongqiang begin
        int permMask = providesAsec ? 0007 : 0002;
        bool isNtfsFS = true;        
        bool isFatFs = true;
        bool isExtFs = true;
        bool isExfatFs = true;

        if (isNtfsFS) {   
            SLOGI("devicePath:%s ,mountpoint:%s\n", devicePath, getMountpoint());
            if (Ntfs::doMount(devicePath, finalPath, false, false, 
                AID_MEDIA_RW, AID_MEDIA_RW, permMask, true)) { 
                SLOGE("%s failed to mount via NTFS (%s)\n", devicePath, strerror(errno));                
                isNtfsFS = false;            
            } else {                
                isFatFs = false;                
                isExtFs = false;                
                isExfatFs = false;            
            }        
        }

        if (isFatFs) { 
            if (Fat::doMount(devicePath, finalPath, false, false, false,                
                AID_MEDIA_RW, AID_MEDIA_RW, permMask, true)) {                
                SLOGE("%s failed to mount via VFAT (%s)\n", devicePath, strerror(errno));                
                isFatFs = false; 
            } else {                
                isExtFs = false;                
                isExfatFs = false;            
            }        
        }

//add by dongqiang end      
        errno = 0;
        int gid;
        extractMetadata(devicePath);

        if (providesAsec && mountAsecExternal() != 0) {
            SLOGE("Failed to mount secure area (%s)", strerror(errno));
            umount(/*getMountpoint()*/finalPath);
            setState(Volume::State_Idle);
            return -1;
        }

        char service[64];
        snprintf(service, 64, "fuse_%s", getLabel());
        property_set("ctl.start", service);

        setState(Volume::State_Mounted);
        mCurrentlyMountedKdev = deviceNodes[i];
        return 0;
    }

    SLOGE("Volume %s found no suitable devices for mounting :(\n", getLabel());
    setState(Volume::State_Idle);

    return -1;
}
int Volume::doUnmount(const char *path, bool force) {
    int retries = 10;

    if (mDebug) {
        SLOGD("Unmounting {%s}, force = %d", path, force);
    }

    while (retries--) {
        if (!umount(path) || errno == EINVAL || errno == ENOENT) {
            SLOGI("%s sucessfully unmounted", path);
            return 0;
        }

        int action = 0;

        if (force) {
            if (retries == 1) {
                action = 2; // SIGKILL
            } else if (retries == 2) {
                action = 1; // SIGHUP
            }
        }

        SLOGW("Failed to unmount %s (%s, retries %d, action %d)",
                path, strerror(errno), retries, action);

        Process::killProcessesWithOpenFiles(path, action);
        usleep(1000*1000);
    }
    errno = EBUSY;
    SLOGE("Giving up on unmount %s (%s)", path, strerror(errno));
    return -1;
}

移除挂载函数:

int Volume::unmountVol(bool force, bool revert, const char* devName) {//add the third param by dongqiang
    int i, rc;

    int flags = getFlags();
    bool providesAsec = (flags & VOL_PROVIDES_ASEC) != 0;
/*
    if (getState() != Volume::State_Mounted) {
        SLOGE("Volume %s unmount request when not mounted", getLabel());
        errno = EINVAL;
        return UNMOUNT_NOT_MOUNTED_ERR;
    }
*/

    setState(Volume::State_Unmounting);
    usleep(1000 * 1000); // Give the framework some time to react

    char service[64];
    snprintf(service, 64, "fuse_%s", getLabel());
    property_set("ctl.stop", service);
    /* Give it a chance to stop.  I wish we had a synchronous way to determine this... */
    sleep(3);

    // TODO: determine failure mode if FUSE times out
    if (providesAsec && doUnmount(Volume::SEC_ASECDIR_EXT, force) != 0) {
        SLOGE("Failed to unmount secure area on %s (%s)", getMountpoint(), strerror(errno));
        goto out_mounted;
    }
    //add by dongqiang begin
    if(strstr(devName, "mmcb")) {
        if (doUnmount(getFuseMountpoint(), force) != 0) {
            SLOGE("Failed to unmount %s (%s)", getFuseMountpoint(), strerror(errno));
            goto fail_remount_secure;
        }
        const char* path_pre = "/mnt/media_rw/";
        char* path = new char[strlen(path_pre) + strlen(devName)];
        strcpy(path, path_pre);
        strcat(path, devName);
        rmdir(path);
        delete(path);
    } else {
        const char* path_pre = "/mnt/media_rw/";
        char* path = new char[strlen(path_pre) + strlen(devName)];
        strcpy(path, path_pre);
        strcat(path, devName);
        if (doUnmount(path, force) != 0) {
            SLOGE("Failed to unmount %s (%s)", getFuseMountpoint(), strerror(errno));
            if(path != NULL) {
                delete(path);
            }
            goto fail_remount_secure;
        }
        int rtCode = rmdir(path);
        delete(path);
    }
    //add by dongqiang end

    if(strstr(devName, "mmcb")) {
        if (doUnmount(getMountpoint(), force) != 0) {
            SLOGE("Failed to unmount %s (%s)", getMountpoint(), strerror(errno));
            goto fail_remount_secure;
        }
        sleep(3);
        const char* path_pre = "/mnt/media_rw/";
        char* path = new char[strlen(path_pre) + strlen(devName)];
        strcpy(path, path_pre);
        strcat(path, devName);
        rmdir(path);
        delete(path);

    } else {
        const char* path_pre = "/mnt/media_rw/";
        char* path = new char[strlen(path_pre) + strlen(devName)];
        strcpy(path, path_pre);
        strcat(path, devName);
        if (doUnmount(path, force) != 0) {
            SLOGE("Failed to unmount %s (%s)", getMountpoint(), strerror(errno));
            if(path != NULL) {
                delete(path);
            }
            goto fail_remount_secure;
        }
        if(path != NULL) {
            rmdir(path);
            delete(path);
        }
    }
    SLOGI("%s unmounted successfully", getMountpoint());

    /* If this is an encrypted volume, and we've been asked to undo
     * the crypto mapping, then revert the dm-crypt mapping, and revert
     * the device info to the original values.
     */
    if (revert && isDecrypted()) {
        cryptfs_revert_volume(getLabel());
        revertDeviceInfo();
        SLOGI("Encrypted volume %s reverted successfully", getMountpoint());
    }

    setUuid(NULL);
    setUserLabel(NULL);
    setState(Volume::State_Idle);
    mCurrentlyMountedKdev = -1;
    return 0;

fail_remount_secure:
    if (providesAsec && mountAsecExternal() != 0) {
        SLOGE("Failed to remount secure area (%s)", strerror(errno));
        goto out_nomedia;
    }

out_mounted:
    setState(Volume::State_Mounted);
    return -1;

out_nomedia:
    setState(Volume::State_NoMedia);
    return -1;
}

如下函数中主要对全局变量g_major和g_minor进行初始化。

int Volume::createDeviceNode(const char *path, int major, int minor) {
    //add by dongqiang begin
    g_major = major;
    g_minor = minor;
    //add by dongqiang end
    mode_t mode = 0660 | S_IFBLK;
    dev_t dev = (major << 8) | minor;

    if (mknod(path, mode, dev) < 0) {
        if (errno != EEXIST) {
            return -1;
        }
    }
    return 0;
}

4.在VolumeManager.cpp中做如下修改(2处):

int VolumeManager::mountVolume(const char *label) {
    Volume *v = lookupVolume(label);

    if (!v) {
        errno = ENOENT;
        return -1;
    }

    return v->mountVol(devName);//modify by dongqiang ---add param
}

int VolumeManager::unmountVolume(const char *label, bool force, bool revert) {
    Volume *v = lookupVolume(label);

    if (!v) {
        errno = ENOENT;
        return -1;
    }

    if (v->getState() == Volume::State_NoMedia) {
        errno = ENODEV;
        return -1;
    }

    if (v->getState() != Volume::State_Mounted) {
        SLOGW("Attempt to unmount volume which isn't mounted (%d)\n",
             v->getState());
        errno = EBUSY;
        return UNMOUNT_NOT_MOUNTED_ERR;
    }

    cleanupAsec(v, force);
    return v->unmountVol(force, revert, NULL);//add the third param by dongqiang
}

5.在DirectVolume.cpp中修改如下:
①定义全局变量数组char nameForRm[32] = {0x00};


int DirectVolume::handleBlockEvent(NetlinkEvent *evt) {
    const char *dp = evt->findParam("DEVPATH");

    PathCollection::iterator  it;
    for (it = mPaths->begin(); it != mPaths->end(); ++it) {
        if ((*it)->match(dp)) {
            /* We can handle this disk */
            int action = evt->getAction();
            const char *devtype = evt->findParam("DEVTYPE");

            if (action == NetlinkEvent::NlActionAdd) {
                int major = atoi(evt->findParam("MAJOR"));
                int minor = atoi(evt->findParam("MINOR"));
                char nodepath[255];

                snprintf(nodepath,
                         sizeof(nodepath), "/dev/block/vold/%d:%d",
                         major, minor);
                if (createDeviceNode(nodepath, major, minor)) {
                    SLOGE("Error making device node '%s' (%s)", nodepath,
                                                               strerror(errno));
                }
                if (!strcmp(devtype, "disk")) {
                    handleDiskAdded(dp, evt);
                } else 
                    handlePartitionAdded(dp, evt);
                }

                /* Send notification iff disk is ready (ie all partitions found) */
                if (getState() == Volume::State_Idle) {
                    char msg[255];

                    snprintf(msg, sizeof(msg),
                             "Volume %s %s disk inserted (%d:%d)", getLabel(),
                             getFuseMountpoint(), mDiskMajor, mDiskMinor);
                    mVm->getBroadcaster()->sendBroadcast(ResponseCode::VolumeDiskInserted,
                                                         msg, false);
                }
            } else if (action == NetlinkEvent::NlActionRemove) {
                if (!strcmp(devtype, "disk")) {
                    handleDiskRemoved(dp, evt);
                } else {
                    handlePartitionRemoved(dp, evt);
                }
            } else if (action == NetlinkEvent::NlActionChange) {
                if (!strcmp(devtype, "disk")) {
                    handleDiskChanged(dp, evt);
                } else {
                    handlePartitionChanged(dp, evt);
                }
            } else {
                    SLOGW("Ignoring non add/remove/change event");
            }

            return 0;
        }
    }
    errno = ENODEV;
    return -1;
}

处理分区添加:

void DirectVolume::handlePartitionAdded(const char *devpath, NetlinkEvent *evt) {
    int major = atoi(evt->findParam("MAJOR"));
    int minor = atoi(evt->findParam("MINOR"));

    int part_num;

    const char *tmp = evt->findParam("PARTN");

    if (tmp) {
        part_num = atoi(tmp);
    } else {
        SLOGW("Kernel block uevent missing 'PARTN'");
        part_num = 1;
    }

    if (part_num > MAX_PARTITIONS || part_num < 1) {
        SLOGE("Invalid 'PARTN' value");
        return;
    }

    if (part_num > mDiskNumParts) {
        mDiskNumParts = part_num;
    }

    if (major != mDiskMajor) {
        SLOGE("Partition '%s' has a different major than its disk!", devpath);
        return;
    }
#ifdef PARTITION_DEBUG
    SLOGD("Dv:partAdd: part_num = %d, minor = %d\n", part_num, minor);
#endif
    if (part_num >= MAX_PARTITIONS) {
        SLOGE("Dv:partAdd: ignoring part_num = %d (max: %d)\n", part_num, MAX_PARTITIONS-1);
    } else {
        if ((mPartMinors[part_num - 1] == -1) && mPendingPartCount)
            mPendingPartCount--;
        mPartMinors[part_num -1] = minor;
    }

    if (!mPendingPartCount) {
#ifdef PARTITION_DEBUG
        SLOGD("Dv:partAdd: Got all partitions - ready to rock!");
#endif
        if (getState() != Volume::State_Formatting) {
            setState(Volume::State_Idle);
            if (mRetryMount == true) {
                mRetryMount = false;
                mountVol(evt->findParam("DEVNAME"));//modify by dongqiang ----add param
            }
        }
    } else {
#ifdef PARTITION_DEBUG
        SLOGD("Dv:partAdd: pending %d disk", mPendingPartCount);
#endif
    }
}

处理disk移除:

void DirectVolume::handleDiskRemoved(const char * /*devpath*/,
                                     NetlinkEvent *evt) {
    int major = atoi(evt->findParam("MAJOR"));
    int minor = atoi(evt->findParam("MINOR"));
    char msg[255];
    bool enabled;

    if (mVm->shareEnabled(getLabel(), "ums", &enabled) == 0 && enabled) {
        mVm->unshareVolume(getLabel(), "ums");
    }

    SLOGD("handleDiskRemoved, volume %s %s disk %d:%d removed\n", getLabel(), getMountpoint(), major, minor);
    snprintf(msg, sizeof(msg), "Volume %s %s disk removed (%d:%d)",
             getLabel(), getFuseMountpoint(), major, minor);
    mVm->getBroadcaster()->sendBroadcast(ResponseCode::VolumeDiskRemoved,
                                             msg, false);
    setState(Volume::State_NoMedia);

    if(strstr(nameForRm, evt->findParam("DEVNAME"))) {
        const char * path_prefix = "/mnt/media_rw/";
        const size_t len = strlen(path_prefix) + strlen(nameForRm);
        char * path = new char[len+1];
        strcpy(path, path_prefix);
        strcat(path, nameForRm);
        SLOGD("dq>---------handleDiskRemoved-----path to remove: %s, name=%s", path, nameForRm);
        Volume::unmountVol(true, false, nameForRm);
        sleep(3);
        int code = rmdir(path);
        SLOGD("handleDiskRemoved,  now remove path: %s, error: %s", path, strerror(code));
    }
}

处理分区移除:

void DirectVolume::handlePartitionRemoved(const char * /*devpath*/,
                                          NetlinkEvent *evt) {
    int major = atoi(evt->findParam("MAJOR"));
    int minor = atoi(evt->findParam("MINOR"));
    char msg[255];
    int state;
    const char* devName = evt->findParam("DEVNAME");

//modify by dongqiang begin 
        const char * path_prefix = "/mnt/media_rw/";
        const size_t len = strlen(path_prefix) + strlen(devName);
        char * path = new char[len+1];
        strcpy(path, path_prefix);
        strcat(path, devName);
        memset(nameForRm, 0x00, sizeof(nameForRm));
        strcpy(nameForRm, devName);
    if(major == 179) {
        //179 sdcard
        SLOGD("Volume %s %s partition %d:%d removed\n", getLabel(), getMountpoint(), major, minor);
    } else {
        //usb
        SLOGD("Volume %s %s partition %d:%d removed\n", getLabel(), /*getMountpoint()*/path, major, minor);
    }
//modify by dongqiang end 
    /*
     * The framework doesn't need to get notified of
     * partition removal unless it's mounted. Otherwise
     * the removal notification will be sent on the Disk
     * itself
     */
    state = getState();
    SLOGD("dq------current state: %d",state);
    if (state != Volume::State_Mounted && state != Volume::State_Shared) {
        SLOGE("state !=State_Mounted && state != State_Shared");
        Volume::unmountVol(true, false, devName);
        sleep(3);
        int code = rmdir(path);
        SLOGD("we now remove path: %s, error: %s", path, strerror(code));
        delete(path);
        return;
    }
//add by dongqiang begin
    if(path != NULL) {
        delete(path);
    }
//add by dongqiang end    
    if ((dev_t) MKDEV(major, minor) == mCurrentlyMountedKdev) {
        /*
         * Yikes, our mounted partition is going away!
         */

        bool providesAsec = (getFlags() & VOL_PROVIDES_ASEC) != 0;
        if (providesAsec && mVm->cleanupAsec(this, true)) {
            SLOGE("Failed to cleanup ASEC - unmount will probably fail!");
        }

        snprintf(msg, sizeof(msg), "Volume %s %s bad removal (%d:%d)",
                 getLabel(), getFuseMountpoint(), major, minor);
        mVm->getBroadcaster()->sendBroadcast(ResponseCode::VolumeBadRemoval,
                                             msg, false);

        if (Volume::unmountVol(true, false, evt->findParam("DEVNAME"))) {//add the third param by dongqiang
            SLOGE("Failed to unmount volume on bad removal (%s)", 
                 strerror(errno));
            // XXX: At this point we're screwed for now
        } else {
            SLOGD("Crisis averted");
        }
    } else if (state == Volume::State_Shared) {
        /* removed during mass storage */
        snprintf(msg, sizeof(msg), "Volume %s bad removal (%d:%d)",
                 getLabel(), major, minor);
        mVm->getBroadcaster()->sendBroadcast(ResponseCode::VolumeBadRemoval,
                                             msg, false);

        if (mVm->unshareVolume(getLabel(), "ums")) {
            SLOGE("Failed to unshare volume on bad removal (%s)",
                strerror(errno));
        } else {
            SLOGD("Crisis averted");
        }
    }
}

6.在Volume.h中修改如下:

//modify by dongqiang, add parameter
int mountVol(const char* devName);
//modify by dongqiang
int unmountVol(bool force, bool revert, const char* devName);//add the third param by dongqiang 

然后对代码进行重新编译,将生成的vold文件拷贝到/system/bin下运行。

附件

ntfs-3g驱动支持源码:
http://download.csdn.net/detail/foreversunshine/9616676
编译生成的bin文件:
ntfs-3g
http://download.csdn.net/detail/foreversunshine/9616678
ntfsfix
http://download.csdn.net/detail/foreversunshine/9616731

0
0

猜你在找
【直播】机器学习&数据挖掘7周实训--韦玮
【套餐】系统集成项目管理工程师顺利通关--徐朋
【直播】3小时掌握Docker最佳实战-徐西宁
【套餐】机器学习系列套餐(算法+实战)--唐宇迪
【直播】计算机视觉原理及实战--屈教授
【套餐】微信订阅号+服务号Java版 v2.0--翟东平
【直播】机器学习之矩阵--黄博士
【套餐】微信订阅号+服务号Java版 v2.0--翟东平
【直播】机器学习之凸优化--马博士
【套餐】Javascript 设计模式实战--曾亮
查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:52885次
    • 积分:893
    • 等级:
    • 排名:千里之外
    • 原创:35篇
    • 转载:5篇
    • 译文:0篇
    • 评论:26条
    文章分类
    最新评论