PatchworkOS  19e446b
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/fs.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 one-time use randomly generated base64URL encoded string that globally identifies a shared file.
17 *
18 * @see https://en.wikipedia.org/wiki/Base64
19 *
20 * @{
21 */
22
23/**
24 * @brief Key entry.
25 */
34
35/**
36 * @brief Generates a key that can be used to retrieve the file within the specified timeout.
37 *
38 * @param key Output buffer to store the generated key.
39 * @param size The size of the output buffer.
40 * @param file The file to share.
41 * @param timeout The time until the shared file expires. If `CLOCKS_NEVER`, it never expires.
42 * @return On success, a key that can be used to claim the file. On failure, `ERR` and `errno` is set.
43 */
44uint64_t key_share(char* key, uint64_t size, file_t* file, clock_t timeout);
45
46/**
47 * @brief Claims a shared file using the provided key.
48 *
49 * @param key The key identifying the shared file.
50 * @return On success, the claimed file. On failure, `NULL` and `errno` is set.
51 */
52file_t* key_claim(const char* key);
53
54/** @} */
file_t * key_claim(const char *key)
Claims a shared file using the provided key.
Definition key.c:148
uint64_t key_share(char *key, uint64_t size, file_t *file, clock_t timeout)
Generates a key that can be used to retrieve the file within the specified timeout.
Definition key.c:87
#define KEY_MAX
Maximum size of a key generated by share().
Definition fs.h:518
__UINT64_TYPE__ clock_t
A nanosecond time.
Definition clock_t.h:13
__UINT64_TYPE__ uint64_t
Definition stdint.h:17
File structure.
Definition file.h:39
Key entry.
Definition key.h:27
clock_t expiry
Definition key.h:32
list_entry_t entry
Definition key.h:28
file_t * file
Definition key.h:31
map_entry_t mapEntry
Definition key.h:29
A entry in a doubly linked list.
Definition list.h:37
Map entry structure.
Definition map.h:69