1 /* PTYFS slave node management */
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.
10 #include <minix/drivers.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.
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.
33 set_node(node_t index
, struct node_data
* data
)
39 SET_BIT(node_map
, index
);
41 node_data
[index
] = *data
;
47 * Deallocate a node using its node index number. This function always
48 * succeeds, intentionally ignoring the case that the node was not allocated.
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.
62 get_node(node_t index
)
65 if (index
>= NR_PTYS
|| !GET_BIT(node_map
, index
))
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.
80 * NR_PTYS is low enough that we can always return it instead of
81 * tracking the actual value.