Jed Estep | f1fc48c | 2015-12-15 16:04:53 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 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 | /* |
| 18 | * Provide a series of proxy functions for basic file accessors. |
| 19 | * The behavior of these functions can be changed to return different |
| 20 | * errors under a variety of conditions. |
| 21 | */ |
| 22 | |
| 23 | #ifndef _UPDATER_OTA_IO_H_ |
| 24 | #define _UPDATER_OTA_IO_H_ |
| 25 | |
Tao Bao | ac27a7a | 2017-09-28 17:43:53 -0700 | [diff] [blame^] | 26 | #include <stddef.h> |
Jed Estep | f1fc48c | 2015-12-15 16:04:53 -0800 | [diff] [blame] | 27 | #include <stdio.h> |
Tao Bao | ac27a7a | 2017-09-28 17:43:53 -0700 | [diff] [blame^] | 28 | #include <sys/stat.h> // mode_t |
Jed Estep | f1fc48c | 2015-12-15 16:04:53 -0800 | [diff] [blame] | 29 | |
Tao Bao | 3dc14cb | 2016-11-22 11:37:13 -0800 | [diff] [blame] | 30 | #include <memory> |
| 31 | |
Tao Bao | 6e02ea9 | 2016-11-17 11:24:07 -0800 | [diff] [blame] | 32 | #include <android-base/unique_fd.h> |
| 33 | |
Jed Estep | ff6df89 | 2015-12-15 16:04:53 -0800 | [diff] [blame] | 34 | #define OTAIO_CACHE_FNAME "/cache/saved.file" |
| 35 | |
| 36 | void ota_set_fault_files(); |
| 37 | |
Jed Estep | f1fc48c | 2015-12-15 16:04:53 -0800 | [diff] [blame] | 38 | int ota_open(const char* path, int oflags); |
| 39 | |
| 40 | int ota_open(const char* path, int oflags, mode_t mode); |
| 41 | |
| 42 | FILE* ota_fopen(const char* filename, const char* mode); |
| 43 | |
Jed Estep | f1fc48c | 2015-12-15 16:04:53 -0800 | [diff] [blame] | 44 | size_t ota_fread(void* ptr, size_t size, size_t nitems, FILE* stream); |
| 45 | |
| 46 | ssize_t ota_read(int fd, void* buf, size_t nbyte); |
| 47 | |
| 48 | size_t ota_fwrite(const void* ptr, size_t size, size_t count, FILE* stream); |
| 49 | |
| 50 | ssize_t ota_write(int fd, const void* buf, size_t nbyte); |
| 51 | |
| 52 | int ota_fsync(int fd); |
| 53 | |
Tao Bao | 6e02ea9 | 2016-11-17 11:24:07 -0800 | [diff] [blame] | 54 | struct OtaCloser { |
Tao Bao | 358c2ec | 2016-11-28 11:48:43 -0800 | [diff] [blame] | 55 | static void Close(int); |
Tao Bao | 6e02ea9 | 2016-11-17 11:24:07 -0800 | [diff] [blame] | 56 | }; |
| 57 | |
| 58 | using unique_fd = android::base::unique_fd_impl<OtaCloser>; |
| 59 | |
Tao Bao | 3dc14cb | 2016-11-22 11:37:13 -0800 | [diff] [blame] | 60 | int ota_close(unique_fd& fd); |
| 61 | |
Tao Bao | 358c2ec | 2016-11-28 11:48:43 -0800 | [diff] [blame] | 62 | struct OtaFcloser { |
Mikhail Lappo | b49767c | 2017-03-23 21:44:26 +0100 | [diff] [blame] | 63 | void operator()(FILE*) const; |
Tao Bao | 358c2ec | 2016-11-28 11:48:43 -0800 | [diff] [blame] | 64 | }; |
| 65 | |
| 66 | using unique_file = std::unique_ptr<FILE, OtaFcloser>; |
| 67 | |
| 68 | int ota_fclose(unique_file& fh); |
Tao Bao | 3dc14cb | 2016-11-22 11:37:13 -0800 | [diff] [blame] | 69 | |
Jed Estep | f1fc48c | 2015-12-15 16:04:53 -0800 | [diff] [blame] | 70 | #endif |