blob: dbfa03e9d35fa99536e89f28b38aaf2343c625f6 [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 <utility>
#include <vector>
namespace cros_disks {
// A class for holding and manipulating mount options.
class MountOptions {
static const char kOptionBind[];
static const char kOptionDirSync[];
static const char kOptionFlush[];
static const char kOptionNoDev[];
static const char kOptionNoExec[];
static const char kOptionNoSuid[];
static const char kOptionReadOnly[];
static const char kOptionReadWrite[];
static const char kOptionSynchronous[];
static const char kOptionUtf8[];
MountOptions() {}
~MountOptions() {}
// Initializes the mount options with a list of option strings.
// If set_user_and_group_id is set to true, uid and gid options are set
// if provided.
// If default_user_id is set to a non-empty value, it is added to the
// mount options if no uid option is found in the option strings.
// default_group_id is handled similarly.
void Initialize(const std::vector<std::string>& options,
bool set_user_and_group_id,
const std::string& default_user_id,
const std::string& default_group_id);
// Returns true if the read-only option is set.
bool IsReadOnlyOptionSet() const;
// Forces the read-only option to be set.
void SetReadOnlyOption();
// Converts the mount options into mount flags and data that are used by
// the mount() library call.
std::pair<unsigned long, std::string> ToMountFlagsAndData() const;
// Converts the mount options into a comma-separated string.
std::string ToString() const;
// List of mount options.
std::vector<std::string> options_;
} // namespace cros_disks