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> |
| 21 | #include "mincrypt/sha.h" |
Hristo Bojinov | db314d6 | 2010-08-02 10:29:49 -0700 | [diff] [blame] | 22 | #include "minelf/Retouch.h" |
Doug Zongker | c4351c7 | 2010-02-22 14:46:32 -0800 | [diff] [blame] | 23 | #include "edify/expr.h" |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 24 | |
| 25 | typedef struct _Patch { |
| 26 | uint8_t sha1[SHA_DIGEST_SIZE]; |
| 27 | const char* patch_filename; |
| 28 | } Patch; |
| 29 | |
| 30 | typedef struct _FileContents { |
| 31 | uint8_t sha1[SHA_DIGEST_SIZE]; |
| 32 | unsigned char* data; |
| 33 | ssize_t size; |
| 34 | struct stat st; |
| 35 | } FileContents; |
| 36 | |
| 37 | // When there isn't enough room on the target filesystem to hold the |
| 38 | // patched version of the file, we copy the original here and delete |
| 39 | // it to free up space. If the expected source file doesn't exist, or |
| 40 | // is corrupted, we look to see if this file contains the bits we want |
| 41 | // and use it as the source instead. |
| 42 | #define CACHE_TEMP_SOURCE "/cache/saved.file" |
| 43 | |
| 44 | typedef ssize_t (*SinkFn)(unsigned char*, ssize_t, void*); |
| 45 | |
| 46 | // applypatch.c |
Doug Zongker | c4351c7 | 2010-02-22 14:46:32 -0800 | [diff] [blame] | 47 | int ShowLicenses(); |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 48 | size_t FreeSpaceForFile(const char* filename); |
Doug Zongker | c4351c7 | 2010-02-22 14:46:32 -0800 | [diff] [blame] | 49 | int CacheSizeCheck(size_t bytes); |
| 50 | int ParseSha1(const char* str, uint8_t* digest); |
| 51 | |
| 52 | int applypatch(const char* source_filename, |
| 53 | const char* target_filename, |
| 54 | const char* target_sha1_str, |
| 55 | size_t target_size, |
| 56 | int num_patches, |
| 57 | char** const patch_sha1_str, |
| 58 | Value** patch_data); |
| 59 | int applypatch_check(const char* filename, |
| 60 | int num_patches, |
| 61 | char** const patch_sha1_str); |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 62 | |
Hristo Bojinov | db314d6 | 2010-08-02 10:29:49 -0700 | [diff] [blame] | 63 | int LoadFileContents(const char* filename, FileContents* file, |
| 64 | int retouch_flag); |
| 65 | int SaveFileContents(const char* filename, FileContents file); |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 66 | void FreeFileContents(FileContents* file); |
Hristo Bojinov | db314d6 | 2010-08-02 10:29:49 -0700 | [diff] [blame] | 67 | int FindMatchingPatch(uint8_t* sha1, char** const patch_sha1_str, |
| 68 | int num_patches); |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 69 | |
| 70 | // bsdiff.c |
| 71 | void ShowBSDiffLicense(); |
| 72 | int ApplyBSDiffPatch(const unsigned char* old_data, ssize_t old_size, |
Doug Zongker | c4351c7 | 2010-02-22 14:46:32 -0800 | [diff] [blame] | 73 | const Value* patch, ssize_t patch_offset, |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 74 | SinkFn sink, void* token, SHA_CTX* ctx); |
| 75 | int ApplyBSDiffPatchMem(const unsigned char* old_data, ssize_t old_size, |
Doug Zongker | c4351c7 | 2010-02-22 14:46:32 -0800 | [diff] [blame] | 76 | const Value* patch, ssize_t patch_offset, |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 77 | unsigned char** new_data, ssize_t* new_size); |
| 78 | |
| 79 | // imgpatch.c |
| 80 | int ApplyImagePatch(const unsigned char* old_data, ssize_t old_size, |
Doug Zongker | c4351c7 | 2010-02-22 14:46:32 -0800 | [diff] [blame] | 81 | const Value* patch, |
Doug Zongker | 512536a | 2010-02-17 16:11:44 -0800 | [diff] [blame] | 82 | SinkFn sink, void* token, SHA_CTX* ctx); |
| 83 | |
| 84 | // freecache.c |
| 85 | int MakeFreeSpaceOnCache(size_t bytes_needed); |
| 86 | |
| 87 | #endif |