ZFS
mmap()
PROTOTYPE
#include <posix.h>
void *mmap(void *addr, size_t len, int prot, int flags, int fid, off_t offset);
DESCRIPTION
mmap() maps the file specified by fid into the CPU memory space, making its contents directly accessible. offset is the number of bytes from the file’s beginning at which the mapping starts. The addr, len, flags, and prot parameters are unused.
Blunk’s implementation of mmap() is limited to TargetZFS volumes created with a compression level of 0.
If successful, mmap() returns the address of the file’s memory mapped contents, beginning at the specified offset. Otherwise, it sets errno and returns MAP_FAILED.
ERROR CODES
| EBADF | fid is not the descriptor of a file open in read mode. |
| EINVAL | offset is larger than the file size. |
| ENODEV | The specified file is not on a TargetZFS volume with 0 compression. |
EXAMPLE
/*---------------------------------------------------------------*/
/* Use mmap() to get pointer to file start. */
/*---------------------------------------------------------------*/
ptr = mmap(0, sbuf.st_size, PROT_READ, 0, fid, 0);
if (ptr == NULL)
{
perror("mmap() failed");
return -1;
}