/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*
* Stuff relating to NFSv3 directory reading ...
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include "clnt.h"
#include "nfs_inet.h"
#include "brpc.h"
#include <rpcsvc/nfs_prot.h>
#include <sys/sysmacros.h>
#include "socket_inet.h"
#include <sys/bootdebug.h>
/*
* Boot needs to be cleaned up to use either dirent32 or dirent64,
* in the meantime use dirent_t and always round to 8 bytes
*/
/*
* Get directory entries:
*
* Uses the nfs "READDIR" operation to read directory entries
* into a local buffer. These are then translated into file
* system independent "dirent" structs and returned in the
* caller's buffer. Returns the number of entries converted
* (-1 if there's an error).
*
* Although the xdr functions can allocate memory, we have
* a limited heap so we allocate our own space,
* assuming the worst case of 256 byte names.
* This is a space hog in our local buffer, so we want
* the number of buffers to be small. To make sure we don't
* get more names than we can handle, we tell the rpc
* routine that we only have space for MAXDENT names if
* they are all the minimum size. This keeps the return
* packet unfragmented, but may result in lots of reads
* to process a large directory. Since this is standalone
* we don't worry about speed. With MAXDENTs at 16, the
* local buffer is 4k.
*/
int
{
int cnt = 0;
struct {
} rdbuf;
int j;
/*
* Keep issuing nfs calls until EOF is reached on
* the directory or the user buffer is filled.
*/
for (j = 0; j < MAXDENTS; j++) {
/*
* Link our buffers together for the benefit of
* XDR. We do this each time we issue the rpc call
* JIC the xdr decode
* routines screw up the linkage!
*/
}
/*
* Cannot give the whole buffer unless every name is
* 256 bytes! Assume the worst case of all 1 byte names.
*/
if (status != RPC_SUCCESS) {
dprintf("nfs3_getdents: RPC error\n");
return (-1);
}
/*
* The most common failure here would be trying to
* issue a getdents call on a non-directory!
*/
return (-1);
}
/*
* Step thru all entries returned by NFS, converting
* to the cannonical form and copying out to the
* user's buffer.
*/
int n;
/*
* catch the case user called at EOF
*/
return (cnt);
n = BDIRENT_RECLEN(n);
if (n > size)
return (cnt);
size -= n;
cnt++;
}
}
return (cnt);
}