From 5d9efe088f5d83921305ee2f93f6c6590c640b47 Mon Sep 17 00:00:00 2001 From: Roland McGrath Date: Sat, 29 Dec 2001 00:40:09 +0000 Subject: 2001-10-13 Roland McGrath * storage-info.c: New file. * Makefile (SRCS): Add it. * mount.c (mounted_hostname, mounted_nfs_port): New global variables. (mount_root): Set them. * nfs.h: Declare them. --- nfs/Makefile | 9 ++--- nfs/mount.c | 9 ++++- nfs/nfs.h | 5 ++- nfs/storage-info.c | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 119 insertions(+), 6 deletions(-) create mode 100644 nfs/storage-info.c (limited to 'nfs') diff --git a/nfs/Makefile b/nfs/Makefile index 12ce9800..9c3f2b7a 100644 --- a/nfs/Makefile +++ b/nfs/Makefile @@ -1,5 +1,5 @@ -# -# Copyright (C) 1995, 1996, 1997, 2000 Free Software Foundation +# +# Copyright (C) 1995,96,97,2000,01 Free Software Foundation, Inc. # Written by Michael I. Bushnell. # # This file is part of the GNU Hurd. @@ -23,8 +23,9 @@ makemode := server target = nfs LCLHDRS = nfs.h mount.h nfs-spec.h -SRCS = ops.c rpc.c mount.c nfs.c cache.c consts.c main.c name-cache.c -OBJS = $(subst .c,.o,$(SRCS)) +SRCS = ops.c rpc.c mount.c nfs.c cache.c consts.c main.c name-cache.c \ + storage-info.c +OBJS = $(SRCS:.c=.o) HURDLIBS = netfs fshelp iohelp threads ports include ../Makeconf diff --git a/nfs/mount.c b/nfs/mount.c index a3a6887e..eb7165ac 100644 --- a/nfs/mount.c +++ b/nfs/mount.c @@ -1,5 +1,5 @@ /* - Copyright (C) 1995, 1996, 1997, 1998 Free Software Foundation, Inc. + Copyright (C) 1995,96,97,98,2001 Free Software Foundation, Inc. Written by Michael I. Bushnell, p/BSG. This file is part of the GNU Hurd. @@ -64,6 +64,10 @@ short nfs_port = NFS_PORT; /* True iff NFS_PORT should be used even if portmapper present. */ int nfs_port_override = 0; +/* Host name and port number we actually decided to use. */ +const char *mounted_hostname; +uint16_t mounted_nfs_port; /* host order */ + int protocol_version = 2; /* Set up an RPC for procedure PROCNUM for talking to the portmapper. @@ -254,6 +258,9 @@ mount_root (char *name, char *host) return 0; } + mounted_hostname = host; + mounted_nfs_port = port; + return np; error_with_rpcbuf: diff --git a/nfs/nfs.h b/nfs/nfs.h index 5fb62c50..147dc900 100644 --- a/nfs/nfs.h +++ b/nfs/nfs.h @@ -1,5 +1,5 @@ /* Data structures and global variables for NFS client - Copyright (C) 1994, 1995, 1996, 1997, 1999 Free Software Foundation + Copyright (C) 1994,95,96,97,99,2001 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 @@ -20,6 +20,7 @@ #include #include +#include #include #include "nfs-spec.h" #include @@ -177,6 +178,8 @@ error_t nfs_error_trans (int); /* mount.c */ struct node *mount_root (char *, char *); +extern const char *mounted_hostname; +extern uint16_t mounted_nfs_port; /* host order */ /* ops.c */ int *register_fresh_stat (struct node *, int *); diff --git a/nfs/storage-info.c b/nfs/storage-info.c new file mode 100644 index 00000000..d4d71fac --- /dev/null +++ b/nfs/storage-info.c @@ -0,0 +1,102 @@ +/* file_get_storage_info RPC for NFS client filesystem + Copyright (C) 2001 Free Software Foundation, Inc. + + 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 "nfs.h" +#include +#include + +error_t +netfs_file_get_storage_info (struct iouser *cred, + struct node *np, + mach_port_t **ports, + mach_msg_type_name_t *ports_type, + mach_msg_type_number_t *num_ports, + int **ints, + mach_msg_type_number_t *num_ints, + off_t **offsets, + mach_msg_type_number_t *num_offsets, + char **data, + mach_msg_type_number_t *data_len) +{ + int name_len, fhpos; + error_t err; + + inline int fmt (size_t buflen) + { + return snprintf (*data, buflen, + "nfsv%u://%s:%u/%n%*c?rsize=%u&wsize=%u", + protocol_version, mounted_hostname, mounted_nfs_port, + &fhpos, np->nn->handle.size * 2, 'X', /* filled below */ + read_size, write_size); + } + + /* We return the file size, so make sure we have it up to date now. */ + err = netfs_validate_stat (np, cred); + if (err) + return err; + + /* Format the name, and then do it again if the buffer was too short. */ + name_len = fmt (*data_len); + if (name_len < 0) + return errno; + ++name_len; /* Include the terminating null. */ + if (name_len <= *data_len) + *data_len = name_len; + else + { + *data = mmap (0, name_len, PROT_READ|PROT_WRITE, MAP_ANON, 0, 0); + if (*data == MAP_FAILED) + return errno; + *data_len = fmt (name_len) + 1; + assert (*data_len == name_len); + } + + /* Now fill in the file handle data in hexadecimal. */ + { + static const char hexdigits[] = "0123456789abcdef"; + size_t i; + for (i = 0; i < np->nn->handle.size; ++i) + { + (*data)[fhpos++] = hexdigits[(uint8_t)np->nn->handle.data[i] >> 4]; + (*data)[fhpos++] = hexdigits[(uint8_t)np->nn->handle.data[i] & 0xf]; + } + } + + /* Now fill in the rest of the canonical-form storage-info data, which + just describes a single run of the file's size, a block-size of one + byte, and our URL as the name for the network store type. */ + + *num_ports = 0; + + assert (*num_offsets >= 2); /* mig always gives us some */ + *num_offsets = 2; + (*offsets)[0] = 0; + (*offsets)[1] = np->nn_stat.st_size; + + assert (*num_ints >= 6); /* mig always gives us some */ + *num_ints = 1; + (*ints)[0] = STORAGE_NETWORK; + (*ints)[1] = 0; /* XXX readonly if we supported it */ + (*ints)[2] = 1; /* block size */ + (*ints)[3] = 1; /* 1 run in offsets list */ + (*ints)[4] = name_len; + (*ints)[5] = 0; /* misc len */ + + return 0; +} -- cgit v1.2.3