//--------------------------------------------------------------------------- void Table::WriteConsistency(void) { char path_lock[_MAX_PATH]; char drive[_MAX_DRIVE]; char dir[_MAX_DIR]; char fname[_MAX_FNAME]; char ext[_MAX_EXT]; //FUCKO //return; _splitpath( Name, drive, dir, fname, ext ); _makepath( path_lock, drive, dir, fname, ".lck"); FILE *lock = fopen(path_lock, "rb"); if (!lock) { // Failed to open lock = fopen(path_lock, "w+b"); // try to create it if (!lock) return; // failed to open or create lock } unsigned int thiscrctable = crc32file(Name); unsigned int thiscrcidx = crc32file(IdxName); fwrite(&thiscrctable, 4, 1, lock); fwrite(&thiscrcidx, 4, 1, lock); fclose(lock); return; }
//--------------------------------------------------------------------------- int Table::ConsistencyCheck(int in) { char path_lock[_MAX_PATH]; char drive[_MAX_DRIVE]; char dir[_MAX_DIR]; char fname[_MAX_FNAME]; char ext[_MAX_EXT]; _splitpath( Name, drive, dir, fname, ext ); _makepath( path_lock, drive, dir, fname, ".lck"); if (access(path_lock, 0)) // file does not exist { SetConsistencyInfo(CONSISTENCY_DONTKNOW); return 1; // no consistency check available, assume ok } FILE *lock = fopen(path_lock, "rb"); if (!lock) { SetConsistencyInfo(CONSISTENCY_DONTKNOW); return 1; // failed to open lock, assume ok } unsigned int lockcrctable, lockcrcidx; fread(&lockcrctable, 4, 1, lock); fread(&lockcrcidx, 4, 1, lock); fclose(lock); unsigned int thiscrctable = crc32file(Name); unsigned int thiscrcidx = crc32file(IdxName); if (lockcrctable != thiscrctable || lockcrcidx != thiscrcidx) { if (in) { SetConsistencyInfo(CONSISTENCY_BACKUPCORRUPTED); return 0; // corrupted } if (!RestoreBackup()) { SetConsistencyInfo(CONSISTENCY_CORRUPTED); return 0; // corrupted } if (!ConsistencyCheck(1)) return 0; else SetConsistencyInfo(CONSISTENCY_RESTORED); } else { SetConsistencyInfo(CONSISTENCY_OK); // Data is valid, let's backup it if we need // #ifdef DBBACKUP MakeBackup(); // #endif } return 1; // data is valid }
main(int argc, char *argp[]) /* Retour: 0 si pas d'erreur */ /* -1 si erreur */ { register errors=0; while(--argc > 0) errors|=crc32file( *++argp); return(errors); }
int main(int argc, char *argv[]) { DWORD crc; long charcnt; register errors = 0; // FB -- change to make the benchmark use stdio without command-line args if (argc <= 1) { errors |= crc32file(NULL, &crc, &charcnt); printf("%08lX %7ld -\n", crc, charcnt); } while(--argc > 0) { errors |= crc32file(*++argv, &crc, &charcnt); printf("%08lX %7ld %s\n", crc, charcnt, *argv); } return(errors != 0); }
int main(int argc, char *argv[]) { DWORD crc; register errors = 0; if (argc == 1) { printf("usage: crc32 <file_name>\n"); } while(--argc > 0) { errors |= crc32file(*++argv, &crc); printf("%08X %s\n", crc, *argv); } return errors != 0; }
main(int argc, char *argv[]) { DWORD crc; long charcnt; register errors = 0; while(--argc > 0) { errors |= crc32file(*++argv, &crc, &charcnt); printf("%08lX %7ld %s\n", crc, charcnt, *argv); } return(errors != 0); }
int main(int argc, char *argv[]) { __global_variables_init(); DWORD crc; __boundcheck_metadata_store((void *)(&crc),(void *)((size_t)(&crc)+sizeof(crc)*8-1)); long charcnt; __boundcheck_metadata_store((void *)(&charcnt),(void *)((size_t)(&charcnt)+sizeof(charcnt)*8-1)); register errors = 0; while(--argc > 0) { errors |= crc32file(*++argv, &crc, &charcnt); printf("%08lX %7ld %s\n", crc, charcnt, *argv); } return(errors != 0); }
rtems_task Init( rtems_task_argument ignored ) { char in_file[20] = "/image.img"; DWORD crc; long charcnt; puts( "\n\n*** untar/imfs/crc example ***" ); printf("Unpacking tar filesystem\nThis may take awhile...\n"); if(Untar_FromMemory((char*) fs_root_tar, fs_root_tar_size) != 0) { printf("Can't unpack tar filesystem\n"); exit(1); } crc32file(in_file,&crc, &charcnt); printf("%08lX %7ld %s\n", crc, charcnt, in_file); printf( "*** end of demonstration ***\n" ); exit( 0 ); }
void test_fcalls(CuTest *tc) { int rc; struct login_t login; char fpath[][5 + LEN_RND_STR + 1] = {"/tmp/", "/tmp/", "/tmp/", "/tmp/"}; for (uint8_t r = 0; r < sizeof(fpath)/sizeof(fpath[0]); r++) { char rnd_s[LEN_RND_STR + 1] = {0}; rnd_str(rnd_s, LEN_RND_STR); snprintf(fpath[r] + 5, LEN_RND_STR + 1, "%s", rnd_s); } login_fill(&login, SERVERNAME, NODE, PASSWORD, OWNER, LINUX_PLATFORM, DEFAULT_FSNAME, DEFAULT_FSTYPE); struct session_t session; memset(&session, 0, sizeof(struct session_t)); rc = tsm_init(DSM_SINGLETHREAD); CuAssertIntEquals(tc, DSM_RC_SUCCESSFUL, rc); rc = tsm_fconnect(&login, &session); CuAssertIntEquals(tc, DSM_RC_SUCCESSFUL, rc); srand(time(NULL)); FILE *file = NULL; for (uint8_t r = 0; r < sizeof(fpath)/sizeof(fpath[0]); r++) { unlink(fpath[r]); file = fopen(fpath[r], "w+"); CuAssertPtrNotNull(tc, file); rc = tsm_fopen(DEFAULT_FSNAME, fpath[r], "written by cutest", &session); CuAssertIntEquals(tc, DSM_RC_SUCCESSFUL, rc); unsigned char *buf = NULL; for (uint8_t b = 0; b < 16; b++) { size_t buf_size = 1 + (rand() % 1048576); /* 2^20 = 1 MiB */ buf = calloc(buf_size, sizeof(unsigned char)); CuAssertPtrNotNull(tc, buf); for (size_t r = 0; r < buf_size; r++) buf[r] = rand() % 256; size_t written = 0; size_t total_written = 0; size_t rand_nmemb; size_t to_write = buf_size; size_t written_tsm = 0; size_t total_written_tsm = 0; do { rand_nmemb = 1 + (rand() % buf_size); written = fwrite(buf, 1, rand_nmemb, file); total_written += written; written_tsm = tsm_fwrite(buf, 1, rand_nmemb, &session); total_written_tsm += written_tsm; buf_size -= rand_nmemb; } while (buf_size != 0 || written == 0); CuAssertIntEquals(tc, to_write, total_written); CuAssertIntEquals(tc, to_write, total_written_tsm); free(buf); } fclose(file); file = NULL; uint32_t crc32sum = 0; rc = crc32file(fpath[r], &crc32sum); CuAssertIntEquals(tc, 0, rc); CuAssertIntEquals(tc, crc32sum , session.tsm_file->archive_info.obj_info.crc32); rc = tsm_fclose(&session); CuAssertIntEquals(tc, DSM_RC_SUCCESSFUL, rc); rc = tsm_delete_fpath(DEFAULT_FSNAME, fpath[r], &session); CuAssertIntEquals(tc, DSM_RC_SUCCESSFUL, rc); } tsm_fdisconnect(&session); tsm_cleanup(DSM_SINGLETHREAD); }