aboutsummaryrefslogtreecommitdiffstats
path: root/brillo/namespaces/platform.h
blob: 6ef6a73d250464d0e59c600de9c22c91615bb002 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Copyright 2020 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef LIBBRILLO_BRILLO_NAMESPACES_PLATFORM_H_
#define LIBBRILLO_BRILLO_NAMESPACES_PLATFORM_H_

#include <sys/types.h>

#include <memory>
#include <string>

#include <base/files/file_path.h>
#include <base/macros.h>
#include <brillo/brillo_export.h>

namespace brillo {
// Platform specific routines abstraction layer.
// Also helps us to be able to mock them in tests.
class BRILLO_EXPORT Platform {
 public:
  Platform();

  virtual ~Platform();
  // Calls the platform fork() function and returns the pid returned
  // by fork().
  virtual pid_t Fork();

  // Calls the platform unmount.
  //
  // Parameters
  //   path - The path to unmount
  //   lazy - Whether to call a lazy unmount
  //   was_busy (OUT) - Set to true on return if the mount point was busy
  virtual bool Unmount(const base::FilePath& path, bool lazy, bool* was_busy);

  // Calls the platform mount.
  //
  // Parameters
  //   source - The path to mount from
  //   target - The path to mount to
  //   fs_type - File system type of the mount
  //   mount_flags - Flags spesifying the type of the mount operation
  //   data - Mount options
  virtual int Mount(const std::string& source,
                    const std::string& target,
                    const std::string& fs_type,
                    uint64_t mount_flags,
                    const void* = nullptr);

  // Checks the file system type of the |path| and returns true if the
  // filesystem type is nsfs.
  //
  // Parameters
  //   path - The path to check the file system type
  virtual bool FileSystemIsNsfs(const base::FilePath& path);

  // Calls the platform waitpid() function and returns the value returned by
  // waitpid().
  //
  // Parameters
  //   pid - The child pid to be waited on
  //   status (OUT)- Termination status of a child process.
  virtual pid_t Waitpid(pid_t pid, int* status);

  DISALLOW_COPY_AND_ASSIGN(Platform);
};

}  // namespace brillo

#endif  // LIBBRILLO_BRILLO_NAMESPACES_PLATFORM_H_