xref: /titanic_52/usr/src/stand/lib/fs/nfs/nfsops.c (revision 986fd29a0dc13f7608ef7f508f6e700bd7bc2720)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*986fd29aSsetje  * Common Development and Distribution License (the "License").
6*986fd29aSsetje  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*986fd29aSsetje  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  *
257c478bd9Sstevel@tonic-gate  * Simple nfs ops - open, close, read, and lseek.
267c478bd9Sstevel@tonic-gate  */
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #include <rpc/types.h>
317c478bd9Sstevel@tonic-gate #include <rpc/auth.h>
327c478bd9Sstevel@tonic-gate #include <sys/t_lock.h>
337c478bd9Sstevel@tonic-gate #include "clnt.h"
347c478bd9Sstevel@tonic-gate #include <sys/fcntl.h>
357c478bd9Sstevel@tonic-gate #include <sys/vfs.h>
367c478bd9Sstevel@tonic-gate #include <errno.h>
377c478bd9Sstevel@tonic-gate #include <sys/promif.h>
387c478bd9Sstevel@tonic-gate #include <rpc/xdr.h>
397c478bd9Sstevel@tonic-gate #include "nfs_inet.h"
407c478bd9Sstevel@tonic-gate #include <sys/stat.h>
417c478bd9Sstevel@tonic-gate #include <sys/bootvfs.h>
427c478bd9Sstevel@tonic-gate #include <sys/bootdebug.h>
437c478bd9Sstevel@tonic-gate #include <sys/salib.h>
447c478bd9Sstevel@tonic-gate #include <sys/sacache.h>
457c478bd9Sstevel@tonic-gate #include <rpc/rpc.h>
467c478bd9Sstevel@tonic-gate #include "brpc.h"
477c478bd9Sstevel@tonic-gate #include <rpcsvc/nfs_prot.h>
487c478bd9Sstevel@tonic-gate #include "socket_inet.h"
497c478bd9Sstevel@tonic-gate #include "mac.h"
507c478bd9Sstevel@tonic-gate #include <sys/mode.h>
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate ushort_t vttoif_tab[] = {
537c478bd9Sstevel@tonic-gate 	0, S_IFREG, S_IFDIR, S_IFBLK, S_IFCHR, S_IFLNK, S_IFIFO,
547c478bd9Sstevel@tonic-gate 	S_IFDOOR, 0, S_IFSOCK, 0
557c478bd9Sstevel@tonic-gate };
567c478bd9Sstevel@tonic-gate 
577c478bd9Sstevel@tonic-gate static int file_desc = 1;
587c478bd9Sstevel@tonic-gate static struct nfs_files {
597c478bd9Sstevel@tonic-gate 	struct nfs_file file;
607c478bd9Sstevel@tonic-gate 	int	desc;
617c478bd9Sstevel@tonic-gate 	struct nfs_files *next;
627c478bd9Sstevel@tonic-gate } nfs_files[1] = {
637c478bd9Sstevel@tonic-gate 	{0, 0, 0},
647c478bd9Sstevel@tonic-gate };
657c478bd9Sstevel@tonic-gate 
667c478bd9Sstevel@tonic-gate #define	dprintf	if (boothowto & RB_DEBUG) printf
677c478bd9Sstevel@tonic-gate 
687c478bd9Sstevel@tonic-gate static int	boot_nfs_open(char *filename, int flags);
697c478bd9Sstevel@tonic-gate static int	boot_nfs_close(int fd);
707c478bd9Sstevel@tonic-gate static ssize_t	boot_nfs_read(int fd, caddr_t buf, size_t size);
717c478bd9Sstevel@tonic-gate static off_t	boot_nfs_lseek(int, off_t, int);
727c478bd9Sstevel@tonic-gate static int	boot_nfs_fstat(int fd, struct bootstat *stp);
737c478bd9Sstevel@tonic-gate static void	boot_nfs_closeall(int flag);
747c478bd9Sstevel@tonic-gate static int	boot_nfs_getdents(int fd, struct dirent *dep, unsigned size);
757c478bd9Sstevel@tonic-gate 
767c478bd9Sstevel@tonic-gate struct boot_fs_ops boot_nfs_ops = {
777c478bd9Sstevel@tonic-gate 	"nfs",
787c478bd9Sstevel@tonic-gate 	boot_nfs_mountroot,
797c478bd9Sstevel@tonic-gate 	boot_nfs_unmountroot,
807c478bd9Sstevel@tonic-gate 	boot_nfs_open,
817c478bd9Sstevel@tonic-gate 	boot_nfs_close,
827c478bd9Sstevel@tonic-gate 	boot_nfs_read,
837c478bd9Sstevel@tonic-gate 	boot_nfs_lseek,
847c478bd9Sstevel@tonic-gate 	boot_nfs_fstat,
857c478bd9Sstevel@tonic-gate 	boot_nfs_closeall,
867c478bd9Sstevel@tonic-gate 	boot_nfs_getdents
877c478bd9Sstevel@tonic-gate };
887c478bd9Sstevel@tonic-gate 
897c478bd9Sstevel@tonic-gate /*
907c478bd9Sstevel@tonic-gate  * bootops.c calls a closeall() function to close all open files. Since
917c478bd9Sstevel@tonic-gate  * we only permit one open file at a time (not counting the device), this
927c478bd9Sstevel@tonic-gate  * is simple to implement.
937c478bd9Sstevel@tonic-gate  */
947c478bd9Sstevel@tonic-gate 
957c478bd9Sstevel@tonic-gate /*ARGSUSED*/
967c478bd9Sstevel@tonic-gate static void
977c478bd9Sstevel@tonic-gate boot_nfs_closeall(int flag)
987c478bd9Sstevel@tonic-gate {
997c478bd9Sstevel@tonic-gate 	struct nfs_files	*filep;
1007c478bd9Sstevel@tonic-gate 
1017c478bd9Sstevel@tonic-gate #ifdef NFS_OPS_DEBUG
1027c478bd9Sstevel@tonic-gate 	if ((boothowto & DBFLAGS) == DBFLAGS)
1037c478bd9Sstevel@tonic-gate 		printf("boot_nfs_closeall(%x)\n", flag);
1047c478bd9Sstevel@tonic-gate #endif
1057c478bd9Sstevel@tonic-gate 
106*986fd29aSsetje 	if (nfs_files->file.version == 0 &&
107*986fd29aSsetje 	    nfs_files->desc == 0 &&
108*986fd29aSsetje 	    nfs_files->next == NULL)
109*986fd29aSsetje 		return;
110*986fd29aSsetje 
1117c478bd9Sstevel@tonic-gate 	/* delete any dynamically allocated entries */
1127c478bd9Sstevel@tonic-gate 	while ((filep = nfs_files->next) != NULL) {
1137c478bd9Sstevel@tonic-gate 		nfs_files->next = filep->next;
1147c478bd9Sstevel@tonic-gate 		bkmem_free((caddr_t)filep, sizeof (struct  nfs_files));
1157c478bd9Sstevel@tonic-gate 	}
1167c478bd9Sstevel@tonic-gate 
1177c478bd9Sstevel@tonic-gate 	/* clear the first, static file */
1187c478bd9Sstevel@tonic-gate 	bzero((caddr_t)nfs_files, sizeof (struct nfs_files));
1197c478bd9Sstevel@tonic-gate 
1207c478bd9Sstevel@tonic-gate 	/* Close device */
1217c478bd9Sstevel@tonic-gate 	release_cache(mac_get_dev());
1227c478bd9Sstevel@tonic-gate 
1237c478bd9Sstevel@tonic-gate 	mac_fini();
1247c478bd9Sstevel@tonic-gate }
1257c478bd9Sstevel@tonic-gate 
1267c478bd9Sstevel@tonic-gate /*
1277c478bd9Sstevel@tonic-gate  * Get a file pointer given a file descriptor.  Return 0 on error
1287c478bd9Sstevel@tonic-gate  */
1297c478bd9Sstevel@tonic-gate static struct nfs_files *
1307c478bd9Sstevel@tonic-gate get_filep(int fd)
1317c478bd9Sstevel@tonic-gate {
1327c478bd9Sstevel@tonic-gate 	struct nfs_files *filep;
1337c478bd9Sstevel@tonic-gate 
1347c478bd9Sstevel@tonic-gate 	for (filep = nfs_files; filep; filep = filep->next) {
1357c478bd9Sstevel@tonic-gate 		if (fd == filep->desc)
1367c478bd9Sstevel@tonic-gate 			return (filep);
1377c478bd9Sstevel@tonic-gate 	}
1387c478bd9Sstevel@tonic-gate 	return (NULL);
1397c478bd9Sstevel@tonic-gate }
1407c478bd9Sstevel@tonic-gate 
1417c478bd9Sstevel@tonic-gate /*
1427c478bd9Sstevel@tonic-gate  * Unmount the root fs -- not supported for this fstype.
1437c478bd9Sstevel@tonic-gate  */
1447c478bd9Sstevel@tonic-gate 
1457c478bd9Sstevel@tonic-gate int
1467c478bd9Sstevel@tonic-gate boot_nfs_unmountroot(void)
1477c478bd9Sstevel@tonic-gate {
1487c478bd9Sstevel@tonic-gate 	return (-1);
1497c478bd9Sstevel@tonic-gate }
1507c478bd9Sstevel@tonic-gate 
1517c478bd9Sstevel@tonic-gate /*
1527c478bd9Sstevel@tonic-gate  * open a file for reading. Note: writing is NOT supported.
1537c478bd9Sstevel@tonic-gate  */
1547c478bd9Sstevel@tonic-gate 
1557c478bd9Sstevel@tonic-gate static int
1567c478bd9Sstevel@tonic-gate boot_nfs_open(char *path, int flags)
1577c478bd9Sstevel@tonic-gate {
1587c478bd9Sstevel@tonic-gate 	struct nfs_files *filep, *newfilep;
1597c478bd9Sstevel@tonic-gate 	int got_filep;
1607c478bd9Sstevel@tonic-gate 
1617c478bd9Sstevel@tonic-gate #ifdef NFS_OPS_DEBUG
1627c478bd9Sstevel@tonic-gate 	if ((boothowto & DBFLAGS) == DBFLAGS)
1637c478bd9Sstevel@tonic-gate 		printf("boot_nfs_open(%s, %x)\n", path, flags);
1647c478bd9Sstevel@tonic-gate #endif
1657c478bd9Sstevel@tonic-gate 
1667c478bd9Sstevel@tonic-gate 	/* file can only be opened readonly. */
1677c478bd9Sstevel@tonic-gate 	if (flags & ~O_RDONLY) {
1687c478bd9Sstevel@tonic-gate 		dprintf("boot_nfs_open: files can only be opened O_RDONLY.\n");
1697c478bd9Sstevel@tonic-gate 		return (-1);
1707c478bd9Sstevel@tonic-gate 	}
1717c478bd9Sstevel@tonic-gate 
1727c478bd9Sstevel@tonic-gate 	if (path == NULL || *path == '\0') {
1737c478bd9Sstevel@tonic-gate 		dprintf("boot_nfs_open: NULL or EMPTY pathname argument.\n");
1747c478bd9Sstevel@tonic-gate 		return (-1);
1757c478bd9Sstevel@tonic-gate 	}
1767c478bd9Sstevel@tonic-gate 
1777c478bd9Sstevel@tonic-gate 	/* Try and find a vacant file pointer */
1787c478bd9Sstevel@tonic-gate 	filep = nfs_files;
1797c478bd9Sstevel@tonic-gate 	got_filep = FALSE;
1807c478bd9Sstevel@tonic-gate 	do {
1817c478bd9Sstevel@tonic-gate 		if (filep->desc == 0) {
1827c478bd9Sstevel@tonic-gate 			filep->desc = file_desc++;
1837c478bd9Sstevel@tonic-gate 			got_filep = TRUE;
1847c478bd9Sstevel@tonic-gate 			break;		/* We've got a file pointer */
1857c478bd9Sstevel@tonic-gate 		}
1867c478bd9Sstevel@tonic-gate 		/* Get next entry if not at end of list */
1877c478bd9Sstevel@tonic-gate 		if (filep->next)
1887c478bd9Sstevel@tonic-gate 			filep = filep->next;
1897c478bd9Sstevel@tonic-gate 	} while (filep->next);
1907c478bd9Sstevel@tonic-gate 
1917c478bd9Sstevel@tonic-gate 	/* If a a vacant file pointer cannot be found, make one */
1927c478bd9Sstevel@tonic-gate 	if (!got_filep) {
1937c478bd9Sstevel@tonic-gate 		if ((newfilep = (struct nfs_files *)
1947c478bd9Sstevel@tonic-gate 		    bkmem_zalloc(sizeof (struct nfs_files))) == 0) {
1957c478bd9Sstevel@tonic-gate 			dprintf("open: Cannot allocate file pointer\n");
1967c478bd9Sstevel@tonic-gate 			return (-1);
1977c478bd9Sstevel@tonic-gate 		}
1987c478bd9Sstevel@tonic-gate 		filep->next = newfilep;
1997c478bd9Sstevel@tonic-gate 		filep = newfilep;
2007c478bd9Sstevel@tonic-gate 		filep->desc = file_desc++;
2017c478bd9Sstevel@tonic-gate 	}
2027c478bd9Sstevel@tonic-gate 
2037c478bd9Sstevel@tonic-gate 	if (lookup(path, &filep->file, FALSE) != 0) {
2047c478bd9Sstevel@tonic-gate #ifdef NFS_OPS_DEBUG
2057c478bd9Sstevel@tonic-gate 		if ((boothowto & DBFLAGS) == DBFLAGS)
2067c478bd9Sstevel@tonic-gate 			printf("boot_nfs_open(): Cannot open '%s'.\n", path);
2077c478bd9Sstevel@tonic-gate #endif
2087c478bd9Sstevel@tonic-gate 		/* zero file pointer */
2097c478bd9Sstevel@tonic-gate 		bzero((caddr_t)filep, sizeof (struct nfs_file));
2107c478bd9Sstevel@tonic-gate 		filep->desc = 0;
2117c478bd9Sstevel@tonic-gate 		return (-1);
2127c478bd9Sstevel@tonic-gate 	}
2137c478bd9Sstevel@tonic-gate 	bzero(&filep->file.cookie, sizeof (filep->file.cookie));
2147c478bd9Sstevel@tonic-gate 
2157c478bd9Sstevel@tonic-gate #ifdef NFS_OPS_DEBUG
2167c478bd9Sstevel@tonic-gate 	if ((boothowto & DBFLAGS) == DBFLAGS)
2177c478bd9Sstevel@tonic-gate 		printf("boot_nfs_open(): '%s' successful, fd = 0x%x\n",
2187c478bd9Sstevel@tonic-gate 		    path, filep->desc);
2197c478bd9Sstevel@tonic-gate #endif
2207c478bd9Sstevel@tonic-gate 	return (filep->desc);
2217c478bd9Sstevel@tonic-gate }
2227c478bd9Sstevel@tonic-gate 
2237c478bd9Sstevel@tonic-gate /*
2247c478bd9Sstevel@tonic-gate  * close a previously opened file.
2257c478bd9Sstevel@tonic-gate  */
2267c478bd9Sstevel@tonic-gate static int
2277c478bd9Sstevel@tonic-gate boot_nfs_close(int fd)
2287c478bd9Sstevel@tonic-gate {
2297c478bd9Sstevel@tonic-gate 	struct nfs_files *filep;
2307c478bd9Sstevel@tonic-gate 
2317c478bd9Sstevel@tonic-gate #ifdef NFS_OPS_DEBUG
2327c478bd9Sstevel@tonic-gate 	if ((boothowto & DBFLAGS) == DBFLAGS)
2337c478bd9Sstevel@tonic-gate 		printf("boot_nfs_close(%d)\n", fd);
2347c478bd9Sstevel@tonic-gate #endif
2357c478bd9Sstevel@tonic-gate 	if ((filep = get_filep(fd)) == 0)
2367c478bd9Sstevel@tonic-gate 		return (0);
2377c478bd9Sstevel@tonic-gate 
2387c478bd9Sstevel@tonic-gate 	/*
2397c478bd9Sstevel@tonic-gate 	 * zero file pointer
2407c478bd9Sstevel@tonic-gate 	 */
2417c478bd9Sstevel@tonic-gate 	bzero((caddr_t)&filep->file, sizeof (struct nfs_file));
2427c478bd9Sstevel@tonic-gate 
2437c478bd9Sstevel@tonic-gate 	/*
2447c478bd9Sstevel@tonic-gate 	 * "close" the fd.
2457c478bd9Sstevel@tonic-gate 	 */
2467c478bd9Sstevel@tonic-gate 	filep->desc = 0;
2477c478bd9Sstevel@tonic-gate 
2487c478bd9Sstevel@tonic-gate 	return (0);
2497c478bd9Sstevel@tonic-gate }
2507c478bd9Sstevel@tonic-gate 
2517c478bd9Sstevel@tonic-gate /*
2527c478bd9Sstevel@tonic-gate  * read from a file.
2537c478bd9Sstevel@tonic-gate  */
2547c478bd9Sstevel@tonic-gate static ssize_t
2557c478bd9Sstevel@tonic-gate boot_nfs_read(int fd, char *buf, size_t size)
2567c478bd9Sstevel@tonic-gate {
2577c478bd9Sstevel@tonic-gate 	struct nfs_files	*filep;
2587c478bd9Sstevel@tonic-gate 	int			count = 0;
2597c478bd9Sstevel@tonic-gate 
2607c478bd9Sstevel@tonic-gate 	if (fd == 0) {
2617c478bd9Sstevel@tonic-gate 		dprintf("boot_nfs_read: Bad file number.\n");
2627c478bd9Sstevel@tonic-gate 		return (-1);
2637c478bd9Sstevel@tonic-gate 	}
2647c478bd9Sstevel@tonic-gate 	if (buf == NULL) {
2657c478bd9Sstevel@tonic-gate 		dprintf("boot_nfs_read: Bad address.\n");
2667c478bd9Sstevel@tonic-gate 		return (-1);
2677c478bd9Sstevel@tonic-gate 	}
2687c478bd9Sstevel@tonic-gate 
2697c478bd9Sstevel@tonic-gate #ifdef NFS_OPS_DEBUG
2707c478bd9Sstevel@tonic-gate 	if ((boothowto & DBFLAGS) == DBFLAGS)
2717c478bd9Sstevel@tonic-gate 		printf("boot_nfs_read(%d, %x, 0x%x)\n", fd, buf, size);
2727c478bd9Sstevel@tonic-gate #endif
2737c478bd9Sstevel@tonic-gate 
2747c478bd9Sstevel@tonic-gate 	/* initialize for read */
2757c478bd9Sstevel@tonic-gate 	if ((filep = get_filep(fd)) == 0)
2767c478bd9Sstevel@tonic-gate 		return (-1);
2777c478bd9Sstevel@tonic-gate 
2787c478bd9Sstevel@tonic-gate 	switch (filep->file.version) {
2797c478bd9Sstevel@tonic-gate 	case NFS_VERSION:
2807c478bd9Sstevel@tonic-gate 		count = nfsread(&filep->file, buf, size);
2817c478bd9Sstevel@tonic-gate 		break;
2827c478bd9Sstevel@tonic-gate 	case NFS_V3:
2837c478bd9Sstevel@tonic-gate 		count = nfs3read(&filep->file, buf, size);
2847c478bd9Sstevel@tonic-gate 		break;
2857c478bd9Sstevel@tonic-gate 	case NFS_V4:
2867c478bd9Sstevel@tonic-gate 		count = nfs4read(&filep->file, buf, size);
2877c478bd9Sstevel@tonic-gate 		break;
2887c478bd9Sstevel@tonic-gate 	default:
2897c478bd9Sstevel@tonic-gate 		printf("boot_nfs_read: NFS Version %d not supported\n",
2907c478bd9Sstevel@tonic-gate 		    filep->file.version);
2917c478bd9Sstevel@tonic-gate 		count = -1;
2927c478bd9Sstevel@tonic-gate 		break;
2937c478bd9Sstevel@tonic-gate 	}
2947c478bd9Sstevel@tonic-gate 
2957c478bd9Sstevel@tonic-gate #ifdef NFS_OPS_DEBUG
2967c478bd9Sstevel@tonic-gate 	if ((boothowto & DBFLAGS) == DBFLAGS)
2977c478bd9Sstevel@tonic-gate 		printf("boot_nfs_read(): 0x%x bytes.\n", count);
2987c478bd9Sstevel@tonic-gate #endif
2997c478bd9Sstevel@tonic-gate 	return (count);
3007c478bd9Sstevel@tonic-gate }
3017c478bd9Sstevel@tonic-gate 
3027c478bd9Sstevel@tonic-gate /*
3037c478bd9Sstevel@tonic-gate  * lseek - move read file pointer.
3047c478bd9Sstevel@tonic-gate  */
3057c478bd9Sstevel@tonic-gate 
3067c478bd9Sstevel@tonic-gate static off_t
3077c478bd9Sstevel@tonic-gate boot_nfs_lseek(int fd, off_t offset, int whence)
3087c478bd9Sstevel@tonic-gate {
3097c478bd9Sstevel@tonic-gate 	struct nfs_files *filep;
3107c478bd9Sstevel@tonic-gate 
3117c478bd9Sstevel@tonic-gate #ifdef NFS_OPS_DEBUG
3127c478bd9Sstevel@tonic-gate 	if ((boothowto & DBFLAGS) == DBFLAGS)
3137c478bd9Sstevel@tonic-gate 		printf("boot_nfs_lseek(%d, 0x%x, %d)\n", fd, offset, whence);
3147c478bd9Sstevel@tonic-gate #endif
3157c478bd9Sstevel@tonic-gate 
3167c478bd9Sstevel@tonic-gate 	if (fd == 0) {
3177c478bd9Sstevel@tonic-gate 		dprintf("boot_nfs_lseek: Bad file number.\n");
3187c478bd9Sstevel@tonic-gate 		return (-1);
3197c478bd9Sstevel@tonic-gate 	}
3207c478bd9Sstevel@tonic-gate 
3217c478bd9Sstevel@tonic-gate 	if ((filep = get_filep(fd)) == 0)
3227c478bd9Sstevel@tonic-gate 		return (-1);
3237c478bd9Sstevel@tonic-gate 
3247c478bd9Sstevel@tonic-gate 	switch (whence) {
3257c478bd9Sstevel@tonic-gate 
3267c478bd9Sstevel@tonic-gate 	case SEEK_SET:
3277c478bd9Sstevel@tonic-gate 		/*
3287c478bd9Sstevel@tonic-gate 		 * file ptr is set to offset from beginning of file
3297c478bd9Sstevel@tonic-gate 		 */
3307c478bd9Sstevel@tonic-gate 		filep->file.offset = offset;
3317c478bd9Sstevel@tonic-gate 		break;
3327c478bd9Sstevel@tonic-gate 	case SEEK_CUR:
3337c478bd9Sstevel@tonic-gate 		/*
3347c478bd9Sstevel@tonic-gate 		 * file ptr is set to offset from current position
3357c478bd9Sstevel@tonic-gate 		 */
3367c478bd9Sstevel@tonic-gate 		filep->file.offset += offset;
3377c478bd9Sstevel@tonic-gate 		break;
3387c478bd9Sstevel@tonic-gate 	case SEEK_END:
3397c478bd9Sstevel@tonic-gate 		/*
3407c478bd9Sstevel@tonic-gate 		 * file ptr is set to current size of file plus offset.
3417c478bd9Sstevel@tonic-gate 		 * But since we only support reading, this is illegal.
3427c478bd9Sstevel@tonic-gate 		 */
3437c478bd9Sstevel@tonic-gate 	default:
3447c478bd9Sstevel@tonic-gate 		/*
3457c478bd9Sstevel@tonic-gate 		 * invalid offset origin
3467c478bd9Sstevel@tonic-gate 		 */
3477c478bd9Sstevel@tonic-gate 		dprintf("boot_nfs_lseek: invalid whence value.\n");
3487c478bd9Sstevel@tonic-gate 		return (-1);
3497c478bd9Sstevel@tonic-gate 	}
3507c478bd9Sstevel@tonic-gate 
3517c478bd9Sstevel@tonic-gate #ifdef notyet
3527c478bd9Sstevel@tonic-gate 	return (filep->file.offset);
3537c478bd9Sstevel@tonic-gate #else
3547c478bd9Sstevel@tonic-gate 	/*
3557c478bd9Sstevel@tonic-gate 	 * BROKE - lseek should return the offset seeked to on a
3567c478bd9Sstevel@tonic-gate 	 * successful seek, not zero - This must be fixed in the
3577c478bd9Sstevel@tonic-gate 	 * kernel before It can be fixed here.
3587c478bd9Sstevel@tonic-gate 	 */
3597c478bd9Sstevel@tonic-gate 	return (0);
3607c478bd9Sstevel@tonic-gate #endif /* notyet */
3617c478bd9Sstevel@tonic-gate }
3627c478bd9Sstevel@tonic-gate 
3637c478bd9Sstevel@tonic-gate /*
3647c478bd9Sstevel@tonic-gate  * This version of fstat supports mode, size, inode #, and times only.
3657c478bd9Sstevel@tonic-gate  * It can be enhanced if more is required,
3667c478bd9Sstevel@tonic-gate  */
3677c478bd9Sstevel@tonic-gate 
3687c478bd9Sstevel@tonic-gate static int
3697c478bd9Sstevel@tonic-gate boot_nfs_fstat(int fd, struct bootstat *stp)
3707c478bd9Sstevel@tonic-gate {
3717c478bd9Sstevel@tonic-gate 	struct vattr va;
3727c478bd9Sstevel@tonic-gate 	struct nfs_files *filep;
3737c478bd9Sstevel@tonic-gate 	int status;
3747c478bd9Sstevel@tonic-gate 
3757c478bd9Sstevel@tonic-gate #ifdef NFS_OPS_DEBUG
3767c478bd9Sstevel@tonic-gate 	if ((boothowto & DBFLAGS) == DBFLAGS) {
3777c478bd9Sstevel@tonic-gate 		printf("boot_nfs_fstat(%d, 0x%x)\n", fd, stp);
3787c478bd9Sstevel@tonic-gate 	}
3797c478bd9Sstevel@tonic-gate #endif
3807c478bd9Sstevel@tonic-gate 	if (fd == 0) {
3817c478bd9Sstevel@tonic-gate 		dprintf("boot_nfs_fstat(): Bad file number 0.\n");
3827c478bd9Sstevel@tonic-gate 		return (-1);
3837c478bd9Sstevel@tonic-gate 	}
3847c478bd9Sstevel@tonic-gate 
3857c478bd9Sstevel@tonic-gate 	if ((filep = get_filep(fd)) == 0)
3867c478bd9Sstevel@tonic-gate 		return (-1);
3877c478bd9Sstevel@tonic-gate 
3887c478bd9Sstevel@tonic-gate 	bzero((char *)&va, sizeof (va));
389*986fd29aSsetje 	va.va_mask = AT_TYPE | AT_SIZE | AT_MODE | AT_NODEID |
3907c478bd9Sstevel@tonic-gate 	    AT_ATIME | AT_CTIME | AT_MTIME;
3917c478bd9Sstevel@tonic-gate 
3927c478bd9Sstevel@tonic-gate 	switch (filep->file.version) {
3937c478bd9Sstevel@tonic-gate 	case NFS_VERSION:
3947c478bd9Sstevel@tonic-gate 		status = nfsgetattr(&filep->file, &va);
3957c478bd9Sstevel@tonic-gate 		break;
3967c478bd9Sstevel@tonic-gate 	case NFS_V3:
3977c478bd9Sstevel@tonic-gate 		status = nfs3getattr(&filep->file, &va);
3987c478bd9Sstevel@tonic-gate 		break;
3997c478bd9Sstevel@tonic-gate 	case NFS_V4:
4007c478bd9Sstevel@tonic-gate 		status = nfs4getattr(&filep->file, &va);
4017c478bd9Sstevel@tonic-gate 		break;
4027c478bd9Sstevel@tonic-gate 	default:
4037c478bd9Sstevel@tonic-gate 		printf("boot_nfs_fstat: NFS Version %d not supported\n",
4047c478bd9Sstevel@tonic-gate 		    filep->file.version);
4057c478bd9Sstevel@tonic-gate 		status = -1;
4067c478bd9Sstevel@tonic-gate 		break;
4077c478bd9Sstevel@tonic-gate 	}
4087c478bd9Sstevel@tonic-gate 
4097c478bd9Sstevel@tonic-gate 	if (status != 0)
4107c478bd9Sstevel@tonic-gate 		return (-1);
4117c478bd9Sstevel@tonic-gate 
4127c478bd9Sstevel@tonic-gate 	if (va.va_size > (u_offset_t)MAXOFF_T) {
4137c478bd9Sstevel@tonic-gate 		dprintf("boot_nfs_fstat(): File too large.\n");
4147c478bd9Sstevel@tonic-gate 		return (-1);
4157c478bd9Sstevel@tonic-gate 	}
4167c478bd9Sstevel@tonic-gate 	stp->st_size = (off_t)va.va_size;
4177c478bd9Sstevel@tonic-gate 	stp->st_mode = VTTOIF(va.va_type) | va.va_mode;
4187c478bd9Sstevel@tonic-gate 	stp->st_atim.tv_sec = va.va_atime.tv_sec;
4197c478bd9Sstevel@tonic-gate 	stp->st_atim.tv_nsec = va.va_atime.tv_nsec;
4207c478bd9Sstevel@tonic-gate 	stp->st_ctim.tv_sec = va.va_ctime.tv_sec;
4217c478bd9Sstevel@tonic-gate 	stp->st_ctim.tv_nsec = va.va_ctime.tv_nsec;
4227c478bd9Sstevel@tonic-gate 	stp->st_mtim.tv_sec = va.va_mtime.tv_sec;
4237c478bd9Sstevel@tonic-gate 	stp->st_mtim.tv_nsec = va.va_mtime.tv_nsec;
4247c478bd9Sstevel@tonic-gate 	stp->st_ino = (ino_t)va.va_nodeid;
4257c478bd9Sstevel@tonic-gate 
4267c478bd9Sstevel@tonic-gate #ifdef NFS_OPS_DEBUG
4277c478bd9Sstevel@tonic-gate 	if ((boothowto & DBFLAGS) == DBFLAGS)
4287c478bd9Sstevel@tonic-gate 		printf("boot_nfs_fstat(): done.\n");
4297c478bd9Sstevel@tonic-gate #endif
4307c478bd9Sstevel@tonic-gate 	return (0);
4317c478bd9Sstevel@tonic-gate }
4327c478bd9Sstevel@tonic-gate 
4337c478bd9Sstevel@tonic-gate static int
4347c478bd9Sstevel@tonic-gate boot_nfs_getdents(int fd, struct dirent *dep, unsigned size)
4357c478bd9Sstevel@tonic-gate {
4367c478bd9Sstevel@tonic-gate 	struct nfs_files *filep;
4377c478bd9Sstevel@tonic-gate 	int status;
4387c478bd9Sstevel@tonic-gate 
4397c478bd9Sstevel@tonic-gate #ifdef NFS_OPS_DEBUG
4407c478bd9Sstevel@tonic-gate 	if ((boothowto & DBFLAGS) == DBFLAGS) {
4417c478bd9Sstevel@tonic-gate 		printf("boot_nfs_getdents(%d, 0x%x, 0x%x)\n", fd, dep, size);
4427c478bd9Sstevel@tonic-gate 	}
4437c478bd9Sstevel@tonic-gate #endif
4447c478bd9Sstevel@tonic-gate 
4457c478bd9Sstevel@tonic-gate 	if (fd == 0) {
4467c478bd9Sstevel@tonic-gate 		dprintf("boot_nfs_getdents(): Bad file number 0.\n");
4477c478bd9Sstevel@tonic-gate 		return (-1);
4487c478bd9Sstevel@tonic-gate 	}
4497c478bd9Sstevel@tonic-gate 
4507c478bd9Sstevel@tonic-gate 	if ((filep = get_filep(fd)) == 0)
4517c478bd9Sstevel@tonic-gate 		return (-1);
4527c478bd9Sstevel@tonic-gate 
4537c478bd9Sstevel@tonic-gate 	switch (filep->file.version) {
4547c478bd9Sstevel@tonic-gate 	case NFS_VERSION:
4557c478bd9Sstevel@tonic-gate 		status = nfsgetdents(&filep->file, dep, size);
4567c478bd9Sstevel@tonic-gate 		break;
4577c478bd9Sstevel@tonic-gate 	case NFS_V3:
4587c478bd9Sstevel@tonic-gate 		status = nfs3getdents(&filep->file, dep, size);
4597c478bd9Sstevel@tonic-gate 		break;
4607c478bd9Sstevel@tonic-gate 	default:
4617c478bd9Sstevel@tonic-gate 		printf("boot_nfs_getdents: NFS Version %d not supported\n",
4627c478bd9Sstevel@tonic-gate 		    filep->file.version);
4637c478bd9Sstevel@tonic-gate 		status = -1;
4647c478bd9Sstevel@tonic-gate 	}
4657c478bd9Sstevel@tonic-gate 
4667c478bd9Sstevel@tonic-gate #ifdef NFS_OPS_DEBUG
4677c478bd9Sstevel@tonic-gate 	if ((boothowto & DBFLAGS) == DBFLAGS)
4687c478bd9Sstevel@tonic-gate 		printf("boot_nfs_getdents(): done.\n");
4697c478bd9Sstevel@tonic-gate #endif
4707c478bd9Sstevel@tonic-gate 	return (status);
4717c478bd9Sstevel@tonic-gate }
472