blob: 5fc7a74da9905bfd30d76bb4395263a9329e01e7 [file] [log] [blame]
// Copyright 2019 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "registry.h"
#include <fuchsia/fshost/llcpp/fidl.h>
#include "src/lib/storage/vfs/cpp/pseudo_dir.h"
#include "src/lib/storage/vfs/cpp/vfs_types.h"
namespace devmgr {
namespace fshost {
Registry::Registry(async::Loop* loop) : vfs_(loop->dispatcher()) {
// Create the root of the registry.
root_ = fbl::MakeRefCounted<fs::PseudoDir>();
// Create a "tracking directory", capable of monitoring registered filesystems,
// and detaching them once they are unmounted.
auto filesystems = fbl::MakeRefCounted<fs::PseudoDir>();
zx_status_t status =
root_->AddEntry(fidl::DiscoverableProtocolName<fuchsia_fshost::Filesystems>, filesystems);
ZX_ASSERT(status == ZX_OK);
// Create a service node, which clients may use to communicate with the registry.
svc_ = fbl::MakeRefCounted<fshost::RegistryVnode>(vfs_.dispatcher(), std::move(filesystems));
status = root_->AddEntry(fidl::DiscoverableProtocolName<fuchsia_fshost::Registry>, svc_);
ZX_ASSERT(status == ZX_OK);
}
zx_status_t Registry::ServeRoot(zx::channel server) {
fs::VnodeConnectionOptions options;
options.rights.read = true;
options.rights.write = true;
options.rights.admin = true;
return vfs_.Serve(root_, std::move(server), options);
}
} // namespace fshost
} // namespace devmgr