blob: 096596f0316213dd9393b7c9d52ba581c0703baa [file] [log] [blame]
Doug Zongker512536a2010-02-17 16:11:44 -08001/*
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
Sen Jiang696692a2016-02-02 16:01:23 +080020#include <stdint.h>
Doug Zongker512536a2010-02-17 16:11:44 -080021#include <sys/stat.h>
Yabin Cuid483c202016-02-03 17:08:52 -080022
23#include <vector>
24
Sen Jiangc48cb5e2016-02-04 16:23:21 +080025#include "openssl/sha.h"
Doug Zongkerc4351c72010-02-22 14:46:32 -080026#include "edify/expr.h"
Doug Zongker512536a2010-02-17 16:11:44 -080027
28typedef struct _Patch {
Sen Jiangc48cb5e2016-02-04 16:23:21 +080029 uint8_t sha1[SHA_DIGEST_LENGTH];
Doug Zongker512536a2010-02-17 16:11:44 -080030 const char* patch_filename;
31} Patch;
32
33typedef struct _FileContents {
Sen Jiangc48cb5e2016-02-04 16:23:21 +080034 uint8_t sha1[SHA_DIGEST_LENGTH];
Doug Zongker512536a2010-02-17 16:11:44 -080035 unsigned char* data;
36 ssize_t size;
37 struct stat st;
38} FileContents;
39
40// When there isn't enough room on the target filesystem to hold the
41// patched version of the file, we copy the original here and delete
42// it to free up space. If the expected source file doesn't exist, or
43// is corrupted, we look to see if this file contains the bits we want
44// and use it as the source instead.
45#define CACHE_TEMP_SOURCE "/cache/saved.file"
46
Doug Zongker66f5ce32014-08-15 14:31:52 -070047typedef ssize_t (*SinkFn)(const unsigned char*, ssize_t, void*);
Doug Zongker512536a2010-02-17 16:11:44 -080048
49// applypatch.c
Doug Zongkerc4351c72010-02-22 14:46:32 -080050int ShowLicenses();
Doug Zongker512536a2010-02-17 16:11:44 -080051size_t FreeSpaceForFile(const char* filename);
Doug Zongkerc4351c72010-02-22 14:46:32 -080052int CacheSizeCheck(size_t bytes);
53int ParseSha1(const char* str, uint8_t* digest);
54
Tao Baoabba55b2015-07-17 18:11:12 -070055int applypatch_flash(const char* source_filename, const char* target_filename,
56 const char* target_sha1_str, size_t target_size);
Doug Zongkerc4351c72010-02-22 14:46:32 -080057int applypatch(const char* source_filename,
58 const char* target_filename,
59 const char* target_sha1_str,
60 size_t target_size,
61 int num_patches,
62 char** const patch_sha1_str,
Doug Zongkera3ccba62012-08-20 15:28:02 -070063 Value** patch_data,
64 Value* bonus_data);
Doug Zongkerc4351c72010-02-22 14:46:32 -080065int applypatch_check(const char* filename,
66 int num_patches,
67 char** const patch_sha1_str);
Doug Zongker512536a2010-02-17 16:11:44 -080068
Doug Zongkera1bc1482014-02-13 15:18:19 -080069int LoadFileContents(const char* filename, FileContents* file);
Doug Zongker1c43c972012-02-28 11:07:09 -080070int SaveFileContents(const char* filename, const FileContents* file);
Doug Zongker512536a2010-02-17 16:11:44 -080071void FreeFileContents(FileContents* file);
Doug Zongker044a0b42013-07-08 09:42:54 -070072int FindMatchingPatch(uint8_t* sha1, char* const * const patch_sha1_str,
Hristo Bojinovdb314d62010-08-02 10:29:49 -070073 int num_patches);
Doug Zongker512536a2010-02-17 16:11:44 -080074
Yabin Cuid483c202016-02-03 17:08:52 -080075// bsdiff.cpp
Doug Zongker512536a2010-02-17 16:11:44 -080076void ShowBSDiffLicense();
77int ApplyBSDiffPatch(const unsigned char* old_data, ssize_t old_size,
Doug Zongkerc4351c72010-02-22 14:46:32 -080078 const Value* patch, ssize_t patch_offset,
Doug Zongker512536a2010-02-17 16:11:44 -080079 SinkFn sink, void* token, SHA_CTX* ctx);
80int ApplyBSDiffPatchMem(const unsigned char* old_data, ssize_t old_size,
Doug Zongkerc4351c72010-02-22 14:46:32 -080081 const Value* patch, ssize_t patch_offset,
Yabin Cuid483c202016-02-03 17:08:52 -080082 std::vector<unsigned char>* new_data);
Doug Zongker512536a2010-02-17 16:11:44 -080083
Yabin Cuid483c202016-02-03 17:08:52 -080084// imgpatch.cpp
Doug Zongker512536a2010-02-17 16:11:44 -080085int ApplyImagePatch(const unsigned char* old_data, ssize_t old_size,
Doug Zongkerc4351c72010-02-22 14:46:32 -080086 const Value* patch,
Doug Zongkera3ccba62012-08-20 15:28:02 -070087 SinkFn sink, void* token, SHA_CTX* ctx,
88 const Value* bonus_data);
Doug Zongker512536a2010-02-17 16:11:44 -080089
Yabin Cuid483c202016-02-03 17:08:52 -080090// freecache.cpp
Doug Zongker512536a2010-02-17 16:11:44 -080091int MakeFreeSpaceOnCache(size_t bytes_needed);
92
93#endif