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: Konstantin Vyshetsky <vkon@google.com> Change-Id: I841c84f5d2c0b9435b394c48b1bfcc2d51d771bb
This commit is contained in:
parent
1cee2ed239
commit
57b23d25eb
1 changed files with 8 additions and 0 deletions
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue