Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 51c02c4a authored by David Anderson's avatar David Anderson Committed by android-build-merger
Browse files

Merge changes Ia35a4541,Iaf13450d

am: b27d572d

Change-Id: I6933bb0fe4e3a239068459c2321c849c86d24220
parents 3e854237 b27d572d
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -38,7 +38,6 @@ cc_library_static {
    include_dirs: ["system/vold"],
    srcs: [
        "fs_mgr.cpp",
        "fs_mgr_dm_ioctl.cpp",
        "fs_mgr_format.cpp",
        "fs_mgr_verity.cpp",
        "fs_mgr_avb.cpp",
+12 −21
Original line number Diff line number Diff line
@@ -50,6 +50,7 @@
#include <ext4_utils/ext4_sb.h>
#include <ext4_utils/ext4_utils.h>
#include <ext4_utils/wipe.h>
#include <libdm/dm.h>
#include <linux/fs.h>
#include <linux/loop.h>
#include <linux/magic.h>
@@ -59,7 +60,6 @@
#include "fs_mgr.h"
#include "fs_mgr_avb.h"
#include "fs_mgr_priv.h"
#include "fs_mgr_priv_dm_ioctl.h"

#define KEY_LOC_PROP   "ro.crypto.keyfile.userdata"
#define KEY_IN_FOOTER  "footer"
@@ -76,6 +76,8 @@

#define ARRAY_SIZE(a) (sizeof(a) / sizeof(*(a)))

using DeviceMapper = android::dm::DeviceMapper;

// record fs stat
enum FsStatFlags {
    FS_STAT_IS_EXT4 = 0x0001,
@@ -802,14 +804,9 @@ bool fs_mgr_update_logical_partition(struct fstab_rec* rec) {
        return true;
    }

    android::base::unique_fd dm_fd(open("/dev/device-mapper", O_RDONLY));
    if (dm_fd < 0) {
        PLOG(ERROR) << "open /dev/device-mapper failed";
        return false;
    }
    struct dm_ioctl io;
    DeviceMapper& dm = DeviceMapper::Instance();
    std::string device_name;
    if (!fs_mgr_dm_get_device_name(&io, rec->blk_device, dm_fd, &device_name)) {
    if (!dm.GetDmDevicePathByName(rec->blk_device, &device_name)) {
        return false;
    }
    free(rec->blk_device);
@@ -1369,12 +1366,6 @@ bool fs_mgr_update_verity_state(fs_mgr_verity_state_callback callback) {
        return false;
    }

    android::base::unique_fd fd(TEMP_FAILURE_RETRY(open("/dev/device-mapper", O_RDWR | O_CLOEXEC)));
    if (fd == -1) {
        PERROR << "Error opening device mapper";
        return false;
    }

    std::unique_ptr<fstab, decltype(&fs_mgr_free_fstab)> fstab(fs_mgr_read_fstab_default(),
                                                               fs_mgr_free_fstab);
    if (!fstab) {
@@ -1382,8 +1373,8 @@ bool fs_mgr_update_verity_state(fs_mgr_verity_state_callback callback) {
        return false;
    }

    alignas(dm_ioctl) char buffer[DM_BUF_SIZE];
    struct dm_ioctl* io = (struct dm_ioctl*)buffer;
    DeviceMapper& dm = DeviceMapper::Instance();

    bool system_root = android::base::GetProperty("ro.build.system_root_image", "") == "true";

    for (int i = 0; i < fstab->num_entries; i++) {
@@ -1399,20 +1390,20 @@ bool fs_mgr_update_verity_state(fs_mgr_verity_state_callback callback) {
            mount_point = basename(fstab->recs[i].mount_point);
        }

        fs_mgr_dm_ioctl_init(io, DM_BUF_SIZE, mount_point);
        const char* status = nullptr;

        const char* status;
        if (ioctl(fd, DM_TABLE_STATUS, io)) {
        std::vector<DeviceMapper::TargetInfo> table;
        if (!dm.GetTableStatus(mount_point, &table) || table.empty() || table[0].data.empty()) {
            if (fstab->recs[i].fs_mgr_flags & MF_VERIFYATBOOT) {
                status = "V";
            } else {
                PERROR << "Failed to query DM_TABLE_STATUS for " << mount_point.c_str();
                continue;
            }
        } else {
            status = table[0].data.c_str();
        }

        status = &buffer[io->data_start + sizeof(struct dm_target_spec)];

        // To be consistent in vboot 1.0 and vboot 2.0 (AVB), change the mount_point
        // back to 'system' for the callback. So it has property [partition.system.verified]
        // instead of [partition.vroot.verified].

fs_mgr/fs_mgr_dm_ioctl.cpp

deleted100644 → 0
+0 −79
Original line number Diff line number Diff line
/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <errno.h>
#include <string.h>

#include <android-base/logging.h>
#include <sys/ioctl.h>

#include "fs_mgr_priv.h"
#include "fs_mgr_priv_dm_ioctl.h"

void fs_mgr_dm_ioctl_init(struct dm_ioctl* io, size_t size, const std::string& name) {
    memset(io, 0, size);
    io->data_size = size;
    io->data_start = sizeof(struct dm_ioctl);
    io->version[0] = 4;
    io->version[1] = 0;
    io->version[2] = 0;
    if (!name.empty()) {
        strlcpy(io->name, name.c_str(), sizeof(io->name));
    }
}

bool fs_mgr_dm_create_device(struct dm_ioctl* io, const std::string& name, int fd) {
    fs_mgr_dm_ioctl_init(io, sizeof(*io), name);
    if (ioctl(fd, DM_DEV_CREATE, io)) {
        PERROR << "Error creating device mapping";
        return false;
    }
    return true;
}

bool fs_mgr_dm_destroy_device(struct dm_ioctl* io, const std::string& name, int fd) {
    fs_mgr_dm_ioctl_init(io, sizeof(*io), name);
    if (ioctl(fd, DM_DEV_REMOVE, io)) {
        PERROR << "Error removing device mapping";
        return false;
    }
    return true;
}

bool fs_mgr_dm_get_device_name(struct dm_ioctl* io, const std::string& name, int fd,
                               std::string* out_dev_name) {
    FS_MGR_CHECK(out_dev_name != nullptr);

    fs_mgr_dm_ioctl_init(io, sizeof(*io), name);
    if (ioctl(fd, DM_DEV_STATUS, io)) {
        PERROR << "Error fetching device-mapper device number";
        return false;
    }

    int dev_num = (io->dev & 0xff) | ((io->dev >> 12) & 0xfff00);
    *out_dev_name = "/dev/block/dm-" + std::to_string(dev_num);

    return true;
}

bool fs_mgr_dm_resume_table(struct dm_ioctl* io, const std::string& name, int fd) {
    fs_mgr_dm_ioctl_init(io, sizeof(*io), name);
    if (ioctl(fd, DM_DEV_SUSPEND, io)) {
        PERROR << "Error activating device table";
        return false;
    }
    return true;
}

fs_mgr/fs_mgr_priv_dm_ioctl.h

deleted100644 → 0
+0 −34
Original line number Diff line number Diff line
/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef __CORE_FS_MGR_PRIV_DM_IOCTL_H
#define __CORE_FS_MGR_PRIV_DM_IOCTL_H

#include <linux/dm-ioctl.h>
#include <string>

void fs_mgr_dm_ioctl_init(struct dm_ioctl* io, size_t size, const std::string& name);

bool fs_mgr_dm_create_device(struct dm_ioctl* io, const std::string& name, int fd);

bool fs_mgr_dm_destroy_device(struct dm_ioctl* io, const std::string& name, int fd);

bool fs_mgr_dm_get_device_name(struct dm_ioctl* io, const std::string& name, int fd,
                               std::string* out_dev_name);

bool fs_mgr_dm_resume_table(struct dm_ioctl* io, const std::string& name, int fd);

#endif /* __CORE_FS_MGR_PRIV_DM_IOCTL_H */
+40 −0
Original line number Diff line number Diff line
@@ -272,6 +272,46 @@ bool DeviceMapper::GetDmDevicePathByName(const std::string& name, std::string* p
    return true;
}

bool DeviceMapper::GetTableStatus(const std::string& name, std::vector<TargetInfo>* table) {
    char buffer[4096];
    struct dm_ioctl* io = reinterpret_cast<struct dm_ioctl*>(buffer);

    InitIo(io, name);
    io->data_size = sizeof(buffer);
    io->data_start = sizeof(*io);
    if (ioctl(fd_, DM_TABLE_STATUS, io) < 0) {
        PLOG(ERROR) << "DM_TABLE_STATUS failed for " << name;
        return false;
    }
    if (io->flags & DM_BUFFER_FULL_FLAG) {
        PLOG(ERROR) << "DM_TABLE_STATUS result for " << name << " was too large";
        return false;
    }

    uint32_t cursor = io->data_start;
    uint32_t data_end = std::min(io->data_size, uint32_t(sizeof(buffer)));
    for (uint32_t i = 0; i < io->target_count; i++) {
        if (cursor + sizeof(struct dm_target_spec) > data_end) {
            break;
        }
        // After each dm_target_spec is a status string. spec->next is an
        // offset from |io->data_start|, and we clamp it to the size of our
        // buffer.
        struct dm_target_spec* spec = reinterpret_cast<struct dm_target_spec*>(buffer + cursor);
        uint32_t data_offset = cursor + sizeof(dm_target_spec);
        uint32_t next_cursor = std::min(io->data_start + spec->next, data_end);

        std::string data;
        if (next_cursor > data_offset) {
            // Note: we use c_str() to eliminate any extra trailing 0s.
            data = std::string(buffer + data_offset, next_cursor - data_offset).c_str();
        }
        table->emplace_back(*spec, data);
        cursor = next_cursor;
    }
    return true;
}

// private methods of DeviceMapper
void DeviceMapper::InitIo(struct dm_ioctl* io, const std::string& name) const {
    CHECK(io != nullptr) << "nullptr passed to dm_ioctl initialization";
Loading