+/* ------------------- */
+#ifdef ATACC
+int path_isadir(struct path *o_path)
+{
+ 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
+
+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 == curdir->d_child->d_prev) ? NULL : dir->d_next;
+ }
+ return dir;
+}
+
+/* -----------------------------------------
+ * if did is not in the cache resolve it with cnid
+ *
+ */
+struct dir *
+ dirlookup( vol, did )
+ const struct vol *vol;
+u_int32_t did;
+{
+#ifdef CNID_DB
+ struct dir *ret;
+ char *upath;
+ u_int32_t id;
+ static char path[MAXPATHLEN + 1];
+ int len;
+ int pathlen;
+ char *ptr;
+ static char buffer[12 + MAXPATHLEN + 1];
+ int buflen = 12 + MAXPATHLEN + 1;
+ char *mpath;
+
+ ret = dirsearch(vol, did);
+ if (ret != NULL || afp_errno == AFPERR_PARAM)
+ return ret;
+
+ id = did;
+ if (NULL == (upath = cnid_resolve(vol->v_db, &id, buffer, buflen)) ) {
+ afp_errno = AFPERR_NOOBJ;
+ return NULL;
+ }
+ ptr = path + MAXPATHLEN;
+ if (NULL == ( mpath = utompath(vol, upath, utf8_encoding()) ) ) {
+ 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;
+ }
+ if ( NULL == (upath = cnid_resolve(vol->v_db, &id, buffer, buflen))
+ ||
+ NULL == (mpath = utompath(vol, upath, utf8_encoding()))
+ ) {
+ afp_errno = AFPERR_NOOBJ;
+ return NULL;
+ }
+
+ len = strlen(mpath) + 1;
+ pathlen += len;
+ if (pathlen > 255) {
+ afp_errno = AFPERR_PARAM;
+ return NULL;
+ }
+ strcpy(ptr - len, mpath);
+ ptr -= len;
+ }
+ /* fill the cache */
+ ptr--;
+ *ptr = (unsigned char)pathlen;
+ ptr--;
+ *ptr = 2;
+ /* cname is not efficient */
+ if (cname( vol, ret, &ptr ) == NULL )
+ return NULL;
+#endif
+ return dirsearch(vol, did);
+}