libmetal  353
utilities.c File Reference

Linux libmetal utility functions. More...

#include <metal/utilities.h>
#include <metal/sys.h>

Functions

int metal_open (const char *path, int shm)
 Open (or create) a file. More...
 
int metal_map (int fd, off_t offset, size_t size, int expand, int flags, void **result)
 Map a segment of a file/device. More...
 
int metal_unmap (void *mem, size_t size)
 Unmap a segment of the process address space. More...
 

Detailed Description

Linux libmetal utility functions.

Function Documentation

◆ metal_map()

int metal_map ( int  fd,
off_t  offset,
size_t  size,
int  expand,
int  flags,
void **  result 
)

Map a segment of a file/device.

This function maps a segment of a file or device into the process address space, after optionally expanding the file if necessary. If required, the file is expanded to hold the requested map area. This is done under and advisory lock, and therefore the called must not have an advisory lock on the file being mmapped.

Parameters
[in]fdFile descriptor to map.
[in]offsetOffset in file to map.
[in]sizeSize of region to map.
[in]expandAllow file expansion via ftruncate if non-zero.
[in]flagsFlags for mmap(), MAP_SHARED included implicitly.
[out]resultReturned pointer to new memory map.
Returns
0 on success, or -errno on error.

◆ metal_open()

int metal_open ( const char *  path,
int  shm 
)

Open (or create) a file.

This function opens or creates a file with read/write permissions and the O_CLOEXEC flag set.

Parameters
[in]pathFile path to open.
[in]shmOpen shared memory (via shm_open) if non-zero.
Returns
File descriptor.

◆ metal_unmap()

int metal_unmap ( void *  mem,
size_t  size 
)

Unmap a segment of the process address space.

This function unmaps a segment of the process address space.

Parameters
[in]memSegment to unmap.
[in]sizeSize of region to unmap.
Returns
0 on success, or -errno on error.