src/sys/mm/rmem/main.c
/**
 * @brief Handles a read request.
 *
 * @param remote Remote client.
 * @param blknum Number of the target block.
 * @param outbox Output mailbox to remote client.
 *
 * @returns Upon successful completion, zero is returned. Upon
 * failure, a negative error code is returned instead.
 */
@brief Handles a read request.
@param remote Remote client.
@param blknum Number of the target block.
@param outbox Output mailbox to remote client.

@returns Upon successful completion, zero is returned. Upon
failure, a negative error code is returned instead.
@brief Handles a read request . @param remote Remote client . @param blknum Number of the target block . @param outbox Output mailbox to remote client . @returns Upon successful completion zero is returned . Upon failure a negative error code is returned instead .
static inline int do_rmem_read(int remote, rpage_t blknum, int outbox, int outport)
{
	int ret = 0;
	int outportal;
	rpage_t _blknum;
	struct rmem_message msg;
	msg.header.source = knode_get_num();
	msg.header.opcode = RMEM_ACK;
	rmem_debug("read() nodenum=%d blknum=%x",
		remote,
		blknum
	);
	_blknum = RMEM_BLOCK_NUM(blknum);
	if ((_blknum == RMEM_NULL) || (_blknum >= RMEM_NUM_BLOCKS))
	{
		uprintf("[nanvix][rmem] invalid block number");
		return (-EINVAL);
	}
	if (!bitmap_check_bit(blocks, _blknum))
	{
		uprintf("[nanvix][rmem] bad read block");
		_blknum = 0;
		ret = -EFAULT;
	}
	uassert((outportal =
		kportal_open(
			knode_get_num(),
			remote,
			outport)
		) >= 0
	);
	uassert(
		kmailbox_write(outbox,
			&msg,
			sizeof(struct rmem_message)
		) == sizeof(struct rmem_message)
	);
	uassert(
		kportal_write(
			outportal,
			&rmem[_blknum][0],
			RMEM_BLOCK_SIZE
		) == RMEM_BLOCK_SIZE
	);
	uassert(kportal_close(outportal) == 0);
	return (ret);
}
static inline int do_rmem_read ( int remote , rpage_t blknum , int outbox , int outport ) { int ret = 0 ; int outportal ; rpage_t _blknum ; struct rmem_message msg ; msg . header . source = knode_get_num ( ) ; msg . header . opcode = RMEM_ACK ; rmem_debug ( " " , remote , blknum ) ; _blknum = RMEM_BLOCK_NUM ( blknum ) ; if ( ( _blknum == RMEM_NULL ) || ( _blknum >= RMEM_NUM_BLOCKS ) ) { uprintf ( " " ) ; return ( - EINVAL ) ; } if ( ! bitmap_check_bit ( blocks , _blknum ) ) { uprintf ( " " ) ; _blknum = 0 ; ret = - EFAULT ; } uassert ( ( outportal = kportal_open ( knode_get_num ( ) , remote , outport ) ) >= 0 ) ; uassert ( kmailbox_write ( outbox , & msg , sizeof ( struct rmem_message ) ) == sizeof ( struct rmem_message ) ) ; uassert ( kportal_write ( outportal , & rmem [ _blknum ] [ 0 ] , RMEM_BLOCK_SIZE ) == RMEM_BLOCK_SIZE ) ; uassert ( kportal_close ( outportal ) == 0 ) ; return ( ret ) ; }
@brief Handles a read request.
@brief Handles a read request .
/* Build operation header. */ /* Invalid block number. */ /*
	 * Bad block number. Let us send a null block
	 * and return an error instead.
	 */