summaryrefslogtreecommitdiffstats
path: root/sys
diff options
context:
space:
mode:
authorphk <phk@FreeBSD.org>2005-09-12 08:46:07 +0000
committerphk <phk@FreeBSD.org>2005-09-12 08:46:07 +0000
commit4e50b9ebd8baff78363d11817588ca53e4dbf062 (patch)
tree7f8b642fd395417090848de585ef5194b216f583 /sys
parentaca041ee53b3ba5759615a7b2b2aee93f1ed8cc2 (diff)
downloadFreeBSD-src-4e50b9ebd8baff78363d11817588ca53e4dbf062.zip
FreeBSD-src-4e50b9ebd8baff78363d11817588ca53e4dbf062.tar.gz
Introduce vfs_read_dirent() which can help VOP_READDIR() implementations
by handling all the cookie stuff.
Diffstat (limited to 'sys')
-rw-r--r--sys/kern/vfs_subr.c27
-rw-r--r--sys/sys/vnode.h2
2 files changed, 29 insertions, 0 deletions
diff --git a/sys/kern/vfs_subr.c b/sys/kern/vfs_subr.c
index 19dc538..461ed1a 100644
--- a/sys/kern/vfs_subr.c
+++ b/sys/kern/vfs_subr.c
@@ -49,6 +49,7 @@ __FBSDID("$FreeBSD$");
#include <sys/bio.h>
#include <sys/buf.h>
#include <sys/conf.h>
+#include <sys/dirent.h>
#include <sys/event.h>
#include <sys/eventhandler.h>
#include <sys/extattr.h>
@@ -3838,3 +3839,29 @@ filt_vfsvnode(struct knote *kn, long hint)
}
return (kn->kn_fflags != 0);
}
+
+int
+vfs_read_dirent(struct vop_readdir_args *ap, struct dirent *dp, off_t off)
+{
+ int error;
+
+ if (dp->d_reclen > ap->a_uio->uio_resid)
+ return (ENAMETOOLONG);
+ error = uiomove(dp, dp->d_reclen, ap->a_uio);
+ if (error) {
+ if (ap->a_ncookies != NULL) {
+ if (ap->a_cookies != NULL)
+ free(ap->a_cookies, M_TEMP);
+ ap->a_cookies = NULL;
+ *ap->a_ncookies = 0;
+ }
+ return (error);
+ }
+ if (ap->a_ncookies == NULL)
+ return (0);
+ *ap->a_cookies = realloc(*ap->a_cookies,
+ (*ap->a_ncookies + 1) * sizeof(u_long), M_TEMP, M_WAITOK | M_ZERO);
+ (*ap->a_cookies)[*ap->a_ncookies] = off;
+ return (0);
+}
+
diff --git a/sys/sys/vnode.h b/sys/sys/vnode.h
index 98b2348..52a1d2f 100644
--- a/sys/sys/vnode.h
+++ b/sys/sys/vnode.h
@@ -727,6 +727,8 @@ void vfs_hash_rehash(struct vnode *vp, u_int hash);
void vfs_hash_remove(struct vnode *vp);
int vfs_kqfilter(struct vop_kqfilter_args *);
+struct dirent;
+int vfs_read_dirent(struct vop_readdir_args *ap, struct dirent *dp, off_t off);
#endif /* _KERNEL */
OpenPOWER on IntegriCloud