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