Drop main() prototype. Syncs with NetBSD-8
[minix.git] / minix / fs / ptyfs / node.c
blob0840eb6697d6793557a3cd089e5afc7e7da203e1
1 /* PTYFS slave node management */
2 /*
3 * While the interface of this module should be flexible enough to implement
4 * various memory management approaches, the current code simply relies on
5 * NR_PTYS being small enough to preallocate all data structures. In the
6 * future, NR_PTYS will no longer be a system-global definition, and future
7 * implementations of this module should not rely on NR_PTYS at all.
8 */
10 #include <minix/drivers.h>
12 #include "node.h"
14 static bitchunk_t node_map[BITMAP_CHUNKS(NR_PTYS)];
15 static struct node_data node_data[NR_PTYS];
18 * Initialize the node module.
20 void
21 init_nodes(void)
24 memset(&node_map, 0, sizeof(node_map));
28 * Allocate a node with a given node index number, and save node data for it.
29 * It is possible that the node is in use already; in that case, only update
30 * its associated data. Return OK on success, or an error code on failure.
32 int
33 set_node(node_t index, struct node_data * data)
36 if (index >= NR_PTYS)
37 return ENOMEM;
39 SET_BIT(node_map, index);
41 node_data[index] = *data;
43 return OK;
47 * Deallocate a node using its node index number. This function always
48 * succeeds, intentionally ignoring the case that the node was not allocated.
50 void
51 clear_node(node_t index)
54 UNSET_BIT(node_map, index);
58 * Return a pointer to the node data associated with the given node index
59 * number. If the node is not allocated, return NULL.
61 struct node_data *
62 get_node(node_t index)
65 if (index >= NR_PTYS || !GET_BIT(node_map, index))
66 return NULL;
68 return &node_data[index];
72 * Return the highest allocated node index number, plus one. This value is
73 * used to check given node indices and limit linear iterations.
75 node_t
76 get_max_node(void)
80 * NR_PTYS is low enough that we can always return it instead of
81 * tracking the actual value.
83 return NR_PTYS;