1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 25*7c478bd9Sstevel@tonic-gate * 26*7c478bd9Sstevel@tonic-gate * Simple nfs ops - open, close, read, and lseek. 27*7c478bd9Sstevel@tonic-gate */ 28*7c478bd9Sstevel@tonic-gate 29*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 30*7c478bd9Sstevel@tonic-gate 31*7c478bd9Sstevel@tonic-gate #include <rpc/types.h> 32*7c478bd9Sstevel@tonic-gate #include <rpc/auth.h> 33*7c478bd9Sstevel@tonic-gate #include <sys/t_lock.h> 34*7c478bd9Sstevel@tonic-gate #include "clnt.h" 35*7c478bd9Sstevel@tonic-gate #include <sys/fcntl.h> 36*7c478bd9Sstevel@tonic-gate #include <sys/vfs.h> 37*7c478bd9Sstevel@tonic-gate #include <errno.h> 38*7c478bd9Sstevel@tonic-gate #include <sys/promif.h> 39*7c478bd9Sstevel@tonic-gate #include <rpc/xdr.h> 40*7c478bd9Sstevel@tonic-gate #include "nfs_inet.h" 41*7c478bd9Sstevel@tonic-gate #include <sys/stat.h> 42*7c478bd9Sstevel@tonic-gate #include <sys/bootvfs.h> 43*7c478bd9Sstevel@tonic-gate #include <sys/bootdebug.h> 44*7c478bd9Sstevel@tonic-gate #include <sys/salib.h> 45*7c478bd9Sstevel@tonic-gate #include <sys/sacache.h> 46*7c478bd9Sstevel@tonic-gate #include <rpc/rpc.h> 47*7c478bd9Sstevel@tonic-gate #include "brpc.h" 48*7c478bd9Sstevel@tonic-gate #include <rpcsvc/nfs_prot.h> 49*7c478bd9Sstevel@tonic-gate 50*7c478bd9Sstevel@tonic-gate #define dprintf if (boothowto & RB_DEBUG) printf 51*7c478bd9Sstevel@tonic-gate 52*7c478bd9Sstevel@tonic-gate static struct timeval zero_timeout = {0, 0}; /* default */ 53*7c478bd9Sstevel@tonic-gate 54*7c478bd9Sstevel@tonic-gate /* 55*7c478bd9Sstevel@tonic-gate * NFS Version 2 specific functions 56*7c478bd9Sstevel@tonic-gate */ 57*7c478bd9Sstevel@tonic-gate 58*7c478bd9Sstevel@tonic-gate ssize_t 59*7c478bd9Sstevel@tonic-gate nfsread(struct nfs_file *filep, char *buf, size_t size) 60*7c478bd9Sstevel@tonic-gate { 61*7c478bd9Sstevel@tonic-gate readargs read_args; 62*7c478bd9Sstevel@tonic-gate readres read_res; 63*7c478bd9Sstevel@tonic-gate enum clnt_stat read_stat; 64*7c478bd9Sstevel@tonic-gate uint_t readcnt = 0; /* # bytes read by nfs */ 65*7c478bd9Sstevel@tonic-gate uint_t count = 0; /* # bytes transferred to buf */ 66*7c478bd9Sstevel@tonic-gate int done = FALSE; /* last block has come in */ 67*7c478bd9Sstevel@tonic-gate int framing_errs = 0; /* stack errors */ 68*7c478bd9Sstevel@tonic-gate char *buf_offset; /* current buffer offset */ 69*7c478bd9Sstevel@tonic-gate struct timeval timeout; 70*7c478bd9Sstevel@tonic-gate #ifndef i386 71*7c478bd9Sstevel@tonic-gate static uint_t pos; /* progress indicator counter */ 72*7c478bd9Sstevel@tonic-gate static char ind[] = "|/-\\"; /* progress indicator */ 73*7c478bd9Sstevel@tonic-gate static int blks_read; 74*7c478bd9Sstevel@tonic-gate #endif 75*7c478bd9Sstevel@tonic-gate 76*7c478bd9Sstevel@tonic-gate read_args.file = filep->fh.fh2; /* structure copy */ 77*7c478bd9Sstevel@tonic-gate read_args.offset = filep->offset; 78*7c478bd9Sstevel@tonic-gate buf_offset = buf; 79*7c478bd9Sstevel@tonic-gate 80*7c478bd9Sstevel@tonic-gate /* Optimize for reads of less than one block size */ 81*7c478bd9Sstevel@tonic-gate 82*7c478bd9Sstevel@tonic-gate if (nfs_readsize == 0) 83*7c478bd9Sstevel@tonic-gate nfs_readsize = READ_SIZE; 84*7c478bd9Sstevel@tonic-gate 85*7c478bd9Sstevel@tonic-gate if (size < nfs_readsize) 86*7c478bd9Sstevel@tonic-gate read_args.count = size; 87*7c478bd9Sstevel@tonic-gate else 88*7c478bd9Sstevel@tonic-gate read_args.count = nfs_readsize; 89*7c478bd9Sstevel@tonic-gate 90*7c478bd9Sstevel@tonic-gate do { 91*7c478bd9Sstevel@tonic-gate /* use the user's buffer to stuff the data into. */ 92*7c478bd9Sstevel@tonic-gate read_res.readres_u.reply.data.data_val = buf_offset; 93*7c478bd9Sstevel@tonic-gate 94*7c478bd9Sstevel@tonic-gate /* 95*7c478bd9Sstevel@tonic-gate * Handle the case where the file does not end 96*7c478bd9Sstevel@tonic-gate * on a block boundary. 97*7c478bd9Sstevel@tonic-gate */ 98*7c478bd9Sstevel@tonic-gate if ((count + read_args.count) > size) 99*7c478bd9Sstevel@tonic-gate read_args.count = size - count; 100*7c478bd9Sstevel@tonic-gate 101*7c478bd9Sstevel@tonic-gate timeout.tv_sec = NFS_REXMIT_MIN; /* Total wait for call */ 102*7c478bd9Sstevel@tonic-gate timeout.tv_usec = 0; 103*7c478bd9Sstevel@tonic-gate do { 104*7c478bd9Sstevel@tonic-gate read_stat = CLNT_CALL(root_CLIENT, NFSPROC_READ, 105*7c478bd9Sstevel@tonic-gate xdr_readargs, (caddr_t)&read_args, 106*7c478bd9Sstevel@tonic-gate xdr_readres, (caddr_t)&read_res, timeout); 107*7c478bd9Sstevel@tonic-gate 108*7c478bd9Sstevel@tonic-gate if (read_stat == RPC_TIMEDOUT) { 109*7c478bd9Sstevel@tonic-gate dprintf("NFS read(%d) timed out. Retrying...\n", 110*7c478bd9Sstevel@tonic-gate read_args.count); 111*7c478bd9Sstevel@tonic-gate /* 112*7c478bd9Sstevel@tonic-gate * If the remote is there and trying to respond, 113*7c478bd9Sstevel@tonic-gate * but our stack is having trouble reassembling 114*7c478bd9Sstevel@tonic-gate * the reply, reduce the read size in an 115*7c478bd9Sstevel@tonic-gate * attempt to compensate. Reset the 116*7c478bd9Sstevel@tonic-gate * transmission and reply wait timers. 117*7c478bd9Sstevel@tonic-gate */ 118*7c478bd9Sstevel@tonic-gate if (errno == ETIMEDOUT) 119*7c478bd9Sstevel@tonic-gate framing_errs++; 120*7c478bd9Sstevel@tonic-gate 121*7c478bd9Sstevel@tonic-gate if (framing_errs > NFS_MAX_FERRS && 122*7c478bd9Sstevel@tonic-gate read_args.count > NFS_READ_DECR) { 123*7c478bd9Sstevel@tonic-gate read_args.count -= NFS_READ_DECR; 124*7c478bd9Sstevel@tonic-gate nfs_readsize -= NFS_READ_DECR; 125*7c478bd9Sstevel@tonic-gate dprintf("NFS Read size now %d.\n", 126*7c478bd9Sstevel@tonic-gate nfs_readsize); 127*7c478bd9Sstevel@tonic-gate timeout.tv_sec = NFS_REXMIT_MIN; 128*7c478bd9Sstevel@tonic-gate framing_errs = 0; 129*7c478bd9Sstevel@tonic-gate } else { 130*7c478bd9Sstevel@tonic-gate if (timeout.tv_sec < NFS_REXMIT_MAX) 131*7c478bd9Sstevel@tonic-gate timeout.tv_sec++; 132*7c478bd9Sstevel@tonic-gate else 133*7c478bd9Sstevel@tonic-gate timeout.tv_sec = 0; 134*7c478bd9Sstevel@tonic-gate /* default RPC */ 135*7c478bd9Sstevel@tonic-gate } 136*7c478bd9Sstevel@tonic-gate } 137*7c478bd9Sstevel@tonic-gate } while (read_stat == RPC_TIMEDOUT); 138*7c478bd9Sstevel@tonic-gate 139*7c478bd9Sstevel@tonic-gate if (read_stat != RPC_SUCCESS) 140*7c478bd9Sstevel@tonic-gate return (-1); 141*7c478bd9Sstevel@tonic-gate 142*7c478bd9Sstevel@tonic-gate readcnt = read_res.readres_u.reply.data.data_len; 143*7c478bd9Sstevel@tonic-gate /* 144*7c478bd9Sstevel@tonic-gate * Handle the case where the file is simply empty, and 145*7c478bd9Sstevel@tonic-gate * nothing could be read. 146*7c478bd9Sstevel@tonic-gate */ 147*7c478bd9Sstevel@tonic-gate if (readcnt == 0) 148*7c478bd9Sstevel@tonic-gate break; /* eof */ 149*7c478bd9Sstevel@tonic-gate 150*7c478bd9Sstevel@tonic-gate /* 151*7c478bd9Sstevel@tonic-gate * Handle the case where the file is smaller than 152*7c478bd9Sstevel@tonic-gate * the size of the read request, thus the request 153*7c478bd9Sstevel@tonic-gate * couldn't be completely filled. 154*7c478bd9Sstevel@tonic-gate */ 155*7c478bd9Sstevel@tonic-gate if (readcnt < read_args.count) { 156*7c478bd9Sstevel@tonic-gate #ifdef NFS_OPS_DEBUG 157*7c478bd9Sstevel@tonic-gate if ((boothowto & DBFLAGS) == DBFLAGS) 158*7c478bd9Sstevel@tonic-gate printf("nfsread(): partial read %d" 159*7c478bd9Sstevel@tonic-gate " instead of %d\n", 160*7c478bd9Sstevel@tonic-gate readcnt, read_args.count); 161*7c478bd9Sstevel@tonic-gate #endif 162*7c478bd9Sstevel@tonic-gate done = TRUE; /* update the counts and exit */ 163*7c478bd9Sstevel@tonic-gate } 164*7c478bd9Sstevel@tonic-gate 165*7c478bd9Sstevel@tonic-gate /* update various offsets */ 166*7c478bd9Sstevel@tonic-gate count += readcnt; 167*7c478bd9Sstevel@tonic-gate filep->offset += readcnt; 168*7c478bd9Sstevel@tonic-gate buf_offset += readcnt; 169*7c478bd9Sstevel@tonic-gate read_args.offset += readcnt; 170*7c478bd9Sstevel@tonic-gate #ifndef i386 171*7c478bd9Sstevel@tonic-gate /* 172*7c478bd9Sstevel@tonic-gate * round and round she goes (though not on every block.. 173*7c478bd9Sstevel@tonic-gate * - OBP's take a fair bit of time to actually print stuff) 174*7c478bd9Sstevel@tonic-gate */ 175*7c478bd9Sstevel@tonic-gate if ((blks_read++ & 0x3) == 0) 176*7c478bd9Sstevel@tonic-gate printf("%c\b", ind[pos++ & 3]); 177*7c478bd9Sstevel@tonic-gate #endif 178*7c478bd9Sstevel@tonic-gate } while (count < size && !done); 179*7c478bd9Sstevel@tonic-gate 180*7c478bd9Sstevel@tonic-gate return (count); 181*7c478bd9Sstevel@tonic-gate } 182*7c478bd9Sstevel@tonic-gate 183*7c478bd9Sstevel@tonic-gate static vtype_t nf_to_vt[] = { 184*7c478bd9Sstevel@tonic-gate VNON, VREG, VDIR, VBLK, VCHR, VLNK, VSOCK 185*7c478bd9Sstevel@tonic-gate }; 186*7c478bd9Sstevel@tonic-gate 187*7c478bd9Sstevel@tonic-gate int 188*7c478bd9Sstevel@tonic-gate nfsgetattr(struct nfs_file *nfp, struct vattr *vap) 189*7c478bd9Sstevel@tonic-gate { 190*7c478bd9Sstevel@tonic-gate enum clnt_stat getattr_stat; 191*7c478bd9Sstevel@tonic-gate attrstat getattr_res; 192*7c478bd9Sstevel@tonic-gate fattr *na; 193*7c478bd9Sstevel@tonic-gate struct timeval timeout = {0, 0}; /* default */ 194*7c478bd9Sstevel@tonic-gate 195*7c478bd9Sstevel@tonic-gate getattr_stat = CLNT_CALL(root_CLIENT, NFSPROC_GETATTR, 196*7c478bd9Sstevel@tonic-gate xdr_nfs_fh, (caddr_t)&(nfp->fh.fh2), 197*7c478bd9Sstevel@tonic-gate xdr_attrstat, (caddr_t)&getattr_res, timeout); 198*7c478bd9Sstevel@tonic-gate 199*7c478bd9Sstevel@tonic-gate if (getattr_stat != RPC_SUCCESS) { 200*7c478bd9Sstevel@tonic-gate dprintf("nfs_getattr: RPC error %d\n", getattr_stat); 201*7c478bd9Sstevel@tonic-gate return (-1); 202*7c478bd9Sstevel@tonic-gate } 203*7c478bd9Sstevel@tonic-gate if (getattr_res.status != NFS_OK) { 204*7c478bd9Sstevel@tonic-gate nfs_error(getattr_res.status); 205*7c478bd9Sstevel@tonic-gate return (getattr_res.status); 206*7c478bd9Sstevel@tonic-gate } 207*7c478bd9Sstevel@tonic-gate 208*7c478bd9Sstevel@tonic-gate /* adapted from nattr_to_vattr() in nfs_client.c */ 209*7c478bd9Sstevel@tonic-gate 210*7c478bd9Sstevel@tonic-gate na = &getattr_res.attrstat_u.attributes; 211*7c478bd9Sstevel@tonic-gate if (vap->va_mask & AT_TYPE) { 212*7c478bd9Sstevel@tonic-gate if (na->type < NFNON || na->type > NFSOCK) 213*7c478bd9Sstevel@tonic-gate vap->va_type = VBAD; 214*7c478bd9Sstevel@tonic-gate else 215*7c478bd9Sstevel@tonic-gate vap->va_type = nf_to_vt[na->type]; 216*7c478bd9Sstevel@tonic-gate } 217*7c478bd9Sstevel@tonic-gate if (vap->va_mask & AT_MODE) 218*7c478bd9Sstevel@tonic-gate vap->va_mode = na->mode; 219*7c478bd9Sstevel@tonic-gate if (vap->va_mask & AT_SIZE) 220*7c478bd9Sstevel@tonic-gate vap->va_size = na->size; 221*7c478bd9Sstevel@tonic-gate if (vap->va_mask & AT_NODEID) 222*7c478bd9Sstevel@tonic-gate vap->va_nodeid = na->fileid; 223*7c478bd9Sstevel@tonic-gate if (vap->va_mask & AT_ATIME) { 224*7c478bd9Sstevel@tonic-gate vap->va_atime.tv_sec = na->atime.seconds; 225*7c478bd9Sstevel@tonic-gate vap->va_atime.tv_nsec = na->atime.useconds * 1000; 226*7c478bd9Sstevel@tonic-gate } 227*7c478bd9Sstevel@tonic-gate if (vap->va_mask & AT_CTIME) { 228*7c478bd9Sstevel@tonic-gate vap->va_ctime.tv_sec = na->ctime.seconds; 229*7c478bd9Sstevel@tonic-gate vap->va_ctime.tv_nsec = na->ctime.useconds * 1000; 230*7c478bd9Sstevel@tonic-gate } 231*7c478bd9Sstevel@tonic-gate if (vap->va_mask & AT_MTIME) { 232*7c478bd9Sstevel@tonic-gate vap->va_mtime.tv_sec = na->mtime.seconds; 233*7c478bd9Sstevel@tonic-gate vap->va_mtime.tv_nsec = na->mtime.useconds * 1000; 234*7c478bd9Sstevel@tonic-gate } 235*7c478bd9Sstevel@tonic-gate 236*7c478bd9Sstevel@tonic-gate #ifdef NFS_OPS_DEBUG 237*7c478bd9Sstevel@tonic-gate if ((boothowto & DBFLAGS) == DBFLAGS) 238*7c478bd9Sstevel@tonic-gate printf("nfs_getattr(): done.\n"); 239*7c478bd9Sstevel@tonic-gate #endif 240*7c478bd9Sstevel@tonic-gate return (getattr_res.status); 241*7c478bd9Sstevel@tonic-gate } 242*7c478bd9Sstevel@tonic-gate 243*7c478bd9Sstevel@tonic-gate /* 244*7c478bd9Sstevel@tonic-gate * Display nfs error messages. 245*7c478bd9Sstevel@tonic-gate */ 246*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 247*7c478bd9Sstevel@tonic-gate void 248*7c478bd9Sstevel@tonic-gate nfs_error(enum nfsstat status) 249*7c478bd9Sstevel@tonic-gate { 250*7c478bd9Sstevel@tonic-gate if (!(boothowto & RB_DEBUG)) 251*7c478bd9Sstevel@tonic-gate return; 252*7c478bd9Sstevel@tonic-gate 253*7c478bd9Sstevel@tonic-gate switch (status) { 254*7c478bd9Sstevel@tonic-gate case NFSERR_PERM: 255*7c478bd9Sstevel@tonic-gate printf("NFS: Not owner.\n"); 256*7c478bd9Sstevel@tonic-gate break; 257*7c478bd9Sstevel@tonic-gate case NFSERR_NOENT: 258*7c478bd9Sstevel@tonic-gate #ifdef NFS_OPS_DEBUG 259*7c478bd9Sstevel@tonic-gate printf("NFS: No such file or directory.\n"); 260*7c478bd9Sstevel@tonic-gate #endif /* NFS_OPS_DEBUG */ 261*7c478bd9Sstevel@tonic-gate break; 262*7c478bd9Sstevel@tonic-gate case NFSERR_IO: 263*7c478bd9Sstevel@tonic-gate printf("NFS: IO ERROR occurred on NFS server.\n"); 264*7c478bd9Sstevel@tonic-gate break; 265*7c478bd9Sstevel@tonic-gate case NFSERR_NXIO: 266*7c478bd9Sstevel@tonic-gate printf("NFS: No such device or address.\n"); 267*7c478bd9Sstevel@tonic-gate break; 268*7c478bd9Sstevel@tonic-gate case NFSERR_ACCES: 269*7c478bd9Sstevel@tonic-gate printf("NFS: Permission denied.\n"); 270*7c478bd9Sstevel@tonic-gate break; 271*7c478bd9Sstevel@tonic-gate case NFSERR_EXIST: 272*7c478bd9Sstevel@tonic-gate printf("NFS: File exists.\n"); 273*7c478bd9Sstevel@tonic-gate break; 274*7c478bd9Sstevel@tonic-gate case NFSERR_NODEV: 275*7c478bd9Sstevel@tonic-gate printf("NFS: No such device.\n"); 276*7c478bd9Sstevel@tonic-gate break; 277*7c478bd9Sstevel@tonic-gate case NFSERR_NOTDIR: 278*7c478bd9Sstevel@tonic-gate printf("NFS: Not a directory.\n"); 279*7c478bd9Sstevel@tonic-gate break; 280*7c478bd9Sstevel@tonic-gate case NFSERR_ISDIR: 281*7c478bd9Sstevel@tonic-gate printf("NFS: Is a directory.\n"); 282*7c478bd9Sstevel@tonic-gate break; 283*7c478bd9Sstevel@tonic-gate case NFSERR_FBIG: 284*7c478bd9Sstevel@tonic-gate printf("NFS: File too large.\n"); 285*7c478bd9Sstevel@tonic-gate break; 286*7c478bd9Sstevel@tonic-gate case NFSERR_NOSPC: 287*7c478bd9Sstevel@tonic-gate printf("NFS: No space left on device.\n"); 288*7c478bd9Sstevel@tonic-gate break; 289*7c478bd9Sstevel@tonic-gate case NFSERR_ROFS: 290*7c478bd9Sstevel@tonic-gate printf("NFS: Read-only filesystem.\n"); 291*7c478bd9Sstevel@tonic-gate break; 292*7c478bd9Sstevel@tonic-gate case NFSERR_NAMETOOLONG: 293*7c478bd9Sstevel@tonic-gate printf("NFS: File name too long.\n"); 294*7c478bd9Sstevel@tonic-gate break; 295*7c478bd9Sstevel@tonic-gate case NFSERR_NOTEMPTY: 296*7c478bd9Sstevel@tonic-gate printf("NFS: Directory not empty.\n"); 297*7c478bd9Sstevel@tonic-gate break; 298*7c478bd9Sstevel@tonic-gate case NFSERR_DQUOT: 299*7c478bd9Sstevel@tonic-gate printf("NFS: Disk quota exceeded.\n"); 300*7c478bd9Sstevel@tonic-gate break; 301*7c478bd9Sstevel@tonic-gate case NFSERR_STALE: 302*7c478bd9Sstevel@tonic-gate printf("NFS: Stale file handle.\n"); 303*7c478bd9Sstevel@tonic-gate break; 304*7c478bd9Sstevel@tonic-gate case NFSERR_WFLUSH: 305*7c478bd9Sstevel@tonic-gate printf("NFS: server's write cache has been flushed.\n"); 306*7c478bd9Sstevel@tonic-gate break; 307*7c478bd9Sstevel@tonic-gate default: 308*7c478bd9Sstevel@tonic-gate printf("NFS: unknown error.\n"); 309*7c478bd9Sstevel@tonic-gate break; 310*7c478bd9Sstevel@tonic-gate } 311*7c478bd9Sstevel@tonic-gate } 312*7c478bd9Sstevel@tonic-gate 313*7c478bd9Sstevel@tonic-gate struct nfs_file * 314*7c478bd9Sstevel@tonic-gate nfslookup(struct nfs_file *dir, char *name, int *nstat) 315*7c478bd9Sstevel@tonic-gate { 316*7c478bd9Sstevel@tonic-gate static struct nfs_file cd; 317*7c478bd9Sstevel@tonic-gate diropargs dirop; 318*7c478bd9Sstevel@tonic-gate diropres res_lookup; 319*7c478bd9Sstevel@tonic-gate enum clnt_stat status; 320*7c478bd9Sstevel@tonic-gate 321*7c478bd9Sstevel@tonic-gate *nstat = (int)NFS_OK; 322*7c478bd9Sstevel@tonic-gate 323*7c478bd9Sstevel@tonic-gate bcopy(&dir->fh.fh2, &dirop.dir, NFS_FHSIZE); 324*7c478bd9Sstevel@tonic-gate dirop.name = name; 325*7c478bd9Sstevel@tonic-gate 326*7c478bd9Sstevel@tonic-gate status = CLNT_CALL(root_CLIENT, NFSPROC_LOOKUP, xdr_diropargs, 327*7c478bd9Sstevel@tonic-gate (caddr_t)&dirop, xdr_diropres, (caddr_t)&res_lookup, 328*7c478bd9Sstevel@tonic-gate zero_timeout); 329*7c478bd9Sstevel@tonic-gate if (status != RPC_SUCCESS) { 330*7c478bd9Sstevel@tonic-gate dprintf("lookup: RPC error.\n"); 331*7c478bd9Sstevel@tonic-gate return (NULL); 332*7c478bd9Sstevel@tonic-gate } 333*7c478bd9Sstevel@tonic-gate if (res_lookup.status != NFS_OK) { 334*7c478bd9Sstevel@tonic-gate nfs_error(res_lookup.status); 335*7c478bd9Sstevel@tonic-gate *nstat = (int)res_lookup.status; 336*7c478bd9Sstevel@tonic-gate return (NULL); 337*7c478bd9Sstevel@tonic-gate } 338*7c478bd9Sstevel@tonic-gate 339*7c478bd9Sstevel@tonic-gate bzero((caddr_t)&cd, sizeof (struct nfs_file)); 340*7c478bd9Sstevel@tonic-gate cd.version = NFS_VERSION; 341*7c478bd9Sstevel@tonic-gate cd.ftype.type2 = res_lookup.diropres_u.diropres.attributes.type; 342*7c478bd9Sstevel@tonic-gate bcopy(&res_lookup.diropres_u.diropres.file, &cd.fh.fh2, NFS_FHSIZE); 343*7c478bd9Sstevel@tonic-gate return (&cd); 344*7c478bd9Sstevel@tonic-gate } 345*7c478bd9Sstevel@tonic-gate 346*7c478bd9Sstevel@tonic-gate /* 347*7c478bd9Sstevel@tonic-gate * Gets symbolic link into pathname. 348*7c478bd9Sstevel@tonic-gate */ 349*7c478bd9Sstevel@tonic-gate int 350*7c478bd9Sstevel@tonic-gate nfsgetsymlink(struct nfs_file *cfile, char **path) 351*7c478bd9Sstevel@tonic-gate { 352*7c478bd9Sstevel@tonic-gate enum clnt_stat status; 353*7c478bd9Sstevel@tonic-gate struct readlinkres linkres; 354*7c478bd9Sstevel@tonic-gate static char symlink_path[NFS_MAXPATHLEN]; 355*7c478bd9Sstevel@tonic-gate 356*7c478bd9Sstevel@tonic-gate /* 357*7c478bd9Sstevel@tonic-gate * linkres needs a zeroed buffer to place path data into: 358*7c478bd9Sstevel@tonic-gate */ 359*7c478bd9Sstevel@tonic-gate bzero(symlink_path, NFS_MAXPATHLEN); 360*7c478bd9Sstevel@tonic-gate linkres.readlinkres_u.data = &symlink_path[0]; 361*7c478bd9Sstevel@tonic-gate 362*7c478bd9Sstevel@tonic-gate status = CLNT_CALL(root_CLIENT, NFSPROC_READLINK, 363*7c478bd9Sstevel@tonic-gate xdr_nfs_fh, (caddr_t)&cfile->fh.fh2, 364*7c478bd9Sstevel@tonic-gate xdr_readlinkres, (caddr_t)&linkres, zero_timeout); 365*7c478bd9Sstevel@tonic-gate if (status != RPC_SUCCESS) { 366*7c478bd9Sstevel@tonic-gate dprintf("nfsgetsymlink: RPC call failed.\n"); 367*7c478bd9Sstevel@tonic-gate return (-1); 368*7c478bd9Sstevel@tonic-gate } 369*7c478bd9Sstevel@tonic-gate if (linkres.status != NFS_OK) { 370*7c478bd9Sstevel@tonic-gate nfs_error(linkres.status); 371*7c478bd9Sstevel@tonic-gate return (linkres.status); 372*7c478bd9Sstevel@tonic-gate } 373*7c478bd9Sstevel@tonic-gate 374*7c478bd9Sstevel@tonic-gate *path = linkres.readlinkres_u.data; 375*7c478bd9Sstevel@tonic-gate 376*7c478bd9Sstevel@tonic-gate return (NFS_OK); 377*7c478bd9Sstevel@tonic-gate } 378