EXPORT m64p_error CALL VidExt_ResizeWindow(int Width, int Height) { const SDL_VideoInfo *videoInfo; int videoFlags = 0; /* call video extension override if necessary */ if (l_VideoExtensionActive) { m64p_error rval; // shut down the OSD osd_exit(); // re-create the OGL context rval = (*l_ExternalVideoFuncTable.VidExtFuncResizeWindow)(Width, Height); if (rval == M64ERR_SUCCESS) { StateChanged(M64CORE_VIDEO_SIZE, (Width << 16) | Height); // re-create the On-Screen Display osd_init(Width, Height); } return rval; } if (!l_VideoOutputActive || !SDL_WasInit(SDL_INIT_VIDEO)) return M64ERR_NOT_INIT; if (l_Fullscreen) { DebugMessage(M64MSG_ERROR, "VidExt_ResizeWindow() called in fullscreen mode."); return M64ERR_INVALID_STATE; } /* Get SDL video flags to use */ videoFlags = SDL_OPENGL | SDL_RESIZABLE; if ((videoInfo = SDL_GetVideoInfo()) == NULL) { DebugMessage(M64MSG_ERROR, "SDL_GetVideoInfo query failed: %s", SDL_GetError()); return M64ERR_SYSTEM_FAIL; } if (videoInfo->hw_available) videoFlags |= SDL_HWSURFACE; else videoFlags |= SDL_SWSURFACE; // destroy the On-Screen Display osd_exit(); /* set the re-sizing the screen will create a new OpenGL context */ l_pScreen = SDL_SetVideoMode(Width, Height, 0, videoFlags); if (l_pScreen == NULL) { DebugMessage(M64MSG_ERROR, "SDL_SetVideoMode failed: %s", SDL_GetError()); return M64ERR_SYSTEM_FAIL; } StateChanged(M64CORE_VIDEO_SIZE, (Width << 16) | Height); // re-create the On-Screen Display osd_init(Width, Height); return M64ERR_SUCCESS; }
/* This is the final leg of main() */ int main_loop(const char *filename, system_t type) { vidinfo_t video; /* register shutdown, in case of assertions, etc. */ // atexit(shutdown_everything); //if (config.open()) // JMH // return -1; if (osd_init()) return -1; osd_getvideoinfo(&video); if (vid_init(video.default_width, video.default_height, video.driver)) return -1; //log printf("vid_init done\n"); console.nextfilename = strdup(filename); console.nexttype = type; // while (false == console.quit) // { //emu_printf("internal_insert in loop\n"); if (internal_insert(console.nextfilename, console.nexttype)) return 1; // } return 0; }
/**\brief 初始化OSD模块(不打开OSD设备,只初始化相关资源) * \return * - AM_SUCCESS 成功 * - 其他值 错误代码(见am_osd.h) */ AM_ErrorCode_t AM_OSD_Init(void) { pthread_mutex_lock(&am_gAdpLock); osd_init(); pthread_mutex_unlock(&am_gAdpLock); return AM_SUCCESS; }
int main(int argc,char **argv) { int i,list,log,success; list = 0; for (i = 1;i < argc;i++) { if (stricmp(argv[i],"-list") == 0) list = 1; } if (list) { printf("\nMAME currently supports the following games:\n\n"); i = 0; while (drivers[i]) { printf("%10s",drivers[i]->name); i++; if (!(i % 7)) printf("\n"); } if (i % 7) printf("\n"); printf("\nTotal games supported: %4d\n", i); return 0; } success = 1; log = 0; for (i = 1;i < argc;i++) { if (stricmp(argv[i],"-log") == 0) log = 1; } if (log) errorlog = fopen("error.log","wa"); if (init_machine(argc > 1 && argv[1][0] != '-' ? argv[1] : DEFAULT_NAME,argc,argv) == 0) { if (osd_init(argc,argv) == 0) { if (run_machine(argc > 1 && argv[1][0] != '-' ? argv[1] : DEFAULT_NAME) == 0) success = 0; else printf("Unable to start emulation\n"); osd_exit(); } else printf("Unable to initialize system\n"); shutdown_machine(); } else printf("Unable to initialize machine emulation\n"); if (errorlog) fclose(errorlog); return success; }
MWBOOL OSD_mapmemgc(PSD mempsd,MWCOORD w,MWCOORD h,int planes,int bpp,int linelen, int size,void *addr) { osd_surface_t *surface; if (osd_init(mempsd, w, h) < 0) return 0; surface = (osd_surface_t*)mempsd->addr; return 1; }
/**\brief 打开一个OSD设备 * \param dev_no OSD设备号 * \param[in] para 设备开启参数 * \return * - AM_SUCCESS 成功 * - 其他值 错误代码(见am_osd.h) */ AM_ErrorCode_t AM_OSD_Open(int dev_no, AM_OSD_OpenPara_t *para) { AM_OSD_Device_t *dev; AM_ErrorCode_t ret = AM_SUCCESS; assert(para); AM_TRY(osd_get_dev(dev_no, &dev)); pthread_mutex_lock(&am_gAdpLock); /*Initialize the global data*/ osd_init(); if(dev->openned) { AM_DEBUG(1, "osd device already openned"); ret = AM_OSD_ERR_BUSY; osd_deinit(); } dev->dev_no = dev_no; dev->vout_dev_no = para->vout_dev_no; dev->surface = NULL; dev->display = NULL; dev->enable = AM_TRUE; if(ret==AM_SUCCESS) { dev->dev_no = dev_no; if(dev->drv->open) { ret = dev->drv->open(dev, para, &dev->surface, &dev->display); if(ret!=AM_SUCCESS) osd_deinit(); } } if(ret==AM_SUCCESS) { dev->openned = AM_TRUE; dev->para = *para; dev->enable_double_buffer = para->enable_double_buffer; } pthread_mutex_unlock(&am_gAdpLock); return ret; }
static PSD OSD_open(PSD psd) { osd_surface_t *surface; if (osd_init(psd, -1, -1) < 0) return NULL; surface = (osd_surface_t*)psd->addr; osd_display_surface(surface); PRINTF("OSD: display created and displayed\n"); return psd; }
void renderer_start(int framebuffer_fd, struct patch *p) { assert(mashup_head == NULL); mashup_head = patch_copy(p); current_patch = mashup_head; mashup_en = 0; renderer_texsize = 512; renderer_hmeshlast = 32; renderer_vmeshlast = 32; renderer_squarew = renderer_texsize/renderer_hmeshlast; renderer_squareh = renderer_texsize/renderer_vmeshlast; osd_init(); raster_start(framebuffer_fd, sampler_return); eval_start(raster_input); sampler_start(eval_input); rsswall_start(); }
int main(int argc, char **argv) { /* initialize interrupt handling */ VIDEOIF->flags = 0; IRQController->Enable = IRQ_FLAG_VSYNC | IRQ_FLAG_PAD | IRQ_FLAG_GLOBALEN; VIDEOIF->settings = VIDEOIF_SET_CABLEDETECT; // temporary during init /* run initializations */ settings_init(); osd_init(); spiflash_init(); VIDEOIF->settings = video_settings[current_videomode]; VIDEOIF->osd_bg = osdbg_settings; while (1) { screen_idle(); screen_mainmenu(); } }
void running_machine::start() { /* initialize basic can't-fail systems here */ fileio_init(this); config_init(this); input_init(this); output_init(this); state_init(this); state_save_allow_registration(this, true); palette_init(this); render_init(this); ui_init(this); generic_machine_init(this); generic_video_init(this); generic_sound_init(this); /* initialize the timers and allocate a soft_reset timer this must be done before cpu_init so that CPU's can allocate timers */ timer_init(this); m_soft_reset_timer = timer_alloc(this, static_soft_reset, NULL); /* init the osd layer */ osd_init(this); /* initialize the base time (needed for doing record/playback) */ time(&m_base_time); /* initialize the input system and input ports for the game this must be done before memory_init in order to allow specifying callbacks based on input port tags */ time_t newbase = input_port_init(this, m_game.ipt); if (newbase != 0) m_base_time = newbase; /* intialize UI input */ ui_input_init(this); /* initialize the streams engine before the sound devices start */ streams_init(this); /* first load ROMs, then populate memory, and finally initialize CPUs these operations must proceed in this order */ rom_init(this); memory_init(this); watchdog_init(this); /* allocate the gfx elements prior to device initialization */ gfx_init(this); /* initialize natural keyboard support */ inputx_init(this); /* initialize image devices */ image_init(this); /* start up the devices */ m_devicelist.start_all(); /* call the game driver's init function this is where decryption is done and memory maps are altered so this location in the init order is important */ ui_set_startup_text(this, "Initializing...", true); if (m_game.driver_init != NULL) (*m_game.driver_init)(this); /* finish image devices init process */ image_postdevice_init(this); /* start the video and audio hardware */ video_init(this); tilemap_init(this); crosshair_init(this); sound_init(this); /* initialize the debugger */ if ((debug_flags & DEBUG_FLAG_ENABLED) != 0) debugger_init(this); /* call the driver's _START callbacks */ if (m_config.m_machine_start != NULL) (*m_config.m_machine_start)(this); if (m_config.m_sound_start != NULL) (*m_config.m_sound_start)(this); if (m_config.m_video_start != NULL) (*m_config.m_video_start)(this); /* set up the cheat engine */ cheat_init(this); /* set up the hiscore engine */ hiscore_init(this); /* disallow save state registrations starting here */ state_save_allow_registration(this, false); }
void running_machine::start() { // initialize basic can't-fail systems here fileio_init(this); config_init(this); input_init(this); output_init(this); state_init(this); state_save_allow_registration(this, true); palette_init(this); render_init(this); ui_init(this); generic_machine_init(this); generic_video_init(this); generic_sound_init(this); // initialize the timers and allocate a soft_reset timer // this must be done before cpu_init so that CPU's can allocate timers timer_init(this); m_soft_reset_timer = timer_alloc(this, static_soft_reset, NULL); // init the osd layer osd_init(this); // initialize the base time (needed for doing record/playback) time(&m_base_time); // initialize the input system and input ports for the game // this must be done before memory_init in order to allow specifying // callbacks based on input port tags time_t newbase = input_port_init(this, m_game.ipt); if (newbase != 0) m_base_time = newbase; // intialize UI input ui_input_init(this); // initialize the streams engine before the sound devices start streams_init(this); // first load ROMs, then populate memory, and finally initialize CPUs // these operations must proceed in this order rom_init(this); memory_init(this); watchdog_init(this); // allocate the gfx elements prior to device initialization gfx_init(this); // initialize natural keyboard support inputx_init(this); // initialize image devices image_init(this); // start up the devices m_devicelist.start_all(); // call the game driver's init function // this is where decryption is done and memory maps are altered // so this location in the init order is important ui_set_startup_text(this, "Initializing...", true); if (m_game.driver_init != NULL) (*m_game.driver_init)(this); // finish image devices init process image_postdevice_init(this); // start the video and audio hardware video_init(this); tilemap_init(this); crosshair_init(this); sound_init(this); // initialize the debugger if ((debug_flags & DEBUG_FLAG_ENABLED) != 0) debugger_init(this); // call the driver's _START callbacks if (m_config.m_machine_start != NULL) (*m_config.m_machine_start)(this); if (m_config.m_sound_start != NULL) (*m_config.m_sound_start)(this); if (m_config.m_video_start != NULL) (*m_config.m_video_start)(this); // if we're coming in with a savegame request, process it now const char *savegame = options_get_string(&m_options, OPTION_STATE); if (savegame[0] != 0) schedule_load(savegame); // if we're in autosave mode, schedule a load else if (options_get_bool(&m_options, OPTION_AUTOSAVE) && (m_game.flags & GAME_SUPPORTS_SAVE) != 0) schedule_load("auto"); // set up the cheat engine if (options_get_bool(&m_options, OPTION_CHEAT)) cheat_init(this); // disallow save state registrations starting here state_save_allow_registration(this, false); }
int run_game(int game) { int err; /* copy some settings into easier-to-handle variables */ record = options.record; playback = options.playback; mame_debug = options.mame_debug; Machine->gamedrv = gamedrv = drivers[game]; Machine->drv = drv = gamedrv->drv; /* copy configuration */ if (options.color_depth == 16 || (options.color_depth != 8 && (Machine->gamedrv->flags & GAME_REQUIRES_16BIT))) Machine->color_depth = 16; else Machine->color_depth = 8; //if (options.vector_width == 0) options.vector_width = 640; //if (options.vector_height == 0) options.vector_height = 480; if (options.vector_width == 0) options.vector_width = 320; if (options.vector_height == 0) options.vector_height = 240; Machine->sample_rate = options.samplerate; /* get orientation right */ Machine->orientation = gamedrv->flags & ORIENTATION_MASK; Machine->ui_orientation = ROT0; if (options.norotate) Machine->orientation = ROT0; if (options.ror) { /* if only one of the components is inverted, switch them */ if ((Machine->orientation & ROT180) == ORIENTATION_FLIP_X || (Machine->orientation & ROT180) == ORIENTATION_FLIP_Y) Machine->orientation ^= ROT180; Machine->orientation ^= ROT90; /* if only one of the components is inverted, switch them */ if ((Machine->ui_orientation & ROT180) == ORIENTATION_FLIP_X || (Machine->ui_orientation & ROT180) == ORIENTATION_FLIP_Y) Machine->ui_orientation ^= ROT180; Machine->ui_orientation ^= ROT90; } if (options.rol) { /* if only one of the components is inverted, switch them */ if ((Machine->orientation & ROT180) == ORIENTATION_FLIP_X || (Machine->orientation & ROT180) == ORIENTATION_FLIP_Y) Machine->orientation ^= ROT180; Machine->orientation ^= ROT270; /* if only one of the components is inverted, switch them */ if ((Machine->ui_orientation & ROT180) == ORIENTATION_FLIP_X || (Machine->ui_orientation & ROT180) == ORIENTATION_FLIP_Y) Machine->ui_orientation ^= ROT180; Machine->ui_orientation ^= ROT270; } if (options.flipx) { Machine->orientation ^= ORIENTATION_FLIP_X; Machine->ui_orientation ^= ORIENTATION_FLIP_X; } if (options.flipy) { Machine->orientation ^= ORIENTATION_FLIP_Y; Machine->ui_orientation ^= ORIENTATION_FLIP_Y; } set_pixel_functions(); /* Do the work*/ err = 1; bailing = 0; #ifdef MESS if (get_filenames()) return err; #endif if (osd_init() == 0) { if (init_machine() == 0) { if (run_machine() == 0) err = 0; else if (!bailing) { bailing = 1; printf("Unable to start machine emulation\n"); } shutdown_machine(); } else if (!bailing) { bailing = 1; printf("Unable to initialize machine emulation\n"); } osd_exit(); } else if (!bailing) { bailing = 1; printf ("Unable to initialize system\n"); } return err; }
/********************************************************************************************************* * emulation thread - runs the core */ m64p_error main_run(void) { VILimit = (float) GetVILimit(); VILimitMilliseconds = (double) 1000.0/VILimit; /* take the r4300 emulator mode from the config file at this point and cache it in a global variable */ r4300emu = ConfigGetParamInt(g_CoreConfig, "R4300Emulator"); /* set some other core parameters based on the config file values */ savestates_set_autoinc_slot(ConfigGetParamBool(g_CoreConfig, "AutoStateSlotIncrement")); savestates_select_slot(ConfigGetParamInt(g_CoreConfig, "CurrentStateSlot")); no_compiled_jump = ConfigGetParamBool(g_CoreConfig, "NoCompiledJump"); /* set up the SDL key repeat and event filter to catch keyboard/joystick commands for the core */ event_initialize(); // initialize memory, and do byte-swapping if it's not been done yet if (g_MemHasBeenBSwapped == 0) { init_memory(1); g_MemHasBeenBSwapped = 1; } else { init_memory(0); } // Attach rom to plugins if (!romOpen_gfx()) { free_memory(); SDL_Quit(); return M64ERR_PLUGIN_FAIL; } if (!romOpen_audio()) { romClosed_gfx(); free_memory(); SDL_Quit(); return M64ERR_PLUGIN_FAIL; } if (!romOpen_input()) { romClosed_audio(); romClosed_gfx(); free_memory(); SDL_Quit(); return M64ERR_PLUGIN_FAIL; } if (ConfigGetParamBool(g_CoreConfig, "OnScreenDisplay")) { // init on-screen display int width = 640, height = 480; readScreen(NULL, &width, &height, 0); // read screen to get width and height osd_init(width, height); } // setup rendering callback from video plugin to the core, for screenshots and On-Screen-Display setRenderingCallback(video_plugin_render_callback); #ifdef WITH_LIRC lircStart(); #endif // WITH_LIRC #ifdef DBG if (ConfigGetParamBool(g_CoreConfig, "EnableDebugger")) init_debugger(); #endif /* Startup message on the OSD */ osd_new_message(OSD_MIDDLE_CENTER, "Mupen64Plus Started..."); g_EmulatorRunning = 1; StateChanged(M64CORE_EMU_STATE, M64EMU_RUNNING); /* call r4300 CPU core and run the game */ r4300_reset_hard(); r4300_reset_soft(); r4300_execute(); #ifdef WITH_LIRC lircStop(); #endif // WITH_LIRC #ifdef DBG if (g_DebuggerActive) destroy_debugger(); #endif if (ConfigGetParamBool(g_CoreConfig, "OnScreenDisplay")) { osd_exit(); } romClosed_RSP(); romClosed_input(); romClosed_audio(); romClosed_gfx(); free_memory(); // clean up g_EmulatorRunning = 0; StateChanged(M64CORE_EMU_STATE, M64EMU_STOPPED); SDL_Quit(); return M64ERR_SUCCESS; }
static void init_machine(running_machine *machine) { mame_private *mame = machine->mame_data; int num; /* initialize basic can't-fail systems here */ cpuintrf_init(machine); sndintrf_init(machine); fileio_init(machine); config_init(machine); output_init(machine); state_init(machine); state_save_allow_registration(TRUE); drawgfx_init(machine); palette_init(machine); render_init(machine); ui_init(machine); generic_machine_init(machine); generic_video_init(machine); mame->rand_seed = 0x9d14abd7; /* initialize the base time (if not doing record/playback) */ if (!Machine->record_file && !Machine->playback_file) time(&mame->base_time); else mame->base_time = 0; /* init the osd layer */ if (osd_init(machine) != 0) fatalerror("osd_init failed"); /* initialize the input system */ /* this must be done before the input ports are initialized */ if (code_init(machine) != 0) fatalerror("code_init failed"); /* initialize the input ports for the game */ /* this must be done before memory_init in order to allow specifying */ /* callbacks based on input port tags */ if (input_port_init(machine, machine->gamedrv->ipt) != 0) fatalerror("input_port_init failed"); /* load the ROMs if we have some */ /* this must be done before memory_init in order to allocate memory regions */ rom_init(machine, machine->gamedrv->rom); /* initialize the timers and allocate a soft_reset timer */ /* this must be done before cpu_init so that CPU's can allocate timers */ timer_init(machine); mame->soft_reset_timer = timer_alloc(soft_reset); /* initialize the memory system for this game */ /* this must be done before cpu_init so that set_context can look up the opcode base */ if (memory_init(machine) != 0) fatalerror("memory_init failed"); /* now set up all the CPUs */ if (cpuexec_init(machine) != 0) fatalerror("cpuexec_init failed"); if (cpuint_init(machine) != 0) fatalerror("cpuint_init failed"); #ifdef MESS /* initialize the devices */ devices_init(machine); #endif /* start the save/load system */ saveload_init(machine); /* call the game driver's init function */ /* this is where decryption is done and memory maps are altered */ /* so this location in the init order is important */ ui_set_startup_text("Initializing...", TRUE); if (machine->gamedrv->driver_init != NULL) (*machine->gamedrv->driver_init)(machine); /* start the audio system */ if (sound_init(machine) != 0) fatalerror("sound_init failed"); /* start the video hardware */ if (video_init(machine) != 0) fatalerror("video_init failed"); /* start the cheat engine */ if (options.cheat) cheat_init(machine); /* call the driver's _START callbacks */ if (machine->drv->machine_start != NULL && (*machine->drv->machine_start)(machine) != 0) fatalerror("Unable to start machine emulation"); if (machine->drv->sound_start != NULL && (*machine->drv->sound_start)(machine) != 0) fatalerror("Unable to start sound emulation"); if (machine->drv->video_start != NULL && (*machine->drv->video_start)(machine) != 0) fatalerror("Unable to start video emulation"); /* free memory regions allocated with REGIONFLAG_DISPOSE (typically gfx roms) */ for (num = 0; num < MAX_MEMORY_REGIONS; num++) if (mame->mem_region[num].flags & ROMREGION_DISPOSE) free_memory_region(machine, num); #ifdef MAME_DEBUG /* initialize the debugger */ if (machine->debug_mode) mame_debug_init(machine); #endif }
int main(int argc, char *const argv[]) { struct mount_opts mop; char *options; int i, rc, flags; progname = strrchr(argv[0], '/'); progname = progname ? progname + 1 : argv[0]; set_defaults(&mop); rc = osd_init(); if (rc) return rc; rc = parse_opts(argc, argv, &mop); if (rc || version) return rc; if (verbose) { for (i = 0; i < argc; i++) printf("arg[%d] = %s\n", i, argv[i]); printf("source = %s (%s), target = %s\n", mop.mo_usource, mop.mo_source, mop.mo_target); printf("options = %s\n", mop.mo_orig_options); } options = malloc(MAXOPT); if (options == NULL) { fprintf(stderr, "can't allocate memory for options\n"); return -1; } strcpy(options, mop.mo_orig_options); rc = parse_options(&mop, options, &flags); if (rc) { fprintf(stderr, "%s: can't parse options: %s\n", progname, options); return(EINVAL); } if (!mop.mo_force) { rc = check_mtab_entry(mop.mo_usource, mop.mo_source, mop.mo_target, "lustre"); if (rc && !(flags & MS_REMOUNT)) { fprintf(stderr, "%s: according to %s %s is " "already mounted on %s\n", progname, MOUNTED, mop.mo_usource, mop.mo_target); return(EEXIST); } if (!rc && (flags & MS_REMOUNT)) { fprintf(stderr, "%s: according to %s %s is " "not already mounted on %s\n", progname, MOUNTED, mop.mo_usource, mop.mo_target); return(ENOENT); } } if (flags & MS_REMOUNT) mop.mo_nomtab++; rc = access(mop.mo_target, F_OK); if (rc) { rc = errno; fprintf(stderr, "%s: %s inaccessible: %s\n", progname, mop.mo_target, strerror(errno)); return rc; } if (!strstr(mop.mo_usource, ":/")) { rc = parse_ldd(mop.mo_source, &mop, options); if (rc) return rc; } /* In Linux 2.4, the target device doesn't get passed to any of our functions. So we'll stick it on the end of the options. */ append_option(options, "device="); strcat(options, mop.mo_source); if (verbose) printf("mounting device %s at %s, flags=%#x options=%s\n", mop.mo_source, mop.mo_target, flags, options); if (!strstr(mop.mo_usource, ":/") && osd_tune_lustre(mop.mo_source, &mop)) { if (verbose) fprintf(stderr, "%s: unable to set tunables for %s" " (may cause reduced IO performance)\n", argv[0], mop.mo_source); } if (!mop.mo_fake) { /* flags and target get to lustre_get_sb, but not lustre_fill_super. Lustre ignores the flags, but mount does not. */ for (i = 0, rc = -EAGAIN; i <= mop.mo_retry && rc != 0; i++) { rc = mount(mop.mo_source, mop.mo_target, "lustre", flags, (void *)options); if (rc == 0) { /* change label from <fsname>:<index> to * <fsname>-<index> to indicate the device has * been registered. only if the label is * supposed to be changed and target service * is supposed to start */ if (mop.mo_ldd.ldd_flags & (LDD_F_VIRGIN | LDD_F_WRITECONF)) { if (mop.mo_nosvc == 0) (void)osd_label_lustre(&mop); } } else { if (verbose) { fprintf(stderr, "%s: mount %s at %s " "failed: %s retries left: " "%d\n", basename(progname), mop.mo_usource, mop.mo_target, strerror(errno), mop.mo_retry - i); } if (mop.mo_retry) { sleep(1 << max((i/2), 5)); } else { rc = errno; } } } } if (rc) { char *cli; rc = errno; cli = strrchr(mop.mo_usource, ':'); if (cli && (strlen(cli) > 2)) cli += 2; else cli = NULL; fprintf(stderr, "%s: mount %s at %s failed: %s\n", progname, mop.mo_usource, mop.mo_target, strerror(errno)); if (errno == EBUSY) fprintf(stderr, "Is the backend filesystem mounted?\n" "Check /etc/mtab and /proc/mounts\n"); if (errno == ENODEV) fprintf(stderr, "Are the lustre modules loaded?\n" "Check /etc/modprobe.conf and " "/proc/filesystems\n"); if (errno == ENOTBLK) fprintf(stderr, "Do you need -o loop?\n"); if (errno == ENOMEDIUM) fprintf(stderr, "This filesystem needs at least 1 OST\n"); if (errno == ENOENT) { fprintf(stderr, "Is the MGS specification correct?\n"); fprintf(stderr, "Is the filesystem name correct?\n"); fprintf(stderr, "If upgrading, is the copied client log" " valid? (see upgrade docs)\n"); } if (errno == EALREADY) fprintf(stderr, "The target service is already running." " (%s)\n", mop.mo_usource); if (errno == ENXIO) fprintf(stderr, "The target service failed to start " "(bad config log?) (%s). " "See /var/log/messages.\n", mop.mo_usource); if (errno == EIO) fprintf(stderr, "Is the MGS running?\n"); if (errno == EADDRINUSE) fprintf(stderr, "The target service's index is already " "in use. (%s)\n", mop.mo_usource); if (errno == EINVAL) { fprintf(stderr, "This may have multiple causes.\n"); if (cli) fprintf(stderr, "Is '%s' the correct filesystem" " name?\n", cli); fprintf(stderr, "Are the mount options correct?\n"); fprintf(stderr, "Check the syslog for more info.\n"); } /* May as well try to clean up loop devs */ if (strncmp(mop.mo_usource, "/dev/loop", 9) == 0) { char cmd[256]; int ret; sprintf(cmd, "/sbin/losetup -d %s", mop.mo_usource); if ((ret = system(cmd)) < 0) rc = errno; else if (ret > 0) rc = WEXITSTATUS(ret); } } else if (!mop.mo_nomtab) { rc = update_mtab_entry(mop.mo_usource, mop.mo_target, "lustre", mop.mo_orig_options, 0,0,0); } free(options); /* mo_usource should be freed, but we can rely on the kernel */ free(mop.mo_source); osd_fini(); return rc; }
int main(int argc, char *const argv[]) { struct mkfs_opts mop; struct lustre_disk_data *ldd = &mop.mo_ldd; char *mountopts = NULL; char wanted_mountopts[512] = ""; unsigned mount_type; int ret = 0; int ret2 = 0; progname = strrchr(argv[0], '/'); if (progname != NULL) progname++; else progname = argv[0]; if ((argc < 2) || (argv[argc - 1][0] == '-')) { usage(stderr); return EINVAL; } memset(&mop, 0, sizeof(mop)); set_defaults(&mop); /* device is last arg */ strscpy(mop.mo_device, argv[argc - 1], sizeof(mop.mo_device)); ret = osd_init(); if (ret != 0) return ret; #ifdef TUNEFS /* For tunefs, we must read in the old values before parsing any new ones. */ /* Check whether the disk has already been formatted by mkfs.lustre */ ret = osd_is_lustre(mop.mo_device, &mount_type); if (ret == 0) { fatal(); fprintf(stderr, "Device %s has not been formatted with " "mkfs.lustre\n", mop.mo_device); ret = ENODEV; goto out; } ldd->ldd_mount_type = mount_type; ret = osd_read_ldd(mop.mo_device, ldd); if (ret != 0) { fatal(); fprintf(stderr, "Failed to read previous Lustre data from %s " "(%d)\n", mop.mo_device, ret); goto out; } ldd->ldd_flags &= ~(LDD_F_WRITECONF | LDD_F_VIRGIN); /* svname of the form lustre:OST1234 means never registered */ ret = strlen(ldd->ldd_svname); if (ldd->ldd_svname[ret - 8] == ':') { ldd->ldd_svname[ret - 8] = '-'; ldd->ldd_flags |= LDD_F_VIRGIN; } else if (ldd->ldd_svname[ret - 8] == '=') { ldd->ldd_svname[ret - 8] = '-'; ldd->ldd_flags |= LDD_F_WRITECONF; } if (strstr(ldd->ldd_params, PARAM_MGSNODE)) mop.mo_mgs_failnodes++; if (verbose > 0) print_ldd("Read previous values", ldd); #endif /* TUNEFS */ ret = parse_opts(argc, argv, &mop, &mountopts); if (ret != 0 || version) goto out; if (!IS_MDT(ldd) && !IS_OST(ldd) && !IS_MGS(ldd)) { fatal(); fprintf(stderr, "must set target type: MDT,OST,MGS\n"); ret = EINVAL; goto out; } if (((IS_MDT(ldd) || IS_MGS(ldd))) && IS_OST(ldd)) { fatal(); fprintf(stderr, "OST type is exclusive with MDT,MGS\n"); ret = EINVAL; goto out; } /* Stand alone MGS doesn't need an index */ if (!IS_MDT(ldd) && IS_MGS(ldd)) { #ifndef TUNEFS /* But if --index was specified flag an error */ if (!(ldd->ldd_flags & LDD_F_NEED_INDEX)) { badopt("index", "MDT,OST"); goto out; } #endif ldd->ldd_flags &= ~LDD_F_NEED_INDEX; } if ((ldd->ldd_flags & (LDD_F_NEED_INDEX | LDD_F_UPGRADE14)) == (LDD_F_NEED_INDEX | LDD_F_UPGRADE14)) { fatal(); fprintf(stderr, "Can't find the target index, " "specify with --index\n"); ret = EINVAL; goto out; } if (ldd->ldd_flags & LDD_F_NEED_INDEX) fprintf(stderr, "warning: %s: for Lustre 2.4 and later, the " "target index must be specified with --index\n", mop.mo_device); /* If no index is supplied for MDT by default set index to zero */ if (IS_MDT(ldd) && (ldd->ldd_svindex == INDEX_UNASSIGNED)) { ldd->ldd_flags &= ~LDD_F_NEED_INDEX; ldd->ldd_svindex = 0; } if (!IS_MGS(ldd) && (mop.mo_mgs_failnodes == 0)) { fatal(); if (IS_MDT(ldd)) fprintf(stderr, "Must specify --mgs or --mgsnode\n"); else fprintf(stderr, "Must specify --mgsnode\n"); ret = EINVAL; goto out; } if ((IS_MDT(ldd) || IS_OST(ldd)) && ldd->ldd_fsname[0] == '\0') { fatal(); fprintf(stderr, "Must specify --fsname for MDT/OST device\n"); ret = EINVAL; goto out; } /* These are the permanent mount options (always included) */ ret = osd_prepare_lustre(&mop, wanted_mountopts, sizeof(wanted_mountopts)); if (ret != 0) { fatal(); fprintf(stderr, "unable to prepare backend (%d)\n", ret); goto out; } if (mountopts) { trim_mountfsoptions(mountopts); if (check_mountfsoptions(mountopts, wanted_mountopts)) { ret = EINVAL; goto out; } snprintf(ldd->ldd_mount_opts, sizeof(ldd->ldd_mount_opts), "%s", mountopts); } else { #ifdef TUNEFS if (ldd->ldd_mount_opts[0] == 0) /* use the defaults unless old opts exist */ #endif { snprintf(ldd->ldd_mount_opts, sizeof(ldd->ldd_mount_opts), "%s", wanted_mountopts); trim_mountfsoptions(ldd->ldd_mount_opts); } } ret = osd_fix_mountopts(&mop, ldd->ldd_mount_opts, sizeof(ldd->ldd_mount_opts)); if (ret != 0) { fatal(); fprintf(stderr, "unable to fix mountfsoptions (%d)\n", ret); goto out; } server_make_name(ldd->ldd_flags, ldd->ldd_svindex, ldd->ldd_fsname, ldd->ldd_svname); if (verbose >= 0) print_ldd("Permanent disk data", ldd); if (print_only) { printf("exiting before disk write.\n"); goto out; } if (check_mtab_entry(mop.mo_device, mop.mo_device, NULL, NULL)) return(EEXIST); /* Create the loopback file */ if (mop.mo_flags & MO_IS_LOOP) { ret = access(mop.mo_device, F_OK); if (ret != 0) ret = errno; #ifndef TUNEFS /* Reformat the loopback file */ if (ret != 0 || (mop.mo_flags & MO_FORCEFORMAT)) { ret = loop_format(&mop); if (ret != 0) goto out; } #endif if (ret == 0) ret = loop_setup(&mop); if (ret != 0) { fatal(); fprintf(stderr, "Loop device setup for %s failed: %s\n", mop.mo_device, strerror(ret)); goto out; } } #ifndef TUNEFS /* Check whether the disk has already been formatted by mkfs.lustre */ if (!(mop.mo_flags & MO_FORCEFORMAT)) { ret = osd_is_lustre(mop.mo_device, &mount_type); if (ret != 0) { fatal(); fprintf(stderr, "Device %s was previously formatted " "for lustre. Use --reformat to reformat it, " "or tunefs.lustre to modify.\n", mop.mo_device); goto out; } } /* Format the backing filesystem */ ret = osd_make_lustre(&mop); if (ret != 0) { fatal(); fprintf(stderr, "mkfs failed %d\n", ret); goto out; } #else /* !TUNEFS */ /* update svname with '=' to refresh config */ if (ldd->ldd_flags & LDD_F_WRITECONF) { struct mount_opts opts; opts.mo_ldd = *ldd; opts.mo_source = mop.mo_device; (void) osd_label_lustre(&opts); } /* Enable quota accounting */ if (mop.mo_flags & MO_QUOTA) { ret = osd_enable_quota(&mop); goto out; } #endif /* !TUNEFS */ /* Write our config files */ ret = osd_write_ldd(&mop); if (ret != 0) { fatal(); fprintf(stderr, "failed to write local files\n"); goto out; } out: osd_fini(); ret2 = loop_cleanup(&mop); if (ret == 0) ret = ret2; /* Fix any crazy return values from system() */ if (ret != 0 && ((ret & 255) == 0)) return 1; if (ret != 0) verrprint("%s: exiting with %d (%s)\n", progname, ret, strerror(ret)); return ret; }
virtual void init(running_machine &machine) { this->osd_interface::init(machine); return osd_init(&machine); }