blob: 2c738d9e2dd3f5e0b4e9b0b532720c5fe123aef2 [file] [log] [blame]
Luis Hector Chavez81efb332017-09-18 14:01:29 -07001// 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
12namespace 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.
16int GetUsernsOutsideId(const std::string& map, int id);
17
18int MakeDir(const base::FilePath& path, int uid, int gid, int mode);
19
20int TouchFile(const base::FilePath& path, int uid, int gid, int mode);
21
22// Find a free loop device and attach it.
23int LoopdevSetup(const base::FilePath& source,
24 base::FilePath* loopdev_path_out);
25
26// Detach the specified loop device.
27int LoopdevDetach(const base::FilePath& loopdev);
28
29// Create a new device mapper target for the source.
30int 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.
36int 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.
40int 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_