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

Commit dd55dba8 authored by Daniel Zheng's avatar Daniel Zheng Committed by Automerger Merge Worker
Browse files

Merge "Add binary to write basic COW" into main am: 0fc7feea am: e42df435...

Merge "Add binary to write basic COW" into main am: 0fc7feea am: e42df435 am: a37a965c am: 6daa94d7 am: 29cf5618

Original change: https://android-review.googlesource.com/c/platform/system/core/+/2763849



Change-Id: I55de6cdec0d5fa3d995c7d2b53f07a293e34f8bd
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents facacca6 29cf5618
Loading
Loading
Loading
Loading
+23 −0
Original line number Diff line number Diff line
@@ -20,3 +20,26 @@ cc_binary {

    cflags: ["-Werror"],
}


cc_binary {
    name: "basic_v2_cow_writer",
    host_supported: true,
    defaults: [
        "fs_mgr_defaults",
        "libsnapshot_cow_defaults",
    ],

    srcs: ["basic_v2_cow_writer.cpp"],

    static_libs: [
        "libsnapshot_cow",
    ],

    shared_libs: [
        "libbase",
        "liblog",
    ],

    cflags: ["-Werror"],
}
+48 −0
Original line number Diff line number Diff line
#include <android-base/file.h>
#include <android-base/logging.h>
#include <libsnapshot/cow_compress.h>
#include <libsnapshot/cow_format.h>
#include <libsnapshot/cow_writer.h>
#include <filesystem>

#include "android-base/unique_fd.h"

using namespace android::snapshot;

// This writes a simple cow v2 file in the current directory. This file will serve as testdata for
// ensuring our v3 cow reader will be able to read a cow file created by the v2 writer.
//
// WARNING: We should not be overriding this test file, as it will serve as historic marker for what
// a device with old writer_v2 will write as a cow.
void write_cow_v2() {
    CowOptions options;
    options.cluster_ops = 5;
    options.num_merge_ops = 1;
    std::string data = "This is some data, believe it";
    data.resize(options.block_size, '\0');

    char cwd_buffer[1024];
    size_t cwd_buffer_size = sizeof(cwd_buffer);

    // Get the current working directory path.
    char* err = getcwd(cwd_buffer, cwd_buffer_size);
    if (!err) {
        LOG(ERROR) << "Couldn't get current directory";
    }
    android::base::unique_fd fd(open(strcat(cwd_buffer, "/cow_v2"), O_CREAT | O_RDWR, 0666));
    if (fd.get() == -1) {
        LOG(FATAL) << "couldn't open tmp_cow";
    }
    std::unique_ptr<ICowWriter> writer = CreateCowWriter(2, options, std::move(fd));
    writer->AddCopy(0, 5);
    writer->AddRawBlocks(2, data.data(), data.size());
    writer->AddLabel(1);
    writer->AddXorBlocks(50, data.data(), data.size(), 24, 10);
    writer->AddZeroBlocks(5, 10);
    writer->AddLabel(2);
    writer->Finalize();
}

int main() {
    write_cow_v2();
}
+2.01 MiB

File added.

No diff preview for this file type.