#include <metal/utilities.h>
#include <metal/sys.h>
|
int | metal_open (const char *path, int shm) |
| Open (or create) a file.
|
|
int | metal_open_unlinked (const char *path, int shm) |
| Open (or create) and unlink a file.
|
|
void | metal_randomize_string (char *template) |
| Randomize a string.
|
|
void | metal_mktemp_template (char template[PATH_MAX], const char *name) |
| Create a file name template suitable for use with metal_mktemp.
|
|
int | metal_mktemp (char *template, int fifo) |
| Create a temporary file or fifo.
|
|
int | metal_mktemp_unlinked (char *template) |
| Open (or create) and unlink a temporary file.
|
|
int | metal_map (int fd, off_t offset, size_t size, int expand, int flags, void **result) |
| Map a segment of a file/device.
|
|
int | metal_unmap (void *mem, size_t size) |
| Unmap a segment of the process address space.
|
|
int | metal_mlock (void *mem, size_t size) |
| Lock in a region of the process address space.
|
|
int | metal_virt2phys (void *addr, unsigned long *phys) |
|
◆ 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] | fd | File descriptor to map. |
[in] | offset | Offset in file to map. |
[in] | size | Size of region to map. |
[in] | expand | Allow file expansion via ftruncate if non-zero. |
[in] | flags | Flags for mmap(), MAP_SHARED included implicitly. |
[out] | result | Returned pointer to new memory map. |
- Returns
- 0 on success, or -errno on error.
◆ metal_mktemp()
int metal_mktemp |
( |
char * | template, |
|
|
int | fifo ) |
Create a temporary file or fifo.
This function creates a temporary file or fifo, and sets the O_CLOEXEC flag on it.
- Parameters
-
[in] | template | File name template (the last 6 characters must be XXXXXX per mkstemp requirements). |
[in] | fifo | Non-zero to create a FIFO instead of a regular file. |
- Returns
- File descriptor.
◆ metal_mktemp_template()
void metal_mktemp_template |
( |
char | template[PATH_MAX], |
|
|
const char * | name ) |
Create a file name template suitable for use with metal_mktemp.
- Parameters
-
[out] | template | Template string to be filled in. |
[in] | name | Module/user identifier used as part of the generated template. |
◆ metal_mktemp_unlinked()
int metal_mktemp_unlinked |
( |
char * | template | ) |
|
Open (or create) and unlink a temporary file.
This function creates a temporary file, and sets the O_CLOEXEC flag on it. O_CLOEXEC flag set. This file is then unlinked to ensure that it is removed when the last reference to the file is dropped. This ensures that libmetal shared maps are released appropriately once all users of the shared data exit.
- Parameters
-
[in] | template | File name template (the last 6 characters must be XXXXXX per mkstemp requirements). |
- Returns
- File descriptor.
◆ metal_mlock()
int metal_mlock |
( |
void * | mem, |
|
|
size_t | size ) |
Lock in a region of the process address space.
- Parameters
-
[in] | mem | Pointer to start of region. |
[in] | size | Size of region. |
- 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] | path | File path to open. |
[in] | shm | Open shared memory (via shm_open) if non-zero. |
- Returns
- File descriptor.
◆ metal_open_unlinked()
int metal_open_unlinked |
( |
const char * | path, |
|
|
int | shm ) |
Open (or create) and unlink a file.
This function opens or creates a file with read/write permissions and the O_CLOEXEC flag set. This file is then unlinked to ensure that it is removed when the last reference to the file is dropped. This ensures that libmetal shared maps are released appropriately once all users of the shared data exit.
- Parameters
-
[in] | path | File path to open. |
[in] | shm | Open shared memory (via shm_open) if non-zero. |
- Returns
- File descriptor.
◆ metal_randomize_string()
void metal_randomize_string |
( |
char * | template | ) |
|
Randomize a string.
This function randomizes the contents of a string.
- Parameters
-
[in] | template | String to be randomized. |
◆ 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] | mem | Segment to unmap. |
[in] | size | Size of region to unmap. |
- Returns
- 0 on success, or -errno on error.
◆ metal_virt2phys()
int metal_virt2phys |
( |
void * | addr, |
|
|
unsigned long * | phys ) |