blob: 5c88e723202339c4dbc2820141279ddf4f68cfa6 [file] [log] [blame]
Ryo Hashimotof8936a42017-08-04 17:41:59 +09001// Copyright 2017 The Chromium OS Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef VIRTUAL_FILE_PROVIDER_FUSE_MAIN_H_
6#define VIRTUAL_FILE_PROVIDER_FUSE_MAIN_H_
7
Cherie Cheung1d39d932020-10-24 00:19:34 +09008#include <sys/types.h>
9
Ryo Hashimotof8936a42017-08-04 17:41:59 +090010#include <string>
11
12#include <base/callback.h>
13#include <base/files/file_path.h>
14#include <base/files/scoped_file.h>
15
16namespace virtual_file_provider {
17
Ryo Hashimoto153d2ff2017-08-14 15:17:23 +090018// Delegate for FuseMain().
19class FuseMainDelegate {
20 public:
21 virtual ~FuseMainDelegate() = default;
22
23 // Returns the size of the file, or returns -1 if the ID is invalid.
24 virtual int64_t GetSize(const std::string& id) = 0;
25
26 // Handles a read request. Data should be written to the given FD.
27 virtual void HandleReadRequest(const std::string& id,
28 int64_t offset,
29 int64_t size,
30 base::ScopedFD fd) = 0;
31
32 // FuseMain() calls this when an ID is released.
33 virtual void NotifyIdReleased(const std::string& id) = 0;
34};
Ryo Hashimotof8936a42017-08-04 17:41:59 +090035
36// Mounts the FUSE file system on the given path and runs the FUSE main loop.
37// This doesn't exit until the FUSE main loop exits (e.g. the file system is
38// unmounted, or this process is terminated).
39// Returns the value returned by libfuse's fuse_main().
Cherie Cheung1d39d932020-10-24 00:19:34 +090040int FuseMain(const base::FilePath& mount_path,
41 FuseMainDelegate* delegate,
42 base::Optional<uid_t> userId,
43 base::Optional<gid_t> groupId);
Ryo Hashimotof8936a42017-08-04 17:41:59 +090044
45} // namespace virtual_file_provider
46
47#endif // VIRTUAL_FILE_PROVIDER_FUSE_MAIN_H_