diff options
author | Jeremie Koenig <jk@jk.fr.eu.org> | 2010-08-17 09:43:29 +0000 |
---|---|---|
committer | Jeremie Koenig <jk@jk.fr.eu.org> | 2010-08-30 14:14:42 +0200 |
commit | d938e96e59a41d5eaa11040513815b757e58eb0c (patch) | |
tree | 38d1eb581cfeace88ebcd475b44f1a1459654392 /main.c |
Basic infrastructure
* procfs.h: New file; basic interfaces for procfs nodes.
* procfs.c: New file; implement the basic infrastructure.
* netfs.c: New file; bridge libnetfs and the procfs interfaces.
* main.c: New file; mostly a "Hello, World!" for now.
* Makefile: New file; standalone for now.
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 58 |
1 files changed, 58 insertions, 0 deletions
@@ -0,0 +1,58 @@ +#include <mach.h> +#include <error.h> +#include <argp.h> +#include <hurd/netfs.h> +#include "procfs.h" + +static error_t get_contents (void *hook, void **contents, size_t *contents_len) +{ + static const char hello[] = "Hello, World!\n"; + *contents = (void *) hello; + *contents_len = sizeof hello - 1; + return 0; +} + +static error_t get_entries (void *hook, void **contents, size_t *contents_len) +{ + static const char entries[] = "hello"; + *contents = (void *) entries; + *contents_len = sizeof entries; + return 0; +} + +static error_t lookup (void *hook, const char *name, struct node **np) +{ + static const struct procfs_node_ops ops = { .get_contents = get_contents }; + + if (strcmp (name, "hello")) + return ENOENT; + + *np = procfs_make_node (&ops, NULL); + if (! *np) + return ENOMEM; + + return 0; +} + +int main (int argc, char **argv) +{ + static const struct procfs_node_ops ops = { + .get_contents = get_entries, + .lookup = lookup, + }; + mach_port_t bootstrap; + + argp_parse (&netfs_std_startup_argp, argc, argv, 0, 0, 0); + + task_get_bootstrap_port (mach_task_self (), &bootstrap); + if (bootstrap == MACH_PORT_NULL) + error (1, 0, "Must be started as a translator"); + + netfs_init (); + netfs_root_node = procfs_make_node (&ops, NULL); + + netfs_startup (bootstrap, 0); + for (;;) + netfs_server_loop (); +} + |