1 // 2 // Copyright (C) 2017 The Android Open Source Project 3 // 4 // Licensed under the Apache License, Version 2.0 (the "License"); 5 // you may not use this file except in compliance with the License. 6 // You may obtain a copy of the License at 7 // 8 // http://www.apache.org/licenses/LICENSE-2.0 9 // 10 // Unless required by applicable law or agreed to in writing, software 11 // distributed under the License is distributed on an "AS IS" BASIS, 12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 // See the License for the specific language governing permissions and 14 // limitations under the License. 15 // 16 17 #include "update_engine/payload_consumer/fec_file_descriptor.h" 18 19 namespace chromeos_update_engine { 20 21 bool FecFileDescriptor::Open(const char* path, int flags) { 22 return Open(path, flags, 0600); 23 } 24 25 bool FecFileDescriptor::Open(const char* path, int flags, mode_t mode) { 26 if (!fh_.open(path, flags, mode)) 27 return false; 28 29 if (!fh_.has_ecc()) { 30 LOG(ERROR) << "No ECC data in the passed file"; 31 fh_.close(); 32 return false; 33 } 34 35 fec_status status; 36 if (!fh_.get_status(status)) { 37 LOG(ERROR) << "Couldn't load ECC status"; 38 fh_.close(); 39 return false; 40 } 41 42 dev_size_ = status.data_size; 43 return true; 44 } 45 46 ssize_t FecFileDescriptor::Read(void* buf, size_t count) { 47 return fh_.read(buf, count); 48 } 49 50 ssize_t FecFileDescriptor::Write(const void* buf, size_t count) { 51 errno = EROFS; 52 return -1; 53 } 54 55 off64_t FecFileDescriptor::Seek(off64_t offset, int whence) { 56 if (fh_.seek(offset, whence)) { 57 return offset; 58 } 59 return -1; 60 } 61 62 uint64_t FecFileDescriptor::BlockDevSize() { 63 return dev_size_; 64 } 65 66 bool FecFileDescriptor::BlkIoctl(int request, 67 uint64_t start, 68 uint64_t length, 69 int* result) { 70 // No IOCTL pass-through in this mode. 71 return false; 72 } 73 74 bool FecFileDescriptor::Close() { 75 return fh_.close(); 76 } 77 78 } // namespace chromeos_update_engine 79