blob: cc4bfd2ad107d35fc419fb5938d540b33958560e [file] [log] [blame]
Jed Estepff6df892015-12-15 16:04:53 -08001/*
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 Baoac27a7a2017-09-28 17:43:53 -070018 * Read configuration files in the OTA package to determine which files, if any, will trigger
19 * errors.
Jed Estepff6df892015-12-15 16:04:53 -080020 *
Tao Baoac27a7a2017-09-28 17:43:53 -070021 * 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 Estepff6df892015-12-15 16:04:53 -080025 *
26 * Example:
27 * ota.zip
28 * <normal package contents>
29 * .libotafault
30 * WRITE
31 *
Tao Baoac27a7a2017-09-28 17:43:53 -070032 * 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 Estepff6df892015-12-15 16:04:53 -080035 */
36
37#ifndef _UPDATER_OTA_IO_CFG_H_
38#define _UPDATER_OTA_IO_CFG_H_
39
40#include <string>
41
Tianjie Xu8cf5c8f2016-09-08 20:10:11 -070042#include <ziparchive/zip_archive.h>
Jed Estepff6df892015-12-15 16:04:53 -080043
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 Xu47282422017-01-09 13:45:37 -080053void ota_io_init(ZipArchiveHandle zip, bool retry);
Jed Estepff6df892015-12-15 16:04:53 -080054
55/*
56 * Return true if a config file is present for the given IO type.
57 */
58bool 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 */
64bool should_hit_cache();
65
66/*
67 * Return the name of the file that should cause an error for the
68 * given IO type.
69 */
70std::string fault_fname(const char* io_type);
71
72#endif