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

Commit e40e90c2 authored by bowgotsai's avatar bowgotsai Committed by android-build-merger
Browse files

Merge "fs_mgr: moves common functions out of fs_mgr_verity.cpp" am: a37ff0dd am: ca11618b

am: bfe74a7a

Change-Id: I148a63c8928db1b198472226b598d981203aab47
parents 07388af1 bfe74a7a
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ LOCAL_CLANG := true
LOCAL_SANITIZE := integer
LOCAL_SRC_FILES:= \
    fs_mgr.c \
    fs_mgr_dm_ioctl.cpp \
    fs_mgr_format.c \
    fs_mgr_fstab.c \
    fs_mgr_slotselect.c \
+11 −0
Original line number Diff line number Diff line
@@ -646,6 +646,17 @@ static int handle_encryptable(const struct fstab_rec* rec)
    }
}

int fs_mgr_test_access(const char *device) {
    int tries = 25;
    while (tries--) {
        if (!access(device, F_OK) || errno != ENOENT) {
            return 0;
        }
        usleep(40 * 1000);
    }
    return -1;
}

/* When multiple fstab records share the same mount_point, it will
 * try to mount each one in turn, and ignore any duplicates after a
 * first successful mount.
+82 −0
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 <sys/ioctl.h>

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

void fs_mgr_verity_ioctl_init(struct dm_ioctl *io, const char *name, unsigned flags)
{
    memset(io, 0, DM_BUF_SIZE);
    io->data_size = DM_BUF_SIZE;
    io->data_start = sizeof(struct dm_ioctl);
    io->version[0] = 4;
    io->version[1] = 0;
    io->version[2] = 0;
    io->flags = flags | DM_READONLY_FLAG;
    if (name) {
        strlcpy(io->name, name, sizeof(io->name));
    }
}

int fs_mgr_create_verity_device(struct dm_ioctl *io, char *name, int fd)
{
    fs_mgr_verity_ioctl_init(io, name, 1);
    if (ioctl(fd, DM_DEV_CREATE, io)) {
        ERROR("Error creating device mapping (%s)", strerror(errno));
        return -1;
    }
    return 0;
}

int fs_mgr_destroy_verity_device(struct dm_ioctl *io, char *name, int fd)
{
    fs_mgr_verity_ioctl_init(io, name, 0);
    if (ioctl(fd, DM_DEV_REMOVE, io)) {
        ERROR("Error removing device mapping (%s)", strerror(errno));
        return -1;
    }
    return 0;
}

int fs_mgr_get_verity_device_name(struct dm_ioctl *io, char *name, int fd, char **dev_name)
{
    fs_mgr_verity_ioctl_init(io, name, 0);
    if (ioctl(fd, DM_DEV_STATUS, io)) {
        ERROR("Error fetching verity device number (%s)", strerror(errno));
        return -1;
    }
    int dev_num = (io->dev & 0xff) | ((io->dev >> 12) & 0xfff00);
    if (asprintf(dev_name, "/dev/block/dm-%u", dev_num) < 0) {
        ERROR("Error getting verity block device name (%s)", strerror(errno));
        return -1;
    }
    return 0;
}

int fs_mgr_resume_verity_table(struct dm_ioctl *io, char *name, int fd)
{
    fs_mgr_verity_ioctl_init(io, name, 0);
    if (ioctl(fd, DM_DEV_SUSPEND, io)) {
        ERROR("Error activating verity device (%s)", strerror(errno));
        return -1;
    }
    return 0;
}
+1 −0
Original line number Diff line number Diff line
@@ -93,6 +93,7 @@ __BEGIN_DECLS
#define DM_BUF_SIZE 4096

int fs_mgr_set_blk_ro(const char *blockdev);
int fs_mgr_test_access(const char *device);
int fs_mgr_update_for_slotselect(struct fstab *fstab);

__END_DECLS
+32 −0
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>

__BEGIN_DECLS

void fs_mgr_verity_ioctl_init(struct dm_ioctl *io, const char *name, unsigned flags);
int fs_mgr_create_verity_device(struct dm_ioctl *io, char *name, int fd);
int fs_mgr_destroy_verity_device(struct dm_ioctl *io, char *name, int fd);
int fs_mgr_get_verity_device_name(struct dm_ioctl *io, char *name, int fd, char **dev_name);
int fs_mgr_resume_verity_table(struct dm_ioctl *io, char *name, int fd);

__END_DECLS

#endif /* __CORE_FS_MGR_PRIV_DM_IOCTL_H */
Loading