diff options
Diffstat (limited to 'nfsd/fsys.c')
-rw-r--r-- | nfsd/fsys.c | 91 |
1 files changed, 54 insertions, 37 deletions
diff --git a/nfsd/fsys.c b/nfsd/fsys.c index d3c50220..7b15d150 100644 --- a/nfsd/fsys.c +++ b/nfsd/fsys.c @@ -1,5 +1,5 @@ /* Filesystem management for NFS server - Copyright (C) 1996 Free Software Foundation, Inc. + Copyright (C) 1996, 2002 Free Software Foundation, Inc. Written by Michael I. Bushnell, p/BSG. This file is part of the GNU Hurd. @@ -20,13 +20,14 @@ #include <stdio.h> #include <errno.h> +#include <error.h> #include <hurd.h> #include <fcntl.h> #include <string.h> #include "nfsd.h" -struct fsys_spec +struct fsys_spec { fsys_t fsys; char *name; @@ -49,18 +50,23 @@ init_filesystems (void) int line; file_t root; static FILE *index_file; + int i; fsystable = (struct fsys_spec *) malloc ((fsystablesize = 10) * sizeof (struct fsys_spec)); + for (i = 0; i < fsystablesize; i++) + { + fsystable[i].fsys = MACH_PORT_NULL; + fsystable[i].name = 0; + } if (!index_file_name) return; - + index_file = fopen (index_file_name, "r"); if (!index_file) { - fprintf (stderr, "%s: Cannot open `%s': %s\n", - program_invocation_name, index_file_name, strerror (errno)); + error (0, errno, "Cannot open `%s'", index_file_name); return; } @@ -72,33 +78,39 @@ init_filesystems (void) fclose (index_file); return; } - + if (nitems != 2) { - fprintf (stderr, "%s:%s:%d Bad syntax\n", - program_invocation_name, index_file_name, line); + error (0, 0, "%s:%d Bad syntax", index_file_name, line); continue; } root = file_name_lookup (name, 0, 0); - if (!root) + if (root == MACH_PORT_NULL) { - fprintf (stderr, "%s:%s:%d Filesystem `%s': %s\n", - program_invocation_name, index_file_name, line, - name, strerror (errno)); + error (0, errno, "%s:%d Filesystem `%s'", + index_file_name, line, name); free (name); continue; } if (index >= fsystablesize) - fsystable = (struct fsys_spec *) realloc (fsystable, - (fsystablesize = index * 2) - * sizeof (struct fsys_spec)); - if (index > nfsys) - nfsys = index; - + { + fsystable = (struct fsys_spec *) + realloc (fsystable, index * 2 * sizeof (struct fsys_spec)); + for (i = fsystablesize; i < index * 2; i++) + { + fsystable[i].fsys = MACH_PORT_NULL; + fsystable[i].name = 0; + } + fsystablesize = index * 2; + } + + if (index + 1 > nfsys) + nfsys = index + 1; + fsystable[index].name = name; - file_getcontrol (root, &fsystable[nfsys].fsys); + file_getcontrol (root, &fsystable[index].fsys); mach_port_deallocate (mach_task_self (), root); } } @@ -109,46 +121,44 @@ write_filesystems (void) { file_t newindex; FILE *f; + error_t err; int i; if (!index_file_name) return; - + if (index_file_dir == MACH_PORT_NULL) { index_file_dir = file_name_split (index_file_name, &index_file_compname); if (index_file_dir == MACH_PORT_NULL) { - fprintf (stderr, "%s: `%s': %s\n", - program_invocation_name, index_file_name, strerror (errno)); + error (0, errno, "`%s'", index_file_name); index_file_name = 0; return; } } /* Create an anonymous file in the same directory */ - errno = dir_mkfile (index_file_dir, O_WRONLY, 0666, &newindex); - if (errno) + err = dir_mkfile (index_file_dir, O_WRONLY, 0666, &newindex); + if (err) { - fprintf (stderr, "%s: `%s': %s\n", - program_invocation_name, index_file_name, strerror (errno)); + error (0, err, "`%s'", index_file_name); index_file_name = 0; mach_port_deallocate (mach_task_self (), index_file_dir); index_file_dir = MACH_PORT_NULL; return; } - + f = fopenport (newindex, "w"); - + for (i = 0; i < nfsys; i++) if (fsystable[i].name) fprintf (f, "%d %s\n", i, fsystable[i].name); /* Link it in */ - errno = dir_link (index_file_dir, newindex, index_file_compname, 0); - if (errno) - fprintf (stderr, "%s: `%s': %s\n", - program_invocation_name, index_file_name, strerror (errno)); + err = dir_link (index_file_dir, newindex, index_file_compname, 0); + if (err) + error (0, err, "`%s'", index_file_name); fflush (f); file_sync (newindex, 1, 0); fclose (f); @@ -174,11 +184,19 @@ enter_filesystem (char *name, file_t root) for (i = 0; i < nfsys; i++) if (fsystable[i].name && !strcmp (fsystable[i].name, name)) return i; - + if (nfsys == fsystablesize) - fsystable = (struct fsys_spec *) realloc (fsystable, - (fsystablesize *= 2) - * sizeof (struct fsys_spec)); + { + fsystable = (struct fsys_spec *) realloc (fsystable, + (fsystablesize * 2) + * sizeof (struct fsys_spec)); + for (i = fsystablesize; i < fsystablesize * 2; i++) + { + fsystable[i].fsys = MACH_PORT_NULL; + fsystable[i].name = 0; + } + fsystablesize *= 2; + } fsystable[nfsys].name = malloc (strlen (name) + 1); strcpy (fsystable[nfsys].name, name); @@ -189,4 +207,3 @@ enter_filesystem (char *name, file_t root) return nfsys - 1; } - |