Lines Matching refs:fh
174 static int write_int32(FILE* fh, int32_t val) in write_int32() argument
176 int res = fwrite(&val, 1, sizeof(val), fh); in write_int32()
185 static int write_int64(FILE* fh, int64_t val) in write_int64() argument
187 int res = fwrite(&val, 1, sizeof(val), fh); in write_int64()
236 static int write_header(FILE* fh, int type, const char* path, const struct stat* st) in write_header() argument
239 if (!write_int32(fh, type)) return 0; in write_header()
240 if (!write_int32(fh, pathLen)) return 0; in write_header()
241 if (fwrite(path, 1, pathLen, fh) != (size_t)pathLen) { in write_header()
246 if (!write_int32(fh, st->st_uid)) return 0; in write_header()
247 if (!write_int32(fh, st->st_gid)) return 0; in write_header()
248 if (!write_int32(fh, st->st_mode)) return 0; in write_header()
249 if (!write_int64(fh, ((int64_t)st->st_atime)*1000*1000*1000)) return 0; in write_header()
250 if (!write_int64(fh, ((int64_t)st->st_mtime)*1000*1000*1000)) return 0; in write_header()
251 if (!write_int64(fh, ((int64_t)st->st_ctime)*1000*1000*1000)) return 0; in write_header()
256 static int backup_dir(FILE* fh, const char* srcPath) in backup_dir() argument
319 if (write_header(fh, TYPE_DIR, fullPath, &statBuffer) == 0) { in backup_dir()
323 if (backup_dir(fh, fullPath) == 0) { in backup_dir()
335 if (write_header(fh, TYPE_FILE, fullPath, &statBuffer) == 0) { in backup_dir()
341 if (!write_int64(fh, size)) { in backup_dir()
354 int copyres = copy_file(fh, src, size, NULL, fullPath); in backup_dir()
377 FILE* fh = fopen(destPath, "w"); in backup_data() local
378 if (fh == NULL) { in backup_data()
389 if (!write_int32(fh, FILE_VERSION)) goto done; in backup_data()
390 if (!write_int32(fh, opt_backupAll)) goto done; in backup_data()
391 if (!backup_dir(fh, "/data")) goto done; in backup_data()
392 if (!write_int32(fh, 0)) goto done; in backup_data()
397 if (fflush(fh) != 0) { in backup_data()
403 if (fsync(fileno(fh)) != 0) { in backup_data()
409 fclose(fh); in backup_data()
416 static int32_t read_int32(FILE* fh, int32_t defVal) in read_int32() argument
419 if (fread(&val, 1, sizeof(val), fh) != sizeof(val)) { in read_int32()
427 static int64_t read_int64(FILE* fh, int64_t defVal) in read_int64() argument
430 if (fread(&val, 1, sizeof(val), fh) != sizeof(val)) { in read_int64()
438 static int read_header(FILE* fh, int* type, char** path, struct stat* st) in read_header() argument
440 *type = read_int32(fh, -1); in read_header()
450 int32_t pathLen = read_int32(fh, -1); in read_header()
456 if (fread(readPath, 1, pathLen, fh) != (size_t)pathLen) { in read_header()
464 st->st_uid = read_int32(fh, -1); in read_header()
469 st->st_gid = read_int32(fh, -1); in read_header()
474 st->st_mode = read_int32(fh, -1); in read_header()
479 int64_t ltime = read_int64(fh, -1); in read_header()
485 ltime = read_int64(fh, -1); in read_header()
491 ltime = read_int64(fh, -1); in read_header()
507 FILE* fh = fopen(srcPath, "r"); in restore_data() local
508 if (fh == NULL) { in restore_data()
514 inputFileVersion = read_int32(fh, 0); in restore_data()
521 opt_backupAll = read_int32(fh, 0); in restore_data()
539 if (read_header(fh, &type, &path, &statBuffer) == 0) { in restore_data()
564 off_t size = read_int64(fh, -1); in restore_data()
581 int copyres = copy_file(dest, fh, size, path, NULL); in restore_data()
626 fclose(fh); in restore_data()