blob: 2545f8c2c9cd6f86132b968b2e4d9f9bfa987266 [file] [log] [blame]
# -*- coding: utf-8 -*-
# Copyright (c) 2013 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.
"""Module containing helper methods for mounting and unmounting an image."""
import os
import constants
from chromite.lib import cros_build_lib
def MountImage(image_path, root_dir, stateful_dir, read_only, safe=False):
"""Mounts a Chromium OS image onto mount dir points."""
from_dir, image = os.path.split(image_path)
cmd = ['./mount_gpt_image.sh',
'--from=%s' % from_dir,
'--image=%s' % image,
'--rootfs_mountpt=%s' % root_dir,
'--stateful_mountpt=%s' % stateful_dir]
if read_only: cmd.append('--read_only')
if safe: cmd.append('--safe')
cros_build_lib.RunCommand(
cmd, print_cmd=False, cwd=constants.CROSUTILS_DIR, capture_output=True)
def UnmountImage(root_dir, stateful_dir):
"""Unmounts a Chromium OS image specified by mount dir points."""
cmd = ['./mount_gpt_image.sh', '--unmount', '--rootfs_mountpt=%s' % root_dir,
'--stateful_mountpt=%s' % stateful_dir]
cros_build_lib.RunCommand(
cmd, print_cmd=False, cwd=constants.CROSUTILS_DIR, capture_output=True)