2 * $Id: directory.c,v 1.65 2003-03-18 00:20:27 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];
177 static char buffer[12 + MAXPATHLEN + 1];
178 int buflen = 12 + MAXPATHLEN + 1;
183 ret = dirsearch(vol, did);
184 if (ret != NULL || afp_errno == AFPERR_PARAM)
187 utf8 = utf8_encoding();
188 maxpath = (utf8)?MAXPATHLEN -7:255;
190 if (NULL == (upath = cnid_resolve(vol->v_db, &id, buffer, buflen)) ) {
191 afp_errno = AFPERR_NOOBJ;
194 ptr = path + MAXPATHLEN;
195 if (NULL == ( mpath = utompath(vol, upath, utf8) ) ) {
196 afp_errno = AFPERR_NOOBJ;
200 pathlen = len; /* no 0 in the last part */
202 strcpy(ptr - len, mpath);
205 ret = dirsearch(vol,id);
209 if ( NULL == (upath = cnid_resolve(vol->v_db, &id, buffer, buflen))
211 NULL == (mpath = utompath(vol, upath, utf8))
213 afp_errno = AFPERR_NOOBJ;
217 len = strlen(mpath) + 1;
219 if (pathlen > maxpath) {
220 afp_errno = AFPERR_PARAM;
223 strcpy(ptr - len, mpath);
227 /* fill the cache, another place where we know about the path type */
233 temp16 = htons(pathlen);
234 memcpy(ptr, &temp16, sizeof(temp16));
236 temp = htonl(kTextEncodingUTF8);
238 memcpy(ptr, &temp, sizeof(temp));
244 *ptr = (unsigned char)pathlen;
248 /* cname is not efficient */
249 if (cname( vol, ret, &ptr ) == NULL )
252 return dirsearch(vol, did);
255 /* --------------------------- */
256 /* rotate the tree to the left */
257 static void dir_leftrotate(vol, dir)
261 struct dir *right = dir->d_right;
263 /* whee. move the right's left tree into dir's right tree */
264 dir->d_right = right->d_left;
265 if (right->d_left != SENTINEL)
266 right->d_left->d_back = dir;
268 if (right != SENTINEL) {
269 right->d_back = dir->d_back;
273 if (!dir->d_back) /* no parent. move the right tree to the top. */
275 else if (dir == dir->d_back->d_left) /* we were on the left */
276 dir->d_back->d_left = right;
278 dir->d_back->d_right = right; /* we were on the right */
280 /* re-insert dir on the left tree */
287 /* rotate the tree to the right */
288 static void dir_rightrotate(vol, dir)
292 struct dir *left = dir->d_left;
294 /* whee. move the left's right tree into dir's left tree */
295 dir->d_left = left->d_right;
296 if (left->d_right != SENTINEL)
297 left->d_right->d_back = dir;
299 if (left != SENTINEL) {
300 left->d_back = dir->d_back;
304 if (!dir->d_back) /* no parent. move the left tree to the top. */
306 else if (dir == dir->d_back->d_right) /* we were on the right */
307 dir->d_back->d_right = left;
309 dir->d_back->d_left = left; /* we were on the left */
311 /* re-insert dir on the right tree */
317 /* recolor after a removal */
318 static struct dir *dir_rmrecolor(vol, dir)
324 while ((dir != vol->v_root) && (dir->d_color == DIRTREE_COLOR_BLACK)) {
325 /* are we on the left tree? */
326 if (dir == dir->d_back->d_left) {
327 leaf = dir->d_back->d_right; /* get right side */
328 if (leaf->d_color == DIRTREE_COLOR_RED) {
329 /* we're red. we need to change to black. */
330 leaf->d_color = DIRTREE_COLOR_BLACK;
331 dir->d_back->d_color = DIRTREE_COLOR_RED;
332 dir_leftrotate(vol, dir->d_back);
333 leaf = dir->d_back->d_right;
336 /* right leaf has black end nodes */
337 if ((leaf->d_left->d_color == DIRTREE_COLOR_BLACK) &&
338 (leaf->d_right->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_right->d_color == DIRTREE_COLOR_BLACK) {
343 leaf->d_left->d_color = DIRTREE_COLOR_BLACK;
344 leaf->d_color = DIRTREE_COLOR_RED;
345 dir_rightrotate(vol, leaf);
346 leaf = dir->d_back->d_right;
348 leaf->d_color = dir->d_back->d_color;
349 dir->d_back->d_color = DIRTREE_COLOR_BLACK;
350 leaf->d_right->d_color = DIRTREE_COLOR_BLACK;
351 dir_leftrotate(vol, dir->d_back);
354 } else { /* right tree */
355 leaf = dir->d_back->d_left; /* left tree */
356 if (leaf->d_color == DIRTREE_COLOR_RED) {
357 leaf->d_color = DIRTREE_COLOR_BLACK;
358 dir->d_back->d_color = DIRTREE_COLOR_RED;
359 dir_rightrotate(vol, dir->d_back);
360 leaf = dir->d_back->d_left;
363 /* left leaf has black end nodes */
364 if ((leaf->d_right->d_color == DIRTREE_COLOR_BLACK) &&
365 (leaf->d_left->d_color = DIRTREE_COLOR_BLACK)) {
366 leaf->d_color = DIRTREE_COLOR_RED; /* recolor leaf as red */
367 dir = dir->d_back; /* ascend */
369 if (leaf->d_left->d_color == DIRTREE_COLOR_BLACK) {
370 leaf->d_right->d_color = DIRTREE_COLOR_BLACK;
371 leaf->d_color = DIRTREE_COLOR_RED;
372 dir_leftrotate(vol, leaf);
373 leaf = dir->d_back->d_left;
375 leaf->d_color = dir->d_back->d_color;
376 dir->d_back->d_color = DIRTREE_COLOR_BLACK;
377 leaf->d_left->d_color = DIRTREE_COLOR_BLACK;
378 dir_rightrotate(vol, dir->d_back);
383 dir->d_color = DIRTREE_COLOR_BLACK;
390 /* remove the node from the tree. this is just like insertion, but
391 * different. actually, it has to worry about a bunch of things that
392 * insertion doesn't care about. */
393 static void dir_remove( vol, dir )
398 struct ofork *of, *last;
399 struct dir *node, *leaf;
400 #endif /* REMOVE_NODES */
402 if (!dir || (dir == SENTINEL))
405 /* i'm not sure if it really helps to delete stuff. */
407 if (dir->d_u_name != dir->d_m_name) {
411 dir->d_m_name = NULL;
412 dir->d_u_name = NULL;
413 #else /* ! REMOVE_NODES */
415 /* go searching for a node with at most one child */
416 if ((dir->d_left == SENTINEL) || (dir->d_right == SENTINEL)) {
420 while (node->d_left != SENTINEL)
425 leaf = (node->d_left != SENTINEL) ? node->d_left : node->d_right;
428 leaf->d_back = node->d_back;
431 } else if (node == node->d_back->d_left) { /* left tree */
432 node->d_back->d_left = leaf;
434 node->d_back->d_right = leaf;
437 /* we want to free node, but we also want to free the data in dir.
438 * currently, that's d_name and the directory traversal bits.
439 * we just copy the necessary bits and then fix up all the
440 * various pointers to the directory. needless to say, there are
441 * a bunch of places that store the directory struct. */
443 struct dir save, *tmp;
445 memcpy(&save, dir, sizeof(save));
446 memcpy(dir, node, sizeof(struct dir));
448 /* restore the red-black bits */
449 dir->d_left = save.d_left;
450 dir->d_right = save.d_right;
451 dir->d_back = save.d_back;
452 dir->d_color = save.d_color;
454 if (node == vol->v_dir) {/* we may need to fix up this pointer */
456 rootpar.d_child = vol->v_dir;
458 /* if we aren't the root directory, we have parents and
459 * siblings to worry about */
460 if (dir->d_parent->d_child == node)
461 dir->d_parent->d_child = dir;
462 dir->d_next->d_prev = dir;
463 dir->d_prev->d_next = dir;
466 /* fix up children. */
470 tmp = (tmp == dir->d_child->d_prev) ? NULL : tmp->d_next;
473 if (node == curdir) /* another pointer to fixup */
476 /* we also need to fix up oforks. bleah */
477 if ((of = dir->d_ofork)) {
478 last = of->of_d_prev;
481 of = (last == of) ? NULL : of->of_d_next;
485 /* set the node's d_name */
486 node->d_m_name = save.d_m_name;
487 node->d_u_name = save.d_u_name;
490 if (node->d_color == DIRTREE_COLOR_BLACK)
491 dir_rmrecolor(vol, leaf);
493 if (node->d_u_name != node->d_m_name) {
494 free(node->d_u_name);
496 free(node->d_m_name);
498 #endif /* ! REMOVE_NODES */
501 /* ---------------------------------------
502 * remove the node and its childs from the tree
504 * FIXME what about opened forks with refs to it?
505 * it's an afp specs violation because you can't delete
506 * an opened forks. Now afpd doesn't care about forks opened by other
507 * process. It's fixable within afpd if fnctl_lock, doable with smb and
508 * next to impossible for nfs and local filesystem access.
510 static void dir_invalidate( vol, dir )
511 const struct vol *vol;
515 /* v_root can't be deleted */
516 if (movecwd(vol, vol->v_root) < 0) {
517 LOG(log_error, logtype_afpd, "cname can't chdir to : %s", vol->v_root);
521 dirchildremove(dir->d_parent, dir);
522 dir_remove( vol, dir );
525 /* ------------------------------------ */
526 static struct dir *dir_insert(vol, dir)
527 const struct vol *vol;
533 while (pdir->d_did != dir->d_did ) {
534 if ( pdir->d_did > dir->d_did ) {
535 if ( pdir->d_left == SENTINEL ) {
542 if ( pdir->d_right == SENTINEL ) {
547 pdir = pdir->d_right;
555 * attempt to extend the current dir. tree to include path
556 * as a side-effect, movecwd to that point and return the new dir
559 extenddir( vol, dir, path )
564 path->u_name = mtoupath(vol, path->m_name, utf8_encoding() );
566 if ( path->u_name == NULL) {
567 afp_errno = AFPERR_PARAM;
570 if (of_stat( path ) != 0 ) {
574 if (!S_ISDIR(path->st.st_mode)) {
578 if (( dir = adddir( vol, dir, path)) == NULL ) {
582 if ( movecwd( vol, dir ) < 0 ) {
589 /* -------------------
590 system rmdir with afp error code.
591 ENOENT is not an error.
593 static int netatalk_rmdir(const char *name)
595 if (rmdir(name) < 0) {
600 return AFPERR_DIRNEMPT;
603 return AFPERR_ACCESS;
613 /* -------------------------
614 appledouble mkdir afp error code.
616 static int netatalk_mkdir(const char *name)
618 if (ad_mkdir(name, DIRBITS | 0777) < 0) {
621 return( AFPERR_NOOBJ );
623 return( AFPERR_VLOCK );
626 return( AFPERR_ACCESS );
628 return( AFPERR_EXIST );
631 return( AFPERR_DFULL );
633 return( AFPERR_PARAM );
639 /* -------------------
640 system unlink with afp error code.
641 ENOENT is not an error.
643 int netatalk_unlink(const char *name)
645 if (unlink(name) < 0) {
653 return AFPERR_ACCESS;
661 /* ------------------- */
662 static int deletedir(char *dir)
664 char path[MAXPATHLEN + 1];
672 if ((len = strlen(dir)) +2 > sizeof(path))
676 if ((dp = opendir(dir)) == NULL)
682 remain = sizeof(path) -len -1;
683 while ((de = readdir(dp)) && err == AFP_OK) {
684 /* skip this and previous directory */
685 if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, ".."))
688 if (strlen(de->d_name) > remain) {
692 strcpy(path + len, de->d_name);
693 if (stat(path, &st)) {
696 if (S_ISDIR(st.st_mode)) {
697 err = deletedir(path);
699 err = netatalk_unlink(path);
704 /* okay. the directory is empty. delete it. note: we already got rid
707 err = netatalk_rmdir(dir);
712 /* do a recursive copy. */
713 static int copydir(char *src, char *dst, int noadouble)
715 char spath[MAXPATHLEN + 1], dpath[MAXPATHLEN + 1];
725 /* doesn't exist or the path is too long. */
726 if (((slen = strlen(src)) > sizeof(spath) - 2) ||
727 ((dlen = strlen(dst)) > sizeof(dpath) - 2) ||
728 ((dp = opendir(src)) == NULL))
731 /* try to create the destination directory */
732 if (AFP_OK != (err = netatalk_mkdir(dst)) ) {
737 /* set things up to copy */
741 srem = sizeof(spath) - slen -1;
746 drem = sizeof(dpath) - dlen -1;
749 while ((de = readdir(dp))) {
750 /* skip this and previous directory */
751 if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, ".."))
754 if (strlen(de->d_name) > srem) {
758 strcpy(spath + slen, de->d_name);
760 if (stat(spath, &st) == 0) {
761 if (strlen(de->d_name) > drem) {
765 strcpy(dpath + dlen, de->d_name);
767 if (S_ISDIR(st.st_mode)) {
768 if (AFP_OK != (err = copydir(spath, dpath, noadouble)))
770 } else if (AFP_OK != (err = copyfile(spath, dpath, NULL, noadouble))) {
774 /* keep the same time stamp. */
775 ut.actime = ut.modtime = st.st_mtime;
781 /* keep the same time stamp. */
782 if (stat(src, &st) == 0) {
783 ut.actime = ut.modtime = st.st_mtime;
793 /* --- public functions follow --- */
795 /* NOTE: we start off with at least one node (the root directory). */
796 struct dir *dirinsert( vol, dir )
802 if ((node = dir_insert(vol, dir)))
805 /* recolor the tree. the current node is red. */
806 dir->d_color = DIRTREE_COLOR_RED;
808 /* parent of this node has to be black. if the parent node
809 * is red, then we have a grandparent. */
810 while ((dir != vol->v_root) &&
811 (dir->d_back->d_color == DIRTREE_COLOR_RED)) {
812 /* are we on the left tree? */
813 if (dir->d_back == dir->d_back->d_back->d_left) {
814 node = dir->d_back->d_back->d_right; /* get the right node */
815 if (node->d_color == DIRTREE_COLOR_RED) {
816 /* we're red. we need to change to black. */
817 dir->d_back->d_color = DIRTREE_COLOR_BLACK;
818 node->d_color = DIRTREE_COLOR_BLACK;
819 dir->d_back->d_back->d_color = DIRTREE_COLOR_RED;
820 dir = dir->d_back->d_back; /* finished. go up. */
822 if (dir == dir->d_back->d_right) {
824 dir_leftrotate(vol, dir);
826 dir->d_back->d_color = DIRTREE_COLOR_BLACK;
827 dir->d_back->d_back->d_color = DIRTREE_COLOR_RED;
828 dir_rightrotate(vol, dir->d_back->d_back);
831 node = dir->d_back->d_back->d_left;
832 if (node->d_color == DIRTREE_COLOR_RED) {
833 /* we're red. we need to change to black. */
834 dir->d_back->d_color = DIRTREE_COLOR_BLACK;
835 node->d_color = DIRTREE_COLOR_BLACK;
836 dir->d_back->d_back->d_color = DIRTREE_COLOR_RED;
837 dir = dir->d_back->d_back; /* finished. ascend */
839 if (dir == dir->d_back->d_left) {
841 dir_rightrotate(vol, dir);
843 dir->d_back->d_color = DIRTREE_COLOR_BLACK;
844 dir->d_back->d_back->d_color = DIRTREE_COLOR_RED;
845 dir_leftrotate(vol, dir->d_back->d_back);
850 vol->v_root->d_color = DIRTREE_COLOR_BLACK;
854 /* free everything down. we don't bother to recolor as this is only
855 * called to free the entire tree */
856 void dirfreename(struct dir *dir)
858 if (dir->d_u_name != dir->d_m_name) {
867 if (!dir || (dir == SENTINEL))
870 if ( dir->d_left != SENTINEL ) {
871 dirfree( dir->d_left );
873 if ( dir->d_right != SENTINEL ) {
874 dirfree( dir->d_right );
877 if (dir != SENTINEL) {
883 /* --------------------------------------------
884 * most of the time mac name and unix name are the same
886 struct dir *dirnew(const char *m_name, const char *u_name)
890 dir = (struct dir *) calloc(1, sizeof( struct dir ));
894 if ((dir->d_m_name = strdup(m_name)) == NULL) {
899 if (m_name == u_name) {
900 dir->d_u_name = dir->d_m_name;
902 else if ((dir->d_u_name = strdup(u_name)) == NULL) {
908 dir->d_left = dir->d_right = SENTINEL;
909 dir->d_next = dir->d_prev = dir;
913 /* -------------------------------------------------- */
919 stat the file or errno
922 curdir: filename parent directory
928 stat the dir or errno
932 curdir: dir parent directory
940 curdir: dir parent directory
947 cname( vol, dir, cpath )
948 const struct vol *vol;
953 static char path[ MAXPATHLEN + 1];
954 static struct path ret;
965 afp_errno = AFPERR_NOOBJ;
966 switch (ret.m_type = *data) { /* path type */
969 len = (unsigned char) *data++;
974 if (afp_version >= 30) {
976 memcpy(&hint, data, sizeof(hint));
978 data += sizeof(hint);
980 memcpy(&len16, data, sizeof(len16));
987 /* else it's an error */
989 afp_errno = AFPERR_PARAM;
993 *cpath += len + size;
1000 if (movecwd( vol, dir ) < 0 ) {
1002 movecwd failed some of dir path are not there anymore.
1003 FIXME Is it true with other errors?
1004 so we remove dir from the cache
1006 if (dir->d_did == DIRDID_ROOT_PARENT)
1008 if (afp_errno == AFPERR_ACCESS) {
1009 if ( movecwd( vol, dir->d_parent ) < 0 ) {
1012 ret.m_name = dir->d_m_name;
1013 ret.u_name = dir->d_u_name;
1015 } else if (afp_errno == AFPERR_NOOBJ) {
1016 if ( movecwd( vol, dir->d_parent ) < 0 ) {
1019 strcpy(path, dir->d_m_name);
1020 if (dir->d_m_name == dir->d_u_name) {
1024 size_t tp = strlen(path)+1;
1026 strcpy(path +tp, dir->d_u_name);
1027 ret.u_name = path +tp;
1030 dir_invalidate(vol, dir);
1033 dir_invalidate(vol, dir);
1036 if (*path == '\0') {
1042 if (*data == sep ) {
1046 while (*data == sep && len > 0 ) {
1047 if ( dir->d_parent == NULL ) {
1050 dir = dir->d_parent;
1055 /* would this be faster with strlen + strncpy? */
1057 while ( *data != sep && len > 0 ) {
1062 /* short cut bits by chopping off a trailing \0. this also
1063 makes the traversal happy w/ filenames at the end of the
1070 if ( p != path ) { /* we got something */
1072 cdir = dir->d_child;
1074 if ( strcmp( cdir->d_m_name, path ) == 0 ) {
1077 cdir = (cdir == dir->d_child->d_prev) ? NULL :
1080 if ( cdir == NULL ) {
1082 /* if dir == curdir it always succeed,
1083 even if curdir is deleted.
1084 it's not a pb because it will fail in extenddir
1086 if ( movecwd( vol, dir ) < 0 ) {
1087 /* dir is not valid anymore
1088 we delete dir from the cache and abort.
1090 if ( dir->d_did == DIRDID_ROOT_PARENT) {
1091 afp_errno = AFPERR_NOOBJ;
1094 if (afp_errno == AFPERR_ACCESS)
1096 dir_invalidate(vol, dir);
1099 cdir = extenddir( vol, dir, &ret );
1103 cdir = extenddir( vol, dir, &ret );
1106 if ( cdir == NULL ) {
1108 if ( len > 0 || !ret.u_name) {
1121 * Move curdir to dir, with a possible chdir()
1123 int movecwd( vol, dir)
1124 const struct vol *vol;
1127 char path[MAXPATHLEN + 1];
1132 if ( dir == curdir ) {
1135 if ( dir->d_did == DIRDID_ROOT_PARENT) {
1136 afp_errno = AFPERR_DID1; /* AFPERR_PARAM;*/
1140 p = path + sizeof(path) - 1;
1143 for ( d = dir; d->d_parent != NULL && d != curdir; d = d->d_parent ) {
1146 if (p -n -1 < path) {
1147 afp_errno = AFPERR_PARAM;
1154 if ( d != curdir ) {
1155 n = strlen( vol->v_path );
1156 if (p -n -1 < path) {
1157 afp_errno = AFPERR_PARAM;
1162 strncpy( p, vol->v_path, n );
1164 if ( chdir( p ) < 0 ) {
1168 afp_errno = AFPERR_ACCESS;
1171 afp_errno = AFPERR_NOOBJ;
1181 * We can't use unix file's perm to support Apple's inherited protection modes.
1182 * If we aren't the file's owner we can't change its perms when moving it and smb
1183 * nfs,... don't even try.
1185 #define AFP_CHECK_ACCESS
1187 int check_access(char *path, int mode)
1189 #ifdef AFP_CHECK_ACCESS
1197 accessmode(p, &ma, curdir, NULL);
1198 if ((mode & OPENACC_WR) && !(ma.ma_user & AR_UWRITE))
1200 if ((mode & OPENACC_RD) && !(ma.ma_user & AR_UREAD))
1206 /* ------------------------------
1208 (name, dir) with curdir:name == dir, from afp_enumerate
1211 int getdirparams(const struct vol *vol,
1212 u_int16_t bitmap, struct path *s_path,
1214 char *buf, int *buflen )
1218 char *data, *l_nameoff = NULL, *utf_nameoff = NULL;
1219 int bit = 0, isad = 0;
1224 struct stat *st = &s_path->st;
1225 char *upath = s_path->u_name;
1227 if ((bitmap & ((1 << DIRPBIT_ATTR) |
1228 (1 << DIRPBIT_CDATE) |
1229 (1 << DIRPBIT_MDATE) |
1230 (1 << DIRPBIT_BDATE) |
1231 (1 << DIRPBIT_FINFO)))) {
1232 memset(&ad, 0, sizeof(ad));
1233 if ( !ad_open( upath, ADFLAGS_HF|ADFLAGS_DIR, O_RDONLY,
1234 DIRBITS | 0777, &ad)) {
1240 while ( bitmap != 0 ) {
1241 while (( bitmap & 1 ) == 0 ) {
1249 ad_getattr(&ad, &ashort);
1250 } else if (*dir->d_u_name == '.' && strcmp(dir->d_u_name, ".")
1251 && strcmp(dir->d_u_name, "..")) {
1252 ashort = htons(ATTRBIT_INVISIBLE);
1255 ashort |= htons(ATTRBIT_SHARED);
1256 memcpy( data, &ashort, sizeof( ashort ));
1257 data += sizeof( ashort );
1261 if ( dir->d_did == DIRDID_ROOT) {
1262 aint = DIRDID_ROOT_PARENT;
1263 } else if (dir->d_did == DIRDID_ROOT_PARENT) {
1266 aint = dir->d_parent->d_did;
1268 memcpy( data, &aint, sizeof( aint ));
1269 data += sizeof( aint );
1272 case DIRPBIT_CDATE :
1273 if (!isad || (ad_getdate(&ad, AD_DATE_CREATE, &aint) < 0))
1274 aint = AD_DATE_FROM_UNIX(st->st_mtime);
1275 memcpy( data, &aint, sizeof( aint ));
1276 data += sizeof( aint );
1279 case DIRPBIT_MDATE :
1280 aint = AD_DATE_FROM_UNIX(st->st_mtime);
1281 memcpy( data, &aint, sizeof( aint ));
1282 data += sizeof( aint );
1285 case DIRPBIT_BDATE :
1286 if (!isad || (ad_getdate(&ad, AD_DATE_BACKUP, &aint) < 0))
1287 aint = AD_DATE_START;
1288 memcpy( data, &aint, sizeof( aint ));
1289 data += sizeof( aint );
1292 case DIRPBIT_FINFO :
1294 memcpy( data, ad_entry( &ad, ADEID_FINDERI ), 32 );
1295 } else { /* no appledouble */
1296 memset( data, 0, 32 );
1297 /* set default view -- this also gets done in ad_open() */
1298 ashort = htons(FINDERINFO_CLOSEDVIEW);
1299 memcpy(data + FINDERINFO_FRVIEWOFF, &ashort, sizeof(ashort));
1301 /* dot files are by default invisible */
1302 if (*dir->d_u_name == '.' && strcmp(dir->d_u_name , ".") &&
1303 strcmp(dir->d_u_name , "..")) {
1304 ashort = htons(FINDERINFO_INVISIBLE);
1305 memcpy(data + FINDERINFO_FRFLAGOFF,
1306 &ashort, sizeof(ashort));
1312 case DIRPBIT_LNAME :
1313 if (dir->d_m_name) /* root of parent can have a null name */
1316 memset(data, 0, sizeof(u_int16_t));
1317 data += sizeof( u_int16_t );
1320 case DIRPBIT_SNAME :
1321 memset(data, 0, sizeof(u_int16_t));
1322 data += sizeof( u_int16_t );
1326 memcpy( data, &dir->d_did, sizeof( aint ));
1327 data += sizeof( aint );
1330 case DIRPBIT_OFFCNT :
1332 /* this needs to handle current directory access rights */
1333 if (st->st_ctime == dir->ctime) {
1334 ashort = dir->offcnt;
1336 else if ((ret = for_each_dirent(vol, upath, NULL,NULL)) >= 0) {
1338 dir->offcnt = ashort;
1339 dir->ctime = st->st_ctime;
1341 ashort = htons( ashort );
1342 memcpy( data, &ashort, sizeof( ashort ));
1343 data += sizeof( ashort );
1347 aint = htonl(st->st_uid);
1348 memcpy( data, &aint, sizeof( aint ));
1349 data += sizeof( aint );
1353 aint = htonl(st->st_gid);
1354 memcpy( data, &aint, sizeof( aint ));
1355 data += sizeof( aint );
1358 case DIRPBIT_ACCESS :
1359 accessmode( upath, &ma, dir , st);
1361 *data++ = ma.ma_user;
1362 *data++ = ma.ma_world;
1363 *data++ = ma.ma_group;
1364 *data++ = ma.ma_owner;
1367 /* Client has requested the ProDOS information block.
1368 Just pass back the same basic block for all
1369 directories. <shirsch@ibm.net> */
1370 case DIRPBIT_PDINFO :
1371 if (afp_version >= 30) { /* UTF8 name */
1372 utf8 = kTextEncodingUTF8;
1373 if (dir->d_m_name) /* root of parent can have a null name */
1376 memset(data, 0, sizeof(u_int16_t));
1377 data += sizeof( u_int16_t );
1379 memcpy(data, &aint, sizeof( aint ));
1380 data += sizeof( aint );
1382 else { /* ProDOS Info Block */
1385 ashort = htons( 0x0200 );
1386 memcpy( data, &ashort, sizeof( ashort ));
1387 data += sizeof( ashort );
1388 memset( data, 0, sizeof( ashort ));
1389 data += sizeof( ashort );
1395 ad_close( &ad, ADFLAGS_HF );
1397 return( AFPERR_BITMAP );
1403 ashort = htons( data - buf );
1404 memcpy( l_nameoff, &ashort, sizeof( ashort ));
1405 data = set_name(vol, data, dir->d_m_name, 0);
1407 if ( utf_nameoff ) {
1408 ashort = htons( data - buf );
1409 memcpy( utf_nameoff, &ashort, sizeof( ashort ));
1410 data = set_name(vol, data, dir->d_m_name, utf8);
1413 ad_close( &ad, ADFLAGS_HF );
1415 *buflen = data - buf;
1419 /* ----------------------------- */
1420 int afp_setdirparams(obj, ibuf, ibuflen, rbuf, rbuflen )
1423 int ibuflen, *rbuflen;
1428 u_int16_t vid, bitmap;
1434 memcpy( &vid, ibuf, sizeof( vid ));
1435 ibuf += sizeof( vid );
1437 if (NULL == ( vol = getvolbyvid( vid )) ) {
1438 return( AFPERR_PARAM );
1441 if (vol->v_flags & AFPVOL_RO)
1442 return AFPERR_VLOCK;
1444 memcpy( &did, ibuf, sizeof( did ));
1445 ibuf += sizeof( int );
1447 if (NULL == ( dir = dirlookup( vol, did )) ) {
1451 memcpy( &bitmap, ibuf, sizeof( bitmap ));
1452 bitmap = ntohs( bitmap );
1453 ibuf += sizeof( bitmap );
1455 if (NULL == ( path = cname( vol, dir, &ibuf )) ) {
1456 return get_afp_errno(AFPERR_NOOBJ);
1459 /* FIXME access error or not a file */
1460 if ( *path->m_name != '\0' ) {
1461 return (path_isadir( path))? afp_errno:AFPERR_BADTYPE ;
1465 * If ibuf is odd, make it even.
1467 if ((u_long)ibuf & 1 ) {
1471 if (AFP_OK == ( rc = setdirparams(vol, path, bitmap, ibuf )) ) {
1472 setvoltime(obj, vol );
1478 * cf AFP3.0.pdf page 244 for change_mdate and change_parent_mdate logic
1480 * assume path == '\0' eg. it's a directory in canonical form
1483 struct path Cur_Path = {
1486 ".", /* unix name */
1487 0, /* stat is not set */
1491 int setdirparams(const struct vol *vol,
1492 struct path *path, u_int16_t bitmap, char *buf )
1500 int bit = 0, aint, isad = 1;
1501 u_int16_t ashort, bshort;
1503 int change_mdate = 0;
1504 int change_parent_mdate = 0;
1507 upath = path->u_name;
1508 memset(&ad, 0, sizeof(ad));
1510 if (ad_open( upath, vol_noadouble(vol)|ADFLAGS_HF|ADFLAGS_DIR,
1511 O_RDWR|O_CREAT, 0666, &ad) < 0) {
1513 * Check to see what we're trying to set. If it's anything
1514 * but ACCESS, UID, or GID, give an error. If it's any of those
1515 * three, we don't need the ad to be open, so just continue.
1517 * note: we also don't need to worry about mdate. also, be quiet
1518 * if we're using the noadouble option.
1520 if (!vol_noadouble(vol) && (bitmap &
1521 ~((1<<DIRPBIT_ACCESS)|(1<<DIRPBIT_UID)|(1<<DIRPBIT_GID)|
1522 (1<<DIRPBIT_MDATE)|(1<<DIRPBIT_PDINFO)))) {
1523 return AFPERR_ACCESS;
1529 * Check to see if a create was necessary. If it was, we'll want
1530 * to set our name, etc.
1532 if ( ad_get_HF_flags( &ad ) & O_CREAT ) {
1533 ad_setentrylen( &ad, ADEID_NAME, strlen( curdir->d_m_name ));
1534 memcpy( ad_entry( &ad, ADEID_NAME ), curdir->d_m_name,
1535 ad_getentrylen( &ad, ADEID_NAME ));
1539 while ( bitmap != 0 ) {
1540 while (( bitmap & 1 ) == 0 ) {
1549 memcpy( &ashort, buf, sizeof( ashort ));
1550 ad_getattr(&ad, &bshort);
1551 if ( ntohs( ashort ) & ATTRBIT_SETCLR ) {
1552 bshort |= htons( ntohs( ashort ) & ~ATTRBIT_SETCLR );
1556 ad_setattr(&ad, bshort);
1557 if ((ashort & htons(ATTRBIT_INVISIBLE)))
1558 change_parent_mdate = 1;
1560 buf += sizeof( ashort );
1563 case DIRPBIT_CDATE :
1566 memcpy(&aint, buf, sizeof(aint));
1567 ad_setdate(&ad, AD_DATE_CREATE, aint);
1569 buf += sizeof( aint );
1572 case DIRPBIT_MDATE :
1573 memcpy(&newdate, buf, sizeof(newdate));
1574 buf += sizeof( newdate );
1577 case DIRPBIT_BDATE :
1580 memcpy(&aint, buf, sizeof(aint));
1581 ad_setdate(&ad, AD_DATE_BACKUP, aint);
1583 buf += sizeof( aint );
1586 case DIRPBIT_FINFO :
1589 * Alright, we admit it, this is *really* sick!
1590 * The 4 bytes that we don't copy, when we're dealing
1591 * with the root of a volume, are the directory's
1592 * location information. This eliminates that annoying
1593 * behavior one sees when mounting above another mount
1597 if ( curdir->d_did == DIRDID_ROOT ) {
1598 memcpy( ad_entry( &ad, ADEID_FINDERI ), buf, 10 );
1599 memcpy( ad_entry( &ad, ADEID_FINDERI ) + 14, buf + 14, 18 );
1601 memcpy( ad_entry( &ad, ADEID_FINDERI ), buf, 32 );
1607 case DIRPBIT_UID : /* What kind of loser mounts as root? */
1608 change_parent_mdate = 1;
1609 memcpy( &aint, buf, sizeof(aint));
1610 buf += sizeof( aint );
1611 if ( (curdir->d_did == DIRDID_ROOT) &&
1612 (setdeskowner( ntohl(aint), -1 ) < 0)) {
1616 err = AFPERR_ACCESS;
1617 goto setdirparam_done;
1621 goto setdirparam_done;
1624 LOG(log_error, logtype_afpd, "setdirparam: setdeskowner: %s",
1628 goto setdirparam_done;
1633 if ( setdirowner( ntohl(aint), -1, vol_noadouble(vol) ) < 0 ) {
1637 err = AFPERR_ACCESS;
1638 goto setdirparam_done;
1642 goto setdirparam_done;
1645 LOG(log_error, logtype_afpd, "setdirparam: setdirowner: %s",
1652 change_parent_mdate = 1;
1653 memcpy( &aint, buf, sizeof( aint ));
1654 buf += sizeof( aint );
1655 if (curdir->d_did == DIRDID_ROOT)
1656 setdeskowner( -1, ntohl(aint) );
1658 #if 0 /* don't error if we can't set the desktop owner. */
1662 err = AFPERR_ACCESS;
1663 goto setdirparam_done;
1667 goto setdirparam_done;
1670 LOG(log_error, logtype_afpd, "setdirparam: setdeskowner: %m" );
1673 goto setdirparam_done;
1679 if ( setdirowner( -1, ntohl(aint), vol_noadouble(vol) ) < 0 ) {
1683 err = AFPERR_ACCESS;
1684 goto setdirparam_done;
1688 goto setdirparam_done;
1691 LOG(log_error, logtype_afpd, "setdirparam: setdirowner: %s",
1698 case DIRPBIT_ACCESS :
1700 change_parent_mdate = 1;
1701 ma.ma_user = *buf++;
1702 ma.ma_world = *buf++;
1703 ma.ma_group = *buf++;
1704 ma.ma_owner = *buf++;
1706 if (curdir->d_did == DIRDID_ROOT)
1707 setdeskmode(mtoumode( &ma ));
1708 #if 0 /* don't error if we can't set the desktop mode */
1712 err = AFPERR_ACCESS;
1713 goto setdirparam_done;
1716 goto setdirparam_done;
1718 LOG(log_error, logtype_afpd, "setdirparam: setdeskmode: %s",
1722 goto setdirparam_done;
1726 if ( setdirmode( mtoumode( &ma ), vol_noadouble(vol),
1727 (vol->v_flags & AFPVOL_DROPBOX)) < 0 ) {
1731 err = AFPERR_ACCESS;
1732 goto setdirparam_done;
1735 goto setdirparam_done;
1737 LOG(log_error, logtype_afpd, "setdirparam: setdirmode: %s",
1740 goto setdirparam_done;
1745 /* Ignore what the client thinks we should do to the
1746 ProDOS information block. Skip over the data and
1747 report nothing amiss. <shirsch@ibm.net> */
1748 case DIRPBIT_PDINFO :
1749 if (afp_version < 30) {
1754 err = AFPERR_BITMAP;
1755 goto setdirparam_done;
1764 if (change_mdate && newdate == 0 && gettimeofday(&tv, NULL) == 0) {
1765 newdate = AD_DATE_FROM_UNIX(tv.tv_sec);
1769 ad_setdate(&ad, AD_DATE_MODIFY, newdate);
1770 ut.actime = ut.modtime = AD_DATE_TO_UNIX(newdate);
1775 ad_flush( &ad, ADFLAGS_HF );
1776 ad_close( &ad, ADFLAGS_HF );
1779 if (change_parent_mdate && curdir->d_did != DIRDID_ROOT
1780 && gettimeofday(&tv, NULL) == 0) {
1781 if (!movecwd(vol, curdir->d_parent)) {
1782 newdate = AD_DATE_FROM_UNIX(tv.tv_sec);
1783 bitmap = 1<<DIRPBIT_MDATE;
1784 setdirparams(vol, &Cur_Path, bitmap, (char *)&newdate);
1785 /* should we reset curdir ?*/
1792 int afp_createdir(obj, ibuf, ibuflen, rbuf, rbuflen )
1795 int ibuflen, *rbuflen;
1801 struct path *s_path;
1809 memcpy( &vid, ibuf, sizeof( vid ));
1810 ibuf += sizeof( vid );
1811 if (NULL == ( vol = getvolbyvid( vid )) ) {
1812 return( AFPERR_PARAM );
1815 if (vol->v_flags & AFPVOL_RO)
1816 return AFPERR_VLOCK;
1818 memcpy( &did, ibuf, sizeof( did ));
1819 ibuf += sizeof( did );
1820 if (NULL == ( dir = dirlookup( vol, did )) ) {
1821 return afp_errno; /* was AFPERR_NOOBJ */
1823 /* for concurrent access we need to be sure we are not in the
1824 * folder we want to create...
1828 if (NULL == ( s_path = cname( vol, dir, &ibuf )) ) {
1829 return get_afp_errno(AFPERR_PARAM);
1831 /* cname was able to move curdir to it! */
1832 if (*s_path->m_name == '\0')
1833 return AFPERR_EXIST;
1835 upath = s_path->u_name;
1836 if (0 != (err = check_name(vol, upath))) {
1840 if (AFP_OK != (err = netatalk_mkdir( upath))) {
1844 if (of_stat(s_path) < 0) {
1848 if ((dir = adddir( vol, curdir, s_path)) == NULL) {
1852 if ( movecwd( vol, dir ) < 0 ) {
1853 return( AFPERR_PARAM );
1856 memset(&ad, 0, sizeof(ad));
1857 if (ad_open( ".", vol_noadouble(vol)|ADFLAGS_HF|ADFLAGS_DIR,
1858 O_RDWR|O_CREAT, 0666, &ad ) < 0) {
1859 if (vol_noadouble(vol))
1860 goto createdir_done;
1861 return( AFPERR_ACCESS );
1864 ad_setentrylen( &ad, ADEID_NAME, strlen( s_path->m_name ));
1865 memcpy( ad_entry( &ad, ADEID_NAME ), s_path->m_name,
1866 ad_getentrylen( &ad, ADEID_NAME ));
1867 ad_flush( &ad, ADFLAGS_HF );
1868 ad_close( &ad, ADFLAGS_HF );
1871 memcpy( rbuf, &dir->d_did, sizeof( u_int32_t ));
1872 *rbuflen = sizeof( u_int32_t );
1873 setvoltime(obj, vol );
1878 * dst new unix filename (not a pathname)
1879 * newname new mac name
1883 int renamedir(src, dst, dir, newparent, newname, noadouble)
1884 char *src, *dst, *newname;
1885 struct dir *dir, *newparent;
1886 const int noadouble;
1893 /* existence check moved to afp_moveandrename */
1894 if ( unix_rename( src, dst ) < 0 ) {
1897 return( AFPERR_NOOBJ );
1899 return( AFPERR_ACCESS );
1901 return AFPERR_VLOCK;
1903 /* tried to move directory into a subdirectory of itself */
1904 return AFPERR_CANTMOVE;
1906 /* this needs to copy and delete. bleah. that means we have
1907 * to deal with entire directory hierarchies. */
1908 if ((err = copydir(src, dst, noadouble)) < 0) {
1912 if ((err = deletedir(src)) < 0)
1916 return( AFPERR_PARAM );
1920 memset(&ad, 0, sizeof(ad));
1921 len = strlen( newname );
1922 /* rename() succeeded so we need to update our tree even if we can't open
1925 if ( !ad_open( dst, ADFLAGS_HF|ADFLAGS_DIR, O_RDWR, 0, &ad)) {
1926 ad_setentrylen( &ad, ADEID_NAME, len );
1927 memcpy( ad_entry( &ad, ADEID_NAME ), newname, len );
1928 ad_flush( &ad, ADFLAGS_HF );
1929 ad_close( &ad, ADFLAGS_HF );
1932 if (dir->d_m_name == dir->d_u_name)
1933 dir->d_u_name = NULL;
1935 if ((buf = (char *) realloc( dir->d_m_name, len + 1 )) == NULL ) {
1936 LOG(log_error, logtype_afpd, "renamedir: realloc mac name: %s", strerror(errno) );
1937 /* FIXME : fatal ? */
1940 dir->d_m_name = buf;
1941 strcpy( dir->d_m_name, newname );
1943 if (newname == dst) {
1944 free(dir->d_u_name);
1945 dir->d_u_name = dir->d_m_name;
1948 if ((buf = (char *) realloc( dir->d_u_name, strlen(dst) + 1 )) == NULL ) {
1949 LOG(log_error, logtype_afpd, "renamedir: realloc unix name: %s", strerror(errno) );
1952 dir->d_u_name = buf;
1953 strcpy( dir->d_u_name, dst );
1956 if (( parent = dir->d_parent ) == NULL ) {
1959 if ( parent == newparent ) {
1963 /* detach from old parent and add to new one. */
1964 dirchildremove(parent, dir);
1965 dir->d_parent = newparent;
1966 dirchildadd(newparent, dir);
1970 #define DOT_APPLEDOUBLE_LEN 13
1971 /* delete an empty directory */
1972 int deletecurdir( vol, path, pathlen )
1973 const struct vol *vol;
1985 if ( curdir->d_parent == NULL ) {
1986 return( AFPERR_ACCESS );
1991 memset(&ad, 0, sizeof(ad));
1992 if ( ad_open( ".", ADFLAGS_HF|ADFLAGS_DIR, O_RDONLY,
1993 DIRBITS | 0777, &ad) == 0 ) {
1995 ad_getattr(&ad, &ashort);
1996 ad_close( &ad, ADFLAGS_HF );
1997 if ((ashort & htons(ATTRBIT_NODELETE))) {
1998 return AFPERR_OLOCK;
2002 /* delete stray .AppleDouble files. this happens to get .Parent files
2004 if ((dp = opendir(".AppleDouble"))) {
2005 strcpy(path, ".AppleDouble/");
2006 while ((de = readdir(dp))) {
2007 /* skip this and previous directory */
2008 if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, ".."))
2011 /* bail if the file exists in the current directory.
2012 * note: this will not fail with dangling symlinks */
2013 if (stat(de->d_name, &st) == 0) {
2015 return AFPERR_DIRNEMPT;
2018 strcpy(path + DOT_APPLEDOUBLE_LEN, de->d_name);
2019 if ((err = netatalk_unlink(path))) {
2027 if ( (err = netatalk_rmdir( ".AppleDouble" )) ) {
2031 /* now get rid of dangling symlinks */
2032 if ((dp = opendir("."))) {
2033 while ((de = readdir(dp))) {
2034 /* skip this and previous directory */
2035 if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, ".."))
2038 /* bail if it's not a symlink */
2039 if ((lstat(de->d_name, &st) == 0) && !S_ISLNK(st.st_mode)) {
2041 return AFPERR_DIRNEMPT;
2044 if ((err = netatalk_unlink(de->d_name))) {
2051 if ( movecwd( vol, curdir->d_parent ) < 0 ) {
2056 if ( !(err = netatalk_rmdir(fdir->d_u_name))) {
2057 dirchildremove(curdir, fdir);
2059 cnid_delete(vol->v_db, fdir->d_did);
2060 #endif /* CNID_DB */
2061 dir_remove( vol, fdir );
2066 /* inode is used as key for cnid.
2067 * Close the descriptor only after cnid_delete
2075 int afp_mapid(obj, ibuf, ibuflen, rbuf, rbuflen )
2078 int ibuflen, *rbuflen;
2088 sfunc = (unsigned char) *ibuf++;
2089 memcpy( &id, ibuf, sizeof( id ));
2097 case 3 :/* unicode */
2098 if (( pw = getpwuid( id )) == NULL ) {
2099 return( AFPERR_NOITEM );
2105 case 4 : /* unicode */
2106 if (( gr = (struct group *)getgrgid( id )) == NULL ) {
2107 return( AFPERR_NOITEM );
2113 return( AFPERR_PARAM );
2118 if (afp_version < 30) {
2119 return( AFPERR_PARAM );
2122 /* map to unicode */
2125 len = strlen( name );
2132 u_int16_t tp = htons(len);
2133 memcpy(rbuf, &tp, sizeof(tp));
2142 memcpy( rbuf, name, len );
2148 int afp_mapname(obj, ibuf, ibuflen, rbuf, rbuflen )
2151 int ibuflen, *rbuflen;
2160 sfunc = (unsigned char) *ibuf++;
2163 case 2 : /* unicode */
2164 memcpy(&ulen, ibuf, sizeof(ulen));
2170 len = (unsigned char) *ibuf++;
2174 return( AFPERR_PARAM );
2181 case 1 : /* unicode */
2183 if (( pw = (struct passwd *)getpwnam( ibuf )) == NULL ) {
2185 return( AFPERR_NOITEM );
2190 case 2 : /* unicode */
2192 if (( gr = (struct group *)getgrnam( ibuf )) == NULL ) {
2194 return( AFPERR_NOITEM );
2203 memcpy( rbuf, &id, sizeof( id ));
2204 *rbuflen = sizeof( id );
2208 /* ------------------------------------
2209 variable DID support
2211 int afp_closedir(obj, ibuf, ibuflen, rbuf, rbuflen )
2214 int ibuflen, *rbuflen;
2225 /* do nothing as dids are static for the life of the process. */
2229 memcpy(&vid, ibuf, sizeof( vid ));
2230 ibuf += sizeof( vid );
2231 if (( vol = getvolbyvid( vid )) == NULL ) {
2232 return( AFPERR_PARAM );
2235 memcpy( &did, ibuf, sizeof( did ));
2236 ibuf += sizeof( did );
2237 if (( dir = dirlookup( vol, did )) == NULL ) {
2238 return( AFPERR_PARAM );
2241 /* dir_remove -- deletedid */
2247 /* did creation gets done automatically
2248 * there's a pb again with case but move it to cname
2250 int afp_opendir(obj, ibuf, ibuflen, rbuf, rbuflen )
2253 int ibuflen, *rbuflen;
2256 struct dir *parentdir;
2264 memcpy(&vid, ibuf, sizeof(vid));
2265 ibuf += sizeof( vid );
2267 if (NULL == ( vol = getvolbyvid( vid )) ) {
2268 return( AFPERR_PARAM );
2271 memcpy(&did, ibuf, sizeof(did));
2272 ibuf += sizeof(did);
2274 if (NULL == ( parentdir = dirlookup( vol, did )) ) {
2278 if (NULL == ( path = cname( vol, parentdir, &ibuf )) ) {
2279 return get_afp_errno(AFPERR_PARAM);
2282 if ( *path->m_name != '\0' ) {
2283 return (path_isadir(path))? afp_errno:AFPERR_BADTYPE ;
2286 if ( !path->st_valid && of_stat(path ) < 0 ) {
2287 return( AFPERR_NOOBJ );
2289 if ( path->st_errno ) {
2290 return( AFPERR_NOOBJ );
2293 memcpy(rbuf, &curdir->d_did, sizeof(curdir->d_did));
2294 *rbuflen = sizeof(curdir->d_did);