FreeBSD/sys/compat/cloudabi/cloudabi_file.c
/* Converts a FreeBSD directory entry structure and writes it to userspace. */
Converts a FreeBSD directory entry structure and writes it to userspace.
Converts a FreeBSD directory entry structure and writes it to userspace .
static int
write_dirent(struct dirent *bde, cloudabi_dircookie_t cookie, struct uio *uio)
{
	cloudabi_dirent_t cde = {
		.d_next = cookie,
		.d_ino = bde->d_fileno,
		.d_namlen = bde->d_namlen,
	};
	size_t len;
	int error;
	switch (bde->d_type) {
	case DT_BLK:
		cde.d_type = CLOUDABI_FILETYPE_BLOCK_DEVICE;
		break;
	case DT_CHR:
		cde.d_type = CLOUDABI_FILETYPE_CHARACTER_DEVICE;
		break;
	case DT_DIR:
		cde.d_type = CLOUDABI_FILETYPE_DIRECTORY;
		break;
	case DT_FIFO:
		cde.d_type = CLOUDABI_FILETYPE_FIFO;
		break;
	case DT_LNK:
		cde.d_type = CLOUDABI_FILETYPE_SYMBOLIC_LINK;
		break;
	case DT_REG:
		cde.d_type = CLOUDABI_FILETYPE_REGULAR_FILE;
		break;
	case DT_SOCK:
		cde.d_type = CLOUDABI_FILETYPE_SOCKET_STREAM;
		break;
	default:
		cde.d_type = CLOUDABI_FILETYPE_UNKNOWN;
		break;
	}
	len = sizeof(cde) < uio->uio_resid ? sizeof(cde) : uio->uio_resid;
	error = uiomove(&cde, len, uio);
	if (error != 0)
		return (error);
	len = bde->d_namlen < uio->uio_resid ? bde->d_namlen : uio->uio_resid;
	return (uiomove(bde->d_name, len, uio));
}
static int write_dirent ( struct dirent * bde , cloudabi_dircookie_t cookie , struct uio * uio ) { cloudabi_dirent_t cde = { . d_next = cookie , . d_ino = bde -> d_fileno , . d_namlen = bde -> d_namlen , } ; size_t len ; int error ; switch ( bde -> d_type ) { case DT_BLK : cde . d_type = CLOUDABI_FILETYPE_BLOCK_DEVICE ; break ; case DT_CHR : cde . d_type = CLOUDABI_FILETYPE_CHARACTER_DEVICE ; break ; case DT_DIR : cde . d_type = CLOUDABI_FILETYPE_DIRECTORY ; break ; case DT_FIFO : cde . d_type = CLOUDABI_FILETYPE_FIFO ; break ; case DT_LNK : cde . d_type = CLOUDABI_FILETYPE_SYMBOLIC_LINK ; break ; case DT_REG : cde . d_type = CLOUDABI_FILETYPE_REGULAR_FILE ; break ; case DT_SOCK : cde . d_type = CLOUDABI_FILETYPE_SOCKET_STREAM ; break ; default : cde . d_type = CLOUDABI_FILETYPE_UNKNOWN ; break ; } len = sizeof ( cde ) < uio -> uio_resid ? sizeof ( cde ) : uio -> uio_resid ; error = uiomove ( & cde , len , uio ) ; if ( error != 0 ) return ( error ) ; len = bde -> d_namlen < uio -> uio_resid ? bde -> d_namlen : uio -> uio_resid ; return ( uiomove ( bde -> d_name , len , uio ) ) ; }
Converts a FreeBSD directory entry structure and writes it to userspace.
Converts a FreeBSD directory entry structure and writes it to userspace .
/* Convert file type. */ /* The exact socket type cannot be derived. */ /* Write directory entry structure. */ /* Write filename. */