FreeBSD/sys/compat/cloudabi/cloudabi_fd.c
/* Converts a file descriptor to a CloudABI file descriptor type. */
Converts a file descriptor to a CloudABI file descriptor type.
Converts a file descriptor to a CloudABI file descriptor type .
cloudabi_filetype_t
cloudabi_convert_filetype(const struct file *fp)
{
	struct socket *so;
	struct vnode *vp;
	switch (fp->f_type) {
	case DTYPE_FIFO:
		return (CLOUDABI_FILETYPE_FIFO);
	case DTYPE_KQUEUE:
		return (CLOUDABI_FILETYPE_POLL);
	case DTYPE_PIPE:
		return (CLOUDABI_FILETYPE_FIFO);
	case DTYPE_PROCDESC:
		return (CLOUDABI_FILETYPE_PROCESS);
	case DTYPE_SHM:
		return (CLOUDABI_FILETYPE_SHARED_MEMORY);
	case DTYPE_SOCKET:
		so = fp->f_data;
		switch (so->so_type) {
		case SOCK_DGRAM:
			return (CLOUDABI_FILETYPE_SOCKET_DGRAM);
		case SOCK_SEQPACKET:
			return (CLOUDABI_FILETYPE_SOCKET_SEQPACKET);
		case SOCK_STREAM:
			return (CLOUDABI_FILETYPE_SOCKET_STREAM);
		default:
			return (CLOUDABI_FILETYPE_UNKNOWN);
		}
	case DTYPE_VNODE:
		vp = fp->f_vnode;
		switch (vp->v_type) {
		case VBLK:
			return (CLOUDABI_FILETYPE_BLOCK_DEVICE);
		case VCHR:
			return (CLOUDABI_FILETYPE_CHARACTER_DEVICE);
		case VDIR:
			return (CLOUDABI_FILETYPE_DIRECTORY);
		case VFIFO:
			return (CLOUDABI_FILETYPE_FIFO);
		case VLNK:
			return (CLOUDABI_FILETYPE_SYMBOLIC_LINK);
		case VREG:
			return (CLOUDABI_FILETYPE_REGULAR_FILE);
		case VSOCK:
			return (CLOUDABI_FILETYPE_SOCKET_STREAM);
		default:
			return (CLOUDABI_FILETYPE_UNKNOWN);
		}
	default:
		return (CLOUDABI_FILETYPE_UNKNOWN);
	}
}
cloudabi_filetype_t cloudabi_convert_filetype ( const struct file * fp ) { struct socket * so ; struct vnode * vp ; switch ( fp -> f_type ) { case DTYPE_FIFO : return ( CLOUDABI_FILETYPE_FIFO ) ; case DTYPE_KQUEUE : return ( CLOUDABI_FILETYPE_POLL ) ; case DTYPE_PIPE : return ( CLOUDABI_FILETYPE_FIFO ) ; case DTYPE_PROCDESC : return ( CLOUDABI_FILETYPE_PROCESS ) ; case DTYPE_SHM : return ( CLOUDABI_FILETYPE_SHARED_MEMORY ) ; case DTYPE_SOCKET : so = fp -> f_data ; switch ( so -> so_type ) { case SOCK_DGRAM : return ( CLOUDABI_FILETYPE_SOCKET_DGRAM ) ; case SOCK_SEQPACKET : return ( CLOUDABI_FILETYPE_SOCKET_SEQPACKET ) ; case SOCK_STREAM : return ( CLOUDABI_FILETYPE_SOCKET_STREAM ) ; default : return ( CLOUDABI_FILETYPE_UNKNOWN ) ; } case DTYPE_VNODE : vp = fp -> f_vnode ; switch ( vp -> v_type ) { case VBLK : return ( CLOUDABI_FILETYPE_BLOCK_DEVICE ) ; case VCHR : return ( CLOUDABI_FILETYPE_CHARACTER_DEVICE ) ; case VDIR : return ( CLOUDABI_FILETYPE_DIRECTORY ) ; case VFIFO : return ( CLOUDABI_FILETYPE_FIFO ) ; case VLNK : return ( CLOUDABI_FILETYPE_SYMBOLIC_LINK ) ; case VREG : return ( CLOUDABI_FILETYPE_REGULAR_FILE ) ; case VSOCK : return ( CLOUDABI_FILETYPE_SOCKET_STREAM ) ; default : return ( CLOUDABI_FILETYPE_UNKNOWN ) ; } default : return ( CLOUDABI_FILETYPE_UNKNOWN ) ; } }
Converts a file descriptor to a CloudABI file descriptor type.
Converts a file descriptor to a CloudABI file descriptor type .