int main(int argc, char *argv[]) { unsigned val; for (val=0;val<8;val++) { lost[val] = 0; stored[val]=0; removed[val]=0; } nf2.device_name = DEFAULT_IFACE; if (check_iface(&nf2)) { exit(1); } if (openDescriptor(&nf2)) { exit(1); } w = initscr(); cbreak(); noecho(); show_stats(); closeDescriptor(&nf2); endwin(); return 0; }
int menu(t_assets *assets) { t_stats stats; int end; int play; int window; end = 0; play = 0; window = 0; srand(time(NULL)); while (!end) { if (Mix_PlayingMusic() != 1) Mix_PlayMusic(assets->sounds.menumusic, -1); events_menu(&play, &end, &window); show_menu(assets, &window, end, play); if (play) { init_stats(&stats); play_game(assets, &stats); show_stats(&stats); play = 0; Mix_PlayMusic(assets->sounds.menumusic, -1); } } return (0); }
int main(int argc, char *argv[]) { int ret; parse_args(argc, argv); if (the_working_paras.cpu_idx!=(uint8_t)-1) { ret = bind_cur_thread_to_cpu(the_working_paras.cpu_idx); if (0==ret) goto BIND_CPU_OK; errno = ret; ERR_DBG_PRINT_QUIT("bind to cpu %d failed", (int)the_working_paras.cpu_idx); } BIND_CPU_OK: register_sig_proc(SIGINT, sig_handler); the_working_paras.sockfd = udp_socket_init(the_working_paras.src_ip, the_working_paras.src_port); if (the_working_paras.sockfd<0) { ERR_DBG_PRINT_QUIT("create socket on %s:%d failed ", the_working_paras.src_ip, (int)the_working_paras.src_port); } set_fd_nonblock(the_working_paras.sockfd); rxtx_loop(); show_stats(); return 0; }
int get_card(player_t human) { char dNum[3]; show_stats(human.pos); printf("\n\t"); for (int i=0; i<12-trickNumber; i++) { pad_zero(dNum, i, 2); printf("%d\t", i); } int cardLoc = UNINIT; while (cardLoc == UNINIT) { cardLoc = get_number_in_range("\n\tCard index? ", -1, 11-trickNumber, 2); if (cardLoc == HELP * UNINIT) { h_playcard(); cardLoc = UNINIT; } if (cardLoc == ENTERED * UNINIT || cardLoc == NOTHING * UNINIT) return play_random_card(human.hand); if (cardLoc == -1) return choose_card(human); if (is_valid_card(human.hand, cardLoc, trick[0].colour, 12-trickNumber)) return cardLoc; if (cardLoc > -1 && cardLoc < 12) printf("\t\tYou must follow suit."); cardLoc = UNINIT; } return play_random_card(human.hand); }
void reveal_coordinate(int x, int y) { /* Als een cel een mijn bevat, dan is de speler dood*/ if (get_cell(x, y)->is_mine == 1 ) { printf("/+/+/+/ MINE EXPLODED /+/+/+/ \n"); printf("\n"); dead = 1; print_grid(); printf("Spel wordt afgesloten...\n"); draw_grid(); update_stats(); show_stats(); sleep(2); deallocate_grid(WIDTH, HEIGHT); exit(0); } /* Als de cel geen mijn is, verander dan zijn staat van covered naar uncovered. */ else { // Zet de status van het vakje op UNCOVERED. get_cell(x, y)->state = UNCOVERED; // Test of het vakje geen naburige mijnen heeft. if (get_cell(x, y)->neighbouring_mines == 0) { // Als het 0 naburige vakjes heeft, moeten al zijn buren bekeken worden of zij een mijn in de buurt hebben. for (int i = -1; i < 2; i++) // Begin bij de cel aan de linkse kant (vandaar de -1). { for (int j = -1; j < 2; j++) // Begin bij de cel aan de rechtse kant. { if ((x + i) < WIDTH && (x + i) >= 0 && (y + j) < HEIGHT && (y + j) >= 0) // Controle of een buurcel van de mijn zich niet buiten de randen van het veld bevindt. { if (get_cell(x + i, y + j)->state == COVERED) { reveal_coordinate(x + i, y + j); // Recursieve oproep op de naburige cellen. } } } } } } }
void Game::event_handler(const SDL_Event& event) { switch (event.type) { case SDL_QUIT: { Program::stop(); break; } case SDL_KEYDOWN: key_handler(event.key); break; case SDL_MOUSEBUTTONUP: if (m_window.stats_button_clicked(event.button)) show_stats(); break; } }
/* * Deze functie wordt aangeroepen als de gebruiker een vlag wil plaatsten op het vakje met positie (x,y) * in het veld. */ void flag_coordinate(int x, int y){ // UNFLAG // if (get_cell(x, y)->state == FLAGGED) { // Is vakje gevlagd? get_cell(x, y)->state = COVERED; // Zet status van vakje terug op covered. nr_of_flags++; // Verhoog aantal vlaggen. if (get_cell (x, y)->is_mine == 1){ // Als het onderliggend vakje een mijn was, dan wordt nr_of_flagged_mines verminderd. nr_of_flagged_mines--; } } // FLAG // else if (nr_of_flags != 0){ // Als de vlaggen niet op zijn, kan de cel van status veranderen. get_cell(x, y)->state = FLAGGED; // Verader de status van de cel naar FLAGGED (= 2) nr_of_flags--; // Verminder het aantal vlaggen dat de speler ter beschikking nog heeft if (get_cell(x, y)->is_mine == 1){ nr_of_flagged_mines++; // Verminder het aantal flagged mines. } if (nr_of_flagged_mines == NR_OF_MINES){ printf("/+/+/+/ YOU WON! /+/+/+/\n"); printf("\n"); print_grid(); draw_grid(); printf("Spel wordt afgesloten...\n"); update_stats(); show_stats(); sleep(2); deallocate_grid(WIDTH, HEIGHT); exit(0); // Programma wordt afgesloten met code 0 = succes. } } // Het aantal vlaggen is op else { printf("NO MORE FLAGS\n"); // Komt op het scherm al er geen vlggen meer zijn. } }
void tournament_t::run() { std::vector<unsigned> pairs; for(unsigned i=0;i<entrants.size();++i){ pairs.push_back(i); } while(true){ std::random_shuffle(pairs.begin(),pairs.end()); for(unsigned p=0;p<pairs.size()-1;p+=2){ unsigned b = pairs[p]; unsigned w = pairs[p+1]; game_result res; res = play_othello_game(entrants[b].bot,entrants[w].bot); update_entrants(&entrants[b],&entrants[w],res); show_stats(); } } }
void printTable(int rows, int columns) { char buffer[10]; int i, j; int x=START_X, y=START_Y; for(i = 0; i< rows; i++) { x += X_INCR; y = START_Y; for(j=0; j<columns; j++) { y+=Y_INCR; move(y, x); sprintf(buffer, "%d", table[i][j]); addstr(buffer); } } show_stats(); }
int main(int argc, char *argv[]) { int ret; parse_args(argc, argv); if (the_working_paras.cpu_idx!=(uint8_t)-1) { ret = bind_cur_thread_to_cpu(the_working_paras.cpu_idx); if (0==ret) goto BIND_CPU_OK; errno = ret; ERR_DBG_PRINT_QUIT("bind to cpu %d failed", (int)the_working_paras.cpu_idx); } BIND_CPU_OK: register_sig_proc(SIGINT, sig_handler); register_sig_proc(SIGALRM, sig_handler); connect2dst(); alarm(the_working_paras.snd_interval); rx_loop(); show_stats(); return 0; }
static void print_results(smt_core_t *core, double construction_time, double search_time) { dpll_stats_t *stat; double mem_used, simplified_percent; stat = &core->stats; show_stats(stat); printf("Search time : %.4f s\n", search_time); mem_used = mem_size() / (1024 * 1024); if (mem_used > 0) { printf("Memory used : %.2f MB\n", mem_used); } printf("\n\n"); // Print status again, in format used by Leonardo's scripts print_status(stdout, smt_status(core)); printf("\n"); validate_assignment(core); printf("\n"); simplified_percent = 0.0; if (stat->literals_before_simpl > 0) { simplified_percent = (100.0 * stat->subsumed_literals) / stat->literals_before_simpl; } printf("STAT %"PRIu64" %"PRIu64" %"PRIu64" %"PRIu32" %"PRIu64" %"PRIu64" %.2f %.2f %.2f\n", stat->decisions, stat->conflicts, stat->propagations, stat->restarts, stat->literals_before_simpl, stat->learned_literals, mem_used, (search_time + construction_time), simplified_percent); fflush(stdout); }
int main(int argc, char *argv[]) { int c; if (install_allegro(SYSTEM_NONE, &errno, atexit) != 0) return 1; for (c=1; c<argc; c++) { if (argv[c][0] == '-') { switch (utolower(argv[c][1])) { case 'a': opt_allegro = TRUE; break; case 'b': opt_binary = TRUE; break; case 'c': opt_compress = TRUE; break; case 'd': opt_delete = TRUE; break; case 'x': opt_extract = TRUE; break; case '0': if ((opt_password) || (c >= argc-1)) { usage(); return 1; } opt_password = argv[++c]; break; default: printf("Unknown option '%s'\n", argv[c]); return 1; } } else { if (!opt_filename) opt_filename = argv[c]; else if (!opt_dataname) opt_dataname = argv[c]; else { usage(); return 1; } } } if ((!opt_filename) || ((opt_allegro) && (opt_binary)) || ((opt_delete) && (opt_extract))) { usage(); return 1; } if (opt_password) packfile_password(opt_password); if (opt_delete) { if (opt_dataname) { usage(); return 1; } update_file(opt_filename, NULL); } else if (opt_extract) { if (!opt_dataname) { usage(); return 1; } if ((!opt_allegro) && (!opt_binary)) { printf("The -x option must be used together with -a or -b\n"); return 1; } extract_data(); } else { if (opt_dataname) update_file(opt_filename, opt_dataname); else show_stats(); } return err; }
int main (int argc, char **argv) { int silent = 0, force = 0; char *device = 0; error_t parse_opt (int key, char *arg, struct argp_state *state) { switch (key) { case 'p': preen = 1; break; case 'y': noquery = 1; break; case 'n': nowrite = 1; break; case 'l': lfname = arg; break; case 'm': lfmode = strtol (arg, 0, 8); break; case 'f': force = 1; break; case 's': silent = 1; break; case ARGP_KEY_ARG: if (!device) { device = arg; break; } /* Fall through */ case ARGP_KEY_NO_ARGS: argp_usage (state); default: return ARGP_ERR_UNKNOWN; } return 0; } struct argp argp = {options, parse_opt, args_doc}; preen = nowrite = noquery = 0; argp_parse (&argp, argc, argv, 0, 0, 0); if (!setup (device)) exit (1); if (preen && sblock->fs_clean && !force) { if (! silent) warning (0, "FILESYSTEM CLEAN"); } else { if (!preen) printf ("** Phase 1 -- Check Blocks and Sizes\n"); pass1 (); if (duplist) { if (!preen) printf ("** Phase 1b -- Rescan for More Duplicates\n"); pass1b (); } if (!preen) printf ("** Phase 2 -- Check Pathnames\n"); pass2 (); if (!preen) printf ("** Phase 3 -- Check Connectivity\n"); pass3 (); if (!preen) printf ("** Phase 4 -- Check Reference Counts\n"); pass4 (); if (!preen) printf ("** Phase 5 -- Check Cyl Groups\n"); pass5 (); if (! silent) show_stats (sblock); } if (fsmodified && !preen) printf ("\n***** FILE SYSTEM WAS MODIFIED *****\n"); exit (fsmodified ? 2 : 0); }
int main(int argc, char *argv[]) #endif { int i; /* Index */ int iter; time_t time_and_date; /* Self-explanatory */ struct tm *loctime; double bmean; /* Benchmark mean */ double bstdev; /* Benchmark stdev */ double lx_memindex; /* Linux memory index (mainly integer operations)*/ double lx_intindex; /* Linux integer index */ double lx_fpindex; /* Linux floating-point index */ double intindex; /* Integer index */ double fpindex; /* Floating-point index */ ulong bnumrun; /* # of runs */ #ifdef MAC MaxApplZone(); #endif #ifdef MACTIMEMGR /* Set up high res timer */ MacHSTdelay=600*1000*1000; /* Delay is 10 minutes */ memset((char *)&myTMTask,0,sizeof(TMTask)); /* Prime and remove the task, calculating overhead */ PrimeTime((QElemPtr)&myTMTask,-MacHSTdelay); RmvTime((QElemPtr)&myTMTask); MacHSTohead=MacHSTdelay+myTMTask.tmCount; #endif #ifdef WIN31TIMER /* Set up the size of the timer info structure */ win31tinfo.dwSize=(DWORD)sizeof(TIMERINFO); /* Load library */ if((hThlp=LoadLibrary("TOOLHELP.DLL"))<32) { printf("Error loading TOOLHELP\n"); exit(0); } if(!(lpfn=GetProcAddress(hThlp,"TimerCount"))) { printf("TOOLHELP error\n"); exit(0); } #endif /* ** Set global parameters to default. */ global_min_ticks=MINIMUM_TICKS; global_min_seconds=MINIMUM_SECONDS; global_allstats=0; global_custrun=0; global_align=8; write_to_file=0; lx_memindex=(double)1.0; /* set for geometric mean computations */ lx_intindex=(double)1.0; lx_fpindex=(double)1.0; intindex=(double)1.0; fpindex=(double)1.0; mem_array_ents=0; /* Nothing in mem array */ /* ** We presume all tests will be run unless told ** otherwise */ for(i=0;i<NUMTESTS;i++) tests_to_do[i]=1; /* ** Initialize test data structures to default ** values. */ set_request_secs(); /* Set all request_secs fields */ global_numsortstruct.adjust=0; global_numsortstruct.arraysize=NUMARRAYSIZE; global_strsortstruct.adjust=0; global_strsortstruct.arraysize=STRINGARRAYSIZE; global_bitopstruct.adjust=0; global_bitopstruct.bitfieldarraysize=BITFARRAYSIZE; global_emfloatstruct.adjust=0; global_emfloatstruct.arraysize=EMFARRAYSIZE; global_fourierstruct.adjust=0; global_assignstruct.adjust=0; global_ideastruct.adjust=0; global_ideastruct.arraysize=IDEAARRAYSIZE; global_huffstruct.adjust=0; global_huffstruct.arraysize=HUFFARRAYSIZE; global_nnetstruct.adjust=0; global_lustruct.adjust=0; /* ** For Macintosh -- read the command line. */ #ifdef MAC UCommandLine(); #endif /* ** Handle any command-line arguments. */ if(argc>1) for(i=1;i<argc;i++) if(parse_arg(argv[i])==-1) { display_help(argv[0]); exit(0); } /* ** Output header */ #ifdef LINUX output_string("\nBYTEmark* Native Mode Benchmark ver. 2 (10/95)\n"); output_string("Index-split by Andrew D. Balsa (11/97)\n"); output_string("Linux/Unix* port by Uwe F. Mayer (12/96,11/97)\n"); #else output_string("BBBBBB YYY Y TTTTTTT EEEEEEE\n"); output_string("BBB B YYY Y TTT EEE\n"); output_string("BBB B YYY Y TTT EEE\n"); output_string("BBBBBB YYY Y TTT EEEEEEE\n"); output_string("BBB B YYY TTT EEE\n"); output_string("BBB B YYY TTT EEE\n"); output_string("BBBBBB YYY TTT EEEEEEE\n\n"); output_string("\nBYTEmark (tm) Native Mode Benchmark ver. 2 (10/95)\n"); #endif /* ** See if the user wants all stats. Output heading info ** if so. */ if(global_allstats) { output_string("\n"); output_string("============================== ALL STATISTICS ===============================\n"); time(&time_and_date); loctime=localtime(&time_and_date); sprintf(buffer,"**Date and time of benchmark run: %s",asctime(loctime)); output_string(buffer); sprintf(buffer,"**Sizeof: char:%u short:%u int:%u long:%u u8:%u u16:%u u32:%u int32:%u\n", (unsigned int)sizeof(char), (unsigned int)sizeof(short), (unsigned int)sizeof(int), (unsigned int)sizeof(long), (unsigned int)sizeof(u8), (unsigned int)sizeof(u16), (unsigned int)sizeof(u32), (unsigned int)sizeof(int32)); output_string(buffer); #ifdef LINUX #include "sysinfo.c" #else sprintf(buffer,"**%s\n",sysname); output_string(buffer); sprintf(buffer,"**%s\n",compilername); output_string(buffer); sprintf(buffer,"**%s\n",compilerversion); output_string(buffer); #endif output_string("=============================================================================\n"); } /* ** Execute the tests. */ output_string("\nNOTE!!! Iteration display disabled to prevent diffs from failing!\n"); #ifdef LINUX output_string("\nTEST : Iterations/sec. : Old Index : New Index\n"); output_string(" : : Pentium 90* : AMD K6/233*\n"); output_string("--------------------:------------------:-------------:------------\n"); #endif for(i=0;i<NUMTESTS;i++) { if(tests_to_do[i]) { sprintf(buffer,"%s :",ftestnames[i]); output_string(buffer); #if 0 if (0!=bench_with_confidence(i, &bmean, &bstdev, &bnumrun)){ output_string("\n** WARNING: The current test result is NOT 95 % statistically certain.\n"); output_string("** WARNING: The variation among the individual results is too large.\n"); output_string(" :"); } #endif for (iter = 0; iter < N_ITERATIONS; ++iter) { (*funcpointer[i])(); } #ifdef LINUX sprintf(buffer," %15.5g : %9.2f : %9.2f\n", bmean,bmean/bindex[i],bmean/lx_bindex[i]); #else sprintf(buffer," Iterations/sec.: %13.2f Index: %6.2f\n", /*bmean,bmean/bindex[i],*/ 0.0, 0.0); #endif output_string(buffer); /* ** Gather integer or FP indexes */ if((i==4)||(i==8)||(i==9)){ /* FP index */ fpindex=fpindex*(bmean/bindex[i]); /* Linux FP index */ lx_fpindex=lx_fpindex*(bmean/lx_bindex[i]); } else{ /* Integer index */ intindex=intindex*(bmean/bindex[i]); if((i==0)||(i==3)||(i==6)||(i==7)) /* Linux integer index */ lx_intindex=lx_intindex*(bmean/lx_bindex[i]); else /* Linux memory index */ lx_memindex=lx_memindex*(bmean/lx_bindex[i]); } if(global_allstats) { sprintf(buffer," Absolute standard deviation: %g\n",bstdev); output_string(buffer); if (bmean>(double)1e-100){ /* avoid division by zero */ sprintf(buffer," Relative standard deviation: %g %%\n", (double)100*bstdev/bmean); output_string(buffer); } sprintf(buffer," Number of runs: %lu\n",bnumrun); output_string(buffer); show_stats(i); sprintf(buffer,"Done with %s\n\n",ftestnames[i]); output_string(buffer); } } } /* printf("...done...\n"); */ /* ** Output the total indexes */ if(global_custrun==0) { output_string("==========================ORIGINAL BYTEMARK RESULTS==========================\n"); sprintf(buffer,"INTEGER INDEX : %.3f\n", /*pow(intindex,(double).142857)*/ 0.0); output_string(buffer); sprintf(buffer,"FLOATING-POINT INDEX: %.3f\n", /*pow(fpindex,(double).33333)*/ 0.0); output_string(buffer); output_string("Baseline (MSDOS*) : Pentium* 90, 256 KB L2-cache, Watcom* compiler 10.0\n"); #ifdef LINUX output_string("==============================LINUX DATA BELOW===============================\n"); hardware(write_to_file, global_ofile); #include "sysinfoc.c" sprintf(buffer,"MEMORY INDEX : %.3f\n", pow(lx_memindex,(double).3333333333)); output_string(buffer); sprintf(buffer,"INTEGER INDEX : %.3f\n", pow(lx_intindex,(double).25)); output_string(buffer); sprintf(buffer,"FLOATING-POINT INDEX: %.3f\n", pow(lx_fpindex,(double).3333333333)); output_string(buffer); output_string("Baseline (LINUX) : AMD K6/233*, 512 KB L2-cache, gcc 2.7.2.3, libc-5.4.38\n"); #endif output_string("* Trademarks are property of their respective holder.\n"); } exit(0); }
static unsigned int call_syscall(struct syscall_desc *scall, char *argv[]) { struct stat64 sb; long long flags; unsigned int i; char *endp; int name, rval; union { char *str; long long num; } args[MAX_ARGS]; #ifdef HAS_FREEBSD_ACL int entry_id = ACL_FIRST_ENTRY; acl_t acl, newacl; acl_entry_t entry, newentry; #endif /* * Verify correctness of the arguments. */ for (i = 0; i < sizeof(args)/sizeof(args[0]); i++) { if (scall->sd_args[i] == TYPE_NONE) { if (argv[i] == NULL || strcmp(argv[i], ":") == 0) break; fprintf(stderr, "too many arguments [%s]\n", argv[i]); exit(1); } else { if (argv[i] == NULL || strcmp(argv[i], ":") == 0) { if (scall->sd_args[i] & TYPE_OPTIONAL) break; fprintf(stderr, "too few arguments\n"); exit(1); } if ((scall->sd_args[i] & TYPE_MASK) == TYPE_STRING) { if (strcmp(argv[i], "NULL") == 0) args[i].str = NULL; else if (strcmp(argv[i], "DEADCODE") == 0) args[i].str = (void *)0xdeadc0de; else args[i].str = argv[i]; } else if ((scall->sd_args[i] & TYPE_MASK) == TYPE_NUMBER) { args[i].num = strtoll(argv[i], &endp, 0); if (*endp != '\0' && !isspace((unsigned char)*endp)) { fprintf(stderr, "invalid argument %u, number expected [%s]\n", i, endp); exit(1); } } else if ((scall->sd_args[i] & TYPE_MASK) == TYPE_DESCRIPTOR) { if (strcmp(argv[i], "AT_FDCWD") == 0) { args[i].num = AT_FDCWD; } else if (strcmp(argv[i], "BADFD") == 0) { /* In case AT_FDCWD is -1 on some systems... */ if (AT_FDCWD == -1) args[i].num = -2; else args[i].num = -1; } else { int pos; pos = strtoll(argv[i], &endp, 0); if (*endp != '\0' && !isspace((unsigned char)*endp)) { fprintf(stderr, "invalid argument %u, number expected [%s]\n", i, endp); exit(1); } args[i].num = descriptor_get(pos); } } } } /* * Call the given syscall. */ #define NUM(n) (args[(n)].num) #define STR(n) (args[(n)].str) switch (scall->sd_action) { case ACTION_OPEN: flags = str2flags(open_flags, STR(1)); if (flags & O_CREAT) { if (i == 2) { fprintf(stderr, "too few arguments\n"); exit(1); } rval = open(STR(0), (int)flags, (mode_t)NUM(2)); } else { if (i == 3) { fprintf(stderr, "too many arguments\n"); exit(1); } rval = open(STR(0), (int)flags); } if (rval >= 0) descriptor_add(rval); break; case ACTION_OPENAT: flags = str2flags(open_flags, STR(2)); if (flags & O_CREAT) { if (i == 3) { fprintf(stderr, "too few arguments\n"); exit(1); } rval = openat(NUM(0), STR(1), (int)flags, (mode_t)NUM(3)); } else { if (i == 4) { fprintf(stderr, "too many arguments\n"); exit(1); } rval = openat(NUM(0), STR(1), (int)flags); } if (rval >= 0) descriptor_add(rval); break; case ACTION_CREATE: rval = open(STR(0), O_CREAT | O_EXCL, (mode_t)NUM(1)); if (rval >= 0) close(rval); break; case ACTION_UNLINK: rval = unlink(STR(0)); break; case ACTION_UNLINKAT: rval = unlinkat(NUM(0), STR(1), (int)str2flags(unlinkat_flags, STR(2))); break; case ACTION_MKDIR: rval = mkdir(STR(0), (mode_t)NUM(1)); break; case ACTION_MKDIRAT: rval = mkdirat(NUM(0), STR(1), (mode_t)NUM(2)); break; case ACTION_RMDIR: rval = rmdir(STR(0)); break; case ACTION_LINK: rval = link(STR(0), STR(1)); break; case ACTION_LINKAT: rval = linkat(NUM(0), STR(1), NUM(2), STR(3), (int)str2flags(linkat_flags, STR(4))); break; case ACTION_SYMLINK: rval = symlink(STR(0), STR(1)); break; case ACTION_SYMLINKAT: rval = symlinkat(STR(0), NUM(1), STR(2)); break; case ACTION_RENAME: rval = rename(STR(0), STR(1)); break; case ACTION_RENAMEAT: rval = renameat(NUM(0), STR(1), NUM(2), STR(3)); break; case ACTION_MKFIFO: rval = mkfifo(STR(0), (mode_t)NUM(1)); break; case ACTION_MKFIFOAT: rval = mkfifoat(NUM(0), STR(1), (mode_t)NUM(2)); break; case ACTION_MKNOD: case ACTION_MKNODAT: { mode_t ntype; dev_t dev; int fa; switch (scall->sd_action) { case ACTION_MKNOD: fa = 0; break; case ACTION_MKNODAT: fa = 1; break; default: abort(); } dev = makedev(NUM(fa + 3), NUM(fa + 4)); if (strcmp(STR(fa + 1), "c") == 0) /* character device */ ntype = S_IFCHR; else if (strcmp(STR(fa + 1), "b") == 0) /* block device */ ntype = S_IFBLK; else if (strcmp(STR(fa + 1), "f") == 0) /* fifo special */ ntype = S_IFIFO; else if (strcmp(STR(fa + 1), "d") == 0) /* directory */ ntype = S_IFDIR; else if (strcmp(STR(fa + 1), "o") == 0) /* regular file */ ntype = S_IFREG; else { fprintf(stderr, "wrong argument 1\n"); exit(1); } switch (scall->sd_action) { case ACTION_MKNOD: rval = mknod(STR(0), ntype | NUM(2), dev); break; case ACTION_MKNODAT: rval = mknodat(NUM(0), STR(1), ntype | NUM(3), dev); break; default: abort(); } break; } case ACTION_BIND: { struct sockaddr_un sunx; sunx.sun_family = AF_UNIX; strncpy(sunx.sun_path, STR(0), sizeof(sunx.sun_path) - 1); sunx.sun_path[sizeof(sunx.sun_path) - 1] = '\0'; rval = socket(AF_UNIX, SOCK_STREAM, 0); if (rval < 0) break; rval = bind(rval, (struct sockaddr *)&sunx, sizeof(sunx)); break; } #ifdef HAS_BINDAT case ACTION_BINDAT: { struct sockaddr_un sunx; sunx.sun_family = AF_UNIX; strncpy(sunx.sun_path, STR(1), sizeof(sunx.sun_path) - 1); sunx.sun_path[sizeof(sunx.sun_path) - 1] = '\0'; rval = socket(AF_UNIX, SOCK_STREAM, 0); if (rval < 0) break; rval = bindat(NUM(0), rval, (struct sockaddr *)&sunx, sizeof(sunx)); break; } #endif case ACTION_CONNECT: { struct sockaddr_un sunx; sunx.sun_family = AF_UNIX; strncpy(sunx.sun_path, STR(0), sizeof(sunx.sun_path) - 1); sunx.sun_path[sizeof(sunx.sun_path) - 1] = '\0'; rval = socket(AF_UNIX, SOCK_STREAM, 0); if (rval < 0) break; rval = connect(rval, (struct sockaddr *)&sunx, sizeof(sunx)); break; } #ifdef HAS_CONNECTAT case ACTION_CONNECTAT: { struct sockaddr_un sunx; sunx.sun_family = AF_UNIX; strncpy(sunx.sun_path, STR(1), sizeof(sunx.sun_path) - 1); sunx.sun_path[sizeof(sunx.sun_path) - 1] = '\0'; rval = socket(AF_UNIX, SOCK_STREAM, 0); if (rval < 0) break; rval = connectat(NUM(0), rval, (struct sockaddr *)&sunx, sizeof(sunx)); break; } #endif case ACTION_CHMOD: rval = chmod(STR(0), (mode_t)NUM(1)); break; case ACTION_FCHMOD: rval = fchmod(NUM(0), (mode_t)NUM(1)); break; #ifdef HAS_LCHMOD case ACTION_LCHMOD: rval = lchmod(STR(0), (mode_t)NUM(1)); break; #endif case ACTION_FCHMODAT: rval = fchmodat(NUM(0), STR(1), (mode_t)NUM(2), str2flags(fchmodat_flags, STR(3))); break; case ACTION_CHOWN: rval = chown(STR(0), (uid_t)NUM(1), (gid_t)NUM(2)); break; case ACTION_FCHOWN: rval = fchown(NUM(0), (uid_t)NUM(1), (gid_t)NUM(2)); break; case ACTION_LCHOWN: rval = lchown(STR(0), (uid_t)NUM(1), (gid_t)NUM(2)); break; case ACTION_FCHOWNAT: rval = fchownat(NUM(0), STR(1), (uid_t)NUM(2), (gid_t)NUM(3), (int)str2flags(fchownat_flags, STR(4))); break; #ifdef HAS_CHFLAGS case ACTION_CHFLAGS: rval = chflags(STR(0), (unsigned long)str2flags(chflags_flags, STR(1))); break; #endif #ifdef HAS_FCHFLAGS case ACTION_FCHFLAGS: rval = fchflags(NUM(0), (unsigned long)str2flags(chflags_flags, STR(1))); break; #endif #ifdef HAS_CHFLAGSAT case ACTION_CHFLAGSAT: rval = chflagsat(NUM(0), STR(1), (unsigned long)str2flags(chflags_flags, STR(2)), (int)str2flags(chflagsat_flags, STR(3))); break; #endif #ifdef HAS_LCHFLAGS case ACTION_LCHFLAGS: rval = lchflags(STR(0), (unsigned long)str2flags(chflags_flags, STR(1))); break; #endif case ACTION_TRUNCATE: rval = truncate64(STR(0), NUM(1)); break; case ACTION_FTRUNCATE: rval = ftruncate64(NUM(0), NUM(1)); break; case ACTION_STAT: rval = stat64(STR(0), &sb); if (rval == 0) { show_stats(&sb, STR(1)); return (i); } break; case ACTION_FSTAT: rval = fstat64(NUM(0), &sb); if (rval == 0) { show_stats(&sb, STR(1)); return (i); } break; case ACTION_LSTAT: rval = lstat64(STR(0), &sb); if (rval == 0) { show_stats(&sb, STR(1)); return (i); } break; case ACTION_FSTATAT: rval = fstatat(NUM(0), STR(1), &sb, (int)str2flags(fstatat_flags, STR(2))); if (rval == 0) { show_stats(&sb, STR(3)); return (i); } break; case ACTION_PATHCONF: case ACTION_FPATHCONF: case ACTION_LPATHCONF: { long lrval; name = str2name(pathconf_names, STR(1)); if (name == -1) { fprintf(stderr, "unknown name %s", STR(1)); exit(1); } errno = 0; switch (scall->sd_action) { case ACTION_PATHCONF: lrval = pathconf(STR(0), name); break; case ACTION_FPATHCONF: lrval = fpathconf(NUM(0), name); break; case ACTION_LPATHCONF: lrval = lpathconf(STR(0), name); break; default: abort(); } if (lrval == -1 && errno == 0) { printf("unlimited\n"); return (i); } else if (lrval >= 0) { printf("%ld\n", lrval); return (i); } rval = -1; break; } #ifdef HAS_FREEBSD_ACL case ACTION_PREPENDACL: rval = -1; acl = acl_get_file(STR(0), ACL_TYPE_NFS4); if (acl == NULL) break; newacl = acl_from_text(STR(1)); if (acl == NULL) break; while (acl_get_entry(newacl, entry_id, &newentry) == 1) { entry_id = ACL_NEXT_ENTRY; if (acl_create_entry_np(&acl, &entry, 0)) break; if (acl_copy_entry(entry, newentry)) break; } rval = acl_set_file(STR(0), ACL_TYPE_NFS4, acl); break; case ACTION_READACL: acl = acl_get_file(STR(0), ACL_TYPE_NFS4); if (acl == NULL) rval = -1; else rval = 0; break; #endif case ACTION_WRITE: rval = write(NUM(0), STR(1), strlen(STR(1))); break; default: fprintf(stderr, "unsupported syscall\n"); exit(1); } #undef STR #undef NUM if (rval < 0) { const char *serrno; serrno = err2str(errno); fprintf(stderr, "%s returned %d\n", scall->sd_name, rval); printf("%s\n", serrno); exit(1); } printf("0\n"); return (i); }
void main(int argc, char **argv) #endif { int i; /* Index */ time_t time_and_date; /* Self-explanatory */ struct tm *loctime; double bmean; /* Benchmark mean */ double bstdev; /* Benchmark stdev */ double intindex; /* Integer index */ double fpindex; /* Floating-point index */ ulong bnumrun; /* # of runs */ #ifdef MAC MaxApplZone(); #endif #ifdef MACTIMEMGR /* Set up high res timer */ MacHSTdelay=600*1000*1000; /* Delay is 10 minutes */ memset((char *)&myTMTask,0,sizeof(TMTask)); /* Prime and remove the task, calculating overhead */ PrimeTime((QElemPtr)&myTMTask,-MacHSTdelay); RmvTime((QElemPtr)&myTMTask); MacHSTohead=MacHSTdelay+myTMTask.tmCount; #endif #ifdef WIN31TIMER /* Set up the size of the timer info structure */ win31tinfo.dwSize=(DWORD)sizeof(TIMERINFO); /* Load library */ if((hThlp=LoadLibrary("TOOLHELP.DLL"))<32) { printf("Error loading TOOLHELP\n"); exit(0); } if(!(lpfn=GetProcAddress(hThlp,"TimerCount"))) { printf("TOOLHELP error\n"); exit(0); } #endif /* ** Set global parameters to default. */ global_min_ticks=MINIMUM_TICKS; global_min_seconds=MINIMUM_SECONDS; global_allstats=0; global_custrun=0; write_to_file=0; intindex=(double)1.0; fpindex=(double)1.0; /* ** We presume all tests will be run unless told ** otherwise */ for(i=0;i<NUMTESTS;i++) tests_to_do[i]=1; /* ** Initialize test data structures to default ** values. */ set_request_secs(); /* Set all request_secs fields */ global_numsortstruct.adjust=0; global_numsortstruct.arraysize=NUMARRAYSIZE; global_strsortstruct.adjust=0; global_strsortstruct.arraysize=STRINGARRAYSIZE; global_bitopstruct.adjust=0; global_bitopstruct.bitfieldarraysize=BITFARRAYSIZE; global_emfloatstruct.adjust=0; global_emfloatstruct.arraysize=EMFARRAYSIZE; global_fourierstruct.adjust=0; global_assignstruct.adjust=0; global_ideastruct.adjust=0; global_ideastruct.arraysize=IDEAARRAYSIZE; global_huffstruct.adjust=0; global_huffstruct.arraysize=HUFFARRAYSIZE; global_nnetstruct.adjust=0; global_lustruct.adjust=0; /* ** For Macintosh -- read the command line. */ #ifdef MAC UCommandLine(); #endif /* ** Handle any command-line arguments. */ if(argc>1) for(i=1;i<argc;i++) if(parse_arg(argv[i])==-1) { display_help(argv[0]); exit(0); } /* ** Output header */ output_string("BBBBBB YYY Y TTTTTTT EEEEEEE\n"); output_string("BBB B YYY Y TTT EEE\n"); output_string("BBB B YYY Y TTT EEE\n"); output_string("BBBBBB YYY Y TTT EEEEEEE\n"); output_string("BBB B YYY TTT EEE\n"); output_string("BBB B YYY TTT EEE\n"); output_string("BBBBBB YYY TTT EEEEEEE\n\n"); output_string("BYTEmark (tm) Native Mode Benchmark ver. 2 (3/95)\n"); /* ** See if the user wants all stats. Output heading info ** if so. */ if(global_allstats) { output_string("========== ALL STATISTICS ==========\n"); time(&time_and_date); loctime=localtime(&time_and_date); sprintf(buffer,"**%s",asctime(loctime)); output_string(buffer); sprintf(buffer,"**%s\n",sysname); output_string(buffer); sprintf(buffer,"**%s\n",compilername); output_string(buffer); sprintf(buffer,"**%s\n",compilerversion); output_string(buffer); sprintf(buffer,"**Sizeof: int:%u short:%u long:%u\n", (unsigned int)sizeof(int), (unsigned int)sizeof(short), (unsigned int)sizeof(long)); output_string(buffer); output_string("====================================\n"); } /* ** Execute the tests. */ for(i=0;i<NUMTESTS;i++) { if(tests_to_do[i]) { sprintf(buffer,"%s:",ftestnames[i]); output_string(buffer); bench_with_confidence(i, &bmean, &bstdev, &bnumrun); sprintf(buffer, "Bmark(%s)", ftestnames[i] ); Report( buffer, TotalTime ); sprintf(buffer," Iterations/sec.: %lf Index: %lf\n", bmean,bmean/bindex[i]); output_string(buffer); /* ** Gather integer or FP indexes */ if((i==4)||(i==8)||(i==9)) /* FP index */ fpindex=fpindex*(bmean/bindex[i]); else /* Integer index */ intindex=intindex*(bmean/bindex[i]); if(global_allstats) { sprintf(buffer," Standard Deviation: %lf\n Number of runs: %lu\n", bstdev,bnumrun); output_string(buffer); show_stats(i); } } } printf("...done...\n"); /* ** Output the total indexes */ if(global_custrun==0) { output_string("===========OVERALL============\n"); sprintf(buffer,"INTEGER INDEX: %lf\nFLOATING-POINT INDEX: %lf\n",pow(intindex,(double).142857), pow(fpindex,(double).33333)); output_string(buffer); output_string(" (90 MHz Dell Pentium = 1.00)\n"); output_string("==============================\n"); } exit(0); }
int main(int argc, char **argv) { char *filename; int64_t blkno, blksize; o2fsck_state *ost = &_ost; int c, open_flags = OCFS2_FLAG_RW | OCFS2_FLAG_STRICT_COMPAT_CHECK; int sb_num = 0; int fsck_mask = FSCK_OK; int slot_recover_err = 0; errcode_t ret; int mount_flags; int proceed = 1; memset(ost, 0, sizeof(o2fsck_state)); ost->ost_ask = 1; ost->ost_dirblocks.db_root = RB_ROOT; ost->ost_dir_parents = RB_ROOT; ost->ost_refcount_trees = RB_ROOT; /* These mean "autodetect" */ blksize = 0; blkno = 0; initialize_ocfs_error_table(); initialize_o2dl_error_table(); initialize_o2cb_error_table(); setlinebuf(stderr); setlinebuf(stdout); tools_progress_disable(); while ((c = getopt(argc, argv, "b:B:DfFGnupavVytPr:")) != EOF) { switch (c) { case 'b': blkno = read_number(optarg); if (blkno < OCFS2_SUPER_BLOCK_BLKNO) { fprintf(stderr, "Invalid blkno: %s\n", optarg); fsck_mask |= FSCK_USAGE; print_usage(); goto out; } break; case 'B': blksize = read_number(optarg); if (blksize < OCFS2_MIN_BLOCKSIZE) { fprintf(stderr, "Invalid blksize: %s\n", optarg); fsck_mask |= FSCK_USAGE; print_usage(); goto out; } break; case 'D': ost->ost_compress_dirs = 1; break; case 'F': ost->ost_skip_o2cb = 1; break; case 'f': ost->ost_force = 1; break; case 'G': ost->ost_fix_fs_gen = 1; break; case 'n': open_flags &= ~OCFS2_FLAG_RW; open_flags |= OCFS2_FLAG_RO; /* Fall through */ case 'a': case 'p': /* * Like extN, -a maps to -p, which is * 'preen'. This means only fix things * that don't require human interaction. * Unlike extN, this is only journal * replay for now. To make it smarter, * ost->ost_answer needs to learn a * new mode. */ ost->ost_ask = 0; ost->ost_answer = 0; break; case 'P': tools_progress_enable(); break; case 'y': ost->ost_ask = 0; ost->ost_answer = 1; break; case 'u': open_flags |= OCFS2_FLAG_BUFFERED; break; case 'v': verbose = 1; break; case 'V': print_version(); exit(FSCK_USAGE); break; case 'r': sb_num = read_number(optarg); break; case 't': if (ost->ost_show_stats) ost->ost_show_extended_stats = 1; ost->ost_show_stats = 1; break; default: fsck_mask |= FSCK_USAGE; print_usage(); goto out; break; } } if (!(open_flags & OCFS2_FLAG_RW) && ost->ost_compress_dirs) { fprintf(stderr, "Compress directories (-D) incompatible with read-only mode\n"); fsck_mask |= FSCK_USAGE; print_usage(); goto out; } if (blksize % OCFS2_MIN_BLOCKSIZE) { fprintf(stderr, "Invalid blocksize: %"PRId64"\n", blksize); fsck_mask |= FSCK_USAGE; print_usage(); goto out; } if (optind >= argc) { fprintf(stderr, "Missing filename\n"); fsck_mask |= FSCK_USAGE; print_usage(); goto out; } filename = argv[optind]; print_version(); ret = ocfs2_check_if_mounted(filename, &mount_flags); if (ret) { com_err(whoami, ret, "while determining whether %s is mounted.", filename); fsck_mask |= FSCK_ERROR; goto out; } if (mount_flags & (OCFS2_MF_MOUNTED | OCFS2_MF_BUSY)) { if (!(open_flags & OCFS2_FLAG_RW)) fprintf(stdout, "\nWARNING!!! Running fsck.ocfs2 (read-" "only) on a mounted filesystem may detect " "invalid errors.\n\n"); else fprintf(stdout, "\nWARNING!!! Running fsck.ocfs2 on a " "mounted filesystem may cause SEVERE " "filesystem damage.\n\n"); proceed = 0; } if (proceed && ost->ost_skip_o2cb) { fprintf(stdout, "\nWARNING!!! You have disabled the cluster check. " "Continue only if you\nare absolutely sure that NO " "node has this filesystem mounted or is\notherwise " "accessing it. If unsure, do NOT continue.\n\n"); proceed = 0; } if (!proceed) { fprintf(stdout, "Do you really want to continue (y/N): "); if (toupper(getchar()) != 'Y') { printf("Aborting operation.\n"); fsck_mask |= FSCK_CANCELED; goto out; } } if (signal(SIGTERM, handle_signal) == SIG_ERR) { com_err(whoami, 0, "Could not set SIGTERM"); exit(1); } if (signal(SIGINT, handle_signal) == SIG_ERR) { com_err(whoami, 0, "Could not set SIGINT"); exit(1); } /* recover superblock should be called at first. */ if (sb_num) { ret = recover_backup_super(ost, filename, sb_num); if (ret) { com_err(whoami, ret, "recover superblock failed.\n"); fsck_mask |= FSCK_ERROR; goto out; } } ret = open_and_check(ost, filename, open_flags, blkno, blksize); if (ret) { fsck_mask |= FSCK_ERROR; goto out; } if (open_flags & OCFS2_FLAG_RW && !ost->ost_skip_o2cb && !ocfs2_mount_local(ost->ost_fs)) { ret = o2cb_init(); if (ret) { com_err(whoami, ret, "while initializing the cluster"); goto close; } block_signals(SIG_BLOCK); ret = ocfs2_initialize_dlm(ost->ost_fs, whoami); if (ret == O2CB_ET_INVALID_STACK_NAME || ret == O2CB_ET_INVALID_CLUSTER_NAME || ret == O2CB_ET_INVALID_HEARTBEAT_MODE) { block_signals(SIG_UNBLOCK); ret = recover_cluster_info(ost); if (ret) { com_err(whoami, ret, "while recovering cluster information"); goto close; } block_signals(SIG_BLOCK); ret = ocfs2_initialize_dlm(ost->ost_fs, whoami); } if (ret) { block_signals(SIG_UNBLOCK); com_err(whoami, ret, "while initializing the DLM"); goto close; } ret = ocfs2_lock_down_cluster(ost->ost_fs); if (ret) { block_signals(SIG_UNBLOCK); com_err(whoami, ret, "while locking down the cluster"); goto close; } cluster_locked = 1; block_signals(SIG_UNBLOCK); } printf("Checking OCFS2 filesystem in %s:\n", filename); printf(" Label: "); print_label(ost); printf(" UUID: "); print_uuid(ost); printf(" Number of blocks: %"PRIu64"\n", ost->ost_fs->fs_blocks); printf(" Block size: %u\n", ost->ost_fs->fs_blocksize); printf(" Number of clusters: %"PRIu32"\n", ost->ost_fs->fs_clusters); printf(" Cluster size: %u\n", ost->ost_fs->fs_clustersize); printf(" Number of slots: %u\n\n", OCFS2_RAW_SB(ost->ost_fs->fs_super)->s_max_slots); /* Let's get enough of a cache to replay the journals */ o2fsck_init_cache(ost, O2FSCK_CACHE_MODE_JOURNAL); if (open_flags & OCFS2_FLAG_RW) { ret = o2fsck_check_journals(ost); if (ret) { printf("fsck saw unrecoverable errors in the journal " "files and will not continue.\n"); goto unlock; } } ret = maybe_replay_journals(ost, filename, open_flags, blkno, blksize); if (ret) { printf("fsck encountered unrecoverable errors while " "replaying the journals and will not continue\n"); fsck_mask |= FSCK_ERROR; goto unlock; } /* Grow the cache */ o2fsck_init_cache(ost, O2FSCK_CACHE_MODE_FULL); /* allocate all this junk after we've replayed the journal and the * sb should be stable */ if (o2fsck_state_init(ost->ost_fs, ost)) { fprintf(stderr, "error allocating run-time state, exiting..\n"); fsck_mask |= FSCK_ERROR; goto unlock; } ret = o2fsck_slot_recovery(ost); if (ret) { printf("fsck encountered errors while recovering slot " "information, check forced.\n"); slot_recover_err = 1; ost->ost_force = 1; } if (fs_is_clean(ost, filename)) { fsck_mask = FSCK_OK; goto clear_dirty_flag; } #if 0 o2fsck_mark_block_used(ost, 0); o2fsck_mark_block_used(ost, 1); o2fsck_mark_block_used(ost, OCFS2_SUPER_BLOCK_BLKNO); #endif mark_magical_clusters(ost); /* XXX we don't use the bad blocks inode, do we? */ /* XXX for now it is assumed that errors returned from a pass * are fatal. these can be fixed over time. */ ret = o2fsck_pass0(ost); if (ret) { com_err(whoami, ret, "while performing pass 0"); goto done; } ret = o2fsck_pass1(ost); if (ret) { com_err(whoami, ret, "while performing pass 1"); goto done; } ret = o2fsck_pass2(ost); if (ret) { com_err(whoami, ret, "while performing pass 2"); goto done; } ret = o2fsck_pass3(ost); if (ret) { com_err(whoami, ret, "while performing pass 3"); goto done; } ret = o2fsck_pass4(ost); if (ret) { com_err(whoami, ret, "while performing pass 4"); goto done; } ret = o2fsck_pass5(ost); if (ret) { com_err(whoami, ret, "while performing pass 5"); goto done; } done: if (ret) fsck_mask |= FSCK_ERROR; else { fsck_mask = FSCK_OK; ost->ost_saw_error = 0; printf("All passes succeeded.\n\n"); o2fsck_print_resource_track(NULL, ost, &ost->ost_rt, ost->ost_fs->fs_io); show_stats(ost); } clear_dirty_flag: if (ost->ost_fs->fs_flags & OCFS2_FLAG_RW) { ret = write_out_superblock(ost); if (ret) com_err(whoami, ret, "while writing back the " "superblock(s)"); if (fsck_mask == FSCK_OK) { if (slot_recover_err) { ret = o2fsck_slot_recovery(ost); if (ret) { com_err(whoami, ret, "while doing slot " "recovery."); goto unlock; } } ret = o2fsck_clear_journal_flags(ost); if (ret) { com_err(whoami, ret, "while clear dirty " "journal flag."); goto unlock; } ret = ocfs2_format_slot_map(ost->ost_fs); if (ret) com_err(whoami, ret, "while format slot " "map."); } } unlock: block_signals(SIG_BLOCK); if (ost->ost_fs->fs_dlm_ctxt) ocfs2_release_cluster(ost->ost_fs); cluster_locked = 0; block_signals(SIG_UNBLOCK); close: block_signals(SIG_BLOCK); if (ost->ost_fs->fs_dlm_ctxt) ocfs2_shutdown_dlm(ost->ost_fs, whoami); block_signals(SIG_UNBLOCK); ret = ocfs2_close(ost->ost_fs); if (ret) { com_err(whoami, ret, "while closing file \"%s\"", filename); /* XXX I wonder about this error.. */ fsck_mask |= FSCK_ERROR; } out: return fsck_mask; }
int main(int argc, char *argv[]) { cracker c; crack_opt_t opts; crack_routine_t lm[4]={crack_lm1,crack_lm2,crack_lm3,crack_lm4}; bool found=false; std::string alphabet, start_pwd, end_pwd, hash, pwd; int thread_cnt=0; // need at least a hash if(argc<2) { usage(); } // process arguments passed to program for (int i=1; i<argc; i++) { if (argv[i][0]=='-' || argv[i][0]=='/') { switch (argv[i][1]) { // custom alphabet case 'c': alphabet = getparam(argc, argv, &i); break; // end password case 'e': end_pwd = getparam(argc, argv, &i); break; // start password case 's': start_pwd = getparam(argc, argv, &i); break; // number of threads case 't': thread_cnt = atoi(getparam (argc, argv, &i)); break; case 'h': case '?': usage(); break; default: printf (" [ unknown option %c", argv[i][1]); break; } } else { hash = argv[i]; } } // no hash? if(hash.empty()) { printf(" [ no hash specified.\n"); usage(); } // initialize if(!c.set_options(thread_cnt,hash,alphabet,start_pwd,end_pwd)) { printf(" [ failed to initialize parameters.\n"); usage(); } // display options c.get_options(&opts); printf (" [ start pwd : \"%s\"\n", opts.start_pwd); printf (" [ end pwd : \"%s\"\n", opts.end_pwd); printf (" [ alphabet : \"%s\"\n", opts.alphabet); printf (" [ total pwd : %" PRIu64 "\n", (uint64_t)opts.total_cbn); printf (" [ thread cbn : %" PRIu64 "\n", opts.thread_cbn); printf (" [ thread cnt : %" PRIu32 "\n\n", opts.thread_cnt); #define CNT 4 for(size_t i=0;i<CNT;i++) { found=false; printf(" [ version %zu\n", (i+1)); c.start(lm[i]); // wait for threads to finish while(!found) { found = c.wait(1); show_stats(&c); if(found || !c.threads_running()) break; } putchar('\n'); if (found) { pwd = c.get_pwd(); printf(" [ found password : %s\n\n", pwd.c_str()); } else printf(" [ password could not be found.\n\n"); // stop any remaining threads c.stop(); } return 0; }
int main(int argc, char **argv) { sqlite3 *db; int option_index, option; if( argc < 3 ){ print_help(NULL); return 1; } db = NULL; option_index = 0; static struct option long_options[] = { {"batch", 0, 0, 'b'}, {"clean", 2, 0, 'c'}, {"export", 2, 0, 'e'}, {"h", 0, 0, 'h'}, {"help", 0, 0, 'h'}, {"import", 2, 0, 'i'}, {"sql", 1, 0, 's'}, {"stats", 2, 0, 't'}, {"statistics", 2, 0, 't'}, {"verify", 2, 0, 'v'}, {"vacuum", 2, 0, 'c'}, // TODO: implement options like '-e essid' to limit // operations to a certain essid where possible {"essid", 1, 0, 'd'}, {0, 0, 0, 0 } }; option = getopt_long( argc, argv, "bc:d:e:hi:s:t:v:", long_options, &option_index ); if( option > 0 ) { switch (option) { case 'b': // Batch if ( check_for_db(&db, argv[1], 0, 1) ) { return 1; } batch_process(db); break; case 'c': // Clean if ( check_for_db(&db, argv[1], 0, 0) ) { return 1; } vacuum(db, (argc > 3 && strcasecmp(argv[3],"all") == 0) ? 1 : 0); break; case 'e': if (argc < 4) { print_help("You must specify an export format."); } else if (strcmp(argv[3],"cowpatty")==0) { if (argc < 6) { print_help("You must specify essid and output file."); } else { // Export if ( check_for_db(&db, argv[1], 0, 0) ) { return 1; } export_cowpatty(db,argv[4],argv[5]); } } else { print_help("Invalid export format specified."); } break; case ':' : case '?' : case 'h': // Show help print_help(NULL); break; case 'i': // Import if (argc < 5) { print_help("You must specifiy an import format and a file."); } else if (strcasecmp(argv[3], IMPORT_COWPATTY) == 0) { if ( check_for_db(&db, argv[1], 1, 0) ) { return 1; } import_cowpatty(db,argv[4]); } else if (strcasecmp(argv[3], IMPORT_ESSID) == 0) { if ( check_for_db(&db, argv[1], 1, 0) ) { return 1; } import_ascii(db, IMPORT_ESSID,argv[4]); } else if (strcasecmp(argv[3], IMPORT_PASSWD) == 0 || strcasecmp(argv[3],"password") == 0) { if ( check_for_db(&db, argv[1], 1, 0) ) { return 1; } import_ascii(db,IMPORT_PASSWD, argv[4]); } else { print_help("Invalid import format specified."); return 1; } break; case 's': // SQL // We don't know if the SQL order is changing the file or not if ( check_for_db(&db, argv[1], 0, 0) ) { return 1; } sql_stdout(db, argv[3], 0); break; case 't': // Stats if ( check_for_db(&db, argv[1], 0, 1) ) { return 1; } show_stats(db, (argv[3] == NULL) ? 0 : 1); break; case 'v': // Verify if ( check_for_db(&db, argv[1], 0, (argc > 3 && strcasecmp(argv[3],"all")==0) ? 0 : 1) ) { return 1; } verify(db, (argc > 3 && strcasecmp(argv[3],"all")==0) ? 1 : 0); break; default: print_help("Invalid option"); break; } } else { print_help(NULL); } if (db) sqlite3_close(db); return 0; }
static unsigned int call_syscall(struct syscall_desc *scall, char *argv[]) { struct stat64 sb; long long flags; unsigned int i; char *endp; int rval; union { char *str; long long num; } args[MAX_ARGS]; /* * Verify correctness of the arguments. */ for (i = 0; i < sizeof(args)/sizeof(args[0]); i++) { if (scall->sd_args[i] == TYPE_NONE) { if (argv[i] == NULL || strcmp(argv[i], ":") == 0) break; fprintf(stderr, "too many arguments [%s]\n", argv[i]); exit(1); } else { if (argv[i] == NULL || strcmp(argv[i], ":") == 0) { if (scall->sd_args[i] & TYPE_OPTIONAL) break; fprintf(stderr, "too few arguments\n"); exit(1); } if (scall->sd_args[i] & TYPE_STRING) { if (strcmp(argv[i], "NULL") == 0) args[i].str = NULL; else if (strcmp(argv[i], "DEADCODE") == 0) args[i].str = (void *)0xdeadc0de; else args[i].str = argv[i]; } else if (scall->sd_args[i] & TYPE_NUMBER) { args[i].num = strtoll(argv[i], &endp, 0); if (*endp != '\0' && !isspace((unsigned char)*endp)) { fprintf(stderr, "invalid argument %u, number expected [%s]\n", i, endp); exit(1); } } } } /* * Call the given syscall. */ #define NUM(n) (args[(n)].num) #define STR(n) (args[(n)].str) switch (scall->sd_action) { case ACTION_OPEN: flags = str2flags(open_flags, STR(1)); if (flags & O_CREAT) { if (i == 2) { fprintf(stderr, "too few arguments\n"); exit(1); } rval = open(STR(0), flags, (mode_t)NUM(2)); } else { if (i == 3) { fprintf(stderr, "too many arguments\n"); exit(1); } rval = open(STR(0), flags); } break; case ACTION_CREATE: rval = open(STR(0), O_CREAT | O_EXCL, NUM(1)); if (rval >= 0) close(rval); break; case ACTION_UNLINK: rval = unlink(STR(0)); break; case ACTION_MKDIR: rval = mkdir(STR(0), NUM(1)); break; case ACTION_RMDIR: rval = rmdir(STR(0)); break; case ACTION_LINK: rval = link(STR(0), STR(1)); break; case ACTION_SYMLINK: rval = symlink(STR(0), STR(1)); break; case ACTION_RENAME: rval = rename(STR(0), STR(1)); break; case ACTION_MKFIFO: rval = mkfifo(STR(0), NUM(1)); break; case ACTION_CHMOD: rval = chmod(STR(0), NUM(1)); break; #ifdef HAS_LCHMOD case ACTION_LCHMOD: rval = lchmod(STR(0), NUM(1)); break; #endif case ACTION_CHOWN: rval = chown(STR(0), NUM(1), NUM(2)); break; case ACTION_LCHOWN: rval = lchown(STR(0), NUM(1), NUM(2)); break; #ifdef HAS_CHFLAGS case ACTION_CHFLAGS: rval = chflags(STR(0), str2flags(chflags_flags, STR(1))); break; #endif #ifdef HAS_LCHFLAGS case ACTION_LCHFLAGS: rval = lchflags(STR(0), str2flags(chflags_flags, STR(1))); break; #endif case ACTION_TRUNCATE: rval = truncate64(STR(0), NUM(1)); break; case ACTION_STAT: rval = stat64(STR(0), &sb); if (rval == 0) { show_stats(&sb, STR(1)); return (i); } break; case ACTION_LSTAT: rval = lstat64(STR(0), &sb); if (rval == 0) { show_stats(&sb, STR(1)); return (i); } break; case ACTION_READDIR: rval = readdir_loop(STR(0)); break; default: fprintf(stderr, "unsupported syscall\n"); exit(1); } #undef STR #undef NUM if (rval < 0) { const char *serrno; serrno = err2str(errno); fprintf(stderr, "%s returned %d\n", scall->sd_name, rval); printf("%s\n", serrno); exit(1); } printf("0\n"); return (i); }
static void raidtest_test(int argc, char *argv[]) { uintmax_t i, nbytes, nreqs, nrreqs, nwreqs, reqs_per_proc, nstart; const char *dev, *file = NULL; struct timeval tstart, tend, tdiff; struct ioreq *iorqs; unsigned nprocs; struct stat sb; pid_t *procs; int ch, fdd, fdf, j, rdonly, wronly; dev = NULL; nprocs = 1; rdonly = wronly = 0; while ((ch = getopt(argc, argv, "d:n:rvw")) != -1) { switch (ch) { case 'd': dev = optarg; break; case 'n': errno = 0; nprocs = strtoul(optarg, NULL, 0); if (errno != 0) { err(EXIT_FAILURE, "Invalid value for '%c' argument.", ch); } break; case 'r': rdonly = 1; break; case 'w': wronly = 1; break; default: usage(); } } argc -= optind; argv += optind; if (dev == NULL) errx(EXIT_FAILURE, "Option '%c' not specified.", 'd'); if (nprocs < 1) errx(EXIT_FAILURE, "Invalid number of processes"); if (rdonly && wronly) { errx(EXIT_FAILURE, "Both '%c' and '%c' options were specified.", 'r', 'w'); } if (argc == 0) file = DEFAULT_DATA_FILE; else if (argc == 1) file = argv[0]; else usage(); fdf = open(file, O_RDONLY); if (fdf < 0) err(EXIT_FAILURE, "Cannot open '%s' file", file); if (fstat(fdf, &sb) < 0) err(EXIT_FAILURE, "Cannot stat '%s' file", file); if ((sb.st_size % sizeof(struct iorec)) != 0) err(EXIT_FAILURE, "Invalid size of '%s' file", file); fdd = open(dev, (rdonly ? O_RDONLY : O_RDWR) | O_DIRECT); if (fdd < 0) err(EXIT_FAILURE, "Cannot open '%s' device", file); procs = malloc(sizeof(pid_t) * nprocs); if (procs == NULL) { close(fdf); close(fdd); errx(EXIT_FAILURE, "Cannot allocate %zu bytes of memory.", sizeof(pid_t) * (size_t)nprocs); } iorqs = malloc((sb.st_size / sizeof(struct iorec)) * sizeof(struct ioreq)); if (iorqs == NULL) { close(fdf); close(fdd); free(procs); errx(EXIT_FAILURE, "Cannot allocate %jd bytes of memory.", (intmax_t)(sb.st_size / sizeof(struct iorec)) * sizeof(struct ioreq)); } nreqs = sb.st_size / sizeof(struct iorec); nbytes = nrreqs = nwreqs = 0; for (i = 0; i < nreqs; i++) { if (read_ioreq(fdf, &iorqs[i])) err(EXIT_FAILURE, "Error while reading"); if (rdonly) iorqs[i].iorq_type = IO_TYPE_READ; else if (wronly) iorqs[i].iorq_type = IO_TYPE_WRITE; nbytes += iorqs[i].iorq_length; switch (iorqs[i].iorq_type) { case IO_TYPE_READ: nrreqs++; break; case IO_TYPE_WRITE: nwreqs++; break; default: fprintf(stderr, "Invalid request type: %u.\n", iorqs[i].iorq_type); break; } } close(fdf); printf("Read %ju requests from %s.\n", nreqs, file); printf("Number of READ requests: %ju.\n", nrreqs); printf("Number of WRITE requests: %ju.\n", nwreqs); printf("Number of bytes to transmit: %ju.\n", nbytes); printf("Number of processes: %u.\n", nprocs); fflush(stdout); reqs_per_proc = nreqs / nprocs; nstart = 0; gettimeofday(&tstart, NULL); for (j = 0; j < (int)nprocs; j++) { procs[i] = fork(); switch (procs[i]) { case 0: free(procs); test_start(fdd, &iorqs[nstart], reqs_per_proc); free(iorqs); close(fdd); exit(EXIT_SUCCESS); case -1: fprintf(stderr, "Cannot create process %u: %s\n", (unsigned)i, strerror(errno)); for (j--; j >= 0; j--) kill(procs[j], SIGKILL); free(procs); free(iorqs); close(fdd); exit(EXIT_FAILURE); } nstart += reqs_per_proc; } free(iorqs); free(procs); for (j = 0; j < (int)nprocs; j++) { int status; wait(&status); } gettimeofday(&tend, NULL); timersub(&tend, &tstart, &tdiff); show_stats(tdiff.tv_sec + (double)tdiff.tv_usec / 1000000, nbytes, nreqs); }
static unsigned int call_syscall(struct syscall_desc *scall, char *argv[]) { struct stat64 sb; struct utimbuf ut; long long flags; unsigned int i; char *endp; int rval; int more; union { char *str; long long num; } args[MAX_ARGS]; more = 0; /* * Verify correctness of the arguments. */ for (i = 0; i < sizeof(args)/sizeof(args[0]); i++) { if (scall->sd_args[i] == TYPE_NONE) { if (argv[i] == NULL || strcmp(argv[i], ":") == 0) break; fprintf(stderr, "too many arguments [%s]\n", argv[i]); exit(1); } else { if (argv[i] == NULL || strcmp(argv[i], ":") == 0) { if (scall->sd_args[i] & TYPE_OPTIONAL) { args[i].str = NULL; break; } fprintf(stderr, "too few arguments\n"); exit(1); } if ((scall->sd_args[i] & TYPE_MASK) == TYPE_STRING) { if (strcmp(argv[i], "NULL") == 0) args[i].str = NULL; else if (strcmp(argv[i], "DEADCODE") == 0) args[i].str = (void *)0xdeadc0de; else args[i].str = argv[i]; } else if ((scall->sd_args[i] & TYPE_MASK) == TYPE_NUMBER) { args[i].num = strtoll(argv[i], &endp, 0); if (*endp != '\0' && !isspace((unsigned char)*endp)) { fprintf(stderr, "invalid argument %u, number expected [%s]\n", i, endp); exit(1); } } else if ((scall->sd_args[i] & TYPE_MASK) == TYPE_DESCRIPTOR) { if (strcmp(argv[i], "AT_FDCWD") == 0) { args[i].num = AT_FDCWD; } else if (strcmp(argv[i], "BADFD") == 0) { /* In case AT_FDCWD is -1 on some systems... */ if (AT_FDCWD == -1) args[i].num = -2; else args[i].num = -1; } else { int pos; pos = strtoll(argv[i], &endp, 0); if (*endp != '\0' && !isspace((unsigned char)*endp)) { fprintf(stderr, "invalid argument %u, number expected [%s]\n", i, endp); exit(1); } args[i].num = descriptor_get(pos); } } } } /* * Call the given syscall. */ #define NUM(n) (args[(n)].num) #define STR(n) (args[(n)].str) switch (scall->sd_action) { case ACTION_OPEN: flags = str2flags(open_flags, STR(1)); if (flags & O_CREAT) { if (i == 2) { fprintf(stderr, "too few arguments\n"); exit(1); } rval = open(STR(0), flags, (mode_t)NUM(2)); } else { if (i == 3) { fprintf(stderr, "too many arguments\n"); exit(1); } rval = open(STR(0), flags); } if (rval >= 0) { more = argv[i] && !strcmp(argv[i], ":"); descriptor_add(rval); } break; case ACTION_CREATE: rval = open(STR(0), O_CREAT | O_EXCL, NUM(1)); if (rval >= 0) { more = argv[i] && !strcmp(argv[i], ":"); descriptor_add(rval); } break; case ACTION_UNLINK: rval = unlink(STR(0)); break; case ACTION_MKDIR: rval = mkdir(STR(0), NUM(1)); break; case ACTION_RMDIR: rval = rmdir(STR(0)); break; case ACTION_LINK: rval = link(STR(0), STR(1)); break; case ACTION_SYMLINK: rval = symlink(STR(0), STR(1)); break; case ACTION_RENAME: rval = rename(STR(0), STR(1)); break; case ACTION_MKFIFO: rval = mkfifo(STR(0), NUM(1)); break; case ACTION_CHMOD: rval = chmod(STR(0), NUM(1)); break; #ifdef HAS_LCHMOD case ACTION_LCHMOD: rval = lchmod(STR(0), NUM(1)); break; #endif case ACTION_CHOWN: rval = chown(STR(0), NUM(1), NUM(2)); break; case ACTION_LCHOWN: rval = lchown(STR(0), NUM(1), NUM(2)); break; #ifdef HAS_CHFLAGS case ACTION_CHFLAGS: rval = chflags(STR(0), str2flags(chflags_flags, STR(1))); break; #endif #ifdef HAS_LCHFLAGS case ACTION_LCHFLAGS: rval = lchflags(STR(0), str2flags(chflags_flags, STR(1))); break; #endif case ACTION_TRUNCATE: rval = truncate64(STR(0), NUM(1)); break; case ACTION_FTRUNCATE: rval = ftruncate64(NUM(0), NUM(1)); break; case ACTION_STAT: rval = stat64(STR(0), &sb); if (rval == 0) { show_stats(&sb, STR(1)); return (i); } break; case ACTION_LSTAT: rval = lstat64(STR(0), &sb); if (rval == 0) { show_stats(&sb, STR(1)); return (i); } break; case ACTION_UTIME : switch (i) { case 1 : rval = utime(STR(0), (struct utimbuf*)NULL); break; case 3: ut.actime = NUM(1); ut.modtime = NUM(2); rval = utime(STR(0), &ut); break; default : fprintf(stderr,"utime() requires 1 or 3 arguments\n"); exit(1); } break; case ACTION_BIND: { struct sockaddr_un sunx; sunx.sun_family = AF_UNIX; strncpy(sunx.sun_path, STR(0), sizeof(sunx.sun_path) - 1); sunx.sun_path[sizeof(sunx.sun_path) - 1] = '\0'; rval = socket(AF_UNIX, SOCK_STREAM, 0); if (rval < 0) break; rval = bind(rval, (struct sockaddr *)&sunx, sizeof(sunx)); break; } case ACTION_MKNOD: case ACTION_MKNODAT: { mode_t ntype; dev_t dev; int fa; switch (scall->sd_action) { case ACTION_MKNOD: fa = 0; break; case ACTION_MKNODAT: fa = 1; break; default: abort(); } dev = makedev(NUM(fa + 3), NUM(fa + 4)); if (strcmp(STR(fa + 1), "c") == 0) /* character device */ ntype = S_IFCHR; else if (strcmp(STR(fa + 1), "b") == 0) /* block device */ ntype = S_IFBLK; else if (strcmp(STR(fa + 1), "f") == 0) /* fifo special */ ntype = S_IFIFO; else if (strcmp(STR(fa + 1), "d") == 0) /* directory */ ntype = S_IFDIR; else if (strcmp(STR(fa + 1), "o") == 0) /* regular file */ ntype = S_IFREG; else { fprintf(stderr, "wrong argument 1\n"); exit(1); } switch (scall->sd_action) { case ACTION_MKNOD: rval = mknod(STR(0), ntype | NUM(2), dev); break; case ACTION_MKNODAT: rval = mknodat(NUM(0), STR(1), ntype | NUM(3), dev); break; default: abort(); } break; } #ifdef HAS_ACL case ACTION_GETFACL : rval = do_getfacl(STR(0), STR(1)); if (rval == 0) return (i); break; case ACTION_SETFACL : rval = do_setfacl(STR(0), STR(1), STR(2)); break; #endif default: fprintf(stderr, "unsupported syscall\n"); exit(1); } #undef STR #undef NUM if (rval < 0) { const char *serrno; serrno = err2str(errno); fprintf(stderr, "%s returned %d\n", scall->sd_name, rval); printf("%s\n", serrno); exit(1); } /* Do not output a "0" when more syscalls to come */ if (!more) printf("0\n"); return (i); }
int main (int argc, char *argv[]) { errcode_t retval = 0; int exit_value = FSCK_OK; ext2_filsys fs = 0; io_manager io_ptr; struct ext2_super_block *sb; const char *lib_ver_date; int my_ver, lib_ver; e2fsck_t ctx; struct problem_context pctx; int flags, run_result; clear_problem_context(&pctx); #ifdef MTRACE mtrace(); #endif #ifdef MCHECK mcheck(0); #endif #ifdef ENABLE_NLS setlocale(LC_MESSAGES, ""); setlocale(LC_CTYPE, ""); bindtextdomain(NLS_CAT_NAME, LOCALEDIR); textdomain(NLS_CAT_NAME); #endif my_ver = ext2fs_parse_version_string(my_ver_string); lib_ver = ext2fs_get_library_version(0, &lib_ver_date); if (my_ver > lib_ver) { fprintf( stderr, _("Error: ext2fs library version " "out of date!\n")); show_version_only++; } retval = PRS(argc, argv, &ctx); if (retval) { com_err("e2fsck", retval, _("while trying to initialize program")); exit(FSCK_ERROR); } reserve_stdio_fds(); #ifdef RESOURCE_TRACK init_resource_track(&ctx->global_rtrack); #endif if (!(ctx->options & E2F_OPT_PREEN) || show_version_only) fprintf(stderr, "e2fsck %s (%s)\n", my_ver_string, my_ver_date); if (show_version_only) { fprintf(stderr, _("\tUsing %s, %s\n"), error_message(EXT2_ET_BASE), lib_ver_date); exit(FSCK_OK); } check_mount(ctx); if (!(ctx->options & E2F_OPT_PREEN) && !(ctx->options & E2F_OPT_NO) && !(ctx->options & E2F_OPT_YES)) { if (!ctx->interactive) fatal_error(ctx, _("need terminal for interactive repairs")); } ctx->superblock = ctx->use_superblock; restart: #ifdef CONFIG_TESTIO_DEBUG io_ptr = test_io_manager; test_io_backing_manager = unix_io_manager; #else io_ptr = unix_io_manager; #endif flags = 0; if ((ctx->options & E2F_OPT_READONLY) == 0) flags |= EXT2_FLAG_RW; if ((ctx->mount_flags & EXT2_MF_MOUNTED) == 0) flags |= EXT2_FLAG_EXCLUSIVE; if (ctx->superblock && ctx->blocksize) { retval = ext2fs_open2(ctx->filesystem_name, ctx->io_options, flags, ctx->superblock, ctx->blocksize, io_ptr, &fs); } else if (ctx->superblock) { int blocksize; for (blocksize = EXT2_MIN_BLOCK_SIZE; blocksize <= EXT2_MAX_BLOCK_SIZE; blocksize *= 2) { retval = ext2fs_open2(ctx->filesystem_name, ctx->io_options, flags, ctx->superblock, blocksize, io_ptr, &fs); if (!retval) break; } } else retval = ext2fs_open2(ctx->filesystem_name, ctx->io_options, flags, 0, 0, io_ptr, &fs); if (!ctx->superblock && !(ctx->options & E2F_OPT_PREEN) && !(ctx->flags & E2F_FLAG_SB_SPECIFIED) && ((retval == EXT2_ET_BAD_MAGIC) || ((retval == 0) && ext2fs_check_desc(fs)))) { if (!fs || (fs->group_desc_count > 1)) { printf(_("%s trying backup blocks...\n"), retval ? _("Couldn't find ext2 superblock,") : _("Group descriptors look bad...")); get_backup_sb(ctx, fs, ctx->filesystem_name, io_ptr); if (fs) ext2fs_close(fs); goto restart; } } if (retval) { com_err(ctx->program_name, retval, _("while trying to open %s"), ctx->filesystem_name); if (retval == EXT2_ET_REV_TOO_HIGH) { printf(_("The filesystem revision is apparently " "too high for this version of e2fsck.\n" "(Or the filesystem superblock " "is corrupt)\n\n")); fix_problem(ctx, PR_0_SB_CORRUPT, &pctx); } else if (retval == EXT2_ET_SHORT_READ) printf(_("Could this be a zero-length partition?\n")); else if ((retval == EPERM) || (retval == EACCES)) printf(_("You must have %s access to the " "filesystem or be root\n"), (ctx->options & E2F_OPT_READONLY) ? "r/o" : "r/w"); else if (retval == ENXIO) printf(_("Possibly non-existent or swap device?\n")); else if (retval == EBUSY) printf(_("Filesystem mounted or opened exclusively " "by another program?\n")); #ifdef EROFS else if (retval == EROFS) printf(_("Disk write-protected; use the -n option " "to do a read-only\n" "check of the device.\n")); #endif else fix_problem(ctx, PR_0_SB_CORRUPT, &pctx); fatal_error(ctx, 0); } ctx->fs = fs; fs->priv_data = ctx; fs->now = ctx->now; sb = fs->super; if (sb->s_rev_level > E2FSCK_CURRENT_REV) { com_err(ctx->program_name, EXT2_ET_REV_TOO_HIGH, _("while trying to open %s"), ctx->filesystem_name); get_newer: fatal_error(ctx, _("Get a newer version of e2fsck!")); } /* * Set the device name, which is used whenever we print error * or informational messages to the user. */ if (ctx->device_name == 0 && (sb->s_volume_name[0] != 0)) { ctx->device_name = string_copy(ctx, sb->s_volume_name, sizeof(sb->s_volume_name)); } if (ctx->device_name == 0) ctx->device_name = ctx->filesystem_name; /* * Make sure the ext3 superblock fields are consistent. */ retval = e2fsck_check_ext3_journal(ctx); if (retval) { com_err(ctx->program_name, retval, _("while checking ext3 journal for %s"), ctx->device_name); fatal_error(ctx, 0); } /* * Check to see if we need to do ext3-style recovery. If so, * do it, and then restart the fsck. */ if (sb->s_feature_incompat & EXT3_FEATURE_INCOMPAT_RECOVER) { if (ctx->options & E2F_OPT_READONLY) { printf(_("Warning: skipping journal recovery " "because doing a read-only filesystem " "check.\n")); io_channel_flush(ctx->fs->io); } else { if (ctx->flags & E2F_FLAG_RESTARTED) { /* * Whoops, we attempted to run the * journal twice. This should never * happen, unless the hardware or * device driver is being bogus. */ com_err(ctx->program_name, 0, _("unable to set superblock flags on %s\n"), ctx->device_name); fatal_error(ctx, 0); } retval = e2fsck_run_ext3_journal(ctx); if (retval) { com_err(ctx->program_name, retval, _("while recovering ext3 journal of %s"), ctx->device_name); fatal_error(ctx, 0); } ext2fs_close(ctx->fs); ctx->fs = 0; ctx->flags |= E2F_FLAG_RESTARTED; goto restart; } } /* * Check for compatibility with the feature sets. We need to * be more stringent than ext2fs_open(). */ if ((sb->s_feature_compat & ~EXT2_LIB_FEATURE_COMPAT_SUPP) || (sb->s_feature_incompat & ~EXT2_LIB_FEATURE_INCOMPAT_SUPP)) { com_err(ctx->program_name, EXT2_ET_UNSUPP_FEATURE, "(%s)", ctx->device_name); goto get_newer; } if (sb->s_feature_ro_compat & ~EXT2_LIB_FEATURE_RO_COMPAT_SUPP) { com_err(ctx->program_name, EXT2_ET_RO_UNSUPP_FEATURE, "(%s)", ctx->device_name); goto get_newer; } #ifdef ENABLE_COMPRESSION if (sb->s_feature_incompat & EXT2_FEATURE_INCOMPAT_COMPRESSION) com_err(ctx->program_name, 0, _("Warning: compression support is experimental.\n")); #endif #ifndef ENABLE_HTREE if (sb->s_feature_compat & EXT2_FEATURE_COMPAT_DIR_INDEX) { com_err(ctx->program_name, 0, _("E2fsck not compiled with HTREE support,\n\t" "but filesystem %s has HTREE directories.\n"), ctx->device_name); goto get_newer; } #endif /* * If the user specified a specific superblock, presumably the * master superblock has been trashed. So we mark the * superblock as dirty, so it can be written out. */ if (ctx->superblock && !(ctx->options & E2F_OPT_READONLY)) ext2fs_mark_super_dirty(fs); /* * We only update the master superblock because (a) paranoia; * we don't want to corrupt the backup superblocks, and (b) we * don't need to update the mount count and last checked * fields in the backup superblock (the kernel doesn't * update the backup superblocks anyway). */ fs->flags |= EXT2_FLAG_MASTER_SB_ONLY; ehandler_init(fs->io); if (ctx->superblock) set_latch_flags(PR_LATCH_RELOC, PRL_LATCHED, 0); ext2fs_mark_valid(fs); check_super_block(ctx); if (ctx->flags & E2F_FLAG_SIGNAL_MASK) fatal_error(ctx, 0); check_if_skip(ctx); if (bad_blocks_file) read_bad_blocks_file(ctx, bad_blocks_file, replace_bad_blocks); else if (cflag) read_bad_blocks_file(ctx, 0, !keep_bad_blocks); /* Test disk */ if (ctx->flags & E2F_FLAG_SIGNAL_MASK) fatal_error(ctx, 0); #ifdef ENABLE_SWAPFS if (normalize_swapfs) { if ((fs->flags & EXT2_FLAG_SWAP_BYTES) == ext2fs_native_flag()) { fprintf(stderr, _("%s: Filesystem byte order " "already normalized.\n"), ctx->device_name); fatal_error(ctx, 0); } } if (swapfs) { swap_filesys(ctx); if (ctx->flags & E2F_FLAG_SIGNAL_MASK) fatal_error(ctx, 0); } #endif /* * Mark the system as valid, 'til proven otherwise */ ext2fs_mark_valid(fs); retval = ext2fs_read_bb_inode(fs, &fs->badblocks); if (retval) { com_err(ctx->program_name, retval, _("while reading bad blocks inode")); preenhalt(ctx); printf(_("This doesn't bode well," " but we'll try to go on...\n")); } run_result = e2fsck_run(ctx); e2fsck_clear_progbar(ctx); if (run_result == E2F_FLAG_RESTART) { printf(_("Restarting e2fsck from the beginning...\n")); retval = e2fsck_reset_context(ctx); if (retval) { com_err(ctx->program_name, retval, _("while resetting context")); fatal_error(ctx, 0); } ext2fs_close(fs); goto restart; } if (run_result & E2F_FLAG_CANCEL) { printf(_("%s: e2fsck canceled.\n"), ctx->device_name ? ctx->device_name : ctx->filesystem_name); exit_value |= FSCK_CANCELED; } if (run_result & E2F_FLAG_ABORT) fatal_error(ctx, _("aborted")); #ifdef MTRACE mtrace_print("Cleanup"); #endif if (ext2fs_test_changed(fs)) { exit_value |= FSCK_NONDESTRUCT; if (!(ctx->options & E2F_OPT_PREEN)) printf(_("\n%s: ***** FILE SYSTEM WAS MODIFIED *****\n"), ctx->device_name); if (ctx->mount_flags & EXT2_MF_ISROOT) { printf(_("%s: ***** REBOOT LINUX *****\n"), ctx->device_name); exit_value |= FSCK_REBOOT; } } if (!ext2fs_test_valid(fs) || ((exit_value & FSCK_CANCELED) && (sb->s_state & EXT2_ERROR_FS))) { printf(_("\n%s: ********** WARNING: Filesystem still has " "errors **********\n\n"), ctx->device_name); exit_value |= FSCK_UNCORRECTED; exit_value &= ~FSCK_NONDESTRUCT; } if (exit_value & FSCK_CANCELED) { int allow_cancellation; profile_get_boolean(ctx->profile, "options", "allow_cancellation", 0, 0, &allow_cancellation); exit_value &= ~FSCK_NONDESTRUCT; if (allow_cancellation && ext2fs_test_valid(fs) && (sb->s_state & EXT2_VALID_FS) && !(sb->s_state & EXT2_ERROR_FS)) exit_value = 0; } else { show_stats(ctx); if (!(ctx->options & E2F_OPT_READONLY)) { if (ext2fs_test_valid(fs)) { if (!(sb->s_state & EXT2_VALID_FS)) exit_value |= FSCK_NONDESTRUCT; sb->s_state = EXT2_VALID_FS; } else sb->s_state &= ~EXT2_VALID_FS; sb->s_mnt_count = 0; sb->s_lastcheck = ctx->now; ext2fs_mark_super_dirty(fs); } } e2fsck_write_bitmaps(ctx); ext2fs_close(fs); ctx->fs = NULL; free(ctx->filesystem_name); free(ctx->journal_name); #ifdef RESOURCE_TRACK if (ctx->options & E2F_OPT_TIME) print_resource_track(NULL, &ctx->global_rtrack); #endif e2fsck_free_context(ctx); return exit_value; }