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