2 * $Id: directory.c,v 1.63 2003-03-09 19:55:33 didg Exp $
4 * Copyright (c) 1990,1993 Regents of The University of Michigan.
5 * All Rights Reserved. See COPYRIGHT.
7 * 19 jan 2000 implemented red-black trees for directory lookups
13 #endif /* HAVE_CONFIG_H */
15 #include <atalk/logger.h>
16 #include <sys/types.h>
20 #include <sys/param.h>
21 #include <netatalk/endian.h>
22 #include <atalk/adouble.h>
23 #include <atalk/afp.h>
24 #include <atalk/util.h>
26 #include <atalk/cnid.h>
34 #endif /* HAVE_FCNTL_H */
41 #else /* STDC_HEADERS */
45 #endif /* HAVE_STRCHR */
46 char *strchr (), *strrchr ();
48 #define memcpy(d,s,n) bcopy ((s), (d), (n))
49 #define memmove(d,s,n) bcopy ((s), (d), (n))
50 #endif /* ! HAVE_MEMCPY */
51 #endif /* STDC_HEADERS */
53 #include "directory.h"
65 #define SENTINEL (&sentinel)
66 static struct dir sentinel = { SENTINEL, SENTINEL, NULL, DIRTREE_COLOR_BLACK,
67 NULL, NULL, NULL, NULL, NULL, 0, 0,
69 static struct dir rootpar = { SENTINEL, SENTINEL, NULL, 0,
70 NULL, NULL, NULL, NULL, NULL, 0, 0,
73 /* (from IM: Toolbox Essentials)
74 * dirFinderInfo (DInfo) fields:
76 * frRect 8 folder's window rectangle
78 * frLocation 4 folder's location in window
79 * frView 2 folder's view (default == closedView (256))
81 * extended dirFinderInfo (DXInfo) fields:
82 * frScroll 4 scroll position
83 * frOpenChain: 4 directory ID chain of open folders
84 * frScript: 1 script flag and code
85 * frXFlags: 1 reserved
86 * frComment: 2 comment ID
87 * frPutAway: 4 home directory ID
91 * redid did assignment for directories. now we use red-black trees.
96 const struct vol *vol;
102 /* check for 0 did */
104 afp_errno = AFPERR_PARAM;
107 if ( did == DIRDID_ROOT_PARENT ) {
109 rootpar.d_did = DIRDID_ROOT_PARENT;
110 rootpar.d_child = vol->v_dir;
115 afp_errno = AFPERR_NOOBJ;
116 while ( dir != SENTINEL ) {
117 if (dir->d_did == did)
118 return dir->d_m_name ? dir : NULL;
119 dir = (dir->d_did > did) ? dir->d_left : dir->d_right;
124 /* ------------------- */
126 int path_isadir(struct path *o_path)
128 return o_path->m_name == '\0' || /* we are in a it */
129 !o_path->st_valid || /* in cache but we can't chdir in it */
130 (!o_path->st_errno && S_ISDIR(o_path->st.st_mode)); /* not in cache an can't chdir */
134 /* ------------------- */
136 dirsearch_byname( cdir, name )
142 if (!strcmp(name, "."))
146 if ( strcmp( dir->d_u_name, name ) == 0 ) {
149 dir = (dir == curdir->d_child->d_prev) ? NULL : dir->d_next;
154 /* -----------------------------------------
155 * if did is not in the cache resolve it with cnid
159 dirlookup( vol, did )
160 const struct vol *vol;
167 static char path[MAXPATHLEN + 1];
171 static char buffer[12 + MAXPATHLEN + 1];
172 int buflen = 12 + MAXPATHLEN + 1;
175 ret = dirsearch(vol, did);
176 if (ret != NULL || afp_errno == AFPERR_PARAM)
180 if (NULL == (upath = cnid_resolve(vol->v_db, &id, buffer, buflen)) ) {
181 afp_errno = AFPERR_NOOBJ;
184 ptr = path + MAXPATHLEN;
185 if (NULL == ( mpath = utompath(vol, upath, utf8_encoding()) ) ) {
186 afp_errno = AFPERR_NOOBJ;
190 pathlen = len; /* no 0 in the last part */
192 strcpy(ptr - len, mpath);
195 ret = dirsearch(vol,id);
199 if ( NULL == (upath = cnid_resolve(vol->v_db, &id, buffer, buflen))
201 NULL == (mpath = utompath(vol, upath, utf8_encoding()))
203 afp_errno = AFPERR_NOOBJ;
207 len = strlen(mpath) + 1;
210 afp_errno = AFPERR_PARAM;
213 strcpy(ptr - len, mpath);
218 *ptr = (unsigned char)pathlen;
221 /* cname is not efficient */
222 if (cname( vol, ret, &ptr ) == NULL )
225 return dirsearch(vol, did);
228 /* --------------------------- */
229 /* rotate the tree to the left */
230 static void dir_leftrotate(vol, dir)
234 struct dir *right = dir->d_right;
236 /* whee. move the right's left tree into dir's right tree */
237 dir->d_right = right->d_left;
238 if (right->d_left != SENTINEL)
239 right->d_left->d_back = dir;
241 if (right != SENTINEL) {
242 right->d_back = dir->d_back;
246 if (!dir->d_back) /* no parent. move the right tree to the top. */
248 else if (dir == dir->d_back->d_left) /* we were on the left */
249 dir->d_back->d_left = right;
251 dir->d_back->d_right = right; /* we were on the right */
253 /* re-insert dir on the left tree */
260 /* rotate the tree to the right */
261 static void dir_rightrotate(vol, dir)
265 struct dir *left = dir->d_left;
267 /* whee. move the left's right tree into dir's left tree */
268 dir->d_left = left->d_right;
269 if (left->d_right != SENTINEL)
270 left->d_right->d_back = dir;
272 if (left != SENTINEL) {
273 left->d_back = dir->d_back;
277 if (!dir->d_back) /* no parent. move the left tree to the top. */
279 else if (dir == dir->d_back->d_right) /* we were on the right */
280 dir->d_back->d_right = left;
282 dir->d_back->d_left = left; /* we were on the left */
284 /* re-insert dir on the right tree */
290 /* recolor after a removal */
291 static struct dir *dir_rmrecolor(vol, dir)
297 while ((dir != vol->v_root) && (dir->d_color == DIRTREE_COLOR_BLACK)) {
298 /* are we on the left tree? */
299 if (dir == dir->d_back->d_left) {
300 leaf = dir->d_back->d_right; /* get right side */
301 if (leaf->d_color == DIRTREE_COLOR_RED) {
302 /* we're red. we need to change to black. */
303 leaf->d_color = DIRTREE_COLOR_BLACK;
304 dir->d_back->d_color = DIRTREE_COLOR_RED;
305 dir_leftrotate(vol, dir->d_back);
306 leaf = dir->d_back->d_right;
309 /* right leaf has black end nodes */
310 if ((leaf->d_left->d_color == DIRTREE_COLOR_BLACK) &&
311 (leaf->d_right->d_color = DIRTREE_COLOR_BLACK)) {
312 leaf->d_color = DIRTREE_COLOR_RED; /* recolor leaf as red */
313 dir = dir->d_back; /* ascend */
315 if (leaf->d_right->d_color == DIRTREE_COLOR_BLACK) {
316 leaf->d_left->d_color = DIRTREE_COLOR_BLACK;
317 leaf->d_color = DIRTREE_COLOR_RED;
318 dir_rightrotate(vol, leaf);
319 leaf = dir->d_back->d_right;
321 leaf->d_color = dir->d_back->d_color;
322 dir->d_back->d_color = DIRTREE_COLOR_BLACK;
323 leaf->d_right->d_color = DIRTREE_COLOR_BLACK;
324 dir_leftrotate(vol, dir->d_back);
327 } else { /* right tree */
328 leaf = dir->d_back->d_left; /* left tree */
329 if (leaf->d_color == DIRTREE_COLOR_RED) {
330 leaf->d_color = DIRTREE_COLOR_BLACK;
331 dir->d_back->d_color = DIRTREE_COLOR_RED;
332 dir_rightrotate(vol, dir->d_back);
333 leaf = dir->d_back->d_left;
336 /* left leaf has black end nodes */
337 if ((leaf->d_right->d_color == DIRTREE_COLOR_BLACK) &&
338 (leaf->d_left->d_color = DIRTREE_COLOR_BLACK)) {
339 leaf->d_color = DIRTREE_COLOR_RED; /* recolor leaf as red */
340 dir = dir->d_back; /* ascend */
342 if (leaf->d_left->d_color == DIRTREE_COLOR_BLACK) {
343 leaf->d_right->d_color = DIRTREE_COLOR_BLACK;
344 leaf->d_color = DIRTREE_COLOR_RED;
345 dir_leftrotate(vol, leaf);
346 leaf = dir->d_back->d_left;
348 leaf->d_color = dir->d_back->d_color;
349 dir->d_back->d_color = DIRTREE_COLOR_BLACK;
350 leaf->d_left->d_color = DIRTREE_COLOR_BLACK;
351 dir_rightrotate(vol, dir->d_back);
356 dir->d_color = DIRTREE_COLOR_BLACK;
363 /* remove the node from the tree. this is just like insertion, but
364 * different. actually, it has to worry about a bunch of things that
365 * insertion doesn't care about. */
366 static void dir_remove( vol, dir )
371 struct ofork *of, *last;
372 struct dir *node, *leaf;
373 #endif /* REMOVE_NODES */
375 if (!dir || (dir == SENTINEL))
378 /* i'm not sure if it really helps to delete stuff. */
380 if (dir->d_u_name != dir->d_m_name) {
384 dir->d_m_name = NULL;
385 dir->d_u_name = NULL;
386 #else /* ! REMOVE_NODES */
388 /* go searching for a node with at most one child */
389 if ((dir->d_left == SENTINEL) || (dir->d_right == SENTINEL)) {
393 while (node->d_left != SENTINEL)
398 leaf = (node->d_left != SENTINEL) ? node->d_left : node->d_right;
401 leaf->d_back = node->d_back;
404 } else if (node == node->d_back->d_left) { /* left tree */
405 node->d_back->d_left = leaf;
407 node->d_back->d_right = leaf;
410 /* we want to free node, but we also want to free the data in dir.
411 * currently, that's d_name and the directory traversal bits.
412 * we just copy the necessary bits and then fix up all the
413 * various pointers to the directory. needless to say, there are
414 * a bunch of places that store the directory struct. */
416 struct dir save, *tmp;
418 memcpy(&save, dir, sizeof(save));
419 memcpy(dir, node, sizeof(struct dir));
421 /* restore the red-black bits */
422 dir->d_left = save.d_left;
423 dir->d_right = save.d_right;
424 dir->d_back = save.d_back;
425 dir->d_color = save.d_color;
427 if (node == vol->v_dir) {/* we may need to fix up this pointer */
429 rootpar.d_child = vol->v_dir;
431 /* if we aren't the root directory, we have parents and
432 * siblings to worry about */
433 if (dir->d_parent->d_child == node)
434 dir->d_parent->d_child = dir;
435 dir->d_next->d_prev = dir;
436 dir->d_prev->d_next = dir;
439 /* fix up children. */
443 tmp = (tmp == dir->d_child->d_prev) ? NULL : tmp->d_next;
446 if (node == curdir) /* another pointer to fixup */
449 /* we also need to fix up oforks. bleah */
450 if ((of = dir->d_ofork)) {
451 last = of->of_d_prev;
454 of = (last == of) ? NULL : of->of_d_next;
458 /* set the node's d_name */
459 node->d_m_name = save.d_m_name;
460 node->d_u_name = save.d_u_name;
463 if (node->d_color == DIRTREE_COLOR_BLACK)
464 dir_rmrecolor(vol, leaf);
466 if (node->d_u_name != node->d_m_name) {
467 free(node->d_u_name);
469 free(node->d_m_name);
471 #endif /* ! REMOVE_NODES */
474 /* ---------------------------------------
475 * remove the node and its childs from the tree
477 * FIXME what about opened forks with refs to it?
478 * it's an afp specs violation because you can't delete
479 * an opened forks. Now afpd doesn't care about forks opened by other
480 * process. It's fixable within afpd if fnctl_lock, doable with smb and
481 * next to impossible for nfs and local filesystem access.
483 static void dir_invalidate( vol, dir )
484 const struct vol *vol;
488 /* v_root can't be deleted */
489 if (movecwd(vol, vol->v_root) < 0) {
490 LOG(log_error, logtype_afpd, "cname can't chdir to : %s", vol->v_root);
494 dirchildremove(dir->d_parent, dir);
495 dir_remove( vol, dir );
498 /* ------------------------------------ */
499 static struct dir *dir_insert(vol, dir)
500 const struct vol *vol;
506 while (pdir->d_did != dir->d_did ) {
507 if ( pdir->d_did > dir->d_did ) {
508 if ( pdir->d_left == SENTINEL ) {
515 if ( pdir->d_right == SENTINEL ) {
520 pdir = pdir->d_right;
528 * attempt to extend the current dir. tree to include path
529 * as a side-effect, movecwd to that point and return the new dir
532 extenddir( vol, dir, path )
537 path->u_name = mtoupath(vol, path->m_name, utf8_encoding() );
539 if ( path->u_name == NULL) {
540 afp_errno = AFPERR_PARAM;
543 if (of_stat( path ) != 0 ) {
547 if (!S_ISDIR(path->st.st_mode)) {
551 if (( dir = adddir( vol, dir, path)) == NULL ) {
555 if ( movecwd( vol, dir ) < 0 ) {
562 /* -------------------
563 system rmdir with afp error code.
564 ENOENT is not an error.
566 static int netatalk_rmdir(const char *name)
568 if (rmdir(name) < 0) {
573 return AFPERR_DIRNEMPT;
576 return AFPERR_ACCESS;
586 /* -------------------------
587 appledouble mkdir afp error code.
589 static int netatalk_mkdir(const char *name)
591 if (ad_mkdir(name, DIRBITS | 0777) < 0) {
594 return( AFPERR_NOOBJ );
596 return( AFPERR_VLOCK );
599 return( AFPERR_ACCESS );
601 return( AFPERR_EXIST );
604 return( AFPERR_DFULL );
606 return( AFPERR_PARAM );
612 /* -------------------
613 system unlink with afp error code.
614 ENOENT is not an error.
616 int netatalk_unlink(const char *name)
618 if (unlink(name) < 0) {
626 return AFPERR_ACCESS;
634 /* ------------------- */
635 static int deletedir(char *dir)
637 char path[MAXPATHLEN + 1];
645 if ((len = strlen(dir)) +2 > sizeof(path))
649 if ((dp = opendir(dir)) == NULL)
655 remain = sizeof(path) -len -1;
656 while ((de = readdir(dp)) && err == AFP_OK) {
657 /* skip this and previous directory */
658 if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, ".."))
661 if (strlen(de->d_name) > remain) {
665 strcpy(path + len, de->d_name);
666 if (stat(path, &st)) {
669 if (S_ISDIR(st.st_mode)) {
670 err = deletedir(path);
672 err = netatalk_unlink(path);
677 /* okay. the directory is empty. delete it. note: we already got rid
680 err = netatalk_rmdir(dir);
685 /* do a recursive copy. */
686 static int copydir(char *src, char *dst, int noadouble)
688 char spath[MAXPATHLEN + 1], dpath[MAXPATHLEN + 1];
698 /* doesn't exist or the path is too long. */
699 if (((slen = strlen(src)) > sizeof(spath) - 2) ||
700 ((dlen = strlen(dst)) > sizeof(dpath) - 2) ||
701 ((dp = opendir(src)) == NULL))
704 /* try to create the destination directory */
705 if (AFP_OK != (err = netatalk_mkdir(dst)) ) {
710 /* set things up to copy */
714 srem = sizeof(spath) - slen -1;
719 drem = sizeof(dpath) - dlen -1;
722 while ((de = readdir(dp))) {
723 /* skip this and previous directory */
724 if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, ".."))
727 if (strlen(de->d_name) > srem) {
731 strcpy(spath + slen, de->d_name);
733 if (stat(spath, &st) == 0) {
734 if (strlen(de->d_name) > drem) {
738 strcpy(dpath + dlen, de->d_name);
740 if (S_ISDIR(st.st_mode)) {
741 if (AFP_OK != (err = copydir(spath, dpath, noadouble)))
743 } else if (AFP_OK != (err = copyfile(spath, dpath, NULL, noadouble))) {
747 /* keep the same time stamp. */
748 ut.actime = ut.modtime = st.st_mtime;
754 /* keep the same time stamp. */
755 if (stat(src, &st) == 0) {
756 ut.actime = ut.modtime = st.st_mtime;
766 /* --- public functions follow --- */
768 /* NOTE: we start off with at least one node (the root directory). */
769 struct dir *dirinsert( vol, dir )
775 if ((node = dir_insert(vol, dir)))
778 /* recolor the tree. the current node is red. */
779 dir->d_color = DIRTREE_COLOR_RED;
781 /* parent of this node has to be black. if the parent node
782 * is red, then we have a grandparent. */
783 while ((dir != vol->v_root) &&
784 (dir->d_back->d_color == DIRTREE_COLOR_RED)) {
785 /* are we on the left tree? */
786 if (dir->d_back == dir->d_back->d_back->d_left) {
787 node = dir->d_back->d_back->d_right; /* get the right node */
788 if (node->d_color == DIRTREE_COLOR_RED) {
789 /* we're red. we need to change to black. */
790 dir->d_back->d_color = DIRTREE_COLOR_BLACK;
791 node->d_color = DIRTREE_COLOR_BLACK;
792 dir->d_back->d_back->d_color = DIRTREE_COLOR_RED;
793 dir = dir->d_back->d_back; /* finished. go up. */
795 if (dir == dir->d_back->d_right) {
797 dir_leftrotate(vol, dir);
799 dir->d_back->d_color = DIRTREE_COLOR_BLACK;
800 dir->d_back->d_back->d_color = DIRTREE_COLOR_RED;
801 dir_rightrotate(vol, dir->d_back->d_back);
804 node = dir->d_back->d_back->d_left;
805 if (node->d_color == DIRTREE_COLOR_RED) {
806 /* we're red. we need to change to black. */
807 dir->d_back->d_color = DIRTREE_COLOR_BLACK;
808 node->d_color = DIRTREE_COLOR_BLACK;
809 dir->d_back->d_back->d_color = DIRTREE_COLOR_RED;
810 dir = dir->d_back->d_back; /* finished. ascend */
812 if (dir == dir->d_back->d_left) {
814 dir_rightrotate(vol, dir);
816 dir->d_back->d_color = DIRTREE_COLOR_BLACK;
817 dir->d_back->d_back->d_color = DIRTREE_COLOR_RED;
818 dir_leftrotate(vol, dir->d_back->d_back);
823 vol->v_root->d_color = DIRTREE_COLOR_BLACK;
827 /* free everything down. we don't bother to recolor as this is only
828 * called to free the entire tree */
829 void dirfreename(struct dir *dir)
831 if (dir->d_u_name != dir->d_m_name) {
840 if (!dir || (dir == SENTINEL))
843 if ( dir->d_left != SENTINEL ) {
844 dirfree( dir->d_left );
846 if ( dir->d_right != SENTINEL ) {
847 dirfree( dir->d_right );
850 if (dir != SENTINEL) {
856 /* --------------------------------------------
857 * most of the time mac name and unix name are the same
859 struct dir *dirnew(const char *m_name, const char *u_name)
863 dir = (struct dir *) calloc(1, sizeof( struct dir ));
867 if ((dir->d_m_name = strdup(m_name)) == NULL) {
872 if (m_name == u_name) {
873 dir->d_u_name = dir->d_m_name;
875 else if ((dir->d_u_name = strdup(u_name)) == NULL) {
881 dir->d_left = dir->d_right = SENTINEL;
882 dir->d_next = dir->d_prev = dir;
886 /* -------------------------------------------------- */
892 stat the file or errno
895 curdir: filename parent directory
901 stat the dir or errno
905 curdir: dir parent directory
913 curdir: dir parent directory
920 cname( vol, dir, cpath )
921 const struct vol *vol;
926 static char path[ MAXPATHLEN + 1];
927 static struct path ret;
938 afp_errno = AFPERR_NOOBJ;
939 switch (ret.m_type = *data) { /* path type */
942 len = (unsigned char) *data++;
947 if (afp_version >= 30) {
949 memcpy(&hint, data, sizeof(hint));
951 data += sizeof(hint);
953 memcpy(&len16, data, sizeof(len16));
960 /* else it's an error */
962 afp_errno = AFPERR_PARAM;
966 *cpath += len + size;
973 if (movecwd( vol, dir ) < 0 ) {
975 movecwd failed some of dir path are not there anymore.
976 FIXME Is it true with other errors?
977 so we remove dir from the cache
979 if (dir->d_did == DIRDID_ROOT_PARENT)
981 if (afp_errno == AFPERR_ACCESS) {
982 if ( movecwd( vol, dir->d_parent ) < 0 ) {
985 ret.m_name = dir->d_m_name;
986 ret.u_name = dir->d_u_name;
990 dir_invalidate(vol, dir);
1003 while (*data == sep && len > 0 ) {
1004 if ( dir->d_parent == NULL ) {
1007 dir = dir->d_parent;
1012 /* would this be faster with strlen + strncpy? */
1014 while ( *data != sep && len > 0 ) {
1019 /* short cut bits by chopping off a trailing \0. this also
1020 makes the traversal happy w/ filenames at the end of the
1027 if ( p != path ) { /* we got something */
1029 cdir = dir->d_child;
1031 if ( strcmp( cdir->d_m_name, path ) == 0 ) {
1034 cdir = (cdir == dir->d_child->d_prev) ? NULL :
1037 if ( cdir == NULL ) {
1039 /* if dir == curdir it always succeed,
1040 even if curdir is deleted.
1041 it's not a pb because it will fail in extenddir
1043 if ( movecwd( vol, dir ) < 0 ) {
1044 /* dir is not valid anymore
1045 we delete dir from the cache and abort.
1047 if ( dir->d_did == DIRDID_ROOT_PARENT)
1049 if (afp_errno == AFPERR_ACCESS)
1051 dir_invalidate(vol, dir);
1054 cdir = extenddir( vol, dir, &ret );
1058 cdir = extenddir( vol, dir, &ret );
1061 if ( cdir == NULL ) {
1063 if ( len > 0 || !ret.u_name) {
1076 * Move curdir to dir, with a possible chdir()
1078 int movecwd( vol, dir)
1079 const struct vol *vol;
1082 char path[MAXPATHLEN + 1];
1087 if ( dir == curdir ) {
1090 if ( dir->d_did == DIRDID_ROOT_PARENT) {
1091 afp_errno = AFPERR_PARAM;
1095 p = path + sizeof(path) - 1;
1098 for ( d = dir; d->d_parent != NULL && d != curdir; d = d->d_parent ) {
1101 if (p -n -1 < path) {
1102 afp_errno = AFPERR_PARAM;
1109 if ( d != curdir ) {
1110 n = strlen( vol->v_path );
1111 if (p -n -1 < path) {
1112 afp_errno = AFPERR_PARAM;
1117 strncpy( p, vol->v_path, n );
1119 if ( chdir( p ) < 0 ) {
1123 afp_errno = AFPERR_ACCESS;
1126 afp_errno = AFPERR_NOOBJ;
1136 * We can't use unix file's perm to support Apple's inherited protection modes.
1137 * If we aren't the file's owner we can't change its perms when moving it and smb
1138 * nfs,... don't even try.
1140 #define AFP_CHECK_ACCESS
1142 int check_access(char *path, int mode)
1144 #ifdef AFP_CHECK_ACCESS
1152 accessmode(p, &ma, curdir, NULL);
1153 if ((mode & OPENACC_WR) && !(ma.ma_user & AR_UWRITE))
1155 if ((mode & OPENACC_RD) && !(ma.ma_user & AR_UREAD))
1161 /* ------------------------------
1163 (name, dir) with curdir:name == dir, from afp_enumerate
1166 int getdirparams(const struct vol *vol,
1167 u_int16_t bitmap, struct path *s_path,
1169 char *buf, int *buflen )
1173 char *data, *l_nameoff = NULL, *utf_nameoff = NULL;
1174 int bit = 0, isad = 0;
1179 struct stat *st = &s_path->st;
1180 char *upath = s_path->u_name;
1182 if ((bitmap & ((1 << DIRPBIT_ATTR) |
1183 (1 << DIRPBIT_CDATE) |
1184 (1 << DIRPBIT_MDATE) |
1185 (1 << DIRPBIT_BDATE) |
1186 (1 << DIRPBIT_FINFO)))) {
1187 memset(&ad, 0, sizeof(ad));
1188 if ( !ad_open( upath, ADFLAGS_HF|ADFLAGS_DIR, O_RDONLY,
1189 DIRBITS | 0777, &ad)) {
1195 while ( bitmap != 0 ) {
1196 while (( bitmap & 1 ) == 0 ) {
1204 ad_getattr(&ad, &ashort);
1205 } else if (*upath == '.' && strcmp(upath, ".") &&
1206 strcmp(upath, "..")) {
1207 ashort = htons(ATTRBIT_INVISIBLE);
1210 ashort |= htons(ATTRBIT_SHARED);
1211 memcpy( data, &ashort, sizeof( ashort ));
1212 data += sizeof( ashort );
1216 if ( dir->d_did == DIRDID_ROOT) {
1217 aint = DIRDID_ROOT_PARENT;
1218 } else if (dir->d_did == DIRDID_ROOT_PARENT) {
1221 aint = dir->d_parent->d_did;
1223 memcpy( data, &aint, sizeof( aint ));
1224 data += sizeof( aint );
1227 case DIRPBIT_CDATE :
1228 if (!isad || (ad_getdate(&ad, AD_DATE_CREATE, &aint) < 0))
1229 aint = AD_DATE_FROM_UNIX(st->st_mtime);
1230 memcpy( data, &aint, sizeof( aint ));
1231 data += sizeof( aint );
1234 case DIRPBIT_MDATE :
1235 aint = AD_DATE_FROM_UNIX(st->st_mtime);
1236 memcpy( data, &aint, sizeof( aint ));
1237 data += sizeof( aint );
1240 case DIRPBIT_BDATE :
1241 if (!isad || (ad_getdate(&ad, AD_DATE_BACKUP, &aint) < 0))
1242 aint = AD_DATE_START;
1243 memcpy( data, &aint, sizeof( aint ));
1244 data += sizeof( aint );
1247 case DIRPBIT_FINFO :
1249 memcpy( data, ad_entry( &ad, ADEID_FINDERI ), 32 );
1250 } else { /* no appledouble */
1251 memset( data, 0, 32 );
1252 /* set default view -- this also gets done in ad_open() */
1253 ashort = htons(FINDERINFO_CLOSEDVIEW);
1254 memcpy(data + FINDERINFO_FRVIEWOFF, &ashort, sizeof(ashort));
1256 /* dot files are by default invisible */
1257 if (*upath == '.' && strcmp(upath, ".") &&
1258 strcmp(upath, "..")) {
1259 ashort = htons(FINDERINFO_INVISIBLE);
1260 memcpy(data + FINDERINFO_FRFLAGOFF,
1261 &ashort, sizeof(ashort));
1267 case DIRPBIT_LNAME :
1268 if (dir->d_m_name) /* root of parent can have a null name */
1271 memset(data, 0, sizeof(u_int16_t));
1272 data += sizeof( u_int16_t );
1275 case DIRPBIT_SNAME :
1276 memset(data, 0, sizeof(u_int16_t));
1277 data += sizeof( u_int16_t );
1281 memcpy( data, &dir->d_did, sizeof( aint ));
1282 data += sizeof( aint );
1285 case DIRPBIT_OFFCNT :
1287 /* this needs to handle current directory access rights */
1288 if (st->st_ctime == dir->ctime) {
1289 ashort = dir->offcnt;
1291 else if ((ret = for_each_dirent(vol, upath, NULL,NULL)) >= 0) {
1293 dir->offcnt = ashort;
1294 dir->ctime = st->st_ctime;
1296 ashort = htons( ashort );
1297 memcpy( data, &ashort, sizeof( ashort ));
1298 data += sizeof( ashort );
1302 aint = htonl(st->st_uid);
1303 memcpy( data, &aint, sizeof( aint ));
1304 data += sizeof( aint );
1308 aint = htonl(st->st_gid);
1309 memcpy( data, &aint, sizeof( aint ));
1310 data += sizeof( aint );
1313 case DIRPBIT_ACCESS :
1314 accessmode( upath, &ma, dir , st);
1316 *data++ = ma.ma_user;
1317 *data++ = ma.ma_world;
1318 *data++ = ma.ma_group;
1319 *data++ = ma.ma_owner;
1322 /* Client has requested the ProDOS information block.
1323 Just pass back the same basic block for all
1324 directories. <shirsch@ibm.net> */
1325 case DIRPBIT_PDINFO :
1326 if (afp_version >= 30) { /* UTF8 name */
1327 utf8 = kTextEncodingUTF8;
1328 if (dir->d_m_name) /* root of parent can have a null name */
1331 memset(data, 0, sizeof(u_int16_t));
1332 data += sizeof( u_int16_t );
1334 memcpy(data, &aint, sizeof( aint ));
1335 data += sizeof( aint );
1337 else { /* ProDOS Info Block */
1340 ashort = htons( 0x0200 );
1341 memcpy( data, &ashort, sizeof( ashort ));
1342 data += sizeof( ashort );
1343 memset( data, 0, sizeof( ashort ));
1344 data += sizeof( ashort );
1350 ad_close( &ad, ADFLAGS_HF );
1352 return( AFPERR_BITMAP );
1358 ashort = htons( data - buf );
1359 memcpy( l_nameoff, &ashort, sizeof( ashort ));
1360 data = set_name(vol, data, dir->d_m_name, 0);
1362 if ( utf_nameoff ) {
1363 ashort = htons( data - buf );
1364 memcpy( utf_nameoff, &ashort, sizeof( ashort ));
1365 data = set_name(vol, data, dir->d_m_name, utf8);
1368 ad_close( &ad, ADFLAGS_HF );
1370 *buflen = data - buf;
1374 /* ----------------------------- */
1375 int afp_setdirparams(obj, ibuf, ibuflen, rbuf, rbuflen )
1378 int ibuflen, *rbuflen;
1383 u_int16_t vid, bitmap;
1389 memcpy( &vid, ibuf, sizeof( vid ));
1390 ibuf += sizeof( vid );
1392 if (NULL == ( vol = getvolbyvid( vid )) ) {
1393 return( AFPERR_PARAM );
1396 if (vol->v_flags & AFPVOL_RO)
1397 return AFPERR_VLOCK;
1399 memcpy( &did, ibuf, sizeof( did ));
1400 ibuf += sizeof( int );
1402 if (NULL == ( dir = dirlookup( vol, did )) ) {
1406 memcpy( &bitmap, ibuf, sizeof( bitmap ));
1407 bitmap = ntohs( bitmap );
1408 ibuf += sizeof( bitmap );
1410 if (NULL == ( path = cname( vol, dir, &ibuf )) ) {
1414 /* FIXME access error or not a file */
1415 if ( *path->m_name != '\0' ) {
1416 return (path_isadir( path))? afp_errno:AFPERR_BADTYPE ;
1420 * If ibuf is odd, make it even.
1422 if ((u_long)ibuf & 1 ) {
1426 if (AFP_OK == ( rc = setdirparams(vol, path, bitmap, ibuf )) ) {
1427 setvoltime(obj, vol );
1433 * cf AFP3.0.pdf page 244 for change_mdate and change_parent_mdate logic
1435 * assume path == '\0' eg. it's a directory in canonical form
1438 struct path Cur_Path = {
1441 ".", /* unix name */
1442 0, /* stat is not set */
1446 int setdirparams(const struct vol *vol,
1447 struct path *path, u_int16_t bitmap, char *buf )
1455 int bit = 0, aint, isad = 1;
1456 u_int16_t ashort, bshort;
1458 int change_mdate = 0;
1459 int change_parent_mdate = 0;
1462 upath = path->u_name;
1463 memset(&ad, 0, sizeof(ad));
1465 if (ad_open( upath, vol_noadouble(vol)|ADFLAGS_HF|ADFLAGS_DIR,
1466 O_RDWR|O_CREAT, 0666, &ad) < 0) {
1468 * Check to see what we're trying to set. If it's anything
1469 * but ACCESS, UID, or GID, give an error. If it's any of those
1470 * three, we don't need the ad to be open, so just continue.
1472 * note: we also don't need to worry about mdate. also, be quiet
1473 * if we're using the noadouble option.
1475 if (!vol_noadouble(vol) && (bitmap &
1476 ~((1<<DIRPBIT_ACCESS)|(1<<DIRPBIT_UID)|(1<<DIRPBIT_GID)|
1477 (1<<DIRPBIT_MDATE)|(1<<DIRPBIT_PDINFO)))) {
1478 return AFPERR_ACCESS;
1484 * Check to see if a create was necessary. If it was, we'll want
1485 * to set our name, etc.
1487 if ( ad_get_HF_flags( &ad ) & O_CREAT ) {
1488 ad_setentrylen( &ad, ADEID_NAME, strlen( curdir->d_m_name ));
1489 memcpy( ad_entry( &ad, ADEID_NAME ), curdir->d_m_name,
1490 ad_getentrylen( &ad, ADEID_NAME ));
1494 while ( bitmap != 0 ) {
1495 while (( bitmap & 1 ) == 0 ) {
1504 memcpy( &ashort, buf, sizeof( ashort ));
1505 ad_getattr(&ad, &bshort);
1506 if ( ntohs( ashort ) & ATTRBIT_SETCLR ) {
1507 bshort |= htons( ntohs( ashort ) & ~ATTRBIT_SETCLR );
1511 ad_setattr(&ad, bshort);
1512 if ((ashort & htons(ATTRBIT_INVISIBLE)))
1513 change_parent_mdate = 1;
1515 buf += sizeof( ashort );
1518 case DIRPBIT_CDATE :
1521 memcpy(&aint, buf, sizeof(aint));
1522 ad_setdate(&ad, AD_DATE_CREATE, aint);
1524 buf += sizeof( aint );
1527 case DIRPBIT_MDATE :
1528 memcpy(&newdate, buf, sizeof(newdate));
1529 buf += sizeof( newdate );
1532 case DIRPBIT_BDATE :
1535 memcpy(&aint, buf, sizeof(aint));
1536 ad_setdate(&ad, AD_DATE_BACKUP, aint);
1538 buf += sizeof( aint );
1541 case DIRPBIT_FINFO :
1544 * Alright, we admit it, this is *really* sick!
1545 * The 4 bytes that we don't copy, when we're dealing
1546 * with the root of a volume, are the directory's
1547 * location information. This eliminates that annoying
1548 * behavior one sees when mounting above another mount
1552 if ( curdir->d_did == DIRDID_ROOT ) {
1553 memcpy( ad_entry( &ad, ADEID_FINDERI ), buf, 10 );
1554 memcpy( ad_entry( &ad, ADEID_FINDERI ) + 14, buf + 14, 18 );
1556 memcpy( ad_entry( &ad, ADEID_FINDERI ), buf, 32 );
1562 case DIRPBIT_UID : /* What kind of loser mounts as root? */
1563 change_parent_mdate = 1;
1564 memcpy( &aint, buf, sizeof(aint));
1565 buf += sizeof( aint );
1566 if ( (curdir->d_did == DIRDID_ROOT) &&
1567 (setdeskowner( ntohl(aint), -1 ) < 0)) {
1571 err = AFPERR_ACCESS;
1572 goto setdirparam_done;
1576 goto setdirparam_done;
1579 LOG(log_error, logtype_afpd, "setdirparam: setdeskowner: %s",
1583 goto setdirparam_done;
1588 if ( setdirowner( ntohl(aint), -1, vol_noadouble(vol) ) < 0 ) {
1592 err = AFPERR_ACCESS;
1593 goto setdirparam_done;
1597 goto setdirparam_done;
1600 LOG(log_error, logtype_afpd, "setdirparam: setdirowner: %s",
1607 change_parent_mdate = 1;
1608 memcpy( &aint, buf, sizeof( aint ));
1609 buf += sizeof( aint );
1610 if (curdir->d_did == DIRDID_ROOT)
1611 setdeskowner( -1, ntohl(aint) );
1613 #if 0 /* don't error if we can't set the desktop owner. */
1617 err = AFPERR_ACCESS;
1618 goto setdirparam_done;
1622 goto setdirparam_done;
1625 LOG(log_error, logtype_afpd, "setdirparam: setdeskowner: %m" );
1628 goto setdirparam_done;
1634 if ( setdirowner( -1, ntohl(aint), vol_noadouble(vol) ) < 0 ) {
1638 err = AFPERR_ACCESS;
1639 goto setdirparam_done;
1643 goto setdirparam_done;
1646 LOG(log_error, logtype_afpd, "setdirparam: setdirowner: %s",
1653 case DIRPBIT_ACCESS :
1655 change_parent_mdate = 1;
1656 ma.ma_user = *buf++;
1657 ma.ma_world = *buf++;
1658 ma.ma_group = *buf++;
1659 ma.ma_owner = *buf++;
1661 if (curdir->d_did == DIRDID_ROOT)
1662 setdeskmode(mtoumode( &ma ));
1663 #if 0 /* don't error if we can't set the desktop mode */
1667 err = AFPERR_ACCESS;
1668 goto setdirparam_done;
1671 goto setdirparam_done;
1673 LOG(log_error, logtype_afpd, "setdirparam: setdeskmode: %s",
1677 goto setdirparam_done;
1681 if ( setdirmode( mtoumode( &ma ), vol_noadouble(vol),
1682 (vol->v_flags & AFPVOL_DROPBOX)) < 0 ) {
1686 err = AFPERR_ACCESS;
1687 goto setdirparam_done;
1690 goto setdirparam_done;
1692 LOG(log_error, logtype_afpd, "setdirparam: setdirmode: %s",
1695 goto setdirparam_done;
1700 /* Ignore what the client thinks we should do to the
1701 ProDOS information block. Skip over the data and
1702 report nothing amiss. <shirsch@ibm.net> */
1703 case DIRPBIT_PDINFO :
1704 if (afp_version < 30) {
1709 err = AFPERR_BITMAP;
1710 goto setdirparam_done;
1719 if (change_mdate && newdate == 0 && gettimeofday(&tv, NULL) == 0) {
1720 newdate = AD_DATE_FROM_UNIX(tv.tv_sec);
1724 ad_setdate(&ad, AD_DATE_MODIFY, newdate);
1725 ut.actime = ut.modtime = AD_DATE_TO_UNIX(newdate);
1730 ad_flush( &ad, ADFLAGS_HF );
1731 ad_close( &ad, ADFLAGS_HF );
1734 if (change_parent_mdate && curdir->d_did != DIRDID_ROOT
1735 && gettimeofday(&tv, NULL) == 0) {
1736 if (!movecwd(vol, curdir->d_parent)) {
1737 newdate = AD_DATE_FROM_UNIX(tv.tv_sec);
1738 bitmap = 1<<DIRPBIT_MDATE;
1739 setdirparams(vol, &Cur_Path, bitmap, (char *)&newdate);
1740 /* should we reset curdir ?*/
1747 int afp_createdir(obj, ibuf, ibuflen, rbuf, rbuflen )
1750 int ibuflen, *rbuflen;
1756 struct path *s_path;
1764 memcpy( &vid, ibuf, sizeof( vid ));
1765 ibuf += sizeof( vid );
1766 if (NULL == ( vol = getvolbyvid( vid )) ) {
1767 return( AFPERR_PARAM );
1770 if (vol->v_flags & AFPVOL_RO)
1771 return AFPERR_VLOCK;
1773 memcpy( &did, ibuf, sizeof( did ));
1774 ibuf += sizeof( did );
1775 if (NULL == ( dir = dirlookup( vol, did )) ) {
1776 return afp_errno; /* was AFPERR_NOOBJ */
1779 if (NULL == ( s_path = cname( vol, dir, &ibuf )) ) {
1782 /* cname was able to move curdir to it! */
1783 if (*s_path->m_name == '\0')
1784 return AFPERR_EXIST;
1786 upath = s_path->u_name;
1787 if (0 != (err = check_name(vol, upath))) {
1791 if (AFP_OK != (err = netatalk_mkdir( upath))) {
1795 if (of_stat(s_path) < 0) {
1799 if ((dir = adddir( vol, curdir, s_path)) == NULL) {
1803 if ( movecwd( vol, dir ) < 0 ) {
1804 return( AFPERR_PARAM );
1807 memset(&ad, 0, sizeof(ad));
1808 if (ad_open( ".", vol_noadouble(vol)|ADFLAGS_HF|ADFLAGS_DIR,
1809 O_RDWR|O_CREAT, 0666, &ad ) < 0) {
1810 if (vol_noadouble(vol))
1811 goto createdir_done;
1812 return( AFPERR_ACCESS );
1815 ad_setentrylen( &ad, ADEID_NAME, strlen( s_path->m_name ));
1816 memcpy( ad_entry( &ad, ADEID_NAME ), s_path->m_name,
1817 ad_getentrylen( &ad, ADEID_NAME ));
1818 ad_flush( &ad, ADFLAGS_HF );
1819 ad_close( &ad, ADFLAGS_HF );
1822 memcpy( rbuf, &dir->d_did, sizeof( u_int32_t ));
1823 *rbuflen = sizeof( u_int32_t );
1824 setvoltime(obj, vol );
1829 * dst new unix filename (not a pathname)
1830 * newname new mac name
1834 int renamedir(src, dst, dir, newparent, newname, noadouble)
1835 char *src, *dst, *newname;
1836 struct dir *dir, *newparent;
1837 const int noadouble;
1844 /* existence check moved to afp_moveandrename */
1845 if ( unix_rename( src, dst ) < 0 ) {
1848 return( AFPERR_NOOBJ );
1850 return( AFPERR_ACCESS );
1852 return AFPERR_VLOCK;
1854 /* tried to move directory into a subdirectory of itself */
1855 return AFPERR_CANTMOVE;
1857 /* this needs to copy and delete. bleah. that means we have
1858 * to deal with entire directory hierarchies. */
1859 if ((err = copydir(src, dst, noadouble)) < 0) {
1863 if ((err = deletedir(src)) < 0)
1867 return( AFPERR_PARAM );
1871 memset(&ad, 0, sizeof(ad));
1872 len = strlen( newname );
1873 /* rename() succeeded so we need to update our tree even if we can't open
1876 if ( !ad_open( dst, ADFLAGS_HF|ADFLAGS_DIR, O_RDWR, 0, &ad)) {
1877 ad_setentrylen( &ad, ADEID_NAME, len );
1878 memcpy( ad_entry( &ad, ADEID_NAME ), newname, len );
1879 ad_flush( &ad, ADFLAGS_HF );
1880 ad_close( &ad, ADFLAGS_HF );
1883 if (dir->d_m_name == dir->d_u_name)
1884 dir->d_u_name = NULL;
1886 if ((buf = (char *) realloc( dir->d_m_name, len + 1 )) == NULL ) {
1887 LOG(log_error, logtype_afpd, "renamedir: realloc mac name: %s", strerror(errno) );
1888 /* FIXME : fatal ? */
1891 dir->d_m_name = buf;
1892 strcpy( dir->d_m_name, newname );
1894 if (newname == dst) {
1895 free(dir->d_u_name);
1896 dir->d_u_name = dir->d_m_name;
1899 if ((buf = (char *) realloc( dir->d_u_name, strlen(dst) + 1 )) == NULL ) {
1900 LOG(log_error, logtype_afpd, "renamedir: realloc unix name: %s", strerror(errno) );
1903 dir->d_u_name = buf;
1904 strcpy( dir->d_u_name, dst );
1907 if (( parent = dir->d_parent ) == NULL ) {
1910 if ( parent == newparent ) {
1914 /* detach from old parent and add to new one. */
1915 dirchildremove(parent, dir);
1916 dir->d_parent = newparent;
1917 dirchildadd(newparent, dir);
1921 #define DOT_APPLEDOUBLE_LEN 13
1922 /* delete an empty directory */
1923 int deletecurdir( vol, path, pathlen )
1924 const struct vol *vol;
1936 if ( curdir->d_parent == NULL ) {
1937 return( AFPERR_ACCESS );
1942 memset(&ad, 0, sizeof(ad));
1943 if ( ad_open( ".", ADFLAGS_HF|ADFLAGS_DIR, O_RDONLY,
1944 DIRBITS | 0777, &ad) == 0 ) {
1946 ad_getattr(&ad, &ashort);
1947 ad_close( &ad, ADFLAGS_HF );
1948 if ((ashort & htons(ATTRBIT_NODELETE))) {
1949 return AFPERR_OLOCK;
1953 /* delete stray .AppleDouble files. this happens to get .Parent files
1955 if ((dp = opendir(".AppleDouble"))) {
1956 strcpy(path, ".AppleDouble/");
1957 while ((de = readdir(dp))) {
1958 /* skip this and previous directory */
1959 if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, ".."))
1962 /* bail if the file exists in the current directory.
1963 * note: this will not fail with dangling symlinks */
1964 if (stat(de->d_name, &st) == 0) {
1966 return AFPERR_DIRNEMPT;
1969 strcpy(path + DOT_APPLEDOUBLE_LEN, de->d_name);
1970 if ((err = netatalk_unlink(path))) {
1978 if ( (err = netatalk_rmdir( ".AppleDouble" )) ) {
1982 /* now get rid of dangling symlinks */
1983 if ((dp = opendir("."))) {
1984 while ((de = readdir(dp))) {
1985 /* skip this and previous directory */
1986 if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, ".."))
1989 /* bail if it's not a symlink */
1990 if ((lstat(de->d_name, &st) == 0) && !S_ISLNK(st.st_mode)) {
1992 return AFPERR_DIRNEMPT;
1995 if ((err = netatalk_unlink(de->d_name))) {
2002 if ( movecwd( vol, curdir->d_parent ) < 0 ) {
2007 if ( !(err = netatalk_rmdir(fdir->d_u_name))) {
2008 dirchildremove(curdir, fdir);
2010 cnid_delete(vol->v_db, fdir->d_did);
2011 #endif /* CNID_DB */
2012 dir_remove( vol, fdir );
2017 /* inode is used as key for cnid.
2018 * Close the descriptor only after cnid_delete
2026 int afp_mapid(obj, ibuf, ibuflen, rbuf, rbuflen )
2029 int ibuflen, *rbuflen;
2039 sfunc = (unsigned char) *ibuf++;
2040 memcpy( &id, ibuf, sizeof( id ));
2048 case 3 :/* unicode */
2049 if (( pw = getpwuid( id )) == NULL ) {
2050 return( AFPERR_NOITEM );
2056 case 4 : /* unicode */
2057 if (( gr = (struct group *)getgrgid( id )) == NULL ) {
2058 return( AFPERR_NOITEM );
2064 return( AFPERR_PARAM );
2069 if (afp_version < 30) {
2070 return( AFPERR_PARAM );
2073 /* map to unicode */
2076 len = strlen( name );
2083 u_int16_t tp = htons(len);
2084 memcpy(rbuf, &tp, sizeof(tp));
2093 memcpy( rbuf, name, len );
2099 int afp_mapname(obj, ibuf, ibuflen, rbuf, rbuflen )
2102 int ibuflen, *rbuflen;
2111 sfunc = (unsigned char) *ibuf++;
2114 case 2 : /* unicode */
2115 memcpy(&ulen, ibuf, sizeof(ulen));
2121 len = (unsigned char) *ibuf++;
2125 return( AFPERR_PARAM );
2132 case 1 : /* unicode */
2134 if (( pw = (struct passwd *)getpwnam( ibuf )) == NULL ) {
2136 return( AFPERR_NOITEM );
2141 case 2 : /* unicode */
2143 if (( gr = (struct group *)getgrnam( ibuf )) == NULL ) {
2145 return( AFPERR_NOITEM );
2154 memcpy( rbuf, &id, sizeof( id ));
2155 *rbuflen = sizeof( id );
2159 /* ------------------------------------
2160 variable DID support
2162 int afp_closedir(obj, ibuf, ibuflen, rbuf, rbuflen )
2165 int ibuflen, *rbuflen;
2176 /* do nothing as dids are static for the life of the process. */
2180 memcpy(&vid, ibuf, sizeof( vid ));
2181 ibuf += sizeof( vid );
2182 if (( vol = getvolbyvid( vid )) == NULL ) {
2183 return( AFPERR_PARAM );
2186 memcpy( &did, ibuf, sizeof( did ));
2187 ibuf += sizeof( did );
2188 if (( dir = dirlookup( vol, did )) == NULL ) {
2189 return( AFPERR_PARAM );
2192 /* dir_remove -- deletedid */
2198 /* did creation gets done automatically
2199 * there's a pb again with case but move it to cname
2201 int afp_opendir(obj, ibuf, ibuflen, rbuf, rbuflen )
2204 int ibuflen, *rbuflen;
2207 struct dir *parentdir;
2215 memcpy(&vid, ibuf, sizeof(vid));
2216 ibuf += sizeof( vid );
2218 if (NULL == ( vol = getvolbyvid( vid )) ) {
2219 return( AFPERR_PARAM );
2222 memcpy(&did, ibuf, sizeof(did));
2223 ibuf += sizeof(did);
2225 if (NULL == ( parentdir = dirlookup( vol, did )) ) {
2229 if (NULL == ( path = cname( vol, parentdir, &ibuf )) ) {
2233 if ( *path->m_name != '\0' ) {
2234 return (path_isadir(path))? afp_errno:AFPERR_BADTYPE ;
2237 if ( !path->st_valid && of_stat(path ) < 0 ) {
2238 return( AFPERR_NOOBJ );
2240 if ( path->st_errno ) {
2241 return( AFPERR_NOOBJ );
2244 memcpy(rbuf, &curdir->d_did, sizeof(curdir->d_did));
2245 *rbuflen = sizeof(curdir->d_did);