blob: 3f1d06c557b90c9b93a09edfc455146b68f97158 [file] [log] [blame]
// 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.
// Helper functions used for ChromeOS ConfigFS
#ifndef CHROMEOS_CONFIG_LIBCROS_CONFIG_CONFIGFS_H_
#define CHROMEOS_CONFIG_LIBCROS_CONFIG_CONFIGFS_H_
#include <string>
#include <vector>
namespace base {
class FilePath;
} // namespace base
namespace brillo {
// Constants which correspond to the directories generated by
// cros_config_schema. See go/configfs for the design of the
// filesystem, and what the private and v1 directories correspond to.
extern const char kConfigFSPrivateDirName[];
extern const char kConfigFSV1DirName[];
extern const char kConfigFSIdentityName[];
extern const char kConfigFSPrivateFSType[];
// Prepare the mount path for ConfigFS (e.g., "/config").
// @mount_path: The mount path where ConfigFS is going to be mounted.
// @private_path_out: Output parameter of the path to use for the
// private file tree.
// @v1_path_out: Output parameter of the path to mount version 1 of
// the filesystem (standard path/property config) at.
// @return true on success, false on error.
bool SetupMountPath(const base::FilePath& mount_path,
base::FilePath* private_path_out,
base::FilePath* v1_path_out);
// Setup a loop device.
// @backing_file: Path to the backing file.
// @loop_file_out: Output parameter of the setup loop file.
// @return true on success, false on error.
bool SetupLoopDevice(const base::FilePath& backing_file,
base::FilePath* loop_file_out);
// Wrapper for mount(2) system call.
// @source: Path to source device or image.
// @target: Target directory. Must exist.
// @filesystemtype: Name of filesystem supported by kernel.
// (e.g., "squashfs").
// @mountflags: See mount(2) manual page.
// @options: List of additional options supported by the filesystem.
// @return true on success, false on error.
bool Mount(const base::FilePath& source,
const base::FilePath& target,
const char* filesystemtype,
unsigned long mountflags,
const std::vector<std::string>& options = {});
// Create a bind mount.
// @source: Path to source directory.
// @target: Path to target directory.
// @return true on success, false on error.
bool Bind(const base::FilePath& source, const base::FilePath& target);
// Remount an existing target with new flags and options.
// @target: Path to an already-mounted target.
// @mountflags: See mount(2) manual page.
// @options: List of additional options supported by the filesyste.
// @return true on success, false on error.
bool Remount(const base::FilePath& target,
unsigned long mountflags,
const std::vector<std::string>& options = {});
} // namespace brillo
#endif // CHROMEOS_CONFIG_LIBCROS_CONFIG_CONFIGFS_H_