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

Commit e7f492dc authored by Yifan Hong's avatar Yifan Hong
Browse files

liblp: BLKROSET 0 prior to FlashPartitionTable

Test: OTA after cppreopt
Change-Id: I0c611588fac73fbd8d1502cb57481f3363e0cbe8
Fixes: 122487294
parent acf859a8
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -19,6 +19,11 @@
#include <sys/stat.h>
#include <unistd.h>

#if defined(__linux__)
#include <linux/fs.h>
#include <sys/ioctl.h>
#endif

#include <android-base/file.h>
#include <ext4_utils/ext4_utils.h>
#include <openssl/sha.h>
@@ -155,5 +160,16 @@ bool UpdatePartitionGroupName(LpMetadataPartitionGroup* group, const std::string
    return true;
}

bool SetBlockReadonly(int fd, bool readonly) {
#if defined(__linux__)
    int val = readonly;
    return ioctl(fd, BLKROSET, &val) == 0;
#else
    (void)fd;
    (void)readonly;
    return true;
#endif
}

}  // namespace fs_mgr
}  // namespace android
+4 −0
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@
#define LWARN LOG(WARNING) << LP_TAG
#define LINFO LOG(INFO) << LP_TAG
#define LERROR LOG(ERROR) << LP_TAG
#define PWARNING PLOG(WARNING) << LP_TAG
#define PERROR PLOG(ERROR) << LP_TAG

namespace android {
@@ -88,6 +89,9 @@ constexpr uint64_t AlignTo(uint64_t base, uint32_t alignment, uint32_t alignment
bool UpdateBlockDevicePartitionName(LpMetadataBlockDevice* device, const std::string& name);
bool UpdatePartitionGroupName(LpMetadataPartitionGroup* group, const std::string& name);

// Call BLKROSET ioctl on fd so that fd is readonly / read-writable.
bool SetBlockReadonly(int fd, bool readonly);

}  // namespace fs_mgr
}  // namespace android

+6 −0
Original line number Diff line number Diff line
@@ -259,6 +259,12 @@ bool FlashPartitionTable(const IPartitionOpener& opener, const std::string& supe
        return false;
    }

    // On retrofit devices, super_partition is system_other and might be set to readonly by
    // fs_mgr_set_blk_ro(). Unset readonly so that fd can be written to.
    if (!SetBlockReadonly(fd.get(), false)) {
        PWARNING << __PRETTY_FUNCTION__ << " BLKROSET 0 failed: " << super_partition;
    }

    // Write zeroes to the first block.
    std::string zeroes(LP_PARTITION_RESERVED_BYTES, 0);
    if (SeekFile64(fd, 0, SEEK_SET) < 0) {