blob: cfdd35112f693e9e8432a9b4874dc0506565beb3 [file]
// Copyright 2022 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.
#ifndef SRC_STORAGE_MINFS_RUNNER_H_
#define SRC_STORAGE_MINFS_RUNNER_H_
#ifdef __Fuchsia__
#include <fidl/fuchsia.fs/cpp/wire.h>
#include <lib/async-loop/cpp/loop.h>
#include <lib/fidl/cpp/wire/channel.h>
#include "src/storage/lib/vfs/cpp/managed_vfs.h"
#endif
#include <lib/zx/result.h>
#include "src/storage/minfs/minfs_private.h"
#include "src/storage/minfs/mount.h"
namespace minfs {
// A wrapper class around a "Minfs" object which manages the external FIDL connections.
class Runner final : public PlatformVfs
#ifdef __Fuchsia__
,
public fidl::WireServer<fuchsia_fs::Admin>
#endif
{
public:
Runner(const Runner&) = delete;
Runner& operator=(const Runner&) = delete;
static zx::result<std::unique_ptr<Runner>> Create(FuchsiaDispatcher dispatcher,
std::unique_ptr<Bcache> bc,
const MountOptions& options);
static std::unique_ptr<Bcache> Destroy(std::unique_ptr<Runner> runner);
#ifdef __Fuchsia__
// ManagedVfs implementation.
void Shutdown(fs::FuchsiaVfs::ShutdownCallback cb) final;
zx::result<fs::FilesystemInfo> GetFilesystemInfo() final;
void OnNoConnections() final;
zx::result<> ServeRoot(fidl::ServerEnd<fuchsia_io::Directory> root);
// fuchsia_fs::Admin implementation.
void Shutdown(ShutdownCompleter::Sync& completer) final;
#endif
void SetUnmountCallback(fit::closure on_unmount) { on_unmount_ = std::move(on_unmount); }
Minfs& minfs() { return *minfs_; }
private:
explicit Runner(FuchsiaDispatcher dispatcher);
// Check if filesystem is readonly.
bool IsReadonly() const __TA_EXCLUDES(vfs_lock_);
#ifdef __Fuchsia__
fidl::ServerBindingGroup<fuchsia_fs::Admin> admin_bindings_;
#endif
std::unique_ptr<Minfs> minfs_;
fit::closure on_unmount_;
};
} // namespace minfs
#endif // SRC_STORAGE_MINFS_RUNNER_H_