Ryo Hashimoto | f8936a4 | 2017-08-04 17:41:59 +0900 | [diff] [blame] | 1 | // 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 Cheung | 1d39d93 | 2020-10-24 00:19:34 +0900 | [diff] [blame] | 8 | #include <sys/types.h> |
| 9 | |
Ryo Hashimoto | f8936a4 | 2017-08-04 17:41:59 +0900 | [diff] [blame] | 10 | #include <string> |
| 11 | |
| 12 | #include <base/callback.h> |
| 13 | #include <base/files/file_path.h> |
| 14 | #include <base/files/scoped_file.h> |
| 15 | |
| 16 | namespace virtual_file_provider { |
| 17 | |
Ryo Hashimoto | 153d2ff | 2017-08-14 15:17:23 +0900 | [diff] [blame] | 18 | // Delegate for FuseMain(). |
| 19 | class 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 Hashimoto | f8936a4 | 2017-08-04 17:41:59 +0900 | [diff] [blame] | 35 | |
| 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 Cheung | 1d39d93 | 2020-10-24 00:19:34 +0900 | [diff] [blame] | 40 | int FuseMain(const base::FilePath& mount_path, |
| 41 | FuseMainDelegate* delegate, |
| 42 | base::Optional<uid_t> userId, |
| 43 | base::Optional<gid_t> groupId); |
Ryo Hashimoto | f8936a4 | 2017-08-04 17:41:59 +0900 | [diff] [blame] | 44 | |
| 45 | } // namespace virtual_file_provider |
| 46 | |
| 47 | #endif // VIRTUAL_FILE_PROVIDER_FUSE_MAIN_H_ |