2 * $Id: directory.c,v 1.64 2003-03-15 01:34:35 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 int get_afp_errno(const int param)
136 if (afp_errno != AFPERR_DID1)
141 /* ------------------- */
143 dirsearch_byname( cdir, name )
149 if (!strcmp(name, "."))
153 if ( strcmp( dir->d_u_name, name ) == 0 ) {
156 dir = (dir == curdir->d_child->d_prev) ? NULL : dir->d_next;
161 /* -----------------------------------------
162 * if did is not in the cache resolve it with cnid
166 dirlookup( vol, did )
167 const struct vol *vol;
174 static char path[MAXPATHLEN + 1];
178 static char buffer[12 + MAXPATHLEN + 1];
179 int buflen = 12 + MAXPATHLEN + 1;
182 ret = dirsearch(vol, did);
183 if (ret != NULL || afp_errno == AFPERR_PARAM)
187 if (NULL == (upath = cnid_resolve(vol->v_db, &id, buffer, buflen)) ) {
188 afp_errno = AFPERR_NOOBJ;
191 ptr = path + MAXPATHLEN;
192 if (NULL == ( mpath = utompath(vol, upath, utf8_encoding()) ) ) {
193 afp_errno = AFPERR_NOOBJ;
197 pathlen = len; /* no 0 in the last part */
199 strcpy(ptr - len, mpath);
202 ret = dirsearch(vol,id);
206 if ( NULL == (upath = cnid_resolve(vol->v_db, &id, buffer, buflen))
208 NULL == (mpath = utompath(vol, upath, utf8_encoding()))
210 afp_errno = AFPERR_NOOBJ;
214 len = strlen(mpath) + 1;
217 afp_errno = AFPERR_PARAM;
220 strcpy(ptr - len, mpath);
225 *ptr = (unsigned char)pathlen;
228 /* cname is not efficient */
229 if (cname( vol, ret, &ptr ) == NULL )
232 return dirsearch(vol, did);
235 /* --------------------------- */
236 /* rotate the tree to the left */
237 static void dir_leftrotate(vol, dir)
241 struct dir *right = dir->d_right;
243 /* whee. move the right's left tree into dir's right tree */
244 dir->d_right = right->d_left;
245 if (right->d_left != SENTINEL)
246 right->d_left->d_back = dir;
248 if (right != SENTINEL) {
249 right->d_back = dir->d_back;
253 if (!dir->d_back) /* no parent. move the right tree to the top. */
255 else if (dir == dir->d_back->d_left) /* we were on the left */
256 dir->d_back->d_left = right;
258 dir->d_back->d_right = right; /* we were on the right */
260 /* re-insert dir on the left tree */
267 /* rotate the tree to the right */
268 static void dir_rightrotate(vol, dir)
272 struct dir *left = dir->d_left;
274 /* whee. move the left's right tree into dir's left tree */
275 dir->d_left = left->d_right;
276 if (left->d_right != SENTINEL)
277 left->d_right->d_back = dir;
279 if (left != SENTINEL) {
280 left->d_back = dir->d_back;
284 if (!dir->d_back) /* no parent. move the left tree to the top. */
286 else if (dir == dir->d_back->d_right) /* we were on the right */
287 dir->d_back->d_right = left;
289 dir->d_back->d_left = left; /* we were on the left */
291 /* re-insert dir on the right tree */
297 /* recolor after a removal */
298 static struct dir *dir_rmrecolor(vol, dir)
304 while ((dir != vol->v_root) && (dir->d_color == DIRTREE_COLOR_BLACK)) {
305 /* are we on the left tree? */
306 if (dir == dir->d_back->d_left) {
307 leaf = dir->d_back->d_right; /* get right side */
308 if (leaf->d_color == DIRTREE_COLOR_RED) {
309 /* we're red. we need to change to black. */
310 leaf->d_color = DIRTREE_COLOR_BLACK;
311 dir->d_back->d_color = DIRTREE_COLOR_RED;
312 dir_leftrotate(vol, dir->d_back);
313 leaf = dir->d_back->d_right;
316 /* right leaf has black end nodes */
317 if ((leaf->d_left->d_color == DIRTREE_COLOR_BLACK) &&
318 (leaf->d_right->d_color = DIRTREE_COLOR_BLACK)) {
319 leaf->d_color = DIRTREE_COLOR_RED; /* recolor leaf as red */
320 dir = dir->d_back; /* ascend */
322 if (leaf->d_right->d_color == DIRTREE_COLOR_BLACK) {
323 leaf->d_left->d_color = DIRTREE_COLOR_BLACK;
324 leaf->d_color = DIRTREE_COLOR_RED;
325 dir_rightrotate(vol, leaf);
326 leaf = dir->d_back->d_right;
328 leaf->d_color = dir->d_back->d_color;
329 dir->d_back->d_color = DIRTREE_COLOR_BLACK;
330 leaf->d_right->d_color = DIRTREE_COLOR_BLACK;
331 dir_leftrotate(vol, dir->d_back);
334 } else { /* right tree */
335 leaf = dir->d_back->d_left; /* left tree */
336 if (leaf->d_color == DIRTREE_COLOR_RED) {
337 leaf->d_color = DIRTREE_COLOR_BLACK;
338 dir->d_back->d_color = DIRTREE_COLOR_RED;
339 dir_rightrotate(vol, dir->d_back);
340 leaf = dir->d_back->d_left;
343 /* left leaf has black end nodes */
344 if ((leaf->d_right->d_color == DIRTREE_COLOR_BLACK) &&
345 (leaf->d_left->d_color = DIRTREE_COLOR_BLACK)) {
346 leaf->d_color = DIRTREE_COLOR_RED; /* recolor leaf as red */
347 dir = dir->d_back; /* ascend */
349 if (leaf->d_left->d_color == DIRTREE_COLOR_BLACK) {
350 leaf->d_right->d_color = DIRTREE_COLOR_BLACK;
351 leaf->d_color = DIRTREE_COLOR_RED;
352 dir_leftrotate(vol, leaf);
353 leaf = dir->d_back->d_left;
355 leaf->d_color = dir->d_back->d_color;
356 dir->d_back->d_color = DIRTREE_COLOR_BLACK;
357 leaf->d_left->d_color = DIRTREE_COLOR_BLACK;
358 dir_rightrotate(vol, dir->d_back);
363 dir->d_color = DIRTREE_COLOR_BLACK;
370 /* remove the node from the tree. this is just like insertion, but
371 * different. actually, it has to worry about a bunch of things that
372 * insertion doesn't care about. */
373 static void dir_remove( vol, dir )
378 struct ofork *of, *last;
379 struct dir *node, *leaf;
380 #endif /* REMOVE_NODES */
382 if (!dir || (dir == SENTINEL))
385 /* i'm not sure if it really helps to delete stuff. */
387 if (dir->d_u_name != dir->d_m_name) {
391 dir->d_m_name = NULL;
392 dir->d_u_name = NULL;
393 #else /* ! REMOVE_NODES */
395 /* go searching for a node with at most one child */
396 if ((dir->d_left == SENTINEL) || (dir->d_right == SENTINEL)) {
400 while (node->d_left != SENTINEL)
405 leaf = (node->d_left != SENTINEL) ? node->d_left : node->d_right;
408 leaf->d_back = node->d_back;
411 } else if (node == node->d_back->d_left) { /* left tree */
412 node->d_back->d_left = leaf;
414 node->d_back->d_right = leaf;
417 /* we want to free node, but we also want to free the data in dir.
418 * currently, that's d_name and the directory traversal bits.
419 * we just copy the necessary bits and then fix up all the
420 * various pointers to the directory. needless to say, there are
421 * a bunch of places that store the directory struct. */
423 struct dir save, *tmp;
425 memcpy(&save, dir, sizeof(save));
426 memcpy(dir, node, sizeof(struct dir));
428 /* restore the red-black bits */
429 dir->d_left = save.d_left;
430 dir->d_right = save.d_right;
431 dir->d_back = save.d_back;
432 dir->d_color = save.d_color;
434 if (node == vol->v_dir) {/* we may need to fix up this pointer */
436 rootpar.d_child = vol->v_dir;
438 /* if we aren't the root directory, we have parents and
439 * siblings to worry about */
440 if (dir->d_parent->d_child == node)
441 dir->d_parent->d_child = dir;
442 dir->d_next->d_prev = dir;
443 dir->d_prev->d_next = dir;
446 /* fix up children. */
450 tmp = (tmp == dir->d_child->d_prev) ? NULL : tmp->d_next;
453 if (node == curdir) /* another pointer to fixup */
456 /* we also need to fix up oforks. bleah */
457 if ((of = dir->d_ofork)) {
458 last = of->of_d_prev;
461 of = (last == of) ? NULL : of->of_d_next;
465 /* set the node's d_name */
466 node->d_m_name = save.d_m_name;
467 node->d_u_name = save.d_u_name;
470 if (node->d_color == DIRTREE_COLOR_BLACK)
471 dir_rmrecolor(vol, leaf);
473 if (node->d_u_name != node->d_m_name) {
474 free(node->d_u_name);
476 free(node->d_m_name);
478 #endif /* ! REMOVE_NODES */
481 /* ---------------------------------------
482 * remove the node and its childs from the tree
484 * FIXME what about opened forks with refs to it?
485 * it's an afp specs violation because you can't delete
486 * an opened forks. Now afpd doesn't care about forks opened by other
487 * process. It's fixable within afpd if fnctl_lock, doable with smb and
488 * next to impossible for nfs and local filesystem access.
490 static void dir_invalidate( vol, dir )
491 const struct vol *vol;
495 /* v_root can't be deleted */
496 if (movecwd(vol, vol->v_root) < 0) {
497 LOG(log_error, logtype_afpd, "cname can't chdir to : %s", vol->v_root);
501 dirchildremove(dir->d_parent, dir);
502 dir_remove( vol, dir );
505 /* ------------------------------------ */
506 static struct dir *dir_insert(vol, dir)
507 const struct vol *vol;
513 while (pdir->d_did != dir->d_did ) {
514 if ( pdir->d_did > dir->d_did ) {
515 if ( pdir->d_left == SENTINEL ) {
522 if ( pdir->d_right == SENTINEL ) {
527 pdir = pdir->d_right;
535 * attempt to extend the current dir. tree to include path
536 * as a side-effect, movecwd to that point and return the new dir
539 extenddir( vol, dir, path )
544 path->u_name = mtoupath(vol, path->m_name, utf8_encoding() );
546 if ( path->u_name == NULL) {
547 afp_errno = AFPERR_PARAM;
550 if (of_stat( path ) != 0 ) {
554 if (!S_ISDIR(path->st.st_mode)) {
558 if (( dir = adddir( vol, dir, path)) == NULL ) {
562 if ( movecwd( vol, dir ) < 0 ) {
569 /* -------------------
570 system rmdir with afp error code.
571 ENOENT is not an error.
573 static int netatalk_rmdir(const char *name)
575 if (rmdir(name) < 0) {
580 return AFPERR_DIRNEMPT;
583 return AFPERR_ACCESS;
593 /* -------------------------
594 appledouble mkdir afp error code.
596 static int netatalk_mkdir(const char *name)
598 if (ad_mkdir(name, DIRBITS | 0777) < 0) {
601 return( AFPERR_NOOBJ );
603 return( AFPERR_VLOCK );
606 return( AFPERR_ACCESS );
608 return( AFPERR_EXIST );
611 return( AFPERR_DFULL );
613 return( AFPERR_PARAM );
619 /* -------------------
620 system unlink with afp error code.
621 ENOENT is not an error.
623 int netatalk_unlink(const char *name)
625 if (unlink(name) < 0) {
633 return AFPERR_ACCESS;
641 /* ------------------- */
642 static int deletedir(char *dir)
644 char path[MAXPATHLEN + 1];
652 if ((len = strlen(dir)) +2 > sizeof(path))
656 if ((dp = opendir(dir)) == NULL)
662 remain = sizeof(path) -len -1;
663 while ((de = readdir(dp)) && err == AFP_OK) {
664 /* skip this and previous directory */
665 if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, ".."))
668 if (strlen(de->d_name) > remain) {
672 strcpy(path + len, de->d_name);
673 if (stat(path, &st)) {
676 if (S_ISDIR(st.st_mode)) {
677 err = deletedir(path);
679 err = netatalk_unlink(path);
684 /* okay. the directory is empty. delete it. note: we already got rid
687 err = netatalk_rmdir(dir);
692 /* do a recursive copy. */
693 static int copydir(char *src, char *dst, int noadouble)
695 char spath[MAXPATHLEN + 1], dpath[MAXPATHLEN + 1];
705 /* doesn't exist or the path is too long. */
706 if (((slen = strlen(src)) > sizeof(spath) - 2) ||
707 ((dlen = strlen(dst)) > sizeof(dpath) - 2) ||
708 ((dp = opendir(src)) == NULL))
711 /* try to create the destination directory */
712 if (AFP_OK != (err = netatalk_mkdir(dst)) ) {
717 /* set things up to copy */
721 srem = sizeof(spath) - slen -1;
726 drem = sizeof(dpath) - dlen -1;
729 while ((de = readdir(dp))) {
730 /* skip this and previous directory */
731 if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, ".."))
734 if (strlen(de->d_name) > srem) {
738 strcpy(spath + slen, de->d_name);
740 if (stat(spath, &st) == 0) {
741 if (strlen(de->d_name) > drem) {
745 strcpy(dpath + dlen, de->d_name);
747 if (S_ISDIR(st.st_mode)) {
748 if (AFP_OK != (err = copydir(spath, dpath, noadouble)))
750 } else if (AFP_OK != (err = copyfile(spath, dpath, NULL, noadouble))) {
754 /* keep the same time stamp. */
755 ut.actime = ut.modtime = st.st_mtime;
761 /* keep the same time stamp. */
762 if (stat(src, &st) == 0) {
763 ut.actime = ut.modtime = st.st_mtime;
773 /* --- public functions follow --- */
775 /* NOTE: we start off with at least one node (the root directory). */
776 struct dir *dirinsert( vol, dir )
782 if ((node = dir_insert(vol, dir)))
785 /* recolor the tree. the current node is red. */
786 dir->d_color = DIRTREE_COLOR_RED;
788 /* parent of this node has to be black. if the parent node
789 * is red, then we have a grandparent. */
790 while ((dir != vol->v_root) &&
791 (dir->d_back->d_color == DIRTREE_COLOR_RED)) {
792 /* are we on the left tree? */
793 if (dir->d_back == dir->d_back->d_back->d_left) {
794 node = dir->d_back->d_back->d_right; /* get the right node */
795 if (node->d_color == DIRTREE_COLOR_RED) {
796 /* we're red. we need to change to black. */
797 dir->d_back->d_color = DIRTREE_COLOR_BLACK;
798 node->d_color = DIRTREE_COLOR_BLACK;
799 dir->d_back->d_back->d_color = DIRTREE_COLOR_RED;
800 dir = dir->d_back->d_back; /* finished. go up. */
802 if (dir == dir->d_back->d_right) {
804 dir_leftrotate(vol, dir);
806 dir->d_back->d_color = DIRTREE_COLOR_BLACK;
807 dir->d_back->d_back->d_color = DIRTREE_COLOR_RED;
808 dir_rightrotate(vol, dir->d_back->d_back);
811 node = dir->d_back->d_back->d_left;
812 if (node->d_color == DIRTREE_COLOR_RED) {
813 /* we're red. we need to change to black. */
814 dir->d_back->d_color = DIRTREE_COLOR_BLACK;
815 node->d_color = DIRTREE_COLOR_BLACK;
816 dir->d_back->d_back->d_color = DIRTREE_COLOR_RED;
817 dir = dir->d_back->d_back; /* finished. ascend */
819 if (dir == dir->d_back->d_left) {
821 dir_rightrotate(vol, dir);
823 dir->d_back->d_color = DIRTREE_COLOR_BLACK;
824 dir->d_back->d_back->d_color = DIRTREE_COLOR_RED;
825 dir_leftrotate(vol, dir->d_back->d_back);
830 vol->v_root->d_color = DIRTREE_COLOR_BLACK;
834 /* free everything down. we don't bother to recolor as this is only
835 * called to free the entire tree */
836 void dirfreename(struct dir *dir)
838 if (dir->d_u_name != dir->d_m_name) {
847 if (!dir || (dir == SENTINEL))
850 if ( dir->d_left != SENTINEL ) {
851 dirfree( dir->d_left );
853 if ( dir->d_right != SENTINEL ) {
854 dirfree( dir->d_right );
857 if (dir != SENTINEL) {
863 /* --------------------------------------------
864 * most of the time mac name and unix name are the same
866 struct dir *dirnew(const char *m_name, const char *u_name)
870 dir = (struct dir *) calloc(1, sizeof( struct dir ));
874 if ((dir->d_m_name = strdup(m_name)) == NULL) {
879 if (m_name == u_name) {
880 dir->d_u_name = dir->d_m_name;
882 else if ((dir->d_u_name = strdup(u_name)) == NULL) {
888 dir->d_left = dir->d_right = SENTINEL;
889 dir->d_next = dir->d_prev = dir;
893 /* -------------------------------------------------- */
899 stat the file or errno
902 curdir: filename parent directory
908 stat the dir or errno
912 curdir: dir parent directory
920 curdir: dir parent directory
927 cname( vol, dir, cpath )
928 const struct vol *vol;
933 static char path[ MAXPATHLEN + 1];
934 static struct path ret;
945 afp_errno = AFPERR_NOOBJ;
946 switch (ret.m_type = *data) { /* path type */
949 len = (unsigned char) *data++;
954 if (afp_version >= 30) {
956 memcpy(&hint, data, sizeof(hint));
958 data += sizeof(hint);
960 memcpy(&len16, data, sizeof(len16));
967 /* else it's an error */
969 afp_errno = AFPERR_PARAM;
973 *cpath += len + size;
980 if (movecwd( vol, dir ) < 0 ) {
982 movecwd failed some of dir path are not there anymore.
983 FIXME Is it true with other errors?
984 so we remove dir from the cache
986 if (dir->d_did == DIRDID_ROOT_PARENT)
988 if (afp_errno == AFPERR_ACCESS) {
989 if ( movecwd( vol, dir->d_parent ) < 0 ) {
992 ret.m_name = dir->d_m_name;
993 ret.u_name = dir->d_u_name;
997 dir_invalidate(vol, dir);
1000 if (*path == '\0') {
1006 if (*data == sep ) {
1010 while (*data == sep && len > 0 ) {
1011 if ( dir->d_parent == NULL ) {
1014 dir = dir->d_parent;
1019 /* would this be faster with strlen + strncpy? */
1021 while ( *data != sep && len > 0 ) {
1026 /* short cut bits by chopping off a trailing \0. this also
1027 makes the traversal happy w/ filenames at the end of the
1034 if ( p != path ) { /* we got something */
1036 cdir = dir->d_child;
1038 if ( strcmp( cdir->d_m_name, path ) == 0 ) {
1041 cdir = (cdir == dir->d_child->d_prev) ? NULL :
1044 if ( cdir == NULL ) {
1046 /* if dir == curdir it always succeed,
1047 even if curdir is deleted.
1048 it's not a pb because it will fail in extenddir
1050 if ( movecwd( vol, dir ) < 0 ) {
1051 /* dir is not valid anymore
1052 we delete dir from the cache and abort.
1054 if ( dir->d_did == DIRDID_ROOT_PARENT) {
1055 afp_errno = AFPERR_NOOBJ;
1058 if (afp_errno == AFPERR_ACCESS)
1060 dir_invalidate(vol, dir);
1063 cdir = extenddir( vol, dir, &ret );
1067 cdir = extenddir( vol, dir, &ret );
1070 if ( cdir == NULL ) {
1072 if ( len > 0 || !ret.u_name) {
1085 * Move curdir to dir, with a possible chdir()
1087 int movecwd( vol, dir)
1088 const struct vol *vol;
1091 char path[MAXPATHLEN + 1];
1096 if ( dir == curdir ) {
1099 if ( dir->d_did == DIRDID_ROOT_PARENT) {
1100 afp_errno = AFPERR_DID1; /* AFPERR_PARAM;*/
1104 p = path + sizeof(path) - 1;
1107 for ( d = dir; d->d_parent != NULL && d != curdir; d = d->d_parent ) {
1110 if (p -n -1 < path) {
1111 afp_errno = AFPERR_PARAM;
1118 if ( d != curdir ) {
1119 n = strlen( vol->v_path );
1120 if (p -n -1 < path) {
1121 afp_errno = AFPERR_PARAM;
1126 strncpy( p, vol->v_path, n );
1128 if ( chdir( p ) < 0 ) {
1132 afp_errno = AFPERR_ACCESS;
1135 afp_errno = AFPERR_NOOBJ;
1145 * We can't use unix file's perm to support Apple's inherited protection modes.
1146 * If we aren't the file's owner we can't change its perms when moving it and smb
1147 * nfs,... don't even try.
1149 #define AFP_CHECK_ACCESS
1151 int check_access(char *path, int mode)
1153 #ifdef AFP_CHECK_ACCESS
1161 accessmode(p, &ma, curdir, NULL);
1162 if ((mode & OPENACC_WR) && !(ma.ma_user & AR_UWRITE))
1164 if ((mode & OPENACC_RD) && !(ma.ma_user & AR_UREAD))
1170 /* ------------------------------
1172 (name, dir) with curdir:name == dir, from afp_enumerate
1175 int getdirparams(const struct vol *vol,
1176 u_int16_t bitmap, struct path *s_path,
1178 char *buf, int *buflen )
1182 char *data, *l_nameoff = NULL, *utf_nameoff = NULL;
1183 int bit = 0, isad = 0;
1188 struct stat *st = &s_path->st;
1189 char *upath = s_path->u_name;
1191 if ((bitmap & ((1 << DIRPBIT_ATTR) |
1192 (1 << DIRPBIT_CDATE) |
1193 (1 << DIRPBIT_MDATE) |
1194 (1 << DIRPBIT_BDATE) |
1195 (1 << DIRPBIT_FINFO)))) {
1196 memset(&ad, 0, sizeof(ad));
1197 if ( !ad_open( upath, ADFLAGS_HF|ADFLAGS_DIR, O_RDONLY,
1198 DIRBITS | 0777, &ad)) {
1204 while ( bitmap != 0 ) {
1205 while (( bitmap & 1 ) == 0 ) {
1213 ad_getattr(&ad, &ashort);
1214 } else if (*upath == '.' && strcmp(upath, ".") &&
1215 strcmp(upath, "..")) {
1216 ashort = htons(ATTRBIT_INVISIBLE);
1219 ashort |= htons(ATTRBIT_SHARED);
1220 memcpy( data, &ashort, sizeof( ashort ));
1221 data += sizeof( ashort );
1225 if ( dir->d_did == DIRDID_ROOT) {
1226 aint = DIRDID_ROOT_PARENT;
1227 } else if (dir->d_did == DIRDID_ROOT_PARENT) {
1230 aint = dir->d_parent->d_did;
1232 memcpy( data, &aint, sizeof( aint ));
1233 data += sizeof( aint );
1236 case DIRPBIT_CDATE :
1237 if (!isad || (ad_getdate(&ad, AD_DATE_CREATE, &aint) < 0))
1238 aint = AD_DATE_FROM_UNIX(st->st_mtime);
1239 memcpy( data, &aint, sizeof( aint ));
1240 data += sizeof( aint );
1243 case DIRPBIT_MDATE :
1244 aint = AD_DATE_FROM_UNIX(st->st_mtime);
1245 memcpy( data, &aint, sizeof( aint ));
1246 data += sizeof( aint );
1249 case DIRPBIT_BDATE :
1250 if (!isad || (ad_getdate(&ad, AD_DATE_BACKUP, &aint) < 0))
1251 aint = AD_DATE_START;
1252 memcpy( data, &aint, sizeof( aint ));
1253 data += sizeof( aint );
1256 case DIRPBIT_FINFO :
1258 memcpy( data, ad_entry( &ad, ADEID_FINDERI ), 32 );
1259 } else { /* no appledouble */
1260 memset( data, 0, 32 );
1261 /* set default view -- this also gets done in ad_open() */
1262 ashort = htons(FINDERINFO_CLOSEDVIEW);
1263 memcpy(data + FINDERINFO_FRVIEWOFF, &ashort, sizeof(ashort));
1265 /* dot files are by default invisible */
1266 if (*upath == '.' && strcmp(upath, ".") &&
1267 strcmp(upath, "..")) {
1268 ashort = htons(FINDERINFO_INVISIBLE);
1269 memcpy(data + FINDERINFO_FRFLAGOFF,
1270 &ashort, sizeof(ashort));
1276 case DIRPBIT_LNAME :
1277 if (dir->d_m_name) /* root of parent can have a null name */
1280 memset(data, 0, sizeof(u_int16_t));
1281 data += sizeof( u_int16_t );
1284 case DIRPBIT_SNAME :
1285 memset(data, 0, sizeof(u_int16_t));
1286 data += sizeof( u_int16_t );
1290 memcpy( data, &dir->d_did, sizeof( aint ));
1291 data += sizeof( aint );
1294 case DIRPBIT_OFFCNT :
1296 /* this needs to handle current directory access rights */
1297 if (st->st_ctime == dir->ctime) {
1298 ashort = dir->offcnt;
1300 else if ((ret = for_each_dirent(vol, upath, NULL,NULL)) >= 0) {
1302 dir->offcnt = ashort;
1303 dir->ctime = st->st_ctime;
1305 ashort = htons( ashort );
1306 memcpy( data, &ashort, sizeof( ashort ));
1307 data += sizeof( ashort );
1311 aint = htonl(st->st_uid);
1312 memcpy( data, &aint, sizeof( aint ));
1313 data += sizeof( aint );
1317 aint = htonl(st->st_gid);
1318 memcpy( data, &aint, sizeof( aint ));
1319 data += sizeof( aint );
1322 case DIRPBIT_ACCESS :
1323 accessmode( upath, &ma, dir , st);
1325 *data++ = ma.ma_user;
1326 *data++ = ma.ma_world;
1327 *data++ = ma.ma_group;
1328 *data++ = ma.ma_owner;
1331 /* Client has requested the ProDOS information block.
1332 Just pass back the same basic block for all
1333 directories. <shirsch@ibm.net> */
1334 case DIRPBIT_PDINFO :
1335 if (afp_version >= 30) { /* UTF8 name */
1336 utf8 = kTextEncodingUTF8;
1337 if (dir->d_m_name) /* root of parent can have a null name */
1340 memset(data, 0, sizeof(u_int16_t));
1341 data += sizeof( u_int16_t );
1343 memcpy(data, &aint, sizeof( aint ));
1344 data += sizeof( aint );
1346 else { /* ProDOS Info Block */
1349 ashort = htons( 0x0200 );
1350 memcpy( data, &ashort, sizeof( ashort ));
1351 data += sizeof( ashort );
1352 memset( data, 0, sizeof( ashort ));
1353 data += sizeof( ashort );
1359 ad_close( &ad, ADFLAGS_HF );
1361 return( AFPERR_BITMAP );
1367 ashort = htons( data - buf );
1368 memcpy( l_nameoff, &ashort, sizeof( ashort ));
1369 data = set_name(vol, data, dir->d_m_name, 0);
1371 if ( utf_nameoff ) {
1372 ashort = htons( data - buf );
1373 memcpy( utf_nameoff, &ashort, sizeof( ashort ));
1374 data = set_name(vol, data, dir->d_m_name, utf8);
1377 ad_close( &ad, ADFLAGS_HF );
1379 *buflen = data - buf;
1383 /* ----------------------------- */
1384 int afp_setdirparams(obj, ibuf, ibuflen, rbuf, rbuflen )
1387 int ibuflen, *rbuflen;
1392 u_int16_t vid, bitmap;
1398 memcpy( &vid, ibuf, sizeof( vid ));
1399 ibuf += sizeof( vid );
1401 if (NULL == ( vol = getvolbyvid( vid )) ) {
1402 return( AFPERR_PARAM );
1405 if (vol->v_flags & AFPVOL_RO)
1406 return AFPERR_VLOCK;
1408 memcpy( &did, ibuf, sizeof( did ));
1409 ibuf += sizeof( int );
1411 if (NULL == ( dir = dirlookup( vol, did )) ) {
1415 memcpy( &bitmap, ibuf, sizeof( bitmap ));
1416 bitmap = ntohs( bitmap );
1417 ibuf += sizeof( bitmap );
1419 if (NULL == ( path = cname( vol, dir, &ibuf )) ) {
1420 return get_afp_errno(AFPERR_NOOBJ);
1423 /* FIXME access error or not a file */
1424 if ( *path->m_name != '\0' ) {
1425 return (path_isadir( path))? afp_errno:AFPERR_BADTYPE ;
1429 * If ibuf is odd, make it even.
1431 if ((u_long)ibuf & 1 ) {
1435 if (AFP_OK == ( rc = setdirparams(vol, path, bitmap, ibuf )) ) {
1436 setvoltime(obj, vol );
1442 * cf AFP3.0.pdf page 244 for change_mdate and change_parent_mdate logic
1444 * assume path == '\0' eg. it's a directory in canonical form
1447 struct path Cur_Path = {
1450 ".", /* unix name */
1451 0, /* stat is not set */
1455 int setdirparams(const struct vol *vol,
1456 struct path *path, u_int16_t bitmap, char *buf )
1464 int bit = 0, aint, isad = 1;
1465 u_int16_t ashort, bshort;
1467 int change_mdate = 0;
1468 int change_parent_mdate = 0;
1471 upath = path->u_name;
1472 memset(&ad, 0, sizeof(ad));
1474 if (ad_open( upath, vol_noadouble(vol)|ADFLAGS_HF|ADFLAGS_DIR,
1475 O_RDWR|O_CREAT, 0666, &ad) < 0) {
1477 * Check to see what we're trying to set. If it's anything
1478 * but ACCESS, UID, or GID, give an error. If it's any of those
1479 * three, we don't need the ad to be open, so just continue.
1481 * note: we also don't need to worry about mdate. also, be quiet
1482 * if we're using the noadouble option.
1484 if (!vol_noadouble(vol) && (bitmap &
1485 ~((1<<DIRPBIT_ACCESS)|(1<<DIRPBIT_UID)|(1<<DIRPBIT_GID)|
1486 (1<<DIRPBIT_MDATE)|(1<<DIRPBIT_PDINFO)))) {
1487 return AFPERR_ACCESS;
1493 * Check to see if a create was necessary. If it was, we'll want
1494 * to set our name, etc.
1496 if ( ad_get_HF_flags( &ad ) & O_CREAT ) {
1497 ad_setentrylen( &ad, ADEID_NAME, strlen( curdir->d_m_name ));
1498 memcpy( ad_entry( &ad, ADEID_NAME ), curdir->d_m_name,
1499 ad_getentrylen( &ad, ADEID_NAME ));
1503 while ( bitmap != 0 ) {
1504 while (( bitmap & 1 ) == 0 ) {
1513 memcpy( &ashort, buf, sizeof( ashort ));
1514 ad_getattr(&ad, &bshort);
1515 if ( ntohs( ashort ) & ATTRBIT_SETCLR ) {
1516 bshort |= htons( ntohs( ashort ) & ~ATTRBIT_SETCLR );
1520 ad_setattr(&ad, bshort);
1521 if ((ashort & htons(ATTRBIT_INVISIBLE)))
1522 change_parent_mdate = 1;
1524 buf += sizeof( ashort );
1527 case DIRPBIT_CDATE :
1530 memcpy(&aint, buf, sizeof(aint));
1531 ad_setdate(&ad, AD_DATE_CREATE, aint);
1533 buf += sizeof( aint );
1536 case DIRPBIT_MDATE :
1537 memcpy(&newdate, buf, sizeof(newdate));
1538 buf += sizeof( newdate );
1541 case DIRPBIT_BDATE :
1544 memcpy(&aint, buf, sizeof(aint));
1545 ad_setdate(&ad, AD_DATE_BACKUP, aint);
1547 buf += sizeof( aint );
1550 case DIRPBIT_FINFO :
1553 * Alright, we admit it, this is *really* sick!
1554 * The 4 bytes that we don't copy, when we're dealing
1555 * with the root of a volume, are the directory's
1556 * location information. This eliminates that annoying
1557 * behavior one sees when mounting above another mount
1561 if ( curdir->d_did == DIRDID_ROOT ) {
1562 memcpy( ad_entry( &ad, ADEID_FINDERI ), buf, 10 );
1563 memcpy( ad_entry( &ad, ADEID_FINDERI ) + 14, buf + 14, 18 );
1565 memcpy( ad_entry( &ad, ADEID_FINDERI ), buf, 32 );
1571 case DIRPBIT_UID : /* What kind of loser mounts as root? */
1572 change_parent_mdate = 1;
1573 memcpy( &aint, buf, sizeof(aint));
1574 buf += sizeof( aint );
1575 if ( (curdir->d_did == DIRDID_ROOT) &&
1576 (setdeskowner( ntohl(aint), -1 ) < 0)) {
1580 err = AFPERR_ACCESS;
1581 goto setdirparam_done;
1585 goto setdirparam_done;
1588 LOG(log_error, logtype_afpd, "setdirparam: setdeskowner: %s",
1592 goto setdirparam_done;
1597 if ( setdirowner( ntohl(aint), -1, vol_noadouble(vol) ) < 0 ) {
1601 err = AFPERR_ACCESS;
1602 goto setdirparam_done;
1606 goto setdirparam_done;
1609 LOG(log_error, logtype_afpd, "setdirparam: setdirowner: %s",
1616 change_parent_mdate = 1;
1617 memcpy( &aint, buf, sizeof( aint ));
1618 buf += sizeof( aint );
1619 if (curdir->d_did == DIRDID_ROOT)
1620 setdeskowner( -1, ntohl(aint) );
1622 #if 0 /* don't error if we can't set the desktop owner. */
1626 err = AFPERR_ACCESS;
1627 goto setdirparam_done;
1631 goto setdirparam_done;
1634 LOG(log_error, logtype_afpd, "setdirparam: setdeskowner: %m" );
1637 goto setdirparam_done;
1643 if ( setdirowner( -1, ntohl(aint), vol_noadouble(vol) ) < 0 ) {
1647 err = AFPERR_ACCESS;
1648 goto setdirparam_done;
1652 goto setdirparam_done;
1655 LOG(log_error, logtype_afpd, "setdirparam: setdirowner: %s",
1662 case DIRPBIT_ACCESS :
1664 change_parent_mdate = 1;
1665 ma.ma_user = *buf++;
1666 ma.ma_world = *buf++;
1667 ma.ma_group = *buf++;
1668 ma.ma_owner = *buf++;
1670 if (curdir->d_did == DIRDID_ROOT)
1671 setdeskmode(mtoumode( &ma ));
1672 #if 0 /* don't error if we can't set the desktop mode */
1676 err = AFPERR_ACCESS;
1677 goto setdirparam_done;
1680 goto setdirparam_done;
1682 LOG(log_error, logtype_afpd, "setdirparam: setdeskmode: %s",
1686 goto setdirparam_done;
1690 if ( setdirmode( mtoumode( &ma ), vol_noadouble(vol),
1691 (vol->v_flags & AFPVOL_DROPBOX)) < 0 ) {
1695 err = AFPERR_ACCESS;
1696 goto setdirparam_done;
1699 goto setdirparam_done;
1701 LOG(log_error, logtype_afpd, "setdirparam: setdirmode: %s",
1704 goto setdirparam_done;
1709 /* Ignore what the client thinks we should do to the
1710 ProDOS information block. Skip over the data and
1711 report nothing amiss. <shirsch@ibm.net> */
1712 case DIRPBIT_PDINFO :
1713 if (afp_version < 30) {
1718 err = AFPERR_BITMAP;
1719 goto setdirparam_done;
1728 if (change_mdate && newdate == 0 && gettimeofday(&tv, NULL) == 0) {
1729 newdate = AD_DATE_FROM_UNIX(tv.tv_sec);
1733 ad_setdate(&ad, AD_DATE_MODIFY, newdate);
1734 ut.actime = ut.modtime = AD_DATE_TO_UNIX(newdate);
1739 ad_flush( &ad, ADFLAGS_HF );
1740 ad_close( &ad, ADFLAGS_HF );
1743 if (change_parent_mdate && curdir->d_did != DIRDID_ROOT
1744 && gettimeofday(&tv, NULL) == 0) {
1745 if (!movecwd(vol, curdir->d_parent)) {
1746 newdate = AD_DATE_FROM_UNIX(tv.tv_sec);
1747 bitmap = 1<<DIRPBIT_MDATE;
1748 setdirparams(vol, &Cur_Path, bitmap, (char *)&newdate);
1749 /* should we reset curdir ?*/
1756 int afp_createdir(obj, ibuf, ibuflen, rbuf, rbuflen )
1759 int ibuflen, *rbuflen;
1765 struct path *s_path;
1773 memcpy( &vid, ibuf, sizeof( vid ));
1774 ibuf += sizeof( vid );
1775 if (NULL == ( vol = getvolbyvid( vid )) ) {
1776 return( AFPERR_PARAM );
1779 if (vol->v_flags & AFPVOL_RO)
1780 return AFPERR_VLOCK;
1782 memcpy( &did, ibuf, sizeof( did ));
1783 ibuf += sizeof( did );
1784 if (NULL == ( dir = dirlookup( vol, did )) ) {
1785 return afp_errno; /* was AFPERR_NOOBJ */
1788 if (NULL == ( s_path = cname( vol, dir, &ibuf )) ) {
1789 return get_afp_errno(AFPERR_PARAM);
1791 /* cname was able to move curdir to it! */
1792 if (*s_path->m_name == '\0')
1793 return AFPERR_EXIST;
1795 upath = s_path->u_name;
1796 if (0 != (err = check_name(vol, upath))) {
1800 if (AFP_OK != (err = netatalk_mkdir( upath))) {
1804 if (of_stat(s_path) < 0) {
1808 if ((dir = adddir( vol, curdir, s_path)) == NULL) {
1812 if ( movecwd( vol, dir ) < 0 ) {
1813 return( AFPERR_PARAM );
1816 memset(&ad, 0, sizeof(ad));
1817 if (ad_open( ".", vol_noadouble(vol)|ADFLAGS_HF|ADFLAGS_DIR,
1818 O_RDWR|O_CREAT, 0666, &ad ) < 0) {
1819 if (vol_noadouble(vol))
1820 goto createdir_done;
1821 return( AFPERR_ACCESS );
1824 ad_setentrylen( &ad, ADEID_NAME, strlen( s_path->m_name ));
1825 memcpy( ad_entry( &ad, ADEID_NAME ), s_path->m_name,
1826 ad_getentrylen( &ad, ADEID_NAME ));
1827 ad_flush( &ad, ADFLAGS_HF );
1828 ad_close( &ad, ADFLAGS_HF );
1831 memcpy( rbuf, &dir->d_did, sizeof( u_int32_t ));
1832 *rbuflen = sizeof( u_int32_t );
1833 setvoltime(obj, vol );
1838 * dst new unix filename (not a pathname)
1839 * newname new mac name
1843 int renamedir(src, dst, dir, newparent, newname, noadouble)
1844 char *src, *dst, *newname;
1845 struct dir *dir, *newparent;
1846 const int noadouble;
1853 /* existence check moved to afp_moveandrename */
1854 if ( unix_rename( src, dst ) < 0 ) {
1857 return( AFPERR_NOOBJ );
1859 return( AFPERR_ACCESS );
1861 return AFPERR_VLOCK;
1863 /* tried to move directory into a subdirectory of itself */
1864 return AFPERR_CANTMOVE;
1866 /* this needs to copy and delete. bleah. that means we have
1867 * to deal with entire directory hierarchies. */
1868 if ((err = copydir(src, dst, noadouble)) < 0) {
1872 if ((err = deletedir(src)) < 0)
1876 return( AFPERR_PARAM );
1880 memset(&ad, 0, sizeof(ad));
1881 len = strlen( newname );
1882 /* rename() succeeded so we need to update our tree even if we can't open
1885 if ( !ad_open( dst, ADFLAGS_HF|ADFLAGS_DIR, O_RDWR, 0, &ad)) {
1886 ad_setentrylen( &ad, ADEID_NAME, len );
1887 memcpy( ad_entry( &ad, ADEID_NAME ), newname, len );
1888 ad_flush( &ad, ADFLAGS_HF );
1889 ad_close( &ad, ADFLAGS_HF );
1892 if (dir->d_m_name == dir->d_u_name)
1893 dir->d_u_name = NULL;
1895 if ((buf = (char *) realloc( dir->d_m_name, len + 1 )) == NULL ) {
1896 LOG(log_error, logtype_afpd, "renamedir: realloc mac name: %s", strerror(errno) );
1897 /* FIXME : fatal ? */
1900 dir->d_m_name = buf;
1901 strcpy( dir->d_m_name, newname );
1903 if (newname == dst) {
1904 free(dir->d_u_name);
1905 dir->d_u_name = dir->d_m_name;
1908 if ((buf = (char *) realloc( dir->d_u_name, strlen(dst) + 1 )) == NULL ) {
1909 LOG(log_error, logtype_afpd, "renamedir: realloc unix name: %s", strerror(errno) );
1912 dir->d_u_name = buf;
1913 strcpy( dir->d_u_name, dst );
1916 if (( parent = dir->d_parent ) == NULL ) {
1919 if ( parent == newparent ) {
1923 /* detach from old parent and add to new one. */
1924 dirchildremove(parent, dir);
1925 dir->d_parent = newparent;
1926 dirchildadd(newparent, dir);
1930 #define DOT_APPLEDOUBLE_LEN 13
1931 /* delete an empty directory */
1932 int deletecurdir( vol, path, pathlen )
1933 const struct vol *vol;
1945 if ( curdir->d_parent == NULL ) {
1946 return( AFPERR_ACCESS );
1951 memset(&ad, 0, sizeof(ad));
1952 if ( ad_open( ".", ADFLAGS_HF|ADFLAGS_DIR, O_RDONLY,
1953 DIRBITS | 0777, &ad) == 0 ) {
1955 ad_getattr(&ad, &ashort);
1956 ad_close( &ad, ADFLAGS_HF );
1957 if ((ashort & htons(ATTRBIT_NODELETE))) {
1958 return AFPERR_OLOCK;
1962 /* delete stray .AppleDouble files. this happens to get .Parent files
1964 if ((dp = opendir(".AppleDouble"))) {
1965 strcpy(path, ".AppleDouble/");
1966 while ((de = readdir(dp))) {
1967 /* skip this and previous directory */
1968 if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, ".."))
1971 /* bail if the file exists in the current directory.
1972 * note: this will not fail with dangling symlinks */
1973 if (stat(de->d_name, &st) == 0) {
1975 return AFPERR_DIRNEMPT;
1978 strcpy(path + DOT_APPLEDOUBLE_LEN, de->d_name);
1979 if ((err = netatalk_unlink(path))) {
1987 if ( (err = netatalk_rmdir( ".AppleDouble" )) ) {
1991 /* now get rid of dangling symlinks */
1992 if ((dp = opendir("."))) {
1993 while ((de = readdir(dp))) {
1994 /* skip this and previous directory */
1995 if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, ".."))
1998 /* bail if it's not a symlink */
1999 if ((lstat(de->d_name, &st) == 0) && !S_ISLNK(st.st_mode)) {
2001 return AFPERR_DIRNEMPT;
2004 if ((err = netatalk_unlink(de->d_name))) {
2011 if ( movecwd( vol, curdir->d_parent ) < 0 ) {
2016 if ( !(err = netatalk_rmdir(fdir->d_u_name))) {
2017 dirchildremove(curdir, fdir);
2019 cnid_delete(vol->v_db, fdir->d_did);
2020 #endif /* CNID_DB */
2021 dir_remove( vol, fdir );
2026 /* inode is used as key for cnid.
2027 * Close the descriptor only after cnid_delete
2035 int afp_mapid(obj, ibuf, ibuflen, rbuf, rbuflen )
2038 int ibuflen, *rbuflen;
2048 sfunc = (unsigned char) *ibuf++;
2049 memcpy( &id, ibuf, sizeof( id ));
2057 case 3 :/* unicode */
2058 if (( pw = getpwuid( id )) == NULL ) {
2059 return( AFPERR_NOITEM );
2065 case 4 : /* unicode */
2066 if (( gr = (struct group *)getgrgid( id )) == NULL ) {
2067 return( AFPERR_NOITEM );
2073 return( AFPERR_PARAM );
2078 if (afp_version < 30) {
2079 return( AFPERR_PARAM );
2082 /* map to unicode */
2085 len = strlen( name );
2092 u_int16_t tp = htons(len);
2093 memcpy(rbuf, &tp, sizeof(tp));
2102 memcpy( rbuf, name, len );
2108 int afp_mapname(obj, ibuf, ibuflen, rbuf, rbuflen )
2111 int ibuflen, *rbuflen;
2120 sfunc = (unsigned char) *ibuf++;
2123 case 2 : /* unicode */
2124 memcpy(&ulen, ibuf, sizeof(ulen));
2130 len = (unsigned char) *ibuf++;
2134 return( AFPERR_PARAM );
2141 case 1 : /* unicode */
2143 if (( pw = (struct passwd *)getpwnam( ibuf )) == NULL ) {
2145 return( AFPERR_NOITEM );
2150 case 2 : /* unicode */
2152 if (( gr = (struct group *)getgrnam( ibuf )) == NULL ) {
2154 return( AFPERR_NOITEM );
2163 memcpy( rbuf, &id, sizeof( id ));
2164 *rbuflen = sizeof( id );
2168 /* ------------------------------------
2169 variable DID support
2171 int afp_closedir(obj, ibuf, ibuflen, rbuf, rbuflen )
2174 int ibuflen, *rbuflen;
2185 /* do nothing as dids are static for the life of the process. */
2189 memcpy(&vid, ibuf, sizeof( vid ));
2190 ibuf += sizeof( vid );
2191 if (( vol = getvolbyvid( vid )) == NULL ) {
2192 return( AFPERR_PARAM );
2195 memcpy( &did, ibuf, sizeof( did ));
2196 ibuf += sizeof( did );
2197 if (( dir = dirlookup( vol, did )) == NULL ) {
2198 return( AFPERR_PARAM );
2201 /* dir_remove -- deletedid */
2207 /* did creation gets done automatically
2208 * there's a pb again with case but move it to cname
2210 int afp_opendir(obj, ibuf, ibuflen, rbuf, rbuflen )
2213 int ibuflen, *rbuflen;
2216 struct dir *parentdir;
2224 memcpy(&vid, ibuf, sizeof(vid));
2225 ibuf += sizeof( vid );
2227 if (NULL == ( vol = getvolbyvid( vid )) ) {
2228 return( AFPERR_PARAM );
2231 memcpy(&did, ibuf, sizeof(did));
2232 ibuf += sizeof(did);
2234 if (NULL == ( parentdir = dirlookup( vol, did )) ) {
2238 if (NULL == ( path = cname( vol, parentdir, &ibuf )) ) {
2239 return get_afp_errno(AFPERR_PARAM);
2242 if ( *path->m_name != '\0' ) {
2243 return (path_isadir(path))? afp_errno:AFPERR_BADTYPE ;
2246 if ( !path->st_valid && of_stat(path ) < 0 ) {
2247 return( AFPERR_NOOBJ );
2249 if ( path->st_errno ) {
2250 return( AFPERR_NOOBJ );
2253 memcpy(rbuf, &curdir->d_did, sizeof(curdir->d_did));
2254 *rbuflen = sizeof(curdir->d_did);