• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (C) 2021 The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //      http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #pragma once
16 
17 #include <dirent.h>
18 #include <fcntl.h>
19 #include <sys/param.h>
20 #include <sys/stat.h>
21 #include <unistd.h>
22 
23 #include <cstdint>
24 #include <string>
25 
26 namespace dittosuite {
27 
28 class SyscallInterface {
29  public:
~SyscallInterface()30   virtual ~SyscallInterface() {}
31 
32   virtual int Access(const std::string& path_name, int mode) = 0;
33   virtual int Close(int fd) = 0;
34   virtual int CloseDir(DIR* dirp) = 0;
35   virtual int FAdvise(int fd, int64_t offset, int64_t len, int advice) = 0;
36   virtual int FAllocate(int fd, int mode, int64_t offset, int64_t len) = 0;
37   virtual int FTruncate(int fd, int64_t length) = 0;
38   virtual int FStat(int filedes, struct stat64* buf) = 0;
39   virtual int FSync(int fd) = 0;
40   virtual int Open(const std::string& path_name, int flags, int mode) = 0;
41   virtual DIR* OpenDir(const std::string& name) = 0;
42   virtual int64_t Read(int fd, char* buf, int64_t count, int64_t offset) = 0;
43   virtual struct dirent* ReadDir(DIR* dirp) = 0;
44   virtual int64_t ReadLink(const std::string& path_name, char* buf, int64_t bufsiz) = 0;
45   virtual void Sync() = 0;
46   virtual int Unlink(const std::string& path_name) = 0;
47   virtual int64_t Write(int fd, char* buf, int64_t count, int64_t offset) = 0;
48 };
49 
50 class Syscall : public SyscallInterface {
51  public:
52   Syscall(Syscall& other) = delete;
53   void operator=(const Syscall&) = delete;
54 
55   static Syscall& GetSyscall();
56 
57   int Access(const std::string& path_name, int mode) override;
58   int Close(int fd) override;
59   int CloseDir(DIR* dirp) override;
60   int FAdvise(int fd, int64_t offset, int64_t len, int advice) override;
61   int FAllocate(int fd, int mode, int64_t offset, int64_t len) override;
62   int FTruncate(int fd, int64_t length) override;
63   int FStat(int filedes, struct stat64* buf) override;
64   int FSync(int fd) override;
65   int Open(const std::string& path_name, int flags, int mode) override;
66   DIR* OpenDir(const std::string& name) override;
67   int64_t Read(int fd, char* buf, int64_t count, int64_t offset) override;
68   struct dirent* ReadDir(DIR* dirp) override;
69   int64_t ReadLink(const std::string& path_name, char* buf, int64_t bufsiz) override;
70   void Sync() override;
71   int Unlink(const std::string& path_name) override;
72   int64_t Write(int fd, char* buf, int64_t count, int64_t offset) override;
73 
74  private:
Syscall()75   Syscall(){};
76 };
77 
78 }  // namespace dittosuite
79