+/* ------------------- */
+#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( const struct vol *vol, struct dir *cdir, char *name)
+{
+struct dir *dir = NULL;
+
+ if ((cdir->d_did != DIRDID_ROOT_PARENT) && (cdir->d_child)) {
+ struct dir key;
+ hnode_t *hn;
+
+ key.d_parent = cdir;
+ key.d_u_name = name;
+ hn = hash_lookup(vol->v_hash, &key);
+ if (hn) {
+ dir = hnode_get(hn);
+ }
+ }
+ 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);
+}
+
+/* child addition/removal */
+static void dirchildadd(const struct vol *vol, struct dir *a, struct dir *b)
+{
+ if (!a->d_child)
+ a->d_child = b;
+ else {
+ b->d_next = a->d_child;
+ b->d_prev = b->d_next->d_prev;
+ b->d_next->d_prev = b;
+ b->d_prev->d_next = b;
+ }
+ if (!hash_alloc_insert(vol->v_hash, b, b)) {
+ LOG(log_error, logtype_afpd, "dirchildadd: can't hash %s", b->d_u_name);
+ }
+}
+
+static void dirchildremove(struct dir *a,struct dir *b)
+{
+ if (a->d_child == b)
+ a->d_child = (b == b->d_next) ? NULL : b->d_next;
+ b->d_next->d_prev = b->d_prev;
+ b->d_prev->d_next = b->d_next;
+ b->d_next = b->d_prev = b;
+}