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

Commit a3c47e63 authored by David Anderson's avatar David Anderson
Browse files

liblp: Enable building on Windows.

Bug: 119689480
Test: builds when fastboot.exe uses liblp
Change-Id: I8ba2ad51d806c4650a0f35d41e4906b703d4661d
parent eb1213f1
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -39,6 +39,11 @@ cc_library {
        "libext4_utils",
        "libz",
    ],
    target: {
        windows: {
            enabled: true,
        },
    },
    export_include_dirs: ["include"],
}

+15 −13
Original line number Diff line number Diff line
@@ -27,6 +27,12 @@
namespace android {
namespace fs_mgr {

using android::base::unique_fd;

#if defined(_WIN32)
static const int O_NOFOLLOW = 0;
#endif

std::unique_ptr<LpMetadata> ReadFromImageFile(int fd) {
    std::unique_ptr<uint8_t[]> buffer = std::make_unique<uint8_t[]>(LP_METADATA_GEOMETRY_SIZE);
    if (SeekFile64(fd, 0, SEEK_SET) < 0) {
@@ -62,7 +68,7 @@ std::unique_ptr<LpMetadata> ReadFromImageBlob(const void* data, size_t bytes) {
}

std::unique_ptr<LpMetadata> ReadFromImageFile(const char* file) {
    android::base::unique_fd fd(open(file, O_RDONLY | O_CLOEXEC));
    unique_fd fd(open(file, O_RDONLY | O_CLOEXEC));
    if (fd < 0) {
        PERROR << __PRETTY_FUNCTION__ << " open failed: " << file;
        return nullptr;
@@ -84,7 +90,7 @@ bool WriteToImageFile(int fd, const LpMetadata& input) {
}

bool WriteToImageFile(const char* file, const LpMetadata& input) {
    android::base::unique_fd fd(open(file, O_CREAT | O_RDWR | O_TRUNC | O_CLOEXEC, 0644));
    unique_fd fd(open(file, O_CREAT | O_RDWR | O_TRUNC | O_CLOEXEC, 0644));
    if (fd < 0) {
        PERROR << __PRETTY_FUNCTION__ << " open failed: " << file;
        return false;
@@ -143,7 +149,7 @@ bool SparseBuilder::IsValid() const {
}

bool SparseBuilder::Export(const char* file) {
    android::base::unique_fd fd(open(file, O_CREAT | O_RDWR | O_TRUNC | O_CLOEXEC, 0644));
    unique_fd fd(open(file, O_CREAT | O_RDWR | O_TRUNC | O_CLOEXEC, 0644));
    if (fd < 0) {
        PERROR << "open failed: " << file;
        return false;
@@ -162,19 +168,15 @@ bool SparseBuilder::Export(const char* file) {
}

bool SparseBuilder::ExportFiles(const std::string& output_dir) {
    android::base::unique_fd dir(open(output_dir.c_str(), O_CLOEXEC | O_DIRECTORY | O_NOFOLLOW));
    if (dir < 0) {
        PERROR << "open dir failed: " << output_dir;
        return false;
    }

    for (size_t i = 0; i < device_images_.size(); i++) {
        std::string name = GetBlockDevicePartitionName(metadata_.block_devices[i]);
        std::string path = output_dir + "/super_" + name + ".img";
        android::base::unique_fd fd(openat(
                dir, path.c_str(), O_CREAT | O_RDWR | O_TRUNC | O_CLOEXEC | O_NOFOLLOW, 0644));
        std::string file_name = "super_" + name + ".img";
        std::string file_path = output_dir + "/" + file_name;

        static const int kOpenFlags = O_CREAT | O_RDWR | O_TRUNC | O_CLOEXEC | O_NOFOLLOW;
        unique_fd fd(open(file_path.c_str(), kOpenFlags, 0644));
        if (fd < 0) {
            PERROR << "open failed: " << path;
            PERROR << "open failed: " << file_path;
            return false;
        }
        // No gzip compression; sparseify; no checksum.
+3 −2
Original line number Diff line number Diff line
@@ -19,8 +19,9 @@
#if defined(__linux__)
#include <linux/fs.h>
#endif
#if !defined(_WIN32)
#include <sys/ioctl.h>
#include <sys/stat.h>
#endif
#include <sys/types.h>
#include <unistd.h>

@@ -84,7 +85,7 @@ bool GetBlockDeviceInfo(const std::string& block_device, BlockDeviceInfo* device

unique_fd PartitionOpener::Open(const std::string& partition_name, int flags) const {
    std::string path = GetPartitionAbsolutePath(partition_name);
    return unique_fd{open(path.c_str(), flags)};
    return unique_fd{open(path.c_str(), flags | O_CLOEXEC)};
}

bool PartitionOpener::GetInfo(const std::string& partition_name, BlockDeviceInfo* info) const {
+2 −0
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ namespace android {
namespace fs_mgr {

bool GetDescriptorSize(int fd, uint64_t* size) {
#if !defined(_WIN32)
    struct stat s;
    if (fstat(fd, &s) < 0) {
        PERROR << __PRETTY_FUNCTION__ << "fstat failed";
@@ -39,6 +40,7 @@ bool GetDescriptorSize(int fd, uint64_t* size) {
        *size = get_block_device_size(fd);
        return *size != 0;
    }
#endif

    int64_t result = SeekFile64(fd, 0, SEEK_END);
    if (result == -1) {
+4 −0
Original line number Diff line number Diff line
@@ -235,6 +235,10 @@ static bool DefaultWriter(int fd, const std::string& blob) {
    return android::base::WriteFully(fd, blob.data(), blob.size());
}

#if defined(_WIN32)
static const int O_SYNC = 0;
#endif

bool FlashPartitionTable(const IPartitionOpener& opener, const std::string& super_partition,
                         const LpMetadata& metadata) {
    android::base::unique_fd fd = opener.Open(super_partition, O_RDWR | O_SYNC);