summaryrefslogtreecommitdiff
path: root/procfs.c
diff options
context:
space:
mode:
authorMadhusudan.C.S <madhusudancs@gmail.com>2008-08-14 15:24:00 +0200
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2010-08-01 01:15:27 +0200
commit41ad1a2b52b6479c778a908c3dacee29c47619db (patch)
tree445d8be7a3ee513a2ecc3b663722f8726c0aa77d /procfs.c
2008-08-14 Madhusudan.C.S <madhusudancs@gmail.com>
* ChangeLog: New file added to procfs * AUTHORS: New file added to procfs * COPYING: New file added to procfs * README: New file added to procfs * Makefile: New file added to procfs * bootstrap.c: New file added to procfs * netfs.c: New file added to procfs * node.c: New file added to procfs * procfs.c: New file added to procfs * procfs.h: New file added to procfs * procfs_dir.c: New file added to procfs * procfs_nonpid_files.c: New file added to procfs * procfs_pid.h: New file added to procfs * procfs_pid_files.c: New file added to procfs
Diffstat (limited to 'procfs.c')
-rw-r--r--procfs.c149
1 files changed, 149 insertions, 0 deletions
diff --git a/procfs.c b/procfs.c
new file mode 100644
index 00000000..1fd0d619
--- /dev/null
+++ b/procfs.c
@@ -0,0 +1,149 @@
+/* procfs -- a translator for providing GNU/Linux compatible
+ proc pseudo-filesystem
+
+ procfs.c -- This file is the main file of the translator.
+ This has important definitions and initializes
+ the translator
+
+ Copyright (C) 2008, FSF.
+ Written as a Summer of Code Project
+
+ procfs is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ procfs is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
+*/
+
+#include <stdio.h>
+#include <argp.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include <unistd.h>
+#include <error.h>
+#include <sys/stat.h>
+#include <hurd/netfs.h>
+
+#include "procfs.h"
+
+/* Defines this Tanslator Name */
+char *netfs_server_name = PROCFS_SERVER_NAME;
+char *netfs_server_version = PROCFS_SERVER_VERSION;
+int netfs_maxsymlinks = 12;
+
+static const struct argp_child argp_children[] =
+ {
+ {&netfs_std_startup_argp, 0, NULL, 0},
+ {0}
+ };
+
+
+const char *argp_program_version = "/proc pseudo-filesystem (" PROCFS_SERVER_NAME
+ ") " PROCFS_SERVER_VERSION "\n"
+"Copyright (C) 2008 Free Software Foundation\n"
+"This is free software; see the source for copying conditions. There is NO\n"
+"warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
+"\n";
+
+static char *args_doc = "PROCFSROOT";
+static char *doc = "proc pseudo-filesystem for Hurd implemented as a translator. "
+"This is still under very humble and initial stages of development.\n"
+"Any Contribution or help is welcome. The code may not even compile";
+
+
+/* The Filesystem */
+struct procfs *procfs;
+
+/* The FILESYSTEM component of PROCFS_FS. */
+char *procfs_root = "";
+
+volatile struct mapped_time_value *procfs_maptime;
+
+/* Startup options. */
+static const struct argp_option procfs_options[] =
+ {
+ { 0 }
+ };
+
+
+/* argp parser function for parsing single procfs command line options */
+static error_t
+parse_procfs_opt (int key, char *arg, struct argp_state *state)
+{
+ switch (key)
+ {
+ case ARGP_KEY_ARG:
+ if (state->arg_num > 1)
+ argp_usage (state);
+ break;
+
+ case ARGP_KEY_NO_ARGS:
+ argp_usage(state);
+ break;
+
+ default:
+ return ARGP_ERR_UNKNOWN;
+ }
+}
+
+/* Program entry point. */
+int
+main (int argc, char **argv)
+{
+ error_t err;
+ mach_port_t bootstrap, underlying_node;
+ struct stat underlying_stat;
+
+ struct argp argp =
+ {
+ procfs_options, parse_procfs_opt,
+ args_doc, doc, argp_children,
+ NULL, NULL
+ };
+
+
+ /* Parse the command line arguments */
+// argp_parse (&argp, argc, argv, 0, 0, 0);
+
+ task_get_bootstrap_port (mach_task_self (), &bootstrap);
+
+ netfs_init ();
+
+ if (maptime_map (0, 0, &procfs_maptime))
+ {
+ perror (PROCFS_SERVER_NAME ": Cannot map time");
+ return 1;
+ }
+
+ procfs_init ();
+
+ err = procfs_create (procfs_root, getpid (), &procfs);
+ if (err)
+ error (4, err, "%s", procfs_root);
+
+ /* Create our root node */
+ netfs_root_node = procfs->root;
+
+ /* Start netfs activities */
+ underlying_node = netfs_startup (bootstrap, 0);
+ if (io_stat (underlying_node, &underlying_stat))
+ error (1, err, "cannot stat underling node");
+
+ /* Initialize stat information of the root node. */
+ netfs_root_node->nn_stat = underlying_stat;
+ netfs_root_node->nn_stat.st_mode =
+ S_IFDIR | (underlying_stat.st_mode & ~S_IFMT & ~S_ITRANS);
+
+ for (;;)
+ netfs_server_loop ();
+ return 1;
+}