2 * Copyright (C) 1997,98,2002 Free Software Foundation Inc.
3 * Copyright (C) 2013 Steven McDonald <steven@steven-mcdonald.id.au>
5 * ftpfs translator written by Miles Bader <miles@gnu.org>
6 * Modified for trovefs by Steven McDonald <steven@steven-mcdonald.id.au>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2, or (at your option)
13 * This software is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
23 #include <sys/types.h>
27 #include <hurd/netfs.h>
30 char *netfs_server_name = "trovefs";
31 char *netfs_server_version = TROVEFS_VERSION;
33 const char *argp_program_version = "trovefs " TROVEFS_VERSION;
35 static char args_doc[] = "BUCKET";
36 static char doc[] = "Trove filesystem translator."
37 "\vIf --hostname is not specified, it defaults to"
38 " \"" TROVEFS_DEFAULT_HOSTNAME "\".";
40 static struct argp_option options[] =
42 {"hostname", 'h', "HOSTNAME", 0, "S3 server hostname to connect to"},
43 {"access-key-id", 'i', "ID", 0, "Access key ID for S3 server"},
44 {"secret-access-key", 'k', "KEY", 0, "Secret access key for S3 server"},
54 char *secret_access_key;
58 parse_opt (int key, char *arg, struct argp_state *state)
60 struct arguments *arguments = state->input;
65 arguments->hostname = arg;
68 arguments->access_key_id = arg;
71 arguments->secret_access_key = arg;
74 if (state->arg_num >= 1)
76 arguments->args[state->arg_num] = arg;
79 if (state->arg_num < 1)
83 return ARGP_ERR_UNKNOWN;
88 static struct argp argp = { options, parse_opt, args_doc, doc };
90 int netfs_maxsymlinks = 0;
93 main (int argc, char *argv[])
96 mach_port_t bootstrap, underlying_node;
97 io_statbuf_t underlying_stat;
98 struct arguments *arguments = malloc (sizeof (struct arguments));
99 arguments->hostname = TROVEFS_DEFAULT_HOSTNAME;
101 argp_parse (&argp, argc, argv, 0, 0, arguments);
103 struct trovefs *trovefs;
105 task_get_bootstrap_port (mach_task_self (), &bootstrap);
109 err = trovefs_create (
111 arguments->args[0], // Bucket.
112 arguments->access_key_id,
113 arguments->secret_access_key,
119 // FIXME: Why the fuck is 'error' broken?
120 // error (1, err, "%s:%s", arguments->hostname, arguments->args[0]);
122 netfs_root_node = trovefs->root;
124 underlying_node = netfs_startup (bootstrap, 0);
125 err = io_stat (underlying_node, &underlying_stat);
129 netfs_root_node->nn_stat = underlying_stat;
130 netfs_root_node->nn_stat.st_mode = S_IFDIR | (underlying_stat.st_mode & ~S_IFMT & ~S_ITRANS);
133 netfs_server_loop ();