Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 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 | |
Tao Bao | 0c7839a | 2016-10-10 15:48:37 -0700 | [diff] [blame] | 17 | #include "updater/install.h" |
| 18 | |
Doug Zongker | fbf3c10 | 2009-06-24 09:36:20 -0700 | [diff] [blame] | 19 | #include <ctype.h> |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 20 | #include <errno.h> |
Tao Bao | 361342c | 2016-02-08 11:15:50 -0800 | [diff] [blame] | 21 | #include <fcntl.h> |
| 22 | #include <ftw.h> |
| 23 | #include <inttypes.h> |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 24 | #include <stdarg.h> |
Doug Zongker | fbf3c10 | 2009-06-24 09:36:20 -0700 | [diff] [blame] | 25 | #include <stdio.h> |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 26 | #include <stdlib.h> |
| 27 | #include <string.h> |
Tao Bao | 361342c | 2016-02-08 11:15:50 -0800 | [diff] [blame] | 28 | #include <sys/capability.h> |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 29 | #include <sys/mount.h> |
| 30 | #include <sys/stat.h> |
| 31 | #include <sys/types.h> |
Doug Zongker | a3f89ea | 2009-09-10 14:10:48 -0700 | [diff] [blame] | 32 | #include <sys/wait.h> |
Nick Kralevich | 5dbdef0 | 2013-09-07 14:41:06 -0700 | [diff] [blame] | 33 | #include <sys/xattr.h> |
Tao Bao | 361342c | 2016-02-08 11:15:50 -0800 | [diff] [blame] | 34 | #include <time.h> |
| 35 | #include <unistd.h> |
Tianjie Xu | 8cf5c8f | 2016-09-08 20:10:11 -0700 | [diff] [blame] | 36 | #include <utime.h> |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 37 | |
Yabin Cui | 64be213 | 2016-02-03 18:16:02 -0800 | [diff] [blame] | 38 | #include <memory> |
Tao Bao | 1bf1772 | 2016-11-03 23:52:01 -0700 | [diff] [blame] | 39 | #include <string> |
Yabin Cui | 64be213 | 2016-02-03 18:16:02 -0800 | [diff] [blame] | 40 | #include <vector> |
| 41 | |
Tao Bao | 1bf1772 | 2016-11-03 23:52:01 -0700 | [diff] [blame] | 42 | #include <android-base/file.h> |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 43 | #include <android-base/logging.h> |
Tianjie Xu | 5fe280a | 2016-10-17 18:15:20 -0700 | [diff] [blame] | 44 | #include <android-base/parsedouble.h> |
Elliott Hughes | 4b166f0 | 2015-12-04 15:30:20 -0800 | [diff] [blame] | 45 | #include <android-base/parseint.h> |
Elliott Hughes | cb22040 | 2016-09-23 15:30:55 -0700 | [diff] [blame] | 46 | #include <android-base/properties.h> |
Elliott Hughes | 4b166f0 | 2015-12-04 15:30:20 -0800 | [diff] [blame] | 47 | #include <android-base/stringprintf.h> |
Tao Bao | d0f3088 | 2016-11-03 23:52:01 -0700 | [diff] [blame] | 48 | #include <android-base/strings.h> |
Tao Bao | 0d3f84f | 2016-12-28 15:09:20 -0800 | [diff] [blame] | 49 | #include <applypatch/applypatch.h> |
| 50 | #include <bootloader_message/bootloader_message.h> |
Tao Bao | 0c7839a | 2016-10-10 15:48:37 -0700 | [diff] [blame] | 51 | #include <cutils/android_reboot.h> |
Tao Bao | de40ba5 | 2016-10-05 23:17:01 -0700 | [diff] [blame] | 52 | #include <ext4_utils/wipe.h> |
Tao Bao | 361342c | 2016-02-08 11:15:50 -0800 | [diff] [blame] | 53 | #include <openssl/sha.h> |
Elliott Hughes | 4bbd5bf | 2016-04-01 18:24:39 -0700 | [diff] [blame] | 54 | #include <selinux/label.h> |
| 55 | #include <selinux/selinux.h> |
Tao Bao | 09e468f | 2017-09-29 14:39:33 -0700 | [diff] [blame] | 56 | #include <tune2fs.h> |
Tianjie Xu | 8cf5c8f | 2016-09-08 20:10:11 -0700 | [diff] [blame] | 57 | #include <ziparchive/zip_archive.h> |
Tao Bao | 1107d96 | 2015-09-09 17:16:55 -0700 | [diff] [blame] | 58 | |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 59 | #include "edify/expr.h" |
Elliott Hughes | 63a3192 | 2016-06-09 17:41:22 -0700 | [diff] [blame] | 60 | #include "mounts.h" |
Ethan Yonker | 8373cfe | 2017-09-08 06:50:54 -0500 | [diff] [blame] | 61 | |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 62 | #include "applypatch/applypatch.h" |
Dees_Troy | 512376c | 2013-09-03 19:39:41 +0000 | [diff] [blame] | 63 | #include "flashutils/flashutils.h" |
Doug Zongker | c9d6e4f | 2014-02-24 16:02:50 -0800 | [diff] [blame] | 64 | #include "install.h" |
Ethan Yonker | 7e1b986 | 2015-03-19 14:10:01 -0500 | [diff] [blame] | 65 | #ifdef HAVE_LIBTUNE2FS |
Michael Runge | b278c25 | 2014-11-21 00:12:28 -0800 | [diff] [blame] | 66 | #include "tune2fs.h" |
Ethan Yonker | 7e1b986 | 2015-03-19 14:10:01 -0500 | [diff] [blame] | 67 | #endif |
Doug Zongker | 8edb00c | 2009-06-11 17:21:44 -0700 | [diff] [blame] | 68 | |
Doug Zongker | 3d177d0 | 2010-07-01 09:18:44 -0700 | [diff] [blame] | 69 | #ifdef USE_EXT4 |
| 70 | #include "make_ext4fs.h" |
Doug Zongker | c9d6e4f | 2014-02-24 16:02:50 -0800 | [diff] [blame] | 71 | #include "wipe.h" |
Doug Zongker | 3d177d0 | 2010-07-01 09:18:44 -0700 | [diff] [blame] | 72 | #endif |
| 73 | |
Tom Marshall | 981118e | 2017-10-25 20:27:08 +0200 | [diff] [blame] | 74 | #include "otautil/ZipUtil.h" |
Tao Bao | d33b2f8 | 2017-09-28 21:29:11 -0700 | [diff] [blame] | 75 | #include "otafault/ota_io.h" |
Tianjie Xu | 8cf5c8f | 2016-09-08 20:10:11 -0700 | [diff] [blame] | 76 | #include "otautil/DirUtil.h" |
Tao Bao | 1fc5bf3 | 2017-10-06 07:43:41 -0700 | [diff] [blame] | 77 | #include "otautil/error_code.h" |
Tao Bao | 09e468f | 2017-09-29 14:39:33 -0700 | [diff] [blame] | 78 | #include "otautil/print_sha1.h" |
Tao Bao | 0c7839a | 2016-10-10 15:48:37 -0700 | [diff] [blame] | 79 | #include "updater/updater.h" |
Doug Zongker | 52b4036 | 2014-02-10 15:30:30 -0800 | [diff] [blame] | 80 | |
Tao Bao | 1107d96 | 2015-09-09 17:16:55 -0700 | [diff] [blame] | 81 | // Send over the buffer to recovery though the command pipe. |
| 82 | static void uiPrint(State* state, const std::string& buffer) { |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 83 | UpdaterInfo* ui = static_cast<UpdaterInfo*>(state->cookie); |
Tao Bao | b6918c7 | 2015-05-19 17:02:16 -0700 | [diff] [blame] | 84 | |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 85 | // "line1\nline2\n" will be split into 3 tokens: "line1", "line2" and "". |
| 86 | // So skip sending empty strings to UI. |
| 87 | std::vector<std::string> lines = android::base::Split(buffer, "\n"); |
| 88 | for (auto& line : lines) { |
| 89 | if (!line.empty()) { |
| 90 | fprintf(ui->cmd_pipe, "ui_print %s\n", line.c_str()); |
Michael Runge | 7548025 | 2014-10-22 19:48:41 -0700 | [diff] [blame] | 91 | } |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 92 | } |
Tao Bao | 1107d96 | 2015-09-09 17:16:55 -0700 | [diff] [blame] | 93 | |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 94 | // On the updater side, we need to dump the contents to stderr (which has |
| 95 | // been redirected to the log file). Because the recovery will only print |
| 96 | // the contents to screen when processing pipe command ui_print. |
| 97 | LOG(INFO) << buffer; |
Michael Runge | 7548025 | 2014-10-22 19:48:41 -0700 | [diff] [blame] | 98 | } |
| 99 | |
Elliott Hughes | 83ce755 | 2016-06-30 09:28:42 -0700 | [diff] [blame] | 100 | void uiPrintf(State* _Nonnull state, const char* _Nonnull format, ...) { |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 101 | std::string error_msg; |
Tao Bao | 1107d96 | 2015-09-09 17:16:55 -0700 | [diff] [blame] | 102 | |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 103 | va_list ap; |
| 104 | va_start(ap, format); |
| 105 | android::base::StringAppendV(&error_msg, format, ap); |
| 106 | va_end(ap); |
Tao Bao | 1107d96 | 2015-09-09 17:16:55 -0700 | [diff] [blame] | 107 | |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 108 | uiPrint(state, error_msg); |
Michael Runge | 7548025 | 2014-10-22 19:48:41 -0700 | [diff] [blame] | 109 | } |
| 110 | |
Tianjie Xu | 5419ad3 | 2018-02-02 16:49:15 -0800 | [diff] [blame] | 111 | // This is the updater side handler for ui_print() in edify script. Contents will be sent over to |
| 112 | // the recovery side for on-screen display. |
| 113 | Value* UIPrintFn(const char* name, State* state, const std::vector<std::unique_ptr<Expr>>& argv) { |
| 114 | std::vector<std::string> args; |
| 115 | if (!ReadArgs(state, argv, &args)) { |
| 116 | return ErrorAbort(state, kArgsParsingFailure, "%s(): Failed to parse the argument(s)", name); |
| 117 | } |
| 118 | |
| 119 | std::string buffer = android::base::Join(args, ""); |
| 120 | uiPrint(state, buffer); |
| 121 | return StringValue(buffer); |
Doug Zongker | 8edb00c | 2009-06-11 17:21:44 -0700 | [diff] [blame] | 122 | } |
| 123 | |
Tianjie Xu | 5419ad3 | 2018-02-02 16:49:15 -0800 | [diff] [blame] | 124 | // package_extract_file(package_file[, dest_file]) |
| 125 | // Extracts a single package_file from the update package and writes it to dest_file, |
| 126 | // overwriting existing files if necessary. Without the dest_file argument, returns the |
| 127 | // contents of the package file as a binary blob. |
| 128 | Value* PackageExtractFileFn(const char* name, State* state, |
| 129 | const std::vector<std::unique_ptr<Expr>>& argv) { |
| 130 | if (argv.size() < 1 || argv.size() > 2) { |
| 131 | return ErrorAbort(state, kArgsParsingFailure, "%s() expects 1 or 2 args, got %zu", name, |
| 132 | argv.size()); |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 133 | } |
Tianjie Xu | 5419ad3 | 2018-02-02 16:49:15 -0800 | [diff] [blame] | 134 | |
| 135 | if (argv.size() == 2) { |
| 136 | // The two-argument version extracts to a file. |
| 137 | |
| 138 | std::vector<std::string> args; |
| 139 | if (!ReadArgs(state, argv, &args)) { |
| 140 | return ErrorAbort(state, kArgsParsingFailure, "%s() Failed to parse %zu args", name, |
| 141 | argv.size()); |
| 142 | } |
| 143 | const std::string& zip_path = args[0]; |
| 144 | const std::string& dest_path = args[1]; |
| 145 | |
| 146 | ZipArchiveHandle za = static_cast<UpdaterInfo*>(state->cookie)->package_zip; |
| 147 | ZipString zip_string_path(zip_path.c_str()); |
| 148 | ZipEntry entry; |
| 149 | if (FindEntry(za, zip_string_path, &entry) != 0) { |
| 150 | LOG(ERROR) << name << ": no " << zip_path << " in package"; |
| 151 | return StringValue(""); |
| 152 | } |
| 153 | |
| 154 | unique_fd fd(TEMP_FAILURE_RETRY( |
| 155 | ota_open(dest_path.c_str(), O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR))); |
| 156 | if (fd == -1) { |
| 157 | PLOG(ERROR) << name << ": can't open " << dest_path << " for write"; |
| 158 | return StringValue(""); |
| 159 | } |
| 160 | |
| 161 | bool success = true; |
| 162 | int32_t ret = ExtractEntryToFile(za, &entry, fd); |
| 163 | if (ret != 0) { |
| 164 | LOG(ERROR) << name << ": Failed to extract entry \"" << zip_path << "\" (" |
| 165 | << entry.uncompressed_length << " bytes) to \"" << dest_path |
| 166 | << "\": " << ErrorCodeString(ret); |
| 167 | success = false; |
| 168 | } |
| 169 | if (ota_fsync(fd) == -1) { |
| 170 | PLOG(ERROR) << "fsync of \"" << dest_path << "\" failed"; |
| 171 | success = false; |
| 172 | } |
| 173 | if (ota_close(fd) == -1) { |
| 174 | PLOG(ERROR) << "close of \"" << dest_path << "\" failed"; |
| 175 | success = false; |
| 176 | } |
| 177 | |
| 178 | return StringValue(success ? "t" : ""); |
| 179 | } else { |
| 180 | // The one-argument version returns the contents of the file as the result. |
| 181 | |
| 182 | std::vector<std::string> args; |
| 183 | if (!ReadArgs(state, argv, &args)) { |
| 184 | return ErrorAbort(state, kArgsParsingFailure, "%s() Failed to parse %zu args", name, |
| 185 | argv.size()); |
| 186 | } |
| 187 | const std::string& zip_path = args[0]; |
| 188 | |
| 189 | ZipArchiveHandle za = static_cast<UpdaterInfo*>(state->cookie)->package_zip; |
| 190 | ZipString zip_string_path(zip_path.c_str()); |
| 191 | ZipEntry entry; |
| 192 | if (FindEntry(za, zip_string_path, &entry) != 0) { |
| 193 | return ErrorAbort(state, kPackageExtractFileFailure, "%s(): no %s in package", name, |
| 194 | zip_path.c_str()); |
| 195 | } |
| 196 | |
| 197 | std::string buffer; |
| 198 | buffer.resize(entry.uncompressed_length); |
| 199 | |
| 200 | int32_t ret = |
| 201 | ExtractToMemory(za, &entry, reinterpret_cast<uint8_t*>(&buffer[0]), buffer.size()); |
| 202 | if (ret != 0) { |
| 203 | return ErrorAbort(state, kPackageExtractFileFailure, |
| 204 | "%s: Failed to extract entry \"%s\" (%zu bytes) to memory: %s", name, |
| 205 | zip_path.c_str(), buffer.size(), ErrorCodeString(ret)); |
| 206 | } |
| 207 | |
| 208 | return new Value(VAL_BLOB, buffer); |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | // apply_patch(src_file, tgt_file, tgt_sha1, tgt_size, patch1_sha1, patch1_blob, [...]) |
| 213 | // Applies a binary patch to the src_file to produce the tgt_file. If the desired target is the |
| 214 | // same as the source, pass "-" for tgt_file. tgt_sha1 and tgt_size are the expected final SHA1 |
| 215 | // hash and size of the target file. The remaining arguments must come in pairs: a SHA1 hash (a |
| 216 | // 40-character hex string) and a blob. The blob is the patch to be applied when the source |
| 217 | // file's current contents have the given SHA1. |
| 218 | // |
| 219 | // The patching is done in a safe manner that guarantees the target file either has the desired |
| 220 | // SHA1 hash and size, or it is untouched -- it will not be left in an unrecoverable intermediate |
| 221 | // state. If the process is interrupted during patching, the target file may be in an intermediate |
| 222 | // state; a copy exists in the cache partition so restarting the update can successfully update |
| 223 | // the file. |
| 224 | Value* ApplyPatchFn(const char* name, State* state, |
| 225 | const std::vector<std::unique_ptr<Expr>>& argv) { |
| 226 | if (argv.size() < 6 || (argv.size() % 2) == 1) { |
| 227 | return ErrorAbort(state, kArgsParsingFailure, |
| 228 | "%s(): expected at least 6 args and an " |
| 229 | "even number, got %zu", |
| 230 | name, argv.size()); |
| 231 | } |
| 232 | |
| 233 | std::vector<std::string> args; |
| 234 | if (!ReadArgs(state, argv, &args, 0, 4)) { |
| 235 | return ErrorAbort(state, kArgsParsingFailure, "%s() Failed to parse the argument(s)", name); |
| 236 | } |
| 237 | const std::string& source_filename = args[0]; |
| 238 | const std::string& target_filename = args[1]; |
| 239 | const std::string& target_sha1 = args[2]; |
| 240 | const std::string& target_size_str = args[3]; |
| 241 | |
| 242 | size_t target_size; |
| 243 | if (!android::base::ParseUint(target_size_str.c_str(), &target_size)) { |
| 244 | return ErrorAbort(state, kArgsParsingFailure, "%s(): can't parse \"%s\" as byte count", name, |
| 245 | target_size_str.c_str()); |
| 246 | } |
| 247 | |
| 248 | int patchcount = (argv.size() - 4) / 2; |
| 249 | std::vector<std::unique_ptr<Value>> arg_values; |
| 250 | if (!ReadValueArgs(state, argv, &arg_values, 4, argv.size() - 4)) { |
| 251 | return nullptr; |
| 252 | } |
| 253 | |
| 254 | for (int i = 0; i < patchcount; ++i) { |
| 255 | if (arg_values[i * 2]->type != VAL_STRING) { |
| 256 | return ErrorAbort(state, kArgsParsingFailure, "%s(): sha-1 #%d is not string", name, i * 2); |
| 257 | } |
| 258 | if (arg_values[i * 2 + 1]->type != VAL_BLOB) { |
| 259 | return ErrorAbort(state, kArgsParsingFailure, "%s(): patch #%d is not blob", name, i * 2 + 1); |
| 260 | } |
| 261 | } |
| 262 | |
| 263 | std::vector<std::string> patch_sha_str; |
| 264 | std::vector<std::unique_ptr<Value>> patches; |
| 265 | for (int i = 0; i < patchcount; ++i) { |
| 266 | patch_sha_str.push_back(arg_values[i * 2]->data); |
| 267 | patches.push_back(std::move(arg_values[i * 2 + 1])); |
| 268 | } |
| 269 | |
| 270 | int result = applypatch(source_filename.c_str(), target_filename.c_str(), target_sha1.c_str(), |
| 271 | target_size, patch_sha_str, patches, nullptr); |
| 272 | |
| 273 | return StringValue(result == 0 ? "t" : ""); |
| 274 | } |
| 275 | |
| 276 | // apply_patch_check(filename, [sha1, ...]) |
| 277 | // Returns true if the contents of filename or the temporary copy in the cache partition (if |
| 278 | // present) have a SHA-1 checksum equal to one of the given sha1 values. sha1 values are |
| 279 | // specified as 40 hex digits. This function differs from sha1_check(read_file(filename), |
| 280 | // sha1 [, ...]) in that it knows to check the cache partition copy, so apply_patch_check() will |
| 281 | // succeed even if the file was corrupted by an interrupted apply_patch() update. |
| 282 | Value* ApplyPatchCheckFn(const char* name, State* state, |
| 283 | const std::vector<std::unique_ptr<Expr>>& argv) { |
| 284 | if (argv.size() < 1) { |
| 285 | return ErrorAbort(state, kArgsParsingFailure, "%s(): expected at least 1 arg, got %zu", name, |
| 286 | argv.size()); |
| 287 | } |
| 288 | |
| 289 | std::vector<std::string> args; |
| 290 | if (!ReadArgs(state, argv, &args, 0, 1)) { |
| 291 | return ErrorAbort(state, kArgsParsingFailure, "%s() Failed to parse the argument(s)", name); |
| 292 | } |
| 293 | const std::string& filename = args[0]; |
| 294 | |
| 295 | std::vector<std::string> sha1s; |
| 296 | if (argv.size() > 1 && !ReadArgs(state, argv, &sha1s, 1, argv.size() - 1)) { |
| 297 | return ErrorAbort(state, kArgsParsingFailure, "%s() Failed to parse the argument(s)", name); |
| 298 | } |
| 299 | int result = applypatch_check(filename.c_str(), sha1s); |
| 300 | |
| 301 | return StringValue(result == 0 ? "t" : ""); |
| 302 | } |
| 303 | |
| 304 | // sha1_check(data) |
| 305 | // to return the sha1 of the data (given in the format returned by |
| 306 | // read_file). |
| 307 | // |
| 308 | // sha1_check(data, sha1_hex, [sha1_hex, ...]) |
| 309 | // returns the sha1 of the file if it matches any of the hex |
| 310 | // strings passed, or "" if it does not equal any of them. |
| 311 | // |
| 312 | Value* Sha1CheckFn(const char* name, State* state, const std::vector<std::unique_ptr<Expr>>& argv) { |
| 313 | if (argv.size() < 1) { |
| 314 | return ErrorAbort(state, kArgsParsingFailure, "%s() expects at least 1 arg", name); |
| 315 | } |
| 316 | |
| 317 | std::vector<std::unique_ptr<Value>> args; |
| 318 | if (!ReadValueArgs(state, argv, &args)) { |
| 319 | return nullptr; |
| 320 | } |
| 321 | |
| 322 | if (args[0]->type == VAL_INVALID) { |
| 323 | return StringValue(""); |
| 324 | } |
| 325 | uint8_t digest[SHA_DIGEST_LENGTH]; |
| 326 | SHA1(reinterpret_cast<const uint8_t*>(args[0]->data.c_str()), args[0]->data.size(), digest); |
| 327 | |
| 328 | if (argv.size() == 1) { |
| 329 | return StringValue(print_sha1(digest)); |
| 330 | } |
| 331 | |
| 332 | for (size_t i = 1; i < argv.size(); ++i) { |
| 333 | uint8_t arg_digest[SHA_DIGEST_LENGTH]; |
| 334 | if (args[i]->type != VAL_STRING) { |
| 335 | LOG(ERROR) << name << "(): arg " << i << " is not a string; skipping"; |
| 336 | } else if (ParseSha1(args[i]->data.c_str(), arg_digest) != 0) { |
| 337 | // Warn about bad args and skip them. |
| 338 | LOG(ERROR) << name << "(): error parsing \"" << args[i]->data << "\" as sha-1; skipping"; |
| 339 | } else if (memcmp(digest, arg_digest, SHA_DIGEST_LENGTH) == 0) { |
| 340 | // Found a match. |
| 341 | return args[i].release(); |
| 342 | } |
| 343 | } |
| 344 | |
| 345 | // Didn't match any of the hex strings; return false. |
| 346 | return StringValue(""); |
Doug Zongker | a23075f | 2012-08-06 16:19:09 -0700 | [diff] [blame] | 347 | } |
Doug Zongker | 8edb00c | 2009-06-11 17:21:44 -0700 | [diff] [blame] | 348 | |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 349 | // mount(fs_type, partition_type, location, mount_point) |
Tao Bao | 0831d0b | 2016-11-03 23:25:04 -0700 | [diff] [blame] | 350 | // mount(fs_type, partition_type, location, mount_point, mount_options) |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 351 | |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 352 | // fs_type="ext4" partition_type="EMMC" location=device |
Tianjie Xu | c444732 | 2017-03-06 14:44:59 -0800 | [diff] [blame] | 353 | Value* MountFn(const char* name, State* state, const std::vector<std::unique_ptr<Expr>>& argv) { |
| 354 | if (argv.size() != 4 && argv.size() != 5) { |
| 355 | return ErrorAbort(state, kArgsParsingFailure, "%s() expects 4-5 args, got %zu", name, |
| 356 | argv.size()); |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | std::vector<std::string> args; |
Tianjie Xu | c444732 | 2017-03-06 14:44:59 -0800 | [diff] [blame] | 360 | if (!ReadArgs(state, argv, &args)) { |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 361 | return ErrorAbort(state, kArgsParsingFailure, "%s() Failed to parse the argument(s)", name); |
| 362 | } |
| 363 | const std::string& fs_type = args[0]; |
| 364 | const std::string& partition_type = args[1]; |
| 365 | const std::string& location = args[2]; |
| 366 | const std::string& mount_point = args[3]; |
| 367 | std::string mount_options; |
| 368 | |
Tianjie Xu | c444732 | 2017-03-06 14:44:59 -0800 | [diff] [blame] | 369 | if (argv.size() == 5) { |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 370 | mount_options = args[4]; |
| 371 | } |
| 372 | |
| 373 | if (fs_type.empty()) { |
| 374 | return ErrorAbort(state, kArgsParsingFailure, "fs_type argument to %s() can't be empty", name); |
| 375 | } |
| 376 | if (partition_type.empty()) { |
| 377 | return ErrorAbort(state, kArgsParsingFailure, "partition_type argument to %s() can't be empty", |
| 378 | name); |
| 379 | } |
| 380 | if (location.empty()) { |
| 381 | return ErrorAbort(state, kArgsParsingFailure, "location argument to %s() can't be empty", name); |
| 382 | } |
| 383 | if (mount_point.empty()) { |
| 384 | return ErrorAbort(state, kArgsParsingFailure, "mount_point argument to %s() can't be empty", |
| 385 | name); |
| 386 | } |
| 387 | |
| 388 | { |
| 389 | char* secontext = nullptr; |
| 390 | |
| 391 | if (sehandle) { |
| 392 | selabel_lookup(sehandle, &secontext, mount_point.c_str(), 0755); |
| 393 | setfscreatecon(secontext); |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 394 | } |
| 395 | |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 396 | mkdir(mount_point.c_str(), 0755); |
Tianjie Xu | 5fe280a | 2016-10-17 18:15:20 -0700 | [diff] [blame] | 397 | |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 398 | if (secontext) { |
| 399 | freecon(secontext); |
| 400 | setfscreatecon(nullptr); |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 401 | } |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 402 | } |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 403 | |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 404 | if (mount(location.c_str(), mount_point.c_str(), fs_type.c_str(), |
| 405 | MS_NOATIME | MS_NODEV | MS_NODIRATIME, mount_options.c_str()) < 0) { |
Tao Bao | 0bbc764 | 2017-03-29 23:57:47 -0700 | [diff] [blame] | 406 | uiPrintf(state, "%s: Failed to mount %s at %s: %s", name, location.c_str(), mount_point.c_str(), |
| 407 | strerror(errno)); |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 408 | return StringValue(""); |
| 409 | } |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 410 | |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 411 | return StringValue(mount_point); |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 412 | } |
| 413 | |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 414 | // is_mounted(mount_point) |
Tianjie Xu | c444732 | 2017-03-06 14:44:59 -0800 | [diff] [blame] | 415 | Value* IsMountedFn(const char* name, State* state, const std::vector<std::unique_ptr<Expr>>& argv) { |
| 416 | if (argv.size() != 1) { |
| 417 | return ErrorAbort(state, kArgsParsingFailure, "%s() expects 1 arg, got %zu", name, argv.size()); |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 418 | } |
Nick Kralevich | 5dbdef0 | 2013-09-07 14:41:06 -0700 | [diff] [blame] | 419 | |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 420 | std::vector<std::string> args; |
Tianjie Xu | c444732 | 2017-03-06 14:44:59 -0800 | [diff] [blame] | 421 | if (!ReadArgs(state, argv, &args)) { |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 422 | return ErrorAbort(state, kArgsParsingFailure, "%s() Failed to parse the argument(s)", name); |
| 423 | } |
| 424 | const std::string& mount_point = args[0]; |
| 425 | if (mount_point.empty()) { |
| 426 | return ErrorAbort(state, kArgsParsingFailure, |
| 427 | "mount_point argument to unmount() can't be empty"); |
| 428 | } |
Nick Kralevich | 5dbdef0 | 2013-09-07 14:41:06 -0700 | [diff] [blame] | 429 | |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 430 | scan_mounted_volumes(); |
| 431 | MountedVolume* vol = find_mounted_volume_by_mount_point(mount_point.c_str()); |
| 432 | if (vol == nullptr) { |
| 433 | return StringValue(""); |
| 434 | } |
Nick Kralevich | 5dbdef0 | 2013-09-07 14:41:06 -0700 | [diff] [blame] | 435 | |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 436 | return StringValue(mount_point); |
Nick Kralevich | 5dbdef0 | 2013-09-07 14:41:06 -0700 | [diff] [blame] | 437 | } |
| 438 | |
Tianjie Xu | c444732 | 2017-03-06 14:44:59 -0800 | [diff] [blame] | 439 | Value* UnmountFn(const char* name, State* state, const std::vector<std::unique_ptr<Expr>>& argv) { |
| 440 | if (argv.size() != 1) { |
| 441 | return ErrorAbort(state, kArgsParsingFailure, "%s() expects 1 arg, got %zu", name, argv.size()); |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 442 | } |
| 443 | std::vector<std::string> args; |
Tianjie Xu | c444732 | 2017-03-06 14:44:59 -0800 | [diff] [blame] | 444 | if (!ReadArgs(state, argv, &args)) { |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 445 | return ErrorAbort(state, kArgsParsingFailure, "%s() Failed to parse the argument(s)", name); |
| 446 | } |
| 447 | const std::string& mount_point = args[0]; |
| 448 | if (mount_point.empty()) { |
| 449 | return ErrorAbort(state, kArgsParsingFailure, |
| 450 | "mount_point argument to unmount() can't be empty"); |
| 451 | } |
Nick Kralevich | 5dbdef0 | 2013-09-07 14:41:06 -0700 | [diff] [blame] | 452 | |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 453 | scan_mounted_volumes(); |
| 454 | MountedVolume* vol = find_mounted_volume_by_mount_point(mount_point.c_str()); |
| 455 | if (vol == nullptr) { |
Tao Bao | 0bbc764 | 2017-03-29 23:57:47 -0700 | [diff] [blame] | 456 | uiPrintf(state, "Failed to unmount %s: No such volume", mount_point.c_str()); |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 457 | return nullptr; |
| 458 | } else { |
| 459 | int ret = unmount_mounted_volume(vol); |
| 460 | if (ret != 0) { |
Tao Bao | 0bbc764 | 2017-03-29 23:57:47 -0700 | [diff] [blame] | 461 | uiPrintf(state, "Failed to unmount %s: %s", mount_point.c_str(), strerror(errno)); |
Nick Kralevich | 6a821fe | 2014-10-23 20:36:42 -0700 | [diff] [blame] | 462 | } |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 463 | } |
Nick Kralevich | 6a821fe | 2014-10-23 20:36:42 -0700 | [diff] [blame] | 464 | |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 465 | return StringValue(mount_point); |
Nick Kralevich | 5dbdef0 | 2013-09-07 14:41:06 -0700 | [diff] [blame] | 466 | } |
| 467 | |
JP Abgrall | 37aedb3 | 2014-06-16 19:07:39 -0700 | [diff] [blame] | 468 | static int exec_cmd(const char* path, char* const argv[]) { |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 469 | pid_t child; |
| 470 | if ((child = vfork()) == 0) { |
| 471 | execv(path, argv); |
Tao Bao | 3da8801 | 2017-02-03 13:09:23 -0800 | [diff] [blame] | 472 | _exit(EXIT_FAILURE); |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 473 | } |
Nick Kralevich | 5dbdef0 | 2013-09-07 14:41:06 -0700 | [diff] [blame] | 474 | |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 475 | int status; |
| 476 | waitpid(child, &status, 0); |
| 477 | if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) { |
| 478 | LOG(ERROR) << path << " failed with status " << WEXITSTATUS(status); |
| 479 | } |
| 480 | return WEXITSTATUS(status); |
Nick Kralevich | 5dbdef0 | 2013-09-07 14:41:06 -0700 | [diff] [blame] | 481 | } |
| 482 | |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 483 | // format(fs_type, partition_type, location, fs_size, mount_point) |
| 484 | // |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 485 | // fs_type="ext4" partition_type="EMMC" location=device fs_size=<bytes> mount_point=<location> |
| 486 | // fs_type="f2fs" partition_type="EMMC" location=device fs_size=<bytes> mount_point=<location> |
JP Abgrall | 37aedb3 | 2014-06-16 19:07:39 -0700 | [diff] [blame] | 487 | // if fs_size == 0, then make fs uses the entire partition. |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 488 | // if fs_size > 0, that is the size to use |
JP Abgrall | 37aedb3 | 2014-06-16 19:07:39 -0700 | [diff] [blame] | 489 | // if fs_size < 0, then reserve that many bytes at the end of the partition (not for "f2fs") |
Tianjie Xu | c444732 | 2017-03-06 14:44:59 -0800 | [diff] [blame] | 490 | Value* FormatFn(const char* name, State* state, const std::vector<std::unique_ptr<Expr>>& argv) { |
| 491 | if (argv.size() != 5) { |
| 492 | return ErrorAbort(state, kArgsParsingFailure, "%s() expects 5 args, got %zu", name, |
| 493 | argv.size()); |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 494 | } |
Nick Kralevich | 5dbdef0 | 2013-09-07 14:41:06 -0700 | [diff] [blame] | 495 | |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 496 | std::vector<std::string> args; |
Tianjie Xu | c444732 | 2017-03-06 14:44:59 -0800 | [diff] [blame] | 497 | if (!ReadArgs(state, argv, &args)) { |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 498 | return ErrorAbort(state, kArgsParsingFailure, "%s() Failed to parse the argument(s)", name); |
| 499 | } |
| 500 | const std::string& fs_type = args[0]; |
| 501 | const std::string& partition_type = args[1]; |
| 502 | const std::string& location = args[2]; |
| 503 | const std::string& fs_size = args[3]; |
| 504 | const std::string& mount_point = args[4]; |
Nick Kralevich | 5dbdef0 | 2013-09-07 14:41:06 -0700 | [diff] [blame] | 505 | |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 506 | if (fs_type.empty()) { |
| 507 | return ErrorAbort(state, kArgsParsingFailure, "fs_type argument to %s() can't be empty", name); |
| 508 | } |
| 509 | if (partition_type.empty()) { |
| 510 | return ErrorAbort(state, kArgsParsingFailure, "partition_type argument to %s() can't be empty", |
| 511 | name); |
| 512 | } |
| 513 | if (location.empty()) { |
| 514 | return ErrorAbort(state, kArgsParsingFailure, "location argument to %s() can't be empty", name); |
| 515 | } |
| 516 | if (mount_point.empty()) { |
| 517 | return ErrorAbort(state, kArgsParsingFailure, "mount_point argument to %s() can't be empty", |
| 518 | name); |
| 519 | } |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 520 | |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 521 | int64_t size; |
| 522 | if (!android::base::ParseInt(fs_size, &size)) { |
Tianjie Xu | 5ad8028 | 2018-01-28 15:37:48 -0800 | [diff] [blame] | 523 | return ErrorAbort(state, kArgsParsingFailure, "%s: failed to parse int in %s", name, |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 524 | fs_size.c_str()); |
| 525 | } |
| 526 | |
| 527 | if (fs_type == "ext4") { |
Jin Qian | ac31808 | 2017-04-21 14:36:12 -0700 | [diff] [blame] | 528 | const char* mke2fs_argv[] = { "/sbin/mke2fs_static", "-t", "ext4", "-b", "4096", |
| 529 | location.c_str(), nullptr, nullptr }; |
| 530 | std::string size_str; |
| 531 | if (size != 0) { |
| 532 | size_str = std::to_string(size / 4096LL); |
| 533 | mke2fs_argv[6] = size_str.c_str(); |
| 534 | } |
| 535 | |
| 536 | int status = exec_cmd(mke2fs_argv[0], const_cast<char**>(mke2fs_argv)); |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 537 | if (status != 0) { |
Jin Qian | 502fd1c | 2017-11-02 11:58:12 -0700 | [diff] [blame] | 538 | LOG(ERROR) << name << ": mke2fs failed (" << status << ") on " << location; |
| 539 | return StringValue(""); |
Jin Qian | ac31808 | 2017-04-21 14:36:12 -0700 | [diff] [blame] | 540 | } |
| 541 | |
Tao Bao | 7af933b | 2017-07-11 16:45:04 -0700 | [diff] [blame] | 542 | const char* e2fsdroid_argv[] = { "/sbin/e2fsdroid_static", "-e", "-a", mount_point.c_str(), |
Jin Qian | ac31808 | 2017-04-21 14:36:12 -0700 | [diff] [blame] | 543 | location.c_str(), nullptr }; |
| 544 | status = exec_cmd(e2fsdroid_argv[0], const_cast<char**>(e2fsdroid_argv)); |
| 545 | if (status != 0) { |
| 546 | LOG(ERROR) << name << ": e2fsdroid failed (" << status << ") on " << location; |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 547 | return StringValue(""); |
Nick Kralevich | 5dbdef0 | 2013-09-07 14:41:06 -0700 | [diff] [blame] | 548 | } |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 549 | return StringValue(location); |
| 550 | } else if (fs_type == "f2fs") { |
| 551 | if (size < 0) { |
| 552 | LOG(ERROR) << name << ": fs_size can't be negative for f2fs: " << fs_size; |
| 553 | return StringValue(""); |
Nick Kralevich | 5dbdef0 | 2013-09-07 14:41:06 -0700 | [diff] [blame] | 554 | } |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 555 | std::string num_sectors = std::to_string(size / 512); |
Nick Kralevich | 5dbdef0 | 2013-09-07 14:41:06 -0700 | [diff] [blame] | 556 | |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 557 | const char* f2fs_path = "/sbin/mkfs.f2fs"; |
Jaegeuk Kim | 1a8bb0f | 2017-11-01 13:24:43 -0700 | [diff] [blame] | 558 | const char* f2fs_argv[] = { "mkfs.f2fs", |
| 559 | "-d1", |
| 560 | "-f", |
Jaegeuk Kim | 2e5dc84 | 2018-04-05 22:42:13 -0700 | [diff] [blame] | 561 | "-O", "encrypt", |
| 562 | "-O", "quota", |
| 563 | "-O", "verity", |
| 564 | "-w", "512", |
Jaegeuk Kim | 1a8bb0f | 2017-11-01 13:24:43 -0700 | [diff] [blame] | 565 | location.c_str(), |
| 566 | (size < 512) ? nullptr : num_sectors.c_str(), |
| 567 | nullptr }; |
Tao Bao | 397a813 | 2017-05-12 11:02:27 -0700 | [diff] [blame] | 568 | int status = exec_cmd(f2fs_path, const_cast<char**>(f2fs_argv)); |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 569 | if (status != 0) { |
| 570 | LOG(ERROR) << name << ": mkfs.f2fs failed (" << status << ") on " << location; |
| 571 | return StringValue(""); |
Nick Kralevich | 5dbdef0 | 2013-09-07 14:41:06 -0700 | [diff] [blame] | 572 | } |
Jaegeuk Kim | c1c7311 | 2017-11-28 19:48:05 -0800 | [diff] [blame] | 573 | |
| 574 | const char* sload_argv[] = { "/sbin/sload.f2fs", "-t", mount_point.c_str(), location.c_str(), |
| 575 | nullptr }; |
| 576 | status = exec_cmd(sload_argv[0], const_cast<char**>(sload_argv)); |
| 577 | if (status != 0) { |
| 578 | LOG(ERROR) << name << ": sload.f2fs failed (" << status << ") on " << location; |
| 579 | return StringValue(""); |
| 580 | } |
| 581 | |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 582 | return StringValue(location); |
| 583 | } else { |
| 584 | LOG(ERROR) << name << ": unsupported fs_type \"" << fs_type << "\" partition_type \"" |
| 585 | << partition_type << "\""; |
| 586 | } |
Nick Kralevich | 5dbdef0 | 2013-09-07 14:41:06 -0700 | [diff] [blame] | 587 | |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 588 | return nullptr; |
Nick Kralevich | 5dbdef0 | 2013-09-07 14:41:06 -0700 | [diff] [blame] | 589 | } |
Doug Zongker | 8edb00c | 2009-06-11 17:21:44 -0700 | [diff] [blame] | 590 | |
Tom Marshall | bf4f24f | 2017-08-23 18:14:00 +0000 | [diff] [blame] | 591 | // rename(src_name, dst_name) |
| 592 | // Renames src_name to dst_name. It automatically creates the necessary directories for dst_name. |
| 593 | // Example: rename("system/app/Hangouts/Hangouts.apk", "system/priv-app/Hangouts/Hangouts.apk") |
| 594 | Value* RenameFn(const char* name, State* state, const std::vector<std::unique_ptr<Expr>>& argv) { |
| 595 | if (argv.size() != 2) { |
| 596 | return ErrorAbort(state, kArgsParsingFailure, "%s() expects 2 args, got %zu", name, |
| 597 | argv.size()); |
| 598 | } |
| 599 | |
| 600 | std::vector<std::string> args; |
| 601 | if (!ReadArgs(state, argv, &args)) { |
| 602 | return ErrorAbort(state, kArgsParsingFailure, "%s() Failed to parse the argument(s)", name); |
| 603 | } |
| 604 | const std::string& src_name = args[0]; |
| 605 | const std::string& dst_name = args[1]; |
| 606 | |
| 607 | if (src_name.empty()) { |
| 608 | return ErrorAbort(state, kArgsParsingFailure, "src_name argument to %s() can't be empty", name); |
| 609 | } |
| 610 | if (dst_name.empty()) { |
| 611 | return ErrorAbort(state, kArgsParsingFailure, "dst_name argument to %s() can't be empty", name); |
| 612 | } |
| 613 | if (!make_parents(dst_name)) { |
| 614 | return ErrorAbort(state, kFileRenameFailure, "Creating parent of %s failed, error %s", |
| 615 | dst_name.c_str(), strerror(errno)); |
| 616 | } else if (access(dst_name.c_str(), F_OK) == 0 && access(src_name.c_str(), F_OK) != 0) { |
| 617 | // File was already moved |
| 618 | return StringValue(dst_name); |
| 619 | } else if (rename(src_name.c_str(), dst_name.c_str()) != 0) { |
| 620 | return ErrorAbort(state, kFileRenameFailure, "Rename of %s to %s failed, error %s", |
| 621 | src_name.c_str(), dst_name.c_str(), strerror(errno)); |
| 622 | } |
| 623 | |
| 624 | return StringValue(dst_name); |
| 625 | } |
| 626 | |
| 627 | // delete([filename, ...]) |
| 628 | // Deletes all the filenames listed. Returns the number of files successfully deleted. |
| 629 | // |
| 630 | // delete_recursive([dirname, ...]) |
| 631 | // Recursively deletes dirnames and all their contents. Returns the number of directories |
| 632 | // successfully deleted. |
| 633 | Value* DeleteFn(const char* name, State* state, const std::vector<std::unique_ptr<Expr>>& argv) { |
| 634 | std::vector<std::string> paths; |
| 635 | if (!ReadArgs(state, argv, &paths)) { |
| 636 | return nullptr; |
| 637 | } |
| 638 | |
| 639 | bool recursive = (strcmp(name, "delete_recursive") == 0); |
| 640 | |
| 641 | int success = 0; |
| 642 | for (const auto& path : paths) { |
| 643 | if ((recursive ? dirUnlinkHierarchy(path.c_str()) : unlink(path.c_str())) == 0) { |
| 644 | ++success; |
| 645 | } |
| 646 | } |
| 647 | |
| 648 | return StringValue(std::to_string(success)); |
| 649 | } |
| 650 | |
| 651 | |
Tianjie Xu | c444732 | 2017-03-06 14:44:59 -0800 | [diff] [blame] | 652 | Value* ShowProgressFn(const char* name, State* state, |
| 653 | const std::vector<std::unique_ptr<Expr>>& argv) { |
| 654 | if (argv.size() != 2) { |
| 655 | return ErrorAbort(state, kArgsParsingFailure, "%s() expects 2 args, got %zu", name, |
| 656 | argv.size()); |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 657 | } |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 658 | |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 659 | std::vector<std::string> args; |
Tianjie Xu | c444732 | 2017-03-06 14:44:59 -0800 | [diff] [blame] | 660 | if (!ReadArgs(state, argv, &args)) { |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 661 | return ErrorAbort(state, kArgsParsingFailure, "%s() Failed to parse the argument(s)", name); |
| 662 | } |
| 663 | const std::string& frac_str = args[0]; |
| 664 | const std::string& sec_str = args[1]; |
Tianjie Xu | 5fe280a | 2016-10-17 18:15:20 -0700 | [diff] [blame] | 665 | |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 666 | double frac; |
| 667 | if (!android::base::ParseDouble(frac_str.c_str(), &frac)) { |
Tianjie Xu | 5ad8028 | 2018-01-28 15:37:48 -0800 | [diff] [blame] | 668 | return ErrorAbort(state, kArgsParsingFailure, "%s: failed to parse double in %s", name, |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 669 | frac_str.c_str()); |
| 670 | } |
| 671 | int sec; |
| 672 | if (!android::base::ParseInt(sec_str.c_str(), &sec)) { |
Tianjie Xu | 5ad8028 | 2018-01-28 15:37:48 -0800 | [diff] [blame] | 673 | return ErrorAbort(state, kArgsParsingFailure, "%s: failed to parse int in %s", name, |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 674 | sec_str.c_str()); |
| 675 | } |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 676 | |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 677 | UpdaterInfo* ui = static_cast<UpdaterInfo*>(state->cookie); |
| 678 | fprintf(ui->cmd_pipe, "progress %f %d\n", frac, sec); |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 679 | |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 680 | return StringValue(frac_str); |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 681 | } |
| 682 | |
Tianjie Xu | 5419ad3 | 2018-02-02 16:49:15 -0800 | [diff] [blame] | 683 | Value* SetProgressFn(const char* name, State* state, |
| 684 | const std::vector<std::unique_ptr<Expr>>& argv) { |
Tianjie Xu | c444732 | 2017-03-06 14:44:59 -0800 | [diff] [blame] | 685 | if (argv.size() != 1) { |
| 686 | return ErrorAbort(state, kArgsParsingFailure, "%s() expects 1 arg, got %zu", name, argv.size()); |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 687 | } |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 688 | |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 689 | std::vector<std::string> args; |
Tianjie Xu | c444732 | 2017-03-06 14:44:59 -0800 | [diff] [blame] | 690 | if (!ReadArgs(state, argv, &args)) { |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 691 | return ErrorAbort(state, kArgsParsingFailure, "%s() Failed to parse the argument(s)", name); |
| 692 | } |
| 693 | const std::string& frac_str = args[0]; |
Tianjie Xu | 5fe280a | 2016-10-17 18:15:20 -0700 | [diff] [blame] | 694 | |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 695 | double frac; |
| 696 | if (!android::base::ParseDouble(frac_str.c_str(), &frac)) { |
Tianjie Xu | 5ad8028 | 2018-01-28 15:37:48 -0800 | [diff] [blame] | 697 | return ErrorAbort(state, kArgsParsingFailure, "%s: failed to parse double in %s", name, |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 698 | frac_str.c_str()); |
| 699 | } |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 700 | |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 701 | UpdaterInfo* ui = static_cast<UpdaterInfo*>(state->cookie); |
| 702 | fprintf(ui->cmd_pipe, "set_progress %f\n", frac); |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 703 | |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 704 | return StringValue(frac_str); |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 705 | } |
| 706 | |
Tom Marshall | 981118e | 2017-10-25 20:27:08 +0200 | [diff] [blame] | 707 | // package_extract_dir(package_dir, dest_dir) |
| 708 | // Extracts all files from the package underneath package_dir and writes them to the |
| 709 | // corresponding tree beneath dest_dir. Any existing files are overwritten. |
| 710 | // Example: package_extract_dir("system", "/system") |
| 711 | // |
| 712 | // Note: package_dir needs to be a relative path; dest_dir needs to be an absolute path. |
| 713 | Value* PackageExtractDirFn(const char* name, State* state, |
| 714 | const std::vector<std::unique_ptr<Expr>>&argv) { |
| 715 | if (argv.size() != 2) { |
| 716 | return ErrorAbort(state, kArgsParsingFailure, "%s() expects 2 args, got %zu", name, |
| 717 | argv.size()); |
| 718 | } |
| 719 | |
| 720 | std::vector<std::string> args; |
| 721 | if (!ReadArgs(state, argv, &args)) { |
| 722 | return ErrorAbort(state, kArgsParsingFailure, "%s() Failed to parse the argument(s)", name); |
| 723 | } |
| 724 | const std::string& zip_path = args[0]; |
| 725 | const std::string& dest_path = args[1]; |
| 726 | |
| 727 | ZipArchiveHandle za = static_cast<UpdaterInfo*>(state->cookie)->package_zip; |
| 728 | |
| 729 | // To create a consistent system image, never use the clock for timestamps. |
| 730 | constexpr struct utimbuf timestamp = { 1217592000, 1217592000 }; // 8/1/2008 default |
| 731 | |
| 732 | bool success = ExtractPackageRecursive(za, zip_path, dest_path, ×tamp, sehandle); |
| 733 | |
| 734 | return StringValue(success ? "t" : ""); |
| 735 | } |
| 736 | |
Tao Bao | ef0eb3b | 2016-11-14 21:29:52 -0800 | [diff] [blame] | 737 | // package_extract_file(package_file[, dest_file]) |
| 738 | // Extracts a single package_file from the update package and writes it to dest_file, |
| 739 | // overwriting existing files if necessary. Without the dest_file argument, returns the |
| 740 | // contents of the package file as a binary blob. |
Tianjie Xu | c444732 | 2017-03-06 14:44:59 -0800 | [diff] [blame] | 741 | Value* PackageExtractFileFn(const char* name, State* state, |
| 742 | const std::vector<std::unique_ptr<Expr>>& argv) { |
| 743 | if (argv.size() < 1 || argv.size() > 2) { |
| 744 | return ErrorAbort(state, kArgsParsingFailure, "%s() expects 1 or 2 args, got %zu", name, |
| 745 | argv.size()); |
Tao Bao | ef0eb3b | 2016-11-14 21:29:52 -0800 | [diff] [blame] | 746 | } |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 747 | |
Tianjie Xu | c444732 | 2017-03-06 14:44:59 -0800 | [diff] [blame] | 748 | if (argv.size() == 2) { |
Tao Bao | ef0eb3b | 2016-11-14 21:29:52 -0800 | [diff] [blame] | 749 | // The two-argument version extracts to a file. |
| 750 | |
| 751 | std::vector<std::string> args; |
Tianjie Xu | c444732 | 2017-03-06 14:44:59 -0800 | [diff] [blame] | 752 | if (!ReadArgs(state, argv, &args)) { |
| 753 | return ErrorAbort(state, kArgsParsingFailure, "%s() Failed to parse %zu args", name, |
| 754 | argv.size()); |
Doug Zongker | 8edb00c | 2009-06-11 17:21:44 -0700 | [diff] [blame] | 755 | } |
Tao Bao | ef0eb3b | 2016-11-14 21:29:52 -0800 | [diff] [blame] | 756 | const std::string& zip_path = args[0]; |
| 757 | const std::string& dest_path = args[1]; |
Doug Zongker | 8edb00c | 2009-06-11 17:21:44 -0700 | [diff] [blame] | 758 | |
Tao Bao | ef0eb3b | 2016-11-14 21:29:52 -0800 | [diff] [blame] | 759 | ZipArchiveHandle za = static_cast<UpdaterInfo*>(state->cookie)->package_zip; |
| 760 | ZipString zip_string_path(zip_path.c_str()); |
| 761 | ZipEntry entry; |
| 762 | if (FindEntry(za, zip_string_path, &entry) != 0) { |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 763 | LOG(ERROR) << name << ": no " << zip_path << " in package"; |
Tao Bao | ef0eb3b | 2016-11-14 21:29:52 -0800 | [diff] [blame] | 764 | return StringValue(""); |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 765 | } |
Doug Zongker | 8edb00c | 2009-06-11 17:21:44 -0700 | [diff] [blame] | 766 | |
Tao Bao | 358c2ec | 2016-11-28 11:48:43 -0800 | [diff] [blame] | 767 | unique_fd fd(TEMP_FAILURE_RETRY( |
| 768 | ota_open(dest_path.c_str(), O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR))); |
Tao Bao | ef0eb3b | 2016-11-14 21:29:52 -0800 | [diff] [blame] | 769 | if (fd == -1) { |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 770 | PLOG(ERROR) << name << ": can't open " << dest_path << " for write"; |
Tao Bao | ef0eb3b | 2016-11-14 21:29:52 -0800 | [diff] [blame] | 771 | return StringValue(""); |
| 772 | } |
| 773 | |
| 774 | bool success = true; |
| 775 | int32_t ret = ExtractEntryToFile(za, &entry, fd); |
| 776 | if (ret != 0) { |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 777 | LOG(ERROR) << name << ": Failed to extract entry \"" << zip_path << "\" (" |
| 778 | << entry.uncompressed_length << " bytes) to \"" << dest_path |
| 779 | << "\": " << ErrorCodeString(ret); |
Tao Bao | ef0eb3b | 2016-11-14 21:29:52 -0800 | [diff] [blame] | 780 | success = false; |
| 781 | } |
| 782 | if (ota_fsync(fd) == -1) { |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 783 | PLOG(ERROR) << "fsync of \"" << dest_path << "\" failed"; |
Tao Bao | ef0eb3b | 2016-11-14 21:29:52 -0800 | [diff] [blame] | 784 | success = false; |
| 785 | } |
| 786 | if (ota_close(fd) == -1) { |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 787 | PLOG(ERROR) << "close of \"" << dest_path << "\" failed"; |
Tao Bao | ef0eb3b | 2016-11-14 21:29:52 -0800 | [diff] [blame] | 788 | success = false; |
| 789 | } |
| 790 | |
| 791 | return StringValue(success ? "t" : ""); |
| 792 | } else { |
| 793 | // The one-argument version returns the contents of the file as the result. |
| 794 | |
| 795 | std::vector<std::string> args; |
Tianjie Xu | c444732 | 2017-03-06 14:44:59 -0800 | [diff] [blame] | 796 | if (!ReadArgs(state, argv, &args)) { |
| 797 | return ErrorAbort(state, kArgsParsingFailure, "%s() Failed to parse %zu args", name, |
| 798 | argv.size()); |
Tao Bao | ef0eb3b | 2016-11-14 21:29:52 -0800 | [diff] [blame] | 799 | } |
| 800 | const std::string& zip_path = args[0]; |
| 801 | |
| 802 | ZipArchiveHandle za = static_cast<UpdaterInfo*>(state->cookie)->package_zip; |
| 803 | ZipString zip_string_path(zip_path.c_str()); |
| 804 | ZipEntry entry; |
| 805 | if (FindEntry(za, zip_string_path, &entry) != 0) { |
| 806 | return ErrorAbort(state, kPackageExtractFileFailure, "%s(): no %s in package", name, |
| 807 | zip_path.c_str()); |
| 808 | } |
| 809 | |
| 810 | std::string buffer; |
| 811 | buffer.resize(entry.uncompressed_length); |
| 812 | |
| 813 | int32_t ret = ExtractToMemory(za, &entry, reinterpret_cast<uint8_t*>(&buffer[0]), buffer.size()); |
| 814 | if (ret != 0) { |
| 815 | return ErrorAbort(state, kPackageExtractFileFailure, |
| 816 | "%s: Failed to extract entry \"%s\" (%zu bytes) to memory: %s", name, |
| 817 | zip_path.c_str(), buffer.size(), ErrorCodeString(ret)); |
| 818 | } |
| 819 | |
| 820 | return new Value(VAL_BLOB, buffer); |
| 821 | } |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 822 | } |
| 823 | |
Tom Marshall | bf4f24f | 2017-08-23 18:14:00 +0000 | [diff] [blame] | 824 | // symlink(target, [src1, src2, ...]) |
| 825 | // Creates all sources as symlinks to target. It unlinks any previously existing src1, src2, etc |
| 826 | // before creating symlinks. |
| 827 | Value* SymlinkFn(const char* name, State* state, const std::vector<std::unique_ptr<Expr>>& argv) { |
| 828 | if (argv.size() == 0) { |
| 829 | return ErrorAbort(state, kArgsParsingFailure, "%s() expects 1+ args, got %zu", name, argv.size()); |
| 830 | } |
| 831 | std::string target; |
| 832 | if (!Evaluate(state, argv[0], &target)) { |
| 833 | return nullptr; |
| 834 | } |
| 835 | |
| 836 | std::vector<std::string> srcs; |
| 837 | if (!ReadArgs(state, argv, &srcs, 1, argv.size())) { |
| 838 | return ErrorAbort(state, kArgsParsingFailure, "%s(): Failed to parse the argument(s)", name); |
| 839 | } |
| 840 | |
| 841 | size_t bad = 0; |
| 842 | for (const auto& src : srcs) { |
| 843 | if (unlink(src.c_str()) == -1 && errno != ENOENT) { |
| 844 | PLOG(ERROR) << name << ": failed to remove " << src; |
| 845 | ++bad; |
| 846 | } else if (!make_parents(src)) { |
| 847 | LOG(ERROR) << name << ": failed to symlink " << src << " to " << target |
| 848 | << ": making parents failed"; |
| 849 | ++bad; |
| 850 | } else if (symlink(target.c_str(), src.c_str()) == -1) { |
| 851 | PLOG(ERROR) << name << ": failed to symlink " << src << " to " << target; |
| 852 | ++bad; |
| 853 | } |
| 854 | } |
| 855 | if (bad != 0) { |
| 856 | return ErrorAbort(state, kSymlinkFailure, "%s: Failed to create %zu symlink(s)", name, bad); |
| 857 | } |
| 858 | return StringValue("t"); |
| 859 | } |
| 860 | |
| 861 | struct perm_parsed_args { |
| 862 | bool has_uid; |
| 863 | uid_t uid; |
| 864 | bool has_gid; |
| 865 | gid_t gid; |
| 866 | bool has_mode; |
| 867 | mode_t mode; |
| 868 | bool has_fmode; |
| 869 | mode_t fmode; |
| 870 | bool has_dmode; |
| 871 | mode_t dmode; |
| 872 | bool has_selabel; |
| 873 | const char* selabel; |
| 874 | bool has_capabilities; |
| 875 | uint64_t capabilities; |
| 876 | }; |
| 877 | |
| 878 | static struct perm_parsed_args ParsePermArgs(State * state, |
| 879 | const std::vector<std::string>& args) { |
| 880 | struct perm_parsed_args parsed; |
| 881 | int bad = 0; |
| 882 | static int max_warnings = 20; |
| 883 | |
| 884 | memset(&parsed, 0, sizeof(parsed)); |
| 885 | |
| 886 | for (size_t i = 1; i < args.size(); i += 2) { |
| 887 | if (args[i] == "uid") { |
| 888 | int64_t uid; |
| 889 | if (sscanf(args[i + 1].c_str(), "%" SCNd64, &uid) == 1) { |
| 890 | parsed.uid = uid; |
| 891 | parsed.has_uid = true; |
| 892 | } else { |
| 893 | uiPrintf(state, "ParsePermArgs: invalid UID \"%s\"\n", args[i + 1].c_str()); |
| 894 | bad++; |
| 895 | } |
| 896 | continue; |
| 897 | } |
| 898 | if (args[i] == "gid") { |
| 899 | int64_t gid; |
| 900 | if (sscanf(args[i + 1].c_str(), "%" SCNd64, &gid) == 1) { |
| 901 | parsed.gid = gid; |
| 902 | parsed.has_gid = true; |
| 903 | } else { |
| 904 | uiPrintf(state, "ParsePermArgs: invalid GID \"%s\"\n", args[i + 1].c_str()); |
| 905 | bad++; |
| 906 | } |
| 907 | continue; |
| 908 | } |
| 909 | if (args[i] == "mode") { |
| 910 | int32_t mode; |
| 911 | if (sscanf(args[i + 1].c_str(), "%" SCNi32, &mode) == 1) { |
| 912 | parsed.mode = mode; |
| 913 | parsed.has_mode = true; |
| 914 | } else { |
| 915 | uiPrintf(state, "ParsePermArgs: invalid mode \"%s\"\n", args[i + 1].c_str()); |
| 916 | bad++; |
| 917 | } |
| 918 | continue; |
| 919 | } |
| 920 | if (args[i] == "dmode") { |
| 921 | int32_t mode; |
| 922 | if (sscanf(args[i + 1].c_str(), "%" SCNi32, &mode) == 1) { |
| 923 | parsed.dmode = mode; |
| 924 | parsed.has_dmode = true; |
| 925 | } else { |
| 926 | uiPrintf(state, "ParsePermArgs: invalid dmode \"%s\"\n", args[i + 1].c_str()); |
| 927 | bad++; |
| 928 | } |
| 929 | continue; |
| 930 | } |
| 931 | if (args[i] == "fmode") { |
| 932 | int32_t mode; |
| 933 | if (sscanf(args[i + 1].c_str(), "%" SCNi32, &mode) == 1) { |
| 934 | parsed.fmode = mode; |
| 935 | parsed.has_fmode = true; |
| 936 | } else { |
| 937 | uiPrintf(state, "ParsePermArgs: invalid fmode \"%s\"\n", args[i + 1].c_str()); |
| 938 | bad++; |
| 939 | } |
| 940 | continue; |
| 941 | } |
| 942 | if (args[i] == "capabilities") { |
| 943 | int64_t capabilities; |
| 944 | if (sscanf(args[i + 1].c_str(), "%" SCNi64, &capabilities) == 1) { |
| 945 | parsed.capabilities = capabilities; |
| 946 | parsed.has_capabilities = true; |
| 947 | } else { |
| 948 | uiPrintf(state, "ParsePermArgs: invalid capabilities \"%s\"\n", args[i + 1].c_str()); |
| 949 | bad++; |
| 950 | } |
| 951 | continue; |
| 952 | } |
| 953 | if (args[i] == "selabel") { |
| 954 | if (!args[i + 1].empty()) { |
| 955 | parsed.selabel = args[i + 1].c_str(); |
| 956 | parsed.has_selabel = true; |
| 957 | } else { |
| 958 | uiPrintf(state, "ParsePermArgs: invalid selabel \"%s\"\n", args[i + 1].c_str()); |
| 959 | bad++; |
| 960 | } |
| 961 | continue; |
| 962 | } |
| 963 | if (max_warnings != 0) { |
| 964 | printf("ParsedPermArgs: unknown key \"%s\", ignoring\n", args[i].c_str()); |
| 965 | max_warnings--; |
| 966 | if (max_warnings == 0) { |
| 967 | LOG(INFO) << "ParsedPermArgs: suppressing further warnings"; |
| 968 | } |
| 969 | } |
| 970 | } |
| 971 | return parsed; |
| 972 | } |
| 973 | |
| 974 | static int ApplyParsedPerms(State* state, const char* filename, const struct stat* statptr, |
| 975 | struct perm_parsed_args parsed) { |
| 976 | int bad = 0; |
| 977 | |
| 978 | if (parsed.has_selabel) { |
| 979 | if (lsetfilecon(filename, parsed.selabel) != 0) { |
| 980 | uiPrintf(state, "ApplyParsedPerms: lsetfilecon of %s to %s failed: %s\n", filename, |
| 981 | parsed.selabel, strerror(errno)); |
| 982 | bad++; |
| 983 | } |
| 984 | } |
| 985 | |
| 986 | /* ignore symlinks */ |
| 987 | if (S_ISLNK(statptr->st_mode)) { |
| 988 | return bad; |
| 989 | } |
| 990 | |
| 991 | if (parsed.has_uid) { |
| 992 | if (chown(filename, parsed.uid, -1) < 0) { |
| 993 | uiPrintf(state, "ApplyParsedPerms: chown of %s to %d failed: %s\n", filename, parsed.uid, |
| 994 | strerror(errno)); |
| 995 | bad++; |
| 996 | } |
| 997 | } |
| 998 | |
| 999 | if (parsed.has_gid) { |
| 1000 | if (chown(filename, -1, parsed.gid) < 0) { |
| 1001 | uiPrintf(state, "ApplyParsedPerms: chgrp of %s to %d failed: %s\n", filename, parsed.gid, |
| 1002 | strerror(errno)); |
| 1003 | bad++; |
| 1004 | } |
| 1005 | } |
| 1006 | |
| 1007 | if (parsed.has_mode) { |
| 1008 | if (chmod(filename, parsed.mode) < 0) { |
| 1009 | uiPrintf(state, "ApplyParsedPerms: chmod of %s to %d failed: %s\n", filename, parsed.mode, |
| 1010 | strerror(errno)); |
| 1011 | bad++; |
| 1012 | } |
| 1013 | } |
| 1014 | |
| 1015 | if (parsed.has_dmode && S_ISDIR(statptr->st_mode)) { |
| 1016 | if (chmod(filename, parsed.dmode) < 0) { |
| 1017 | uiPrintf(state, "ApplyParsedPerms: chmod of %s to %d failed: %s\n", filename, parsed.dmode, |
| 1018 | strerror(errno)); |
| 1019 | bad++; |
| 1020 | } |
| 1021 | } |
| 1022 | |
| 1023 | if (parsed.has_fmode && S_ISREG(statptr->st_mode)) { |
| 1024 | if (chmod(filename, parsed.fmode) < 0) { |
| 1025 | uiPrintf(state, "ApplyParsedPerms: chmod of %s to %d failed: %s\n", filename, parsed.fmode, |
| 1026 | strerror(errno)); |
| 1027 | bad++; |
| 1028 | } |
| 1029 | } |
| 1030 | |
| 1031 | if (parsed.has_capabilities && S_ISREG(statptr->st_mode)) { |
| 1032 | if (parsed.capabilities == 0) { |
| 1033 | if ((removexattr(filename, XATTR_NAME_CAPS) == -1) && (errno != ENODATA)) { |
| 1034 | // Report failure unless it's ENODATA (attribute not set) |
| 1035 | uiPrintf(state, "ApplyParsedPerms: removexattr of %s to %" PRIx64 " failed: %s\n", filename, |
| 1036 | parsed.capabilities, strerror(errno)); |
| 1037 | bad++; |
| 1038 | } |
| 1039 | } else { |
| 1040 | struct vfs_cap_data cap_data; |
| 1041 | memset(&cap_data, 0, sizeof(cap_data)); |
| 1042 | cap_data.magic_etc = VFS_CAP_REVISION | VFS_CAP_FLAGS_EFFECTIVE; |
| 1043 | cap_data.data[0].permitted = (uint32_t)(parsed.capabilities & 0xffffffff); |
| 1044 | cap_data.data[0].inheritable = 0; |
| 1045 | cap_data.data[1].permitted = (uint32_t)(parsed.capabilities >> 32); |
| 1046 | cap_data.data[1].inheritable = 0; |
| 1047 | if (setxattr(filename, XATTR_NAME_CAPS, &cap_data, sizeof(cap_data), 0) < 0) { |
| 1048 | uiPrintf(state, "ApplyParsedPerms: setcap of %s to %" PRIx64 " failed: %s\n", filename, |
| 1049 | parsed.capabilities, strerror(errno)); |
| 1050 | bad++; |
| 1051 | } |
| 1052 | } |
| 1053 | } |
| 1054 | |
| 1055 | return bad; |
| 1056 | } |
| 1057 | |
| 1058 | // nftw doesn't allow us to pass along context, so we need to use |
| 1059 | // global variables. *sigh* |
| 1060 | static struct perm_parsed_args recursive_parsed_args; |
| 1061 | static State* recursive_state; |
| 1062 | |
| 1063 | static int do_SetMetadataRecursive(const char* filename, const struct stat* statptr, int fileflags, |
| 1064 | struct FTW* pfwt) { |
| 1065 | return ApplyParsedPerms(recursive_state, filename, statptr, recursive_parsed_args); |
| 1066 | } |
| 1067 | |
| 1068 | static Value* SetMetadataFn(const char* name, State* state, const std::vector<std::unique_ptr<Expr>>& argv) { |
| 1069 | if ((argv.size() % 2) != 1) { |
| 1070 | return ErrorAbort(state, kArgsParsingFailure, "%s() expects an odd number of arguments, got %zu", |
| 1071 | name, argv.size()); |
| 1072 | } |
| 1073 | |
| 1074 | std::vector<std::string> args; |
| 1075 | if (!ReadArgs(state, argv, &args)) { |
| 1076 | return ErrorAbort(state, kArgsParsingFailure, "%s() Failed to parse the argument(s)", name); |
| 1077 | } |
| 1078 | |
| 1079 | struct stat sb; |
| 1080 | if (lstat(args[0].c_str(), &sb) == -1) { |
| 1081 | return ErrorAbort(state, kSetMetadataFailure, "%s: Error on lstat of \"%s\": %s", name, |
| 1082 | args[0].c_str(), strerror(errno)); |
| 1083 | } |
| 1084 | |
| 1085 | struct perm_parsed_args parsed = ParsePermArgs(state, args); |
| 1086 | int bad = 0; |
| 1087 | bool recursive = (strcmp(name, "set_metadata_recursive") == 0); |
| 1088 | |
| 1089 | if (recursive) { |
| 1090 | recursive_parsed_args = parsed; |
| 1091 | recursive_state = state; |
| 1092 | bad += nftw(args[0].c_str(), do_SetMetadataRecursive, 30, FTW_CHDIR | FTW_DEPTH | FTW_PHYS); |
| 1093 | memset(&recursive_parsed_args, 0, sizeof(recursive_parsed_args)); |
| 1094 | recursive_state = NULL; |
| 1095 | } else { |
| 1096 | bad += ApplyParsedPerms(state, args[0].c_str(), &sb, parsed); |
| 1097 | } |
| 1098 | |
| 1099 | if (bad > 0) { |
| 1100 | return ErrorAbort(state, kSetMetadataFailure, "%s: some changes failed", name); |
| 1101 | } |
| 1102 | |
| 1103 | return StringValue(""); |
| 1104 | } |
| 1105 | |
Tianjie Xu | c444732 | 2017-03-06 14:44:59 -0800 | [diff] [blame] | 1106 | Value* GetPropFn(const char* name, State* state, const std::vector<std::unique_ptr<Expr>>& argv) { |
| 1107 | if (argv.size() != 1) { |
| 1108 | return ErrorAbort(state, kArgsParsingFailure, "%s() expects 1 arg, got %zu", name, argv.size()); |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 1109 | } |
| 1110 | std::string key; |
| 1111 | if (!Evaluate(state, argv[0], &key)) { |
| 1112 | return nullptr; |
| 1113 | } |
| 1114 | std::string value = android::base::GetProperty(key, ""); |
Doug Zongker | 8edb00c | 2009-06-11 17:21:44 -0700 | [diff] [blame] | 1115 | |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 1116 | return StringValue(value); |
Doug Zongker | 8edb00c | 2009-06-11 17:21:44 -0700 | [diff] [blame] | 1117 | } |
| 1118 | |
Doug Zongker | 47cace9 | 2009-06-18 10:11:50 -0700 | [diff] [blame] | 1119 | // file_getprop(file, key) |
| 1120 | // |
| 1121 | // interprets 'file' as a getprop-style file (key=value pairs, one |
Tao Bao | 51d516e | 2016-11-03 14:49:01 -0700 | [diff] [blame] | 1122 | // per line. # comment lines, blank lines, lines without '=' ignored), |
Michael Runge | aa1a31e | 2014-04-25 18:47:18 -0700 | [diff] [blame] | 1123 | // and returns the value for 'key' (or "" if it isn't defined). |
Tianjie Xu | 5419ad3 | 2018-02-02 16:49:15 -0800 | [diff] [blame] | 1124 | Value* FileGetPropFn(const char* name, State* state, |
| 1125 | const std::vector<std::unique_ptr<Expr>>& argv) { |
Tianjie Xu | c444732 | 2017-03-06 14:44:59 -0800 | [diff] [blame] | 1126 | if (argv.size() != 2) { |
| 1127 | return ErrorAbort(state, kArgsParsingFailure, "%s() expects 2 args, got %zu", name, |
| 1128 | argv.size()); |
Tao Bao | 358c2ec | 2016-11-28 11:48:43 -0800 | [diff] [blame] | 1129 | } |
| 1130 | |
| 1131 | std::vector<std::string> args; |
Tianjie Xu | c444732 | 2017-03-06 14:44:59 -0800 | [diff] [blame] | 1132 | if (!ReadArgs(state, argv, &args)) { |
Tao Bao | 358c2ec | 2016-11-28 11:48:43 -0800 | [diff] [blame] | 1133 | return ErrorAbort(state, kArgsParsingFailure, "%s() Failed to parse the argument(s)", name); |
| 1134 | } |
| 1135 | const std::string& filename = args[0]; |
| 1136 | const std::string& key = args[1]; |
| 1137 | |
| 1138 | struct stat st; |
| 1139 | if (stat(filename.c_str(), &st) < 0) { |
| 1140 | return ErrorAbort(state, kFileGetPropFailure, "%s: failed to stat \"%s\": %s", name, |
| 1141 | filename.c_str(), strerror(errno)); |
| 1142 | } |
| 1143 | |
| 1144 | constexpr off_t MAX_FILE_GETPROP_SIZE = 65536; |
| 1145 | if (st.st_size > MAX_FILE_GETPROP_SIZE) { |
| 1146 | return ErrorAbort(state, kFileGetPropFailure, "%s too large for %s (max %lld)", |
| 1147 | filename.c_str(), name, static_cast<long long>(MAX_FILE_GETPROP_SIZE)); |
| 1148 | } |
| 1149 | |
| 1150 | std::string buffer(st.st_size, '\0'); |
| 1151 | unique_file f(ota_fopen(filename.c_str(), "rb")); |
| 1152 | if (f == nullptr) { |
| 1153 | return ErrorAbort(state, kFileOpenFailure, "%s: failed to open %s: %s", name, filename.c_str(), |
| 1154 | strerror(errno)); |
| 1155 | } |
| 1156 | |
| 1157 | if (ota_fread(&buffer[0], 1, st.st_size, f.get()) != static_cast<size_t>(st.st_size)) { |
| 1158 | ErrorAbort(state, kFreadFailure, "%s: failed to read %zu bytes from %s", name, |
| 1159 | static_cast<size_t>(st.st_size), filename.c_str()); |
| 1160 | return nullptr; |
| 1161 | } |
| 1162 | |
| 1163 | ota_fclose(f); |
| 1164 | |
| 1165 | std::vector<std::string> lines = android::base::Split(buffer, "\n"); |
| 1166 | for (size_t i = 0; i < lines.size(); i++) { |
| 1167 | std::string line = android::base::Trim(lines[i]); |
| 1168 | |
| 1169 | // comment or blank line: skip to next line |
| 1170 | if (line.empty() || line[0] == '#') { |
| 1171 | continue; |
| 1172 | } |
| 1173 | size_t equal_pos = line.find('='); |
| 1174 | if (equal_pos == std::string::npos) { |
| 1175 | continue; |
Doug Zongker | 47cace9 | 2009-06-18 10:11:50 -0700 | [diff] [blame] | 1176 | } |
| 1177 | |
Tao Bao | 358c2ec | 2016-11-28 11:48:43 -0800 | [diff] [blame] | 1178 | // trim whitespace between key and '=' |
| 1179 | std::string str = android::base::Trim(line.substr(0, equal_pos)); |
Doug Zongker | 47cace9 | 2009-06-18 10:11:50 -0700 | [diff] [blame] | 1180 | |
Tao Bao | 358c2ec | 2016-11-28 11:48:43 -0800 | [diff] [blame] | 1181 | // not the key we're looking for |
| 1182 | if (key != str) continue; |
Doug Zongker | 47cace9 | 2009-06-18 10:11:50 -0700 | [diff] [blame] | 1183 | |
Tao Bao | 358c2ec | 2016-11-28 11:48:43 -0800 | [diff] [blame] | 1184 | return StringValue(android::base::Trim(line.substr(equal_pos + 1))); |
| 1185 | } |
Doug Zongker | 47cace9 | 2009-06-18 10:11:50 -0700 | [diff] [blame] | 1186 | |
Tao Bao | 358c2ec | 2016-11-28 11:48:43 -0800 | [diff] [blame] | 1187 | return StringValue(""); |
Doug Zongker | 8edb00c | 2009-06-11 17:21:44 -0700 | [diff] [blame] | 1188 | } |
| 1189 | |
Doug Zongker | 8edb00c | 2009-06-11 17:21:44 -0700 | [diff] [blame] | 1190 | // apply_patch_space(bytes) |
Tianjie Xu | 5419ad3 | 2018-02-02 16:49:15 -0800 | [diff] [blame] | 1191 | Value* ApplyPatchSpaceFn(const char* name, State* state, |
| 1192 | const std::vector<std::unique_ptr<Expr>>& argv) { |
Tianjie Xu | c444732 | 2017-03-06 14:44:59 -0800 | [diff] [blame] | 1193 | if (argv.size() != 1) { |
| 1194 | return ErrorAbort(state, kArgsParsingFailure, "%s() expects 1 args, got %zu", name, |
| 1195 | argv.size()); |
| 1196 | } |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 1197 | std::vector<std::string> args; |
Tianjie Xu | c444732 | 2017-03-06 14:44:59 -0800 | [diff] [blame] | 1198 | if (!ReadArgs(state, argv, &args)) { |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 1199 | return ErrorAbort(state, kArgsParsingFailure, "%s() Failed to parse the argument(s)", name); |
| 1200 | } |
| 1201 | const std::string& bytes_str = args[0]; |
Doug Zongker | c4351c7 | 2010-02-22 14:46:32 -0800 | [diff] [blame] | 1202 | |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 1203 | size_t bytes; |
| 1204 | if (!android::base::ParseUint(bytes_str.c_str(), &bytes)) { |
Tianjie Xu | 5ad8028 | 2018-01-28 15:37:48 -0800 | [diff] [blame] | 1205 | return ErrorAbort(state, kArgsParsingFailure, "%s(): can't parse \"%s\" as byte count", name, |
| 1206 | bytes_str.c_str()); |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 1207 | } |
Doug Zongker | c4351c7 | 2010-02-22 14:46:32 -0800 | [diff] [blame] | 1208 | |
Tianjie Xu | 99b73be | 2017-11-28 17:23:06 -0800 | [diff] [blame] | 1209 | // Skip the cache size check if the update is a retry. |
| 1210 | if (state->is_retry || CacheSizeCheck(bytes) == 0) { |
| 1211 | return StringValue("t"); |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 1212 | } |
Tianjie Xu | 99b73be | 2017-11-28 17:23:06 -0800 | [diff] [blame] | 1213 | return StringValue(""); |
Doug Zongker | d9c9d10 | 2009-06-12 12:24:39 -0700 | [diff] [blame] | 1214 | } |
| 1215 | |
Tianjie Xu | c444732 | 2017-03-06 14:44:59 -0800 | [diff] [blame] | 1216 | Value* WipeCacheFn(const char* name, State* state, const std::vector<std::unique_ptr<Expr>>& argv) { |
| 1217 | if (!argv.empty()) { |
| 1218 | return ErrorAbort(state, kArgsParsingFailure, "%s() expects no args, got %zu", name, |
| 1219 | argv.size()); |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 1220 | } |
| 1221 | fprintf(static_cast<UpdaterInfo*>(state->cookie)->cmd_pipe, "wipe_cache\n"); |
| 1222 | return StringValue("t"); |
Doug Zongker | d0181b8 | 2011-10-19 10:51:12 -0700 | [diff] [blame] | 1223 | } |
| 1224 | |
Tianjie Xu | c444732 | 2017-03-06 14:44:59 -0800 | [diff] [blame] | 1225 | Value* RunProgramFn(const char* name, State* state, const std::vector<std::unique_ptr<Expr>>& argv) { |
| 1226 | if (argv.size() < 1) { |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 1227 | return ErrorAbort(state, kArgsParsingFailure, "%s() expects at least 1 arg", name); |
| 1228 | } |
Tianjie Xu | 5fe280a | 2016-10-17 18:15:20 -0700 | [diff] [blame] | 1229 | |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 1230 | std::vector<std::string> args; |
Tianjie Xu | c444732 | 2017-03-06 14:44:59 -0800 | [diff] [blame] | 1231 | if (!ReadArgs(state, argv, &args)) { |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 1232 | return ErrorAbort(state, kArgsParsingFailure, "%s() Failed to parse the argument(s)", name); |
| 1233 | } |
Doug Zongker | a3f89ea | 2009-09-10 14:10:48 -0700 | [diff] [blame] | 1234 | |
Tianjie Xu | c444732 | 2017-03-06 14:44:59 -0800 | [diff] [blame] | 1235 | char* args2[argv.size() + 1]; |
| 1236 | for (size_t i = 0; i < argv.size(); i++) { |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 1237 | args2[i] = &args[i][0]; |
| 1238 | } |
Tianjie Xu | c444732 | 2017-03-06 14:44:59 -0800 | [diff] [blame] | 1239 | args2[argv.size()] = nullptr; |
Doug Zongker | a3f89ea | 2009-09-10 14:10:48 -0700 | [diff] [blame] | 1240 | |
Tianjie Xu | c444732 | 2017-03-06 14:44:59 -0800 | [diff] [blame] | 1241 | LOG(INFO) << "about to run program [" << args2[0] << "] with " << argv.size() << " args"; |
Doug Zongker | a3f89ea | 2009-09-10 14:10:48 -0700 | [diff] [blame] | 1242 | |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 1243 | pid_t child = fork(); |
| 1244 | if (child == 0) { |
| 1245 | execv(args2[0], args2); |
| 1246 | PLOG(ERROR) << "run_program: execv failed"; |
Tao Bao | 3da8801 | 2017-02-03 13:09:23 -0800 | [diff] [blame] | 1247 | _exit(EXIT_FAILURE); |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 1248 | } |
Doug Zongker | a3f89ea | 2009-09-10 14:10:48 -0700 | [diff] [blame] | 1249 | |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 1250 | int status; |
| 1251 | waitpid(child, &status, 0); |
| 1252 | if (WIFEXITED(status)) { |
| 1253 | if (WEXITSTATUS(status) != 0) { |
| 1254 | LOG(ERROR) << "run_program: child exited with status " << WEXITSTATUS(status); |
Doug Zongker | a3f89ea | 2009-09-10 14:10:48 -0700 | [diff] [blame] | 1255 | } |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 1256 | } else if (WIFSIGNALED(status)) { |
| 1257 | LOG(ERROR) << "run_program: child terminated by signal " << WTERMSIG(status); |
| 1258 | } |
Doug Zongker | a3f89ea | 2009-09-10 14:10:48 -0700 | [diff] [blame] | 1259 | |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 1260 | return StringValue(std::to_string(status)); |
Doug Zongker | a3f89ea | 2009-09-10 14:10:48 -0700 | [diff] [blame] | 1261 | } |
| 1262 | |
Hristo Bojinov | db314d6 | 2010-08-02 10:29:49 -0700 | [diff] [blame] | 1263 | // Read a local file and return its contents (the Value* returned |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 1264 | // is actually a FileContents*). |
Tianjie Xu | c444732 | 2017-03-06 14:44:59 -0800 | [diff] [blame] | 1265 | Value* ReadFileFn(const char* name, State* state, const std::vector<std::unique_ptr<Expr>>& argv) { |
| 1266 | if (argv.size() != 1) { |
| 1267 | return ErrorAbort(state, kArgsParsingFailure, "%s() expects 1 arg, got %zu", name, argv.size()); |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 1268 | } |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 1269 | |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 1270 | std::vector<std::string> args; |
Tianjie Xu | c444732 | 2017-03-06 14:44:59 -0800 | [diff] [blame] | 1271 | if (!ReadArgs(state, argv, &args)) { |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 1272 | return ErrorAbort(state, kArgsParsingFailure, "%s() Failed to parse the argument(s)", name); |
| 1273 | } |
| 1274 | const std::string& filename = args[0]; |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 1275 | |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 1276 | Value* v = new Value(VAL_INVALID, ""); |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 1277 | |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 1278 | FileContents fc; |
| 1279 | if (LoadFileContents(filename.c_str(), &fc) == 0) { |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 1280 | v->type = VAL_BLOB; |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 1281 | v->data = std::string(fc.data.begin(), fc.data.end()); |
| 1282 | } |
| 1283 | return v; |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 1284 | } |
Doug Zongker | 8edb00c | 2009-06-11 17:21:44 -0700 | [diff] [blame] | 1285 | |
Tao Bao | 1bf1772 | 2016-11-03 23:52:01 -0700 | [diff] [blame] | 1286 | // write_value(value, filename) |
| 1287 | // Writes 'value' to 'filename'. |
| 1288 | // Example: write_value("960000", "/sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq") |
Tianjie Xu | c444732 | 2017-03-06 14:44:59 -0800 | [diff] [blame] | 1289 | Value* WriteValueFn(const char* name, State* state, const std::vector<std::unique_ptr<Expr>>& argv) { |
| 1290 | if (argv.size() != 2) { |
| 1291 | return ErrorAbort(state, kArgsParsingFailure, "%s() expects 2 args, got %zu", name, |
| 1292 | argv.size()); |
Tao Bao | d0f3088 | 2016-11-03 23:52:01 -0700 | [diff] [blame] | 1293 | } |
Tao Bao | 1bf1772 | 2016-11-03 23:52:01 -0700 | [diff] [blame] | 1294 | |
Tao Bao | d0f3088 | 2016-11-03 23:52:01 -0700 | [diff] [blame] | 1295 | std::vector<std::string> args; |
Tianjie Xu | c444732 | 2017-03-06 14:44:59 -0800 | [diff] [blame] | 1296 | if (!ReadArgs(state, argv, &args)) { |
Tao Bao | d0f3088 | 2016-11-03 23:52:01 -0700 | [diff] [blame] | 1297 | return ErrorAbort(state, kArgsParsingFailure, "%s(): Failed to parse the argument(s)", name); |
| 1298 | } |
Tao Bao | 1bf1772 | 2016-11-03 23:52:01 -0700 | [diff] [blame] | 1299 | |
Tao Bao | d0f3088 | 2016-11-03 23:52:01 -0700 | [diff] [blame] | 1300 | const std::string& filename = args[1]; |
| 1301 | if (filename.empty()) { |
| 1302 | return ErrorAbort(state, kArgsParsingFailure, "%s(): Filename cannot be empty", name); |
| 1303 | } |
Tao Bao | 1bf1772 | 2016-11-03 23:52:01 -0700 | [diff] [blame] | 1304 | |
Tao Bao | d0f3088 | 2016-11-03 23:52:01 -0700 | [diff] [blame] | 1305 | const std::string& value = args[0]; |
| 1306 | if (!android::base::WriteStringToFile(value, filename)) { |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 1307 | PLOG(ERROR) << name << ": Failed to write to \"" << filename << "\""; |
Tao Bao | d0f3088 | 2016-11-03 23:52:01 -0700 | [diff] [blame] | 1308 | return StringValue(""); |
| 1309 | } else { |
| 1310 | return StringValue("t"); |
| 1311 | } |
Tao Bao | 1bf1772 | 2016-11-03 23:52:01 -0700 | [diff] [blame] | 1312 | } |
| 1313 | |
Doug Zongker | c87bab1 | 2013-11-25 13:53:25 -0800 | [diff] [blame] | 1314 | // Immediately reboot the device. Recovery is not finished normally, |
| 1315 | // so if you reboot into recovery it will re-start applying the |
| 1316 | // current package (because nothing has cleared the copy of the |
| 1317 | // arguments stored in the BCB). |
| 1318 | // |
| 1319 | // The argument is the partition name passed to the android reboot |
| 1320 | // property. It can be "recovery" to boot from the recovery |
| 1321 | // partition, or "" (empty string) to boot from the regular boot |
| 1322 | // partition. |
Tianjie Xu | c444732 | 2017-03-06 14:44:59 -0800 | [diff] [blame] | 1323 | Value* RebootNowFn(const char* name, State* state, const std::vector<std::unique_ptr<Expr>>& argv) { |
| 1324 | if (argv.size() != 2) { |
| 1325 | return ErrorAbort(state, kArgsParsingFailure, "%s() expects 2 args, got %zu", name, |
| 1326 | argv.size()); |
Tao Bao | bedf5fc | 2016-11-18 12:01:26 -0800 | [diff] [blame] | 1327 | } |
Doug Zongker | c87bab1 | 2013-11-25 13:53:25 -0800 | [diff] [blame] | 1328 | |
Tao Bao | bedf5fc | 2016-11-18 12:01:26 -0800 | [diff] [blame] | 1329 | std::vector<std::string> args; |
Tianjie Xu | c444732 | 2017-03-06 14:44:59 -0800 | [diff] [blame] | 1330 | if (!ReadArgs(state, argv, &args)) { |
Tao Bao | bedf5fc | 2016-11-18 12:01:26 -0800 | [diff] [blame] | 1331 | return ErrorAbort(state, kArgsParsingFailure, "%s(): Failed to parse the argument(s)", name); |
| 1332 | } |
| 1333 | const std::string& filename = args[0]; |
| 1334 | const std::string& property = args[1]; |
Doug Zongker | c87bab1 | 2013-11-25 13:53:25 -0800 | [diff] [blame] | 1335 | |
Tao Bao | bedf5fc | 2016-11-18 12:01:26 -0800 | [diff] [blame] | 1336 | // Zero out the 'command' field of the bootloader message. Leave the rest intact. |
| 1337 | bootloader_message boot; |
| 1338 | std::string err; |
| 1339 | if (!read_bootloader_message_from(&boot, filename, &err)) { |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 1340 | LOG(ERROR) << name << "(): Failed to read from \"" << filename << "\": " << err; |
Tao Bao | bedf5fc | 2016-11-18 12:01:26 -0800 | [diff] [blame] | 1341 | return StringValue(""); |
| 1342 | } |
| 1343 | memset(boot.command, 0, sizeof(boot.command)); |
| 1344 | if (!write_bootloader_message_to(boot, filename, &err)) { |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 1345 | LOG(ERROR) << name << "(): Failed to write to \"" << filename << "\": " << err; |
Tao Bao | bedf5fc | 2016-11-18 12:01:26 -0800 | [diff] [blame] | 1346 | return StringValue(""); |
| 1347 | } |
Doug Zongker | c87bab1 | 2013-11-25 13:53:25 -0800 | [diff] [blame] | 1348 | |
Dmitri Plotnikov | ed9db0f | 2017-04-18 08:28:26 -0700 | [diff] [blame] | 1349 | std::string reboot_cmd = "reboot," + property; |
| 1350 | if (android::base::GetBoolProperty("ro.boot.quiescent", false)) { |
| 1351 | reboot_cmd += ",quiescent"; |
| 1352 | } |
Tao Bao | bedf5fc | 2016-11-18 12:01:26 -0800 | [diff] [blame] | 1353 | android::base::SetProperty(ANDROID_RB_PROPERTY, reboot_cmd); |
Doug Zongker | c87bab1 | 2013-11-25 13:53:25 -0800 | [diff] [blame] | 1354 | |
Tao Bao | bedf5fc | 2016-11-18 12:01:26 -0800 | [diff] [blame] | 1355 | sleep(5); |
| 1356 | return ErrorAbort(state, kRebootFailure, "%s() failed to reboot", name); |
Doug Zongker | c87bab1 | 2013-11-25 13:53:25 -0800 | [diff] [blame] | 1357 | } |
| 1358 | |
| 1359 | // Store a string value somewhere that future invocations of recovery |
| 1360 | // can access it. This value is called the "stage" and can be used to |
| 1361 | // drive packages that need to do reboots in the middle of |
| 1362 | // installation and keep track of where they are in the multi-stage |
| 1363 | // install. |
| 1364 | // |
| 1365 | // The first argument is the block device for the misc partition |
| 1366 | // ("/misc" in the fstab), which is where this value is stored. The |
| 1367 | // second argument is the string to store; it should not exceed 31 |
| 1368 | // bytes. |
Tianjie Xu | c444732 | 2017-03-06 14:44:59 -0800 | [diff] [blame] | 1369 | Value* SetStageFn(const char* name, State* state, const std::vector<std::unique_ptr<Expr>>& argv) { |
| 1370 | if (argv.size() != 2) { |
| 1371 | return ErrorAbort(state, kArgsParsingFailure, "%s() expects 2 args, got %zu", name, |
| 1372 | argv.size()); |
Tao Bao | bedf5fc | 2016-11-18 12:01:26 -0800 | [diff] [blame] | 1373 | } |
Doug Zongker | c87bab1 | 2013-11-25 13:53:25 -0800 | [diff] [blame] | 1374 | |
Tao Bao | bedf5fc | 2016-11-18 12:01:26 -0800 | [diff] [blame] | 1375 | std::vector<std::string> args; |
Tianjie Xu | c444732 | 2017-03-06 14:44:59 -0800 | [diff] [blame] | 1376 | if (!ReadArgs(state, argv, &args)) { |
Tao Bao | bedf5fc | 2016-11-18 12:01:26 -0800 | [diff] [blame] | 1377 | return ErrorAbort(state, kArgsParsingFailure, "%s() Failed to parse the argument(s)", name); |
| 1378 | } |
| 1379 | const std::string& filename = args[0]; |
| 1380 | const std::string& stagestr = args[1]; |
Doug Zongker | c87bab1 | 2013-11-25 13:53:25 -0800 | [diff] [blame] | 1381 | |
Tao Bao | bedf5fc | 2016-11-18 12:01:26 -0800 | [diff] [blame] | 1382 | // Store this value in the misc partition, immediately after the |
| 1383 | // bootloader message that the main recovery uses to save its |
| 1384 | // arguments in case of the device restarting midway through |
| 1385 | // package installation. |
| 1386 | bootloader_message boot; |
| 1387 | std::string err; |
| 1388 | if (!read_bootloader_message_from(&boot, filename, &err)) { |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 1389 | LOG(ERROR) << name << "(): Failed to read from \"" << filename << "\": " << err; |
Tao Bao | bedf5fc | 2016-11-18 12:01:26 -0800 | [diff] [blame] | 1390 | return StringValue(""); |
| 1391 | } |
| 1392 | strlcpy(boot.stage, stagestr.c_str(), sizeof(boot.stage)); |
| 1393 | if (!write_bootloader_message_to(boot, filename, &err)) { |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 1394 | LOG(ERROR) << name << "(): Failed to write to \"" << filename << "\": " << err; |
Tao Bao | bedf5fc | 2016-11-18 12:01:26 -0800 | [diff] [blame] | 1395 | return StringValue(""); |
| 1396 | } |
Doug Zongker | c87bab1 | 2013-11-25 13:53:25 -0800 | [diff] [blame] | 1397 | |
Tao Bao | bedf5fc | 2016-11-18 12:01:26 -0800 | [diff] [blame] | 1398 | return StringValue(filename); |
Doug Zongker | c87bab1 | 2013-11-25 13:53:25 -0800 | [diff] [blame] | 1399 | } |
| 1400 | |
| 1401 | // Return the value most recently saved with SetStageFn. The argument |
| 1402 | // is the block device for the misc partition. |
Tianjie Xu | c444732 | 2017-03-06 14:44:59 -0800 | [diff] [blame] | 1403 | Value* GetStageFn(const char* name, State* state, const std::vector<std::unique_ptr<Expr>>& argv) { |
| 1404 | if (argv.size() != 1) { |
| 1405 | return ErrorAbort(state, kArgsParsingFailure, "%s() expects 1 arg, got %zu", name, argv.size()); |
Tao Bao | bedf5fc | 2016-11-18 12:01:26 -0800 | [diff] [blame] | 1406 | } |
Doug Zongker | c87bab1 | 2013-11-25 13:53:25 -0800 | [diff] [blame] | 1407 | |
Tao Bao | bedf5fc | 2016-11-18 12:01:26 -0800 | [diff] [blame] | 1408 | std::vector<std::string> args; |
Tianjie Xu | c444732 | 2017-03-06 14:44:59 -0800 | [diff] [blame] | 1409 | if (!ReadArgs(state, argv, &args)) { |
Tao Bao | bedf5fc | 2016-11-18 12:01:26 -0800 | [diff] [blame] | 1410 | return ErrorAbort(state, kArgsParsingFailure, "%s() Failed to parse the argument(s)", name); |
| 1411 | } |
| 1412 | const std::string& filename = args[0]; |
Doug Zongker | c87bab1 | 2013-11-25 13:53:25 -0800 | [diff] [blame] | 1413 | |
Tao Bao | bedf5fc | 2016-11-18 12:01:26 -0800 | [diff] [blame] | 1414 | bootloader_message boot; |
| 1415 | std::string err; |
| 1416 | if (!read_bootloader_message_from(&boot, filename, &err)) { |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 1417 | LOG(ERROR) << name << "(): Failed to read from \"" << filename << "\": " << err; |
Tao Bao | bedf5fc | 2016-11-18 12:01:26 -0800 | [diff] [blame] | 1418 | return StringValue(""); |
| 1419 | } |
Doug Zongker | c87bab1 | 2013-11-25 13:53:25 -0800 | [diff] [blame] | 1420 | |
Tao Bao | bedf5fc | 2016-11-18 12:01:26 -0800 | [diff] [blame] | 1421 | return StringValue(boot.stage); |
Doug Zongker | c87bab1 | 2013-11-25 13:53:25 -0800 | [diff] [blame] | 1422 | } |
| 1423 | |
Tianjie Xu | c444732 | 2017-03-06 14:44:59 -0800 | [diff] [blame] | 1424 | Value* WipeBlockDeviceFn(const char* name, State* state, const std::vector<std::unique_ptr<Expr>>& argv) { |
| 1425 | if (argv.size() != 2) { |
| 1426 | return ErrorAbort(state, kArgsParsingFailure, "%s() expects 2 args, got %zu", name, |
| 1427 | argv.size()); |
Tao Bao | 358c2ec | 2016-11-28 11:48:43 -0800 | [diff] [blame] | 1428 | } |
Doug Zongker | c9d6e4f | 2014-02-24 16:02:50 -0800 | [diff] [blame] | 1429 | |
Tao Bao | 358c2ec | 2016-11-28 11:48:43 -0800 | [diff] [blame] | 1430 | std::vector<std::string> args; |
Tianjie Xu | c444732 | 2017-03-06 14:44:59 -0800 | [diff] [blame] | 1431 | if (!ReadArgs(state, argv, &args)) { |
Tao Bao | 358c2ec | 2016-11-28 11:48:43 -0800 | [diff] [blame] | 1432 | return ErrorAbort(state, kArgsParsingFailure, "%s() Failed to parse the argument(s)", name); |
| 1433 | } |
| 1434 | const std::string& filename = args[0]; |
| 1435 | const std::string& len_str = args[1]; |
Doug Zongker | c9d6e4f | 2014-02-24 16:02:50 -0800 | [diff] [blame] | 1436 | |
Tao Bao | 358c2ec | 2016-11-28 11:48:43 -0800 | [diff] [blame] | 1437 | size_t len; |
| 1438 | if (!android::base::ParseUint(len_str.c_str(), &len)) { |
| 1439 | return nullptr; |
| 1440 | } |
| 1441 | unique_fd fd(ota_open(filename.c_str(), O_WRONLY, 0644)); |
| 1442 | // The wipe_block_device function in ext4_utils returns 0 on success and 1 |
| 1443 | // for failure. |
| 1444 | int status = wipe_block_device(fd, len); |
| 1445 | return StringValue((status == 0) ? "t" : ""); |
Doug Zongker | c9d6e4f | 2014-02-24 16:02:50 -0800 | [diff] [blame] | 1446 | } |
| 1447 | |
Tianjie Xu | c444732 | 2017-03-06 14:44:59 -0800 | [diff] [blame] | 1448 | Value* EnableRebootFn(const char* name, State* state, const std::vector<std::unique_ptr<Expr>>& argv) { |
| 1449 | if (!argv.empty()) { |
| 1450 | return ErrorAbort(state, kArgsParsingFailure, "%s() expects no args, got %zu", name, |
| 1451 | argv.size()); |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 1452 | } |
| 1453 | UpdaterInfo* ui = static_cast<UpdaterInfo*>(state->cookie); |
| 1454 | fprintf(ui->cmd_pipe, "enable_reboot\n"); |
| 1455 | return StringValue("t"); |
Doug Zongker | c704e06 | 2014-05-23 08:40:35 -0700 | [diff] [blame] | 1456 | } |
| 1457 | |
Tianjie Xu | c444732 | 2017-03-06 14:44:59 -0800 | [diff] [blame] | 1458 | Value* Tune2FsFn(const char* name, State* state, const std::vector<std::unique_ptr<Expr>>& argv) { |
Ethan Yonker | 7e1b986 | 2015-03-19 14:10:01 -0500 | [diff] [blame] | 1459 | #ifdef HAVE_LIBTUNE2FS |
Tianjie Xu | c444732 | 2017-03-06 14:44:59 -0800 | [diff] [blame] | 1460 | if (argv.empty()) { |
| 1461 | return ErrorAbort(state, kArgsParsingFailure, "%s() expects args, got %zu", name, argv.size()); |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 1462 | } |
Michael Runge | b278c25 | 2014-11-21 00:12:28 -0800 | [diff] [blame] | 1463 | |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 1464 | std::vector<std::string> args; |
Tianjie Xu | c444732 | 2017-03-06 14:44:59 -0800 | [diff] [blame] | 1465 | if (!ReadArgs(state, argv, &args)) { |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 1466 | return ErrorAbort(state, kArgsParsingFailure, "%s() could not read args", name); |
| 1467 | } |
Michael Runge | b278c25 | 2014-11-21 00:12:28 -0800 | [diff] [blame] | 1468 | |
Tianjie Xu | c444732 | 2017-03-06 14:44:59 -0800 | [diff] [blame] | 1469 | char* args2[argv.size() + 1]; |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 1470 | // Tune2fs expects the program name as its args[0] |
| 1471 | args2[0] = const_cast<char*>(name); |
| 1472 | if (args2[0] == nullptr) { |
| 1473 | return nullptr; |
| 1474 | } |
Tianjie Xu | c444732 | 2017-03-06 14:44:59 -0800 | [diff] [blame] | 1475 | for (size_t i = 0; i < argv.size(); ++i) { |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 1476 | args2[i + 1] = &args[i][0]; |
| 1477 | } |
Michael Runge | b278c25 | 2014-11-21 00:12:28 -0800 | [diff] [blame] | 1478 | |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 1479 | // tune2fs changes the file system parameters on an ext2 file system; it |
| 1480 | // returns 0 on success. |
Tianjie Xu | c444732 | 2017-03-06 14:44:59 -0800 | [diff] [blame] | 1481 | int result = tune2fs_main(argv.size() + 1, args2); |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 1482 | if (result != 0) { |
| 1483 | return ErrorAbort(state, kTune2FsFailure, "%s() returned error code %d", name, result); |
| 1484 | } |
| 1485 | return StringValue("t"); |
Ethan Yonker | 7e1b986 | 2015-03-19 14:10:01 -0500 | [diff] [blame] | 1486 | #else |
Ethan Yonker | 8373cfe | 2017-09-08 06:50:54 -0500 | [diff] [blame] | 1487 | return ErrorAbort(state, kTune2FsFailure, "%s() support not present, no libtune2fs", name); |
Ethan Yonker | 7e1b986 | 2015-03-19 14:10:01 -0500 | [diff] [blame] | 1488 | #endif // HAVE_LIBTUNE2FS |
Michael Runge | b278c25 | 2014-11-21 00:12:28 -0800 | [diff] [blame] | 1489 | } |
| 1490 | |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 1491 | void RegisterInstallFunctions() { |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 1492 | RegisterFunction("mount", MountFn); |
| 1493 | RegisterFunction("is_mounted", IsMountedFn); |
| 1494 | RegisterFunction("unmount", UnmountFn); |
| 1495 | RegisterFunction("format", FormatFn); |
| 1496 | RegisterFunction("show_progress", ShowProgressFn); |
| 1497 | RegisterFunction("set_progress", SetProgressFn); |
Tom Marshall | bf4f24f | 2017-08-23 18:14:00 +0000 | [diff] [blame] | 1498 | RegisterFunction("delete", DeleteFn); |
| 1499 | RegisterFunction("delete_recursive", DeleteFn); |
Tom Marshall | 981118e | 2017-10-25 20:27:08 +0200 | [diff] [blame] | 1500 | RegisterFunction("package_extract_dir", PackageExtractDirFn); |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 1501 | RegisterFunction("package_extract_file", PackageExtractFileFn); |
Tom Marshall | bf4f24f | 2017-08-23 18:14:00 +0000 | [diff] [blame] | 1502 | RegisterFunction("symlink", SymlinkFn); |
| 1503 | |
| 1504 | // Usage: |
| 1505 | // set_metadata("filename", "key1", "value1", "key2", "value2", ...) |
| 1506 | // Example: |
| 1507 | // set_metadata("/system/bin/netcfg", "uid", 0, "gid", 3003, "mode", 02750, "selabel", |
| 1508 | // "u:object_r:system_file:s0", "capabilities", 0x0); |
| 1509 | RegisterFunction("set_metadata", SetMetadataFn); |
| 1510 | |
| 1511 | // Usage: |
| 1512 | // set_metadata_recursive("dirname", "key1", "value1", "key2", "value2", ...) |
| 1513 | // Example: |
| 1514 | // set_metadata_recursive("/system", "uid", 0, "gid", 0, "fmode", 0644, "dmode", 0755, |
| 1515 | // "selabel", "u:object_r:system_file:s0", "capabilities", 0x0); |
| 1516 | RegisterFunction("set_metadata_recursive", SetMetadataFn); |
Nick Kralevich | 5dbdef0 | 2013-09-07 14:41:06 -0700 | [diff] [blame] | 1517 | |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 1518 | RegisterFunction("getprop", GetPropFn); |
| 1519 | RegisterFunction("file_getprop", FileGetPropFn); |
Nick Kralevich | 5dbdef0 | 2013-09-07 14:41:06 -0700 | [diff] [blame] | 1520 | |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 1521 | RegisterFunction("apply_patch", ApplyPatchFn); |
| 1522 | RegisterFunction("apply_patch_check", ApplyPatchCheckFn); |
| 1523 | RegisterFunction("apply_patch_space", ApplyPatchSpaceFn); |
Nick Kralevich | 5dbdef0 | 2013-09-07 14:41:06 -0700 | [diff] [blame] | 1524 | |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 1525 | RegisterFunction("wipe_block_device", WipeBlockDeviceFn); |
Doug Zongker | 8edb00c | 2009-06-11 17:21:44 -0700 | [diff] [blame] | 1526 | |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 1527 | RegisterFunction("read_file", ReadFileFn); |
| 1528 | RegisterFunction("sha1_check", Sha1CheckFn); |
Tom Marshall | bf4f24f | 2017-08-23 18:14:00 +0000 | [diff] [blame] | 1529 | RegisterFunction("rename", RenameFn); |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 1530 | RegisterFunction("write_value", WriteValueFn); |
Doug Zongker | d9c9d10 | 2009-06-12 12:24:39 -0700 | [diff] [blame] | 1531 | |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 1532 | RegisterFunction("wipe_cache", WipeCacheFn); |
Doug Zongker | 52b4036 | 2014-02-10 15:30:30 -0800 | [diff] [blame] | 1533 | |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 1534 | RegisterFunction("ui_print", UIPrintFn); |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 1535 | |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 1536 | RegisterFunction("run_program", RunProgramFn); |
Doug Zongker | d0181b8 | 2011-10-19 10:51:12 -0700 | [diff] [blame] | 1537 | |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 1538 | RegisterFunction("reboot_now", RebootNowFn); |
| 1539 | RegisterFunction("get_stage", GetStageFn); |
| 1540 | RegisterFunction("set_stage", SetStageFn); |
Doug Zongker | a3f89ea | 2009-09-10 14:10:48 -0700 | [diff] [blame] | 1541 | |
Tao Bao | 039f2da | 2016-11-22 16:29:50 -0800 | [diff] [blame] | 1542 | RegisterFunction("enable_reboot", EnableRebootFn); |
| 1543 | RegisterFunction("tune2fs", Tune2FsFn); |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 1544 | } |