blob: 01f02e7d7df0cb639a4671f7cd70c85803c35b75 [file] [log] [blame]
// Copyright 2018 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 "cros-disks/fuse_helper.h"
#include <algorithm>
#include <memory>
#include <base/logging.h>
#include "cros-disks/fuse_mounter.h"
#include "cros-disks/mount_options.h"
#include "cros-disks/platform.h"
#include "cros-disks/system_mounter.h"
#include "cros-disks/uri.h"
namespace cros_disks {
const char FUSEHelper::kFilesUser[] = "chronos";
const char FUSEHelper::kFilesGroup[] = "chronos-access";
const char FUSEHelper::kOptionAllowOther[] = "allow_other";
const char FUSEHelper::kOptionDefaultPermissions[] = "default_permissions";
FUSEHelper::FUSEHelper(const std::string& fuse_type,
const Platform* platform,
const base::FilePath& mount_program_path,
const std::string& mount_user)
: fuse_type_(fuse_type),
platform_(platform),
mount_program_path_(mount_program_path),
mount_user_(mount_user) {}
FUSEHelper::~FUSEHelper() = default;
bool FUSEHelper::CanMount(const Uri& source) const {
return source.scheme() == type() && !source.path().empty();
}
std::string FUSEHelper::GetTargetSuffix(const Uri& source) const {
std::string path = source.path();
std::replace(path.begin(), path.end(), '/', '$');
std::replace(path.begin(), path.end(), '.', '_');
return path;
}
std::unique_ptr<FUSEMounter> FUSEHelper::CreateMounter(
const base::FilePath& working_dir,
const Uri& source,
const base::FilePath& target_path,
const std::vector<std::string>& options) const {
MountOptions mount_options;
mount_options.Initialize(options, false, "", "");
return std::make_unique<FUSEMounter>(
source.path(), target_path.value(), type(), mount_options, platform(),
program_path().value(), user(), "", std::vector<std::string>(), false);
}
} // namespace cros_disks