• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
22 #include <vector>
23 
24 #include "openssl/sha.h"
25 #include "edify/expr.h"
26 
27 struct FileContents {
28   uint8_t sha1[SHA_DIGEST_LENGTH];
29   std::vector<unsigned char> data;
30   struct stat st;
31 };
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 
40 typedef ssize_t (*SinkFn)(const unsigned char*, ssize_t, void*);
41 
42 // applypatch.c
43 int ShowLicenses();
44 size_t FreeSpaceForFile(const char* filename);
45 int CacheSizeCheck(size_t bytes);
46 int ParseSha1(const char* str, uint8_t* digest);
47 
48 int applypatch_flash(const char* source_filename, const char* target_filename,
49                      const char* target_sha1_str, size_t target_size);
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,
56                Value** patch_data,
57                Value* bonus_data);
58 int applypatch_check(const char* filename,
59                      int num_patches,
60                      char** const patch_sha1_str);
61 
62 int LoadFileContents(const char* filename, FileContents* file);
63 int SaveFileContents(const char* filename, const FileContents* file);
64 void FreeFileContents(FileContents* file);
65 int FindMatchingPatch(uint8_t* sha1, char* const * const patch_sha1_str,
66                       int num_patches);
67 
68 // bsdiff.cpp
69 void ShowBSDiffLicense();
70 int ApplyBSDiffPatch(const unsigned char* old_data, ssize_t old_size,
71                      const Value* patch, ssize_t patch_offset,
72                      SinkFn sink, void* token, SHA_CTX* ctx);
73 int ApplyBSDiffPatchMem(const unsigned char* old_data, ssize_t old_size,
74                         const Value* patch, ssize_t patch_offset,
75                         std::vector<unsigned char>* new_data);
76 
77 // imgpatch.cpp
78 int ApplyImagePatch(const unsigned char* old_data, ssize_t old_size,
79                     const Value* patch,
80                     SinkFn sink, void* token, SHA_CTX* ctx,
81                     const Value* bonus_data);
82 
83 // freecache.cpp
84 int MakeFreeSpaceOnCache(size_t bytes_needed);
85 
86 #endif
87