summaryrefslogtreecommitdiff
path: root/procfs_dir.h
diff options
context:
space:
mode:
authorJeremie Koenig <jk@jk.fr.eu.org>2010-08-23 14:15:54 +0000
committerJeremie Koenig <jk@jk.fr.eu.org>2010-08-30 14:31:31 +0200
commitf522af65aa004fea09705c74115836c6acd1cddb (patch)
tree9de6222c1be5b8e1f678801233436796ea753a94 /procfs_dir.h
parent4646c4a3ef6171a0ddec4fcfe0c6aa34b50501cd (diff)
Revamp procfs_dir
* procfs_dir.c, procfs_dir.h: Revamp the interface to make the more complicated use cases somewhat less hackish. * process.c: Update, specify a default make_node function. * rootdir.c: Likewise; make this optional "self" link use case somewhat less hackish.
Diffstat (limited to 'procfs_dir.h')
-rw-r--r--procfs_dir.h48
1 files changed, 36 insertions, 12 deletions
diff --git a/procfs_dir.h b/procfs_dir.h
index 4eb934e..12e99d2 100644
--- a/procfs_dir.h
+++ b/procfs_dir.h
@@ -1,20 +1,44 @@
+/* This module provides an abstraction layer for implementing simple
+ directories with (mostly) static contents. The user defines the
+ contents of the directory by providing a table of entries and various
+ optional callback functions. */
-/* Each entry associates a name with a callback function for creating new
- nodes corresponding to that entry. */
+/* These operations define how a given entry will behave. Either can be
+ omitted, both from the entry-specific operations and from the
+ directory-wide defaults. */
+struct procfs_dir_entry_ops
+{
+ /* Called when this entry is looked up to create a corresponding node. */
+ struct node *(*make_node)(void *dir_hook, const void *entry_hook);
+ /* If this is provided and returns 0, this entry will be hidden. */
+ int (*exists)(void *dir_hook, const void *entry_hook);
+};
+
+/* Describes an individual directory entry, associating a NAME with
+ * arbitrary HOOK data and node-specific OPS. */
struct procfs_dir_entry
{
const char *name;
- struct node *(*make_node)(void *dir_hook, void *entry_hook);
- void *hook;
+ const void *hook;
+ struct procfs_dir_entry_ops ops;
+};
+
+/* Describes a complete directory. ENTRIES is a table terminated by a
+ null NAME field. ENTRY_OPS provides default operations for the
+ entries which don't specify them. The optional CLEANUP function
+ should release all the resources associated with the directory hook. */
+struct procfs_dir_ops
+{
+ const struct procfs_dir_entry *entries;
+ void (*cleanup)(void *dir_hook);
+ struct procfs_dir_entry_ops entry_ops;
};
-/* A simple directory is built from a table of entries. The table is
- terminated by a null NAME pointer. The DIR_HOOK is passed the
- MAKE_NODE callback function of looked up procfs_dir_entries, and to
- the provided CLEANUP function when the directory is destroyed.
- Returns the new directory node. If not enough memory can be
- allocated, CLEANUP is invoked immediately and NULL is returned. */
+/* Create and return a new node for the directory described in OPS.
+ The DIR_HOOK is passed the MAKE_NODE callback function of looked up
+ entries, as well as to the CLEANUP callback when the node is
+ destroyed. If not enough memory can be allocated, OPS->CLEANUP is
+ invoked immediately and NULL is returned. */
struct node *
-procfs_dir_make_node (const struct procfs_dir_entry *entries,
- void *dir_hook, void (*cleanup) (void *dir_hook));
+procfs_dir_make_node (const struct procfs_dir_ops *ops, void *dir_hook);