Android 9.0挂载TF卡并链接到一个新的目录上

TF卡映射到指定路径,如果要实现该功能只需要修改vold中代码就可以了
修改代码

system/vold/model/PublicVolume.cpp
system/vold/model/PublicVolume.h

在PublicVolume.cpp中的doMount()方法中修改默认TF卡名称

  // Use UUID as stable name, if available
    // std::string stableName = getId();
    std::string stableName = "Tfcard";
    /*
    if (!mFsUuid.empty()) {
        stableName = mFsUuid;
    }*/

在PublicVolume.cpp中的doMount()方法调用linkExternal();方法

status_t PublicVolume::doMount() {
		linkExternal();
    return OK;
}
void PublicVolume::linkExternal() {
    std::string source(getPath());
	 LOG(VERBOSE) << "linkExternal()...";
	
    std::string target("/storage/sdcard0");//自定义的链接路径
	
	
    if (TEMP_FAILURE_RETRY(unlink(target.c_str()))) {
        if (errno != ENOENT) {
            LOG(VERBOSE) << "Failed to unlink " << target.c_str() << strerror(errno);
        }
    }
	
    LOG(DEBUG) << "Linking " << source << " to " << target;
    if (TEMP_FAILURE_RETRY(symlink(source.c_str(), target.c_str()))) {
		LOG(ERROR) << "Failed to link " << source.c_str() << " to "
			<< target.c_str() <<  strerror(errno);
    }
}

在PublicVolume.h头文件中申明linkExternal()

class PublicVolume : public VolumeBase {
public:
    explicit PublicVolume(dev_t device);
	void linkExternal();
    virtual ~PublicVolume();

protected:
    status_t doCreate() override;
    status_t doDestroy() override;
    status_t doMount() override;
    status_t doUnmount() override;
    status_t doFormat(const std::string& fsType) override;

    status_t readMetadata();
    status_t initAsecStage();

private:
    /* Kernel device representing partition */
    dev_t mDevice;
    /* Block device path */
    std::string mDevPath;
    /* Mount point of raw partition */
    std::string mRawPath;

    std::string mFuseDefault;
    std::string mFuseRead;
    std::string mFuseWrite;

    /* PID of FUSE wrapper */
    pid_t mFusePid;

    /* Filesystem type */
    std::string mFsType;
    /* Filesystem UUID */
    std::string mFsUuid;
    /* User-visible filesystem label */
    std::string mFsLabel;

    DISALLOW_COPY_AND_ASSIGN(PublicVolume);
};

}  // namespace vold
}  // namespace android

#endif
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值