+static int enumerate_loop(struct dirent *de, char *mname _U_, void *data)
+{
+ struct savedir *sd = data;
+ char *start, *end;
+ int len,lenm;
+
+ end = sd->sd_buf + sd->sd_buflen;
+ len = strlen(de->d_name);
+ *(sd->sd_last)++ = len;
+ lenm = 0; /* strlen(mname);*/
+ if ( sd->sd_last + len +lenm + 4 > end ) {
+ char *buf;
+
+ start = sd->sd_buf;
+ if (!(buf = realloc( sd->sd_buf, sd->sd_buflen +SDBUFBRK )) ) {
+ LOG(log_error, logtype_afpd, "afp_enumerate: realloc: %s",
+ strerror(errno) );
+ errno = ENOMEM;
+ return -1;
+ }
+ sd->sd_buf = buf;
+ sd->sd_buflen += SDBUFBRK;
+ sd->sd_last = ( sd->sd_last - start ) + sd->sd_buf;
+ end = sd->sd_buf + sd->sd_buflen;
+ }
+
+ memcpy( sd->sd_last, de->d_name, len + 1 );
+ sd->sd_last += len + 1;
+#if 0
+ *(sd->sd_last)++ = lenm;
+ memcpy( sd->sd_last, mname, lenm + 1 );
+ sd->sd_last += lenm + 1;
+#endif
+ return 0;
+}
+
+/* -----------------------------
+ * FIXME:
+ * Doesn't work with dangling symlink
+ * ie:
+ * - Move a folder with a dangling symlink in the trash
+ * - empty the trash
+ * afp_enumerate return an empty listing but offspring count != 0 in afp_getdirparams
+ * and the Mac doesn't try to call afp_delete!
+ *
+ * Another option for symlink
+ * cf:
+ * http://sourceforge.net/tracker/index.php?func=detail&aid=461938&group_id=8642&atid=108642
+ *
+*/
+char *check_dirent(const struct vol *vol, char *name)
+{
+ if (!strcmp(name, "..") || !strcmp(name, "."))
+ return NULL;
+
+ if (!vol->vfs->vfs_validupath(vol, name))
+ return NULL;
+
+ /* check for vetoed filenames */
+ if (veto_file(vol->v_veto, name))
+ return NULL;
+
+#if 0
+ char *m_name = NULL;
+
+ if (NULL == (m_name = utompath(vol, name, 0, utf8_encoding())))
+ return NULL;
+
+ /* now check against too big a file */
+ if (strlen(m_name) > vol->max_filename)
+ return NULL;
+#endif
+ return name;
+}
+
+/* ----------------------------- */
+int
+for_each_dirent(const struct vol *vol, char *name, dir_loop fn, void *data)
+{
+ DIR *dp;
+ struct dirent *de;
+ char *m_name;
+ int ret;
+
+ if (NULL == ( dp = opendir( name)) ) {
+ return -1;
+ }
+ ret = 0;
+ for ( de = readdir( dp ); de != NULL; de = readdir( dp )) {
+ if (!(m_name = check_dirent(vol, de->d_name)))
+ continue;
+
+ ret++;
+ if (fn && fn(de,m_name, data) < 0) {
+ closedir(dp);
+ return -1;
+ }
+ }
+ closedir(dp);
+ return ret;
+}
+
+/* This is the maximal length of a single entry for a file/dir in the reply
+ block if all bits in the file/dir bitmap are set: header(4) + params(104) +
+ macnamelength(1) + macname(31) + utf8(4) + utf8namelen(2) + utf8name(255) +
+ oddpadding(1) */
+
+#define REPLY_PARAM_MAXLEN (4 + 104 + 1 + MACFILELEN + 4 + 2 + 255 + 1)
+
+/* ----------------------------- */
+static int enumerate(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_,
+ char *rbuf,
+ size_t *rbuflen,
+ int ext)