void gpfs_send_attr(stat_x *sxp, int f) { struct rsync_gpfs_attr *a = sxp->gpfs_attr; if (a && a->buf) { int ndx = (use_gpfs_attr_cache) ? gpfs_find_attr(a) : -1; /* write 1 if it was 0; means not in cache (yet), +1 */ /* +1 is to compress the GPFS_NDX_NOATTR better */ write_varint(f, ndx + 1 + 1); if (ndx < 0) { write_varint(f, a->size); write_buf(f, a->buf, a->size); } } else { /* we have no attribute for this file */ /* +1 is just because of the trivial compression * of the mostly awaited GPFS_NDX_NOATTR */ write_varint(f, GPFS_NDX_NOATTR + 1); } }
static int writer_varint(lua_State* L) { writer_t* writer = lua_touserdata(L, 1); lua_Integer integer = luaL_checkinteger(L, 2); write_varint(writer, (uint64_t)integer); return 0; }
static int writer_stream(lua_State* L) { writer_t* writer = lua_touserdata(L, 1); if(lua_type(L, 2) != LUA_TSTRING) luaL_error(L, "string expected"); size_t size; const char* str = lua_tolstring(L, 2, &size); write_varint(writer, size); write_raw(writer, (uint8_t*)str, size); return 0; }
int main(int argc, char **argv) { try { bool all_ram_mode = false; char * m1 = NULL; char * m2 = NULL; if (argc > 1 && strcmp(argv[1], "--all-in-ram") == 0) { all_ram_mode = true; --argc; ++argv; } if (argc != 4) { printf("usage: bdelta [--all-in-ram] <oldfile> <newfile> <patchfile>\n"); printf("needs two files to compare + output file:\n"); exit(1); } if (!fileExists(argv[1]) || !fileExists(argv[2])) { printf("one of the input files does not exist\n"); exit(1); } unsigned size = getLenOfFile(argv[1]); unsigned size2 = getLenOfFile(argv[2]); FILE *f1 = fopen(argv[1], "rb"), *f2 = fopen(argv[2], "rb"); BDelta_Instance *b; if (all_ram_mode) { m1 = new char[size]; m2 = new char[size2]; fread_fixed(f1, m1, size); fread_fixed(f2, m2, size2); b = bdelta_init_alg(size, size2, m_read, m1, m2, 1); } else { b = bdelta_init_alg(size, size2, f_read, f1, f2, 1); } int nummatches; // List of primes for reference. Taken from Wikipedia. // 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 // 1-20 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 // 21-40 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 // 41-60 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 // 61-80 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 // 81-100 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521 523 541 // 101-120 547 557 563 569 571 577 587 593 599 601 607 613 617 619 631 641 643 647 653 659 // 121-140 661 673 677 683 691 701 709 719 727 733 739 743 751 757 761 769 773 787 797 809 // 141-160 811 821 823 827 829 839 853 857 859 863 877 881 883 887 907 911 919 929 937 941 // 161-180 947 953 967 971 977 983 991 997 my_pass(b, 997, 1994, 0); my_pass(b, 503, 1006, 0); my_pass(b, 127, 254, 0); my_pass(b, 31, 62, 0); my_pass(b, 7, 14, 0); my_pass(b, 5, 10, 0); my_pass(b, 3, 6, 0); my_pass(b, 13, 26, BDELTA_GLOBAL); my_pass(b, 7, 14, 0); my_pass(b, 5, 10, 0); nummatches = bdelta_numMatches(b); #ifdef FEFE long long * copyloc1 = new long long[nummatches + 1]; long long * copyloc2 = new long long[nummatches + 1]; unsigned * copynum = new unsigned[nummatches + 1]; #else unsigned * copyloc1 = new unsigned[nummatches + 1]; unsigned * copyloc2 = new unsigned[nummatches + 1]; unsigned * copynum = new unsigned[nummatches + 1]; #endif FILE *fout = fopen(argv[3], "wb"); if (!fout) { printf("couldn't open output file\n"); exit(1); } const char *magic = "BDT"; fwrite_fixed(fout, magic, 3); unsigned short version = 2; write_word(fout, version); unsigned char intsize = 4; fwrite_fixed(fout, &intsize, 1); write_dword(fout, size); write_dword(fout, size2); write_dword(fout, nummatches); unsigned lastp1 = 0, lastp2 = 0; for (int i = 0; i < nummatches; ++i) { unsigned p1, p2, num; bdelta_getMatch(b, i, &p1, &p2, &num); // printf("%*x, %*x, %*x, %*x\n", 10, p1, 10, p2, 10, num, 10, p2-lastp2); #ifdef FEFE copyloc1[i] = (long long)p1 - lastp1; copyloc2[i] = (long long)p2 - lastp2; copynum[i] = num; write_varint(fout, copyloc1[i]); write_varint(fout, copyloc2[i]); write_varint(fout, copynum[i]); // printf("%u/%u: (%ld -> %u,%ld -> %u,%u)\n",i,nummatches,copyloc1[i],p1,copyloc2[i],p2,copynum[i]); #else copyloc1[i] = p1 - lastp1; write_dword(fout, copyloc1[i]); copyloc2[i] = p2 - lastp2; write_dword(fout, copyloc2[i]); copynum[i] = num; write_dword(fout, copynum[i]); #endif lastp1 = p1 + num; lastp2 = p2 + num; } if (size2 != lastp2) { copyloc1[nummatches] = 0; copynum[nummatches] = 0; copyloc2[nummatches] = size2 - lastp2; ++nummatches; } // write_unsigned_list(adds, nummatches+1, fout); // write_unsigned_list(copynum, nummatches, fout); // write_signed_list(copyloc, nummatches, fout); // fwrite(copyloc1, 4, nummatches, fout); // fwrite(copyloc2, 4, nummatches, fout); // fwrite(copynum, 4, nummatches, fout); unsigned fp = 0; for (int i = 0; i < nummatches; ++i) { unsigned num = copyloc2[i]; while (num > 0) { unsigned towrite = (num > 4096) ? 4096 : num; unsigned char buf[4096]; const void * b; if (all_ram_mode) b = m_read(m2, buf, fp, towrite); else b = f_read(f2, buf, fp, towrite); fwrite_fixed(fout, b, towrite); num -= towrite; fp += towrite; } // fp+=copyloc2[i]; if (i != nummatches) fp += copynum[i]; } fclose(fout); bdelta_done_alg(b); delete [] m1; delete [] m2; fclose(f1); fclose(f2); delete [] copynum; delete [] copyloc2; delete [] copyloc1; } catch (const char * desc){ fprintf (stderr, "FATAL: %s\n", desc); return -1; } return 0; }