summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames A. Morrison <a2morri@csclub.uwaterloo.ca>2002-04-16 00:40:18 +0000
committerJames A. Morrison <a2morri@csclub.uwaterloo.ca>2002-04-16 00:40:18 +0000
commitef64f2ceeaa2583b6622b1f90cea591137d8f51a (patch)
tree19140f5b32dbb221283e8fa1025c6d068cdb06cb
Import gopherfs
-rw-r--r--COPYING340
-rw-r--r--Makefile33
-rw-r--r--NOTES4
-rw-r--r--args.c93
-rw-r--r--gopher.c179
-rw-r--r--gopherfs.c99
-rw-r--r--gopherfs.h116
-rw-r--r--netfs.c482
-rw-r--r--node.c142
9 files changed, 1488 insertions, 0 deletions
diff --git a/COPYING b/COPYING
new file mode 100644
index 000000000..d60c31a97
--- /dev/null
+++ b/COPYING
@@ -0,0 +1,340 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
+ 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users. This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it. (Some other Free Software Foundation software is covered by
+the GNU Library General Public License instead.) You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+ To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have. You must make sure that they, too, receive or can get the
+source code. And you must show them these terms so they know their
+rights.
+
+ We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+ Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software. If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+ Finally, any free program is threatened constantly by software
+patents. We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary. To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ GNU GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License. The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language. (Hereinafter, translation is included without limitation in
+the term "modification".) Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+ 1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+ 2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) You must cause the modified files to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ b) You must cause any work that you distribute or publish, that in
+ whole or in part contains or is derived from the Program or any
+ part thereof, to be licensed as a whole at no charge to all third
+ parties under the terms of this License.
+
+ c) If the modified program normally reads commands interactively
+ when run, you must cause it, when started running for such
+ interactive use in the most ordinary way, to print or display an
+ announcement including an appropriate copyright notice and a
+ notice that there is no warranty (or else, saying that you provide
+ a warranty) and that users may redistribute the program under
+ these conditions, and telling the user how to view a copy of this
+ License. (Exception: if the Program itself is interactive but
+ does not normally print such an announcement, your work based on
+ the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+ a) Accompany it with the complete corresponding machine-readable
+ source code, which must be distributed under the terms of Sections
+ 1 and 2 above on a medium customarily used for software interchange; or,
+
+ b) Accompany it with a written offer, valid for at least three
+ years, to give any third party, for a charge no more than your
+ cost of physically performing source distribution, a complete
+ machine-readable copy of the corresponding source code, to be
+ distributed under the terms of Sections 1 and 2 above on a medium
+ customarily used for software interchange; or,
+
+ c) Accompany it with the information you received as to the offer
+ to distribute corresponding source code. (This alternative is
+ allowed only for noncommercial distribution and only if you
+ received the program in object code or executable form with such
+ an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it. For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable. However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License. Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+ 5. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Program or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+ 6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+ 7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all. For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded. In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+ 9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation. If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+ 10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission. For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this. Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+ NO WARRANTY
+
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the program's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ This program 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 of the License, or
+ (at your option) any later version.
+
+ This program 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-1307 USA
+
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
+
+ Gnomovision version 69, Copyright (C) year name of author
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, the commands you use may
+be called something other than `show w' and `show c'; they could even be
+mouse-clicks or menu items--whatever suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the program, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+ <signature of Ty Coon>, 1 April 1989
+ Ty Coon, President of Vice
+
+This General Public License does not permit incorporating your program into
+proprietary programs. If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library. If this is what you want to do, use the GNU Library General
+Public License instead of this License.
diff --git a/Makefile b/Makefile
new file mode 100644
index 000000000..d7396c419
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,33 @@
+# Makefile for gopherfs
+#
+# Copyright (C) 1997, 2000 Free Software Foundation, Inc.
+#
+# This program 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.
+#
+# This program 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+dir := gopherfs
+makemode := server
+
+target = gopherfs
+
+#SRCS = ftpfs.c fs.c host.c netfs.c dir.c conn.c ccache.c node.c ncache.c
+SRCS = gopherfs.c args.c netfs.c gopher.c node.c
+#LCLHDRS = ftpfs.h ccache.h
+LCLHDRS = gopherfs.h
+
+OBJS = $(SRCS:.c=.o)
+#HURDLIBS = netfs fshelp iohelp threads ports ihash ftpconn shouldbeinlibc
+HURDLIBS = netfs fshelp iohelp ports
+
+include ../Makeconf
diff --git a/NOTES b/NOTES
new file mode 100644
index 000000000..f95b606ea
--- /dev/null
+++ b/NOTES
@@ -0,0 +1,4 @@
+* Consider caching hostname lookups and reusing the parent node's
+ server name, so as not to allocate it twice.
+
+* learn how to deal with (struct node *)->references
diff --git a/args.c b/args.c
new file mode 100644
index 000000000..38852563c
--- /dev/null
+++ b/args.c
@@ -0,0 +1,93 @@
+/* Gopher filesystem. Argument handling routines.
+
+ Copyright (C) 2001, 2002 James A. Morrison <ja2morri@uwaterloo.ca>
+ Copyright (C) 2000 Igor Khavkine <igor@twu.net>
+
+ Gopherfs 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.
+
+ Gopherfs 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 <string.h>
+#include <limits.h>
+#include <unistd.h>
+#include <error.h>
+#include <argp.h>
+#include <argz.h>
+
+#include <hurd/netfs.h>
+
+#include "gopherfs.h"
+
+/* ARGP data */
+const char *argp_program_version = "gopherfs 0.1.2";
+const char *argp_program_bug_address = "ja2morri@uwaterloo.ca";
+char args_doc[] = "REMOTE_FS [SERVER]";
+char doc[] = "Hurd gopher filesystem translator";
+static const struct argp_option options[] = {
+ {"debug", 'D', 0, 0, "enable debug output"},
+ {0}
+};
+/* the function that groks the arguments and fills
+ * global options
+ */
+static error_t
+parse_opt (int key, char *arg, struct argp_state *state)
+{
+ switch (key)
+ {
+ case 'D':
+ debug_flag = 1;
+ break;
+ case ARGP_KEY_ARG:
+ if (state->arg_num == 0)
+ gopherfs_root_server = arg;
+ else if (state->arg_num == 1)
+ {
+ gopherfs_root_port = 70;
+ gopherfs_server_dir = arg;
+ }
+ else if (state->arg_num == 2)
+ {
+ char *tail;
+ gopherfs_root_port = (unsigned short) strtol (arg, &tail, 10);
+ if (tail == arg || gopherfs_root_port > USHRT_MAX)
+ {
+ /* XXX bad integer conversion */
+ error (1, errno, "bad port number");
+ }
+ }
+ else
+ return ARGP_ERR_UNKNOWN;
+ break;
+ default:
+ return ARGP_ERR_UNKNOWN;
+ }
+ return 0;
+}
+static struct argp_child argp_children[] = { {&netfs_std_startup_argp}, {0} };
+static struct argp parser =
+ { options, parse_opt, args_doc, doc, argp_children };
+
+/* Used by netfs_set_options to handle runtime option parsing. */
+struct argp *netfs_runtime_argp = &parser;
+
+/* maybe overwrite this some time later */
+error_t netfs_append_args (char **argz, size_t * argz_len);
+
+/* handle all initial parameter parsing */
+error_t
+gopherfs_parse_args (int argc, char **argv)
+{
+ /* XXX: handle command line arguments properly */
+ return argp_parse (&parser, argc, argv, 0, 0, /*&conf */ 0);
+}
diff --git a/gopher.c b/gopher.c
new file mode 100644
index 000000000..a112150ea
--- /dev/null
+++ b/gopher.c
@@ -0,0 +1,179 @@
+/* Gopher protocol routines
+
+ Copyright (C) 2002 James A. Morrison <ja2morri@uwaterloo.ca>
+ Copyright (C) 2000 Igor Khavkine <igor@twu.net>
+ This file is part of Gopherfs.
+
+ Gopherfs 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.
+
+ Gopherfs 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 <error.h>
+#include <errno.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netdb.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+
+#include "gopherfs.h"
+
+#include <hurd/hurd_types.h>
+#include <hurd/netfs.h>
+
+/* do a DNS lookup for NAME and store result in *ENT */
+error_t
+lookup_host (char *name, struct hostent **ent)
+{
+ error_t err;
+ struct hostent hentbuf;
+ int herr = 0;
+ char *tmpbuf;
+ size_t tmpbuflen = 512;
+
+ tmpbuf = (char *) malloc (tmpbuflen);
+ if (!tmpbuf)
+ return ENOMEM;
+
+ /* XXX: use getaddrinfo */
+ while ((err = gethostbyname_r (name, &hentbuf, tmpbuf,
+ tmpbuflen, ent, &herr)) == ERANGE)
+ {
+ tmpbuflen *= 2;
+ tmpbuf = (char *) realloc (tmpbuf, tmpbuflen);
+ if (!tmpbuf)
+ return ENOMEM;
+ }
+ free (tmpbuf);
+
+ if (!herr)
+ return EINVAL;
+
+ return 0;
+}
+
+/* store the remote socket in *FD after writing a gopher selector
+ to it */
+error_t
+open_selector (struct netnode * node, int *fd)
+{
+ error_t err;
+ struct hostent *server_ent;
+ struct sockaddr_in server;
+ ssize_t written;
+ size_t towrite;
+
+ err = lookup_host (node->server, &server_ent);
+ if (!err)
+ return err;
+ if (debug_flag)
+ fprintf (stderr, "trying to open %s:%d/%s\n", node->server,
+ node->port, node->selector);
+
+ server.sin_family = AF_INET;
+ server.sin_port = htons (node->port);
+ server.sin_addr = *(struct in_addr *) server_ent->h_addr;
+
+ *fd = socket (PF_INET, SOCK_STREAM, 0);
+ if (*fd == -1)
+ return errno;
+
+ err = connect (*fd, (struct sockaddr *) &server, sizeof (server));
+ if (err == -1)
+ return errno;
+
+ towrite = strlen (node->selector);
+ /* guard against EINTR failures */
+ written = TEMP_FAILURE_RETRY (write (*fd, node->selector, towrite));
+ written += TEMP_FAILURE_RETRY (write (*fd, "\r\n", 2));
+ if (written == -1 || written < (towrite + 2))
+ return errno;
+
+ return 0;
+}
+
+/* fetch a directory node from the gopher server
+ DIR should already be locked */
+error_t
+fill_dirnode (struct netnode * dir)
+{
+ error_t err = 0;
+ FILE *sel;
+ int sel_fd;
+ char *line;
+ size_t line_len;
+ struct node *nd, **prevp;
+
+ err = open_selector (dir, &sel_fd);
+ if (err)
+ return err;
+ if (debug_flag)
+ fprintf (stderr, "filling out dir %s\n", dir->name);
+ errno = 0;
+ sel = fdopen (sel_fd, "r");
+ if (!sel)
+ {
+ close (sel_fd);
+ return errno;
+ }
+
+ dir->noents = TRUE;
+ dir->num_ents = 0;
+ prevp = &dir->ents;
+ line = NULL;
+ line_len = 0;
+ while (getline (&line, &line_len, sel) >= 0)
+ {
+ char type, *name, *selector, *server;
+ unsigned short port;
+ char *tok, *endtok;
+
+ if (debug_flag)
+ fprintf (stderr, "%s\n", line);
+ if (*line == '.' || err)
+ break;
+
+ /* parse the gopher node description */
+ type = *line;
+ endtok = line + 1;
+ name = strsep (&endtok, "\t");
+ selector = strsep (&endtok, "\t");
+ server = strsep (&endtok, "\t");
+ port = (unsigned short) atoi (strsep (&endtok, "\t"));
+
+ nd = gopherfs_make_node (type, name, selector, server, port);
+ if (!nd)
+ {
+ err = ENOMEM;
+ break;
+ }
+ *prevp = nd;
+ nd->prevp = prevp;
+ prevp = &nd->next;
+
+ dir->num_ents++;
+ if (dir->noents)
+ dir->noents = FALSE;
+ }
+ free (line);
+
+ if (err)
+ {
+ fclose (sel);
+ return err;
+ }
+
+ return 0;
+}
diff --git a/gopherfs.c b/gopherfs.c
new file mode 100644
index 000000000..063ede67a
--- /dev/null
+++ b/gopherfs.c
@@ -0,0 +1,99 @@
+/* Gopher filesystem
+
+ Copyright (C) 2002 James A. Morrison <ja2morri@uwaterloo.ca>
+ Copyright (C) 2000 Igor Khavkine <igor@twu.net>
+ This file is part of the Gopherfs translator.
+
+ Gopherfs 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.
+
+ Gopherfs 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 <string.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <maptime.h>
+#include <errno.h>
+#include <error.h>
+#include <argp.h>
+#include <argz.h>
+
+#include <hurd/netfs.h>
+
+#include "gopherfs.h"
+
+/* definition of global config parapeters */
+char *gopherfs_root_server;
+unsigned short gopherfs_root_port;
+char *gopherfs_server_dir;
+
+int debug_flag;
+
+struct gopherfs *gopherfs; /* filesystem global pointer */
+volatile struct mapped_time_value *gopherfs_maptime;
+
+int
+main (int argc, char **argv)
+{
+ error_t err;
+ mach_port_t bootstrap;
+
+ gopherfs_parse_args (argc, argv);
+ if (debug_flag)
+ fprintf (stderr, "pid %d\n", getpid ());
+
+ task_get_bootstrap_port (mach_task_self (), &bootstrap);
+ if (bootstrap == MACH_PORT_NULL)
+ error (1, 0, "Must be started as a translator");
+
+ netfs_init ();
+
+ err = maptime_map (0, 0, &gopherfs_maptime);
+ if (err)
+ error (1, err, "Error mapping time.");
+
+
+ /* err = gopherfs_create (...); */
+ /* XXX */
+ gopherfs = (struct gopherfs *) malloc (sizeof (struct gopherfs));
+ if (! gopherfs)
+ error (1, errno, "Cannot allocate gopherfs.");
+
+ gopherfs->umask = 0;
+ gopherfs->uid = getuid ();
+ gopherfs->gid = getgid ();
+ gopherfs->next_inode = 0;
+ gopherfs->root =
+ gopherfs_make_node (GPHR_DIR, "dir", "", gopherfs_root_server,
+ gopherfs_root_port);
+ fprintf (stderr, "attaching to %s\n", gopherfs_root_server);
+ /* XXX */
+ netfs_root_node = gopherfs->root;
+ netfs_startup (bootstrap, 0);
+
+ if (debug_flag)
+ fprintf (stderr, "entering the main loop\n");
+ for (;;)
+ fprintf (stderr, "loop\n");
+ netfs_server_loop ();
+
+ /*NOT REACHED */
+ fprintf (stderr, "Reached, now it will die");
+
+ /* free (gopherfs); */
+ return 0;
+}
+
+
+/*
+ * vim:ts=2:sw=2:autoindent:cindent:
+ */
diff --git a/gopherfs.h b/gopherfs.h
new file mode 100644
index 000000000..a6b4b369d
--- /dev/null
+++ b/gopherfs.h
@@ -0,0 +1,116 @@
+/* Gopher filesystem
+
+ Copyright (C) 2002 James A. Morrison <ja2morri@uwaterloo.ca>
+ Copyright (C) 2000 Igor Khavkine <igor@twu.net>
+ This file is part of the Gopherfs translator.
+
+ Gopherfs 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.
+
+ Gopherfs 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. */
+
+#ifndef __GOPHERFS_H__
+#define __GOPHERFS_H__
+
+#include <stdlib.h>
+#include <cthreads.h>
+#include <maptime.h>
+#include <sys/stat.h>
+/* #include <pthreads.h> */
+#include <error.h>
+#include <netdb.h>
+
+#include <hurd/hurd_types.h>
+
+/* declaration of global config parapeters */
+extern char *gopherfs_root_server;
+extern unsigned short gopherfs_root_port;
+extern char *gopherfs_server_dir;
+
+extern int debug_flag;
+extern volatile struct mapped_time_value *gopherfs_maptime;
+
+
+/* handle all initial parameter parsing */
+error_t gopherfs_parse_args (int argc, char **argv);
+
+/* private data per `struct node' */
+struct netnode
+{
+ char *name;
+ char *selector;
+ char *server;
+ unsigned short port;
+ enum
+ {
+ GPHR_FILE = '0', /* Item is a file */
+ GPHR_DIR = '1', /* Item is a directory */
+ GPHR_CSOPH = '2', /* Item is a CSO phone-book server */
+ GPHR_ERROR = '3', /* Error */
+ GPHR_BINHEX = '4', /* Item is a BinHexed Macintosh file */
+ GPHR_DOSBIN = '5', /* Item is DOS binary archive of some sort */
+ GPHR_UUENC = '6', /* Item is a UNIX uuencoded file */
+ GPHR_SEARCH = '7', /* Item is an Index-Search server */
+ GPHR_TELNET = '8', /* Item points to a text-based telnet session */
+ GPHR_BIN = '9' /* Item is a binary file */
+ }
+ type;
+
+ /* directory entries if this is a directory */
+ struct node *ents;
+ boolean_t noents;
+ unsigned int num_ents;
+ /* XXX cache reference ? */
+};
+
+/* The filesystem data type */
+struct gopherfs
+{
+ struct node *root;
+ /* stat infrmation */
+ mode_t umask;
+ uid_t uid;
+ gid_t gid;
+ ino_t next_inode;
+ /* some kind of cache thingy */
+};
+/* global pointer to the filesystem */
+extern struct gopherfs *gopherfs;
+
+/* do a DNS lookup for NAME and store result in *ENT */
+error_t lookup_host (char *name, struct hostent **ent);
+
+/* store the remote socket in *FD after writing a gopher selector
+ to it */
+error_t open_selector (struct netnode *node, int *fd);
+
+/* make an instance of `struct netnode' with the specified parameters,
+ return NULL on error */
+struct netnode *gopherfs_make_netnode (char type, char *name, char *selector,
+ char *server, unsigned short port);
+
+/* fetch a directory node from the gopher server
+ DIR should already be locked */
+error_t fill_dirnode (struct netnode *dir);
+
+/* free an instance of `struct netnode' */
+void free_netnode (struct netnode *node);
+
+/* make an instance of `struct node' with the specified parameters,
+ return NULL on error */
+struct node *gopherfs_make_node (char type, char *name, char *selector,
+ char *server, unsigned short port);
+
+/* free an instance of `struct node' */
+void free_node (struct node *node);
+
+#endif /* __GOPHERFS_H__ */
diff --git a/netfs.c b/netfs.c
new file mode 100644
index 000000000..959bd94bd
--- /dev/null
+++ b/netfs.c
@@ -0,0 +1,482 @@
+/* gopherfs interface to libnetfs
+
+ Copyright (C) 2000 Free Software Foundation, Inc.
+ Written by Igor Khavkine <igor@twu.net>
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd 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.
+
+ The GNU Hurd 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 <stddef.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <maptime.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <dirent.h>
+#include <mach.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include "gopherfs.h"
+
+#include <hurd/hurd_types.h>
+#include <hurd/netfs.h>
+
+
+/* Attempt to create a file named NAME in DIR for USER with MODE. Set *NODE
+ to the new node upon return. On any error, clear *NODE. *NODE should be
+ locked on success; no matter what, unlock DIR before returning. */
+error_t
+netfs_attempt_create_file (struct iouser *user, struct node *dir,
+ char *name, mode_t mode, struct node **node)
+{
+ *node = NULL;
+ mutex_unlock (&dir->lock);
+ return EROFS;
+}
+
+/* Node NODE is being opened by USER, with FLAGS. NEWNODE is nonzero if we
+ just created this node. Return an error if we should not permit the open
+ to complete because of a permission restriction. */
+error_t
+netfs_check_open_permissions (struct iouser *user, struct node *node,
+ int flags, int newnode)
+{
+ error_t err = 0;
+ if (!err && (flags & O_READ))
+ err = fshelp_access (&node->nn_stat, S_IREAD, user);
+ if (!err && (flags & O_WRITE))
+ err = fshelp_access (&node->nn_stat, S_IWRITE, user);
+ if (!err && (flags & O_EXEC))
+ err = fshelp_access (&node->nn_stat, S_IEXEC, user);
+ return err;
+}
+
+/* This should attempt a utimes call for the user specified by CRED on node
+ NODE, to change the atime to ATIME and the mtime to MTIME. */
+error_t
+netfs_attempt_utimes (struct iouser *cred, struct node *node,
+ struct timespec *atime, struct timespec *mtime)
+{
+ error_t err = 0;
+ int flags = TOUCH_CTIME;
+
+ if (!err)
+ err = fshelp_isowner (&node->nn_stat, cred);
+
+ if (!err) {
+ if (atime) {
+ node->nn_stat.st_atime = atime->tv_sec;
+ node->nn_stat.st_atime_usec = atime->tv_nsec / 1000;
+ } else
+ flags |= TOUCH_ATIME;
+
+ if (mtime) {
+ node->nn_stat.st_mtime = mtime->tv_sec;
+ node->nn_stat.st_mtime_usec = mtime->tv_nsec / 1000;
+ } else
+ flags |= TOUCH_MTIME;
+
+ fshelp_touch (&node->nn_stat, flags, gopherfs_maptime);
+ }
+
+ return err;
+}
+
+/* Return the valid access types (bitwise OR of O_READ, O_WRITE, and O_EXEC)
+ in *TYPES for file NODE and user CRED. */
+error_t
+netfs_report_access (struct iouser *cred, struct node *node, int *types)
+{
+ *types = 0;
+ if (fshelp_access (&node->nn_stat, S_IREAD, cred) == 0)
+ *types |= O_READ;
+ if (fshelp_access (&node->nn_stat, S_IWRITE, cred) == 0)
+ *types |= O_WRITE;
+ if (fshelp_access (&node->nn_stat, S_IEXEC, cred) == 0)
+ *types |= O_EXEC;
+
+ return 0;
+}
+
+/* Trivial definitions. */
+
+/* Make sure that NP->nn_stat is filled with current information. CRED
+ identifies the user responsible for the operation. */
+error_t netfs_validate_stat (struct node *node, struct iouser *cred)
+{
+ /* Assume that gopher data is static and will not change for however
+ * long we keep the cached node. Hence nn_stat is always valid.
+ * XXX: would be a good idea to introduce a forced refresh call */
+ return 0;
+}
+
+/* This should sync the file NODE completely to disk, for the user CRED. If
+ WAIT is set, return only after sync is completely finished. */
+error_t
+netfs_attempt_sync (struct iouser *cred, struct node *node, int wait)
+{
+ return 0;
+}
+
+#if 0
+/* The granularity with which we allocate space to return our result. */
+#define DIRENTS_CHUNK_SIZE (8*1024)
+
+/* Returned directory entries are aligned to blocks this many bytes long.
+ Must be a power of two. */
+#define DIRENT_ALIGN 4
+#define DIRENT_NAME_OFFS (offsetof (struct dirent, d_name))
+
+/* Length is structure before the name + the name + '\0', all
+ padded to a four-byte alignment. */
+#define DIRENT_LEN(name_len) \
+ ((DIRENT_NAME_OFFS + (name_len) + 1 + (DIRENT_ALIGN - 1)) \
+ & ~(DIRENT_ALIGN - 1))
+#endif
+
+/* Fetch a directory */
+error_t
+netfs_get_dirents (struct iouser *cred, struct node *dir,
+ int first_entry, int max_entries, char **data,
+ mach_msg_type_number_t *data_len,
+ vm_size_t max_data_len, int *data_entries)
+{
+ error_t err = 0;
+ struct node *nd;
+ int count;
+ size_t size;
+ char *p;
+
+ if (!dir || dir->nn->type != GPHR_DIR)
+ return ENOTDIR;
+
+ if (!dir->nn->ents && !dir->nn->noents) {
+ mutex_lock (&dir->lock);
+ err = fill_dirnode (dir->nn);
+ mutex_unlock (&dir->lock);
+ if (err)
+ return err;
+ }
+
+ for (nd = dir->nn->ents; first_entry > 0 && nd; first_entry--, nd=nd->next)
+ ;
+ if (!nd)
+ max_entries = 0;
+
+ if (max_entries == 0) {
+ *data_len = 0;
+ *data_entries = 0;
+ *data = NULL;
+ return 0;
+ }
+
+#define DIRENTS_CHUNK_SIZE (8*1024)
+ size = (max_data_len == 0 || max_data_len > DIRENTS_CHUNK_SIZE)
+ ? DIRENTS_CHUNK_SIZE
+ : max_data_len;
+ errno = 0;
+ *data = NULL;
+ err = vm_allocate (mach_task_self (), (vm_address_t *)data,
+ size, /*anywhere*/TRUE);
+ if (err)
+ return err;
+ err = vm_protect (mach_task_self (), (vm_address_t)*data, size,
+ /*set_maximum*/FALSE, VM_PROT_READ | VM_PROT_WRITE);
+ if (err)
+ return err;
+
+ p = *data;
+ for (count = 0; nd && (max_entries == -1 || count < max_entries); count++) {
+#define DIRENT_NAME_OFFS offsetof (struct dirent, d_name)
+ vm_address_t addr;
+ struct dirent ent;
+
+ ent.d_fileno = nd->nn_stat.st_ino;
+ ent.d_type = IFTODT (nd->nn_stat.st_mode);
+ ent.d_namlen = strlen (nd->nn->name);
+ ent.d_reclen = DIRENT_NAME_OFFS + ent.d_namlen + 1;
+ if (p - *data + ent.d_reclen > size) {
+ size_t extra = ((p - *data + ent.d_reclen - size)/DIRENTS_CHUNK_SIZE + 1)*DIRENTS_CHUNK_SIZE;
+ if (extra + size > max_data_len)
+ break;
+ addr = (vm_address_t) (*data + size);
+ err = vm_allocate (mach_task_self (), &addr, extra, /*anywhere*/FALSE);
+ if (err)
+ break;
+ err = vm_protect (mach_task_self (), (vm_address_t)*data, size,
+ /*set_maximum*/FALSE, VM_PROT_READ | VM_PROT_WRITE);
+ if (err)
+ break;
+ size += extra;
+ }
+ /* copy the dirent structure */
+ memcpy (p, &ent, DIRENT_NAME_OFFS);
+ /* copy ent.d_name */
+ strncpy (p + DIRENT_NAME_OFFS, nd->nn->name, ent.d_namlen);
+ p += ent.d_reclen;
+
+ nd = nd->next;
+ }
+ if (err) {
+ vm_deallocate (mach_task_self (), (vm_address_t)*data, size);
+ *data_len = 0;
+ *data_entries = 0;
+ *data = NULL;
+ return 0;
+ } else {
+ vm_address_t alloc_end = (vm_address_t) (*data + size);
+ vm_address_t real_end = round_page (p);
+
+ if (alloc_end > real_end)
+ vm_deallocate (mach_task_self (), real_end, alloc_end - real_end);
+ *data_len = p - *data;
+ *data_entries = count;
+ }
+
+ return 0;
+}
+
+/* Lookup NAME in DIR for USER; set *NODE to the found name upon return. If
+ the name was not found, then return ENOENT. On any error, clear *NODE.
+ (*NODE, if found, should be locked, this call should unlock DIR no matter
+ what.) */
+error_t netfs_attempt_lookup (struct iouser *user, struct node *dir,
+ char *name, struct node ** node)
+{
+ error_t err;
+ struct node *nd;
+
+ if (dir->nn->type != GPHR_DIR)
+ err = ENOTDIR;
+ for (nd = dir->nn->ents; nd && strcmp (name, nd->nn->name); nd = nd->next)
+ ;
+ if (nd) {
+ mutex_lock (&nd->lock);
+ *node = nd;
+ err = 0;
+ } else
+ err = ENOENT;
+
+ mutex_unlock (&dir->lock);
+ return 0;
+}
+
+/* Delete NAME in DIR for USER. */
+error_t netfs_attempt_unlink (struct iouser *user, struct node *dir,
+ char *name)
+{
+ return EROFS;
+}
+
+/* Note that in this one call, neither of the specific nodes are locked. */
+error_t netfs_attempt_rename (struct iouser *user, struct node *fromdir,
+ char *fromname, struct node *todir,
+ char *toname, int excl)
+{
+ return EROFS;
+}
+
+/* Attempt to create a new directory named NAME in DIR for USER with mode
+ MODE. */
+error_t netfs_attempt_mkdir (struct iouser *user, struct node *dir,
+ char *name, mode_t mode)
+{
+ return EROFS;
+}
+
+/* Attempt to remove directory named NAME in DIR for USER. */
+error_t netfs_attempt_rmdir (struct iouser *user,
+ struct node *dir, char *name)
+{
+ return EROFS;
+}
+
+/* This should attempt a chmod call for the user specified by CRED on node
+ NODE, to change the owner to UID and the group to GID. */
+error_t netfs_attempt_chown (struct iouser *cred, struct node *node,
+ uid_t uid, uid_t gid)
+{
+ return EROFS;
+}
+
+/* This should attempt a chauthor call for the user specified by CRED on node
+ NODE, to change the author to AUTHOR. */
+error_t netfs_attempt_chauthor (struct iouser *cred, struct node *node,
+ uid_t author)
+{
+ return EROFS;
+}
+
+/* This should attempt a chmod call for the user specified by CRED on node
+ NODE, to change the mode to MODE. Unlike the normal Unix and Hurd meaning
+ of chmod, this function is also used to attempt to change files into other
+ types. If such a transition is attempted which is impossible, then return
+ EOPNOTSUPP. */
+error_t netfs_attempt_chmod (struct iouser *cred, struct node *node,
+ mode_t mode)
+{
+ return EROFS;
+}
+
+/* Attempt to turn NODE (user CRED) into a symlink with target NAME. */
+error_t netfs_attempt_mksymlink (struct iouser *cred, struct node *node,
+ char *name)
+{
+ return EROFS;
+}
+
+/* Attempt to turn NODE (user CRED) into a device. TYPE is either S_IFBLK or
+ S_IFCHR. */
+error_t netfs_attempt_mkdev (struct iouser *cred, struct node *node,
+ mode_t type, dev_t indexes)
+{
+ return EROFS;
+}
+
+/* Attempt to set the passive translator record for FILE to ARGZ (of length
+ ARGZLEN) for user CRED. */
+error_t netfs_set_translator (struct iouser *cred, struct node *node,
+ char *argz, size_t argzlen)
+{
+ return EROFS;
+}
+
+#if 0
+/* The user may define this function (but should define it together with
+ netfs_set_translator). For locked node NODE with S_IPTRANS set in its
+ mode, look up the name of its translator. Store the name into newly
+ malloced storage, and return it in *ARGZ; set *ARGZ_LEN to the total
+ length. */
+error_t netfs_get_translator (struct node *node, char **argz, size_t *argz_len)
+{
+}
+#endif
+
+/* This should attempt a chflags call for the user specified by CRED on node
+ NODE, to change the flags to FLAGS. */
+error_t netfs_attempt_chflags (struct iouser *cred, struct node *node,
+ int flags)
+{
+ return EROFS;
+}
+
+/* This should attempt to set the size of the file NODE (for user CRED) to
+ SIZE bytes long. */
+error_t netfs_attempt_set_size (struct iouser *cred, struct node *node,
+ off_t size)
+{
+ return EROFS;
+}
+
+/* This should attempt to fetch filesystem status information for the remote
+ filesystem, for the user CRED. */
+error_t netfs_attempt_statfs (struct iouser *cred, struct node *node,
+ struct statfs *st)
+{
+ return EOPNOTSUPP;
+}
+
+/* This should sync the entire remote filesystem. If WAIT is set, return
+ only after sync is completely finished. */
+error_t netfs_attempt_syncfs (struct iouser *cred, int wait)
+{
+ return 0;
+}
+
+/* Create a link in DIR with name NAME to FILE for USER. Note that neither
+ DIR nor FILE are locked. If EXCL is set, do not delete the target, but
+ return EEXIST if NAME is already found in DIR. */
+error_t netfs_attempt_link (struct iouser *user, struct node *dir,
+ struct node *file, char *name, int excl)
+{
+ return EROFS;
+}
+
+/* Attempt to create an anonymous file related to DIR for USER with MODE.
+ Set *NODE to the returned file upon success. No matter what, unlock DIR. */
+error_t netfs_attempt_mkfile (struct iouser *user, struct node *dir,
+ mode_t mode, struct node ** node)
+{
+ *node = NULL;
+ mutex_unlock (&dir->lock);
+ return EROFS;
+}
+
+/* maximum numer of symlinks, does not really apply, so set to 0 */
+int netfs_maxsymlinks = 0;
+/* Read the contents of NODE (a symlink), for USER, into BUF. */
+error_t netfs_attempt_readlink (struct iouser *user, struct node *node,
+ char *buf)
+{
+ return EINVAL;
+}
+
+/* Read from the file NODE for user CRED starting at OFFSET and continuing for
+ up to *LEN bytes. Put the data at DATA. Set *LEN to the amount
+ successfully read upon return. */
+error_t netfs_attempt_read (struct iouser *cred, struct node *node,
+ off_t offset, size_t *len, void *data)
+{
+ error_t err;
+ int remote_fd;
+ ssize_t read_len;
+
+ err = open_selector (node->nn, &remote_fd);
+ if (err)
+ return err;
+
+ read_len = pread (remote_fd, data, *len, offset);
+ if (read_len < 0)
+ err = errno;
+ else {
+ *len = (size_t)read_len;
+ err = 0;
+ }
+
+ return err;
+}
+
+/* Write to the file NODE for user CRED starting at OFSET and continuing for up
+ to *LEN bytes from DATA. Set *LEN to the amount seccessfully written upon
+ return. */
+error_t netfs_attempt_write (struct iouser *cred, struct node *node,
+ off_t offset, size_t *len, void *data)
+{
+ return EROFS;
+}
+
+/* XXX doesn't say anywhere what this must do */
+#if 0
+/* The user must define this function. Create a new user
+ from the specified UID and GID arrays. */
+struct iouser *netfs_make_user (uid_t *uids, int nuids,
+ uid_t *gids, int ngids)
+{
+}
+#endif
+
+/* The user must define this function. Node NP is all done; free
+ all its associated storage. */
+void netfs_node_norefs (struct node *np)
+{
+ mutex_lock (&np->lock);
+ *np->prevp = np->next;
+ np->next->prevp = np->prevp;
+ free_node (np);
+ /* XXX: remove node from tree and delete the cache entry */
+}
diff --git a/node.c b/node.c
new file mode 100644
index 000000000..ad1f74569
--- /dev/null
+++ b/node.c
@@ -0,0 +1,142 @@
+/* Gopherfs node handling routines
+
+ Copyright (C) 2002 James A. Morrison <ja2morri@uwaterloo.ca>
+ Copyright (C) 2000 Igor Khavkine <igor@twu.net>
+ This file is part of the Gopherfs translator.
+
+ Gopherfs 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.
+
+ Gopherfs 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 <string.h>
+#include <stdlib.h>
+#include <errno.h>
+
+#include "gopherfs.h"
+
+#include <hurd/hurd_types.h>
+#include <hurd/netfs.h>
+
+/* make an instance of `struct netnode' with the specified parameters,
+ return NULL on error */
+struct netnode *
+gopherfs_make_netnode (char type, char *name, char *selector,
+ char *server, unsigned short port)
+{
+ struct netnode *nn;
+ int err;
+
+ nn = (struct netnode *) malloc (sizeof (struct netnode));
+ if (!nn)
+ return NULL;
+ memset (nn, 0, sizeof (struct netnode));
+ nn->type = type;
+ nn->name = strdup (name);
+ if (! nn->name)
+ err = 1;
+ nn->selector = strdup (selector);
+ if (! nn->selector)
+ err = 2;
+ nn->server = strdup (server);
+ if (! nn->server)
+ err = 3;
+ nn->port = port;
+ nn->ents = NULL;
+ nn->noents = FALSE;
+ /* XXX init cache references */
+
+ switch (err)
+ {
+ case 4:
+ free (nn->server);
+ case 3:
+ free (nn->selector);
+ case 2:
+ free (nn->name);
+ case 1:
+ free (nn);
+ case 0:
+ return NULL;
+ default:
+ return nn;
+ }
+
+}
+
+/* free an instance of `struct netnode' */
+void
+free_netnode (struct netnode *node)
+{
+ struct node *nd;
+
+ free (node->server);
+ free (node->selector);
+ free (node->name);
+ for (nd = node->ents; nd; nd = nd->next)
+ free (nd);
+ free (node);
+}
+
+/* make an instance of `struct node' with the specified parameters,
+ return NULL on error */
+struct node *
+gopherfs_make_node (char type, char *name, char *selector,
+ char *server, unsigned short port)
+{
+ struct netnode *nn;
+ struct node *nd;
+
+ nn = gopherfs_make_netnode (type, name, selector, server, port);
+ if (!nn)
+ return NULL;
+
+ nd = netfs_make_node (nn);
+ if (!nd)
+ {
+ free (nn);
+ return NULL;
+ }
+ nd->next = NULL;
+ nd->prevp = NULL;
+ nd->owner = gopherfs->uid;
+
+ /* XXX Hold a reference to the new dir's node. */
+ spin_lock (&netfs_node_refcnt_lock);
+ nd->references++;
+ spin_unlock (&netfs_node_refcnt_lock);
+
+ /* fill in stat info for the node */
+ nd->nn_stat.st_mode = (S_IRUSR | S_IRGRP | S_IROTH) & ~gopherfs->umask;
+ nd->nn_stat.st_mode |= type == GPHR_DIR ? S_IFDIR : S_IFREG;
+ nd->nn_stat.st_nlink = 1;
+ nd->nn_stat.st_uid = gopherfs->uid;
+ nd->nn_stat.st_gid = gopherfs->gid;
+ nd->nn_stat.st_rdev = 0;
+ nd->nn_stat.st_size = 0;
+ nd->nn_stat.st_blksize = 0;
+ nd->nn_stat.st_blocks = 0;
+ nd->nn_stat.st_ino = gopherfs->next_inode++;
+ fshelp_touch (&nd->nn_stat, TOUCH_ATIME | TOUCH_MTIME | TOUCH_CTIME,
+ gopherfs_maptime);
+
+ return nd;
+}
+
+/* free an instance of `struct node' */
+void
+free_node (struct node *node)
+{
+ /* XXX possibly take care of cache references */
+ free_netnode (node->nn);
+ free (node);
+}