+/* ------------------- */
+#ifdef ATACC
+int path_isadir(struct path *o_path)
+{
+ return o_path->d_dir != NULL;
+#if 0
+ return o_path->m_name == '\0' || /* we are in a it */
+ !o_path->st_valid || /* in cache but we can't chdir in it */
+ (!o_path->st_errno && S_ISDIR(o_path->st.st_mode)); /* not in cache an can't chdir */
+#endif
+}
+#endif
+
+int get_afp_errno(const int param)
+{
+ if (afp_errno != AFPERR_DID1)
+ return afp_errno;
+ return param;
+}
+
+/* ------------------- */
+struct dir *
+ dirsearch_byname( cdir, name )
+ struct dir *cdir;
+ const char *name;
+{
+struct dir *dir;
+
+ if (!strcmp(name, "."))
+ return cdir;
+ dir = cdir->d_child;
+ while (dir) {
+ if ( strcmp( dir->d_u_name, name ) == 0 ) {
+ break;
+ }
+ dir = (dir == cdir->d_child->d_prev) ? NULL : dir->d_next;
+ }
+ return dir;
+}
+
+/* -----------------------------------------
+ * if did is not in the cache resolve it with cnid
+ *
+ * FIXME
+ * OSX call it with bogus id, ie file ID not folder ID,
+ * and we are really bad in this case.
+ */
+struct dir *
+ dirlookup( vol, did )
+ const struct vol *vol;
+u_int32_t did;
+{
+ struct dir *ret;
+ char *upath;
+ cnid_t id, cnid;
+ static char path[MAXPATHLEN + 1];
+ size_t len, pathlen;
+ char *ptr;
+ static char buffer[12 + MAXPATHLEN + 1];
+ int buflen = 12 + MAXPATHLEN + 1;
+ char *mpath;
+ int utf8;
+ size_t maxpath;
+
+ ret = dirsearch(vol, did);
+ if (ret != NULL || afp_errno == AFPERR_PARAM)
+ return ret;
+
+ utf8 = utf8_encoding();
+ maxpath = (utf8)?MAXPATHLEN -7:255;
+ id = did;
+ if (NULL == (upath = cnid_resolve(vol->v_cdb, &id, buffer, buflen)) ) {
+ afp_errno = AFPERR_NOOBJ;
+ return NULL;
+ }
+ ptr = path + MAXPATHLEN;
+ if (NULL == ( mpath = utompath(vol, upath, did, utf8) ) ) {
+ afp_errno = AFPERR_NOOBJ;
+ return NULL;
+ }
+ len = strlen(mpath);
+ pathlen = len; /* no 0 in the last part */
+ len++;
+ strcpy(ptr - len, mpath);
+ ptr -= len;
+ while (1) {
+ ret = dirsearch(vol,id);
+ if (ret != NULL) {
+ break;
+ }
+ cnid = id;
+ if ( NULL == (upath = cnid_resolve(vol->v_cdb, &id, buffer, buflen))
+ ||
+ NULL == (mpath = utompath(vol, upath, cnid, utf8))
+ ) {
+ afp_errno = AFPERR_NOOBJ;
+ return NULL;
+ }
+
+ len = strlen(mpath) + 1;
+ pathlen += len;
+ if (pathlen > maxpath) {
+ afp_errno = AFPERR_PARAM;
+ return NULL;
+ }
+ strcpy(ptr - len, mpath);
+ ptr -= len;
+ }
+
+ /* fill the cache, another place where we know about the path type */
+ if (utf8) {
+ u_int16_t temp16;
+ u_int32_t temp;
+
+ ptr -= 2;
+ temp16 = htons(pathlen);
+ memcpy(ptr, &temp16, sizeof(temp16));
+
+ temp = htonl(kTextEncodingUTF8);
+ ptr -= 4;
+ memcpy(ptr, &temp, sizeof(temp));
+ ptr--;
+ *ptr = 3;
+ }
+ else {
+ ptr--;
+ *ptr = (unsigned char)pathlen;
+ ptr--;
+ *ptr = 2;
+ }
+ /* cname is not efficient */
+ if (cname( vol, ret, &ptr ) == NULL )
+ return NULL;
+
+ return dirsearch(vol, did);
+}