Luis Hector Chavez | 81efb33 | 2017-09-18 14:01:29 -0700 | [diff] [blame^] | 1 | // Copyright 2017 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 LIBCONTAINER_LIBCONTAINER_UTIL_H_ |
| 6 | #define LIBCONTAINER_LIBCONTAINER_UTIL_H_ |
| 7 | |
| 8 | #include <string> |
| 9 | |
| 10 | #include <base/files/file_path.h> |
| 11 | |
| 12 | namespace libcontainer { |
| 13 | |
| 14 | // Given a uid/gid map of "inside1 outside1 length1, ...", and an id inside of |
| 15 | // the user namespace, return the equivalent outside id, or return < 0 on error. |
| 16 | int GetUsernsOutsideId(const std::string& map, int id); |
| 17 | |
| 18 | int MakeDir(const base::FilePath& path, int uid, int gid, int mode); |
| 19 | |
| 20 | int TouchFile(const base::FilePath& path, int uid, int gid, int mode); |
| 21 | |
| 22 | // Find a free loop device and attach it. |
| 23 | int LoopdevSetup(const base::FilePath& source, |
| 24 | base::FilePath* loopdev_path_out); |
| 25 | |
| 26 | // Detach the specified loop device. |
| 27 | int LoopdevDetach(const base::FilePath& loopdev); |
| 28 | |
| 29 | // Create a new device mapper target for the source. |
| 30 | int DeviceMapperSetup(const base::FilePath& source, |
| 31 | const std::string& verity_cmdline, |
| 32 | base::FilePath* dm_path_out, |
| 33 | std::string* dm_name_out); |
| 34 | |
| 35 | // Tear down the device mapper target. |
| 36 | int DeviceMapperDetach(const std::string& dm_name); |
| 37 | |
| 38 | // Match mount_one in minijail, mount one mountpoint with |
| 39 | // consideration for combination of MS_BIND/MS_RDONLY flag. |
| 40 | int MountExternal(const std::string& src, |
| 41 | const std::string& dest, |
| 42 | const std::string& type, |
| 43 | unsigned long flags, |
| 44 | const std::string& data); |
| 45 | |
| 46 | } // namespace libcontainer |
| 47 | |
| 48 | #endif // LIBCONTAINER_LIBCONTAINER_UTIL_H_ |