//------------------------------split_thru_region------------------------------ // Split Node 'n' through merge point. Node *PhaseIdealLoop::split_thru_region( Node *n, Node *region ) { uint wins = 0; assert( n->is_CFG(), "" ); assert( region->is_Region(), "" ); Node *r = new (C, region->req()) RegionNode( region->req() ); IdealLoopTree *loop = get_loop( n ); for( uint i = 1; i < region->req(); i++ ) { Node *x = n->clone(); Node *in0 = n->in(0); if( in0->in(0) == region ) x->set_req( 0, in0->in(i) ); for( uint j = 1; j < n->req(); j++ ) { Node *in = n->in(j); if( get_ctrl(in) == region ) x->set_req( j, in->in(i) ); } _igvn.register_new_node_with_optimizer(x); set_loop(x, loop); set_idom(x, x->in(0), dom_depth(x->in(0))+1); r->init_req(i, x); } // Record region r->set_req(0,region); // Not a TRUE RegionNode _igvn.register_new_node_with_optimizer(r); set_loop(r, loop); if( !loop->_child ) loop->_body.push(r); return r; }
//-------------------------------register_control------------------------- void PhaseIdealLoop::register_control(Node* n, IdealLoopTree *loop, Node* pred) { assert(n->is_CFG(), "must be control node"); _igvn.register_new_node_with_optimizer(n); loop->_body.push(n); set_loop(n, loop); // When called from beautify_loops() idom is not constructed yet. if (_idom != NULL) { set_idom(n, pred, dom_depth(pred)); } }
int losetup_main(int argc, char **argv) { unsigned opt; char *opt_o; unsigned long long offset = 0; opt = getopt32(argc, argv, "do:", &opt_o); argc -= optind; argv += optind; if (opt == 0x3) // -d + -o (illegal) bb_show_usage(); if (opt == 0x1) { // -d /* detach takes exactly one argument */ if (argc != 1) bb_show_usage(); if (!del_loop(argv[0])) return EXIT_SUCCESS; bb_perror_nomsg_and_die(); } if (opt == 0x2) // -o offset = xatoull(opt_o); /* -o or no option */ if (argc == 2) { if (set_loop(&argv[0], argv[1], offset) < 0) bb_perror_nomsg_and_die(); } else if (argc == 1) { char *s = query_loop(argv[0]); if (!s) bb_perror_nomsg_and_die(); printf("%s: %s\n", argv[0], s); if (ENABLE_FEATURE_CLEAN_UP) free(s); } else { char dev[sizeof(LOOP_NAME"0")] = LOOP_NAME"0"; char c; for (c = '0'; c <= '9'; ++c) { char *s; dev[sizeof(LOOP_NAME"0")-2] = c; s = query_loop(dev); if (s) { printf("%s: %s\n", dev, s); if (ENABLE_FEATURE_CLEAN_UP) free(s); } } } return EXIT_SUCCESS; }
void get_events(void) { SDL_Event event; while (SDL_PollEvent(&event)) { /** Get user events */ switch (event.type) { case SDL_QUIT: /** User quit the application. */ set_loop(false); break; case SDL_KEYDOWN: if (event.key.keysym.sym == SDLK_ESCAPE) { set_loop(false); break; } } } return; }
/** Constructor. * @param addr_type Specify IPv4 or IPv6 * @param multicast_addr_s textual representation of the multicast IP address * to use for multicast communication. NOT a hostname! * @param port port * @param timeout timeout, if 0 all operationsare blocking, otherwise it * is tried for timeout seconds. */ MulticastDatagramSocket::MulticastDatagramSocket(AddrType addr_type, const char *multicast_addr_s, unsigned short port, float timeout) : Socket(addr_type, UDP, timeout) { multicast_addr = (struct ::sockaddr_in *)malloc(sizeof(struct ::sockaddr_in)); struct in_addr a; if ( inet_aton(multicast_addr_s, &a) == -1 ) { throw SocketException("Invalid address given"); } multicast_addr->sin_family = AF_INET; multicast_addr->sin_addr.s_addr = a.s_addr; multicast_addr->sin_port = htons(port); //set_ttl(1); set_loop(false); }
/** Constructor. * @param broadcast_addr_s textual representation of the broadcast IP address * to use for broadcast communication. NOT a hostname! * @param port port * @param timeout timeout, if 0 all operationsare blocking, otherwise it * is tried for timeout seconds. */ BroadcastDatagramSocket::BroadcastDatagramSocket(const char *broadcast_addr_s, unsigned short port, float timeout) : Socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP, timeout) { broadcast_addr = (struct ::sockaddr_in *)malloc(sizeof(struct ::sockaddr_in)); struct in_addr a; if ( inet_aton(broadcast_addr_s, &a) == -1 ) { throw SocketException("Invalid address given"); } broadcast_addr->sin_family = AF_INET; broadcast_addr->sin_addr.s_addr = a.s_addr; broadcast_addr->sin_port = htons(port); #if 0 //set_ttl(1); set_loop(false); #endif }
bool PathFollow2D::_set(const StringName& p_name, const Variant& p_value) { if (p_name==SceneStringNames::get_singleton()->offset) { set_offset(p_value); } else if (p_name==SceneStringNames::get_singleton()->unit_offset) { set_unit_offset(p_value); } else if (p_name==SceneStringNames::get_singleton()->rotate) { set_rotate(p_value); } else if (p_name==SceneStringNames::get_singleton()->v_offset) { set_v_offset(p_value); } else if (p_name==SceneStringNames::get_singleton()->h_offset) { set_h_offset(p_value); } else if (String(p_name)=="cubic_interp") { set_cubic_interpolation(p_value); } else if (String(p_name)=="loop") { set_loop(p_value); } else if (String(p_name)=="lookahead") { set_lookahead(p_value); } else return false; return true; }
int losetup_main (int argc, char **argv) { int offset = 0; /* This will need a "while(getopt()!=-1)" loop when we can have more than one option, but for now we can't. */ switch(getopt(argc,argv, "do:")) { case 'd': /* detach takes exactly one argument */ if(optind+1!=argc) bb_show_usage(); if(!del_loop(argv[optind])) return EXIT_SUCCESS; die_failed: bb_perror_msg_and_die("%s",argv[optind]); case 'o': offset = bb_xparse_number (optarg, NULL); /* Fall through to do the losetup */ case -1: /* losetup takes two argument:, loop_device and file */ if(optind+2==argc) { if(set_loop(&argv[optind], argv[optind + 1], offset)>=0) return EXIT_SUCCESS; else goto die_failed; } if(optind+1==argc) { char *s=query_loop(argv[optind]); if (!s) goto die_failed; printf("%s: %s\n",argv[optind],s); if(ENABLE_FEATURE_CLEAN_UP) free(s); return EXIT_SUCCESS; } break; } bb_show_usage(); return EXIT_FAILURE; }
int main(int argc, char **argv){ int fd, i, j, m, n, op, off, arg, c, d; struct slice all; struct pt *ptp; enum action what = LIST; char *type, *diskdevice, *device, *progname; int verbose = 0; char partname[PARTNAME_SIZE], params[PARTNAME_SIZE + 16]; char * loopdev = NULL; char * delim = NULL; char *uuid = NULL; char *mapname = NULL; int loopro = 0; int hotplug = 0; int loopcreated = 0; int sync = 0; struct stat buf; uint32_t cookie = 0; initpts(); init_crc32(); type = device = diskdevice = NULL; memset(&all, 0, sizeof(all)); memset(&partname, 0, sizeof(partname)); /* Check whether hotplug mode. */ progname = strrchr(argv[0], '/'); if (!progname) progname = argv[0]; else progname++; if (!strcmp(progname, "kpartx.dev")) { /* Hotplug mode */ hotplug = 1; /* Setup for original kpartx variables */ if (!(device = get_hotplug_device())) exit(1); diskdevice = device; what = ADD; } else if (argc < 2) { usage(); exit(1); } while ((arg = getopt(argc, argv, short_opts)) != EOF) switch(arg) { case 'g': force_gpt=1; break; case 't': type = optarg; break; case 'v': verbose = 1; break; case 'p': delim = optarg; break; case 'l': what = LIST; break; case 'a': what = ADD; break; case 'd': what = DELETE; break; case 's': sync = 1; break; default: usage(); exit(1); } if (!sync) dm_udev_set_sync_support(0); if (dm_prereq(DM_TARGET, 0, 0, 0) && (what == ADD || what == DELETE)) { fprintf(stderr, "device mapper prerequisites not met\n"); exit(1); } if (hotplug) { /* already got [disk]device */ } else if (optind == argc-2) { device = argv[optind]; diskdevice = argv[optind+1]; } else if (optind == argc-1) { diskdevice = device = argv[optind]; } else { usage(); exit(1); } if (stat(device, &buf)) { printf("failed to stat() %s\n", device); exit (1); } if (S_ISREG (buf.st_mode)) { /* already looped file ? */ loopdev = find_loop_by_file(device); if (!loopdev && what == DELETE) exit (0); if (!loopdev) { loopdev = find_unused_loop_device(); if (set_loop(loopdev, device, 0, &loopro)) { fprintf(stderr, "can't set up loop\n"); exit (1); } loopcreated = 1; } device = loopdev; } if (delim == NULL) { delim = malloc(DELIM_SIZE); memset(delim, 0, DELIM_SIZE); set_delimiter(device, delim); } off = find_devname_offset(device); if (!loopdev) { uuid = dm_mapuuid((unsigned int)MAJOR(buf.st_rdev), (unsigned int)MINOR(buf.st_rdev)); mapname = dm_mapname((unsigned int)MAJOR(buf.st_rdev), (unsigned int)MINOR(buf.st_rdev)); } if (!uuid) uuid = device + off; if (!mapname) mapname = device + off; fd = open(device, O_RDONLY); if (fd == -1) { perror(device); exit(1); } /* add/remove partitions to the kernel devmapper tables */ int r = 0; for (i = 0; i < ptct; i++) { ptp = &pts[i]; if (type && strcmp(type, ptp->type)) continue; /* here we get partitions */ n = ptp->fn(fd, all, slices, SIZE(slices)); #ifdef DEBUG if (n >= 0) printf("%s: %d slices\n", ptp->type, n); #endif if (n > 0) close(fd); else continue; switch(what) { case LIST: for (j = 0, c = 0, m = 0; j < n; j++) { if (slices[j].size == 0) continue; if (slices[j].container > 0) { c++; continue; } slices[j].minor = m++; printf("%s%s%d : 0 %" PRIu64 " %s %" PRIu64"\n", mapname, delim, j+1, slices[j].size, device, slices[j].start); } /* Loop to resolve contained slices */ d = c; while (c) { for (j = 0; j < n; j++) { uint64_t start; int k = slices[j].container - 1; if (slices[j].size == 0) continue; if (slices[j].minor > 0) continue; if (slices[j].container == 0) continue; slices[j].minor = m++; start = slices[j].start - slices[k].start; printf("%s%s%d : 0 %" PRIu64 " /dev/dm-%d %" PRIu64 "\n", mapname, delim, j+1, slices[j].size, slices[k].minor, start); c--; } /* Terminate loop if nothing more to resolve */ if (d == c) break; } if (loopcreated && S_ISREG (buf.st_mode)) { if (del_loop(device)) { if (verbose) printf("can't del loop : %s\n", device); exit(1); } printf("loop deleted : %s\n", device); } break; case DELETE: for (j = n-1; j >= 0; j--) { if (safe_sprintf(partname, "%s%s%d", mapname, delim, j+1)) { fprintf(stderr, "partname too small\n"); exit(1); } strip_slash(partname); if (!slices[j].size || !dm_map_present(partname)) continue; if (!dm_simplecmd(DM_DEVICE_REMOVE, partname, 0, &cookie)) { r++; continue; } if (verbose) printf("del devmap : %s\n", partname); } if (S_ISREG (buf.st_mode)) { if (del_loop(device)) { if (verbose) printf("can't del loop : %s\n", device); exit(1); } printf("loop deleted : %s\n", device); } break; case ADD: for (j = 0, c = 0; j < n; j++) { if (slices[j].size == 0) continue; /* Skip all contained slices */ if (slices[j].container > 0) { c++; continue; } if (safe_sprintf(partname, "%s%s%d", mapname, delim, j+1)) { fprintf(stderr, "partname too small\n"); exit(1); } strip_slash(partname); if (safe_sprintf(params, "%s %" PRIu64 , device, slices[j].start)) { fprintf(stderr, "params too small\n"); exit(1); } op = (dm_map_present(partname) ? DM_DEVICE_RELOAD : DM_DEVICE_CREATE); if (!dm_addmap(op, partname, DM_TARGET, params, slices[j].size, uuid, j+1, buf.st_mode & 0777, buf.st_uid, buf.st_gid, &cookie)) { fprintf(stderr, "create/reload failed on %s\n", partname); r++; } if (op == DM_DEVICE_RELOAD && !dm_simplecmd(DM_DEVICE_RESUME, partname, 1, &cookie)) { fprintf(stderr, "resume failed on %s\n", partname); r++; } dm_devn(partname, &slices[j].major, &slices[j].minor); if (verbose) printf("add map %s (%d:%d): 0 %" PRIu64 " %s %s\n", partname, slices[j].major, slices[j].minor, slices[j].size, DM_TARGET, params); } /* Loop to resolve contained slices */ d = c; while (c) { for (j = 0; j < n; j++) { uint64_t start; int k = slices[j].container - 1; if (slices[j].size == 0) continue; /* Skip all existing slices */ if (slices[j].minor > 0) continue; /* Skip all simple slices */ if (slices[j].container == 0) continue; /* Check container slice */ if (slices[k].size == 0) fprintf(stderr, "Invalid slice %d\n", k); if (safe_sprintf(partname, "%s%s%d", mapname, delim, j+1)) { fprintf(stderr, "partname too small\n"); exit(1); } strip_slash(partname); start = slices[j].start - slices[k].start; if (safe_sprintf(params, "%d:%d %" PRIu64, slices[k].major, slices[k].minor, start)) { fprintf(stderr, "params too small\n"); exit(1); } op = (dm_map_present(partname) ? DM_DEVICE_RELOAD : DM_DEVICE_CREATE); dm_addmap(op, partname, DM_TARGET, params, slices[j].size, uuid, j+1, buf.st_mode & 0777, buf.st_uid, buf.st_gid, &cookie); if (op == DM_DEVICE_RELOAD) dm_simplecmd(DM_DEVICE_RESUME, partname, 1, &cookie); dm_devn(partname, &slices[j].major, &slices[j].minor); if (verbose) printf("add map %s : 0 %" PRIu64 " %s %s\n", partname, slices[j].size, DM_TARGET, params); c--; } /* Terminate loop */ if (d == c) break; } break; default: break; } if (n > 0) break; } dm_udev_wait(cookie); dm_lib_release(); dm_lib_exit(); return r; }
void get_events(int16_t *mouse_x, int16_t *mouse_y) { SDL_Event event; while (SDL_PollEvent(&event)) { /** Get user events. **/ switch(event.type) { case SDL_QUIT: /** User press the cross to close the application. **/ quit_game=true ; set_loop(false) ; break; case SDL_KEYDOWN : if (event.key.keysym.scancode == SDL_SCANCODE_ESCAPE) { /** The user fallback to the previous screen. **/ set_loop(false) ; break ; } case SDL_MOUSEMOTION : *mouse_x = event.motion.x ; /** We keep the mouse position at everytime in the game. **/ *mouse_y = event.motion.y ; /** We keep the mouse position at everytime in the game. **/ if ( ! game_control->is_animation_running && game_control->GAME_STATUS != DRAG_CARD_ON && game_control->GAME_STATUS != GAME_START ) { if ( mouse_over_card(event.motion.x,event.motion.y) != -1 && ! game_control->is_animation_running ) { /** The mouse is over an card. **/ if ( game_control->cursor_type != SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_HAND) ) { /** We set the cursor to an hand cursor to notify the user that he can return or drag-and-drop the card. **/ game_control->cursor_type = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_HAND) ; SDL_SetCursor(game_control->cursor_type) ; game_control->mouse_over_card=true ; } } else { if ( game_control->cursor_type != SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_ARROW) && ! game_control->is_animation_running && ! is_mouse_in_buttons_bboxes(event.motion.x) ) { /** We reset the cursor to default. **/ game_control->cursor_type = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_ARROW) ; SDL_SetCursor(game_control->cursor_type) ; game_control->mouse_over_card=false ; } } } if ( ! game_control->is_animation_running ) { /** The mouse is over an button. **/ mouse_over_button(event.motion.x,event.motion.y) ; break ; } break ; case SDL_MOUSEBUTTONDOWN : if (event.button.button == SDL_BUTTON_LEFT && event.button.state == SDL_PRESSED) { int8_t ret ; if ( ! game_control->is_animation_running && ((ret=mouse_over_card(event.button.x,event.button.y)) != -1) ) { if (game_control->player[ret].is_back_faced) { /** We process an card returning aniation. **/ current_card = &game_control->player[ret] ; game_control->GAME_STATUS = RETURN_A_CARD ; break ; } else if (! game_control->player[ret].is_back_faced && game_control->GAME_STATUS != DRAG_CARD_ON) { /** The user can drag an card. **/ dragging_card->card = &game_control->player[ret] ; dragging_card->x = event.button.x - game_control->player[ret].x ; dragging_card->y = event.button.y - game_control->player[ret].y ; game_control->player[ret].is_moving = true ; game_control->GAME_STATUS = DRAG_CARD_ON ; game_control->cursor_type = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZEALL) ; SDL_SetCursor(game_control->cursor_type) ; break ; } } else if ( ! game_control->is_animation_running && (ret = press_button(event.button.x,event.button.y)) != -1 ) { /** The user press an button which is allowed. **/ do_change_game_status(ret) ; break ; } } case SDL_MOUSEBUTTONUP : if ( game_control->GAME_STATUS == DRAG_CARD_ON) { /** The user release an card he is dragging, so we process. **/ game_control->GAME_STATUS = DRAG_CARD_OFF ; game_control->cursor_type = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_ARROW) ; SDL_SetCursor(game_control->cursor_type) ; } break ; } } return ; }
int main(void) { /** SDL2 initialized: */ if (sdl_init(SDL_INIT_VIDEO) != 0) { fprintf(stdout, "SDL initialize failed (%s)\n", SDL_GetError()); exit(EXIT_FAILURE); } /** Window creation: */ SDL_Window *pWindow = NULL; pWindow = sdl_create_window("Balls", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, WIDTH, HEIGHT, SDL_WINDOW_SHOWN); if (pWindow == NULL) { fprintf(stderr, "Windows creation error: (%s)\n", SDL_GetError()); exit(EXIT_FAILURE); } /** Renderer creation. */ SDL_Renderer *pRenderer; if ((pRenderer = sdl_create_renderer(pWindow, -1, SDL_RENDERER_ACCELERATED)) == NULL) { fprintf(stderr, "SDL Renderer creating error (%s)\n", SDL_GetError()); exit(EXIT_FAILURE); } /** Random seed initialized. **/ struct timeval tv; gettimeofday(&tv, NULL); srand((unsigned int) tv.tv_usec); /** Define the balls and initialized the balls. **/ Ball *red_ball = init_ball('r'); Ball *green_ball = init_ball('g'); Ball *blue_ball = init_ball('b'); Ball *yellow_ball = init_ball('y'); Ball *pink_ball = init_ball('p'); Ball *turquoise_ball = init_ball('t'); const int FPS = 90; const int FRAME_DELAY = 1000 / FPS; set_loop(true); while (loop) { /** SDL2 mainloop. **/ int frame_start = SDL_GetTicks(); /** Check if a ball collide the border rounded box: **/ check_collide_borders(red_ball); check_collide_borders(green_ball); check_collide_borders(blue_ball); check_collide_borders(yellow_ball); check_collide_borders(pink_ball); check_collide_borders(turquoise_ball); /** Increment the balls positions: **/ translate_ball(red_ball); translate_ball(green_ball); translate_ball(blue_ball); translate_ball(yellow_ball); translate_ball(pink_ball); translate_ball(turquoise_ball); clear(pRenderer, 127, 127, 127, 127); /** Displaying the interior black boxe using a SDL2_gfx function. **/ boxRGBA(pRenderer, 32, 32, WIDTH - 32, HEIGHT - 32, 0, 0, 0, 255); /** Display the balls: **/ display_ball(pRenderer, red_ball); display_ball(pRenderer, green_ball); display_ball(pRenderer, blue_ball); display_ball(pRenderer, yellow_ball); display_ball(pRenderer, pink_ball); display_ball(pRenderer, turquoise_ball); display(pRenderer); update(pWindow); get_events(); int frame_end = SDL_GetTicks() - frame_start; if (frame_end < FRAME_DELAY) { SDL_Delay(FRAME_DELAY - frame_end); } } free_ball(red_ball); free_ball(green_ball); free_ball(blue_ball); free_ball(yellow_ball); free_ball(pink_ball); free_ball(turquoise_ball); clean_up(pRenderer, pWindow); SDL_Quit(); exit(EXIT_SUCCESS); }
static int do_mount(char *specialfile, char *dir, char *filesystemtype, long flags, void *string_flags, int useMtab, int fakeIt, char *mtab_opts, int mount_all) { int status = 0; #if defined BB_FEATURE_MOUNT_LOOP char *lofile = NULL; #endif if (! fakeIt) { #if defined BB_FEATURE_MOUNT_LOOP if (use_loop==TRUE) { int loro = flags & MS_RDONLY; lofile = specialfile; specialfile = find_unused_loop_device(); if (specialfile == NULL) { error_msg_and_die("Could not find a spare loop device"); } if (set_loop(specialfile, lofile, 0, &loro)) { error_msg_and_die("Could not setup loop device"); } if (!(flags & MS_RDONLY) && loro) { /* loop is ro, but wanted rw */ error_msg("WARNING: loop device is read-only"); flags |= MS_RDONLY; } } #endif status = mount(specialfile, dir, filesystemtype, flags, string_flags); if (status < 0 && errno == EROFS) { error_msg("%s is write-protected, mounting read-only", specialfile); status = mount(specialfile, dir, filesystemtype, flags |= MS_RDONLY, string_flags); } /* Don't whine about already mounted filesystems when mounting all. */ if (status < 0 && errno == EBUSY && mount_all) return TRUE; } /* If the mount was sucessful, do anything needed, then return TRUE */ if (status == 0 || fakeIt==TRUE) { #if defined BB_FEATURE_MTAB_SUPPORT if (useMtab) { erase_mtab(specialfile); // Clean any stale entries write_mtab(specialfile, dir, filesystemtype, flags, mtab_opts); } #endif return (TRUE); } /* Bummer. mount failed. Clean up */ #if defined BB_FEATURE_MOUNT_LOOP if (lofile != NULL) { del_loop(specialfile); } #endif if (errno == EPERM) { error_msg_and_die("permission denied. Are you root?"); } return (FALSE); }
int do_mount (char *source, char *target, char *fstype, long flags, int fakeIt, int mountall, int loop) { int ret = 0; char *loopfile = NULL; if (source == NULL || target == NULL || fstype == NULL) { printf("%s:%d: invalid settings.\n", __FUNCTION__, __LINE__); return 1; } if (!fakeIt) { if (loop) { int loro = flags & MS_RDONLY; loopfile = strdup(source); source = find_unused_loop_device(); if (!source) { printf("Find spare loop device failed.\n"); if (loopfile != NULL) { free(loopfile); loopfile = NULL;} return 1; } if (set_loop(source, loopfile, 0, &loro)) { if (loopfile != NULL) { free(loopfile); loopfile = NULL;} return 1; } if (!(flags & MS_RDONLY) && !loro) { flags |= MS_RDONLY; } } ret = mount(source, target, fstype, flags, NULL); if (ret < 0) { perror("Mount fail"); fprintf(stderr, "%s:%d, mount %s on %s fail\n", __FUNCTION__, __LINE__, source, target); } if (ret < 0 && errno == EROFS) { printf("%s is write-protected, mounting read-only.\n", source); ret = mount(source, target, fstype, flags |= MS_RDONLY, NULL); } /* Don't whine about already mounted filesystems when mounting all. */ if (ret < 0 && errno == EBUSY && mountall) { if (loopfile != NULL) { free(loopfile); loopfile = NULL;} return 0; } } if (ret == 0 || fakeIt == 1) { if (loop) { if (g_LoopData == NULL) { g_LoopData = malloc(sizeof(LOOP_DATA) * MAX_LOOP_DATA); if (g_LoopData) { memset(g_LoopData,0,sizeof(LOOP_DATA) * MAX_LOOP_DATA); } } if (g_LoopData) { // we need to save it for umount int k,loopfile_len; for (k=0;k<MAX_LOOP_DATA;k++) { if (g_LoopData[k].source == NULL) { g_LoopData[k].source = source; //we need to free it when we do umount g_LoopData[k].target = strdup(target); loopfile_len = strlen(loopfile) + 1; g_LoopData[k].orgfile = malloc(loopfile_len); strncpy(g_LoopData[k].orgfile,loopfile,loopfile_len); printf("save loop data(%d) source : %s target : %s\n",k,g_LoopData[k].source,g_LoopData[k].target); break; } } } } if (loopfile != NULL) { free(loopfile); loopfile = NULL;} return 0; } if (loopfile != NULL) { del_loop(source); free(source); if (loopfile != NULL) { free(loopfile); loopfile = NULL;} } if (ret == EPERM) { printf("You don't have enough permission.\n"); } return 1; }
int main (int argc, char **argv) { FILE *file; DIR *dir; struct dirent *dev; char imagefile[BUF_MAX]; char configuuid[BUF_MAX]; char imageuuid[BUF_MAX]; char cmdline[BUF_MAX]; char devname[BUF_MAX]; char uuid[BUF_MAX]; char *value; off_t offset; struct monoimage_header bi_header; struct stat s; fprintf(stderr, "MI: linuxrc starting...\n"); /* mount proc */ if ( mount("proc", "/proc", "proc", 0, NULL) < 0 ) { fprintf(stderr, "mount /proc: %s\n", strerror(errno)); DIE; } /* open /proc/cmdline, read image filename */ if ( (file = fopen("/proc/cmdline", "r")) == NULL ) { fprintf(stderr, "/proc/cmdline: open: %s\n", strerror(errno)); DIE; } if ( fgets(cmdline, BUF_MAX, file) == NULL ) { fprintf(stderr, "read /proc/cmdline: %s\n", strerror(errno)); DIE; } fclose(file); /* parse out actual image filename and image/config devices */ if ((value = get_cmdline_var(cmdline, "F")) != NULL) { strcpy(imagefile, "/images/"); strcat(imagefile, value); } else { fprintf(stderr, "no F in cmdline\n"); DIE; } if ((value = get_cmdline_var(cmdline, "I")) != NULL) { strcpy(imageuuid, value); } else { fprintf(stderr, "no I in cmdline\n"); DIE; } if ((value = get_cmdline_var(cmdline, "C")) != NULL) { strcpy(configuuid, value); } else { fprintf(stderr, "no C in cmdline\n"); DIE; } fprintf(stderr, "MI: image file: %s\n", imagefile); fprintf(stderr, "MI: image uuid: %s\n", imageuuid); fprintf(stderr, "MI: config uuid: %s\n", configuuid); /* walk /dev looking for the uuid we're interested in */ dir = opendir("/dev"); if (dir == NULL) { fprintf(stderr, "opendir /dev: %s\n", strerror(errno)); DIE; } while ( ( dev = readdir(dir) ) ) { strncpy(devname, "/dev/", 6); strncat(devname, dev->d_name, strlen(dev->d_name)); if (stat(devname, &s) == 0 && S_ISBLK(s.st_mode)) { strcpy(uuid, ext2_uuid(devname)); if (strcmp(imageuuid, uuid) == 0) { /* mount this device on /images */ fprintf(stderr, "MI: mounting %s on /images\n", devname); if ( mount (devname, "/images", "ext3", 0, NULL) < 0 ) { fprintf(stderr, "mount /images: %s\n", strerror(errno)); DIE; } else { goto DONE; } } } } DONE: /* check we can find the image file */ if ( stat (imagefile, &s) != 0 ) { fprintf(stderr, "stat %s failed: %s\n", imagefile, strerror(errno)); /* * try the failsafe image, which * should be /failsafe.img on FS_DEV * (umount /images first..) */ strcpy(imagefile, "/images/"); strcat(imagefile, FS_IMG); if ( umount2("/images",0) != 0) { fprintf(stderr, "umount /images failed: %s\n", strerror(errno)); /* don't die, it might fail to umount 'cos the previous mount failed */ } if ( mount (FS_DEV, "/images", "ext3", 0, NULL) < 0 ) { fprintf(stderr, "mount failsafe /images: %s\n", strerror(errno)); DIE; } if ( stat (imagefile, &s) != 0 ) { fprintf(stderr, "stat failsafe image %s failed: %s\n", imagefile, strerror(errno)); DIE; } fprintf(stderr, "using failsafe image %s\n", imagefile); } /* read header from /images/%s, get rootfs offset */ if ( (file = fopen(imagefile, "r")) == NULL ) { fprintf(stderr, "%s: open: %s\n", imagefile, strerror(errno)); DIE; } if ( fread(&bi_header, sizeof(bi_header), 1, file) != 1 ) { fprintf(stderr, "read %s: %s\n", imagefile, strerror(errno)); DIE; } offset = bi_header.rootfs_offset; fprintf(stderr, "MI: root filesystem at %ld\n", offset); /* losetup image on /dev/loop0 */ if( set_loop("/dev/loop0", imagefile, offset) < 0 ) { fprintf(stderr, "set_loop: %s\n", strerror(errno)); DIE; } /* success! */ exit(0); }
// Mount one directory. Handles CIFS, NFS, loopback, autobind, and filesystem // type detection. Returns 0 for success, nonzero for failure. // NB: mp->xxx fields may be trashed on exit static int singlemount(struct mntent *mp, int ignore_busy) { int rc = -1, vfsflags; char *loopFile = 0, *filteropts = 0; llist_t *fl = 0; struct stat st; vfsflags = parse_mount_options(mp->mnt_opts, &filteropts); // Treat fstype "auto" as unspecified. if (mp->mnt_type && strcmp(mp->mnt_type,"auto") == 0) mp->mnt_type = 0; // Might this be an CIFS filesystem? if (ENABLE_FEATURE_MOUNT_CIFS && (!mp->mnt_type || strcmp(mp->mnt_type,"cifs") == 0) && (mp->mnt_fsname[0]=='/' || mp->mnt_fsname[0]=='\\') && mp->mnt_fsname[0]==mp->mnt_fsname[1] ) { len_and_sockaddr *lsa; char *ip, *dotted; char *s; rc = 1; // Replace '/' with '\' and verify that unc points to "//server/share". for (s = mp->mnt_fsname; *s; ++s) if (*s == '/') *s = '\\'; // get server IP s = strrchr(mp->mnt_fsname, '\\'); if (s <= mp->mnt_fsname+1) goto report_error; *s = '\0'; lsa = host2sockaddr(mp->mnt_fsname+2, 0); *s = '\\'; if (!lsa) goto report_error; // insert ip=... option into string flags. dotted = xmalloc_sockaddr2dotted_noport(&lsa->sa, lsa->len); ip = xasprintf("ip=%s", dotted); parse_mount_options(ip, &filteropts); // compose new unc '\\server-ip\share' // (s => slash after hostname) mp->mnt_fsname = xasprintf("\\\\%s%s", dotted, s); // lock is required vfsflags |= MS_MANDLOCK; mp->mnt_type = (char*)"cifs"; rc = mount_it_now(mp, vfsflags, filteropts); if (ENABLE_FEATURE_CLEAN_UP) { free(mp->mnt_fsname); free(ip); free(dotted); free(lsa); } goto report_error; } // Might this be an NFS filesystem? if (ENABLE_FEATURE_MOUNT_NFS && (!mp->mnt_type || !strcmp(mp->mnt_type,"nfs")) && strchr(mp->mnt_fsname, ':') != NULL ) { rc = nfsmount(mp, vfsflags, filteropts); goto report_error; } // Look at the file. (Not found isn't a failure for remount, or for // a synthetic filesystem like proc or sysfs.) // (We use stat, not lstat, in order to allow // mount symlink_to_file_or_blkdev dir) if (!stat(mp->mnt_fsname, &st) && !(vfsflags & (MS_REMOUNT | MS_BIND | MS_MOVE)) ) { // Do we need to allocate a loopback device for it? if (ENABLE_FEATURE_MOUNT_LOOP && S_ISREG(st.st_mode)) { loopFile = bb_simplify_path(mp->mnt_fsname); mp->mnt_fsname = 0; switch (set_loop(&(mp->mnt_fsname), loopFile, 0)) { case 0: case 1: break; default: bb_error_msg( errno == EPERM || errno == EACCES ? bb_msg_perm_denied_are_you_root : "cannot setup loop device"); return errno; } // Autodetect bind mounts } else if (S_ISDIR(st.st_mode) && !mp->mnt_type) vfsflags |= MS_BIND; } /* If we know the fstype (or don't need to), jump straight * to the actual mount. */ if (mp->mnt_type || (vfsflags & (MS_REMOUNT | MS_BIND | MS_MOVE))) rc = mount_it_now(mp, vfsflags, filteropts); else { // Loop through filesystem types until mount succeeds // or we run out /* Initialize list of block backed filesystems. This has to be * done here so that during "mount -a", mounts after /proc shows up * can autodetect. */ if (!fslist) { fslist = get_block_backed_filesystems(); if (ENABLE_FEATURE_CLEAN_UP && fslist) atexit(delete_block_backed_filesystems); } for (fl = fslist; fl; fl = fl->link) { mp->mnt_type = fl->data; rc = mount_it_now(mp, vfsflags, filteropts); if (!rc) break; } } // If mount failed, clean up loop file (if any). if (ENABLE_FEATURE_MOUNT_LOOP && rc && loopFile) { del_loop(mp->mnt_fsname); if (ENABLE_FEATURE_CLEAN_UP) { free(loopFile); free(mp->mnt_fsname); } } report_error: if (ENABLE_FEATURE_CLEAN_UP) free(filteropts); if (rc && errno == EBUSY && ignore_busy) rc = 0; if (rc < 0) /* perror here sometimes says "mounting ... on ... failed: Success" */ bb_error_msg("mounting %s on %s failed", mp->mnt_fsname, mp->mnt_dir); return rc; }
int load_game(char* s) { int i, ver, vt_entries = MAX_VIEWTABLE; UINT8 t; SINT16 parm[7]; char sig[8]; char id[8]; char description[256]; FILE *f = fopen(s, "rb"); if(!f) return err_BadFileOpen; read_bytes(f, sig, 8); if (strncmp (sig, strSig, 8)) { fclose(f); return err_BadFileOpen; } read_string (f, description); ver = read_uint8(f); if (ver == 0) vt_entries = 64; game.state = read_uint8(f); /* game.name - not saved */ read_string(f, id); if(strcmp(id, game.id)) { fclose(f); return err_BadFileOpen; } /* game.crc - not saved */ for (i = 0; i < MAX_FLAGS; i++) game.flags[i] = read_uint8(f); for (i = 0; i < MAX_VARS; i++) game.vars[i] = read_uint8(f); game.horizon = read_sint16(f); game.line_status = read_sint16(f); game.line_user_input = read_sint16(f); game.line_min_print = read_sint16(f); /* These are never saved */ game.cursor_pos = 0; game.input_buffer[0] = 0; game.echo_buffer[0] = 0; game.keypress = 0; game.input_mode = read_sint16(f); game.lognum = read_sint16(f); game.player_control = read_sint16(f); game.quit_prog_now = read_sint16(f); game.status_line = read_sint16(f); game.clock_enabled = read_sint16(f); game.exit_all_logics = read_sint16(f); game.picture_shown = read_sint16(f); game.has_prompt = read_sint16(f); game.game_flags = read_sint16(f); game.input_enabled = !read_sint16(f); for (i = 0; i < _HEIGHT; i++) game.pri_table[i] = read_uint8(f); if(game.has_window) close_window(); game.msg_box_ticks = 0; game.block.active = FALSE; /* game.window - fixed by close_window() */ /* game.has_window - fixed by close_window() */ game.gfx_mode = read_sint16(f); game.cursor_char = read_uint8(f); game.color_fg = read_sint16(f); game.color_bg = read_sint16(f); /* game.hires (#ifdef USE_HIRES) - rebuilt from image stack */ /* game.sbuf - rebuilt from image stack */ /* game.ego_words - fixed by clean_input */ /* game.num_ego_words - fixed by clean_input */ game.num_objects = read_sint16(f); for(i = 0; i < (SINT16)game.num_objects; i++) object_set_location(i, read_sint16(f)); /* Those are not serialized */ for (i = 0; i < MAX_DIRS; i++) { game.ev_keyp[i].occured = FALSE; } for (i = 0; i < MAX_STRINGS; i++) read_string (f, game.strings[i]); for (i = 0; i < MAX_DIRS; i++) { if(read_uint8(f) & RES_LOADED) agi_load_resource (rLOGIC, i); else agi_unload_resource (rLOGIC, i); game.logics[i].sIP = read_sint16(f); game.logics[i].cIP = read_sint16(f); } for (i = 0; i < MAX_DIRS; i++) { if(read_uint8(f) & RES_LOADED) agi_load_resource(rPICTURE, i); else agi_unload_resource(rPICTURE, i); } for (i = 0; i < MAX_DIRS; i++) { if(read_uint8(f) & RES_LOADED) agi_load_resource(rVIEW, i); else agi_unload_resource(rVIEW, i); } for(i = 0; i < MAX_DIRS; i++) { if(read_uint8(f) & RES_LOADED) agi_load_resource(rSOUND, i); else agi_unload_resource(rSOUND, i); } /* game.pictures - loaded above */ /* game.logics - loaded above */ /* game.views - loaded above */ /* game.sounds - loaded above */ for (i = 0; i < vt_entries; i++) { struct vt_entry* v = &game.view_table[i]; v->step_time = read_uint8(f); v->step_time_count = read_uint8(f); v->entry = read_uint8(f); v->x_pos = read_sint16(f); v->y_pos = read_sint16(f); v->current_view = read_uint8(f); /* v->view_data - fixed below */ v->current_loop = read_uint8(f); v->num_loops = read_uint8(f); /* v->loop_data - fixed below */ v->current_cel = read_uint8(f); v->num_cels = read_uint8(f); /* v->cel_data - fixed below */ /* v->cel_data_2 - fixed below */ v->x_pos2 = read_sint16(f); v->y_pos2 = read_sint16(f); /* v->s - fixed below */ v->x_size = read_sint16(f); v->y_size = read_sint16(f); v->step_size = read_uint8(f); v->cycle_time = read_uint8(f); v->cycle_time_count = read_uint8(f); v->direction = read_uint8(f); v->motion = read_uint8(f); v->cycle = read_uint8(f); v->priority = read_uint8(f); v->flags = read_uint16(f); v->parm1 = read_uint8(f); v->parm2 = read_uint8(f); v->parm3 = read_uint8(f); v->parm4 = read_uint8(f); } for (i = vt_entries; i < MAX_VIEWTABLE; i++) { memset (&game.view_table[i], 0, sizeof (struct vt_entry)); } /* Fix some pointers in viewtable */ for (i = 0; i < MAX_VIEWTABLE; i++) { struct vt_entry* v = &game.view_table[i]; if(game.dir_view[v->current_view].offset == _EMPTY) continue; if(!(game.dir_view[v->current_view].flags & RES_LOADED)) agi_load_resource(rVIEW, v->current_view); set_view(v, v->current_view); /* Fix v->view_data */ set_loop(v, v->current_loop); /* Fix v->loop_data */ set_cel(v, v->current_cel); /* Fix v->cel_data */ v->cel_data_2 = v->cel_data; v->s = NULL; /* not sure if it is used... */ } erase_both(); /* Clear input line */ clear_screen(0); write_status(); /* Recreate background from saved image stack */ clear_image_stack(); while ((t = read_uint8(f)) != 0) { for (i = 0; i < 7; i++) parm[i] = read_sint16(f); replay_image_stack_call (t, parm[0], parm[1], parm[2], parm[3], parm[4], parm[5], parm[6]); } fclose(f); setflag(F_restore_just_ran, TRUE); game.has_prompt = 0; /* force input line repaint if necessary*/ clean_input(); erase_both(); blit_both(); commit_both(); show_pic(); do_update(); return err_OK; }
static int singlemount(struct mntent *mp, int ignore_busy) { int rc = -1, vfsflags; char *loopFile = 0, *filteropts = 0; llist_t *fl = 0; struct stat st; vfsflags = parse_mount_options(mp->mnt_opts, &filteropts); // Treat fstype "auto" as unspecified. if (mp->mnt_type && !strcmp(mp->mnt_type,"auto")) mp->mnt_type = 0; // Might this be an NFS filesystem? if (ENABLE_FEATURE_MOUNT_NFS && (!mp->mnt_type || !strcmp(mp->mnt_type,"nfs")) && strchr(mp->mnt_fsname, ':') != NULL) { if (nfsmount(mp->mnt_fsname, mp->mnt_dir, &vfsflags, &filteropts, 1)) { bb_perror_msg("nfsmount failed"); goto report_error; } else { // Strangely enough, nfsmount() doesn't actually mount() anything. mp->mnt_type = "nfs"; rc = mount_it_now(mp, vfsflags, filteropts); if (ENABLE_FEATURE_CLEAN_UP) free(filteropts); goto report_error; } } // Look at the file. (Not found isn't a failure for remount, or for // a synthetic filesystem like proc or sysfs.) if (stat(mp->mnt_fsname, &st)); else if (!(vfsflags & (MS_REMOUNT | MS_BIND | MS_MOVE))) { // Do we need to allocate a loopback device for it? if (ENABLE_FEATURE_MOUNT_LOOP && S_ISREG(st.st_mode)) { loopFile = bb_simplify_path(mp->mnt_fsname); mp->mnt_fsname = 0; switch(set_loop(&(mp->mnt_fsname), loopFile, 0)) { case 0: case 1: break; default: bb_error_msg( errno == EPERM || errno == EACCES ? bb_msg_perm_denied_are_you_root : "Couldn't setup loop device"); return errno; } // Autodetect bind mounts } else if (S_ISDIR(st.st_mode) && !mp->mnt_type) vfsflags |= MS_BIND; } /* If we know the fstype (or don't need to), jump straight * to the actual mount. */ if (mp->mnt_type || (vfsflags & (MS_REMOUNT | MS_BIND | MS_MOVE))) rc = mount_it_now(mp, vfsflags, filteropts); // Loop through filesystem types until mount succeeds or we run out else { /* Initialize list of block backed filesystems. This has to be * done here so that during "mount -a", mounts after /proc shows up * can autodetect. */ if (!fslist) { fslist = get_block_backed_filesystems(); if (ENABLE_FEATURE_CLEAN_UP && fslist) atexit(delete_block_backed_filesystems); } for (fl = fslist; fl; fl = fl->link) { mp->mnt_type = fl->data; if (!(rc = mount_it_now(mp,vfsflags, filteropts))) break; mp->mnt_type = 0; } } if (ENABLE_FEATURE_CLEAN_UP) free(filteropts); // If mount failed, clean up loop file (if any). if (ENABLE_FEATURE_MOUNT_LOOP && rc && loopFile) { del_loop(mp->mnt_fsname); if (ENABLE_FEATURE_CLEAN_UP) { free(loopFile); free(mp->mnt_fsname); } } report_error: if (rc && errno == EBUSY && ignore_busy) rc = 0; if (rc < 0) bb_perror_msg("Mounting %s on %s failed", mp->mnt_fsname, mp->mnt_dir); return rc; }
int losetup_main(int argc, char **argv) { char dev[] = LOOP_NAME"0"; unsigned opt; char *opt_o; char *s; unsigned long long offset = 0; /* max 2 args, all opts are mutually exclusive */ opt_complementary = "?2:d--of:o--df:f-do"; opt = getopt32(argv, "do:f", &opt_o); argc -= optind; argv += optind; if (opt == 0x2) // -o offset = xatoull(opt_o); if (opt == 0x4 && argc) // -f does not take any argument bb_show_usage(); if (opt == 0x1) { // -d /* detach takes exactly one argument */ if (argc != 1) bb_show_usage(); if (del_loop(argv[0])) bb_simple_perror_msg_and_die(argv[0]); return EXIT_SUCCESS; } if (argc == 2) { /* -o or no option */ if (set_loop(&argv[0], argv[1], offset) < 0) bb_simple_perror_msg_and_die(argv[0]); return EXIT_SUCCESS; } if (argc == 1) { /* -o or no option */ s = query_loop(argv[0]); if (!s) bb_simple_perror_msg_and_die(argv[0]); printf("%s: %s\n", argv[0], s); if (ENABLE_FEATURE_CLEAN_UP) free(s); return EXIT_SUCCESS; } /* -o, -f or no option */ while (1) { s = query_loop(dev); if (!s) { if (opt == 0x4) { puts(dev); return EXIT_SUCCESS; } } else { if (opt != 0x4) printf("%s: %s\n", dev, s); if (ENABLE_FEATURE_CLEAN_UP) free(s); } if (++dev[sizeof(dev) - 2] > '9') break; } return EXIT_SUCCESS; }