Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef _APPLYPATCH_H |
| 18 | #define _APPLYPATCH_H |
| 19 | |
| 20 | #include <sys/stat.h> |
Yabin Cui | d483c20 | 2016-02-03 17:08:52 -0800 | [diff] [blame] | 21 | |
| 22 | #include <vector> |
| 23 | |
Sen Jiang | c48cb5e | 2016-02-04 16:23:21 +0800 | [diff] [blame] | 24 | #include "openssl/sha.h" |
Doug Zongker | c4351c7 | 2010-02-22 14:46:32 -0800 | [diff] [blame] | 25 | #include "edify/expr.h" |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 26 | |
Yabin Cui | 1c522df | 2016-02-10 16:41:10 -0800 | [diff] [blame] | 27 | struct FileContents { |
Sen Jiang | c48cb5e | 2016-02-04 16:23:21 +0800 | [diff] [blame] | 28 | uint8_t sha1[SHA_DIGEST_LENGTH]; |
Yabin Cui | 1c522df | 2016-02-10 16:41:10 -0800 | [diff] [blame] | 29 | std::vector<unsigned char> data; |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 30 | struct stat st; |
Yabin Cui | 1c522df | 2016-02-10 16:41:10 -0800 | [diff] [blame] | 31 | }; |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 32 | |
| 33 | // When there isn't enough room on the target filesystem to hold the |
| 34 | // patched version of the file, we copy the original here and delete |
| 35 | // it to free up space. If the expected source file doesn't exist, or |
| 36 | // is corrupted, we look to see if this file contains the bits we want |
| 37 | // and use it as the source instead. |
| 38 | #define CACHE_TEMP_SOURCE "/cache/saved.file" |
| 39 | |
Doug Zongker | 66f5ce3 | 2014-08-15 14:31:52 -0700 | [diff] [blame] | 40 | typedef ssize_t (*SinkFn)(const unsigned char*, ssize_t, void*); |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 41 | |
| 42 | // applypatch.c |
Doug Zongker | c4351c7 | 2010-02-22 14:46:32 -0800 | [diff] [blame] | 43 | int ShowLicenses(); |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 44 | size_t FreeSpaceForFile(const char* filename); |
Doug Zongker | c4351c7 | 2010-02-22 14:46:32 -0800 | [diff] [blame] | 45 | int CacheSizeCheck(size_t bytes); |
| 46 | int ParseSha1(const char* str, uint8_t* digest); |
| 47 | |
Tao Bao | abba55b | 2015-07-17 18:11:12 -0700 | [diff] [blame] | 48 | int applypatch_flash(const char* source_filename, const char* target_filename, |
| 49 | const char* target_sha1_str, size_t target_size); |
Doug Zongker | c4351c7 | 2010-02-22 14:46:32 -0800 | [diff] [blame] | 50 | int applypatch(const char* source_filename, |
| 51 | const char* target_filename, |
| 52 | const char* target_sha1_str, |
| 53 | size_t target_size, |
| 54 | int num_patches, |
| 55 | char** const patch_sha1_str, |
Doug Zongker | a3ccba6 | 2012-08-20 15:28:02 -0700 | [diff] [blame] | 56 | Value** patch_data, |
| 57 | Value* bonus_data); |
Doug Zongker | c4351c7 | 2010-02-22 14:46:32 -0800 | [diff] [blame] | 58 | int applypatch_check(const char* filename, |
| 59 | int num_patches, |
| 60 | char** const patch_sha1_str); |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 61 | |
Doug Zongker | a1bc148 | 2014-02-13 15:18:19 -0800 | [diff] [blame] | 62 | int LoadFileContents(const char* filename, FileContents* file); |
Doug Zongker | 1c43c97 | 2012-02-28 11:07:09 -0800 | [diff] [blame] | 63 | int SaveFileContents(const char* filename, const FileContents* file); |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 64 | void FreeFileContents(FileContents* file); |
Doug Zongker | 044a0b4 | 2013-07-08 09:42:54 -0700 | [diff] [blame] | 65 | int FindMatchingPatch(uint8_t* sha1, char* const * const patch_sha1_str, |
Hristo Bojinov | db314d6 | 2010-08-02 10:29:49 -0700 | [diff] [blame] | 66 | int num_patches); |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 67 | |
Yabin Cui | d483c20 | 2016-02-03 17:08:52 -0800 | [diff] [blame] | 68 | // bsdiff.cpp |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 69 | void ShowBSDiffLicense(); |
| 70 | int ApplyBSDiffPatch(const unsigned char* old_data, ssize_t old_size, |
Doug Zongker | c4351c7 | 2010-02-22 14:46:32 -0800 | [diff] [blame] | 71 | const Value* patch, ssize_t patch_offset, |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 72 | SinkFn sink, void* token, SHA_CTX* ctx); |
| 73 | int ApplyBSDiffPatchMem(const unsigned char* old_data, ssize_t old_size, |
Doug Zongker | c4351c7 | 2010-02-22 14:46:32 -0800 | [diff] [blame] | 74 | const Value* patch, ssize_t patch_offset, |
Yabin Cui | d483c20 | 2016-02-03 17:08:52 -0800 | [diff] [blame] | 75 | std::vector<unsigned char>* new_data); |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 76 | |
Yabin Cui | d483c20 | 2016-02-03 17:08:52 -0800 | [diff] [blame] | 77 | // imgpatch.cpp |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 78 | int ApplyImagePatch(const unsigned char* old_data, ssize_t old_size, |
Doug Zongker | c4351c7 | 2010-02-22 14:46:32 -0800 | [diff] [blame] | 79 | const Value* patch, |
Doug Zongker | a3ccba6 | 2012-08-20 15:28:02 -0700 | [diff] [blame] | 80 | SinkFn sink, void* token, SHA_CTX* ctx, |
| 81 | const Value* bonus_data); |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 82 | |
Yabin Cui | d483c20 | 2016-02-03 17:08:52 -0800 | [diff] [blame] | 83 | // freecache.cpp |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 84 | int MakeFreeSpaceOnCache(size_t bytes_needed); |
| 85 | |
| 86 | #endif |