static int disc_modevent(module_t mod, int type, void *data) { struct disc_softc *sc; switch (type) { case MOD_LOAD: mtx_init(&disc_mtx, "disc_mtx", NULL, MTX_DEF); LIST_INIT(&disc_softc_list); if_clone_attach(&disc_cloner); break; case MOD_UNLOAD: if_clone_detach(&disc_cloner); mtx_lock(&disc_mtx); while ((sc = LIST_FIRST(&disc_softc_list)) != NULL) { LIST_REMOVE(sc, sc_list); mtx_unlock(&disc_mtx); disc_destroy(sc); mtx_lock(&disc_mtx); } mtx_unlock(&disc_mtx); mtx_destroy(&disc_mtx); break; default: return (EOPNOTSUPP); } return (0); }
static void disc_clone_destroy(struct ifnet *ifp) { struct disc_softc *sc; sc = ifp->if_softc; mtx_lock(&disc_mtx); LIST_REMOVE(sc, sc_list); mtx_unlock(&disc_mtx); disc_destroy(sc); }
int main (int argc, char *argv[]) { disc *d; progstats stats; double duration; suseconds_t us; int out, ret; unscrambler *u; unscrambler_progress_func pfunc; u_int32_t current_sector; /* First of all... */ drop_euid (); welcome (); d = NULL; out = false; if (optparse (argc, argv)) { if (options.device) { /* Dump DVD to file */ fprintf (stderr, "Initializing DVD drive... "); if (!(d = disc_new (options.device, options.command))) { fprintf (stderr, "Failed\n"); #ifndef WIN32 fprintf (stderr, "Probably you do not have access to the DVD device. Ask the administrator\n" "to add you to the proper group, or use 'sudo'.\n" ); #endif } else { fprintf (stderr, "OK\n"); if(options.allmethods) { fprintf (stderr, "Trying all methods... This will take a LOOOONG time and generate an insanely long console output :p\n"); for(options.command=0;options.command<=4;options.command++) { for(options.dump_method=0;options.dump_method<=9;options.dump_method++) { fprintf (stderr, "Trying with command %d, method %d\n", options.command, options.dump_method); out = dologic(d, stats); if(out==true) { break; } } if(out==true) { fprintf (stderr, "Command %d and method %d combination worked!\n", options.command, options.dump_method); break; } } } else { out = dologic(d, stats); } d = disc_destroy (d); } } else if (options.raw_in) { /* Convert raw image to ISO format */ u = unscrambler_new (); if (options.gui) pfunc = (unscrambler_progress_func) progress_for_guis; else pfunc = (unscrambler_progress_func) progress; if ((out = unscrambler_unscramble_file (u, options.raw_in, options.iso_out, pfunc, &stats, ¤t_sector))) fprintf (stderr, "Unscrambling completed successfully!\n"); else fprintf (stderr, "\nUnscrambling failed at sectors: %u..%u\n", current_sector, current_sector+15); u = unscrambler_destroy (u); } else { MY_ASSERT (0); } if (out) { duration = stats.end_time.tv_sec - stats.start_time.tv_sec; if (stats.end_time.tv_usec >= stats.start_time.tv_usec) { us = stats.end_time.tv_usec - stats.start_time.tv_usec; } else { if (duration > 0) duration--; us = USECS_PER_SEC + stats.end_time.tv_usec - stats.start_time.tv_usec; } duration += ((double) us / (double) USECS_PER_SEC); if (duration < 0) duration = 0; fprintf (stderr, "Operation took %.2f seconds\n", duration); ret = EXIT_SUCCESS; } else { ret = EXIT_FAILURE; } my_free (options.device); my_free (options.iso_out); my_free (options.raw_out); my_free (options.raw_in); } return (out); }