blob: 478055dc9f6ce2f36404cecc7b2304b250464557 [file] [log] [blame]
Doug Zongker9931f7f2009-06-10 14:11:53 -07001/*
2 * Copyright (C) 2009 The Android Open Source Project
Shashank Mittal815ca5d2010-07-27 11:09:19 -07003 * Copyright (c) 2010, Code Aurora Forum. All rights reserved.
Doug Zongker9931f7f2009-06-10 14:11:53 -07004 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
Doug Zongkerfbf3c102009-06-24 09:36:20 -070018#include <ctype.h>
Doug Zongker9931f7f2009-06-10 14:11:53 -070019#include <errno.h>
20#include <stdarg.h>
Doug Zongkerfbf3c102009-06-24 09:36:20 -070021#include <stdio.h>
Doug Zongker9931f7f2009-06-10 14:11:53 -070022#include <stdlib.h>
23#include <string.h>
24#include <sys/mount.h>
25#include <sys/stat.h>
26#include <sys/types.h>
Doug Zongkera3f89ea2009-09-10 14:10:48 -070027#include <sys/wait.h>
Doug Zongker9931f7f2009-06-10 14:11:53 -070028#include <unistd.h>
29
Doug Zongker8edb00c2009-06-11 17:21:44 -070030#include "cutils/misc.h"
31#include "cutils/properties.h"
Doug Zongker9931f7f2009-06-10 14:11:53 -070032#include "edify/expr.h"
Doug Zongker512536a2010-02-17 16:11:44 -080033#include "mincrypt/sha.h"
Doug Zongker9931f7f2009-06-10 14:11:53 -070034#include "minzip/DirUtil.h"
Koushik Dutta1b867542010-11-10 23:52:09 -080035#include "mounts.h"
Steve Kondik4123b582010-11-14 03:18:40 -050036#include "flashutils/flashutils.h"
Doug Zongker9931f7f2009-06-10 14:11:53 -070037#include "mtdutils/mtdutils.h"
Shashank Mittal815ca5d2010-07-27 11:09:19 -070038#include "mmcutils/mmcutils.h"
Doug Zongker9931f7f2009-06-10 14:11:53 -070039#include "updater.h"
Doug Zongker512536a2010-02-17 16:11:44 -080040#include "applypatch/applypatch.h"
Doug Zongker8edb00c2009-06-11 17:21:44 -070041
Doug Zongker56c51052010-07-01 09:18:44 -070042#ifdef USE_EXT4
43#include "make_ext4fs.h"
44#endif
45
46// mount(fs_type, partition_type, location, mount_point)
Doug Zongker9931f7f2009-06-10 14:11:53 -070047//
Doug Zongker56c51052010-07-01 09:18:44 -070048// fs_type="yaffs2" partition_type="MTD" location=partition
49// fs_type="ext4" partition_type="EMMC" location=device
Doug Zongker512536a2010-02-17 16:11:44 -080050Value* MountFn(const char* name, State* state, int argc, Expr* argv[]) {
Doug Zongker9931f7f2009-06-10 14:11:53 -070051 char* result = NULL;
Doug Zongker56c51052010-07-01 09:18:44 -070052 if (argc != 4) {
53 return ErrorAbort(state, "%s() expects 4 args, got %d", name, argc);
Doug Zongker9931f7f2009-06-10 14:11:53 -070054 }
Doug Zongker56c51052010-07-01 09:18:44 -070055 char* fs_type;
56 char* partition_type;
Doug Zongker9931f7f2009-06-10 14:11:53 -070057 char* location;
58 char* mount_point;
Doug Zongker56c51052010-07-01 09:18:44 -070059 if (ReadArgs(state, argv, 4, &fs_type, &partition_type,
60 &location, &mount_point) < 0) {
Doug Zongker9931f7f2009-06-10 14:11:53 -070061 return NULL;
62 }
63
Doug Zongker56c51052010-07-01 09:18:44 -070064 if (strlen(fs_type) == 0) {
65 ErrorAbort(state, "fs_type argument to %s() can't be empty", name);
66 goto done;
67 }
68 if (strlen(partition_type) == 0) {
69 ErrorAbort(state, "partition_type argument to %s() can't be empty",
70 name);
Doug Zongker9931f7f2009-06-10 14:11:53 -070071 goto done;
72 }
73 if (strlen(location) == 0) {
Doug Zongkerd9c9d102009-06-12 12:24:39 -070074 ErrorAbort(state, "location argument to %s() can't be empty", name);
Doug Zongker9931f7f2009-06-10 14:11:53 -070075 goto done;
76 }
77 if (strlen(mount_point) == 0) {
Doug Zongkerd9c9d102009-06-12 12:24:39 -070078 ErrorAbort(state, "mount_point argument to %s() can't be empty", name);
Doug Zongker9931f7f2009-06-10 14:11:53 -070079 goto done;
80 }
81
82 mkdir(mount_point, 0755);
83
Koushik Duttadf1e4062010-12-18 17:42:31 -080084 if (strcmp(partition_type, "MTD") == 0 || strcmp(partition_type, "MMC") == 0) {
Steve Kondik4123b582010-11-14 03:18:40 -050085 if (0 == mount_partition(location, mount_point, get_default_filesystem(), 0))
Koushik Dutta1b867542010-11-10 23:52:09 -080086 result = mount_point;
87 else
Doug Zongker9931f7f2009-06-10 14:11:53 -070088 result = strdup("");
Doug Zongker9931f7f2009-06-10 14:11:53 -070089 } else {
Doug Zongker56c51052010-07-01 09:18:44 -070090 if (mount(location, mount_point, fs_type,
Doug Zongker9931f7f2009-06-10 14:11:53 -070091 MS_NOATIME | MS_NODEV | MS_NODIRATIME, "") < 0) {
Doug Zongker60babf82009-09-18 15:11:24 -070092 fprintf(stderr, "%s: failed to mount %s at %s: %s\n",
93 name, location, mount_point, strerror(errno));
Doug Zongker9931f7f2009-06-10 14:11:53 -070094 result = strdup("");
95 } else {
96 result = mount_point;
97 }
98 }
99
100done:
Doug Zongker56c51052010-07-01 09:18:44 -0700101 free(fs_type);
102 free(partition_type);
Doug Zongker9931f7f2009-06-10 14:11:53 -0700103 free(location);
104 if (result != mount_point) free(mount_point);
Doug Zongker512536a2010-02-17 16:11:44 -0800105 return StringValue(result);
Doug Zongker9931f7f2009-06-10 14:11:53 -0700106}
107
Doug Zongker8edb00c2009-06-11 17:21:44 -0700108
109// is_mounted(mount_point)
Doug Zongker512536a2010-02-17 16:11:44 -0800110Value* IsMountedFn(const char* name, State* state, int argc, Expr* argv[]) {
Doug Zongker8edb00c2009-06-11 17:21:44 -0700111 char* result = NULL;
112 if (argc != 1) {
Doug Zongkerd9c9d102009-06-12 12:24:39 -0700113 return ErrorAbort(state, "%s() expects 1 arg, got %d", name, argc);
Doug Zongker8edb00c2009-06-11 17:21:44 -0700114 }
115 char* mount_point;
Doug Zongkerd9c9d102009-06-12 12:24:39 -0700116 if (ReadArgs(state, argv, 1, &mount_point) < 0) {
Doug Zongker8edb00c2009-06-11 17:21:44 -0700117 return NULL;
118 }
119 if (strlen(mount_point) == 0) {
Doug Zongkerd9c9d102009-06-12 12:24:39 -0700120 ErrorAbort(state, "mount_point argument to unmount() can't be empty");
Doug Zongker8edb00c2009-06-11 17:21:44 -0700121 goto done;
122 }
123
124 scan_mounted_volumes();
125 const MountedVolume* vol = find_mounted_volume_by_mount_point(mount_point);
126 if (vol == NULL) {
127 result = strdup("");
128 } else {
129 result = mount_point;
130 }
131
132done:
133 if (result != mount_point) free(mount_point);
Doug Zongker512536a2010-02-17 16:11:44 -0800134 return StringValue(result);
Doug Zongker8edb00c2009-06-11 17:21:44 -0700135}
136
137
Doug Zongker512536a2010-02-17 16:11:44 -0800138Value* UnmountFn(const char* name, State* state, int argc, Expr* argv[]) {
Doug Zongker9931f7f2009-06-10 14:11:53 -0700139 char* result = NULL;
140 if (argc != 1) {
Doug Zongkerd9c9d102009-06-12 12:24:39 -0700141 return ErrorAbort(state, "%s() expects 1 arg, got %d", name, argc);
Doug Zongker9931f7f2009-06-10 14:11:53 -0700142 }
143 char* mount_point;
Doug Zongkerd9c9d102009-06-12 12:24:39 -0700144 if (ReadArgs(state, argv, 1, &mount_point) < 0) {
Doug Zongker9931f7f2009-06-10 14:11:53 -0700145 return NULL;
146 }
147 if (strlen(mount_point) == 0) {
Doug Zongkerd9c9d102009-06-12 12:24:39 -0700148 ErrorAbort(state, "mount_point argument to unmount() can't be empty");
Doug Zongker9931f7f2009-06-10 14:11:53 -0700149 goto done;
150 }
151
152 scan_mounted_volumes();
153 const MountedVolume* vol = find_mounted_volume_by_mount_point(mount_point);
154 if (vol == NULL) {
155 fprintf(stderr, "unmount of %s failed; no such volume\n", mount_point);
156 result = strdup("");
157 } else {
158 unmount_mounted_volume(vol);
159 result = mount_point;
160 }
161
162done:
163 if (result != mount_point) free(mount_point);
Doug Zongker512536a2010-02-17 16:11:44 -0800164 return StringValue(result);
Doug Zongker9931f7f2009-06-10 14:11:53 -0700165}
Doug Zongker8edb00c2009-06-11 17:21:44 -0700166
167
Doug Zongker56c51052010-07-01 09:18:44 -0700168// format(fs_type, partition_type, location)
Doug Zongker9931f7f2009-06-10 14:11:53 -0700169//
Doug Zongker56c51052010-07-01 09:18:44 -0700170// fs_type="yaffs2" partition_type="MTD" location=partition
171// fs_type="ext4" partition_type="EMMC" location=device
Doug Zongker512536a2010-02-17 16:11:44 -0800172Value* FormatFn(const char* name, State* state, int argc, Expr* argv[]) {
Doug Zongker9931f7f2009-06-10 14:11:53 -0700173 char* result = NULL;
Doug Zongker56c51052010-07-01 09:18:44 -0700174 if (argc != 3) {
175 return ErrorAbort(state, "%s() expects 3 args, got %d", name, argc);
Doug Zongker9931f7f2009-06-10 14:11:53 -0700176 }
Doug Zongker56c51052010-07-01 09:18:44 -0700177 char* fs_type;
178 char* partition_type;
Doug Zongker9931f7f2009-06-10 14:11:53 -0700179 char* location;
Doug Zongker56c51052010-07-01 09:18:44 -0700180 if (ReadArgs(state, argv, 3, &fs_type, &partition_type, &location) < 0) {
Doug Zongker9931f7f2009-06-10 14:11:53 -0700181 return NULL;
182 }
183
Doug Zongker56c51052010-07-01 09:18:44 -0700184 if (strlen(fs_type) == 0) {
185 ErrorAbort(state, "fs_type argument to %s() can't be empty", name);
186 goto done;
187 }
188 if (strlen(partition_type) == 0) {
189 ErrorAbort(state, "partition_type argument to %s() can't be empty",
190 name);
Doug Zongker9931f7f2009-06-10 14:11:53 -0700191 goto done;
192 }
193 if (strlen(location) == 0) {
Doug Zongkerd9c9d102009-06-12 12:24:39 -0700194 ErrorAbort(state, "location argument to %s() can't be empty", name);
Doug Zongker9931f7f2009-06-10 14:11:53 -0700195 goto done;
196 }
197
Koushik Duttadf1e4062010-12-18 17:42:31 -0800198 if (strcmp(partition_type, "MTD") == 0 || strcmp(partition_type, "MMC") == 0) {
Koushik Dutta1b867542010-11-10 23:52:09 -0800199 if (0 != erase_partition(location, NULL)) {
Doug Zongker9931f7f2009-06-10 14:11:53 -0700200 result = strdup("");
201 goto done;
202 }
Doug Zongker56c51052010-07-01 09:18:44 -0700203#ifdef USE_EXT4
204 } else if (strcmp(fs_type, "ext4") == 0) {
205 reset_ext4fs_info();
Brian Swetland792b0072010-09-15 18:03:58 -0700206 int status = make_ext4fs(location, NULL, NULL, 0, 0, 0);
Doug Zongker56c51052010-07-01 09:18:44 -0700207 if (status != 0) {
208 fprintf(stderr, "%s: make_ext4fs failed (%d) on %s",
209 name, status, location);
210 result = strdup("");
211 goto done;
212 }
213 result = location;
214#endif
Doug Zongker9931f7f2009-06-10 14:11:53 -0700215 } else {
Doug Zongker56c51052010-07-01 09:18:44 -0700216 fprintf(stderr, "%s: unsupported fs_type \"%s\" partition_type \"%s\"",
217 name, fs_type, partition_type);
Doug Zongker9931f7f2009-06-10 14:11:53 -0700218 }
Shashank Mittal815ca5d2010-07-27 11:09:19 -0700219 result = location;
Doug Zongker9931f7f2009-06-10 14:11:53 -0700220done:
Doug Zongker56c51052010-07-01 09:18:44 -0700221 free(fs_type);
222 free(partition_type);
Doug Zongker9931f7f2009-06-10 14:11:53 -0700223 if (result != location) free(location);
Doug Zongker512536a2010-02-17 16:11:44 -0800224 return StringValue(result);
Doug Zongker9931f7f2009-06-10 14:11:53 -0700225}
226
Doug Zongker8edb00c2009-06-11 17:21:44 -0700227
Doug Zongker512536a2010-02-17 16:11:44 -0800228Value* DeleteFn(const char* name, State* state, int argc, Expr* argv[]) {
Doug Zongker9931f7f2009-06-10 14:11:53 -0700229 char** paths = malloc(argc * sizeof(char*));
230 int i;
231 for (i = 0; i < argc; ++i) {
Doug Zongkerd9c9d102009-06-12 12:24:39 -0700232 paths[i] = Evaluate(state, argv[i]);
Doug Zongker9931f7f2009-06-10 14:11:53 -0700233 if (paths[i] == NULL) {
234 int j;
235 for (j = 0; j < i; ++i) {
236 free(paths[j]);
237 }
238 free(paths);
239 return NULL;
240 }
241 }
242
243 bool recursive = (strcmp(name, "delete_recursive") == 0);
244
245 int success = 0;
246 for (i = 0; i < argc; ++i) {
247 if ((recursive ? dirUnlinkHierarchy(paths[i]) : unlink(paths[i])) == 0)
248 ++success;
249 free(paths[i]);
250 }
251 free(paths);
252
253 char buffer[10];
254 sprintf(buffer, "%d", success);
Doug Zongker512536a2010-02-17 16:11:44 -0800255 return StringValue(strdup(buffer));
Doug Zongker9931f7f2009-06-10 14:11:53 -0700256}
257
Doug Zongker8edb00c2009-06-11 17:21:44 -0700258
Doug Zongker512536a2010-02-17 16:11:44 -0800259Value* ShowProgressFn(const char* name, State* state, int argc, Expr* argv[]) {
Doug Zongker9931f7f2009-06-10 14:11:53 -0700260 if (argc != 2) {
Doug Zongkerd9c9d102009-06-12 12:24:39 -0700261 return ErrorAbort(state, "%s() expects 2 args, got %d", name, argc);
Doug Zongker9931f7f2009-06-10 14:11:53 -0700262 }
263 char* frac_str;
264 char* sec_str;
Doug Zongkerd9c9d102009-06-12 12:24:39 -0700265 if (ReadArgs(state, argv, 2, &frac_str, &sec_str) < 0) {
Doug Zongker9931f7f2009-06-10 14:11:53 -0700266 return NULL;
267 }
268
269 double frac = strtod(frac_str, NULL);
270 int sec = strtol(sec_str, NULL, 10);
271
Doug Zongkerd9c9d102009-06-12 12:24:39 -0700272 UpdaterInfo* ui = (UpdaterInfo*)(state->cookie);
Doug Zongker9931f7f2009-06-10 14:11:53 -0700273 fprintf(ui->cmd_pipe, "progress %f %d\n", frac, sec);
274
Doug Zongker9931f7f2009-06-10 14:11:53 -0700275 free(sec_str);
Doug Zongker512536a2010-02-17 16:11:44 -0800276 return StringValue(frac_str);
Doug Zongkerfbf3c102009-06-24 09:36:20 -0700277}
278
Doug Zongker512536a2010-02-17 16:11:44 -0800279Value* SetProgressFn(const char* name, State* state, int argc, Expr* argv[]) {
Doug Zongkerfbf3c102009-06-24 09:36:20 -0700280 if (argc != 1) {
281 return ErrorAbort(state, "%s() expects 1 arg, got %d", name, argc);
282 }
283 char* frac_str;
284 if (ReadArgs(state, argv, 1, &frac_str) < 0) {
285 return NULL;
286 }
287
288 double frac = strtod(frac_str, NULL);
289
290 UpdaterInfo* ui = (UpdaterInfo*)(state->cookie);
291 fprintf(ui->cmd_pipe, "set_progress %f\n", frac);
292
Doug Zongker512536a2010-02-17 16:11:44 -0800293 return StringValue(frac_str);
Doug Zongker9931f7f2009-06-10 14:11:53 -0700294}
295
Doug Zongker8edb00c2009-06-11 17:21:44 -0700296// package_extract_dir(package_path, destination_path)
Doug Zongker512536a2010-02-17 16:11:44 -0800297Value* PackageExtractDirFn(const char* name, State* state,
Doug Zongker8edb00c2009-06-11 17:21:44 -0700298 int argc, Expr* argv[]) {
Doug Zongker9931f7f2009-06-10 14:11:53 -0700299 if (argc != 2) {
Doug Zongkerd9c9d102009-06-12 12:24:39 -0700300 return ErrorAbort(state, "%s() expects 2 args, got %d", name, argc);
Doug Zongker9931f7f2009-06-10 14:11:53 -0700301 }
302 char* zip_path;
303 char* dest_path;
Doug Zongkerd9c9d102009-06-12 12:24:39 -0700304 if (ReadArgs(state, argv, 2, &zip_path, &dest_path) < 0) return NULL;
Doug Zongker9931f7f2009-06-10 14:11:53 -0700305
Doug Zongkerd9c9d102009-06-12 12:24:39 -0700306 ZipArchive* za = ((UpdaterInfo*)(state->cookie))->package_zip;
Doug Zongker9931f7f2009-06-10 14:11:53 -0700307
308 // To create a consistent system image, never use the clock for timestamps.
309 struct utimbuf timestamp = { 1217592000, 1217592000 }; // 8/1/2008 default
310
311 bool success = mzExtractRecursive(za, zip_path, dest_path,
312 MZ_EXTRACT_FILES_ONLY, &timestamp,
313 NULL, NULL);
314 free(zip_path);
315 free(dest_path);
Doug Zongker512536a2010-02-17 16:11:44 -0800316 return StringValue(strdup(success ? "t" : ""));
Doug Zongker9931f7f2009-06-10 14:11:53 -0700317}
318
Doug Zongker8edb00c2009-06-11 17:21:44 -0700319
320// package_extract_file(package_path, destination_path)
Doug Zongker6aece332010-02-01 14:40:12 -0800321// or
322// package_extract_file(package_path)
323// to return the entire contents of the file as the result of this
Doug Zongker512536a2010-02-17 16:11:44 -0800324// function (the char* returned is actually a FileContents*).
325Value* PackageExtractFileFn(const char* name, State* state,
Doug Zongker8edb00c2009-06-11 17:21:44 -0700326 int argc, Expr* argv[]) {
Doug Zongker6aece332010-02-01 14:40:12 -0800327 if (argc != 1 && argc != 2) {
328 return ErrorAbort(state, "%s() expects 1 or 2 args, got %d",
329 name, argc);
Doug Zongker8edb00c2009-06-11 17:21:44 -0700330 }
Doug Zongker8edb00c2009-06-11 17:21:44 -0700331 bool success = false;
Doug Zongker6aece332010-02-01 14:40:12 -0800332 if (argc == 2) {
333 // The two-argument version extracts to a file.
Doug Zongker8edb00c2009-06-11 17:21:44 -0700334
Doug Zongker6aece332010-02-01 14:40:12 -0800335 char* zip_path;
336 char* dest_path;
337 if (ReadArgs(state, argv, 2, &zip_path, &dest_path) < 0) return NULL;
338
339 ZipArchive* za = ((UpdaterInfo*)(state->cookie))->package_zip;
340 const ZipEntry* entry = mzFindZipEntry(za, zip_path);
341 if (entry == NULL) {
342 fprintf(stderr, "%s: no %s in package\n", name, zip_path);
343 goto done2;
344 }
345
346 FILE* f = fopen(dest_path, "wb");
347 if (f == NULL) {
348 fprintf(stderr, "%s: can't open %s for write: %s\n",
349 name, dest_path, strerror(errno));
350 goto done2;
351 }
352 success = mzExtractZipEntryToFile(za, entry, fileno(f));
353 fclose(f);
354
355 done2:
356 free(zip_path);
357 free(dest_path);
Doug Zongker512536a2010-02-17 16:11:44 -0800358 return StringValue(strdup(success ? "t" : ""));
Doug Zongker6aece332010-02-01 14:40:12 -0800359 } else {
360 // The one-argument version returns the contents of the file
361 // as the result.
362
363 char* zip_path;
Doug Zongker512536a2010-02-17 16:11:44 -0800364 Value* v = malloc(sizeof(Value));
365 v->type = VAL_BLOB;
366 v->size = -1;
367 v->data = NULL;
Doug Zongker6aece332010-02-01 14:40:12 -0800368
369 if (ReadArgs(state, argv, 1, &zip_path) < 0) return NULL;
370
371 ZipArchive* za = ((UpdaterInfo*)(state->cookie))->package_zip;
372 const ZipEntry* entry = mzFindZipEntry(za, zip_path);
373 if (entry == NULL) {
374 fprintf(stderr, "%s: no %s in package\n", name, zip_path);
375 goto done1;
376 }
377
Doug Zongker512536a2010-02-17 16:11:44 -0800378 v->size = mzGetZipEntryUncompLen(entry);
379 v->data = malloc(v->size);
380 if (v->data == NULL) {
Doug Zongker6aece332010-02-01 14:40:12 -0800381 fprintf(stderr, "%s: failed to allocate %ld bytes for %s\n",
Doug Zongker512536a2010-02-17 16:11:44 -0800382 name, (long)v->size, zip_path);
Doug Zongker6aece332010-02-01 14:40:12 -0800383 goto done1;
384 }
385
Doug Zongker512536a2010-02-17 16:11:44 -0800386 success = mzExtractZipEntryToBuffer(za, entry,
387 (unsigned char *)v->data);
Doug Zongker6aece332010-02-01 14:40:12 -0800388
389 done1:
390 free(zip_path);
391 if (!success) {
Doug Zongker512536a2010-02-17 16:11:44 -0800392 free(v->data);
393 v->data = NULL;
394 v->size = -1;
Doug Zongker6aece332010-02-01 14:40:12 -0800395 }
Doug Zongker512536a2010-02-17 16:11:44 -0800396 return v;
Doug Zongker8edb00c2009-06-11 17:21:44 -0700397 }
Doug Zongker8edb00c2009-06-11 17:21:44 -0700398}
399
400
Doug Zongker9931f7f2009-06-10 14:11:53 -0700401// symlink target src1 src2 ...
Doug Zongker60babf82009-09-18 15:11:24 -0700402// unlinks any previously existing src1, src2, etc before creating symlinks.
Doug Zongker512536a2010-02-17 16:11:44 -0800403Value* SymlinkFn(const char* name, State* state, int argc, Expr* argv[]) {
Doug Zongker9931f7f2009-06-10 14:11:53 -0700404 if (argc == 0) {
Doug Zongkerd9c9d102009-06-12 12:24:39 -0700405 return ErrorAbort(state, "%s() expects 1+ args, got %d", name, argc);
Doug Zongker9931f7f2009-06-10 14:11:53 -0700406 }
407 char* target;
Doug Zongkerd9c9d102009-06-12 12:24:39 -0700408 target = Evaluate(state, argv[0]);
Doug Zongker9931f7f2009-06-10 14:11:53 -0700409 if (target == NULL) return NULL;
410
Doug Zongkerd9c9d102009-06-12 12:24:39 -0700411 char** srcs = ReadVarArgs(state, argc-1, argv+1);
Doug Zongker9931f7f2009-06-10 14:11:53 -0700412 if (srcs == NULL) {
413 free(target);
414 return NULL;
415 }
416
417 int i;
418 for (i = 0; i < argc-1; ++i) {
Doug Zongker60babf82009-09-18 15:11:24 -0700419 if (unlink(srcs[i]) < 0) {
420 if (errno != ENOENT) {
421 fprintf(stderr, "%s: failed to remove %s: %s\n",
422 name, srcs[i], strerror(errno));
423 }
424 }
425 if (symlink(target, srcs[i]) < 0) {
426 fprintf(stderr, "%s: failed to symlink %s to %s: %s\n",
427 name, srcs[i], target, strerror(errno));
428 }
Doug Zongker9931f7f2009-06-10 14:11:53 -0700429 free(srcs[i]);
430 }
431 free(srcs);
Doug Zongker512536a2010-02-17 16:11:44 -0800432 return StringValue(strdup(""));
Doug Zongker9931f7f2009-06-10 14:11:53 -0700433}
434
Doug Zongker8edb00c2009-06-11 17:21:44 -0700435
Doug Zongker512536a2010-02-17 16:11:44 -0800436Value* SetPermFn(const char* name, State* state, int argc, Expr* argv[]) {
Doug Zongker9931f7f2009-06-10 14:11:53 -0700437 char* result = NULL;
438 bool recursive = (strcmp(name, "set_perm_recursive") == 0);
439
440 int min_args = 4 + (recursive ? 1 : 0);
441 if (argc < min_args) {
Doug Zongkerd9c9d102009-06-12 12:24:39 -0700442 return ErrorAbort(state, "%s() expects %d+ args, got %d", name, argc);
Doug Zongker9931f7f2009-06-10 14:11:53 -0700443 }
444
Doug Zongkerd9c9d102009-06-12 12:24:39 -0700445 char** args = ReadVarArgs(state, argc, argv);
Doug Zongker9931f7f2009-06-10 14:11:53 -0700446 if (args == NULL) return NULL;
447
448 char* end;
449 int i;
450
451 int uid = strtoul(args[0], &end, 0);
452 if (*end != '\0' || args[0][0] == 0) {
Doug Zongkerd9c9d102009-06-12 12:24:39 -0700453 ErrorAbort(state, "%s: \"%s\" not a valid uid", name, args[0]);
Doug Zongker9931f7f2009-06-10 14:11:53 -0700454 goto done;
455 }
456
457 int gid = strtoul(args[1], &end, 0);
458 if (*end != '\0' || args[1][0] == 0) {
Doug Zongkerd9c9d102009-06-12 12:24:39 -0700459 ErrorAbort(state, "%s: \"%s\" not a valid gid", name, args[1]);
Doug Zongker9931f7f2009-06-10 14:11:53 -0700460 goto done;
461 }
462
463 if (recursive) {
464 int dir_mode = strtoul(args[2], &end, 0);
465 if (*end != '\0' || args[2][0] == 0) {
Doug Zongkerd9c9d102009-06-12 12:24:39 -0700466 ErrorAbort(state, "%s: \"%s\" not a valid dirmode", name, args[2]);
Doug Zongker9931f7f2009-06-10 14:11:53 -0700467 goto done;
468 }
469
470 int file_mode = strtoul(args[3], &end, 0);
471 if (*end != '\0' || args[3][0] == 0) {
Doug Zongkerd9c9d102009-06-12 12:24:39 -0700472 ErrorAbort(state, "%s: \"%s\" not a valid filemode",
Doug Zongker9931f7f2009-06-10 14:11:53 -0700473 name, args[3]);
474 goto done;
475 }
476
477 for (i = 4; i < argc; ++i) {
478 dirSetHierarchyPermissions(args[i], uid, gid, dir_mode, file_mode);
479 }
480 } else {
481 int mode = strtoul(args[2], &end, 0);
482 if (*end != '\0' || args[2][0] == 0) {
Doug Zongkerd9c9d102009-06-12 12:24:39 -0700483 ErrorAbort(state, "%s: \"%s\" not a valid mode", name, args[2]);
Doug Zongker9931f7f2009-06-10 14:11:53 -0700484 goto done;
485 }
486
Doug Zongker0bbfe3d2009-06-25 13:37:31 -0700487 for (i = 3; i < argc; ++i) {
Doug Zongker60babf82009-09-18 15:11:24 -0700488 if (chown(args[i], uid, gid) < 0) {
489 fprintf(stderr, "%s: chown of %s to %d %d failed: %s\n",
490 name, args[i], uid, gid, strerror(errno));
491 }
492 if (chmod(args[i], mode) < 0) {
493 fprintf(stderr, "%s: chmod of %s to %o failed: %s\n",
494 name, args[i], mode, strerror(errno));
495 }
Doug Zongker9931f7f2009-06-10 14:11:53 -0700496 }
497 }
498 result = strdup("");
499
500done:
501 for (i = 0; i < argc; ++i) {
502 free(args[i]);
503 }
504 free(args);
505
Doug Zongker512536a2010-02-17 16:11:44 -0800506 return StringValue(result);
Doug Zongker9931f7f2009-06-10 14:11:53 -0700507}
508
Doug Zongker8edb00c2009-06-11 17:21:44 -0700509
Doug Zongker512536a2010-02-17 16:11:44 -0800510Value* GetPropFn(const char* name, State* state, int argc, Expr* argv[]) {
Doug Zongker8edb00c2009-06-11 17:21:44 -0700511 if (argc != 1) {
Doug Zongkerd9c9d102009-06-12 12:24:39 -0700512 return ErrorAbort(state, "%s() expects 1 arg, got %d", name, argc);
Doug Zongker8edb00c2009-06-11 17:21:44 -0700513 }
514 char* key;
Doug Zongkerd9c9d102009-06-12 12:24:39 -0700515 key = Evaluate(state, argv[0]);
Doug Zongker8edb00c2009-06-11 17:21:44 -0700516 if (key == NULL) return NULL;
517
518 char value[PROPERTY_VALUE_MAX];
519 property_get(key, value, "");
520 free(key);
521
Doug Zongker512536a2010-02-17 16:11:44 -0800522 return StringValue(strdup(value));
Doug Zongker8edb00c2009-06-11 17:21:44 -0700523}
524
525
Doug Zongker47cace92009-06-18 10:11:50 -0700526// file_getprop(file, key)
527//
528// interprets 'file' as a getprop-style file (key=value pairs, one
529// per line, # comment lines and blank lines okay), and returns the value
530// for 'key' (or "" if it isn't defined).
Doug Zongker512536a2010-02-17 16:11:44 -0800531Value* FileGetPropFn(const char* name, State* state, int argc, Expr* argv[]) {
Doug Zongker47cace92009-06-18 10:11:50 -0700532 char* result = NULL;
533 char* buffer = NULL;
534 char* filename;
535 char* key;
536 if (ReadArgs(state, argv, 2, &filename, &key) < 0) {
537 return NULL;
538 }
539
540 struct stat st;
541 if (stat(filename, &st) < 0) {
542 ErrorAbort(state, "%s: failed to stat \"%s\": %s",
543 name, filename, strerror(errno));
544 goto done;
545 }
546
547#define MAX_FILE_GETPROP_SIZE 65536
548
549 if (st.st_size > MAX_FILE_GETPROP_SIZE) {
550 ErrorAbort(state, "%s too large for %s (max %d)",
551 filename, name, MAX_FILE_GETPROP_SIZE);
552 goto done;
553 }
554
555 buffer = malloc(st.st_size+1);
556 if (buffer == NULL) {
557 ErrorAbort(state, "%s: failed to alloc %d bytes", name, st.st_size+1);
558 goto done;
559 }
560
561 FILE* f = fopen(filename, "rb");
562 if (f == NULL) {
563 ErrorAbort(state, "%s: failed to open %s: %s",
564 name, filename, strerror(errno));
565 goto done;
566 }
567
568 if (fread(buffer, 1, st.st_size, f) != st.st_size) {
569 ErrorAbort(state, "%s: failed to read %d bytes from %s",
570 name, st.st_size+1, filename);
571 fclose(f);
572 goto done;
573 }
574 buffer[st.st_size] = '\0';
575
576 fclose(f);
577
578 char* line = strtok(buffer, "\n");
579 do {
580 // skip whitespace at start of line
581 while (*line && isspace(*line)) ++line;
582
583 // comment or blank line: skip to next line
584 if (*line == '\0' || *line == '#') continue;
585
586 char* equal = strchr(line, '=');
587 if (equal == NULL) {
588 ErrorAbort(state, "%s: malformed line \"%s\": %s not a prop file?",
589 name, line, filename);
590 goto done;
591 }
592
593 // trim whitespace between key and '='
594 char* key_end = equal-1;
595 while (key_end > line && isspace(*key_end)) --key_end;
596 key_end[1] = '\0';
597
598 // not the key we're looking for
599 if (strcmp(key, line) != 0) continue;
600
601 // skip whitespace after the '=' to the start of the value
602 char* val_start = equal+1;
603 while(*val_start && isspace(*val_start)) ++val_start;
604
605 // trim trailing whitespace
606 char* val_end = val_start + strlen(val_start)-1;
607 while (val_end > val_start && isspace(*val_end)) --val_end;
608 val_end[1] = '\0';
609
610 result = strdup(val_start);
611 break;
612
613 } while ((line = strtok(NULL, "\n")));
614
615 if (result == NULL) result = strdup("");
616
617 done:
618 free(filename);
619 free(key);
620 free(buffer);
Doug Zongker512536a2010-02-17 16:11:44 -0800621 return StringValue(result);
Doug Zongker47cace92009-06-18 10:11:50 -0700622}
623
624
Doug Zongker8edb00c2009-06-11 17:21:44 -0700625static bool write_raw_image_cb(const unsigned char* data,
626 int data_len, void* ctx) {
627 int r = mtd_write_data((MtdWriteContext*)ctx, (const char *)data, data_len);
628 if (r == data_len) return true;
629 fprintf(stderr, "%s\n", strerror(errno));
630 return false;
631}
632
633// write_raw_image(file, partition)
Doug Zongker512536a2010-02-17 16:11:44 -0800634Value* WriteRawImageFn(const char* name, State* state, int argc, Expr* argv[]) {
Doug Zongker8edb00c2009-06-11 17:21:44 -0700635 char* result = NULL;
636
637 char* partition;
638 char* filename;
Doug Zongkerd9c9d102009-06-12 12:24:39 -0700639 if (ReadArgs(state, argv, 2, &filename, &partition) < 0) {
Doug Zongker8edb00c2009-06-11 17:21:44 -0700640 return NULL;
641 }
642
643 if (strlen(partition) == 0) {
Doug Zongkerd9c9d102009-06-12 12:24:39 -0700644 ErrorAbort(state, "partition argument to %s can't be empty", name);
Doug Zongker8edb00c2009-06-11 17:21:44 -0700645 goto done;
646 }
647 if (strlen(filename) == 0) {
Doug Zongkerd9c9d102009-06-12 12:24:39 -0700648 ErrorAbort(state, "file argument to %s can't be empty", name);
Doug Zongker8edb00c2009-06-11 17:21:44 -0700649 goto done;
650 }
651
Koushik Dutta1b867542010-11-10 23:52:09 -0800652 if (0 == restore_raw_partition(partition, filename))
653 result = strdup(partition);
654 else
Doug Zongker8edb00c2009-06-11 17:21:44 -0700655 result = strdup("");
Doug Zongker8edb00c2009-06-11 17:21:44 -0700656
657done:
658 if (result != partition) free(partition);
659 free(filename);
Doug Zongker512536a2010-02-17 16:11:44 -0800660 return StringValue(result);
Doug Zongker8edb00c2009-06-11 17:21:44 -0700661}
662
Doug Zongker8edb00c2009-06-11 17:21:44 -0700663// apply_patch_space(bytes)
Doug Zongkerc4351c72010-02-22 14:46:32 -0800664Value* ApplyPatchSpaceFn(const char* name, State* state,
665 int argc, Expr* argv[]) {
666 char* bytes_str;
667 if (ReadArgs(state, argv, 1, &bytes_str) < 0) {
668 return NULL;
669 }
670
671 char* endptr;
672 size_t bytes = strtol(bytes_str, &endptr, 10);
673 if (bytes == 0 && endptr == bytes_str) {
674 ErrorAbort(state, "%s(): can't parse \"%s\" as byte count\n\n",
675 name, bytes_str);
676 free(bytes_str);
677 return NULL;
678 }
679
680 return StringValue(strdup(CacheSizeCheck(bytes) ? "" : "t"));
681}
682
683
684// apply_patch(srcfile, tgtfile, tgtsha1, tgtsize, sha1_1, patch_1, ...)
Doug Zongker512536a2010-02-17 16:11:44 -0800685Value* ApplyPatchFn(const char* name, State* state, int argc, Expr* argv[]) {
Doug Zongkerc4351c72010-02-22 14:46:32 -0800686 if (argc < 6 || (argc % 2) == 1) {
687 return ErrorAbort(state, "%s(): expected at least 6 args and an "
688 "even number, got %d",
689 name, argc);
Doug Zongker8edb00c2009-06-11 17:21:44 -0700690 }
691
Doug Zongkerc4351c72010-02-22 14:46:32 -0800692 char* source_filename;
693 char* target_filename;
694 char* target_sha1;
695 char* target_size_str;
696 if (ReadArgs(state, argv, 4, &source_filename, &target_filename,
697 &target_sha1, &target_size_str) < 0) {
698 return NULL;
Doug Zongker8edb00c2009-06-11 17:21:44 -0700699 }
Doug Zongker8edb00c2009-06-11 17:21:44 -0700700
Doug Zongkerc4351c72010-02-22 14:46:32 -0800701 char* endptr;
702 size_t target_size = strtol(target_size_str, &endptr, 10);
703 if (target_size == 0 && endptr == target_size_str) {
704 ErrorAbort(state, "%s(): can't parse \"%s\" as byte count",
705 name, target_size_str);
706 free(source_filename);
707 free(target_filename);
708 free(target_sha1);
709 free(target_size_str);
710 return NULL;
711 }
712
713 int patchcount = (argc-4) / 2;
714 Value** patches = ReadValueVarArgs(state, argc-4, argv+4);
Doug Zongker8edb00c2009-06-11 17:21:44 -0700715
716 int i;
Doug Zongkerc4351c72010-02-22 14:46:32 -0800717 for (i = 0; i < patchcount; ++i) {
718 if (patches[i*2]->type != VAL_STRING) {
719 ErrorAbort(state, "%s(): sha-1 #%d is not string", name, i);
720 break;
721 }
722 if (patches[i*2+1]->type != VAL_BLOB) {
723 ErrorAbort(state, "%s(): patch #%d is not blob", name, i);
724 break;
725 }
Doug Zongker8edb00c2009-06-11 17:21:44 -0700726 }
Doug Zongkerc4351c72010-02-22 14:46:32 -0800727 if (i != patchcount) {
728 for (i = 0; i < patchcount*2; ++i) {
729 FreeValue(patches[i]);
730 }
731 free(patches);
732 return NULL;
733 }
Doug Zongker8edb00c2009-06-11 17:21:44 -0700734
Doug Zongkerc4351c72010-02-22 14:46:32 -0800735 char** patch_sha_str = malloc(patchcount * sizeof(char*));
736 for (i = 0; i < patchcount; ++i) {
737 patch_sha_str[i] = patches[i*2]->data;
738 patches[i*2]->data = NULL;
739 FreeValue(patches[i*2]);
740 patches[i] = patches[i*2+1];
Doug Zongker8edb00c2009-06-11 17:21:44 -0700741 }
Doug Zongkerc4351c72010-02-22 14:46:32 -0800742
743 int result = applypatch(source_filename, target_filename,
744 target_sha1, target_size,
745 patchcount, patch_sha_str, patches);
746
747 for (i = 0; i < patchcount; ++i) {
748 FreeValue(patches[i]);
749 }
750 free(patch_sha_str);
751 free(patches);
752
753 return StringValue(strdup(result == 0 ? "t" : ""));
754}
755
756// apply_patch_check(file, [sha1_1, ...])
757Value* ApplyPatchCheckFn(const char* name, State* state,
758 int argc, Expr* argv[]) {
759 if (argc < 1) {
760 return ErrorAbort(state, "%s(): expected at least 1 arg, got %d",
761 name, argc);
762 }
763
764 char* filename;
765 if (ReadArgs(state, argv, 1, &filename) < 0) {
766 return NULL;
767 }
768
769 int patchcount = argc-1;
770 char** sha1s = ReadVarArgs(state, argc-1, argv+1);
771
772 int result = applypatch_check(filename, patchcount, sha1s);
773
774 int i;
775 for (i = 0; i < patchcount; ++i) {
776 free(sha1s[i]);
777 }
778 free(sha1s);
779
780 return StringValue(strdup(result == 0 ? "t" : ""));
Doug Zongker8edb00c2009-06-11 17:21:44 -0700781}
782
Doug Zongker512536a2010-02-17 16:11:44 -0800783Value* UIPrintFn(const char* name, State* state, int argc, Expr* argv[]) {
Doug Zongkerd9c9d102009-06-12 12:24:39 -0700784 char** args = ReadVarArgs(state, argc, argv);
785 if (args == NULL) {
786 return NULL;
787 }
788
789 int size = 0;
790 int i;
791 for (i = 0; i < argc; ++i) {
792 size += strlen(args[i]);
793 }
794 char* buffer = malloc(size+1);
795 size = 0;
796 for (i = 0; i < argc; ++i) {
797 strcpy(buffer+size, args[i]);
798 size += strlen(args[i]);
799 free(args[i]);
800 }
801 free(args);
802 buffer[size] = '\0';
803
804 char* line = strtok(buffer, "\n");
805 while (line) {
806 fprintf(((UpdaterInfo*)(state->cookie))->cmd_pipe,
807 "ui_print %s\n", line);
808 line = strtok(NULL, "\n");
809 }
810 fprintf(((UpdaterInfo*)(state->cookie))->cmd_pipe, "ui_print\n");
811
Doug Zongker512536a2010-02-17 16:11:44 -0800812 return StringValue(buffer);
Doug Zongkerd9c9d102009-06-12 12:24:39 -0700813}
814
Doug Zongker512536a2010-02-17 16:11:44 -0800815Value* RunProgramFn(const char* name, State* state, int argc, Expr* argv[]) {
Doug Zongkera3f89ea2009-09-10 14:10:48 -0700816 if (argc < 1) {
817 return ErrorAbort(state, "%s() expects at least 1 arg", name);
818 }
819 char** args = ReadVarArgs(state, argc, argv);
820 if (args == NULL) {
821 return NULL;
822 }
823
824 char** args2 = malloc(sizeof(char*) * (argc+1));
825 memcpy(args2, args, sizeof(char*) * argc);
826 args2[argc] = NULL;
827
828 fprintf(stderr, "about to run program [%s] with %d args\n", args2[0], argc);
829
830 pid_t child = fork();
831 if (child == 0) {
832 execv(args2[0], args2);
833 fprintf(stderr, "run_program: execv failed: %s\n", strerror(errno));
834 _exit(1);
835 }
836 int status;
837 waitpid(child, &status, 0);
838 if (WIFEXITED(status)) {
839 if (WEXITSTATUS(status) != 0) {
840 fprintf(stderr, "run_program: child exited with status %d\n",
841 WEXITSTATUS(status));
842 }
843 } else if (WIFSIGNALED(status)) {
844 fprintf(stderr, "run_program: child terminated by signal %d\n",
845 WTERMSIG(status));
846 }
847
848 int i;
849 for (i = 0; i < argc; ++i) {
850 free(args[i]);
851 }
852 free(args);
853 free(args2);
854
855 char buffer[20];
856 sprintf(buffer, "%d", status);
857
Doug Zongker512536a2010-02-17 16:11:44 -0800858 return StringValue(strdup(buffer));
Doug Zongkera3f89ea2009-09-10 14:10:48 -0700859}
860
Doug Zongker512536a2010-02-17 16:11:44 -0800861// Take a sha-1 digest and return it as a newly-allocated hex string.
862static char* PrintSha1(uint8_t* digest) {
863 char* buffer = malloc(SHA_DIGEST_SIZE*2 + 1);
864 int i;
865 const char* alphabet = "0123456789abcdef";
866 for (i = 0; i < SHA_DIGEST_SIZE; ++i) {
867 buffer[i*2] = alphabet[(digest[i] >> 4) & 0xf];
868 buffer[i*2+1] = alphabet[digest[i] & 0xf];
869 }
870 buffer[i*2] = '\0';
871 return buffer;
872}
873
874// sha1_check(data)
875// to return the sha1 of the data (given in the format returned by
876// read_file).
877//
878// sha1_check(data, sha1_hex, [sha1_hex, ...])
879// returns the sha1 of the file if it matches any of the hex
880// strings passed, or "" if it does not equal any of them.
881//
882Value* Sha1CheckFn(const char* name, State* state, int argc, Expr* argv[]) {
883 if (argc < 1) {
884 return ErrorAbort(state, "%s() expects at least 1 arg", name);
885 }
886
887 Value** args = ReadValueVarArgs(state, argc, argv);
888 if (args == NULL) {
889 return NULL;
890 }
891
892 if (args[0]->size < 0) {
893 fprintf(stderr, "%s(): no file contents received", name);
894 return StringValue(strdup(""));
895 }
896 uint8_t digest[SHA_DIGEST_SIZE];
897 SHA(args[0]->data, args[0]->size, digest);
898 FreeValue(args[0]);
899
900 if (argc == 1) {
901 return StringValue(PrintSha1(digest));
902 }
903
904 int i;
905 uint8_t* arg_digest = malloc(SHA_DIGEST_SIZE);
906 for (i = 1; i < argc; ++i) {
907 if (args[i]->type != VAL_STRING) {
908 fprintf(stderr, "%s(): arg %d is not a string; skipping",
909 name, i);
910 } else if (ParseSha1(args[i]->data, arg_digest) != 0) {
911 // Warn about bad args and skip them.
912 fprintf(stderr, "%s(): error parsing \"%s\" as sha-1; skipping",
913 name, args[i]->data);
914 } else if (memcmp(digest, arg_digest, SHA_DIGEST_SIZE) == 0) {
915 break;
916 }
917 FreeValue(args[i]);
918 }
919 if (i >= argc) {
920 // Didn't match any of the hex strings; return false.
921 return StringValue(strdup(""));
922 }
923 // Found a match; free all the remaining arguments and return the
924 // matched one.
925 int j;
926 for (j = i+1; j < argc; ++j) {
927 FreeValue(args[j]);
928 }
929 return args[i];
930}
931
932// Read a local file and return its contents (the char* returned
933// is actually a FileContents*).
934Value* ReadFileFn(const char* name, State* state, int argc, Expr* argv[]) {
935 if (argc != 1) {
936 return ErrorAbort(state, "%s() expects 1 arg, got %d", name, argc);
937 }
938 char* filename;
939 if (ReadArgs(state, argv, 1, &filename) < 0) return NULL;
940
941 Value* v = malloc(sizeof(Value));
942 v->type = VAL_BLOB;
943
944 FileContents fc;
945 if (LoadFileContents(filename, &fc) != 0) {
946 ErrorAbort(state, "%s() loading \"%s\" failed: %s",
947 name, filename, strerror(errno));
948 free(filename);
949 free(v);
950 free(fc.data);
951 return NULL;
952 }
953
954 v->size = fc.size;
955 v->data = (char*)fc.data;
956
957 free(filename);
958 return v;
959}
Doug Zongker8edb00c2009-06-11 17:21:44 -0700960
Doug Zongker9931f7f2009-06-10 14:11:53 -0700961void RegisterInstallFunctions() {
962 RegisterFunction("mount", MountFn);
Doug Zongker8edb00c2009-06-11 17:21:44 -0700963 RegisterFunction("is_mounted", IsMountedFn);
Doug Zongker9931f7f2009-06-10 14:11:53 -0700964 RegisterFunction("unmount", UnmountFn);
965 RegisterFunction("format", FormatFn);
966 RegisterFunction("show_progress", ShowProgressFn);
Doug Zongkerfbf3c102009-06-24 09:36:20 -0700967 RegisterFunction("set_progress", SetProgressFn);
Doug Zongker9931f7f2009-06-10 14:11:53 -0700968 RegisterFunction("delete", DeleteFn);
969 RegisterFunction("delete_recursive", DeleteFn);
Doug Zongker8edb00c2009-06-11 17:21:44 -0700970 RegisterFunction("package_extract_dir", PackageExtractDirFn);
971 RegisterFunction("package_extract_file", PackageExtractFileFn);
Doug Zongker9931f7f2009-06-10 14:11:53 -0700972 RegisterFunction("symlink", SymlinkFn);
973 RegisterFunction("set_perm", SetPermFn);
974 RegisterFunction("set_perm_recursive", SetPermFn);
Doug Zongker8edb00c2009-06-11 17:21:44 -0700975
976 RegisterFunction("getprop", GetPropFn);
Doug Zongker47cace92009-06-18 10:11:50 -0700977 RegisterFunction("file_getprop", FileGetPropFn);
Doug Zongker8edb00c2009-06-11 17:21:44 -0700978 RegisterFunction("write_raw_image", WriteRawImageFn);
Doug Zongker8edb00c2009-06-11 17:21:44 -0700979
980 RegisterFunction("apply_patch", ApplyPatchFn);
Doug Zongkerc4351c72010-02-22 14:46:32 -0800981 RegisterFunction("apply_patch_check", ApplyPatchCheckFn);
982 RegisterFunction("apply_patch_space", ApplyPatchSpaceFn);
Doug Zongkerd9c9d102009-06-12 12:24:39 -0700983
Doug Zongker512536a2010-02-17 16:11:44 -0800984 RegisterFunction("read_file", ReadFileFn);
985 RegisterFunction("sha1_check", Sha1CheckFn);
986
Doug Zongkerd9c9d102009-06-12 12:24:39 -0700987 RegisterFunction("ui_print", UIPrintFn);
Doug Zongkera3f89ea2009-09-10 14:10:48 -0700988
989 RegisterFunction("run_program", RunProgramFn);
Doug Zongker9931f7f2009-06-10 14:11:53 -0700990}