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