blob: 4489decb65630afa3d0df8ba1ae0095cb6c57e45 [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
Tao Baofada91c2016-10-27 18:16:06 -070023#include <memory>
Tianjie Xuaced5d92016-10-12 10:55:04 -070024#include <string>
Yabin Cuid483c202016-02-03 17:08:52 -080025#include <vector>
26
Tao Baofada91c2016-10-27 18:16:06 -070027#include <openssl/sha.h>
28
Doug Zongkerc4351c72010-02-22 14:46:32 -080029#include "edify/expr.h"
Doug Zongker512536a2010-02-17 16:11:44 -080030
Yabin Cuid6c93af2016-02-10 16:41:10 -080031struct FileContents {
Sen Jiangc48cb5e2016-02-04 16:23:21 +080032 uint8_t sha1[SHA_DIGEST_LENGTH];
Yabin Cuid6c93af2016-02-10 16:41:10 -080033 std::vector<unsigned char> data;
Doug Zongker512536a2010-02-17 16:11:44 -080034 struct stat st;
Yabin Cuid6c93af2016-02-10 16:41:10 -080035};
Doug Zongker512536a2010-02-17 16:11:44 -080036
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
Doug Zongker66f5ce32014-08-15 14:31:52 -070044typedef ssize_t (*SinkFn)(const unsigned char*, ssize_t, void*);
Doug Zongker512536a2010-02-17 16:11:44 -080045
Tao Baofada91c2016-10-27 18:16:06 -070046// applypatch.cpp
Doug Zongkerc4351c72010-02-22 14:46:32 -080047int ShowLicenses();
Doug Zongker512536a2010-02-17 16:11:44 -080048size_t FreeSpaceForFile(const char* filename);
Doug Zongkerc4351c72010-02-22 14:46:32 -080049int CacheSizeCheck(size_t bytes);
50int ParseSha1(const char* str, uint8_t* digest);
51
52int applypatch(const char* source_filename,
53 const char* target_filename,
54 const char* target_sha1_str,
55 size_t target_size,
Tianjie Xuaced5d92016-10-12 10:55:04 -070056 const std::vector<std::string>& patch_sha1_str,
Tao Baofada91c2016-10-27 18:16:06 -070057 const std::vector<std::unique_ptr<Value>>& patch_data,
58 const Value* bonus_data);
Doug Zongkerc4351c72010-02-22 14:46:32 -080059int applypatch_check(const char* filename,
Tianjie Xuaced5d92016-10-12 10:55:04 -070060 const std::vector<std::string>& patch_sha1_str);
Tao Baofada91c2016-10-27 18:16:06 -070061int applypatch_flash(const char* source_filename, const char* target_filename,
62 const char* target_sha1_str, size_t target_size);
Doug Zongker512536a2010-02-17 16:11:44 -080063
Doug Zongkera1bc1482014-02-13 15:18:19 -080064int LoadFileContents(const char* filename, FileContents* file);
Doug Zongker1c43c972012-02-28 11:07:09 -080065int SaveFileContents(const char* filename, const FileContents* file);
Doug Zongker512536a2010-02-17 16:11:44 -080066
Tao Baoc8e79342016-12-28 10:11:22 -080067// bspatch.cpp
Doug Zongker512536a2010-02-17 16:11:44 -080068void ShowBSDiffLicense();
69int ApplyBSDiffPatch(const unsigned char* old_data, ssize_t old_size,
Doug Zongkerc4351c72010-02-22 14:46:32 -080070 const Value* patch, ssize_t patch_offset,
Doug Zongker512536a2010-02-17 16:11:44 -080071 SinkFn sink, void* token, SHA_CTX* ctx);
72int ApplyBSDiffPatchMem(const unsigned char* old_data, ssize_t old_size,
Doug Zongkerc4351c72010-02-22 14:46:32 -080073 const Value* patch, ssize_t patch_offset,
Yabin Cuid483c202016-02-03 17:08:52 -080074 std::vector<unsigned char>* new_data);
Doug Zongker512536a2010-02-17 16:11:44 -080075
Yabin Cuid483c202016-02-03 17:08:52 -080076// imgpatch.cpp
Doug Zongker512536a2010-02-17 16:11:44 -080077int ApplyImagePatch(const unsigned char* old_data, ssize_t old_size,
Doug Zongkerc4351c72010-02-22 14:46:32 -080078 const Value* patch,
Doug Zongkera3ccba62012-08-20 15:28:02 -070079 SinkFn sink, void* token, SHA_CTX* ctx,
80 const Value* bonus_data);
Doug Zongker512536a2010-02-17 16:11:44 -080081
Yabin Cuid483c202016-02-03 17:08:52 -080082// freecache.cpp
Doug Zongker512536a2010-02-17 16:11:44 -080083int MakeFreeSpaceOnCache(size_t bytes_needed);
84
85#endif