blob: 415bc1b3cd2a3a23e296c1fe3235698f5e21b154 [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
20#include <sys/stat.h>
21#include "mincrypt/sha.h"
Doug Zongkerc4351c72010-02-22 14:46:32 -080022#include "edify/expr.h"
Doug Zongker512536a2010-02-17 16:11:44 -080023
24typedef struct _Patch {
25 uint8_t sha1[SHA_DIGEST_SIZE];
26 const char* patch_filename;
27} Patch;
28
29typedef struct _FileContents {
30 uint8_t sha1[SHA_DIGEST_SIZE];
31 unsigned char* data;
32 ssize_t size;
33 struct stat st;
34} FileContents;
35
36// When there isn't enough room on the target filesystem to hold the
37// patched version of the file, we copy the original here and delete
38// it to free up space. If the expected source file doesn't exist, or
39// is corrupted, we look to see if this file contains the bits we want
40// and use it as the source instead.
41#define CACHE_TEMP_SOURCE "/cache/saved.file"
42
Doug Zongker66f5ce32014-08-15 14:31:52 -070043typedef ssize_t (*SinkFn)(const unsigned char*, ssize_t, void*);
Doug Zongker512536a2010-02-17 16:11:44 -080044
45// applypatch.c
Doug Zongkerc4351c72010-02-22 14:46:32 -080046int ShowLicenses();
Doug Zongker512536a2010-02-17 16:11:44 -080047size_t FreeSpaceForFile(const char* filename);
Doug Zongkerc4351c72010-02-22 14:46:32 -080048int CacheSizeCheck(size_t bytes);
49int ParseSha1(const char* str, uint8_t* digest);
50
Tao Baoabba55b2015-07-17 18:11:12 -070051int applypatch_flash(const char* source_filename, const char* target_filename,
52 const char* target_sha1_str, size_t target_size);
Doug Zongkerc4351c72010-02-22 14:46:32 -080053int applypatch(const char* source_filename,
54 const char* target_filename,
55 const char* target_sha1_str,
56 size_t target_size,
57 int num_patches,
58 char** const patch_sha1_str,
Doug Zongkera3ccba62012-08-20 15:28:02 -070059 Value** patch_data,
60 Value* bonus_data);
Doug Zongkerc4351c72010-02-22 14:46:32 -080061int applypatch_check(const char* filename,
62 int num_patches,
63 char** const patch_sha1_str);
Doug Zongker512536a2010-02-17 16:11:44 -080064
Doug Zongkera1bc1482014-02-13 15:18:19 -080065int LoadFileContents(const char* filename, FileContents* file);
Doug Zongker1c43c972012-02-28 11:07:09 -080066int SaveFileContents(const char* filename, const FileContents* file);
Doug Zongker512536a2010-02-17 16:11:44 -080067void FreeFileContents(FileContents* file);
Doug Zongker044a0b42013-07-08 09:42:54 -070068int FindMatchingPatch(uint8_t* sha1, char* const * const patch_sha1_str,
Hristo Bojinovdb314d62010-08-02 10:29:49 -070069 int num_patches);
Doug Zongker512536a2010-02-17 16:11:44 -080070
71// bsdiff.c
72void ShowBSDiffLicense();
73int ApplyBSDiffPatch(const unsigned char* old_data, ssize_t old_size,
Doug Zongkerc4351c72010-02-22 14:46:32 -080074 const Value* patch, ssize_t patch_offset,
Doug Zongker512536a2010-02-17 16:11:44 -080075 SinkFn sink, void* token, SHA_CTX* ctx);
76int ApplyBSDiffPatchMem(const unsigned char* old_data, ssize_t old_size,
Doug Zongkerc4351c72010-02-22 14:46:32 -080077 const Value* patch, ssize_t patch_offset,
Doug Zongker512536a2010-02-17 16:11:44 -080078 unsigned char** new_data, ssize_t* new_size);
79
80// imgpatch.c
81int ApplyImagePatch(const unsigned char* old_data, ssize_t old_size,
Doug Zongkerc4351c72010-02-22 14:46:32 -080082 const Value* patch,
Doug Zongkera3ccba62012-08-20 15:28:02 -070083 SinkFn sink, void* token, SHA_CTX* ctx,
84 const Value* bonus_data);
Doug Zongker512536a2010-02-17 16:11:44 -080085
86// freecache.c
87int MakeFreeSpaceOnCache(size_t bytes_needed);
88
89#endif