Lines Matching refs:fh
173 static int write_int32(FILE* fh, int32_t val) in write_int32() argument
175 int res = fwrite(&val, 1, sizeof(val), fh); in write_int32()
184 static int write_int64(FILE* fh, int64_t val) in write_int64() argument
186 int res = fwrite(&val, 1, sizeof(val), fh); in write_int64()
235 static int write_header(FILE* fh, int type, const char* path, const struct stat* st) in write_header() argument
238 if (!write_int32(fh, type)) return 0; in write_header()
239 if (!write_int32(fh, pathLen)) return 0; in write_header()
240 if (fwrite(path, 1, pathLen, fh) != (size_t)pathLen) { in write_header()
245 if (!write_int32(fh, st->st_uid)) return 0; in write_header()
246 if (!write_int32(fh, st->st_gid)) return 0; in write_header()
247 if (!write_int32(fh, st->st_mode)) return 0; in write_header()
248 if (!write_int64(fh, ((int64_t)st->st_atime)*1000*1000*1000)) return 0; in write_header()
249 if (!write_int64(fh, ((int64_t)st->st_mtime)*1000*1000*1000)) return 0; in write_header()
250 if (!write_int64(fh, ((int64_t)st->st_ctime)*1000*1000*1000)) return 0; in write_header()
255 static int backup_dir(FILE* fh, const char* srcPath) in backup_dir() argument
318 if (write_header(fh, TYPE_DIR, fullPath, &statBuffer) == 0) { in backup_dir()
322 if (backup_dir(fh, fullPath) == 0) { in backup_dir()
334 if (write_header(fh, TYPE_FILE, fullPath, &statBuffer) == 0) { in backup_dir()
340 if (!write_int64(fh, size)) { in backup_dir()
353 int copyres = copy_file(fh, src, size, nullptr, fullPath); in backup_dir()
376 FILE* fh = fopen(destPath, "w"); in backup_data() local
377 if (fh == nullptr) { in backup_data()
388 if (!write_int32(fh, FILE_VERSION)) goto done; in backup_data()
389 if (!write_int32(fh, opt_backupAll)) goto done; in backup_data()
390 if (!backup_dir(fh, "/data")) goto done; in backup_data()
391 if (!write_int32(fh, 0)) goto done; in backup_data()
396 if (fflush(fh) != 0) { in backup_data()
402 if (fsync(fileno(fh)) != 0) { in backup_data()
408 fclose(fh); in backup_data()
415 static int32_t read_int32(FILE* fh, int32_t defVal) in read_int32() argument
418 if (fread(&val, 1, sizeof(val), fh) != sizeof(val)) { in read_int32()
426 static int64_t read_int64(FILE* fh, int64_t defVal) in read_int64() argument
429 if (fread(&val, 1, sizeof(val), fh) != sizeof(val)) { in read_int64()
437 static int read_header(FILE* fh, int* type, char** path, struct stat* st) in read_header() argument
439 *type = read_int32(fh, -1); in read_header()
449 int32_t pathLen = read_int32(fh, -1); in read_header()
455 if (fread(readPath, 1, pathLen, fh) != (size_t)pathLen) { in read_header()
463 st->st_uid = read_int32(fh, -1); in read_header()
468 st->st_gid = read_int32(fh, -1); in read_header()
473 st->st_mode = read_int32(fh, -1); in read_header()
478 int64_t ltime = read_int64(fh, -1); in read_header()
484 ltime = read_int64(fh, -1); in read_header()
490 ltime = read_int64(fh, -1); in read_header()
506 FILE* fh = fopen(srcPath, "r"); in restore_data() local
507 if (fh == nullptr) { in restore_data()
513 inputFileVersion = read_int32(fh, 0); in restore_data()
520 opt_backupAll = read_int32(fh, 0); in restore_data()
538 if (read_header(fh, &type, &path, &statBuffer) == 0) { in restore_data()
563 off_t size = read_int64(fh, -1); in restore_data()
580 int copyres = copy_file(dest, fh, size, path, nullptr); in restore_data()
625 fclose(fh); in restore_data()