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 #include <base/logging.h>
20
21 namespace chromeos_update_engine {
22
Open(const char * path,int flags)23 bool FecFileDescriptor::Open(const char* path, int flags) {
24 return Open(path, flags, 0600);
25 }
26
Open(const char * path,int flags,mode_t mode)27 bool FecFileDescriptor::Open(const char* path, int flags, mode_t mode) {
28 if (!fh_.open(path, flags, mode))
29 return false;
30
31 if (!fh_.has_ecc()) {
32 LOG(ERROR) << "No ECC data in the passed file";
33 fh_.close();
34 return false;
35 }
36
37 fec_status status{};
38 if (!fh_.get_status(status)) {
39 LOG(ERROR) << "Couldn't load ECC status";
40 fh_.close();
41 return false;
42 }
43
44 dev_size_ = status.data_size;
45 return true;
46 }
47
Read(void * buf,size_t count)48 ssize_t FecFileDescriptor::Read(void* buf, size_t count) {
49 return fh_.read(buf, count);
50 }
51
Write(const void * buf,size_t count)52 ssize_t FecFileDescriptor::Write(const void* buf, size_t count) {
53 errno = EROFS;
54 return -1;
55 }
56
Seek(off64_t offset,int whence)57 off64_t FecFileDescriptor::Seek(off64_t offset, int whence) {
58 if (fh_.seek(offset, whence)) {
59 return offset;
60 }
61 return -1;
62 }
63
BlockDevSize()64 uint64_t FecFileDescriptor::BlockDevSize() {
65 return dev_size_;
66 }
67
BlkIoctl(int request,uint64_t start,uint64_t length,int * result)68 bool FecFileDescriptor::BlkIoctl(int request,
69 uint64_t start,
70 uint64_t length,
71 int* result) {
72 // No IOCTL pass-through in this mode.
73 return false;
74 }
75
Close()76 bool FecFileDescriptor::Close() {
77 return fh_.close();
78 }
79
80 } // namespace chromeos_update_engine
81