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

Commit 57b23d25 authored by Konstantin Vyshetsky's avatar Konstantin Vyshetsky
Browse files

fastbootd: reset file descriptor on unaligned writes



Writes on file descriptors opened with O_DIRECT will fail if the buffer
is not page aligned. This CL will reset the file descriptor without the
O_DIRECT flag for such instances.

Bug: 225108941
Signed-off-by: default avatarKonstantin Vyshetsky <vkon@google.com>
Change-Id: I841c84f5d2c0b9435b394c48b1bfcc2d51d771bb
parent 1cee2ed2
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -91,6 +91,14 @@ int FlashRawDataChunk(PartitionHandle* handle, const char* data, size_t len) {
    while (ret < len) {
        int this_len = std::min(max_write_size, len - ret);
        memcpy(aligned_buffer_unique_ptr.get(), data, this_len);
        // In case of non 4KB aligned writes, reopen without O_DIRECT flag
        if (this_len & 0xFFF) {
            if (handle->Reset(O_WRONLY) != true) {
                PLOG(ERROR) << "Failed to reset file descriptor";
                return -1;
            }
        }

        int this_ret = write(handle->fd(), aligned_buffer_unique_ptr.get(), this_len);
        if (this_ret < 0) {
            PLOG(ERROR) << "Failed to flash data of len " << len;