void swat_crossing_people(void) { OBJECT *odog,*owagon; void *dogani,*wagonani; current_proc->pdata.p_otherguy=current_proc->pa8; process_sleep(0x50); /* create dog */ get_char_ani(ANIM_TABLE2,ANIM_F2_FRIEND); // get ptr to anim table dogani=current_proc->pa9; current_proc->pa9=COMPUTE_ADDR((current_proc->pa8)->oheap,GET_LONG(current_proc->pa9)); // get ptr to frame gso_dmawnz(odog,(ADDRESS)current_proc->pa9,(current_proc->pa8)->oheap,0); alloc_cache((OIMGTBL *)current_proc->pa9,(current_proc->pa8)->oheap,odog); odog->oxpos.u.intpos=worldtlx.u.intpos-SCX(0x30); odog->oxvel.pos=SCX(0x30000); odog->oypos.u.intpos=ground_y-SCY(0x20); odog->ozval=100; insert_object(odog,&objlst); /* create wagon */ get_char_ani(ANIM_TABLE2,ANIM_F3_FRIEND); // get ptr to anim table wagonani=current_proc->pa9; current_proc->pa9=COMPUTE_ADDR((current_proc->pa8)->oheap,GET_LONG(current_proc->pa9)); // get ptr to frame gso_dmawnz(owagon,(ADDRESS)current_proc->pa9,(current_proc->pa8)->oheap,0); alloc_cache((OIMGTBL *)current_proc->pa9,(current_proc->pa8)->oheap,owagon); match_ani_points(odog,owagon); // match to two multi_adjust_xy(owagon,-66,-25); // lineup wagon with dog owagon->oxvel.pos=SCX(0x30000); // set speed to match dog owagon->ozval=200; insert_object(owagon,&objlst); /* cross */ do { process_sleep(3); /* update dog */ current_proc->pa8=odog; current_proc->pa9=dogani; frame_a9(odog); dogani=current_proc->pa9; /* update wagon */ current_proc->pa8=owagon; current_proc->pa9=wagonani; frame_a9(owagon); wagonani=current_proc->pa9; } while (abs(worldtlx.u.intpos-odog->oxpos.u.intpos)<700); delobjp(odog); delobjp(owagon); process_suicide(); }
void create_baiters(void) { BAITPOS *pa10; OBJECT *obj; pa10=baiter_pos_list; /* cb_1 */ do { if (pa10->b_ypos<0) return; gso_dmawnz_ns(obj,(ADDRESS)pa10->b_frame,hidden_anims,0); alloc_cache(pa10->b_frame,&hidden_anims,obj); (short)obj->ochar=pa10->b_xpos; (short)obj->oid=pa10->b_ypos; set_xy_coordinates(obj,pa10->b_xpos+wave_x_position,pa10->b_ypos+wave_y_position); insert_object(obj,&objlst); CREATE(PID_PONG_SPEED,baiter_enemy); pa10++; } while(1); }
void ce4b(void) { OBJECT *obj; XYTYPE temp; gso_dmawnz(obj,(ADDRESS)&expld1,hidden_anims,0); alloc_cache(&expld1,&hidden_anims,obj); temp.yx=(LONG)current_proc->pa9; set_xy_coordinates(obj,temp.u.xpos+2,temp.u.ypos+5); insert_object(obj,&objlst); process_sleep(2); set_xy_coordinates(obj,temp.u.xpos+2,temp.u.ypos+5); animate(SINGLE_ANI,&expld2,obj->oflags); process_sleep(2); animate(SINGLE_ANI,&expld3,obj->oflags); process_sleep(2); animate(SINGLE_ANI,&expld4,obj->oflags); process_sleep(2); animate(SINGLE_ANI,&expld5,obj->oflags); process_sleep(2); delobj(obj); process_suicide(); }
void create_player_1_ship(void) { OBJECT *obj; gso_dmawnz(obj,(ADDRESS)&ship1,hidden_anims,0); alloc_cache(&ship1,&hidden_anims,obj); set_xy_coordinates(obj,SCX(0x50),SCY(0xe0)); player_1_ship=obj; insert_object(obj,&objlst); return; }
OBJECT *make_a_spike(void) { OBJECT *obj; gso_dmawnz(obj,(ADDRESS)EJBSPIKE,bell_anims,0); alloc_cache((OIMGTBL *)EJBSPIKE,&bell_anims,obj); obj->oxpos.u.intpos=(short)current_proc->a3; obj->oypos.u.intpos=SCY(0xa80)+12; (short)current_proc->a3+=SCX(15); // spike spacing insert_object(obj,&objlst); return(obj); }
OBJECT *makestar(void) { OBJECT *obj; gso_dmawnz(obj,(ADDRESS)&star,hidden_anims,0); alloc_cache(&star,&hidden_anims,obj); obj->ozval=-100; obj->oxpos.u.intpos=randu(SCX(400))-1; obj->oypos.u.intpos=randu(SCY(254))-1; insert_object(obj,&objlst); obj->oyvel.pos=randu(SCY(0x20000))+SCY(0x20000); return(obj); }
/****************************************************************************** Function: void temple_calla(void) By: David Schwartz Date: Feb 1995 Parameters: None Returns: None Description: setup the bridge background ******************************************************************************/ void temple_calla(void) { OBJECT *obj; alloc_vram_perm_bg_list((ADDRESS *)temple_perm_list,&temple_anims); current_proc->a10=10; (long)current_proc->a11=-1; do { /* candd */ gso_dmawnz(obj,(ADDRESS)KANDLE1,temple_anims,0); obj->oxpos.u.intpos=(short)current_proc->a11+8+2; obj->oypos.u.intpos=0xb2+6; //+36; alloc_cache(KANDLE1,temple_anims,obj); insert_object(obj,&baklst6); /* flame */ (OBJECT *)current_proc->pa9=obj; gso_dmawnz(obj,(ADDRESS)wik1,temple_anims,0); alloc_cache(wik1,temple_anims,current_proc->pa8); insert_object(current_proc->pa8,&baklst6); obj->oxpos.u.intpos=((OBJECT *)current_proc->pa9)->oxpos.u.intpos+SCX(7); obj->oypos.u.intpos=((OBJECT *)current_proc->pa9)->oypos.u.intpos-SCY(12); CREATE(PID_BANI,candle_flame); (long)current_proc->a11+=SCX(0x96); } while(--current_proc->a10>0); create_dumb_animators(tony_candle_table,&temple_anims); return; }
void flr2(OIMGTBL *pa5) { OBJECT *obj; gso_dmawnz(obj,(ADDRESS)pa5,bell_anims,0); alloc_cache(pa5,&bell_anims,obj); if (current_proc->a3) flip_single(obj); /* flr3 */ obj->oypos.u.intpos=(short)current_proc->a7; obj->oxpos.u.intpos=(short)current_proc->a6; obj->ozval=1000; (short)current_proc->a6+=obj->osize.u.xpos; insert_object(obj,&baklst8); return; }
void f_indian(void) { OBJECT *obj,*ta8; void *animframe; //current_proc->pa9=a_ind_friend; get_char_ani(ANIM_TABLE2,ANIM_F1_FRIEND); other_ochar_sound(4,FT_ST); mframew_5; process_sleep(0x20); ta8=current_proc->pa8; current_proc->a10=(ADDRESS)current_proc->pa8; current_proc->a0=(ADDRESS)current_proc->pa9; animframe=(void*)get_char_ani(ANIM_TABLE2,ANIM_F2_FRIEND); // get mk2game frame ptr current_proc->pa9=(void*)current_proc->a0; animframe=(void*)COMPUTE_ADDR(ta8->oheap,GET_LONG(animframe)); gso_dmawnz(obj,(ADDRESS)animframe,ta8->oheap,0); alloc_cache((OIMGTBL*)animframe,ta8->oheap,obj); lineup_1pwm(obj,(OBJECT *)current_proc->a10); multi_adjust_xy(obj,-(SCX(0x70)),-SCY(0x100)); insert_object(obj,&objlst); gravity_ani_ysize(SCY(0x20000),SCY(0x6000)); shake_n_sound(); if ( random()<0 ) { p7_centered(txt_raiden1,160,SCY(0xf0)-14); p7_centered(txt_raiden2,160,SCY(0xf0)); } else { p7_centered(txt_kano,160,SCY(0xf0)); } current_proc->pa8=ta8; process_sleep(0x60); death_blow_complete(); wait_forever(); }
void hat_proc(void) { OBJECT *obj; current_proc->a10=(ADDRESS)current_proc->pa8; //gso_dmawnz(obj,(ADDRESS)&FETCHHAT2,friendship_anims,0); //alloc_cache(&FETCHHAT2,&friendship_anims,obj); get_char_ani(ANIM_TABLE2,ANIM_F3_FRIEND); // get ptr to anim table current_proc->pa9=COMPUTE_ADDR((current_proc->pa8)->oheap,GET_LONG(current_proc->pa9)); // get ptr to frame gso_dmawnz(obj,(ADDRESS)current_proc->pa9,(current_proc->pa8)->oheap,0); alloc_cache((OIMGTBL *)current_proc->pa9,(current_proc->pa8)->oheap,obj); lineup_a0_onto_a1(obj,(OBJECT *)current_proc->a10); multi_adjust_xy(obj,SCX(0x50),SCY(0x10)); insert_object(obj,&objlst); obj->oyvel.pos=-SCY(0x40000); set_proj_vel(obj,SCX(0xa0000),2); process_suicide(); }
void cute_lil_doggy(void) { OBJECT *obj; current_proc->a10=(ADDRESS)current_proc->pa8; get_char_ani(ANIM_TABLE2,ANIM_F2_FRIEND); // get ptr to anim table current_proc->pa9=COMPUTE_ADDR((current_proc->pa8)->oheap,GET_LONG(current_proc->pa9)); // get ptr to frame gso_dmawnz(obj,(ADDRESS)current_proc->pa9,(current_proc->pa8)->oheap,0); alloc_cache((OIMGTBL *)current_proc->pa9,(current_proc->pa8)->oheap,obj); if (((OBJECT *)current_proc->a10)->oflags & M_FLIPH) { obj->oxpos.u.intpos=SCRRGT+SCX(0x30)+SCX(0x30)+worldtlx.u.intpos-SCX(0x30); obj->oxvel.pos=-SCX(0x60000); flip_single(obj); } else { obj->oxpos.u.intpos=worldtlx.u.intpos-SCX(0x30); obj->oxvel.pos=SCX(0x60000); } /* cute3 */ obj->oypos.u.intpos=ground_y-SCY(0x20); obj->ozval=100; insert_object(obj,&objlst); //current_proc->pa9=a_dog; get_char_ani(ANIM_TABLE2,ANIM_F2_FRIEND); init_anirate(3); do { next_anirate(); process_sleep(1); } while (abs(worldtlx.u.intpos-obj->oxpos.u.intpos)<700); stop_a8(obj); wait_forever(); }
void pop_up_my_toy(void) { ADDRESS animframe; OBJECT *obj; tsound(0x92); shake_a11(6,6); takeover_him(r_scared_of_monkey); animframe=(ADDRESS)COMPUTE_ADDR((current_proc->pa8)->oheap,GET_LONG(current_proc->pa9)); gso_dmawnz(obj,(ADDRESS)animframe,(current_proc->pa8)->oheap,0); alloc_cache((OIMGTBL *)animframe,(current_proc->pa8)->oheap,obj); obj->ozval=100; lineup_1pwm(obj,(OBJECT*)current_proc->a11); insert_object(obj,&objlst); framew(4); process_sleep(0x30); death_blow_complete(); wait_forever(); }
static errcode_t unix_set_blksize(io_channel channel, int blksize) { struct unix_private_data *data; errcode_t retval; EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL); data = (struct unix_private_data *) channel->private_data; EXT2_CHECK_MAGIC(data, EXT2_ET_MAGIC_UNIX_IO_CHANNEL); if (channel->block_size != blksize) { #ifndef NO_IO_CACHE if ((retval = flush_cached_blocks(channel, data, 0))) return retval; #endif channel->block_size = blksize; free_cache(data); if ((retval = alloc_cache(channel, data))) return retval; } return 0; }
void sonya_flower_proc(void) { ADDRESS animframe; OBJECT *obj; process_sleep(20+randu(10)); get_char_ani(ANIM_TABLE2,ANIM_F1_FRIEND); animframe=(ADDRESS)COMPUTE_ADDR((current_proc->pa8)->oheap,GET_LONG(current_proc->pa9)); gso_dmawnz_ns(obj,(ADDRESS)animframe,(current_proc->pa8)->oheap,0); alloc_cache((OIMGTBL *)animframe,(current_proc->pa8)->oheap,obj); obj->oxpos.u.intpos=randu(SCRRGT); ground_a8(); obj->oypos.u.intpos+=randu(SCY(5)); a8_front_plus_1(obj); insert_object(obj,&objlst); get_char_ani(ANIM_TABLE2,ANIM_F1_FRIEND); framew(3+randu(6)); process_suicide(); }
//extern OIMGTBL *ostrich1; void f_shang(void) { OBJECT *obj=current_proc->pa8; void *animframe; CREATE(PID_BANI,end_friend_proc); tsound(0x8c); create_fx(FX_INVISO_POOF); process_sleep(8); set_inviso(current_proc->pa8); current_proc->a10=(ADDRESS)current_proc->pa8; get_char_ani(ANIM_TABLE2,ANIM_F1_FRIEND); animframe=(void*)COMPUTE_ADDR(obj->oheap,GET_LONG(current_proc->pa9)); gso_dmawnz(obj,(ADDRESS)animframe,obj->oheap,0); alloc_cache((OIMGTBL *)animframe,obj->oheap,obj); obj->oxpos.u.intpos=((OBJECT*)current_proc->a10)->oxpos.u.intpos; obj->oypos.u.intpos=ground_y-SCY(0x20); insert_object(obj,&objlst); process_sleep(0x40); bounce(); bounce(); obj->oxvel.pos=SCX(0x30000); /* shang4 */ current_proc->a10=5; do { bounce(); } while(--current_proc->a10>0 ); stop_a8(current_proc->pa8); wait_forever(); }
void gbld3(void *pa5) { OBJECT *obj; OBJECT *ta3; ta3=current_proc->pa8; // save player object we are following gso_dmawnz(obj,(ADDRESS)pa5,blood_anims,0); alloc_cache(pa5,&blood_anims,obj); if (ta3->ochar<=FT_SK) (WORD *)current_proc->a0=ochar_blood_palettes[ta3->ochar]; else (WORD *)current_proc->a0=ochar_blood_palettes[0]; if ((WORD *)current_proc->a0!=BLOOD_P) swpal((void *)current_proc->a0,obj); // not normal blood switch /* gbld5 */ obj->ozval=FRONT_Z+1; obj->oflags=(obj->oflags & (~M_FLIPH)) | (((OBJECT *)current_proc->a11)->oflags & M_FLIPH); return; }
void bub_1_proc(void) { ADDRESS animframe; OBJECT *obj; find_ani2_part2(ANIM_F1_FRIEND); animframe=(ADDRESS)COMPUTE_ADDR((current_proc->pa8)->oheap,GET_LONG(current_proc->pa9)); current_proc->a11=(ADDRESS)current_proc->pa8; gso_dmawnz(obj,(ADDRESS)animframe,(current_proc->pa8)->oheap,0); alloc_cache((OIMGTBL *)animframe,(current_proc->pa8)->oheap,obj); lineup_1pwm(obj,(OBJECT*)current_proc->a11); insert_object(obj,&objlst); ((ADDRESS *)current_proc->pa9)++; framew(1); set_proj_vel(current_proc->pa8,SCX(0x20000)+randu(SCX(0x30000)),-1); (current_proc->pa8)->oyvel.pos=srandarc(SCY(0x20000)); process_sleep(20+randu(30)); framew(4); delobjp(current_proc->pa8); process_suicide(); }
static errcode_t unix_open(const char *name, int flags, io_channel *channel) { io_channel io = NULL; struct unix_private_data *data = NULL; errcode_t retval; int open_flags; struct stat st; #ifdef __linux__ struct utsname ut; #endif if (name == 0) return EXT2_ET_BAD_DEVICE_NAME; retval = ext2fs_get_mem(sizeof(struct struct_io_channel), &io); if (retval) return retval; memset(io, 0, sizeof(struct struct_io_channel)); io->magic = EXT2_ET_MAGIC_IO_CHANNEL; retval = ext2fs_get_mem(sizeof(struct unix_private_data), &data); if (retval) goto cleanup; io->manager = unix_io_manager; retval = ext2fs_get_mem(strlen(name)+1, &io->name); if (retval) goto cleanup; strcpy(io->name, name); io->private_data = data; io->block_size = 1024; io->read_error = 0; io->write_error = 0; io->refcount = 1; memset(data, 0, sizeof(struct unix_private_data)); data->magic = EXT2_ET_MAGIC_UNIX_IO_CHANNEL; data->io_stats.num_fields = 2; if ((retval = alloc_cache(io, data))) goto cleanup; open_flags = (flags & IO_FLAG_RW) ? O_RDWR : O_RDONLY; if (flags & IO_FLAG_EXCLUSIVE) open_flags |= O_EXCL; #ifdef HAVE_OPEN64 data->dev = open64(io->name, open_flags); #else data->dev = open(io->name, open_flags); #endif if (data->dev < 0) { retval = errno; goto cleanup; } #ifdef BLKROGET if (flags & IO_FLAG_RW) { int error; int readonly = 0; /* Is the block device actually writable? */ error = ioctl(data->dev, BLKROGET, &readonly); if (!error && readonly) { close(data->dev); retval = EPERM; goto cleanup; } } #endif #ifdef __linux__ #undef RLIM_INFINITY #if (defined(__alpha__) || ((defined(__sparc__) || defined(__mips__)) && (SIZEOF_LONG == 4))) #define RLIM_INFINITY ((unsigned long)(~0UL>>1)) #else #define RLIM_INFINITY (~0UL) #endif /* * Work around a bug in 2.4.10-2.4.18 kernels where writes to * block devices are wrongly getting hit by the filesize * limit. This workaround isn't perfect, since it won't work * if glibc wasn't built against 2.2 header files. (Sigh.) * */ if ((flags & IO_FLAG_RW) && (uname(&ut) == 0) && ((ut.release[0] == '2') && (ut.release[1] == '.') && (ut.release[2] == '4') && (ut.release[3] == '.') && (ut.release[4] == '1') && (ut.release[5] >= '0') && (ut.release[5] < '8')) && (fstat(data->dev, &st) == 0) && (S_ISBLK(st.st_mode))) { struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = (unsigned long) RLIM_INFINITY; setrlimit(RLIMIT_FSIZE, &rlim); getrlimit(RLIMIT_FSIZE, &rlim); if (((unsigned long) rlim.rlim_cur) < ((unsigned long) rlim.rlim_max)) { rlim.rlim_cur = rlim.rlim_max; setrlimit(RLIMIT_FSIZE, &rlim); } } #endif *channel = io; return 0; cleanup: if (data) { free_cache(data); ext2fs_free_mem(&data); } if (io) ext2fs_free_mem(&io); return retval; }
bool check_prefs_changed_comp (bool checkonly) { #ifdef FSUAE if (!g_fs_uae_jit_compiler) { return false; } #endif bool changed = 0; static int cachesize_prev, comptrust_prev; static bool canbang_prev; if (currprefs.comptrustbyte != changed_prefs.comptrustbyte || currprefs.comptrustword != changed_prefs.comptrustword || currprefs.comptrustlong != changed_prefs.comptrustlong || currprefs.comptrustnaddr!= changed_prefs.comptrustnaddr || currprefs.compnf != changed_prefs.compnf || currprefs.comp_hardflush != changed_prefs.comp_hardflush || currprefs.comp_constjump != changed_prefs.comp_constjump || currprefs.compfpu != changed_prefs.compfpu || currprefs.fpu_strict != changed_prefs.fpu_strict || currprefs.cachesize != changed_prefs.cachesize) changed = 1; if (checkonly) return changed; currprefs.comptrustbyte = changed_prefs.comptrustbyte; currprefs.comptrustword = changed_prefs.comptrustword; currprefs.comptrustlong = changed_prefs.comptrustlong; currprefs.comptrustnaddr= changed_prefs.comptrustnaddr; currprefs.compnf = changed_prefs.compnf; currprefs.comp_hardflush = changed_prefs.comp_hardflush; currprefs.comp_constjump = changed_prefs.comp_constjump; currprefs.compfpu = changed_prefs.compfpu; currprefs.fpu_strict = changed_prefs.fpu_strict; if (currprefs.cachesize != changed_prefs.cachesize) { if (currprefs.cachesize && !changed_prefs.cachesize) { cachesize_prev = currprefs.cachesize; comptrust_prev = currprefs.comptrustbyte; canbang_prev = canbang; } else if (!currprefs.cachesize && changed_prefs.cachesize == cachesize_prev) { changed_prefs.comptrustbyte = currprefs.comptrustbyte = comptrust_prev; changed_prefs.comptrustword = currprefs.comptrustword = comptrust_prev; changed_prefs.comptrustlong = currprefs.comptrustlong = comptrust_prev; changed_prefs.comptrustnaddr = currprefs.comptrustnaddr = comptrust_prev; } currprefs.cachesize = changed_prefs.cachesize; alloc_cache(); changed = 1; } // Turn off illegal-mem logging when using JIT... if(currprefs.cachesize) currprefs.illegal_mem = changed_prefs.illegal_mem;// = 0; if ((!canbang || !currprefs.cachesize) && currprefs.comptrustbyte != 1) { // Set all of these to indirect when canbang == 0 currprefs.comptrustbyte = 1; currprefs.comptrustword = 1; currprefs.comptrustlong = 1; currprefs.comptrustnaddr= 1; changed_prefs.comptrustbyte = 1; changed_prefs.comptrustword = 1; changed_prefs.comptrustlong = 1; changed_prefs.comptrustnaddr= 1; changed = 1; if (currprefs.cachesize) write_log (_T("JIT: Reverting to \"indirect\" access, because canbang is zero!\n")); } if (changed) write_log (_T("JIT: cache=%d. b=%d w=%d l=%d fpu=%d nf=%d inline=%d hard=%d\n"), currprefs.cachesize, currprefs.comptrustbyte, currprefs.comptrustword, currprefs.comptrustlong, currprefs.compfpu, currprefs.compnf, currprefs.comp_constjump, currprefs.comp_hardflush); return changed; }
static errcode_t unix_open(const char *name, int flags, io_channel *channel) { io_channel io = NULL; struct unix_private_data *data = NULL; errcode_t retval; int open_flags, zeroes = 0; int f_nocache = 0; ext2fs_struct_stat st; #ifdef __linux__ struct utsname ut; #endif if (name == 0) return EXT2_ET_BAD_DEVICE_NAME; retval = ext2fs_get_mem(sizeof(struct struct_io_channel), &io); if (retval) goto cleanup; memset(io, 0, sizeof(struct struct_io_channel)); io->magic = EXT2_ET_MAGIC_IO_CHANNEL; retval = ext2fs_get_mem(sizeof(struct unix_private_data), &data); if (retval) goto cleanup; io->manager = unix_io_manager; retval = ext2fs_get_mem(strlen(name)+1, &io->name); if (retval) goto cleanup; strcpy(io->name, name); io->private_data = data; io->block_size = 1024; io->read_error = 0; io->write_error = 0; io->refcount = 1; memset(data, 0, sizeof(struct unix_private_data)); data->magic = EXT2_ET_MAGIC_UNIX_IO_CHANNEL; data->io_stats.num_fields = 2; open_flags = (flags & IO_FLAG_RW) ? O_RDWR : O_RDONLY; if (flags & IO_FLAG_EXCLUSIVE) open_flags |= O_EXCL; #if defined(O_DIRECT) if (flags & IO_FLAG_DIRECT_IO) { open_flags |= O_DIRECT; io->align = ext2fs_get_dio_alignment(data->dev); } #elif defined(F_NOCACHE) if (flags & IO_FLAG_DIRECT_IO) { f_nocache = F_NOCACHE; io->align = 4096; } #endif data->flags = flags; data->dev = ext2fs_open_file(io->name, open_flags, 0); if (data->dev < 0) { retval = errno; goto cleanup; } if (f_nocache) { if (fcntl(data->dev, f_nocache, 1) < 0) { retval = errno; goto cleanup; } } /* * If the device is really a block device, then set the * appropriate flag, otherwise we can set DISCARD_ZEROES flag * because we are going to use punch hole instead of discard * and if it succeed, subsequent read from sparse area returns * zero. */ if (ext2fs_stat(io->name, &st) == 0) { if (S_ISBLK(st.st_mode)) io->flags |= CHANNEL_FLAGS_BLOCK_DEVICE; else io->flags |= CHANNEL_FLAGS_DISCARD_ZEROES; } #ifdef BLKDISCARDZEROES ioctl(data->dev, BLKDISCARDZEROES, &zeroes); if (zeroes) io->flags |= CHANNEL_FLAGS_DISCARD_ZEROES; #endif #if defined(__CYGWIN__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) /* * Some operating systems require that the buffers be aligned, * regardless of O_DIRECT */ if (!io->align) io->align = 512; #endif if ((retval = alloc_cache(io, data))) goto cleanup; #ifdef BLKROGET if (flags & IO_FLAG_RW) { int error; int readonly = 0; /* Is the block device actually writable? */ error = ioctl(data->dev, BLKROGET, &readonly); if (!error && readonly) { close(data->dev); retval = EPERM; goto cleanup; } } #endif #ifdef __linux__ #undef RLIM_INFINITY #if (defined(__alpha__) || ((defined(__sparc__) || defined(__mips__)) && (SIZEOF_LONG == 4))) #define RLIM_INFINITY ((unsigned long)(~0UL>>1)) #else #define RLIM_INFINITY (~0UL) #endif /* * Work around a bug in 2.4.10-2.4.18 kernels where writes to * block devices are wrongly getting hit by the filesize * limit. This workaround isn't perfect, since it won't work * if glibc wasn't built against 2.2 header files. (Sigh.) * */ if ((flags & IO_FLAG_RW) && (uname(&ut) == 0) && ((ut.release[0] == '2') && (ut.release[1] == '.') && (ut.release[2] == '4') && (ut.release[3] == '.') && (ut.release[4] == '1') && (ut.release[5] >= '0') && (ut.release[5] < '8')) && (ext2fs_stat(io->name, &st) == 0) && (S_ISBLK(st.st_mode))) { struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = (unsigned long) RLIM_INFINITY; setrlimit(RLIMIT_FSIZE, &rlim); getrlimit(RLIMIT_FSIZE, &rlim); if (((unsigned long) rlim.rlim_cur) < ((unsigned long) rlim.rlim_max)) { rlim.rlim_cur = rlim.rlim_max; setrlimit(RLIMIT_FSIZE, &rlim); } } #endif *channel = io; return 0; cleanup: if (data) { free_cache(data); ext2fs_free_mem(&data); } if (io) ext2fs_free_mem(&io); return retval; }
static errcode_t unix_open(const char *name, int flags, io_channel *channel) { io_channel io = NULL; struct unix_private_data *data = NULL; errcode_t retval; int open_flags; struct stat st; #ifdef __linux__ struct utsname ut; #endif if (name == 0) return EXT2_ET_BAD_DEVICE_NAME; retval = ext2fs_get_mem(sizeof(struct struct_io_channel), &io); if (retval) return retval; memset(io, 0, sizeof(struct struct_io_channel)); io->magic = EXT2_ET_MAGIC_IO_CHANNEL; retval = ext2fs_get_mem(sizeof(struct unix_private_data), &data); if (retval) goto cleanup; io->manager = unix_io_manager; retval = ext2fs_get_mem(strlen(name)+1, &io->name); if (retval) goto cleanup; strcpy(io->name, name); io->private_data = data; io->block_size = 1024; io->read_error = 0; io->write_error = 0; io->refcount = 1; memset(data, 0, sizeof(struct unix_private_data)); data->magic = EXT2_ET_MAGIC_UNIX_IO_CHANNEL; if ((retval = alloc_cache(io, data))) goto cleanup; open_flags = (flags & IO_FLAG_RW) ? O_RDWR : O_RDONLY; #ifdef CONFIG_LFS data->dev = open64(io->name, open_flags); #else data->dev = open(io->name, open_flags); #endif if (data->dev < 0) { retval = errno; goto cleanup; } #ifdef __linux__ #undef RLIM_INFINITY #if (defined(__alpha__) || ((defined(__sparc__) || defined(__mips__)) && (SIZEOF_LONG \ == 4))) #define RLIM_INFINITY ((unsigned long)(~0UL>>1)) #else #define RLIM_INFINITY (~0UL) #endif if ((flags & IO_FLAG_RW) && (uname(&ut) == 0) && ((ut.release[0] == '2') && (ut.release[1] == '.') && (ut.release[2] == '4') && (ut.release[3] == '.') && (ut.release[4] == '1') && (ut.release[5] >= '0') && (ut.release[5] < '8')) && (fstat(data->dev, &st) == 0) && (S_ISBLK(st.st_mode))) { struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = (unsigned long) RLIM_INFINITY; setrlimit(RLIMIT_FSIZE, &rlim); getrlimit(RLIMIT_FSIZE, &rlim); if (((unsigned long) rlim.rlim_cur) < ((unsigned long) rlim.rlim_max)) { rlim.rlim_cur = rlim.rlim_max; setrlimit(RLIMIT_FSIZE, &rlim); } } #endif *channel = io; return 0; cleanup: if (data) { free_cache(data); ext2fs_free_mem(&data); } ext2fs_free_mem(&io); return retval; }