Jed Estep | ff6df89 | 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 | /* |
Tao Bao | ac27a7a | 2017-09-28 17:43:53 -0700 | [diff] [blame] | 18 | * Read configuration files in the OTA package to determine which files, if any, will trigger |
| 19 | * errors. |
Jed Estep | ff6df89 | 2015-12-15 16:04:53 -0800 | [diff] [blame] | 20 | * |
Tao Bao | ac27a7a | 2017-09-28 17:43:53 -0700 | [diff] [blame] | 21 | * OTA packages can be modified to trigger errors by adding a top-level directory called |
| 22 | * .libotafault, which may optionally contain up to three files called READ, WRITE, and FSYNC. |
| 23 | * Each one of these optional files contains the name of a single file on the device disk which |
| 24 | * will cause an IO error on the first call of the appropriate I/O action to that file. |
Jed Estep | ff6df89 | 2015-12-15 16:04:53 -0800 | [diff] [blame] | 25 | * |
| 26 | * Example: |
| 27 | * ota.zip |
| 28 | * <normal package contents> |
| 29 | * .libotafault |
| 30 | * WRITE |
| 31 | * |
Tao Bao | ac27a7a | 2017-09-28 17:43:53 -0700 | [diff] [blame] | 32 | * If the contents of the file WRITE were /system/build.prop, the first write action to |
| 33 | * /system/build.prop would fail with EIO. Note that READ and FSYNC files are absent, so these |
| 34 | * actions will not cause an error. |
Jed Estep | ff6df89 | 2015-12-15 16:04:53 -0800 | [diff] [blame] | 35 | */ |
| 36 | |
| 37 | #ifndef _UPDATER_OTA_IO_CFG_H_ |
| 38 | #define _UPDATER_OTA_IO_CFG_H_ |
| 39 | |
| 40 | #include <string> |
| 41 | |
Tianjie Xu | 8cf5c8f | 2016-09-08 20:10:11 -0700 | [diff] [blame] | 42 | #include <ziparchive/zip_archive.h> |
Jed Estep | ff6df89 | 2015-12-15 16:04:53 -0800 | [diff] [blame] | 43 | |
| 44 | #define OTAIO_BASE_DIR ".libotafault" |
| 45 | #define OTAIO_READ "READ" |
| 46 | #define OTAIO_WRITE "WRITE" |
| 47 | #define OTAIO_FSYNC "FSYNC" |
| 48 | #define OTAIO_CACHE "CACHE" |
| 49 | |
| 50 | /* |
| 51 | * Initialize libotafault by providing a reference to the OTA package. |
| 52 | */ |
Tianjie Xu | 4728242 | 2017-01-09 13:45:37 -0800 | [diff] [blame] | 53 | void ota_io_init(ZipArchiveHandle zip, bool retry); |
Jed Estep | ff6df89 | 2015-12-15 16:04:53 -0800 | [diff] [blame] | 54 | |
| 55 | /* |
| 56 | * Return true if a config file is present for the given IO type. |
| 57 | */ |
| 58 | bool should_fault_inject(const char* io_type); |
| 59 | |
| 60 | /* |
| 61 | * Return true if an EIO should occur on the next hit to /cache/saved.file |
| 62 | * instead of the next hit to the specified file. |
| 63 | */ |
| 64 | bool should_hit_cache(); |
| 65 | |
| 66 | /* |
| 67 | * Return the name of the file that should cause an error for the |
| 68 | * given IO type. |
| 69 | */ |
| 70 | std::string fault_fname(const char* io_type); |
| 71 | |
| 72 | #endif |