xref: /aosp_15_r20/system/libvintf/include-host/vintf/HostFileSystem.h (revision 70a7ec852fcefd15a4fb57f8f183a8b1c3aacb08)
1*70a7ec85SAndroid Build Coastguard Worker /*
2*70a7ec85SAndroid Build Coastguard Worker  * Copyright (C) 2020 The Android Open Source Project
3*70a7ec85SAndroid Build Coastguard Worker  *
4*70a7ec85SAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*70a7ec85SAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*70a7ec85SAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*70a7ec85SAndroid Build Coastguard Worker  *
8*70a7ec85SAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*70a7ec85SAndroid Build Coastguard Worker  *
10*70a7ec85SAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*70a7ec85SAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*70a7ec85SAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*70a7ec85SAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*70a7ec85SAndroid Build Coastguard Worker  * limitations under the License.
15*70a7ec85SAndroid Build Coastguard Worker  */
16*70a7ec85SAndroid Build Coastguard Worker 
17*70a7ec85SAndroid Build Coastguard Worker #pragma once
18*70a7ec85SAndroid Build Coastguard Worker 
19*70a7ec85SAndroid Build Coastguard Worker #include <memory>
20*70a7ec85SAndroid Build Coastguard Worker 
21*70a7ec85SAndroid Build Coastguard Worker #include <utils/Errors.h>
22*70a7ec85SAndroid Build Coastguard Worker #include <vintf/Dirmap.h>
23*70a7ec85SAndroid Build Coastguard Worker #include <vintf/FileSystem.h>
24*70a7ec85SAndroid Build Coastguard Worker 
25*70a7ec85SAndroid Build Coastguard Worker namespace android::vintf::details {
26*70a7ec85SAndroid Build Coastguard Worker 
27*70a7ec85SAndroid Build Coastguard Worker // A FileSystem object that uses Dirmap to redirect reads.
28*70a7ec85SAndroid Build Coastguard Worker // FileSystem is read via the internal impl.
29*70a7ec85SAndroid Build Coastguard Worker class HostFileSystem : public FileSystemImpl {
30*70a7ec85SAndroid Build Coastguard Worker    public:
31*70a7ec85SAndroid Build Coastguard Worker     // Use FileSystemImpl for any actual reads.
32*70a7ec85SAndroid Build Coastguard Worker     HostFileSystem(const Dirmap& dirmap, status_t missingError);
33*70a7ec85SAndroid Build Coastguard Worker     // Use |impl| for any actual reads. Does not own impl.
34*70a7ec85SAndroid Build Coastguard Worker     HostFileSystem(const Dirmap& dirmap, status_t missingError, FileSystem* impl);
35*70a7ec85SAndroid Build Coastguard Worker     // Use |impl| for any actual reads. Owns impl.
36*70a7ec85SAndroid Build Coastguard Worker     HostFileSystem(const Dirmap& dirmap, status_t missingError, std::unique_ptr<FileSystem>&& impl);
37*70a7ec85SAndroid Build Coastguard Worker 
38*70a7ec85SAndroid Build Coastguard Worker     status_t fetch(const std::string& path, std::string* fetched,
39*70a7ec85SAndroid Build Coastguard Worker                    std::string* error) const override;
40*70a7ec85SAndroid Build Coastguard Worker     status_t listFiles(const std::string& path, std::vector<std::string>* out,
41*70a7ec85SAndroid Build Coastguard Worker                        std::string* error) const override;
42*70a7ec85SAndroid Build Coastguard Worker     status_t modifiedTime(const std::string& path, timespec* mtime,
43*70a7ec85SAndroid Build Coastguard Worker                           std::string* error) const override;
44*70a7ec85SAndroid Build Coastguard Worker 
45*70a7ec85SAndroid Build Coastguard Worker    private:
46*70a7ec85SAndroid Build Coastguard Worker     std::string resolve(const std::string& path, std::string* error) const;
47*70a7ec85SAndroid Build Coastguard Worker 
48*70a7ec85SAndroid Build Coastguard Worker     Dirmap mDirMap;
49*70a7ec85SAndroid Build Coastguard Worker     status_t mMissingError;
50*70a7ec85SAndroid Build Coastguard Worker 
51*70a7ec85SAndroid Build Coastguard Worker     std::unique_ptr<FileSystem> mImplUniq;
52*70a7ec85SAndroid Build Coastguard Worker     FileSystem* mImpl;
53*70a7ec85SAndroid Build Coastguard Worker };
54*70a7ec85SAndroid Build Coastguard Worker 
55*70a7ec85SAndroid Build Coastguard Worker }  // namespace android::vintf::details
56