Lines Matching refs:FILE
5 * you may not use this file except in compliance with the License.
33 static int LoadPartitionContents(const char* filename, FileContents* file);
46 // Read a file into memory; optionally (retouch_flag == RETOUCH_DO_MASK) mask
48 // don't fail due to randomization); store the file contents and associated
49 // metadata in *file.
52 int LoadFileContents(const char* filename, FileContents* file,
54 file->data = NULL;
60 return LoadPartitionContents(filename, file);
63 if (stat(filename, &file->st) != 0) {
68 file->size = file->st.st_size;
69 file->data = malloc(file->size);
71 FILE* f = fopen(filename, "rb");
74 free(file->data);
75 file->data = NULL;
79 ssize_t bytes_read = fread(file->data, 1, file->size, f);
80 if (bytes_read != file->size) {
82 filename, (long)bytes_read, (long)file->size);
83 free(file->data);
84 file->data = NULL;
91 // within a file, this means the file is assumed "corrupt" for simplicity.
94 if (retouch_mask_data(file->data, file->size,
97 free(file->data);
98 file->data = NULL;
103 SHA(file->data, file->size, file->sha1);
134 // "end-of-file" marker), so the caller must specify the possible
139 static int LoadPartitionContents(const char* filename, FileContents* file) {
190 FILE* dev = NULL;
228 file->data = malloc(size[index[pairs-1]]);
229 char* p = (char*)file->data;
230 file->size = 0; // # bytes read so far
236 size_t next = size[index[i]] - file->size;
251 free(file->data);
252 file->data = NULL;
256 file->size += read;
268 free(file->data);
269 file->data = NULL;
300 free(file->data);
301 file->data = NULL;
307 file->sha1[i] = sha_final[i];
311 file->st.st_mode = 0644;
312 file->st.st_uid = 0;
313 file->st.st_gid = 0;
326 int SaveFileContents(const char* filename, const FileContents* file) {
334 ssize_t bytes_written = FileSink(file->data, file->size, &fd);
335 if (bytes_written != file->size) {
337 filename, (long)bytes_written, (long)file->size,
345 if (chmod(filename, file->st.st_mode) != 0) {
349 if (chown(filename, file->st.st_uid, file->st.st_gid) != 0) {
424 FILE* f = fopen(partition, "wb");
488 // Returns 0 if the contents of the file (argv[2]) or the cached file
493 FileContents file;
494 file.data = NULL;
500 if (LoadFileContents(filename, &file, RETOUCH_DO_MASK) != 0 ||
502 FindMatchingPatch(file.sha1, patch_sha1_str, num_patches) < 0)) {
503 printf("file \"%s\" doesn't have any of expected "
506 free(file.data);
507 file.data = NULL;
509 // If the source file is missing or corrupted, it might be because
511 // should have been made in CACHE_TEMP_SOURCE. If that file
515 if (LoadFileContents(CACHE_TEMP_SOURCE, &file, RETOUCH_DO_MASK) != 0) {
516 printf("failed to load cache file\n");
520 if (FindMatchingPatch(file.sha1, patch_sha1_str, num_patches) < 0) {
522 free(file.data);
527 free(file.data);
589 // (the original file is not touched until we have the desired
599 // new file (the type of patch is automatically detected from the
600 // blob daat). If that new file has sha1 hash <target_sha1_str>,
641 // We try to load the target file into the source_file object.
645 // The early-exit case: the patch was already applied, this file
657 // Need to load the source file: either we failed to load the
658 // target file, or we did but it's different from the source file.
676 printf("source file is bad; trying copy\n");
681 printf("failed to read copy file\n");
693 printf("copy file doesn't match source SHA-1s either\n");
740 // file?
748 // space to hold the file.
757 printf("failed to back up source file\n");
779 // copy the source file to cache, then delete it from the original
798 printf("failed to back up source file\n");
841 // We write the decoded output to "<tgt-file>.patch".
848 printf("failed to open output file %s: %s\n",
872 printf("Unknown patch file format\n");
904 // Copy the temp file to the partition.
911 // Give the .patch file the same owner, group, and mode of the
912 // original source file.
923 // Finally, rename the .patch file to replace the target file.