blob: ccd8424ab1caf80386fb7fdf0acb70515f2a3f5e [file] [log] [blame]
The Android Open Source Project88b60792009-03-03 19:28:42 -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
Doug Zongker5a790872009-06-12 09:42:43 -070020#include <sys/stat.h>
The Android Open Source Project88b60792009-03-03 19:28:42 -080021#include "mincrypt/sha.h"
22
23typedef struct _Patch {
24 uint8_t sha1[SHA_DIGEST_SIZE];
25 const char* patch_filename;
26} Patch;
27
28typedef struct _FileContents {
29 uint8_t sha1[SHA_DIGEST_SIZE];
30 unsigned char* data;
31 size_t size;
32 struct stat st;
33} FileContents;
34
35// When there isn't enough room on the target filesystem to hold the
36// patched version of the file, we copy the original here and delete
37// it to free up space. If the expected source file doesn't exist, or
38// is corrupted, we look to see if this file contains the bits we want
39// and use it as the source instead.
40#define CACHE_TEMP_SOURCE "/cache/saved.file"
41
Doug Zongker5da317e2009-06-02 13:38:17 -070042// When writing to an MTD partition, we first put the output in this
43// temp file, then copy it to the partition once the patching is
44// finished (and the target sha1 verified).
45#define MTD_TARGET_TEMP_FILE "/tmp/mtd-temp"
46
The Android Open Source Project88b60792009-03-03 19:28:42 -080047// applypatch.c
48size_t FreeSpaceForFile(const char* filename);
Doug Zongker5a790872009-06-12 09:42:43 -070049int applypatch(int argc, char** argv);
The Android Open Source Project88b60792009-03-03 19:28:42 -080050
51// bsdiff.c
52void ShowBSDiffLicense();
53int ApplyBSDiffPatch(const unsigned char* old_data, ssize_t old_size,
Doug Zongker02d444b2009-05-27 18:24:03 -070054 const char* patch_filename, ssize_t offset,
55 FILE* output, SHA_CTX* ctx);
56int ApplyBSDiffPatchMem(const unsigned char* old_data, ssize_t old_size,
57 const char* patch_filename, ssize_t patch_offset,
58 unsigned char** new_data, ssize_t* new_size);
59
60// imgpatch.c
61int ApplyImagePatch(const unsigned char* old_data, ssize_t old_size,
The Android Open Source Project88b60792009-03-03 19:28:42 -080062 const char* patch_filename,
63 FILE* output, SHA_CTX* ctx);
64
65// freecache.c
66int MakeFreeSpaceOnCache(size_t bytes_needed);
67
68#endif