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  * Read configuration files in the OTA package to determine which files, if any, will trigger
19  * errors.
20  *
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.
25  *
26  * Example:
27  * ota.zip
28  *   <normal package contents>
29  *   .libotafault
30  *     WRITE
31  *
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.
35  */
36 
37 #ifndef _UPDATER_OTA_IO_CFG_H_
38 #define _UPDATER_OTA_IO_CFG_H_
39 
40 #include <string>
41 
42 #include <ziparchive/zip_archive.h>
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  */
53 void ota_io_init(ZipArchiveHandle zip, bool retry);
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
73