summaryrefslogtreecommitdiff
path: root/procfs.c
blob: 1fd0d6195355070025086a8e586881117b4b0db4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
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;
}