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 = (u_int) last_cookie;
180 *(u_int *) chain[num_entries].ne_cookie = (u_int) last_cookie;
181 chain[num_entries].ne_name = key;
182 if (num_entries < max_entries - 1) { /* link to next one */
183 chain[num_entries].ne_nextentry = &chain[num_entries + 1];
186 } /* end of "while (k)" */
187 } /* end of "for (i ... NKVHASH ..." */
189 /* terminate chain */
190 if (num_entries > 0) {
191 chain[num_entries - 1].ne_nextentry = NULL;
200 /* This one is called only if map is browsable */
202 amfs_readdir_browsable(am_node *mp, nfscookie cookie, nfsdirlist *dp, nfsentry *ep, u_int count, int fully_browsable)
204 u_int gen = *(u_int *) (uintptr_t) cookie;
206 static nfsentry *te, *te_next;
209 dp->dl_eof = FALSE; /* assume readdir not done */
211 if (amuDebug(D_READDIR))
212 plog(XLOG_DEBUG, "amfs_readdir_browsable gen=%u, count=%d",
217 * In the default instance (which is used to start a search) we return
220 * This assumes that the count is big enough to allow both "." and ".."
221 * to be returned in a single packet. If it isn't (which would be
222 * fairly unbelievable) then tough.
224 dlog("%s: default search", __func__);
226 * Check for enough room. This is extremely approximate but is more
227 * than enough space. Really need 2 times:
232 * plus the dirlist structure */
233 if (count < (2 * (2 * (sizeof(*ep) + sizeof("..") + 4) + sizeof(*dp))))
237 * compute # of entries to send in this chain.
238 * heuristics: 128 bytes per entry.
239 * This is too much probably, but it seems to work better because
240 * of the re-entrant nature of nfs_readdir, and esp. on systems
243 chain_length = count / 128;
245 /* reset static state counters */
251 ep[0].ne_fileid = mp->am_gen;
253 ep[0].ne_nextentry = &ep[1];
254 *(u_int *) ep[0].ne_cookie = 0;
258 ep[1].ne_fileid = mp->am_parent->am_gen;
260 ep[1].ne_fileid = mp->am_gen;
262 ep[1].ne_name = "..";
263 ep[1].ne_nextentry = NULL;
264 (void)memcpy(ep[1].ne_cookie, &dotdotcookie, sizeof(dotdotcookie));
267 * If map is browsable, call a function make_entry_chain() to construct
268 * a linked list of unmounted keys, and return it. Then link the chain
269 * to the regular list. Get the chain only once, but return
270 * chunks of it each time.
272 te = make_entry_chain(mp, dp->dl_entries, fully_browsable);
275 if (amuDebug(D_READDIR)) {
277 for (j = 0, ne = te; ne; ne = ne->ne_nextentry)
278 plog(XLOG_DEBUG, "gen1 key %4d \"%s\"", j++, ne->ne_name);
281 /* return only "chain_length" entries */
283 for (i=1; i<chain_length; ++i) {
284 te_next = te_next->ne_nextentry;
289 nfsentry *te_saved = te_next->ne_nextentry;
290 te_next->ne_nextentry = NULL; /* terminate "te" chain */
291 te_next = te_saved; /* save rest of "te" for next iteration */
292 dp->dl_eof = FALSE; /* tell readdir there's more */
294 dp->dl_eof = TRUE; /* tell readdir that's it */
296 ep[1].ne_nextentry = te; /* append this chunk of "te" chain */
297 if (amuDebug(D_READDIR)) {
299 for (j = 0, ne = te; ne; ne = ne->ne_nextentry)
300 plog(XLOG_DEBUG, "gen2 key %4d \"%s\"", j++, ne->ne_name);
301 for (j = 0, ne = ep; ne; ne = ne->ne_nextentry)
302 plog(XLOG_DEBUG, "gen2+ key %4d \"%s\" fi=%d ck=%d",
303 j++, ne->ne_name, ne->ne_fileid, *(u_int *)ne->ne_cookie);
304 plog(XLOG_DEBUG, "EOF is %d", dp->dl_eof);
307 } /* end of "if (gen == 0)" statement */
309 dlog("%s: real child", __func__);
311 if (gen == DOT_DOT_COOKIE) {
312 dlog("%s: End of readdir in %s", __func__, mp->am_path);
314 dp->dl_entries = NULL;
319 * If browsable directories, then continue serving readdir() with another
320 * chunk of entries, starting from where we left off (when gen was equal
321 * to 0). Once again, assume last chunk served to readdir.
326 te = te_next; /* reset 'te' from last saved te_next */
327 if (!te) { /* another indicator of end of readdir */
328 dp->dl_entries = NULL;
332 * compute # of entries to send in this chain.
333 * heuristics: 128 bytes per entry.
335 chain_length = count / 128;
337 /* return only "chain_length" entries */
338 for (i = 1; i < chain_length; ++i) {
339 te_next = te_next->ne_nextentry;
344 nfsentry *te_saved = te_next->ne_nextentry;
345 te_next->ne_nextentry = NULL; /* terminate "te" chain */
346 te_next = te_saved; /* save rest of "te" for next iteration */
347 dp->dl_eof = FALSE; /* tell readdir there's more */
349 ep = te; /* send next chunk of "te" chain */
351 if (amuDebug(D_READDIR)) {
353 plog(XLOG_DEBUG, "dl_entries=%p, te_next=%p, dl_eof=%d",
354 dp->dl_entries, te_next, dp->dl_eof);
355 for (ne = te; ne; ne = ne->ne_nextentry)
356 plog(XLOG_DEBUG, "gen3 key %4d \"%s\"", j++, ne->ne_name);
362 amfs_readdir(am_node *mp, nfscookie cookie, nfsdirlist *dp, nfsentry *ep, u_int count)
364 u_int gen = *(u_int *) (uintptr_t) cookie;
367 dp->dl_eof = FALSE; /* assume readdir not done */
369 /* when gen is 0, we start reading from the beginning of the directory */
372 * In the default instance (which is used to start a search) we return
375 * This assumes that the count is big enough to allow both "." and ".."
376 * to be returned in a single packet. If it isn't (which would be
377 * fairly unbelievable) then tough.
379 dlog("%s: default search", __func__);
381 * Check for enough room. This is extremely approximate but is more
382 * than enough space. Really need 2 times:
387 * plus the dirlist structure */
388 #define NEEDROOM (2 * (2 * (sizeof(*ep) + sizeof("..") + 4) + sizeof(*dp)))
389 if (count < NEEDROOM) {
390 dlog("%s: not enough room %u < %zu", __func__, count, NEEDROOM);
394 xp = next_nonerror_node(mp->am_child);
398 ep[0].ne_fileid = mp->am_gen;
400 ep[0].ne_nextentry = &ep[1];
401 *(u_int *) ep[0].ne_cookie = 0;
405 ep[1].ne_fileid = mp->am_parent->am_gen;
407 ep[1].ne_fileid = mp->am_gen;
408 ep[1].ne_name = "..";
409 ep[1].ne_nextentry = NULL;
410 (void)memcpy(ep[1].ne_cookie, (xp ? &xp->am_gen : &dotdotcookie),
411 sizeof(dotdotcookie));
414 dp->dl_eof = TRUE; /* by default assume readdir done */
416 if (amuDebug(D_READDIR)) {
419 for (j = 0, ne = ep; ne; ne = ne->ne_nextentry)
420 plog(XLOG_DEBUG, "gen1 key %4d \"%s\" fi=%d ck=%d",
421 j++, ne->ne_name, ne->ne_fileid, *(u_int *)ne->ne_cookie);
425 dlog("%s: real child", __func__);
427 if (gen == DOT_DOT_COOKIE) {
428 dlog("%s: End of readdir in %s", __func__, mp->am_path);
430 dp->dl_entries = NULL;
431 if (amuDebug(D_READDIR))
432 plog(XLOG_DEBUG, "end of readdir eof=TRUE, dl_entries=0\n");
436 /* non-browsable directories code */
438 while (xp && xp->am_gen != gen)
442 int nbytes = count / 2; /* conservative */
443 int todo = MAX_READDIR_ENTRIES;
447 am_node *xp_next = next_nonerror_node(xp->am_osib);
450 *(u_int *) ep->ne_cookie = xp_next->am_gen;
452 *(u_int *) ep->ne_cookie = DOT_DOT_COOKIE;
456 ep->ne_fileid = xp->am_gen;
457 ep->ne_name = xp->am_name;
458 nbytes -= sizeof(*ep) + 1;
460 nbytes -= strlen(xp->am_name);
464 if (nbytes > 0 && !dp->dl_eof && todo > 1) {
465 ep->ne_nextentry = ep + 1;
473 ep->ne_nextentry = NULL;
475 if (amuDebug(D_READDIR)) {
478 for (j=0,ne=ep; ne; ne=ne->ne_nextentry)
479 plog(XLOG_DEBUG, "gen2 key %4d \"%s\" fi=%d ck=%d",
480 j++, ne->ne_name, ne->ne_fileid, *(u_int *)ne->ne_cookie);
488 * Search a chain for an entry with some name.
491 key_already_in_chain3(char *keyname, const am_entry3 *chain)
493 const am_entry3 *tmpchain = chain;
496 if (keyname && tmpchain->name && STREQ(keyname, tmpchain->name))
498 tmpchain = tmpchain->nextentry;
505 * Create a chain of entries which are not linked.
508 make_entry_chain3(am_node *mp, const am_entry3 *current_chain, int fully_browsable)
510 static uint64 last_cookie = (uint64) 2; /* monotonically increasing */
511 static am_entry3 chain[MAX_CHAIN];
512 static int max_entries = MAX_CHAIN;
514 int num_entries = 0, i;
516 am_entry3 *retval = (am_entry3 *) NULL;
521 plog(XLOG_DEBUG, "make_entry_chain3: mp is (NULL)");
524 mf = mp->am_al->al_mnt;
526 plog(XLOG_DEBUG, "make_entry_chain3: mp->am_al->al_mnt is (NULL)");
529 mmp = (mnt_map *) mf->mf_private;
531 plog(XLOG_DEBUG, "make_entry_chain3: mp->am_al->al_mnt->mf_private is (NULL)");
536 preflen = strlen(mp->am_pref);
538 /* iterate over keys */
539 for (i = 0; i < NKVHASH; i++) {
541 for (k = mmp->kvhash[i]; k ; k = k->next) {
544 * Skip unwanted entries which are either not real entries or
545 * very difficult to interpret (wildcards...) This test needs
546 * lots of improvement. Any takers?
552 /* Skip '/defaults' */
553 if (STREQ(key, "/defaults"))
557 if (!fully_browsable && strchr(key, '*'))
561 * If the map has a prefix-string then check if the key starts with
562 * this string, and if it does, skip over this prefix. If it has a
563 * prefix and it doesn't match the start of the key, skip it.
566 if (preflen > strlen(key))
568 if (!NSTREQ(key, mp->am_pref, preflen))
573 /* no more '/' are allowed, unless browsable_dirs=full was used */
574 if (!fully_browsable && strchr(key, '/'))
577 /* no duplicates allowed */
578 if (key_already_in_chain3(key, current_chain))
581 /* fill in a cell and link the entry */
582 if (num_entries >= max_entries) {
584 plog(XLOG_DEBUG, "make_entry_chain3: no more space in chain");
585 if (num_entries > 0) {
586 chain[num_entries - 1].nextentry = NULL;
592 /* we have space. put entry in next cell */
594 chain[num_entries].fileid = last_cookie;
595 chain[num_entries].cookie = last_cookie;
596 chain[num_entries].name = key;
597 if (num_entries < max_entries - 1) { /* link to next one */
598 chain[num_entries].nextentry = &chain[num_entries + 1];
601 } /* end of "while (k)" */
602 } /* end of "for (i ... NKVHASH ..." */
604 /* terminate chain */
605 if (num_entries > 0) {
606 chain[num_entries - 1].nextentry = NULL;
613 static size_t needroom3(void)
616 * Check for enough room. This is extremely approximate but should
617 * be enough space. Really need 2 times:
621 * 8byte next entry addres) = sizeof(am_entry3)
622 * 2byte name + 1byte terminator
623 * plus the size of the am_dirlist3 structure */
624 return ((2 * ((sizeof(am_entry3) + sizeof("..") + 1))) + sizeof(am_dirlist3));
627 /* This one is called only if map is browsable */
629 amfs_readdir3_browsable(am_node *mp, am_cookie3 cookie,
630 am_dirlist3 *dp, am_entry3 *ep, u_int count,
633 uint64 gen = *(uint64 *) (uintptr_t) cookie;
635 static am_entry3 *te, *te_next;
638 dp->eof = FALSE; /* assume readdir not done */
640 if (amuDebug(D_READDIR))
641 plog(XLOG_DEBUG, "amfs_readdir3_browsable gen=%lu, count=%d", (long unsigned) gen, count);
644 size_t needed = needroom3();
646 * In the default instance (which is used to start a search) we return
649 * This assumes that the count is big enough to allow both "." and ".."
650 * to be returned in a single packet. If it isn't (which would be
651 * fairly unbelievable) then tough.
653 dlog("%s: default search", __func__);
655 if (count < needed) {
656 dlog("%s: not enough room %u < %zu", __func__, count, needed);
661 * compute # of entries to send in this chain.
662 * heuristics: 128 bytes per entry.
663 * This is too much probably, but it seems to work better because
664 * of the re-entrant nature of nfs_readdir, and esp. on systems
667 chain_length = count / 128;
669 /* reset static state counters */
675 ep[0].fileid = mp->am_gen;
677 ep[0].nextentry = &ep[1];
682 ep[1].fileid = mp->am_parent->am_gen;
684 ep[1].fileid = mp->am_gen;
687 ep[1].nextentry = NULL;
688 ep[1].cookie = dotdotcookie;
691 * If map is browsable, call a function make_entry_chain() to construct
692 * a linked list of unmounted keys, and return it. Then link the chain
693 * to the regular list. Get the chain only once, but return
694 * chunks of it each time.
696 te = make_entry_chain3(mp, dp->entries, fully_browsable);
699 if (amuDebug(D_READDIR)) {
701 for (j = 0, ne = te; ne; ne = ne->ne_nextentry)
702 plog(XLOG_DEBUG, "gen1 key %4d \"%s\"", j++, ne->ne_name);
705 /* return only "chain_length" entries */
707 for (i=1; i<chain_length; ++i) {
708 te_next = te_next->nextentry;
713 am_entry3 *te_saved = te_next->nextentry;
714 te_next->nextentry = NULL; /* terminate "te" chain */
715 te_next = te_saved; /* save rest of "te" for next iteration */
716 dp->eof = FALSE; /* tell readdir there's more */
718 dp->eof = TRUE; /* tell readdir that's it */
720 ep[1].nextentry = te; /* append this chunk of "te" chain */
721 if (amuDebug(D_READDIR)) {
723 for (j = 0, ne = te; ne; ne = ne->ne_nextentry)
724 plog(XLOG_DEBUG, "gen2 key %4d \"%s\"", j++, ne->name);
725 for (j = 0, ne = ep; ne; ne = ne->ne_nextentry) {
726 plog(XLOG_DEBUG, "gen2+ key %4d \"%s\" fi=%lu ck=%lu",
727 j++, ne->name, (long unsigned) ne->fileid, (long unsigned) ne->cookie);
729 plog(XLOG_DEBUG, "EOF is %d", dp->eof);
732 } /* end of "if (gen == 0)" statement */
734 dlog("%s: real child", __func__);
736 if (gen == DOT_DOT_COOKIE) {
737 dlog("%s: End of readdir in %s", __func__, mp->am_path);
744 * If browsable directories, then continue serving readdir() with another
745 * chunk of entries, starting from where we left off (when gen was equal
746 * to 0). Once again, assume last chunk served to readdir.
751 te = te_next; /* reset 'te' from last saved te_next */
752 if (!te) { /* another indicator of end of readdir */
757 * compute # of entries to send in this chain.
758 * heuristics: 128 bytes per entry.
760 chain_length = count / 128;
762 /* return only "chain_length" entries */
763 for (i = 1; i < chain_length; ++i) {
764 te_next = te_next->nextentry;
769 am_entry3 *te_saved = te_next->nextentry;
770 te_next->nextentry = NULL; /* terminate "te" chain */
771 te_next = te_saved; /* save rest of "te" for next iteration */
772 dp->eof = FALSE; /* tell readdir there's more */
774 ep = te; /* send next chunk of "te" chain */
776 if (amuDebug(D_READDIR)) {
779 "entries=%p, te_next=%p, eof=%d", dp->entries, te_next, dp->eof);
780 for (ne = te; ne; ne = ne->nextentry)
781 plog(XLOG_DEBUG, "gen3 key %4d \"%s\"", j++, ne->name);
787 amfs_readdir3(am_node *mp, am_cookie3 cookie,
788 am_dirlist3 *dp, am_entry3 *ep, u_int count)
790 uint64 gen = *(uint64 *) (uintptr_t) cookie;
793 if (amuDebug(D_READDIR))
794 plog(XLOG_DEBUG, "amfs_readdir3 gen=%lu, count=%d", (long unsigned) gen, count);
796 dp->eof = FALSE; /* assume readdir not done */
798 /* when gen is 0, we start reading from the beginning of the directory */
800 size_t needed = needroom3();
802 * In the default instance (which is used to start a search) we return
805 * This assumes that the count is big enough to allow both "." and ".."
806 * to be returned in a single packet. If it isn't (which would be
807 * fairly unbelievable) then tough.
809 dlog("%s: default search", __func__);
811 if (count < needed) {
812 dlog("%s: not enough room %u < %zu", __func__, count, needed);
816 xp = next_nonerror_node(mp->am_child);
820 ep[0].fileid = mp->am_gen;
823 ep[0].nextentry = &ep[1];
827 ep[1].fileid = mp->am_parent->am_gen;
829 ep[1].fileid = mp->am_gen;
831 ep[1].nextentry = NULL;
832 ep[1].cookie = (xp ? xp->am_gen : dotdotcookie);
835 dp->eof = TRUE; /* by default assume readdir done */
837 if (amuDebug(D_READDIR)) {
840 for (j = 0, ne = ep; ne; ne = ne->nextentry) {
841 plog(XLOG_DEBUG, "gen1 key %4d \"%s\" fi=%lu ck=%lu",
842 j++, ne->name, (long unsigned) ne->fileid, (long unsigned) ne->cookie);
847 dlog("%s: real child", __func__);
849 if (gen == (uint64) DOT_DOT_COOKIE) {
850 dlog("%s: End of readdir in %s", __func__, mp->am_path);
853 if (amuDebug(D_READDIR))
854 plog(XLOG_DEBUG, "end of readdir eof=TRUE, dl_entries=0\n");
858 /* non-browsable directories code */
860 while (xp && xp->am_gen != gen)
864 int nbytes = count / 2; /* conservative */
865 int todo = MAX_READDIR_ENTRIES;
869 am_node *xp_next = next_nonerror_node(xp->am_osib);
872 ep->cookie = xp_next->am_gen;
874 ep->cookie = (uint64) dotdotcookie;
878 ep->fileid = xp->am_gen;
879 ep->name = xp->am_name;
880 nbytes -= sizeof(*ep) + 1;
882 nbytes -= strlen(xp->am_name);
886 if (nbytes > 0 && !dp->dl_eof && todo > 1) {
887 ep->nextentry = ep + 1;
895 ep->nextentry = NULL;
897 if (amuDebug(D_READDIR)) {
900 for (j = 0, ne = ep; ne; ne = ne->nextentry) {
901 plog(XLOG_DEBUG, "gen2 key %4d \"%s\" fi=%lu ck=%lu",
902 j++, ne->name, (long unsigned) ne->fileid, (long unsigned) ne->cookie);
911 * This readdir function which call a special version of it that allows
912 * browsing if browsable_dirs=yes was set on the map.
915 amfs_generic_readdir(am_node *mp, voidp cookie, voidp dp, voidp ep, u_int count)
919 /* check if map is browsable */
921 if (mp->am_al->al_mnt && mp->am_al->al_mnt->mf_mopts) {
923 mnt.mnt_opts = mp->am_al->al_mnt->mf_mopts;
924 if (amu_hasmntopt(&mnt, "fullybrowsable"))
926 else if (amu_hasmntopt(&mnt, "browsable"))
929 full = (browsable == 2);
931 if (nfs_dispatcher == nfs_program_2) {
933 return amfs_readdir_browsable(mp, cookie, dp, ep, count, full);
935 return amfs_readdir(mp, cookie, dp, ep, count);
938 return amfs_readdir3_browsable(mp, (am_cookie3) (uintptr_t) cookie, dp, ep, count, full);
940 return amfs_readdir3(mp, (am_cookie3) (uintptr_t) cookie, dp, ep, count);