2 * Copyright (c) 1997-2014 Erez Zadok
3 * Copyright (c) 1990 Jan-Simon Pendry
4 * Copyright (c) 1990 Imperial College of Science, Technology & Medicine
5 * Copyright (c) 1990 The Regents of the University of California.
8 * This code is derived from software contributed to Berkeley by
9 * Jan-Simon Pendry at Imperial College, London.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * File: am-utils/amd/readdir.c
44 #endif /* HAVE_CONFIG_H */
49 /****************************************************************************
51 ****************************************************************************/
52 #define DOT_DOT_COOKIE (u_int) 1
53 #define MAX_CHAIN 2048
56 /****************************************************************************
57 *** FORWARD DEFINITIONS ***
58 ****************************************************************************/
59 static int key_already_in_chain(char *keyname, const nfsentry *chain);
60 static nfsentry *make_entry_chain(am_node *mp, const nfsentry *current_chain, int fully_browsable);
61 static int amfs_readdir_browsable(am_node *mp, nfscookie cookie, nfsdirlist *dp, nfsentry *ep, u_int count, int fully_browsable);
63 static const u_int dotdotcookie = DOT_DOT_COOKIE;
65 /****************************************************************************
67 ****************************************************************************/
69 * Was: NEW_TOPLVL_READDIR
70 * Search a chain for an entry with some name.
71 * -Erez Zadok <ezk@cs.columbia.edu>
74 key_already_in_chain(char *keyname, const nfsentry *chain)
76 const nfsentry *tmpchain = chain;
79 if (keyname && tmpchain->ne_name && STREQ(keyname, tmpchain->ne_name))
81 tmpchain = tmpchain->ne_nextentry;
89 * Create a chain of entries which are not linked.
90 * -Erez Zadok <ezk@cs.columbia.edu>
93 make_entry_chain(am_node *mp, const nfsentry *current_chain, int fully_browsable)
95 static u_int last_cookie = (u_int) 2; /* monotonically increasing */
96 static nfsentry chain[MAX_CHAIN];
97 static int max_entries = MAX_CHAIN;
99 int num_entries = 0, i;
101 nfsentry *retval = (nfsentry *) NULL;
106 plog(XLOG_DEBUG, "make_entry_chain: mp is (NULL)");
109 mf = mp->am_al->al_mnt;
111 plog(XLOG_DEBUG, "make_entry_chain: mp->am_al->al_mnt is (NULL)");
114 mmp = (mnt_map *) mf->mf_private;
116 plog(XLOG_DEBUG, "make_entry_chain: mp->am_al->al_mnt->mf_private is (NULL)");
121 preflen = strlen(mp->am_pref);
123 /* iterate over keys */
124 for (i = 0; i < NKVHASH; i++) {
126 for (k = mmp->kvhash[i]; k ; k = k->next) {
129 * Skip unwanted entries which are either not real entries or
130 * very difficult to interpret (wildcards...) This test needs
131 * lots of improvement. Any takers?
137 /* Skip '/defaults' */
138 if (STREQ(key, "/defaults"))
142 if (!fully_browsable && strchr(key, '*'))
146 * If the map has a prefix-string then check if the key starts with
147 * this string, and if it does, skip over this prefix. If it has a
148 * prefix and it doesn't match the start of the key, skip it.
151 if (preflen > strlen(key))
153 if (!NSTREQ(key, mp->am_pref, preflen))
158 /* no more '/' are allowed, unless browsable_dirs=full was used */
159 if (!fully_browsable && strchr(key, '/'))
162 /* no duplicates allowed */
163 if (key_already_in_chain(key, current_chain))
166 /* fill in a cell and link the entry */
167 if (num_entries >= max_entries) {
169 plog(XLOG_DEBUG, "make_entry_chain: no more space in chain");
170 if (num_entries > 0) {
171 chain[num_entries - 1].ne_nextentry = NULL;
177 /* we have space. put entry in next cell */
179 chain[num_entries].ne_fileid = last_cookie;
180 (void)memcpy(chain[num_entries].ne_cookie, &last_cookie,
181 sizeof(last_cookie));
182 chain[num_entries].ne_name = key;
183 if (num_entries < max_entries - 1) { /* link to next one */
184 chain[num_entries].ne_nextentry = &chain[num_entries + 1];
187 } /* end of "while (k)" */
188 } /* end of "for (i ... NKVHASH ..." */
190 /* terminate chain */
191 if (num_entries > 0) {
192 chain[num_entries - 1].ne_nextentry = NULL;
201 /* This one is called only if map is browsable */
203 amfs_readdir_browsable(am_node *mp, nfscookie cookie, nfsdirlist *dp, nfsentry *ep, u_int count, int fully_browsable)
205 u_int gen = *(u_int *) (uintptr_t) cookie;
207 static nfsentry *te, *te_next;
210 dp->dl_eof = FALSE; /* assume readdir not done */
212 if (amuDebug(D_READDIR))
213 plog(XLOG_DEBUG, "amfs_readdir_browsable gen=%u, count=%d",
218 * In the default instance (which is used to start a search) we return
221 * This assumes that the count is big enough to allow both "." and ".."
222 * to be returned in a single packet. If it isn't (which would be
223 * fairly unbelievable) then tough.
225 dlog("%s: default search", __func__);
227 * Check for enough room. This is extremely approximate but is more
228 * than enough space. Really need 2 times:
233 * plus the dirlist structure */
234 if (count < (2 * (2 * (sizeof(*ep) + sizeof("..") + 4) + sizeof(*dp))))
238 * compute # of entries to send in this chain.
239 * heuristics: 128 bytes per entry.
240 * This is too much probably, but it seems to work better because
241 * of the re-entrant nature of nfs_readdir, and esp. on systems
244 chain_length = count / 128;
246 /* reset static state counters */
252 ep[0].ne_fileid = mp->am_gen;
254 ep[0].ne_nextentry = &ep[1];
255 (void)memset(ep[0].ne_cookie, 0, sizeof(u_int));
259 ep[1].ne_fileid = mp->am_parent->am_gen;
261 ep[1].ne_fileid = mp->am_gen;
263 ep[1].ne_name = "..";
264 ep[1].ne_nextentry = NULL;
265 (void)memcpy(ep[1].ne_cookie, &dotdotcookie, sizeof(dotdotcookie));
268 * If map is browsable, call a function make_entry_chain() to construct
269 * a linked list of unmounted keys, and return it. Then link the chain
270 * to the regular list. Get the chain only once, but return
271 * chunks of it each time.
273 te = make_entry_chain(mp, dp->dl_entries, fully_browsable);
276 if (amuDebug(D_READDIR)) {
278 for (j = 0, ne = te; ne; ne = ne->ne_nextentry)
279 plog(XLOG_DEBUG, "gen1 key %4d \"%s\"", j++, ne->ne_name);
282 /* return only "chain_length" entries */
284 for (i=1; i<chain_length; ++i) {
285 te_next = te_next->ne_nextentry;
290 nfsentry *te_saved = te_next->ne_nextentry;
291 te_next->ne_nextentry = NULL; /* terminate "te" chain */
292 te_next = te_saved; /* save rest of "te" for next iteration */
293 dp->dl_eof = FALSE; /* tell readdir there's more */
295 dp->dl_eof = TRUE; /* tell readdir that's it */
297 ep[1].ne_nextentry = te; /* append this chunk of "te" chain */
298 if (amuDebug(D_READDIR)) {
300 for (j = 0, ne = te; ne; ne = ne->ne_nextentry)
301 plog(XLOG_DEBUG, "gen2 key %4d \"%s\"", j++, ne->ne_name);
302 for (j = 0, ne = ep; ne; ne = ne->ne_nextentry) {
304 (void)memcpy(&cookie, ne->ne_cookie, sizeof(cookie));
305 plog(XLOG_DEBUG, "gen2+ key %4d \"%s\" fi=%d ck=%d",
306 j++, ne->ne_name, ne->ne_fileid, cookie);
308 plog(XLOG_DEBUG, "EOF is %d", dp->dl_eof);
311 } /* end of "if (gen == 0)" statement */
313 dlog("%s: real child", __func__);
315 if (gen == DOT_DOT_COOKIE) {
316 dlog("%s: End of readdir in %s", __func__, mp->am_path);
318 dp->dl_entries = NULL;
323 * If browsable directories, then continue serving readdir() with another
324 * chunk of entries, starting from where we left off (when gen was equal
325 * to 0). Once again, assume last chunk served to readdir.
330 te = te_next; /* reset 'te' from last saved te_next */
331 if (!te) { /* another indicator of end of readdir */
332 dp->dl_entries = NULL;
336 * compute # of entries to send in this chain.
337 * heuristics: 128 bytes per entry.
339 chain_length = count / 128;
341 /* return only "chain_length" entries */
342 for (i = 1; i < chain_length; ++i) {
343 te_next = te_next->ne_nextentry;
348 nfsentry *te_saved = te_next->ne_nextentry;
349 te_next->ne_nextentry = NULL; /* terminate "te" chain */
350 te_next = te_saved; /* save rest of "te" for next iteration */
351 dp->dl_eof = FALSE; /* tell readdir there's more */
353 ep = te; /* send next chunk of "te" chain */
355 if (amuDebug(D_READDIR)) {
357 plog(XLOG_DEBUG, "dl_entries=%p, te_next=%p, dl_eof=%d",
358 dp->dl_entries, te_next, dp->dl_eof);
359 for (ne = te; ne; ne = ne->ne_nextentry)
360 plog(XLOG_DEBUG, "gen3 key %4d \"%s\"", j++, ne->ne_name);
366 amfs_readdir(am_node *mp, nfscookie cookie, nfsdirlist *dp, nfsentry *ep, u_int count)
368 u_int gen = *(u_int *) (uintptr_t) cookie;
371 dp->dl_eof = FALSE; /* assume readdir not done */
373 /* when gen is 0, we start reading from the beginning of the directory */
376 * In the default instance (which is used to start a search) we return
379 * This assumes that the count is big enough to allow both "." and ".."
380 * to be returned in a single packet. If it isn't (which would be
381 * fairly unbelievable) then tough.
383 dlog("%s: default search", __func__);
385 * Check for enough room. This is extremely approximate but is more
386 * than enough space. Really need 2 times:
391 * plus the dirlist structure */
392 #define NEEDROOM (2 * (2 * (sizeof(*ep) + sizeof("..") + 4) + sizeof(*dp)))
393 if (count < NEEDROOM) {
394 dlog("%s: not enough room %u < %zu", __func__, count, NEEDROOM);
398 xp = next_nonerror_node(mp->am_child);
402 ep[0].ne_fileid = mp->am_gen;
404 ep[0].ne_nextentry = &ep[1];
405 (void)memset(ep[0].ne_cookie, 0, sizeof(u_int));
409 ep[1].ne_fileid = mp->am_parent->am_gen;
411 ep[1].ne_fileid = mp->am_gen;
412 ep[1].ne_name = "..";
413 ep[1].ne_nextentry = NULL;
414 (void)memcpy(ep[1].ne_cookie, (xp ? &xp->am_gen : &dotdotcookie),
415 sizeof(dotdotcookie));
418 dp->dl_eof = TRUE; /* by default assume readdir done */
420 if (amuDebug(D_READDIR)) {
423 for (j = 0, ne = ep; ne; ne = ne->ne_nextentry) {
425 (void)memcpy(&cookie, ne->ne_cookie, sizeof(cookie));
426 plog(XLOG_DEBUG, "gen1 key %4d \"%s\" fi=%d ck=%d",
427 j++, ne->ne_name, ne->ne_fileid, cookie);
432 dlog("%s: real child", __func__);
434 if (gen == DOT_DOT_COOKIE) {
435 dlog("%s: End of readdir in %s", __func__, mp->am_path);
437 dp->dl_entries = NULL;
438 if (amuDebug(D_READDIR))
439 plog(XLOG_DEBUG, "end of readdir eof=TRUE, dl_entries=0\n");
443 /* non-browsable directories code */
445 while (xp && xp->am_gen != gen)
449 int nbytes = count / 2; /* conservative */
450 int todo = MAX_READDIR_ENTRIES;
454 am_node *xp_next = next_nonerror_node(xp->am_osib);
457 (void)memcpy(ep->ne_cookie, &xp_next->am_gen, sizeof(xp_next->am_gen));
459 (void)memcpy(ep->ne_cookie, &dotdotcookie, sizeof(dotdotcookie));
463 ep->ne_fileid = xp->am_gen;
464 ep->ne_name = xp->am_name;
465 nbytes -= sizeof(*ep) + 1;
467 nbytes -= strlen(xp->am_name);
471 if (nbytes > 0 && !dp->dl_eof && todo > 1) {
472 ep->ne_nextentry = ep + 1;
480 ep->ne_nextentry = NULL;
482 if (amuDebug(D_READDIR)) {
485 for (j=0,ne=ep; ne; ne=ne->ne_nextentry) {
487 (void)memcpy(&cookie, ne->ne_cookie, sizeof(cookie));
488 plog(XLOG_DEBUG, "gen2 key %4d \"%s\" fi=%d ck=%d",
489 j++, ne->ne_name, ne->ne_fileid, cookie);
498 * Search a chain for an entry with some name.
501 key_already_in_chain3(char *keyname, const am_entry3 *chain)
503 const am_entry3 *tmpchain = chain;
506 if (keyname && tmpchain->name && STREQ(keyname, tmpchain->name))
508 tmpchain = tmpchain->nextentry;
515 * Create a chain of entries which are not linked.
518 make_entry_chain3(am_node *mp, const am_entry3 *current_chain, int fully_browsable)
520 static uint64 last_cookie = (uint64) 2; /* monotonically increasing */
521 static am_entry3 chain[MAX_CHAIN];
522 static int max_entries = MAX_CHAIN;
524 int num_entries = 0, i;
526 am_entry3 *retval = (am_entry3 *) NULL;
531 plog(XLOG_DEBUG, "make_entry_chain3: mp is (NULL)");
534 mf = mp->am_al->al_mnt;
536 plog(XLOG_DEBUG, "make_entry_chain3: mp->am_al->al_mnt is (NULL)");
539 mmp = (mnt_map *) mf->mf_private;
541 plog(XLOG_DEBUG, "make_entry_chain3: mp->am_al->al_mnt->mf_private is (NULL)");
546 preflen = strlen(mp->am_pref);
548 /* iterate over keys */
549 for (i = 0; i < NKVHASH; i++) {
551 for (k = mmp->kvhash[i]; k ; k = k->next) {
554 * Skip unwanted entries which are either not real entries or
555 * very difficult to interpret (wildcards...) This test needs
556 * lots of improvement. Any takers?
562 /* Skip '/defaults' */
563 if (STREQ(key, "/defaults"))
567 if (!fully_browsable && strchr(key, '*'))
571 * If the map has a prefix-string then check if the key starts with
572 * this string, and if it does, skip over this prefix. If it has a
573 * prefix and it doesn't match the start of the key, skip it.
576 if (preflen > strlen(key))
578 if (!NSTREQ(key, mp->am_pref, preflen))
583 /* no more '/' are allowed, unless browsable_dirs=full was used */
584 if (!fully_browsable && strchr(key, '/'))
587 /* no duplicates allowed */
588 if (key_already_in_chain3(key, current_chain))
591 /* fill in a cell and link the entry */
592 if (num_entries >= max_entries) {
594 plog(XLOG_DEBUG, "make_entry_chain3: no more space in chain");
595 if (num_entries > 0) {
596 chain[num_entries - 1].nextentry = NULL;
602 /* we have space. put entry in next cell */
604 chain[num_entries].fileid = last_cookie;
605 chain[num_entries].cookie = last_cookie;
606 chain[num_entries].name = key;
607 if (num_entries < max_entries - 1) { /* link to next one */
608 chain[num_entries].nextentry = &chain[num_entries + 1];
611 } /* end of "while (k)" */
612 } /* end of "for (i ... NKVHASH ..." */
614 /* terminate chain */
615 if (num_entries > 0) {
616 chain[num_entries - 1].nextentry = NULL;
623 static size_t needroom3(void)
626 * Check for enough room. This is extremely approximate but should
627 * be enough space. Really need 2 times:
631 * 8byte next entry addres) = sizeof(am_entry3)
632 * 2byte name + 1byte terminator
633 * plus the size of the am_dirlist3 structure */
634 return ((2 * ((sizeof(am_entry3) + sizeof("..") + 1))) + sizeof(am_dirlist3));
637 /* This one is called only if map is browsable */
639 amfs_readdir3_browsable(am_node *mp, am_cookie3 cookie,
640 am_dirlist3 *dp, am_entry3 *ep, u_int count,
643 uint64 gen = *(uint64 *) (uintptr_t) cookie;
645 static am_entry3 *te, *te_next;
648 dp->eof = FALSE; /* assume readdir not done */
650 if (amuDebug(D_READDIR))
651 plog(XLOG_DEBUG, "amfs_readdir3_browsable gen=%lu, count=%d", (long unsigned) gen, count);
654 size_t needed = needroom3();
656 * In the default instance (which is used to start a search) we return
659 * This assumes that the count is big enough to allow both "." and ".."
660 * to be returned in a single packet. If it isn't (which would be
661 * fairly unbelievable) then tough.
663 dlog("%s: default search", __func__);
665 if (count < needed) {
666 dlog("%s: not enough room %u < %zu", __func__, count, needed);
671 * compute # of entries to send in this chain.
672 * heuristics: 128 bytes per entry.
673 * This is too much probably, but it seems to work better because
674 * of the re-entrant nature of nfs_readdir, and esp. on systems
677 chain_length = count / 128;
679 /* reset static state counters */
685 ep[0].fileid = mp->am_gen;
687 ep[0].nextentry = &ep[1];
692 ep[1].fileid = mp->am_parent->am_gen;
694 ep[1].fileid = mp->am_gen;
697 ep[1].nextentry = NULL;
698 ep[1].cookie = dotdotcookie;
701 * If map is browsable, call a function make_entry_chain() to construct
702 * a linked list of unmounted keys, and return it. Then link the chain
703 * to the regular list. Get the chain only once, but return
704 * chunks of it each time.
706 te = make_entry_chain3(mp, dp->entries, fully_browsable);
709 if (amuDebug(D_READDIR)) {
711 for (j = 0, ne = te; ne; ne = ne->ne_nextentry)
712 plog(XLOG_DEBUG, "gen1 key %4d \"%s\"", j++, ne->ne_name);
715 /* return only "chain_length" entries */
717 for (i=1; i<chain_length; ++i) {
718 te_next = te_next->nextentry;
723 am_entry3 *te_saved = te_next->nextentry;
724 te_next->nextentry = NULL; /* terminate "te" chain */
725 te_next = te_saved; /* save rest of "te" for next iteration */
726 dp->eof = FALSE; /* tell readdir there's more */
728 dp->eof = TRUE; /* tell readdir that's it */
730 ep[1].nextentry = te; /* append this chunk of "te" chain */
731 if (amuDebug(D_READDIR)) {
733 for (j = 0, ne = te; ne; ne = ne->ne_nextentry)
734 plog(XLOG_DEBUG, "gen2 key %4d \"%s\"", j++, ne->name);
735 for (j = 0, ne = ep; ne; ne = ne->ne_nextentry) {
736 plog(XLOG_DEBUG, "gen2+ key %4d \"%s\" fi=%lu ck=%lu",
737 j++, ne->name, (long unsigned) ne->fileid, (long unsigned) ne->cookie);
739 plog(XLOG_DEBUG, "EOF is %d", dp->eof);
742 } /* end of "if (gen == 0)" statement */
744 dlog("%s: real child", __func__);
746 if (gen == DOT_DOT_COOKIE) {
747 dlog("%s: End of readdir in %s", __func__, mp->am_path);
754 * If browsable directories, then continue serving readdir() with another
755 * chunk of entries, starting from where we left off (when gen was equal
756 * to 0). Once again, assume last chunk served to readdir.
761 te = te_next; /* reset 'te' from last saved te_next */
762 if (!te) { /* another indicator of end of readdir */
767 * compute # of entries to send in this chain.
768 * heuristics: 128 bytes per entry.
770 chain_length = count / 128;
772 /* return only "chain_length" entries */
773 for (i = 1; i < chain_length; ++i) {
774 te_next = te_next->nextentry;
779 am_entry3 *te_saved = te_next->nextentry;
780 te_next->nextentry = NULL; /* terminate "te" chain */
781 te_next = te_saved; /* save rest of "te" for next iteration */
782 dp->eof = FALSE; /* tell readdir there's more */
784 ep = te; /* send next chunk of "te" chain */
786 if (amuDebug(D_READDIR)) {
789 "entries=%p, te_next=%p, eof=%d", dp->entries, te_next, dp->eof);
790 for (ne = te; ne; ne = ne->nextentry)
791 plog(XLOG_DEBUG, "gen3 key %4d \"%s\"", j++, ne->name);
797 amfs_readdir3(am_node *mp, am_cookie3 cookie,
798 am_dirlist3 *dp, am_entry3 *ep, u_int count)
800 uint64 gen = *(uint64 *) (uintptr_t) cookie;
803 if (amuDebug(D_READDIR))
804 plog(XLOG_DEBUG, "amfs_readdir3 gen=%lu, count=%d", (long unsigned) gen, count);
806 dp->eof = FALSE; /* assume readdir not done */
808 /* when gen is 0, we start reading from the beginning of the directory */
810 size_t needed = needroom3();
812 * In the default instance (which is used to start a search) we return
815 * This assumes that the count is big enough to allow both "." and ".."
816 * to be returned in a single packet. If it isn't (which would be
817 * fairly unbelievable) then tough.
819 dlog("%s: default search", __func__);
821 if (count < needed) {
822 dlog("%s: not enough room %u < %zu", __func__, count, needed);
826 xp = next_nonerror_node(mp->am_child);
830 ep[0].fileid = mp->am_gen;
833 ep[0].nextentry = &ep[1];
837 ep[1].fileid = mp->am_parent->am_gen;
839 ep[1].fileid = mp->am_gen;
841 ep[1].nextentry = NULL;
842 ep[1].cookie = (xp ? xp->am_gen : dotdotcookie);
845 dp->eof = TRUE; /* by default assume readdir done */
847 if (amuDebug(D_READDIR)) {
850 for (j = 0, ne = ep; ne; ne = ne->nextentry) {
851 plog(XLOG_DEBUG, "gen1 key %4d \"%s\" fi=%lu ck=%lu",
852 j++, ne->name, (long unsigned) ne->fileid, (long unsigned) ne->cookie);
857 dlog("%s: real child", __func__);
859 if (gen == (uint64) DOT_DOT_COOKIE) {
860 dlog("%s: End of readdir in %s", __func__, mp->am_path);
863 if (amuDebug(D_READDIR))
864 plog(XLOG_DEBUG, "end of readdir eof=TRUE, dl_entries=0\n");
868 /* non-browsable directories code */
870 while (xp && xp->am_gen != gen)
874 int nbytes = count / 2; /* conservative */
875 int todo = MAX_READDIR_ENTRIES;
879 am_node *xp_next = next_nonerror_node(xp->am_osib);
882 ep->cookie = xp_next->am_gen;
884 ep->cookie = (uint64) dotdotcookie;
888 ep->fileid = xp->am_gen;
889 ep->name = xp->am_name;
890 nbytes -= sizeof(*ep) + 1;
892 nbytes -= strlen(xp->am_name);
896 if (nbytes > 0 && !dp->dl_eof && todo > 1) {
897 ep->nextentry = ep + 1;
905 ep->nextentry = NULL;
907 if (amuDebug(D_READDIR)) {
910 for (j = 0, ne = ep; ne; ne = ne->nextentry) {
911 plog(XLOG_DEBUG, "gen2 key %4d \"%s\" fi=%lu ck=%lu",
912 j++, ne->name, (long unsigned) ne->fileid, (long unsigned) ne->cookie);
921 * This readdir function which call a special version of it that allows
922 * browsing if browsable_dirs=yes was set on the map.
925 amfs_generic_readdir(am_node *mp, voidp cookie, voidp dp, voidp ep, u_int count)
929 /* check if map is browsable */
931 if (mp->am_al->al_mnt && mp->am_al->al_mnt->mf_mopts) {
933 mnt.mnt_opts = mp->am_al->al_mnt->mf_mopts;
934 if (amu_hasmntopt(&mnt, "fullybrowsable"))
936 else if (amu_hasmntopt(&mnt, "browsable"))
939 full = (browsable == 2);
941 if (nfs_dispatcher == nfs_program_2) {
943 return amfs_readdir_browsable(mp, cookie, dp, ep, count, full);
945 return amfs_readdir(mp, cookie, dp, ep, count);
948 return amfs_readdir3_browsable(mp, (am_cookie3) (uintptr_t) cookie, dp, ep, count, full);
950 return amfs_readdir3(mp, (am_cookie3) (uintptr_t) cookie, dp, ep, count);