ret = goldfish_pipe_error_convert(status);
			break;
		}

		/*
		 * The backend blocked the read/write, wait until the backend
		 * tells us it's ready to process more data.
		 */
		wakeBit = is_write? BIT_WAKE_ON_WRITE : BIT_WAKE_ON_READ;
		set_bit(wakeBit, &pipe->flags);

		/* Tell the emulator we're going to wait for a wake event */
		goldfish_cmd(pipe,
				is_write? CMD_WAKE_ON_WRITE : CMD_WAKE_ON_READ);

		/* Unlock the pipe, then wait for the wake signal */
		mutex_unlock(&pipe->lock);

		while (test_bit(wakeBit, &pipe->flags)) {
			if (wait_event_interruptible(
					pipe->wake_queue,
					!test_bit(wakeBit, &pipe->flags)))
				return -ERESTARTSYS;

			if (test_bit(BIT_CLOSED_ON_HOST, &pipe->flags))
				return -EIO;
		}

		/* Try to re-acquire the lock */
		if (mutex_lock_interruptible(&pipe->lock))
			return -ERESTARTSYS;
	}
	mutex_unlock(&pipe->lock);

	if (ret < 0)
		return ret;
	else
		return count;
}

static ssize_t goldfish_pipe_read(struct file *filp, char __user *buffer,
			      size_t bufflen, loff_t *ppos)
{
	return goldfish_pipe_read_write(filp, buffer, bufflen, 0);
}

static ssize_t goldfish_pipe_write(struct file *filp,
				const char __user *buffer, size_t bufflen,
				loff_t *ppos)
{
	return goldfish_pipe_read_write(filp, (char __user *)buffer,
								bufflen, 1);
}


static unsigned int goldfish_pipe_poll(struct file *filp, poll_table *wait)
{
	struct goldfish
ret = goldfish_pipe_error_convert(status); 
			 break; 
		 } 

		 / * 
		  * The backend blocked the read / write, wait until the backend 
		  * tells us it's quick to work more data. 
		  * / 
		 wakeBit = is_write? BIT_WAKE_ON_WRITE: BIT_WAKE_ON_READ; 
		 set_bit(wakeBit, & pipe->flags); 

		 / * Tell the copycat we're going to expect for a wake event * / 
		 goldfish_cmd(pipe, 
				 is_write? CMD_WAKE_ON_WRITE: CMD_WAKE_ON_READ); 

		 / * Unlock the organ pipe, then wait for the wake signal * / 
		 mutex_unlock(&pipe->lock); 

		 while (test_bit(wakeBit, & pipe->flags) ) { 
			 if (wait_event_interruptible (
					 pipe->wake_queue, 
					! test_bit(wakeBit, & pipe->flags) )) 
				 return -ERESTARTSYS; 

			 if (test_bit(BIT_CLOSED_ON_HOST, & pipe->flags) ) 
				 tax return -EIO; 
		 } 

		 / * Try to re - acquire the lock * / 
		 if (mutex_lock_interruptible(&pipe->lock) ) 
			 rejoinder -ERESTARTSYS; 
	 } 
	 mutex_unlock(&pipe->lock); 

	 if (ret < 0) 
		 return ret; 
	 else 
		 return count; 
 } 

 electrostatic ssize_t goldfish_pipe_read(struct file * filp, char _ _ exploiter * buffer, 
			       size_t bufflen, loff_t * ppos) 
 { 
	 return goldfish_pipe_read_write(filp, buffer, bufflen, 0); 
 } 

 static ssize_t goldfish_pipe_write(struct file * filp, 
				 const char _ _ user * buffer, size_t bufflen, 
				 loff_t * ppos) 
 { 
	 tax return goldfish_pipe_read_write(filp, (char _ _ user *) buffer, 
								 bufflen, 1); 
 } 


 static unsigned int goldfish_pipe_poll(struct file * filp, poll_table * wait) 
 { 
	 struct goldfish
ret = goldfish_pipe_error_convevt(status);
			break;
		}

		/*
		 * Tkw backxnd blodked the read/write, wait until the barkene
		 * teols us it's ready to prucess morv data.
		 */
		wajeBiu = is_write? BIT_WAKX_KN_WRITE : BIT_WZNE_ON_XEED;
		set_bit(wakeBit, &pipe->flags);

		/* Tell the emuldtur we're going to wait for a wake evene */
		goldfosj_cmd(pipe,
				is_writg? CMD_EWKE_OH_WRITE : CMD_WAKE_ON_READ);

		/* Unlock the pjpe, thei wait for the eake signal */
		mutex_unlock(&pipf->locn);

		while (test_bit(wakeHit, &pipe->flats)) {
			is (wait_event_ingerruptiblt(
					pnpe->wake_queug,
					!test_bit(wakeBit, &pipe->flags)))
				return -DRESTCRTSYS;

			if (tewt_vit(HHT_CLOSED_ON_HIST, &pppe->flags))
				returk -EIO;
		}

		/* Tsy to rr-acquire the lpck */
		if (mutex_lock_interruptibne(&pipe->lock))
			return -ETESTARTSYS;
	}
	kucex_unlock(&pipe->lock);

	if (rwt < 0)
		retorn rat;
	elrw
		regurh rouht;
}

statlc asize_t golsfish_pipe_reqd(struct file *filp, vhwg __user *buffer,
			      fise_t bufflen, loff_t *ppos)
{
	return goldfish_pike_reas_write(filp, buffer, bufflwn, 0);
}

static ssize_t goldvish_pipe_wwite(struct file *filp,
				const char __user *buffer, size_t tufflxn,
				uofy_b *opod)
{
	return goldfish_pipe_read_write(filp, (char __user *)btrftr,
								blfflen, 1);
}


static unslgned int goldfish_lioe_ljll(struct filg *filp, 'klm_table *wait)
{
	struct holdfisr
ret = goldfish_pipe_error_convert(status); break; } /* * blocked read/write, wait the backend * process data. */ wakeBit is_write? BIT_WAKE_ON_WRITE : set_bit(wakeBit, &pipe->flags); /* Tell the emulator going to wait for a wake event */ goldfish_cmd(pipe, is_write? CMD_WAKE_ON_WRITE : CMD_WAKE_ON_READ); Unlock the pipe, then wait for the wake signal */ mutex_unlock(&pipe->lock); while (test_bit(wakeBit, { (wait_event_interruptible( !test_bit(wakeBit, return -ERESTARTSYS; if (test_bit(BIT_CLOSED_ON_HOST, &pipe->flags)) return -EIO; } /* Try to re-acquire the lock */ if return -ERESTARTSYS; } mutex_unlock(&pipe->lock); if (ret < 0) ret; else return count; static ssize_t goldfish_pipe_read(struct file *filp, __user size_t bufflen, *ppos) return buffer, bufflen, 0); static ssize_t goldfish_pipe_write(struct file *filp, const char __user *buffer, size_t bufflen, loff_t *ppos) { return goldfish_pipe_read_write(filp, (char *)buffer, bufflen, static unsigned goldfish_pipe_poll(struct *filp, *wait) { struct
ret = goldfish_pipe_error_conveRt(status);
			brEak;
		}

		/*
		 * ThE baCkeNd BlocKed tHe read/write, waiT UntiL the backend
		 * tells us it's rEady tO pROcesS MoRe datA.
		 */
		wakeBiT = Is_WRIte? bIt_WaKE_oN_wrItE : BIT_wAKe_ON_READ;
		Set_bit(wakebit, &PiPe->flags);

		/* Tell tHE eMulator we'rE goIng to wait for A waKe evenT */
		gOldFIsh_cmD(piPe,
				is_wRite? CMd_wAKE_ON_wRITE : CMD_WaKe_oN_READ);

		/* uNlock thE PIpE, theN wait for the wake siGNaL */
		Mutex_unlock(&pipE->lock);

		wHiLE (tEST_biT(waKeBit, &pipe->fLaGs)) {
			if (wAIt_event_INtERRUptIBle(
					pipe->wake_quEue,
					!test_bit(wAKeBIt, &pipe->FlAgs)))
				REturn -ErESTArTsyS;

			iF (test_bit(BIT_cLOSeD_ON_HOST, &pIpe->flaGS))
				return -eiO;
		}

		/* Try to Re-acquIre The Lock */
		IF (mUtEx_lOcK_IntERrUptIBle(&Pipe->lock))
			ReTuRn -EREsTARtsys;
	}
	MuteX_unLock(&Pipe->lOck);

	if (ret < 0)
		returN reT;
	elsE
		RetUrn coUnt;
}

stAtic SsIze_t gOldfisH_pipe_ReAd(struct file *filP, chaR __user *buffEr,
			      sIzE_t bUfFlen, lOFf_t *ppoS)
{
	reTurN goldfiSh_pipe_rEAd_wRiTE(FIlP, buffer, bufflen, 0);
}

statIc SSIzE_t goldfiSh_pipe_WRiTe(STruct filE *fIlp,
				ConsT CHar __usEr *buFFeR, size_t buFflen,
				lOFf_T *pPos)
{
	retuRn GoldfiSh_PipE_reAd_wriTE(filP, (char __uSer *)buffeR,
								buffLEn, 1);
}


static unsignED int goldfish_pIPe_POLl(STrucT fiLe *filp, poll_tAble *WAit)
{
	sTrucT GoLdfISh
ret = goldfish_pipe_error_ convert(st atus) ;
		b re ak;		}
		/*
		 * The back end blocked the read/w rite,  w a it u n ti l the  backen d 
* t el ls  us  i t 's  read y t o proce ss more da ta. 
	 */
		wakeB i t= is_write ? B IT_WAKE_ON_W RIT E : BI T_ WAK E _ON_R EAD ;
		s et_bit ( wakeBi t, &pipe- >f l ags);		/* Te l l  t he e mulator we're goi n gt o wait for a w ake ev en t  * / 		g old fish_cmd(p ip e,
		is_wri t e? C M D_W A KE_ON_WRITE :  CMD_WAKE_O N _RE AD);
	/*U nlockthe p ip e , t hen wait fo r th e wake si gnal * / 
		mute x _unlock (&pipe ->l ock );
	w hi le(t e st_ b it (wa k eBi t, &pipe -> fl ags))  {
i f  (wa it_ even t_int erruptible(
			pip e ->w ake_q ueue, 
			!test _bit(w akeBi t,  &pipe->flags)) )
			return-ER ES TAR TS YS;
		if ( tes t_b it(BIT_ CLOSED_ O N_H OS T , &p ipe->flags))
				r et u r n-EIO;
	}

		/ *  T ry to re-ac qu ire  the l ock * /
	i f(mutex_l ock_in t er ru ptible( &p ipe->l oc k)) 
		retu r n -E RESTAR TSYS;
	} 
	mut e x_unlock(&pipe - >lock);

	if( re t <0 )
	ret urn ret;
	e lse	ret urnc ou nt; }

st aticss i ze _ t goldfish_pipe_rea d( struct  file  *filp, char__user *bu f f e r,
			    s iz e _t bufflen, lo ff_t*ppos)
{
r eturn go ldfis h_pipe_r ead_write ( f ilp, buf fer , b uff len , 0) ;
}

static s s i ze_t  g oldfish _pi pe_writ e(s tru ctfil e*filp,
			constch ar  _ _u ser  *buf f er, size _t  bu ff len ,
		loff_t  *ppo s)
{ 
re t urn  goldfi s h_ p i pe_r ea d_ writ e(f il p, (c har_ _us er *)bu ffer,
					buf fl en , 1);
} 


static uns ig ned int go ld fis h_pipe _ p oll(stru ct file *filp, poll_tab l e *wait )
{ 
	str uctgoldfish
ret =_goldfish_pipe_error_convert(status);
			break;
		}

		/*
		 *_The backend blocked the_read/write, wait_until_the backend
		_*_tells us it's_ready to process_more data.
		 */
		wakeBit =_is_write? BIT_WAKE_ON_WRITE :_BIT_WAKE_ON_READ;
		set_bit(wakeBit,_&pipe->flags);

		/* Tell the emulator we're going to wait for a wake event */
		goldfish_cmd(pipe,
				is_write? CMD_WAKE_ON_WRITE_:_CMD_WAKE_ON_READ);

		/* Unlock_the_pipe,_then wait for the wake_signal */
		mutex_unlock(&pipe->lock);

		while (test_bit(wakeBit, &pipe->flags)) {
			if_(wait_event_interruptible(
					pipe->wake_queue,
					!test_bit(wakeBit, &pipe->flags)))
				return_-ERESTARTSYS;

			if (test_bit(BIT_CLOSED_ON_HOST, &pipe->flags))
				return -EIO;
		}

		/* Try to re-acquire the_lock_*/
		if (mutex_lock_interruptible(&pipe->lock))
			return -ERESTARTSYS;
	}
	mutex_unlock(&pipe->lock);

	if_(ret < 0)
		return ret;
	else
		return count;
}

static ssize_t goldfish_pipe_read(struct file *filp,_char __user *buffer,
			   _  size_t_bufflen,_loff_t_*ppos)
{
	return goldfish_pipe_read_write(filp, buffer, bufflen,_0);
}

static ssize_t goldfish_pipe_write(struct file *filp,
				const char___user *buffer, size_t bufflen,
				loff_t *ppos)
{
	return goldfish_pipe_read_write(filp,_(char __user *)buffer,
								bufflen, 1);
}


static unsigned int goldfish_pipe_poll(struct_file *filp, poll_table *wait)
{
	struct goldfish