[Kernel] Fix ContentPackage leaking its registered device.
This commit is contained in:
parent
6411674f0f
commit
85ad87eb73
|
@ -41,8 +41,9 @@ ContentPackage::ContentPackage(KernelState* kernel_state, std::string root_name,
|
||||||
}
|
}
|
||||||
|
|
||||||
ContentPackage::~ContentPackage() {
|
ContentPackage::~ContentPackage() {
|
||||||
kernel_state_->file_system()->UnregisterSymbolicLink(root_name_ + ":");
|
auto fs = kernel_state_->file_system();
|
||||||
// TODO(benvanik): unregister device.
|
fs->UnregisterSymbolicLink(root_name_ + ":");
|
||||||
|
fs->UnregisterDevice(device_path_);
|
||||||
}
|
}
|
||||||
|
|
||||||
ContentManager::ContentManager(KernelState* kernel_state,
|
ContentManager::ContentManager(KernelState* kernel_state,
|
||||||
|
|
|
@ -32,8 +32,20 @@ bool VirtualFileSystem::RegisterDevice(std::unique_ptr<Device> device) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool VirtualFileSystem::RegisterSymbolicLink(std::string path,
|
bool VirtualFileSystem::UnregisterDevice(const std::string& path) {
|
||||||
std::string target) {
|
auto global_lock = global_critical_region_.Acquire();
|
||||||
|
for (auto it = devices_.begin(); it != devices_.end(); ++it) {
|
||||||
|
if ((*it)->mount_path() == path) {
|
||||||
|
XELOGD("Unregistered device: %s", (*it)->mount_path().c_str());
|
||||||
|
devices_.erase(it);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool VirtualFileSystem::RegisterSymbolicLink(const std::string& path,
|
||||||
|
const std::string& target) {
|
||||||
auto global_lock = global_critical_region_.Acquire();
|
auto global_lock = global_critical_region_.Acquire();
|
||||||
symlinks_.insert({path, target});
|
symlinks_.insert({path, target});
|
||||||
XELOGD("Registered symbolic link: %s => %s", path.c_str(), target.c_str());
|
XELOGD("Registered symbolic link: %s => %s", path.c_str(), target.c_str());
|
||||||
|
@ -41,7 +53,7 @@ bool VirtualFileSystem::RegisterSymbolicLink(std::string path,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool VirtualFileSystem::UnregisterSymbolicLink(std::string path) {
|
bool VirtualFileSystem::UnregisterSymbolicLink(const std::string& path) {
|
||||||
auto global_lock = global_critical_region_.Acquire();
|
auto global_lock = global_critical_region_.Acquire();
|
||||||
auto it = symlinks_.find(path);
|
auto it = symlinks_.find(path);
|
||||||
if (it == symlinks_.end()) {
|
if (it == symlinks_.end()) {
|
||||||
|
@ -63,7 +75,7 @@ bool VirtualFileSystem::IsSymbolicLink(const std::string& path) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Entry* VirtualFileSystem::ResolvePath(std::string path) {
|
Entry* VirtualFileSystem::ResolvePath(const std::string& path) {
|
||||||
auto global_lock = global_critical_region_.Acquire();
|
auto global_lock = global_critical_region_.Acquire();
|
||||||
|
|
||||||
// Resolve relative paths
|
// Resolve relative paths
|
||||||
|
@ -120,12 +132,13 @@ Entry* VirtualFileSystem::ResolvePath(std::string path) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
Entry* VirtualFileSystem::ResolveBasePath(std::string path) {
|
Entry* VirtualFileSystem::ResolveBasePath(const std::string& path) {
|
||||||
auto base_path = xe::find_base_path(path);
|
auto base_path = xe::find_base_path(path);
|
||||||
return ResolvePath(base_path);
|
return ResolvePath(base_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
Entry* VirtualFileSystem::CreatePath(std::string path, uint32_t attributes) {
|
Entry* VirtualFileSystem::CreatePath(const std::string& path,
|
||||||
|
uint32_t attributes) {
|
||||||
// Create all required directories recursively.
|
// Create all required directories recursively.
|
||||||
auto path_parts = xe::split_path(path);
|
auto path_parts = xe::split_path(path);
|
||||||
if (path_parts.empty()) {
|
if (path_parts.empty()) {
|
||||||
|
@ -153,7 +166,7 @@ Entry* VirtualFileSystem::CreatePath(std::string path, uint32_t attributes) {
|
||||||
attributes);
|
attributes);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool VirtualFileSystem::DeletePath(std::string path) {
|
bool VirtualFileSystem::DeletePath(const std::string& path) {
|
||||||
auto entry = ResolvePath(path);
|
auto entry = ResolvePath(path);
|
||||||
if (!entry) {
|
if (!entry) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -166,7 +179,7 @@ bool VirtualFileSystem::DeletePath(std::string path) {
|
||||||
return parent->Delete(entry);
|
return parent->Delete(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
X_STATUS VirtualFileSystem::OpenFile(std::string path,
|
X_STATUS VirtualFileSystem::OpenFile(const std::string& path,
|
||||||
FileDisposition creation_disposition,
|
FileDisposition creation_disposition,
|
||||||
uint32_t desired_access, File** out_file,
|
uint32_t desired_access, File** out_file,
|
||||||
FileAction* out_action) {
|
FileAction* out_action) {
|
||||||
|
|
|
@ -29,18 +29,20 @@ class VirtualFileSystem {
|
||||||
~VirtualFileSystem();
|
~VirtualFileSystem();
|
||||||
|
|
||||||
bool RegisterDevice(std::unique_ptr<Device> device);
|
bool RegisterDevice(std::unique_ptr<Device> device);
|
||||||
|
bool UnregisterDevice(const std::string& path);
|
||||||
|
|
||||||
bool RegisterSymbolicLink(std::string path, std::string target);
|
bool RegisterSymbolicLink(const std::string& path, const std::string& target);
|
||||||
bool UnregisterSymbolicLink(std::string path);
|
bool UnregisterSymbolicLink(const std::string& path);
|
||||||
bool IsSymbolicLink(const std::string& path);
|
bool IsSymbolicLink(const std::string& path);
|
||||||
|
|
||||||
Entry* ResolvePath(std::string path);
|
Entry* ResolvePath(const std::string& path);
|
||||||
Entry* ResolveBasePath(std::string path);
|
Entry* ResolveBasePath(const std::string& path);
|
||||||
|
|
||||||
Entry* CreatePath(std::string path, uint32_t attributes);
|
Entry* CreatePath(const std::string& path, uint32_t attributes);
|
||||||
bool DeletePath(std::string path);
|
bool DeletePath(const std::string& path);
|
||||||
|
|
||||||
X_STATUS OpenFile(std::string path, FileDisposition creation_disposition,
|
X_STATUS OpenFile(const std::string& path,
|
||||||
|
FileDisposition creation_disposition,
|
||||||
uint32_t desired_access, File** out_file,
|
uint32_t desired_access, File** out_file,
|
||||||
FileAction* out_action);
|
FileAction* out_action);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue