Home | History | Annotate | Download | only in applypatch
      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 #include "mincrypt/sha.h"
     22 #include "edify/expr.h"
     23 
     24 typedef struct _Patch {
     25   uint8_t sha1[SHA_DIGEST_SIZE];
     26   const char* patch_filename;
     27 } Patch;
     28 
     29 typedef 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 
     43 typedef ssize_t (*SinkFn)(unsigned char*, ssize_t, void*);
     44 
     45 // applypatch.c
     46 int ShowLicenses();
     47 size_t FreeSpaceForFile(const char* filename);
     48 int CacheSizeCheck(size_t bytes);
     49 int ParseSha1(const char* str, uint8_t* digest);
     50 
     51 int applypatch(const char* source_filename,
     52                const char* target_filename,
     53                const char* target_sha1_str,
     54                size_t target_size,
     55                int num_patches,
     56                char** const patch_sha1_str,
     57                Value** patch_data);
     58 int applypatch_check(const char* filename,
     59                      int num_patches,
     60                      char** const patch_sha1_str);
     61 
     62 // Read a file into memory; store it and its associated metadata in
     63 // *file.  Return 0 on success.
     64 int LoadFileContents(const char* filename, FileContents* file);
     65 void FreeFileContents(FileContents* file);
     66 
     67 // bsdiff.c
     68 void ShowBSDiffLicense();
     69 int ApplyBSDiffPatch(const unsigned char* old_data, ssize_t old_size,
     70                      const Value* patch, ssize_t patch_offset,
     71                      SinkFn sink, void* token, SHA_CTX* ctx);
     72 int ApplyBSDiffPatchMem(const unsigned char* old_data, ssize_t old_size,
     73                         const Value* patch, ssize_t patch_offset,
     74                         unsigned char** new_data, ssize_t* new_size);
     75 
     76 // imgpatch.c
     77 int ApplyImagePatch(const unsigned char* old_data, ssize_t old_size,
     78                     const Value* patch,
     79                     SinkFn sink, void* token, SHA_CTX* ctx);
     80 
     81 // freecache.c
     82 int MakeFreeSpaceOnCache(size_t bytes_needed);
     83 
     84 #endif
     85