예제 #1
0
파일: fileio.c 프로젝트: AzagraMac/PS2_SDK
int fioRead(int fd, void *ptr, int size)
{
	struct _fio_read_arg arg;
	int res;

	if ((res = fioInit()) < 0)
		return res;

	WaitSema(_fio_completion_sema);

	arg.fd      = fd;
	arg.ptr       = ptr;
	arg.size      = size;
	arg.read_data = (struct _fio_read_data *)_fio_intr_data;

	if (!IS_UNCACHED_SEG(ptr))
		SifWriteBackDCache(ptr, size);
	SifWriteBackDCache(_fio_intr_data, 128);
	SifWriteBackDCache(&arg, sizeof(arg));

	if ((res = SifCallRpc(&_fio_cd, FIO_F_READ, _fio_block_mode, &arg, sizeof arg,
					_fio_recv_data, 4, (void *)_fio_read_intr, _fio_intr_data)) < 0)
		return res;

	if(_fio_block_mode == FIO_NOWAIT)
		return 0;
	else
		return _fio_recv_data[0];
}
예제 #2
0
int sendto(int s, void *dataptr, int size, unsigned int flags,
		struct sockaddr *to, int tolen)
{
	send_pkt *pkt = (send_pkt *)_rpc_buffer;
	int miss;

	pkt->socket = s;
	pkt->length = size;
	pkt->flags = flags;
	pkt->ee_addr = dataptr;
	memcpy((void *)&pkt->sockaddr, (void *)to, sizeof(struct sockaddr));

	if((u32)dataptr & 0xf)
	{
		miss = 16 - ((u32)dataptr & 0xf);
		if(miss > size) miss = size;

	} else {

		miss = 0;
	}

	pkt->malign = miss;

	if( !IS_UNCACHED_SEG(dataptr))
		SifWriteBackDCache(dataptr, size);

	memcpy((void *)pkt->malign_buff, UNCACHED_SEG(dataptr), miss);

	SifCallRpc(&_ps2ip, ID_SENDTO, 0, (void*)_rpc_buffer, sizeof(send_pkt), 
				(void*)_rpc_buffer, 4, 0, 0);

	return _rpc_buffer[0];
}
예제 #3
0
int recvfrom(int s, void *mem, int len, unsigned int flags,
		  struct sockaddr *from, int *fromlen)
{
	s_recv_pkt *send_pkt = (s_recv_pkt *)_rpc_buffer;
	r_recv_pkt *recv_pkt = (r_recv_pkt *)_rpc_buffer;

	if(!_init_check) return -1;

	send_pkt->socket = s;
	send_pkt->length = len;
	send_pkt->flags = flags;
	send_pkt->ee_addr = mem;
	send_pkt->intr_data = _intr_data;

	if( !IS_UNCACHED_SEG(mem))
		SifWriteBackDCache(mem, len);
	SifWriteBackDCache(_intr_data, 128);
	SifWriteBackDCache(_rpc_buffer, sizeof(s_recv_pkt));

	SifCallRpc(&_ps2ip, ID_RECVFROM, 0, (void*)_rpc_buffer, sizeof(s_recv_pkt), 
				(void*)_rpc_buffer, sizeof(r_recv_pkt), recv_intr, _intr_data);

	memcpy((void *)from, (void *)&recv_pkt->sockaddr, sizeof(struct sockaddr));
	*fromlen = sizeof(struct sockaddr);

	return recv_pkt->ret;
}
예제 #4
0
파일: fileio.c 프로젝트: scuriumk/ps2sdk
int fioGetstat(const char *name, fio_stat_t *buf)
{
	struct _fio_getstat_arg arg;
	int res, result;

	if ((res = fioInit()) < 0)
		return res;

	WaitSema(_fio_completion_sema);

	arg.p.buf = buf;
	strncpy(arg.name, name, FIO_PATH_MAX - 1);
	arg.name[FIO_PATH_MAX - 1] = 0;

	if (!IS_UNCACHED_SEG(buf))
		SifWriteBackDCache(buf, sizeof(fio_stat_t));

	if ((res = SifCallRpc(&_fio_cd, FIO_F_GETSTAT, 0, &arg, sizeof arg,
					&arg, 4, (void *)_fio_intr, NULL)) >= 0)
	{
		result=arg.p.result;
	}
	else
	{
		result=res;
	}

	return result;
}
예제 #5
0
파일: fileio.c 프로젝트: scuriumk/ps2sdk
int fioDread(int fd, fio_dirent_t *buf)
{
	struct _fio_dread_arg arg;
	int res, result;

	if ((res = fioInit()) < 0)
		return res;

	WaitSema(_fio_completion_sema);

	arg.p.fd = fd;
	arg.buf = buf;

	if (!IS_UNCACHED_SEG(buf))
		SifWriteBackDCache(buf, sizeof(fio_dirent_t));

	if ((res = SifCallRpc(&_fio_cd, FIO_F_DREAD, 0, &arg, sizeof arg,
					&arg, 4, (void *)_fio_intr, NULL)) >= 0)
	{
		result=arg.p.result;
	}
	else
	{
		result=res;
	}

	return result;
}
예제 #6
0
파일: fileio.c 프로젝트: scuriumk/ps2sdk
int fioWrite(int fd, const void *ptr, int size)
{
	struct _fio_write_arg arg;
	int mis, res, result;

	if ((res = fioInit()) < 0)
		return res;

	WaitSema(_fio_completion_sema);

	arg.fd = fd;
	arg.ptr  = ptr;
	arg.size = size;

	/* Copy the unaligned (16-byte) portion into the argument */
	mis = 0;
	if ((u32)ptr & 0xf) {
		mis = 16 - ((u32)ptr & 0xf);
		if (mis > size)
			mis = size;
	}
	arg.mis = mis;

	if (mis)
		memcpy(arg.aligned, ptr, mis);

	if (!IS_UNCACHED_SEG(ptr))
		SifWriteBackDCache((void*)ptr, size);

	if ((res = SifCallRpc(&_fio_cd, FIO_F_WRITE, _fio_block_mode, &arg, sizeof arg,
					_fio_recv_data, 4, (void *)_fio_intr, NULL)) >= 0)
	{
		result=(_fio_block_mode == FIO_NOWAIT)?0:_fio_recv_data[0];
	}
	else
	{
		result=res;
	}

	return result;
}