PatchworkOS
19e446b
A non-POSIX operating system.
Theme:
Default
Round
Robot
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
*/
26
typedef
struct
27
{
28
list_entry_t
entry
;
29
map_entry_t
mapEntry
;
30
char
key[
KEY_MAX
];
31
file_t
*
file
;
32
clock_t
expiry
;
33
}
key_entry_t
;
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
*/
44
uint64_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
*/
52
file_t
*
key_claim
(
const
char
* key);
53
54
/** @} */
key_claim
file_t * key_claim(const char *key)
Claims a shared file using the provided key.
Definition
key.c:148
key_share
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
KEY_MAX
#define KEY_MAX
Maximum size of a key generated by share().
Definition
fs.h:518
clock_t
__UINT64_TYPE__ clock_t
A nanosecond time.
Definition
clock_t.h:13
file.h
fs.h
list.h
map.h
uint64_t
__UINT64_TYPE__ uint64_t
Definition
stdint.h:17
file_t
File structure.
Definition
file.h:39
key_entry_t
Key entry.
Definition
key.h:27
key_entry_t::expiry
clock_t expiry
Definition
key.h:32
key_entry_t::entry
list_entry_t entry
Definition
key.h:28
key_entry_t::file
file_t * file
Definition
key.h:31
key_entry_t::mapEntry
map_entry_t mapEntry
Definition
key.h:29
list_entry_t
A entry in a doubly linked list.
Definition
list.h:37
map_entry_t
Map entry structure.
Definition
map.h:69
include
kernel
fs
key.h
Generated on Sat Jan 24 2026 10:59:24 for PatchworkOS by
1.9.8