2 * $Id: directory.c,v 1.58 2003-01-24 07:08:42 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 mpath = utompath(vol, upath);
187 pathlen = len; /* no 0 in the last part */
189 strcpy(ptr - len, mpath);
192 ret = dirsearch(vol,id);
196 if ((upath = cnid_resolve(vol->v_db, &id, buffer, buflen)) == NULL) {
197 afp_errno = AFPERR_NOOBJ;
200 mpath = utompath(vol, upath);
201 len = strlen(mpath) + 1;
204 afp_errno = AFPERR_PARAM;
207 strcpy(ptr - len, mpath);
212 *ptr = (unsigned char)pathlen;
215 /* cname is not efficient */
216 if (cname( vol, ret, &ptr ) == NULL )
219 return dirsearch(vol, did);
222 /* --------------------------- */
223 /* rotate the tree to the left */
224 static void dir_leftrotate(vol, dir)
228 struct dir *right = dir->d_right;
230 /* whee. move the right's left tree into dir's right tree */
231 dir->d_right = right->d_left;
232 if (right->d_left != SENTINEL)
233 right->d_left->d_back = dir;
235 if (right != SENTINEL) {
236 right->d_back = dir->d_back;
240 if (!dir->d_back) /* no parent. move the right tree to the top. */
242 else if (dir == dir->d_back->d_left) /* we were on the left */
243 dir->d_back->d_left = right;
245 dir->d_back->d_right = right; /* we were on the right */
247 /* re-insert dir on the left tree */
254 /* rotate the tree to the right */
255 static void dir_rightrotate(vol, dir)
259 struct dir *left = dir->d_left;
261 /* whee. move the left's right tree into dir's left tree */
262 dir->d_left = left->d_right;
263 if (left->d_right != SENTINEL)
264 left->d_right->d_back = dir;
266 if (left != SENTINEL) {
267 left->d_back = dir->d_back;
271 if (!dir->d_back) /* no parent. move the left tree to the top. */
273 else if (dir == dir->d_back->d_right) /* we were on the right */
274 dir->d_back->d_right = left;
276 dir->d_back->d_left = left; /* we were on the left */
278 /* re-insert dir on the right tree */
284 /* recolor after a removal */
285 static struct dir *dir_rmrecolor(vol, dir)
291 while ((dir != vol->v_root) && (dir->d_color == DIRTREE_COLOR_BLACK)) {
292 /* are we on the left tree? */
293 if (dir == dir->d_back->d_left) {
294 leaf = dir->d_back->d_right; /* get right side */
295 if (leaf->d_color == DIRTREE_COLOR_RED) {
296 /* we're red. we need to change to black. */
297 leaf->d_color = DIRTREE_COLOR_BLACK;
298 dir->d_back->d_color = DIRTREE_COLOR_RED;
299 dir_leftrotate(vol, dir->d_back);
300 leaf = dir->d_back->d_right;
303 /* right leaf has black end nodes */
304 if ((leaf->d_left->d_color == DIRTREE_COLOR_BLACK) &&
305 (leaf->d_right->d_color = DIRTREE_COLOR_BLACK)) {
306 leaf->d_color = DIRTREE_COLOR_RED; /* recolor leaf as red */
307 dir = dir->d_back; /* ascend */
309 if (leaf->d_right->d_color == DIRTREE_COLOR_BLACK) {
310 leaf->d_left->d_color = DIRTREE_COLOR_BLACK;
311 leaf->d_color = DIRTREE_COLOR_RED;
312 dir_rightrotate(vol, leaf);
313 leaf = dir->d_back->d_right;
315 leaf->d_color = dir->d_back->d_color;
316 dir->d_back->d_color = DIRTREE_COLOR_BLACK;
317 leaf->d_right->d_color = DIRTREE_COLOR_BLACK;
318 dir_leftrotate(vol, dir->d_back);
321 } else { /* right tree */
322 leaf = dir->d_back->d_left; /* left tree */
323 if (leaf->d_color == DIRTREE_COLOR_RED) {
324 leaf->d_color = DIRTREE_COLOR_BLACK;
325 dir->d_back->d_color = DIRTREE_COLOR_RED;
326 dir_rightrotate(vol, dir->d_back);
327 leaf = dir->d_back->d_left;
330 /* left leaf has black end nodes */
331 if ((leaf->d_right->d_color == DIRTREE_COLOR_BLACK) &&
332 (leaf->d_left->d_color = DIRTREE_COLOR_BLACK)) {
333 leaf->d_color = DIRTREE_COLOR_RED; /* recolor leaf as red */
334 dir = dir->d_back; /* ascend */
336 if (leaf->d_left->d_color == DIRTREE_COLOR_BLACK) {
337 leaf->d_right->d_color = DIRTREE_COLOR_BLACK;
338 leaf->d_color = DIRTREE_COLOR_RED;
339 dir_leftrotate(vol, leaf);
340 leaf = dir->d_back->d_left;
342 leaf->d_color = dir->d_back->d_color;
343 dir->d_back->d_color = DIRTREE_COLOR_BLACK;
344 leaf->d_left->d_color = DIRTREE_COLOR_BLACK;
345 dir_rightrotate(vol, dir->d_back);
350 dir->d_color = DIRTREE_COLOR_BLACK;
357 /* remove the node from the tree. this is just like insertion, but
358 * different. actually, it has to worry about a bunch of things that
359 * insertion doesn't care about. */
360 static void dir_remove( vol, dir )
365 struct ofork *of, *last;
366 struct dir *node, *leaf;
367 #endif /* REMOVE_NODES */
369 if (!dir || (dir == SENTINEL))
372 /* i'm not sure if it really helps to delete stuff. */
374 if (dir->d_u_name != dir->d_m_name) {
378 dir->d_m_name = NULL;
379 dir->d_u_name = NULL;
380 #else /* ! REMOVE_NODES */
382 /* go searching for a node with at most one child */
383 if ((dir->d_left == SENTINEL) || (dir->d_right == SENTINEL)) {
387 while (node->d_left != SENTINEL)
392 leaf = (node->d_left != SENTINEL) ? node->d_left : node->d_right;
395 leaf->d_back = node->d_back;
398 } else if (node == node->d_back->d_left) { /* left tree */
399 node->d_back->d_left = leaf;
401 node->d_back->d_right = leaf;
404 /* we want to free node, but we also want to free the data in dir.
405 * currently, that's d_name and the directory traversal bits.
406 * we just copy the necessary bits and then fix up all the
407 * various pointers to the directory. needless to say, there are
408 * a bunch of places that store the directory struct. */
410 struct dir save, *tmp;
412 memcpy(&save, dir, sizeof(save));
413 memcpy(dir, node, sizeof(struct dir));
415 /* restore the red-black bits */
416 dir->d_left = save.d_left;
417 dir->d_right = save.d_right;
418 dir->d_back = save.d_back;
419 dir->d_color = save.d_color;
421 if (node == vol->v_dir) {/* we may need to fix up this pointer */
423 rootpar.d_child = vol->v_dir;
425 /* if we aren't the root directory, we have parents and
426 * siblings to worry about */
427 if (dir->d_parent->d_child == node)
428 dir->d_parent->d_child = dir;
429 dir->d_next->d_prev = dir;
430 dir->d_prev->d_next = dir;
433 /* fix up children. */
437 tmp = (tmp == dir->d_child->d_prev) ? NULL : tmp->d_next;
440 if (node == curdir) /* another pointer to fixup */
443 /* we also need to fix up oforks. bleah */
444 if ((of = dir->d_ofork)) {
445 last = of->of_d_prev;
448 of = (last == of) ? NULL : of->of_d_next;
452 /* set the node's d_name */
453 node->d_m_name = save.d_m_name;
454 node->d_u_name = save.d_u_name;
457 if (node->d_color == DIRTREE_COLOR_BLACK)
458 dir_rmrecolor(vol, leaf);
460 if (node->d_u_name != node->d_m_name) {
461 free(node->d_u_name);
463 free(node->d_m_name);
465 #endif /* ! REMOVE_NODES */
468 /* ---------------------------------------
469 * remove the node and its childs from the tree
471 * FIXME what about opened forks with refs to it?
472 * it's an afp specs violation because you can't delete
473 * an opened forks. Now afpd doesn't care about forks opened by other
474 * process. It's fixable within afpd if fnctl_lock, doable with smb and
475 * next to impossible for nfs and local filesystem access.
477 static void dir_invalidate( vol, dir )
478 const struct vol *vol;
482 /* v_root can't be deleted */
483 if (movecwd(vol, vol->v_root) < 0) {
484 LOG(log_error, logtype_afpd, "cname can't chdir to : %s", vol->v_root);
488 dirchildremove(dir->d_parent, dir);
489 dir_remove( vol, dir );
492 /* ------------------------------------ */
493 static struct dir *dir_insert(vol, dir)
494 const struct vol *vol;
500 while (pdir->d_did != dir->d_did ) {
501 if ( pdir->d_did > dir->d_did ) {
502 if ( pdir->d_left == SENTINEL ) {
509 if ( pdir->d_right == SENTINEL ) {
514 pdir = pdir->d_right;
522 * attempt to extend the current dir. tree to include path
523 * as a side-effect, movecwd to that point and return the new dir
526 extenddir( vol, dir, path )
533 path->u_name = p = mtoupath(vol, path->m_name );
534 if ( of_stat( path ) != 0 ) {
538 if (!S_ISDIR(path->st.st_mode)) {
542 if (( dir = adddir( vol, dir, path)) == NULL ) {
546 if ( movecwd( vol, dir ) < 0 ) {
553 static int deletedir(char *dir)
555 char path[MAXPATHLEN + 1];
562 if ((len = strlen(dir)) > sizeof(path))
566 if ((dp = opendir(dir)) == NULL)
572 while ((de = readdir(dp))) {
573 /* skip this and previous directory */
574 if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, ".."))
577 strncpy(path + len, de->d_name, sizeof(path) - len);
578 if (stat(path, &st) == 0) {
579 if (S_ISDIR(st.st_mode)) {
580 if ((err = deletedir(path)) < 0) {
584 } else if (unlink(path) < 0) {
587 continue; /* somebody went and deleted it behind our backs. */
605 /* okay. the directory is empty. delete it. note: we already got rid
607 if (rmdir(dir) < 0) {
611 case ENOTEMPTY : /* should never happen */
612 return( AFPERR_DIRNEMPT );
615 return( AFPERR_ACCESS );
619 return( AFPERR_PARAM );
625 /* do a recursive copy. */
626 static int copydir(char *src, char *dst, int noadouble)
628 char spath[MAXPATHLEN + 1], dpath[MAXPATHLEN + 1];
636 /* doesn't exist or the path is too long. */
637 if (((slen = strlen(src)) > sizeof(spath) - 2) ||
638 ((dlen = strlen(dst)) > sizeof(dpath) - 2) ||
639 ((dp = opendir(src)) == NULL))
642 /* try to create the destination directory */
643 if (ad_mkdir(dst, DIRBITS | 0777) < 0) {
647 return( AFPERR_NOOBJ );
649 return( AFPERR_VLOCK );
652 return( AFPERR_ACCESS );
654 return( AFPERR_EXIST );
657 return( AFPERR_DFULL );
659 return( AFPERR_PARAM );
663 /* set things up to copy */
671 while ((de = readdir(dp))) {
672 /* skip this and previous directory */
673 if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, ".."))
676 strncpy(spath + slen, de->d_name, sizeof(spath) - slen);
677 if (stat(spath, &st) == 0) {
678 strncpy(dpath + dlen, de->d_name, sizeof(dpath) - dlen);
680 if (S_ISDIR(st.st_mode)) {
681 if ((err = copydir(spath, dpath, noadouble)) < 0)
683 } else if ((err = copyfile(spath, dpath, NULL, noadouble)) < 0) {
687 /* keep the same time stamp. */
688 ut.actime = ut.modtime = st.st_mtime;
694 /* keep the same time stamp. */
695 if (stat(src, &st) == 0) {
696 ut.actime = ut.modtime = st.st_mtime;
706 /* --- public functions follow --- */
708 /* NOTE: we start off with at least one node (the root directory). */
709 struct dir *dirinsert( vol, dir )
715 if ((node = dir_insert(vol, dir)))
718 /* recolor the tree. the current node is red. */
719 dir->d_color = DIRTREE_COLOR_RED;
721 /* parent of this node has to be black. if the parent node
722 * is red, then we have a grandparent. */
723 while ((dir != vol->v_root) &&
724 (dir->d_back->d_color == DIRTREE_COLOR_RED)) {
725 /* are we on the left tree? */
726 if (dir->d_back == dir->d_back->d_back->d_left) {
727 node = dir->d_back->d_back->d_right; /* get the right node */
728 if (node->d_color == DIRTREE_COLOR_RED) {
729 /* we're red. we need to change to black. */
730 dir->d_back->d_color = DIRTREE_COLOR_BLACK;
731 node->d_color = DIRTREE_COLOR_BLACK;
732 dir->d_back->d_back->d_color = DIRTREE_COLOR_RED;
733 dir = dir->d_back->d_back; /* finished. go up. */
735 if (dir == dir->d_back->d_right) {
737 dir_leftrotate(vol, dir);
739 dir->d_back->d_color = DIRTREE_COLOR_BLACK;
740 dir->d_back->d_back->d_color = DIRTREE_COLOR_RED;
741 dir_rightrotate(vol, dir->d_back->d_back);
744 node = dir->d_back->d_back->d_left;
745 if (node->d_color == DIRTREE_COLOR_RED) {
746 /* we're red. we need to change to black. */
747 dir->d_back->d_color = DIRTREE_COLOR_BLACK;
748 node->d_color = DIRTREE_COLOR_BLACK;
749 dir->d_back->d_back->d_color = DIRTREE_COLOR_RED;
750 dir = dir->d_back->d_back; /* finished. ascend */
752 if (dir == dir->d_back->d_left) {
754 dir_rightrotate(vol, dir);
756 dir->d_back->d_color = DIRTREE_COLOR_BLACK;
757 dir->d_back->d_back->d_color = DIRTREE_COLOR_RED;
758 dir_leftrotate(vol, dir->d_back->d_back);
763 vol->v_root->d_color = DIRTREE_COLOR_BLACK;
767 /* free everything down. we don't bother to recolor as this is only
768 * called to free the entire tree */
772 if (!dir || (dir == SENTINEL))
775 if ( dir->d_left != SENTINEL ) {
776 dirfree( dir->d_left );
778 if ( dir->d_right != SENTINEL ) {
779 dirfree( dir->d_right );
782 if (dir != SENTINEL) {
783 if (dir->d_u_name != dir->d_m_name) {
791 /* --------------------------------------------
792 * most of the time mac name and unix name are the same
794 struct dir *dirnew(const char *m_name, const char *u_name)
798 dir = (struct dir *) calloc(1, sizeof( struct dir ));
802 if ((dir->d_m_name = strdup(m_name)) == NULL) {
807 if (m_name == u_name) {
808 dir->d_u_name = dir->d_m_name;
810 else if ((dir->d_u_name = strdup(u_name)) == NULL) {
816 dir->d_left = dir->d_right = SENTINEL;
817 dir->d_next = dir->d_prev = dir;
821 /* -------------------------------------------------- */
827 stat the file or errno
830 curdir: filename parent directory
836 stat the dir or errno
840 curdir: dir parent directory
848 curdir: dir parent directory
855 cname( vol, dir, cpath )
856 const struct vol *vol;
861 static char path[ MAXPATHLEN + 1];
862 static struct path ret;
873 afp_errno = AFPERR_NOOBJ;
874 switch (ret.m_type = *data) { /* path type */
877 len = (unsigned char) *data++;
882 if (afp_version >= 30) {
884 memcpy(&hint, data, sizeof(hint));
886 data += sizeof(hint);
888 memcpy(&len16, data, sizeof(len16));
895 /* else it's an error */
897 afp_errno = AFPERR_PARAM;
901 *cpath += len + size;
908 if (movecwd( vol, dir ) < 0 ) {
910 movecwd failed some of dir path are not there anymore.
911 FIXME Is it true with other errors?
912 so we remove dir from the cache
914 if (dir->d_did == DIRDID_ROOT_PARENT)
916 if (afp_errno == AFPERR_ACCESS) {
917 if ( movecwd( vol, dir->d_parent ) < 0 ) {
920 ret.m_name = dir->d_m_name;
921 ret.u_name = dir->d_u_name;
925 dir_invalidate(vol, dir);
938 while (*data == sep && len > 0 ) {
939 if ( dir->d_parent == NULL ) {
947 /* would this be faster with strlen + strncpy? */
949 while ( *data != sep && len > 0 ) {
954 /* short cut bits by chopping off a trailing \0. this also
955 makes the traversal happy w/ filenames at the end of the
962 if ( p != path ) { /* we got something */
966 if ( strcmp( cdir->d_m_name, path ) == 0 ) {
969 cdir = (cdir == dir->d_child->d_prev) ? NULL :
972 if ( cdir == NULL ) {
974 /* if dir == curdir it always succeed,
975 even if curdir is deleted.
976 it's not a pb because it will fail in extenddir
978 if ( movecwd( vol, dir ) < 0 ) {
979 /* dir is not valid anymore
980 we delete dir from the cache and abort.
982 if ( dir->d_did == DIRDID_ROOT_PARENT)
984 if (afp_errno == AFPERR_ACCESS)
986 dir_invalidate(vol, dir);
989 cdir = extenddir( vol, dir, &ret );
993 cdir = extenddir( vol, dir, &ret );
996 if ( cdir == NULL ) {
1011 * Move curdir to dir, with a possible chdir()
1013 int movecwd( vol, dir)
1014 const struct vol *vol;
1017 char path[MAXPATHLEN + 1];
1022 if ( dir == curdir ) {
1025 if ( dir->d_did == DIRDID_ROOT_PARENT) {
1026 afp_errno = AFPERR_PARAM;
1030 p = path + sizeof(path) - 1;
1033 for ( d = dir; d->d_parent != NULL && d != curdir; d = d->d_parent ) {
1036 if (p -n -1 < path) {
1037 afp_errno = AFPERR_PARAM;
1044 if ( d != curdir ) {
1045 n = strlen( vol->v_path );
1046 if (p -n -1 < path) {
1047 afp_errno = AFPERR_PARAM;
1052 strncpy( p, vol->v_path, n );
1054 if ( chdir( p ) < 0 ) {
1058 afp_errno = AFPERR_ACCESS;
1061 afp_errno = AFPERR_NOOBJ;
1071 * We can't use unix file's perm to support Apple's inherited protection modes.
1072 * If we aren't the file's owner we can't change its perms when moving it and smb
1073 * nfs,... don't even try.
1075 #define AFP_CHECK_ACCESS
1077 int check_access(char *path, int mode)
1079 #ifdef AFP_CHECK_ACCESS
1087 accessmode(p, &ma, curdir, NULL);
1088 if ((mode & OPENACC_WR) && !(ma.ma_user & AR_UWRITE))
1090 if ((mode & OPENACC_RD) && !(ma.ma_user & AR_UREAD))
1096 /* ------------------------------
1098 (name, dir) with curdir:name == dir, from afp_enumerate
1101 int getdirparams(const struct vol *vol,
1102 u_int16_t bitmap, struct path *s_path,
1104 char *buf, int *buflen )
1108 char *data, *l_nameoff = NULL, *utf_nameoff = NULL;
1109 int bit = 0, isad = 0;
1114 struct stat *st = &s_path->st;
1115 char *upath = s_path->u_name;
1117 if ((bitmap & ((1 << DIRPBIT_ATTR) |
1118 (1 << DIRPBIT_CDATE) |
1119 (1 << DIRPBIT_MDATE) |
1120 (1 << DIRPBIT_BDATE) |
1121 (1 << DIRPBIT_FINFO)))) {
1122 memset(&ad, 0, sizeof(ad));
1123 if ( !ad_open( upath, ADFLAGS_HF|ADFLAGS_DIR, O_RDONLY,
1124 DIRBITS | 0777, &ad)) {
1130 while ( bitmap != 0 ) {
1131 while (( bitmap & 1 ) == 0 ) {
1139 ad_getattr(&ad, &ashort);
1140 } else if (*upath == '.' && strcmp(upath, ".") &&
1141 strcmp(upath, "..")) {
1142 ashort = htons(ATTRBIT_INVISIBLE);
1145 ashort |= htons(ATTRBIT_SHARED);
1146 memcpy( data, &ashort, sizeof( ashort ));
1147 data += sizeof( ashort );
1151 if ( dir->d_did == DIRDID_ROOT) {
1152 aint = DIRDID_ROOT_PARENT;
1153 } else if (dir->d_did == DIRDID_ROOT_PARENT) {
1156 aint = dir->d_parent->d_did;
1158 memcpy( data, &aint, sizeof( aint ));
1159 data += sizeof( aint );
1162 case DIRPBIT_CDATE :
1163 if (!isad || (ad_getdate(&ad, AD_DATE_CREATE, &aint) < 0))
1164 aint = AD_DATE_FROM_UNIX(st->st_mtime);
1165 memcpy( data, &aint, sizeof( aint ));
1166 data += sizeof( aint );
1169 case DIRPBIT_MDATE :
1170 aint = AD_DATE_FROM_UNIX(st->st_mtime);
1171 memcpy( data, &aint, sizeof( aint ));
1172 data += sizeof( aint );
1175 case DIRPBIT_BDATE :
1176 if (!isad || (ad_getdate(&ad, AD_DATE_BACKUP, &aint) < 0))
1177 aint = AD_DATE_START;
1178 memcpy( data, &aint, sizeof( aint ));
1179 data += sizeof( aint );
1182 case DIRPBIT_FINFO :
1184 memcpy( data, ad_entry( &ad, ADEID_FINDERI ), 32 );
1185 } else { /* no appledouble */
1186 memset( data, 0, 32 );
1187 /* set default view -- this also gets done in ad_open() */
1188 ashort = htons(FINDERINFO_CLOSEDVIEW);
1189 memcpy(data + FINDERINFO_FRVIEWOFF, &ashort, sizeof(ashort));
1191 /* dot files are by default invisible */
1192 if (*upath == '.' && strcmp(upath, ".") &&
1193 strcmp(upath, "..")) {
1194 ashort = htons(FINDERINFO_INVISIBLE);
1195 memcpy(data + FINDERINFO_FRFLAGOFF,
1196 &ashort, sizeof(ashort));
1202 case DIRPBIT_LNAME :
1203 if (dir->d_m_name) /* root of parent can have a null name */
1206 memset(data, 0, sizeof(u_int16_t));
1207 data += sizeof( u_int16_t );
1210 case DIRPBIT_SNAME :
1211 memset(data, 0, sizeof(u_int16_t));
1212 data += sizeof( u_int16_t );
1216 memcpy( data, &dir->d_did, sizeof( aint ));
1217 data += sizeof( aint );
1220 case DIRPBIT_OFFCNT :
1222 /* this needs to handle current directory access rights */
1223 if (st->st_ctime == dir->ctime) {
1224 ashort = dir->offcnt;
1226 else if ((ret = for_each_dirent(vol, upath, NULL,NULL)) >= 0) {
1228 dir->offcnt = ashort;
1229 dir->ctime = st->st_ctime;
1231 ashort = htons( ashort );
1232 memcpy( data, &ashort, sizeof( ashort ));
1233 data += sizeof( ashort );
1237 aint = htonl(st->st_uid);
1238 memcpy( data, &aint, sizeof( aint ));
1239 data += sizeof( aint );
1243 aint = htonl(st->st_gid);
1244 memcpy( data, &aint, sizeof( aint ));
1245 data += sizeof( aint );
1248 case DIRPBIT_ACCESS :
1249 accessmode( upath, &ma, dir , st);
1251 *data++ = ma.ma_user;
1252 *data++ = ma.ma_world;
1253 *data++ = ma.ma_group;
1254 *data++ = ma.ma_owner;
1257 /* Client has requested the ProDOS information block.
1258 Just pass back the same basic block for all
1259 directories. <shirsch@ibm.net> */
1260 case DIRPBIT_PDINFO :
1261 if (afp_version >= 30) { /* UTF8 name */
1262 utf8 = kTextEncodingUTF8;
1263 if (dir->d_m_name) /* root of parent can have a null name */
1266 memset(data, 0, sizeof(u_int16_t));
1267 data += sizeof( u_int16_t );
1269 memcpy(data, &aint, sizeof( aint ));
1270 data += sizeof( aint );
1272 else { /* ProDOS Info Block */
1275 ashort = htons( 0x0200 );
1276 memcpy( data, &ashort, sizeof( ashort ));
1277 data += sizeof( ashort );
1278 memset( data, 0, sizeof( ashort ));
1279 data += sizeof( ashort );
1285 ad_close( &ad, ADFLAGS_HF );
1287 return( AFPERR_BITMAP );
1293 ashort = htons( data - buf );
1294 memcpy( l_nameoff, &ashort, sizeof( ashort ));
1295 data = set_name(data, dir->d_m_name, 0);
1297 if ( utf_nameoff ) {
1298 ashort = htons( data - buf );
1299 memcpy( utf_nameoff, &ashort, sizeof( ashort ));
1300 data = set_name(data, dir->d_m_name, utf8);
1303 ad_close( &ad, ADFLAGS_HF );
1305 *buflen = data - buf;
1309 /* ----------------------------- */
1310 int afp_setdirparams(obj, ibuf, ibuflen, rbuf, rbuflen )
1313 int ibuflen, *rbuflen;
1318 u_int16_t vid, bitmap;
1324 memcpy( &vid, ibuf, sizeof( vid ));
1325 ibuf += sizeof( vid );
1327 if (NULL == ( vol = getvolbyvid( vid )) ) {
1328 return( AFPERR_PARAM );
1331 if (vol->v_flags & AFPVOL_RO)
1332 return AFPERR_VLOCK;
1334 memcpy( &did, ibuf, sizeof( did ));
1335 ibuf += sizeof( int );
1337 if (NULL == ( dir = dirlookup( vol, did )) ) {
1341 memcpy( &bitmap, ibuf, sizeof( bitmap ));
1342 bitmap = ntohs( bitmap );
1343 ibuf += sizeof( bitmap );
1345 if (NULL == ( path = cname( vol, dir, &ibuf )) ) {
1349 /* FIXME access error or not a file */
1350 if ( *path->m_name != '\0' ) {
1351 return (path_isadir( path))? afp_errno:AFPERR_BADTYPE ;
1355 * If ibuf is odd, make it even.
1357 if ((u_long)ibuf & 1 ) {
1361 if (AFP_OK == ( rc = setdirparams(vol, path, bitmap, ibuf )) ) {
1362 setvoltime(obj, vol );
1368 * cf AFP3.0.pdf page 244 for change_mdate and change_parent_mdate logic
1370 * assume path == '\0' eg. it's a directory in canonical form
1373 struct path Cur_Path = {
1376 ".", /* unix name */
1377 0, /* stat is not set */
1381 int setdirparams(const struct vol *vol,
1382 struct path *path, u_int16_t bitmap, char *buf )
1390 int bit = 0, aint, isad = 1;
1391 u_int16_t ashort, bshort;
1393 int change_mdate = 0;
1394 int change_parent_mdate = 0;
1397 upath = path->u_name;
1398 memset(&ad, 0, sizeof(ad));
1400 if (ad_open( upath, vol_noadouble(vol)|ADFLAGS_HF|ADFLAGS_DIR,
1401 O_RDWR|O_CREAT, 0666, &ad) < 0) {
1403 * Check to see what we're trying to set. If it's anything
1404 * but ACCESS, UID, or GID, give an error. If it's any of those
1405 * three, we don't need the ad to be open, so just continue.
1407 * note: we also don't need to worry about mdate. also, be quiet
1408 * if we're using the noadouble option.
1410 if (!vol_noadouble(vol) && (bitmap &
1411 ~((1<<DIRPBIT_ACCESS)|(1<<DIRPBIT_UID)|(1<<DIRPBIT_GID)|
1412 (1<<DIRPBIT_MDATE)|(1<<DIRPBIT_PDINFO)))) {
1413 return AFPERR_ACCESS;
1419 * Check to see if a create was necessary. If it was, we'll want
1420 * to set our name, etc.
1422 if ( ad_getoflags( &ad, ADFLAGS_HF ) & O_CREAT ) {
1423 ad_setentrylen( &ad, ADEID_NAME, strlen( curdir->d_m_name ));
1424 memcpy( ad_entry( &ad, ADEID_NAME ), curdir->d_m_name,
1425 ad_getentrylen( &ad, ADEID_NAME ));
1429 while ( bitmap != 0 ) {
1430 while (( bitmap & 1 ) == 0 ) {
1439 memcpy( &ashort, buf, sizeof( ashort ));
1440 ad_getattr(&ad, &bshort);
1441 if ( ntohs( ashort ) & ATTRBIT_SETCLR ) {
1442 bshort |= htons( ntohs( ashort ) & ~ATTRBIT_SETCLR );
1446 ad_setattr(&ad, bshort);
1447 if ((ashort & htons(ATTRBIT_INVISIBLE)))
1448 change_parent_mdate = 1;
1450 buf += sizeof( ashort );
1453 case DIRPBIT_CDATE :
1456 memcpy(&aint, buf, sizeof(aint));
1457 ad_setdate(&ad, AD_DATE_CREATE, aint);
1459 buf += sizeof( aint );
1462 case DIRPBIT_MDATE :
1463 memcpy(&newdate, buf, sizeof(newdate));
1464 buf += sizeof( newdate );
1467 case DIRPBIT_BDATE :
1470 memcpy(&aint, buf, sizeof(aint));
1471 ad_setdate(&ad, AD_DATE_BACKUP, aint);
1473 buf += sizeof( aint );
1476 case DIRPBIT_FINFO :
1479 * Alright, we admit it, this is *really* sick!
1480 * The 4 bytes that we don't copy, when we're dealing
1481 * with the root of a volume, are the directory's
1482 * location information. This eliminates that annoying
1483 * behavior one sees when mounting above another mount
1487 if ( curdir->d_did == DIRDID_ROOT ) {
1488 memcpy( ad_entry( &ad, ADEID_FINDERI ), buf, 10 );
1489 memcpy( ad_entry( &ad, ADEID_FINDERI ) + 14, buf + 14, 18 );
1491 memcpy( ad_entry( &ad, ADEID_FINDERI ), buf, 32 );
1497 case DIRPBIT_UID : /* What kind of loser mounts as root? */
1498 change_parent_mdate = 1;
1499 memcpy( &aint, buf, sizeof(aint));
1500 buf += sizeof( aint );
1501 if ( (curdir->d_did == DIRDID_ROOT) &&
1502 (setdeskowner( ntohl(aint), -1 ) < 0)) {
1506 err = AFPERR_ACCESS;
1507 goto setdirparam_done;
1511 goto setdirparam_done;
1514 LOG(log_error, logtype_afpd, "setdirparam: setdeskowner: %s",
1518 goto setdirparam_done;
1523 if ( setdirowner( ntohl(aint), -1, vol_noadouble(vol) ) < 0 ) {
1527 err = AFPERR_ACCESS;
1528 goto setdirparam_done;
1532 goto setdirparam_done;
1535 LOG(log_error, logtype_afpd, "setdirparam: setdirowner: %s",
1542 change_parent_mdate = 1;
1543 memcpy( &aint, buf, sizeof( aint ));
1544 buf += sizeof( aint );
1545 if (curdir->d_did == DIRDID_ROOT)
1546 setdeskowner( -1, ntohl(aint) );
1548 #if 0 /* don't error if we can't set the desktop owner. */
1552 err = AFPERR_ACCESS;
1553 goto setdirparam_done;
1557 goto setdirparam_done;
1560 LOG(log_error, logtype_afpd, "setdirparam: setdeskowner: %m" );
1563 goto setdirparam_done;
1569 if ( setdirowner( -1, ntohl(aint), vol_noadouble(vol) ) < 0 ) {
1573 err = AFPERR_ACCESS;
1574 goto setdirparam_done;
1578 goto setdirparam_done;
1581 LOG(log_error, logtype_afpd, "setdirparam: setdirowner: %s",
1588 case DIRPBIT_ACCESS :
1590 change_parent_mdate = 1;
1591 ma.ma_user = *buf++;
1592 ma.ma_world = *buf++;
1593 ma.ma_group = *buf++;
1594 ma.ma_owner = *buf++;
1596 if (curdir->d_did == DIRDID_ROOT)
1597 setdeskmode(mtoumode( &ma ));
1598 #if 0 /* don't error if we can't set the desktop mode */
1602 err = AFPERR_ACCESS;
1603 goto setdirparam_done;
1606 goto setdirparam_done;
1608 LOG(log_error, logtype_afpd, "setdirparam: setdeskmode: %s",
1612 goto setdirparam_done;
1616 if ( setdirmode( mtoumode( &ma ), vol_noadouble(vol),
1617 (vol->v_flags & AFPVOL_DROPBOX)) < 0 ) {
1621 err = AFPERR_ACCESS;
1622 goto setdirparam_done;
1625 goto setdirparam_done;
1627 LOG(log_error, logtype_afpd, "setdirparam: setdirmode: %s",
1630 goto setdirparam_done;
1635 /* Ignore what the client thinks we should do to the
1636 ProDOS information block. Skip over the data and
1637 report nothing amiss. <shirsch@ibm.net> */
1638 case DIRPBIT_PDINFO :
1639 if (afp_version < 30) {
1644 err = AFPERR_BITMAP;
1645 goto setdirparam_done;
1654 if (change_mdate && newdate == 0 && gettimeofday(&tv, NULL) == 0) {
1655 newdate = AD_DATE_FROM_UNIX(tv.tv_sec);
1659 ad_setdate(&ad, AD_DATE_MODIFY, newdate);
1660 ut.actime = ut.modtime = AD_DATE_TO_UNIX(newdate);
1665 ad_flush( &ad, ADFLAGS_HF );
1666 ad_close( &ad, ADFLAGS_HF );
1669 if (change_parent_mdate && curdir->d_did != DIRDID_ROOT
1670 && gettimeofday(&tv, NULL) == 0) {
1671 if (!movecwd(vol, curdir->d_parent)) {
1672 newdate = AD_DATE_FROM_UNIX(tv.tv_sec);
1673 bitmap = 1<<DIRPBIT_MDATE;
1674 setdirparams(vol, &Cur_Path, bitmap, (char *)&newdate);
1675 /* should we reset curdir ?*/
1682 int afp_createdir(obj, ibuf, ibuflen, rbuf, rbuflen )
1685 int ibuflen, *rbuflen;
1691 struct path *s_path;
1698 memcpy( &vid, ibuf, sizeof( vid ));
1699 ibuf += sizeof( vid );
1700 if (NULL == ( vol = getvolbyvid( vid )) ) {
1701 return( AFPERR_PARAM );
1704 if (vol->v_flags & AFPVOL_RO)
1705 return AFPERR_VLOCK;
1707 memcpy( &did, ibuf, sizeof( did ));
1708 ibuf += sizeof( did );
1709 if (NULL == ( dir = dirlookup( vol, did )) ) {
1710 return afp_errno; /* was AFPERR_NOOBJ */
1713 if (NULL == ( s_path = cname( vol, dir, &ibuf )) ) {
1716 /* cname was able to move curdir to it! */
1717 if (*s_path->m_name == '\0')
1718 return AFPERR_EXIST;
1720 upath = s_path->u_name;
1723 if (0 != (ret = check_name(vol, upath))) {
1728 if ( ad_mkdir( upath, DIRBITS | 0777 ) < 0 ) {
1731 return( AFPERR_NOOBJ );
1733 return( AFPERR_VLOCK );
1735 return( AFPERR_ACCESS );
1737 return( AFPERR_EXIST );
1740 return( AFPERR_DFULL );
1742 return( AFPERR_PARAM );
1746 if (of_stat(s_path) < 0) {
1750 if ((dir = adddir( vol, curdir, s_path)) == NULL) {
1754 if ( movecwd( vol, dir ) < 0 ) {
1755 return( AFPERR_PARAM );
1758 memset(&ad, 0, sizeof(ad));
1759 if (ad_open( ".", vol_noadouble(vol)|ADFLAGS_HF|ADFLAGS_DIR,
1760 O_RDWR|O_CREAT, 0666, &ad ) < 0) {
1761 if (vol_noadouble(vol))
1762 goto createdir_done;
1763 return( AFPERR_ACCESS );
1766 ad_setentrylen( &ad, ADEID_NAME, strlen( s_path->m_name ));
1767 memcpy( ad_entry( &ad, ADEID_NAME ), s_path->m_name,
1768 ad_getentrylen( &ad, ADEID_NAME ));
1769 ad_flush( &ad, ADFLAGS_HF );
1770 ad_close( &ad, ADFLAGS_HF );
1773 memcpy( rbuf, &dir->d_did, sizeof( u_int32_t ));
1774 *rbuflen = sizeof( u_int32_t );
1775 setvoltime(obj, vol );
1780 * dst new unix filename (not a pathname)
1781 * newname new mac name
1785 int renamedir(src, dst, dir, newparent, newname, noadouble)
1786 char *src, *dst, *newname;
1787 struct dir *dir, *newparent;
1788 const int noadouble;
1795 /* existence check moved to afp_moveandrename */
1796 if ( unix_rename( src, dst ) < 0 ) {
1799 return( AFPERR_NOOBJ );
1801 return( AFPERR_ACCESS );
1803 return AFPERR_VLOCK;
1805 /* tried to move directory into a subdirectory of itself */
1806 return AFPERR_CANTMOVE;
1808 /* this needs to copy and delete. bleah. that means we have
1809 * to deal with entire directory hierarchies. */
1810 if ((err = copydir(src, dst, noadouble)) < 0) {
1814 if ((err = deletedir(src)) < 0)
1818 return( AFPERR_PARAM );
1822 memset(&ad, 0, sizeof(ad));
1823 len = strlen( newname );
1824 /* rename() succeeded so we need to update our tree even if we can't open
1827 if ( !ad_open( dst, ADFLAGS_HF|ADFLAGS_DIR, O_RDWR, 0, &ad)) {
1828 ad_setentrylen( &ad, ADEID_NAME, len );
1829 memcpy( ad_entry( &ad, ADEID_NAME ), newname, len );
1830 ad_flush( &ad, ADFLAGS_HF );
1831 ad_close( &ad, ADFLAGS_HF );
1834 if (dir->d_m_name == dir->d_u_name)
1835 dir->d_u_name = NULL;
1837 if ((buf = (char *) realloc( dir->d_m_name, len + 1 )) == NULL ) {
1838 LOG(log_error, logtype_afpd, "renamedir: realloc mac name: %s", strerror(errno) );
1839 /* FIXME : fatal ? */
1842 dir->d_m_name = buf;
1843 strcpy( dir->d_m_name, newname );
1845 if (newname == dst) {
1846 free(dir->d_u_name);
1847 dir->d_u_name = dir->d_m_name;
1850 if ((buf = (char *) realloc( dir->d_u_name, strlen(dst) + 1 )) == NULL ) {
1851 LOG(log_error, logtype_afpd, "renamedir: realloc unix name: %s", strerror(errno) );
1854 dir->d_u_name = buf;
1855 strcpy( dir->d_u_name, dst );
1858 if (( parent = dir->d_parent ) == NULL ) {
1861 if ( parent == newparent ) {
1865 /* detach from old parent and add to new one. */
1866 dirchildremove(parent, dir);
1867 dir->d_parent = newparent;
1868 dirchildadd(newparent, dir);
1872 #define DOT_APPLEDOUBLE_LEN 13
1873 /* delete an empty directory */
1874 int deletecurdir( vol, path, pathlen )
1875 const struct vol *vol;
1886 if ( curdir->d_parent == NULL ) {
1887 return( AFPERR_ACCESS );
1890 if ( curdir->d_child != NULL ) {
1891 return( AFPERR_DIRNEMPT );
1896 memset(&ad, 0, sizeof(ad));
1897 if ( ad_open( ".", ADFLAGS_HF|ADFLAGS_DIR, O_RDONLY,
1898 DIRBITS | 0777, &ad) == 0 ) {
1900 ad_getattr(&ad, &ashort);
1901 ad_close( &ad, ADFLAGS_HF );
1902 if ((ashort & htons(ATTRBIT_NODELETE))) {
1903 return AFPERR_OLOCK;
1907 /* delete stray .AppleDouble files. this happens to get .Parent files
1909 if ((dp = opendir(".AppleDouble"))) {
1910 strcpy(path, ".AppleDouble/");
1911 while ((de = readdir(dp))) {
1912 /* skip this and previous directory */
1913 if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, ".."))
1916 /* bail if the file exists in the current directory.
1917 * note: this will not fail with dangling symlinks */
1918 if (stat(de->d_name, &st) == 0) {
1920 return AFPERR_DIRNEMPT;
1923 strcpy(path + DOT_APPLEDOUBLE_LEN, de->d_name);
1924 if (unlink(path) < 0) {
1929 return( AFPERR_ACCESS );
1931 return AFPERR_VLOCK;
1935 return( AFPERR_PARAM );
1942 if ( rmdir( ".AppleDouble" ) < 0 ) {
1947 return( AFPERR_DIRNEMPT );
1949 return AFPERR_VLOCK;
1952 return( AFPERR_ACCESS );
1954 return( AFPERR_PARAM );
1958 /* now get rid of dangling symlinks */
1959 if ((dp = opendir("."))) {
1960 while ((de = readdir(dp))) {
1961 /* skip this and previous directory */
1962 if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, ".."))
1965 /* bail if it's not a symlink */
1966 if ((lstat(de->d_name, &st) == 0) && !S_ISLNK(st.st_mode)) {
1967 return AFPERR_DIRNEMPT;
1970 if (unlink(de->d_name) < 0) {
1974 return( AFPERR_ACCESS );
1976 return AFPERR_VLOCK;
1980 return( AFPERR_PARAM );
1987 if ( movecwd( vol, curdir->d_parent ) < 0 ) {
1991 if ( rmdir(fdir->d_u_name) < 0 ) {
1994 return( AFPERR_NOOBJ );
1996 return( AFPERR_DIRNEMPT );
1999 return( AFPERR_ACCESS );
2001 return AFPERR_VLOCK;
2003 return( AFPERR_PARAM );
2007 dirchildremove(curdir, fdir);
2009 cnid_delete(vol->v_db, fdir->d_did);
2010 #endif /* CNID_DB */
2011 dir_remove( vol, fdir );
2016 int afp_mapid(obj, ibuf, ibuflen, rbuf, rbuflen )
2019 int ibuflen, *rbuflen;
2029 sfunc = (unsigned char) *ibuf++;
2030 memcpy( &id, ibuf, sizeof( id ));
2038 case 3 :/* unicode */
2039 if (( pw = getpwuid( id )) == NULL ) {
2040 return( AFPERR_NOITEM );
2046 case 4 : /* unicode */
2047 if (( gr = (struct group *)getgrgid( id )) == NULL ) {
2048 return( AFPERR_NOITEM );
2054 return( AFPERR_PARAM );
2059 if (afp_version < 30) {
2060 return( AFPERR_PARAM );
2063 /* map to unicode */
2066 len = strlen( name );
2073 u_int16_t tp = htons(len);
2074 memcpy(rbuf, &tp, sizeof(tp));
2083 memcpy( rbuf, name, len );
2089 int afp_mapname(obj, ibuf, ibuflen, rbuf, rbuflen )
2092 int ibuflen, *rbuflen;
2101 sfunc = (unsigned char) *ibuf++;
2104 case 2 : /* unicode */
2105 memcpy(&ulen, ibuf, sizeof(ulen));
2111 len = (unsigned char) *ibuf++;
2115 return( AFPERR_PARAM );
2122 case 1 : /* unicode */
2124 if (( pw = (struct passwd *)getpwnam( ibuf )) == NULL ) {
2126 return( AFPERR_NOITEM );
2131 case 2 : /* unicode */
2133 if (( gr = (struct group *)getgrnam( ibuf )) == NULL ) {
2135 return( AFPERR_NOITEM );
2144 memcpy( rbuf, &id, sizeof( id ));
2145 *rbuflen = sizeof( id );
2149 /* ------------------------------------
2150 variable DID support
2152 int afp_closedir(obj, ibuf, ibuflen, rbuf, rbuflen )
2155 int ibuflen, *rbuflen;
2166 /* do nothing as dids are static for the life of the process. */
2170 memcpy(&vid, ibuf, sizeof( vid ));
2171 ibuf += sizeof( vid );
2172 if (( vol = getvolbyvid( vid )) == NULL ) {
2173 return( AFPERR_PARAM );
2176 memcpy( &did, ibuf, sizeof( did ));
2177 ibuf += sizeof( did );
2178 if (( dir = dirlookup( vol, did )) == NULL ) {
2179 return( AFPERR_PARAM );
2182 /* dir_remove -- deletedid */
2188 /* did creation gets done automatically
2189 * there's a pb again with case but move it to cname
2191 int afp_opendir(obj, ibuf, ibuflen, rbuf, rbuflen )
2194 int ibuflen, *rbuflen;
2197 struct dir *parentdir;
2205 memcpy(&vid, ibuf, sizeof(vid));
2206 ibuf += sizeof( vid );
2208 if (NULL == ( vol = getvolbyvid( vid )) ) {
2209 return( AFPERR_PARAM );
2212 memcpy(&did, ibuf, sizeof(did));
2213 ibuf += sizeof(did);
2215 if (NULL == ( parentdir = dirlookup( vol, did )) ) {
2219 if (NULL == ( path = cname( vol, parentdir, &ibuf )) ) {
2223 if ( *path->m_name != '\0' ) {
2224 return (path_isadir(path))? afp_errno:AFPERR_BADTYPE ;
2227 if ( !path->st_valid && of_stat(path ) < 0 ) {
2228 return( AFPERR_NOOBJ );
2230 if ( path->st_errno ) {
2231 return( AFPERR_NOOBJ );
2234 memcpy(rbuf, &curdir->d_did, sizeof(curdir->d_did));
2235 *rbuflen = sizeof(curdir->d_did);