PatchworkOS  966e257
A non-POSIX operating system.
Loading...
Searching...
No Matches
key.h
Go to the documentation of this file.
1#pragma once
2
3#include <kernel/fs/file.h>
4#include <kernel/utils/map.h>
5
6#include <sys/io.h>
7#include <sys/list.h>
8
9/**
10 * @brief Keys for sharing file descriptors between processes.
11 * @defgroup kernel_fs_key Keys
12 * @ingroup kernel_fs
13 *
14 * Keys are used with the `share()` and `claim()` system calls to send files between processes.
15 *
16 * Each key is a 64-bit one-time use randomly generated token that globally identifies a shared file.
17 *
18 * @{
19 */
20
21/**
22 * @brief Key entry.
23 */
24typedef struct
25{
26 list_entry_t entry; ///< Used to store the key entry in a time sorted list.
27 map_entry_t mapEntry; ///< Used to store the key entry in a map for fast lookup.
32
33/**
34 * @brief Generates a key that can be used to retrieve the file within the specified timeout.
35 *
36 * @param key Output pointer to store the generated key.
37 * @param file The file to share.
38 * @param timeout The time until the shared file expires. If `CLOCKS_NEVER`, it never expires.
39 * @return On success, a key that can be used to claim the file. On failure, `ERR` and `errno` is set.
40 */
41uint64_t key_share(key_t* key, file_t* file, clock_t timeout);
42
43/**
44 * @brief Claims a shared file using the provided key.
45 *
46 * @param key Pointer to the key identifying the shared file.
47 * @return On success, the claimed file. On failure, `NULL` and `errno` is set.
48 */
50
51/** @} */
file_t * key_claim(key_t *key)
Claims a shared file using the provided key.
Definition key.c:142
uint64_t key_share(key_t *key, file_t *file, clock_t timeout)
Generates a key that can be used to retrieve the file within the specified timeout.
Definition key.c:62
__UINT64_TYPE__ clock_t
A nanosecond time.
Definition clock_t.h:13
static dentry_t * file
Definition log_file.c:22
__UINT64_TYPE__ uint64_t
Definition stdint.h:17
File structure.
Definition file.h:39
Key entry.
Definition key.h:25
clock_t expiry
Definition key.h:30
key_t key
Definition key.h:28
list_entry_t entry
Used to store the key entry in a time sorted list.
Definition key.h:26
file_t * file
Definition key.h:29
map_entry_t mapEntry
Used to store the key entry in a map for fast lookup.
Definition key.h:27
Key type.
Definition io.h:454
A entry in a doubly linked list.
Definition list.h:36
Map entry structure.
Definition map.h:68