blob: 2c6819569f7930af760d3461eac1583b35469fe2 [file] [log] [blame]
// Copyright (c) 2011 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.
#include <string>
#include <vector>
#include <gtest/gtest_prod.h>
namespace cros_disks {
// A class for querying information about mount points.
class MountInfo {
MountInfo(const MountInfo&) = delete;
MountInfo& operator=(const MountInfo&) = delete;
// Decodes an encoded path by replacing any occurrence of \xxx, a backslash
// followed by an octal number, with an ASCII character of the same octal
// value.
std::string DecodePath(const std::string& encoded_path) const;
// Returns the list of mount paths associated with a given source path.
std::vector<std::string> GetMountPaths(const std::string& source_path) const;
// Returns true if a given mount path is found among the mount points.
bool HasMountPath(const std::string& mount_path) const;
// Retrieves the list of mount points from a given file, which has
// the same format as /proc/self/mountinfo. Returns true on success.
// Refer to <linux source>/Documentation/filesystems/proc.txt for details
// about /proc/self/mountinfo.
bool RetrieveFromFile(const std::string& path);
// Retrieves the list of mount points of the current process by reading
// /proc/self/mountinfo. Returns true on success.
bool RetrieveFromCurrentProcess();
struct MountPointData;
// Converts a 3-character octal string into a decimal integer.
// Returns -1 if the conversion fails.
int ConvertOctalStringToInt(const std::string& octal) const;
// A list of mount points gathered by the last call to RetrieveMountInfo().
std::vector<MountPointData> mount_points_;
FRIEND_TEST(MountInfoTest, ConvertOctalStringToInt);
} // namespace cros_disks