1 // Copyright 2020 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 LIBBRILLO_BRILLO_NAMESPACES_PLATFORM_H_
6 #define LIBBRILLO_BRILLO_NAMESPACES_PLATFORM_H_
7 
8 #include <sys/types.h>
9 
10 #include <memory>
11 #include <string>
12 
13 #include <base/files/file_path.h>
14 #include <base/macros.h>
15 #include <brillo/brillo_export.h>
16 
17 namespace brillo {
18 // Platform specific routines abstraction layer.
19 // Also helps us to be able to mock them in tests.
20 class BRILLO_EXPORT Platform {
21  public:
22   Platform();
23 
24   virtual ~Platform();
25   // Calls the platform fork() function and returns the pid returned
26   // by fork().
27   virtual pid_t Fork();
28 
29   // Calls the platform unmount.
30   //
31   // Parameters
32   //   path - The path to unmount
33   //   lazy - Whether to call a lazy unmount
34   //   was_busy (OUT) - Set to true on return if the mount point was busy
35   virtual bool Unmount(const base::FilePath& path, bool lazy, bool* was_busy);
36 
37   // Calls the platform mount.
38   //
39   // Parameters
40   //   source - The path to mount from
41   //   target - The path to mount to
42   //   fs_type - File system type of the mount
43   //   mount_flags - Flags spesifying the type of the mount operation
44   //   data - Mount options
45   virtual int Mount(const std::string& source,
46                     const std::string& target,
47                     const std::string& fs_type,
48                     uint64_t mount_flags,
49                     const void* = nullptr);
50 
51   // Checks the file system type of the |path| and returns true if the
52   // filesystem type is nsfs.
53   //
54   // Parameters
55   //   path - The path to check the file system type
56   virtual bool FileSystemIsNsfs(const base::FilePath& path);
57 
58   // Calls the platform waitpid() function and returns the value returned by
59   // waitpid().
60   //
61   // Parameters
62   //   pid - The child pid to be waited on
63   //   status (OUT)- Termination status of a child process.
64   virtual pid_t Waitpid(pid_t pid, int* status);
65 
66   DISALLOW_COPY_AND_ASSIGN(Platform);
67 };
68 
69 }  // namespace brillo
70 
71 #endif  // LIBBRILLO_BRILLO_NAMESPACES_PLATFORM_H_
72