Home | History | Annotate | Download | only in rawbu

Lines Matching refs:fh

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