MacOSX: - tested with SDK 10.4 (under Snow Leopard) - should also work with later SDKs and 64Bit
iOS: - tested with iOS SDK 4.2 - running on iOS 4.3.x
FreeBSD:- tested with 8.2
+OpenSolaris
Cygwin
;;
*solaris*)
AC_CHECK_HEADERS([sys/filio.h])
+ AC_CHECK_HEADERS([sys/sockio.h])
if test x$ENABLE_EXAMPLES = xyes; then
AC_CHECK_LIB([socket], [main], , [AC_MSG_ERROR([Can not find required library])])
AC_CHECK_LIB([nsl], [main], , [AC_MSG_ERROR([Can not find required library])])
/*
- * Call NFS/REMOVE
+ * Call NFS/READDIR
* Function returns
* 0 : The call was initiated. The callback will be invoked when the call completes.
* <0 : An error occured when trying to set up the call. The callback will not be invoked.
*/
int rpc_nfs_readdir_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, uint64_t cookie, char *cookieverf, int count, void *private_data);
+/*
+ * Call NFS/READDIRPLUS
+ * Function returns
+ * 0 : The call was initiated. The callback will be invoked when the call completes.
+ * <0 : An error occured when trying to set up the call. The callback will not be invoked.
+ *
+ * When the callback is invoked, status indicates the result:
+ * RPC_STATUS_SUCCESS : We got a successful response from the nfs daemon.
+ * data is READDIRPLUS3res *
+ * RPC_STATUS_ERROR : An error occured when trying to contact the nfs daemon.
+ * data is the error string.
+ * RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
+ * data is NULL.
+ */
+int rpc_nfs_readdirplus_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, uint64_t cookie, char *cookieverf, int count, void *private_data);
+
/*
* Call NFS/FSSTAT
* Function returns
struct nfsdirent *next;
char *name;
uint64_t inode;
+
+ /* some extra fields we get for free through the READDIRPLUS3 call. You need libnfs-raw-nfs.h for these */
+ uint32_t type; /* NF3REG, NF3DIR, NF3BLK, ... */
+ uint32_t mode;
+ uint64_t size;
+ struct timeval atime;
+ struct timeval mtime;
+ struct timeval ctime;
};
/*
* nfs_readdir() never blocks, so no special sync/async versions are available
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
+#include <poll.h>
+#include <sys/socket.h>
+#include <net/if.h>
+#include <netdb.h>
+#ifdef HAVE_SYS_SOCKIO_H
+#include <sys/sockio.h>
+#endif
#include "libnfs.h"
#include "libnfs-raw.h"
#include "libnfs-raw-mount.h"
*/
static void nfs_opendir_cb(struct rpc_context *rpc _U_, int status, void *command_data, void *private_data)
{
- READDIR3res *res;
+ READDIRPLUS3res *res;
struct nfs_cb_data *data = private_data;
struct nfs_context *nfs = data->nfs;
struct nfsdir *nfsdir = data->continue_data;
- struct entry3 *entry;
+ struct entryplus3 *entry;
uint64_t cookie;
-
+
if (status == RPC_STATUS_ERROR) {
data->cb(-EFAULT, nfs, command_data, data->private_data);
nfs_free_nfsdir(nfsdir);
return;
}
- entry =res->READDIR3res_u.resok.reply.entries;
+ entry =res->READDIRPLUS3res_u.resok.reply.entries;
while (entry != NULL) {
struct nfsdirent *nfsdirent;
return;
}
nfsdirent->inode = entry->fileid;
+ if (entry->name_attributes.attributes_follow) {
+ nfsdirent->type = entry->name_attributes.post_op_attr_u.attributes.type;
+ nfsdirent->mode = entry->name_attributes.post_op_attr_u.attributes.mode;
+ nfsdirent->size = entry->name_attributes.post_op_attr_u.attributes.size;
+
+ nfsdirent->atime.tv_sec = entry->name_attributes.post_op_attr_u.attributes.atime.seconds;
+ nfsdirent->atime.tv_usec = entry->name_attributes.post_op_attr_u.attributes.atime.nseconds/1000;
+ nfsdirent->mtime.tv_sec = entry->name_attributes.post_op_attr_u.attributes.mtime.seconds;
+ nfsdirent->mtime.tv_usec = entry->name_attributes.post_op_attr_u.attributes.mtime.nseconds/1000;
+ nfsdirent->ctime.tv_sec = entry->name_attributes.post_op_attr_u.attributes.ctime.seconds;
+ nfsdirent->ctime.tv_usec = entry->name_attributes.post_op_attr_u.attributes.ctime.nseconds/1000;
+ }
+
nfsdirent->next = nfsdir->entries;
nfsdir->entries = nfsdirent;
entry = entry->nextentry;
}
- if (res->READDIR3res_u.resok.reply.eof == 0) {
- if (rpc_nfs_readdir_async(nfs->rpc, nfs_opendir_cb, &data->fh, cookie, res->READDIR3res_u.resok.cookieverf, 20000, data) != 0) {
- rpc_set_error(nfs->rpc, "RPC error: Failed to send READDIR call for %s", data->path);
+ if (res->READDIRPLUS3res_u.resok.reply.eof == 0) {
+ if (rpc_nfs_readdirplus_async(nfs->rpc, nfs_opendir_cb, &data->fh, cookie, res->READDIRPLUS3res_u.resok.cookieverf, 8192, data) != 0) {
+ rpc_set_error(nfs->rpc, "RPC error: Failed to send READDIRPLUS call for %s", data->path);
data->cb(-ENOMEM, nfs, rpc_get_error(nfs->rpc), data->private_data);
nfs_free_nfsdir(nfsdir);
data->continue_data = NULL;
cookieverf3 cv;
bzero(cv, sizeof(cookieverf3));
- if (rpc_nfs_readdir_async(nfs->rpc, nfs_opendir_cb, &data->fh, 0, (char *)&cv, 20000, data) != 0) {
- rpc_set_error(nfs->rpc, "RPC error: Failed to send READDIR call for %s", data->path);
+ if (rpc_nfs_readdirplus_async(nfs->rpc, nfs_opendir_cb, &data->fh, 0, (char *)&cv, 8192, data) != 0) {
+ rpc_set_error(nfs->rpc, "RPC error: Failed to send READDIRPLUS call for %s", data->path);
data->cb(-ENOMEM, nfs, rpc_get_error(nfs->rpc), data->private_data);
free_nfs_cb_data(data);
return -1;
if (FD_ISSET(fds->fd, &efds)) {
fds->revents |= POLLHUP;
}
+ return 1;
}
#endif
#ifdef HAVE_SYS_FILIO_H
#include <sys/filio.h>
#endif
+#ifdef HAVE_SYS_SOCKIO_H
+#include <sys/sockio.h>
+#endif
#include <sys/types.h>
#include "libnfs.h"
#include "libnfs-raw.h"
return 0;
}
-
int rpc_nfs_readdir_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, uint64_t cookie, char *cookieverf, int count, void *private_data)
{
struct rpc_pdu *pdu;
return 0;
}
+int rpc_nfs_readdirplus_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, uint64_t cookie, char *cookieverf, int count, void *private_data)
+{
+ struct rpc_pdu *pdu;
+ READDIRPLUS3args args;
+
+ pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V3, NFS3_READDIRPLUS, cb, private_data, (xdrproc_t)xdr_READDIRPLUS3res, sizeof(READDIRPLUS3res));
+ if (pdu == NULL) {
+ rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for nfs/readdirplus call");
+ return -1;
+ }
+
+ bzero(&args, sizeof(READDIRPLUS3args));
+ args.dir.data.data_len = fh->data.data_len;
+ args.dir.data.data_val = fh->data.data_val;
+ args.cookie = cookie;
+ memcpy(&args.cookieverf, cookieverf, sizeof(cookieverf3));
+ args.dircount = count;
+ args.maxcount = count;
+
+ if (xdr_READDIRPLUS3args(&pdu->xdr, &args) == 0) {
+ rpc_set_error(rpc, "XDR error: Failed to encode READDIRPLUS3args");
+ rpc_free_pdu(rpc, pdu);
+ return -2;
+ }
+
+ if (rpc_queue_pdu(rpc, pdu) != 0) {
+ rpc_set_error(rpc, "Out of memory. Failed to queue pdu for nfs/readdirplus call");
+ rpc_free_pdu(rpc, pdu);
+ return -3;
+ }
+
+ return 0;
+}
+
int rpc_nfs_fsstat_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, void *private_data)
{
struct rpc_pdu *pdu;