2 * $Id: directory.c,v 1.37 2002-08-22 13:41:19 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"
64 #endif /* FORCE_UIDGID */
68 #define SENTINEL (&sentinel)
69 static struct dir sentinel = { SENTINEL, SENTINEL, NULL, DIRTREE_COLOR_BLACK,
70 NULL, NULL, NULL, NULL, NULL, 0, 0, NULL };
71 static struct dir rootpar = { SENTINEL, SENTINEL, NULL, 0,
72 NULL, NULL, NULL, NULL, NULL, 0, 0, NULL };
74 /* (from IM: Toolbox Essentials)
75 * dirFinderInfo (DInfo) fields:
77 * frRect 8 folder's window rectangle
79 * frLocation 4 folder's location in window
80 * frView 2 folder's view (default == closedView (256))
82 * extended dirFinderInfo (DXInfo) fields:
83 * frScroll 4 scroll position
84 * frOpenChain: 4 directory ID chain of open folders
85 * frScript: 1 script flag and code
86 * frXFlags: 1 reserved
87 * frComment: 2 comment ID
88 * frPutAway: 4 home directory ID
92 * redid did assignment for directories. now we use red-black trees.
97 const struct vol *vol;
103 /* check for 0 did */
107 if ( did == DIRDID_ROOT_PARENT ) {
109 rootpar.d_did = DIRDID_ROOT_PARENT;
110 rootpar.d_child = vol->v_dir;
115 while ( dir != SENTINEL ) {
116 if (dir->d_did == did)
117 return dir->d_name ? dir : NULL;
118 dir = (dir->d_did > did) ? dir->d_left : dir->d_right;
123 /* -----------------------------------------
124 * if did is not in the cache resolve it with cnid
128 dirlookup( vol, did )
129 const struct vol *vol;
136 static char path[MAXPATHLEN + 1];
140 static char buffer[12 + MAXPATHLEN + 1];
141 int buflen = 12 + MAXPATHLEN + 1;
143 ret = dirsearch(vol, did);
148 if ((upath = cnid_resolve(vol->v_db, &id, buffer, buflen)) == NULL) {
151 ptr = path + MAXPATHLEN;
153 pathlen = len; /* no 0 in the last part */
155 strcpy(ptr - len, upath);
158 ret = dirsearch(vol,id);
162 if ((upath = cnid_resolve(vol->v_db, &id, buffer, buflen)) == NULL)
164 len = strlen(upath) + 1;
168 strcpy(ptr - len, upath);
173 *ptr = (unsigned char)pathlen;
176 /* cname is not efficient */
177 if (cname( vol, ret, &ptr ) == NULL )
180 return dirsearch(vol, did);
183 /* --------------------------- */
184 /* rotate the tree to the left */
185 static void dir_leftrotate(vol, dir)
189 struct dir *right = dir->d_right;
191 /* whee. move the right's left tree into dir's right tree */
192 dir->d_right = right->d_left;
193 if (right->d_left != SENTINEL)
194 right->d_left->d_back = dir;
196 if (right != SENTINEL) {
197 right->d_back = dir->d_back;
201 if (!dir->d_back) /* no parent. move the right tree to the top. */
203 else if (dir == dir->d_back->d_left) /* we were on the left */
204 dir->d_back->d_left = right;
206 dir->d_back->d_right = right; /* we were on the right */
208 /* re-insert dir on the left tree */
215 /* rotate the tree to the right */
216 static void dir_rightrotate(vol, dir)
220 struct dir *left = dir->d_left;
222 /* whee. move the left's right tree into dir's left tree */
223 dir->d_left = left->d_right;
224 if (left->d_right != SENTINEL)
225 left->d_right->d_back = dir;
227 if (left != SENTINEL) {
228 left->d_back = dir->d_back;
232 if (!dir->d_back) /* no parent. move the left tree to the top. */
234 else if (dir == dir->d_back->d_right) /* we were on the right */
235 dir->d_back->d_right = left;
237 dir->d_back->d_left = left; /* we were on the left */
239 /* re-insert dir on the right tree */
245 /* recolor after a removal */
246 static struct dir *dir_rmrecolor(vol, dir)
252 while ((dir != vol->v_root) && (dir->d_color == DIRTREE_COLOR_BLACK)) {
253 /* are we on the left tree? */
254 if (dir == dir->d_back->d_left) {
255 leaf = dir->d_back->d_right; /* get right side */
256 if (leaf->d_color == DIRTREE_COLOR_RED) {
257 /* we're red. we need to change to black. */
258 leaf->d_color = DIRTREE_COLOR_BLACK;
259 dir->d_back->d_color = DIRTREE_COLOR_RED;
260 dir_leftrotate(vol, dir->d_back);
261 leaf = dir->d_back->d_right;
264 /* right leaf has black end nodes */
265 if ((leaf->d_left->d_color == DIRTREE_COLOR_BLACK) &&
266 (leaf->d_right->d_color = DIRTREE_COLOR_BLACK)) {
267 leaf->d_color = DIRTREE_COLOR_RED; /* recolor leaf as red */
268 dir = dir->d_back; /* ascend */
270 if (leaf->d_right->d_color == DIRTREE_COLOR_BLACK) {
271 leaf->d_left->d_color = DIRTREE_COLOR_BLACK;
272 leaf->d_color = DIRTREE_COLOR_RED;
273 dir_rightrotate(vol, leaf);
274 leaf = dir->d_back->d_right;
276 leaf->d_color = dir->d_back->d_color;
277 dir->d_back->d_color = DIRTREE_COLOR_BLACK;
278 leaf->d_right->d_color = DIRTREE_COLOR_BLACK;
279 dir_leftrotate(vol, dir->d_back);
282 } else { /* right tree */
283 leaf = dir->d_back->d_left; /* left tree */
284 if (leaf->d_color == DIRTREE_COLOR_RED) {
285 leaf->d_color = DIRTREE_COLOR_BLACK;
286 dir->d_back->d_color = DIRTREE_COLOR_RED;
287 dir_rightrotate(vol, dir->d_back);
288 leaf = dir->d_back->d_left;
291 /* left leaf has black end nodes */
292 if ((leaf->d_right->d_color == DIRTREE_COLOR_BLACK) &&
293 (leaf->d_left->d_color = DIRTREE_COLOR_BLACK)) {
294 leaf->d_color = DIRTREE_COLOR_RED; /* recolor leaf as red */
295 dir = dir->d_back; /* ascend */
297 if (leaf->d_left->d_color == DIRTREE_COLOR_BLACK) {
298 leaf->d_right->d_color = DIRTREE_COLOR_BLACK;
299 leaf->d_color = DIRTREE_COLOR_RED;
300 dir_leftrotate(vol, leaf);
301 leaf = dir->d_back->d_left;
303 leaf->d_color = dir->d_back->d_color;
304 dir->d_back->d_color = DIRTREE_COLOR_BLACK;
305 leaf->d_left->d_color = DIRTREE_COLOR_BLACK;
306 dir_rightrotate(vol, dir->d_back);
311 dir->d_color = DIRTREE_COLOR_BLACK;
318 /* remove the node from the tree. this is just like insertion, but
319 * different. actually, it has to worry about a bunch of things that
320 * insertion doesn't care about. */
321 static void dir_remove( vol, dir )
326 struct ofork *of, *last;
327 struct dir *node, *leaf;
328 #endif /* REMOVE_NODES */
330 if (!dir || (dir == SENTINEL))
333 /* i'm not sure if it really helps to delete stuff. */
337 #else /* ! REMOVE_NODES */
339 /* go searching for a node with at most one child */
340 if ((dir->d_left == SENTINEL) || (dir->d_right == SENTINEL)) {
344 while (node->d_left != SENTINEL)
349 leaf = (node->d_left != SENTINEL) ? node->d_left : node->d_right;
352 leaf->d_back = node->d_back;
355 } else if (node == node->d_back->d_left) { /* left tree */
356 node->d_back->d_left = leaf;
358 node->d_back->d_right = leaf;
361 /* we want to free node, but we also want to free the data in dir.
362 * currently, that's d_name and the directory traversal bits.
363 * we just copy the necessary bits and then fix up all the
364 * various pointers to the directory. needless to say, there are
365 * a bunch of places that store the directory struct. */
367 struct dir save, *tmp;
369 memcpy(&save, dir, sizeof(save));
370 memcpy(dir, node, sizeof(struct dir));
372 /* restore the red-black bits */
373 dir->d_left = save.d_left;
374 dir->d_right = save.d_right;
375 dir->d_back = save.d_back;
376 dir->d_color = save.d_color;
378 if (node == vol->v_dir) {/* we may need to fix up this pointer */
380 rootpar.d_child = vol->v_dir;
382 /* if we aren't the root directory, we have parents and
383 * siblings to worry about */
384 if (dir->d_parent->d_child == node)
385 dir->d_parent->d_child = dir;
386 dir->d_next->d_prev = dir;
387 dir->d_prev->d_next = dir;
390 /* fix up children. */
394 tmp = (tmp == dir->d_child->d_prev) ? NULL : tmp->d_next;
397 if (node == curdir) /* another pointer to fixup */
400 /* we also need to fix up oforks. bleah */
401 if ((of = dir->d_ofork)) {
402 last = of->of_d_prev;
405 of = (last == of) ? NULL : of->of_d_next;
409 /* set the node's d_name */
410 node->d_name = save.d_name;
413 if (node->d_color == DIRTREE_COLOR_BLACK)
414 dir_rmrecolor(vol, leaf);
417 #endif /* ! REMOVE_NODES */
420 /* ---------------------------------------
421 * remove the node and its childs from the tree
423 * FIXME what about opened forks with refs to it?
424 * it's an afp specs violation because you can't delete
425 * an opened forks. Now afpd doesn't care about forks opened by other
426 * process. It's fixable within afpd if fnctl_lock, doable with smb and
427 * next to impossible for nfs and local filesystem access.
430 static void dir_invalidate( vol, dir )
431 const struct vol *vol;
435 /* v_root can't be deleted */
436 if (movecwd(vol, vol->v_root) < 0)
437 printf("Yuup cant change dir to v_root\n");
440 dirchildremove(dir->d_parent, dir);
441 dir_remove( vol, dir );
444 /* ------------------------------------ */
445 static struct dir *dir_insert(vol, dir)
446 const struct vol *vol;
452 while (pdir->d_did != dir->d_did ) {
453 if ( pdir->d_did > dir->d_did ) {
454 if ( pdir->d_left == SENTINEL ) {
461 if ( pdir->d_right == SENTINEL ) {
466 pdir = pdir->d_right;
474 * attempt to extend the current dir. tree to include path
475 * as a side-effect, movecwd to that point and return the new dir
479 extenddir( vol, dir, path )
487 p = mtoupath(vol, path );
488 if ( stat( p, &st ) != 0 ) {
491 if (!S_ISDIR(st.st_mode)) {
495 if (( dir = adddir( vol, dir, path, strlen( path ), p, strlen(p),
500 if ( movecwd( vol, dir ) < 0 ) {
507 static int deletedir(char *dir)
509 char path[MAXPATHLEN + 1];
515 if ((len = strlen(dir)) > sizeof(path))
519 if ((dp = opendir(dir)) == NULL)
525 while ((de = readdir(dp))) {
526 /* skip this and previous directory */
527 if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, ".."))
530 strncpy(path + len, de->d_name, sizeof(path) - len);
531 if (stat(path, &st) == 0) {
532 if (S_ISDIR(st.st_mode)) {
533 if ((err = deletedir(path)) < 0) {
537 } else if (unlink(path) < 0) {
540 continue; /* somebody went and deleted it behind our backs. */
558 /* okay. the directory is empty. delete it. note: we already got rid
560 if (rmdir(dir) < 0) {
564 case ENOTEMPTY : /* should never happen */
565 return( AFPERR_DIRNEMPT );
568 return( AFPERR_ACCESS );
572 return( AFPERR_PARAM );
578 /* do a recursive copy. */
579 static int copydir(char *src, char *dst, int noadouble)
581 char spath[MAXPATHLEN + 1], dpath[MAXPATHLEN + 1];
588 /* doesn't exist or the path is too long. */
589 if (((slen = strlen(src)) > sizeof(spath) - 2) ||
590 ((dlen = strlen(dst)) > sizeof(dpath) - 2) ||
591 ((dp = opendir(src)) == NULL))
594 /* try to create the destination directory */
595 if (ad_mkdir(dst, DIRBITS | 0777) < 0) {
599 return( AFPERR_NOOBJ );
601 return( AFPERR_VLOCK );
604 return( AFPERR_ACCESS );
606 return( AFPERR_EXIST );
609 return( AFPERR_DFULL );
611 return( AFPERR_PARAM );
615 /* set things up to copy */
623 while ((de = readdir(dp))) {
624 /* skip this and previous directory */
625 if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, ".."))
628 strncpy(spath + slen, de->d_name, sizeof(spath) - slen);
629 if (stat(spath, &st) == 0) {
630 strncpy(dpath + dlen, de->d_name, sizeof(dpath) - dlen);
632 if (S_ISDIR(st.st_mode)) {
633 if ((err = copydir(spath, dpath, noadouble)) < 0)
635 } else if ((err = copyfile(spath, dpath, NULL, noadouble)) < 0) {
639 /* keep the same time stamp. */
640 ut.actime = ut.modtime = st.st_mtime;
646 /* keep the same time stamp. */
647 if (stat(src, &st) == 0) {
648 ut.actime = ut.modtime = st.st_mtime;
658 /* --- public functions follow --- */
660 /* NOTE: we start off with at least one node (the root directory). */
661 struct dir *dirinsert( vol, dir )
667 if ((node = dir_insert(vol, dir)))
670 /* recolor the tree. the current node is red. */
671 dir->d_color = DIRTREE_COLOR_RED;
673 /* parent of this node has to be black. if the parent node
674 * is red, then we have a grandparent. */
675 while ((dir != vol->v_root) &&
676 (dir->d_back->d_color == DIRTREE_COLOR_RED)) {
677 /* are we on the left tree? */
678 if (dir->d_back == dir->d_back->d_back->d_left) {
679 node = dir->d_back->d_back->d_right; /* get the right node */
680 if (node->d_color == DIRTREE_COLOR_RED) {
681 /* we're red. we need to change to black. */
682 dir->d_back->d_color = DIRTREE_COLOR_BLACK;
683 node->d_color = DIRTREE_COLOR_BLACK;
684 dir->d_back->d_back->d_color = DIRTREE_COLOR_RED;
685 dir = dir->d_back->d_back; /* finished. go up. */
687 if (dir == dir->d_back->d_right) {
689 dir_leftrotate(vol, dir);
691 dir->d_back->d_color = DIRTREE_COLOR_BLACK;
692 dir->d_back->d_back->d_color = DIRTREE_COLOR_RED;
693 dir_rightrotate(vol, dir->d_back->d_back);
696 node = dir->d_back->d_back->d_left;
697 if (node->d_color == DIRTREE_COLOR_RED) {
698 /* we're red. we need to change to black. */
699 dir->d_back->d_color = DIRTREE_COLOR_BLACK;
700 node->d_color = DIRTREE_COLOR_BLACK;
701 dir->d_back->d_back->d_color = DIRTREE_COLOR_RED;
702 dir = dir->d_back->d_back; /* finished. ascend */
704 if (dir == dir->d_back->d_left) {
706 dir_rightrotate(vol, dir);
708 dir->d_back->d_color = DIRTREE_COLOR_BLACK;
709 dir->d_back->d_back->d_color = DIRTREE_COLOR_RED;
710 dir_leftrotate(vol, dir->d_back->d_back);
715 vol->v_root->d_color = DIRTREE_COLOR_BLACK;
719 /* free everything down. we don't bother to recolor as this is only
720 * called to free the entire tree */
724 if (!dir || (dir == SENTINEL))
727 if ( dir->d_left != SENTINEL ) {
728 dirfree( dir->d_left );
730 if ( dir->d_right != SENTINEL ) {
731 dirfree( dir->d_right );
734 if (dir != SENTINEL) {
741 struct dir *dirnew(const int len)
745 dir = (struct dir *) calloc(1, sizeof( struct dir ));
749 if ((dir->d_name = (char *) malloc(sizeof(char)*len)) == NULL) {
754 dir->d_left = dir->d_right = SENTINEL;
755 dir->d_next = dir->d_prev = dir;
760 /* XXX: this needs to be changed to handle path types */
762 cname( vol, dir, cpath )
763 const struct vol *vol;
768 static char path[ MAXPATHLEN + 1];
776 if ( *data++ != 2 ) { /* path type */
779 len = (unsigned char) *data++;
786 if ( !extend && movecwd( vol, dir ) < 0 ) {
788 movecwd failed so dir is not there anymore.
789 FIXME Is it true with other errors?
790 if path == '\0' ==> the cpath parameter is that dir,
791 and maybe we are trying to recreate it! So we can't
795 if ( dir->d_did == DIRDID_ROOT_PARENT)
797 cdir = dir->d_parent;
798 dir_invalidate(vol, dir);
799 if (*path != '\0' || u == NULL) {
800 /* FIXME: if path != '\0' then extend != 0 ?
801 * u == NUL ==> cpath is something like:
806 if (movecwd(vol, cdir) < 0) {
807 printf("can't change to parent\n");
808 return NULL; /* give up the whole tree is out of synch*/
810 /* restore the previous token */
811 strncpy(path, u, olen);
817 if ( *data == '\0' ) {
823 while ( *data == '\0' && len > 0 ) {
824 if ( dir->d_parent == NULL ) {
832 /* would this be faster with strlen + strncpy? */
838 while ( *data != '\0' && len > 0 ) {
843 /* short cut bits by chopping off a trailing \0. this also
844 makes the traversal happy w/ filenames at the end of the
851 * Dung Nguyen <ntd@adb.fr>
853 * AFPD cannot handle paths with "::" if the "::" notation is
854 * not at the beginning of the path. The following path will not
855 * be interpreted correctly:
857 * :a:b:::c: (directory c at the same level as directory a) */
865 if ( p != path ) { /* we got something */
869 if ( strcasecmp( cdir->d_name, path ) == 0 ) {
872 cdir = (cdir == dir->d_child->d_prev) ? NULL :
875 if ( cdir == NULL ) {
877 /* if dir == curdir it always succeed,
878 even if curdir is deleted.
879 it's not a pb because it will failed in extenddir
881 if ( movecwd( vol, dir ) < 0 ) {
882 /* dir is not valid anymore
883 we delete dir from the cache and abort.
885 dir_invalidate(vol, dir);
888 cdir = extenddir( vol, dir, path );
892 cdir = extenddir( vol, dir, path );
895 if ( cdir == NULL ) {
909 * Move curdir to dir, with a possible chdir()
911 int movecwd( vol, dir)
912 const struct vol *vol;
915 char path[MAXPATHLEN + 1];
920 if ( dir == curdir ) {
923 if ( dir->d_did == DIRDID_ROOT_PARENT) {
927 p = path + sizeof(path) - 1;
930 for ( d = dir; d->d_parent != NULL && d != curdir; d = d->d_parent ) {
932 u = mtoupath(vol, d->d_name );
939 n = strlen( vol->v_path );
941 strncpy( p, vol->v_path, n );
943 if ( chdir( p ) < 0 ) {
950 int getdirparams(const struct vol *vol,
952 char *upath, struct dir *dir, struct stat *st,
953 char *buf, int *buflen )
957 char *data, *nameoff = NULL;
960 int bit = 0, isad = 1;
965 memset(&uidgid, 0, sizeof(uidgid));
966 #endif /* FORCE_UIDGID */
968 memset(&ad, 0, sizeof(ad));
971 save_uidgid ( &uidgid );
973 #endif /* FORCE_UIDGID */
975 if ( ad_open( upath, ADFLAGS_HF|ADFLAGS_DIR, O_RDONLY,
976 DIRBITS | 0777, &ad) < 0 ) {
981 while ( bitmap != 0 ) {
982 while (( bitmap & 1 ) == 0 ) {
990 ad_getattr(&ad, &ashort);
991 } else if (*upath == '.' && strcmp(upath, ".") &&
992 strcmp(upath, "..")) {
993 ashort = htons(ATTRBIT_INVISIBLE);
996 ashort |= htons(ATTRBIT_SHARED);
997 memcpy( data, &ashort, sizeof( ashort ));
998 data += sizeof( ashort );
1002 if ( dir->d_did == DIRDID_ROOT) {
1003 aint = DIRDID_ROOT_PARENT;
1004 } else if (dir->d_did == DIRDID_ROOT_PARENT) {
1007 aint = dir->d_parent->d_did;
1009 memcpy( data, &aint, sizeof( aint ));
1010 data += sizeof( aint );
1013 case DIRPBIT_CDATE :
1014 if (!isad || (ad_getdate(&ad, AD_DATE_CREATE, &aint) < 0))
1015 aint = AD_DATE_FROM_UNIX(st->st_mtime);
1016 memcpy( data, &aint, sizeof( aint ));
1017 data += sizeof( aint );
1020 case DIRPBIT_MDATE :
1021 aint = AD_DATE_FROM_UNIX(st->st_mtime);
1022 memcpy( data, &aint, sizeof( aint ));
1023 data += sizeof( aint );
1026 case DIRPBIT_BDATE :
1027 if (!isad || (ad_getdate(&ad, AD_DATE_BACKUP, &aint) < 0))
1028 aint = AD_DATE_START;
1029 memcpy( data, &aint, sizeof( aint ));
1030 data += sizeof( aint );
1033 case DIRPBIT_FINFO :
1035 memcpy( data, ad_entry( &ad, ADEID_FINDERI ), 32 );
1036 } else { /* no appledouble */
1037 memset( data, 0, 32 );
1038 /* set default view -- this also gets done in ad_open() */
1039 ashort = htons(FINDERINFO_CLOSEDVIEW);
1040 memcpy(data + FINDERINFO_FRVIEWOFF, &ashort, sizeof(ashort));
1042 /* dot files are by default invisible */
1043 if (*upath == '.' && strcmp(upath, ".") &&
1044 strcmp(upath, "..")) {
1045 ashort = htons(FINDERINFO_INVISIBLE);
1046 memcpy(data + FINDERINFO_FRFLAGOFF,
1047 &ashort, sizeof(ashort));
1053 case DIRPBIT_LNAME :
1054 if (dir->d_name) /* root of parent can have a null name */
1057 memset(data, 0, sizeof(u_int16_t));
1058 data += sizeof( u_int16_t );
1061 case DIRPBIT_SNAME :
1062 memset(data, 0, sizeof(u_int16_t));
1063 data += sizeof( u_int16_t );
1067 memcpy( data, &dir->d_did, sizeof( aint ));
1068 data += sizeof( aint );
1071 case DIRPBIT_OFFCNT :
1073 /* this needs to handle current directory access rights */
1074 if ((dp = opendir( upath ))) {
1075 while (( de = readdir( dp )) != NULL ) {
1076 if (!strcmp(de->d_name, "..") || !strcmp(de->d_name, "."))
1079 if (!validupath(vol, de->d_name))
1082 /* check for vetoed filenames */
1083 if (veto_file(vol->v_veto, de->d_name))
1086 /* now check against too long a filename */
1087 if (strlen(utompath(vol, de->d_name)) > MACFILELEN)
1094 ashort = htons( ashort );
1095 memcpy( data, &ashort, sizeof( ashort ));
1096 data += sizeof( ashort );
1100 aint = htonl(st->st_uid);
1101 memcpy( data, &aint, sizeof( aint ));
1102 data += sizeof( aint );
1106 aint = htonl(st->st_gid);
1107 memcpy( data, &aint, sizeof( aint ));
1108 data += sizeof( aint );
1111 case DIRPBIT_ACCESS :
1112 utommode( st, &ma );
1113 #ifndef SENDFILE_FLAVOR_LINUX /* ignore this section if it's linux */
1115 accessmode( upath, &ma, dir );
1116 #endif /* HAVE_ACCESS */
1117 #endif /* SENDFILE_FLAVOR_LINUX */
1118 #ifdef AFS /* If only AFS defined, access() works only for AFS filesystems */
1119 afsmode( upath, &ma, dir );
1121 *data++ = ma.ma_user;
1122 *data++ = ma.ma_world;
1123 *data++ = ma.ma_group;
1124 *data++ = ma.ma_owner;
1127 /* Client has requested the ProDOS information block.
1128 Just pass back the same basic block for all
1129 directories. <shirsch@ibm.net> */
1130 case DIRPBIT_PDINFO : /* ProDOS Info Block */
1133 ashort = htons( 0x0200 );
1134 memcpy( data, &ashort, sizeof( ashort ));
1135 data += sizeof( ashort );
1136 memset( data, 0, sizeof( ashort ));
1137 data += sizeof( ashort );
1142 ad_close( &ad, ADFLAGS_HF );
1145 restore_uidgid ( &uidgid );
1146 #endif /* FORCE_UIDGID */
1147 return( AFPERR_BITMAP );
1153 ashort = htons( data - buf );
1154 memcpy( nameoff, &ashort, sizeof( ashort ));
1156 if ((aint = strlen( dir->d_name )) > MACFILELEN)
1160 memcpy( data, dir->d_name, aint );
1164 ad_close( &ad, ADFLAGS_HF );
1166 *buflen = data - buf;
1170 int afp_setdirparams(obj, ibuf, ibuflen, rbuf, rbuflen )
1173 int ibuflen, *rbuflen;
1178 u_int16_t vid, bitmap;
1184 memcpy( &vid, ibuf, sizeof( vid ));
1185 ibuf += sizeof( vid );
1187 if (( vol = getvolbyvid( vid )) == NULL ) {
1188 return( AFPERR_PARAM );
1191 if (vol->v_flags & AFPVOL_RO)
1192 return AFPERR_VLOCK;
1194 memcpy( &did, ibuf, sizeof( did ));
1195 ibuf += sizeof( int );
1197 if (( dir = dirsearch( vol, did )) == NULL ) {
1198 return( AFPERR_NOOBJ );
1201 memcpy( &bitmap, ibuf, sizeof( bitmap ));
1202 bitmap = ntohs( bitmap );
1203 ibuf += sizeof( bitmap );
1205 if (( path = cname( vol, dir, &ibuf )) == NULL ) {
1206 return( AFPERR_NOOBJ );
1209 if ( *path != '\0' ) {
1210 return( AFPERR_BADTYPE ); /* not a directory */
1214 * If ibuf is odd, make it even.
1216 if ((u_long)ibuf & 1 ) {
1220 if (( rc = setdirparams(vol, path, bitmap, ibuf )) == AFP_OK ) {
1221 setvoltime(obj, vol );
1227 * cf AFP3.0.pdf page 244 for change_mdate and change_parent_mdate logic
1229 * assume path == '\0' eg. it's a directory in canonical form
1231 int setdirparams(const struct vol *vol,
1232 char *path, u_int16_t bitmap, char *buf )
1240 int bit = 0, aint, isad = 1;
1241 u_int16_t ashort, bshort;
1243 int change_mdate = 0;
1244 int change_parent_mdate = 0;
1249 memset(&uidgid, 0, sizeof(uidgid));
1250 #endif /* FORCE_UIDGID */
1252 upath = mtoupath(vol, path);
1253 memset(&ad, 0, sizeof(ad));
1255 save_uidgid ( &uidgid );
1256 #endif /* FORCE_UIDGID */
1258 if (ad_open( upath, vol_noadouble(vol)|ADFLAGS_HF|ADFLAGS_DIR,
1259 O_RDWR|O_CREAT, 0666, &ad) < 0) {
1261 * Check to see what we're trying to set. If it's anything
1262 * but ACCESS, UID, or GID, give an error. If it's any of those
1263 * three, we don't need the ad to be open, so just continue.
1265 * note: we also don't need to worry about mdate. also, be quiet
1266 * if we're using the noadouble option.
1268 if (!vol_noadouble(vol) && (bitmap &
1269 ~((1<<DIRPBIT_ACCESS)|(1<<DIRPBIT_UID)|(1<<DIRPBIT_GID)|
1270 (1<<DIRPBIT_MDATE)|(1<<DIRPBIT_PDINFO)))) {
1272 restore_uidgid ( &uidgid );
1273 #endif /* FORCE_UIDGID */
1274 return AFPERR_ACCESS;
1280 * Check to see if a create was necessary. If it was, we'll want
1281 * to set our name, etc.
1283 if ( ad_getoflags( &ad, ADFLAGS_HF ) & O_CREAT ) {
1284 ad_setentrylen( &ad, ADEID_NAME, strlen( curdir->d_name ));
1285 memcpy( ad_entry( &ad, ADEID_NAME ), curdir->d_name,
1286 ad_getentrylen( &ad, ADEID_NAME ));
1290 while ( bitmap != 0 ) {
1291 while (( bitmap & 1 ) == 0 ) {
1300 memcpy( &ashort, buf, sizeof( ashort ));
1301 ad_getattr(&ad, &bshort);
1302 if ( ntohs( ashort ) & ATTRBIT_SETCLR ) {
1303 bshort |= htons( ntohs( ashort ) & ~ATTRBIT_SETCLR );
1307 ad_setattr(&ad, bshort);
1308 if ((ashort & htons(ATTRBIT_INVISIBLE)))
1309 change_parent_mdate = 1;
1311 buf += sizeof( ashort );
1314 case DIRPBIT_CDATE :
1317 memcpy(&aint, buf, sizeof(aint));
1318 ad_setdate(&ad, AD_DATE_CREATE, aint);
1320 buf += sizeof( aint );
1323 case DIRPBIT_MDATE :
1324 memcpy(&newdate, buf, sizeof(newdate));
1325 buf += sizeof( newdate );
1328 case DIRPBIT_BDATE :
1331 memcpy(&aint, buf, sizeof(aint));
1332 ad_setdate(&ad, AD_DATE_BACKUP, aint);
1334 buf += sizeof( aint );
1337 case DIRPBIT_FINFO :
1340 * Alright, we admit it, this is *really* sick!
1341 * The 4 bytes that we don't copy, when we're dealing
1342 * with the root of a volume, are the directory's
1343 * location information. This eliminates that annoying
1344 * behavior one sees when mounting above another mount
1348 if ( curdir->d_did == DIRDID_ROOT ) {
1349 memcpy( ad_entry( &ad, ADEID_FINDERI ), buf, 10 );
1350 memcpy( ad_entry( &ad, ADEID_FINDERI ) + 14, buf + 14, 18 );
1352 memcpy( ad_entry( &ad, ADEID_FINDERI ), buf, 32 );
1358 case DIRPBIT_UID : /* What kind of loser mounts as root? */
1359 change_parent_mdate = 1;
1360 memcpy( &aint, buf, sizeof(aint));
1361 buf += sizeof( aint );
1362 if ( (curdir->d_did == DIRDID_ROOT) &&
1363 (setdeskowner( ntohl(aint), -1 ) < 0)) {
1367 err = AFPERR_ACCESS;
1368 goto setdirparam_done;
1372 goto setdirparam_done;
1375 LOG(log_error, logtype_afpd, "setdirparam: setdeskowner: %s",
1379 goto setdirparam_done;
1384 if ( setdirowner( ntohl(aint), -1, vol_noadouble(vol) ) < 0 ) {
1388 err = AFPERR_ACCESS;
1389 goto setdirparam_done;
1393 goto setdirparam_done;
1396 LOG(log_error, logtype_afpd, "setdirparam: setdirowner: %s",
1403 change_parent_mdate = 1;
1404 memcpy( &aint, buf, sizeof( aint ));
1405 buf += sizeof( aint );
1406 if (curdir->d_did == DIRDID_ROOT)
1407 setdeskowner( -1, ntohl(aint) );
1409 #if 0 /* don't error if we can't set the desktop owner. */
1413 err = AFPERR_ACCESS;
1414 goto setdirparam_done;
1418 goto setdirparam_done;
1421 LOG(log_error, logtype_afpd, "setdirparam: setdeskowner: %m" );
1424 goto setdirparam_done;
1430 if ( setdirowner( -1, ntohl(aint), vol_noadouble(vol) ) < 0 ) {
1434 err = AFPERR_ACCESS;
1435 goto setdirparam_done;
1439 goto setdirparam_done;
1442 LOG(log_error, logtype_afpd, "setdirparam: setdirowner: %s",
1449 case DIRPBIT_ACCESS :
1451 change_parent_mdate = 1;
1452 ma.ma_user = *buf++;
1453 ma.ma_world = *buf++;
1454 ma.ma_group = *buf++;
1455 ma.ma_owner = *buf++;
1457 if (curdir->d_did == DIRDID_ROOT)
1458 setdeskmode(mtoumode( &ma ));
1459 #if 0 /* don't error if we can't set the desktop mode */
1463 err = AFPERR_ACCESS;
1464 goto setdirparam_done;
1467 goto setdirparam_done;
1469 LOG(log_error, logtype_afpd, "setdirparam: setdeskmode: %s",
1473 goto setdirparam_done;
1477 if ( setdirmode( mtoumode( &ma ), vol_noadouble(vol),
1478 (vol->v_flags & AFPVOL_DROPBOX)) < 0 ) {
1482 err = AFPERR_ACCESS;
1483 goto setdirparam_done;
1486 goto setdirparam_done;
1488 LOG(log_error, logtype_afpd, "setdirparam: setdirmode: %s",
1491 goto setdirparam_done;
1496 /* Ignore what the client thinks we should do to the
1497 ProDOS information block. Skip over the data and
1498 report nothing amiss. <shirsch@ibm.net> */
1499 case DIRPBIT_PDINFO :
1504 err = AFPERR_BITMAP;
1505 goto setdirparam_done;
1514 if (change_mdate && newdate == 0 && gettimeofday(&tv, NULL) == 0) {
1515 newdate = AD_DATE_FROM_UNIX(tv.tv_sec);
1519 ad_setdate(&ad, AD_DATE_MODIFY, newdate);
1520 ut.actime = ut.modtime = AD_DATE_TO_UNIX(newdate);
1525 ad_flush( &ad, ADFLAGS_HF );
1526 ad_close( &ad, ADFLAGS_HF );
1530 restore_uidgid ( &uidgid );
1531 #endif /* FORCE_UIDGID */
1533 if (change_parent_mdate && curdir->d_did != DIRDID_ROOT
1534 && gettimeofday(&tv, NULL) == 0) {
1535 if (!movecwd(vol, curdir->d_parent)) {
1536 newdate = AD_DATE_FROM_UNIX(tv.tv_sec);
1537 bitmap = 1<<DIRPBIT_MDATE;
1538 setdirparams(vol, "", bitmap, (char *)&newdate);
1539 /* should we reset curdir ?*/
1546 int afp_createdir(obj, ibuf, ibuflen, rbuf, rbuflen )
1549 int ibuflen, *rbuflen;
1561 memset(&uidgid, 0, sizeof(uidgid));
1562 #endif /* FORCE_UIDGID */
1567 memcpy( &vid, ibuf, sizeof( vid ));
1568 ibuf += sizeof( vid );
1569 if (( vol = getvolbyvid( vid )) == NULL ) {
1570 return( AFPERR_PARAM );
1573 if (vol->v_flags & AFPVOL_RO)
1574 return AFPERR_VLOCK;
1576 memcpy( &did, ibuf, sizeof( did ));
1577 ibuf += sizeof( did );
1578 if (( dir = dirsearch( vol, did )) == NULL ) {
1579 return( AFPERR_NOOBJ );
1582 if (( path = cname( vol, dir, &ibuf )) == NULL ) {
1585 return( AFPERR_ACCESS );
1586 case EEXIST: /* FIXME this on is impossible? */
1587 return( AFPERR_EXIST );
1589 return( AFPERR_NOOBJ );
1592 /* FIXME check done elswhere? cname was able to move curdir to it! */
1594 return AFPERR_EXIST;
1595 upath = mtoupath(vol, path);
1598 if (0 != (ret = check_name(vol, upath))) {
1604 save_uidgid ( &uidgid );
1606 #endif /* FORCE_UIDGID */
1608 if ( ad_mkdir( upath, DIRBITS | 0777 ) < 0 ) {
1610 restore_uidgid ( &uidgid );
1611 #endif /* FORCE_UIDGID */
1614 return( AFPERR_NOOBJ );
1616 return( AFPERR_VLOCK );
1618 return( AFPERR_ACCESS );
1620 return( AFPERR_EXIST );
1623 return( AFPERR_DFULL );
1625 return( AFPERR_PARAM );
1629 if (stat(upath, &st) < 0) {
1631 restore_uidgid ( &uidgid );
1632 #endif /* FORCE_UIDGID */
1636 if ((dir = adddir( vol, curdir, path, strlen( path ), upath,
1637 strlen(upath), &st)) == NULL) {
1639 restore_uidgid ( &uidgid );
1640 #endif /* FORCE_UIDGID */
1644 if ( movecwd( vol, dir ) < 0 ) {
1646 restore_uidgid ( &uidgid );
1647 #endif /* FORCE_UIDGID */
1648 return( AFPERR_PARAM );
1651 memset(&ad, 0, sizeof(ad));
1652 if (ad_open( "", vol_noadouble(vol)|ADFLAGS_HF|ADFLAGS_DIR,
1653 O_RDWR|O_CREAT, 0666, &ad ) < 0) {
1654 if (vol_noadouble(vol))
1655 goto createdir_done;
1657 restore_uidgid ( &uidgid );
1658 #endif /* FORCE_UIDGID */
1659 return( AFPERR_ACCESS );
1662 ad_setentrylen( &ad, ADEID_NAME, strlen( path ));
1663 memcpy( ad_entry( &ad, ADEID_NAME ), path,
1664 ad_getentrylen( &ad, ADEID_NAME ));
1665 ad_flush( &ad, ADFLAGS_HF );
1666 ad_close( &ad, ADFLAGS_HF );
1669 memcpy( rbuf, &dir->d_did, sizeof( u_int32_t ));
1670 *rbuflen = sizeof( u_int32_t );
1671 setvoltime(obj, vol );
1673 restore_uidgid ( &uidgid );
1674 #endif /* FORCE_UIDGID */
1679 int renamedir(src, dst, dir, newparent, newname, noadouble)
1680 char *src, *dst, *newname;
1681 struct dir *dir, *newparent;
1682 const int noadouble;
1689 /* existence check moved to afp_moveandrename */
1690 if ( rename( src, dst ) < 0 ) {
1693 return( AFPERR_NOOBJ );
1695 return( AFPERR_ACCESS );
1697 return AFPERR_VLOCK;
1699 /* tried to move directory into a subdirectory of itself */
1700 return AFPERR_CANTMOVE;
1702 /* this needs to copy and delete. bleah. that means we have
1703 * to deal with entire directory hierarchies. */
1704 if ((err = copydir(src, dst, noadouble)) < 0) {
1708 if ((err = deletedir(src)) < 0)
1712 return( AFPERR_PARAM );
1716 memset(&ad, 0, sizeof(ad));
1717 if ( ad_open( dst, ADFLAGS_HF|ADFLAGS_DIR, O_RDWR, 0, &ad) < 0 ) {
1721 len = strlen(newname);
1722 goto renamedir_done;
1724 return( AFPERR_NOOBJ );
1726 return( AFPERR_ACCESS );
1728 return( AFPERR_PARAM );
1731 len = strlen( newname );
1732 ad_setentrylen( &ad, ADEID_NAME, len );
1733 memcpy( ad_entry( &ad, ADEID_NAME ), newname, len );
1734 ad_flush( &ad, ADFLAGS_HF );
1735 ad_close( &ad, ADFLAGS_HF );
1738 if ((buf = (char *) realloc( dir->d_name, len + 1 )) == NULL ) {
1739 LOG(log_error, logtype_afpd, "renamedir: realloc: %s", strerror(errno) );
1743 strcpy( dir->d_name, newname );
1745 if (( parent = dir->d_parent ) == NULL ) {
1748 if ( parent == newparent ) {
1752 /* detach from old parent and add to new one. */
1753 dirchildremove(parent, dir);
1754 dir->d_parent = newparent;
1755 dirchildadd(newparent, dir);
1759 #define DOT_APPLEDOUBLE_LEN 13
1760 /* delete an empty directory */
1761 int deletecurdir( vol, path, pathlen )
1762 const struct vol *vol;
1775 memset(&uidgid, 0, sizeof(uidgid));
1776 #endif /* FORCE_UIDGID */
1778 if ( curdir->d_parent == NULL ) {
1779 return( AFPERR_ACCESS );
1782 if ( curdir->d_child != NULL ) {
1783 return( AFPERR_DIRNEMPT );
1789 save_uidgid ( &uidgid );
1791 #endif /* FORCE_UIDGID */
1793 memset(&ad, 0, sizeof(ad));
1794 if ( ad_open( ".", ADFLAGS_HF|ADFLAGS_DIR, O_RDONLY,
1795 DIRBITS | 0777, &ad) == 0 ) {
1797 ad_getattr(&ad, &ashort);
1798 ad_close( &ad, ADFLAGS_HF );
1799 if ((ashort & htons(ATTRBIT_NODELETE))) {
1801 restore_uidgid ( &uidgid );
1802 #endif /* FORCE_UIDGID */
1803 return AFPERR_OLOCK;
1807 /* delete stray .AppleDouble files. this happens to get .Parent files
1809 if ((dp = opendir(".AppleDouble"))) {
1810 strcpy(path, ".AppleDouble/");
1811 while ((de = readdir(dp))) {
1812 /* skip this and previous directory */
1813 if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, ".."))
1816 /* bail if the file exists in the current directory.
1817 * note: this will not fail with dangling symlinks */
1818 if (stat(de->d_name, &st) == 0) {
1821 restore_uidgid ( &uidgid );
1822 #endif /* FORCE_UIDGID */
1823 return AFPERR_DIRNEMPT;
1826 strcpy(path + DOT_APPLEDOUBLE_LEN, de->d_name);
1827 if (unlink(path) < 0) {
1833 restore_uidgid ( &uidgid );
1834 #endif /* FORCE_UIDGID */
1835 return( AFPERR_ACCESS );
1838 restore_uidgid ( &uidgid );
1839 #endif /* FORCE_UIDGID */
1840 return AFPERR_VLOCK;
1845 restore_uidgid ( &uidgid );
1846 #endif /* FORCE_UIDGID */
1847 return( AFPERR_PARAM );
1854 if ( rmdir( ".AppleDouble" ) < 0 ) {
1860 restore_uidgid ( &uidgid );
1861 #endif /* FORCE_UIDGID */
1862 return( AFPERR_DIRNEMPT );
1865 restore_uidgid ( &uidgid );
1866 #endif /* FORCE_UIDGID */
1867 return AFPERR_VLOCK;
1871 restore_uidgid ( &uidgid );
1872 #endif /* FORCE_UIDGID */
1873 return( AFPERR_ACCESS );
1876 restore_uidgid ( &uidgid );
1877 #endif /* FORCE_UIDGID */
1878 return( AFPERR_PARAM );
1882 /* now get rid of dangling symlinks */
1883 if ((dp = opendir("."))) {
1884 while ((de = readdir(dp))) {
1885 /* skip this and previous directory */
1886 if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, ".."))
1889 /* bail if it's not a symlink */
1890 if ((lstat(de->d_name, &st) == 0) && !S_ISLNK(st.st_mode)) {
1892 restore_uidgid ( &uidgid );
1893 #endif /* FORCE_UIDGID */
1894 return AFPERR_DIRNEMPT;
1897 if (unlink(de->d_name) < 0) {
1902 restore_uidgid ( &uidgid );
1903 #endif /* FORCE_UIDGID */
1904 return( AFPERR_ACCESS );
1907 restore_uidgid ( &uidgid );
1908 #endif /* FORCE_UIDGID */
1909 return AFPERR_VLOCK;
1914 restore_uidgid ( &uidgid );
1915 #endif /* FORCE_UIDGID */
1916 return( AFPERR_PARAM );
1923 if ( movecwd( vol, curdir->d_parent ) < 0 ) {
1925 restore_uidgid ( &uidgid );
1926 #endif /* FORCE_UIDGID */
1927 return( AFPERR_NOOBJ );
1930 if ( rmdir(mtoupath(vol, fdir->d_name)) < 0 ) {
1934 restore_uidgid ( &uidgid );
1935 #endif /* FORCE_UIDGID */
1936 return( AFPERR_NOOBJ );
1939 restore_uidgid ( &uidgid );
1940 #endif /* FORCE_UIDGID */
1941 return( AFPERR_DIRNEMPT );
1945 restore_uidgid ( &uidgid );
1946 #endif /* FORCE_UIDGID */
1947 return( AFPERR_ACCESS );
1950 restore_uidgid ( &uidgid );
1951 #endif /* FORCE_UIDGID */
1952 return AFPERR_VLOCK;
1955 restore_uidgid ( &uidgid );
1956 #endif /* FORCE_UIDGID */
1957 return( AFPERR_PARAM );
1961 dirchildremove(curdir, fdir);
1963 cnid_delete(vol->v_db, fdir->d_did);
1964 #endif /* CNID_DB */
1965 dir_remove( vol, fdir );
1968 restore_uidgid ( &uidgid );
1969 #endif /* FORCE_UIDGID */
1973 int afp_mapid(obj, ibuf, ibuflen, rbuf, rbuflen )
1976 int ibuflen, *rbuflen;
1985 sfunc = (unsigned char) *ibuf++;
1986 memcpy( &id, ibuf, sizeof( id ));
1993 if (( pw = getpwuid( id )) == NULL ) {
1995 return( AFPERR_NOITEM );
2001 if (( gr = (struct group *)getgrgid( id )) == NULL ) {
2003 return( AFPERR_NOITEM );
2010 return( AFPERR_PARAM );
2013 len = strlen( name );
2022 memcpy( rbuf, name, len );
2028 int afp_mapname(obj, ibuf, ibuflen, rbuf, rbuflen )
2031 int ibuflen, *rbuflen;
2039 sfunc = (unsigned char) *ibuf++;
2040 len = (unsigned char) *ibuf++;
2046 if (( pw = (struct passwd *)getpwnam( ibuf )) == NULL ) {
2048 return( AFPERR_NOITEM );
2054 if (( gr = (struct group *)getgrnam( ibuf )) == NULL ) {
2056 return( AFPERR_NOITEM );
2062 return( AFPERR_PARAM );
2068 memcpy( rbuf, &id, sizeof( id ));
2069 *rbuflen = sizeof( id );
2073 /* variable DID support */
2074 int afp_closedir(obj, ibuf, ibuflen, rbuf, rbuflen )
2077 int ibuflen, *rbuflen;
2088 /* do nothing as dids are static for the life of the process. */
2092 memcpy(&vid, ibuf, sizeof( vid ));
2093 ibuf += sizeof( vid );
2094 if (( vol = getvolbyvid( vid )) == NULL ) {
2095 return( AFPERR_PARAM );
2098 memcpy( &did, ibuf, sizeof( did ));
2099 ibuf += sizeof( did );
2100 if (( dir = dirsearch( vol, did )) == NULL ) {
2101 return( AFPERR_PARAM );
2104 /* dir_remove -- deletedid */
2110 /* did creation gets done automatically */
2111 int afp_opendir(obj, ibuf, ibuflen, rbuf, rbuflen )
2114 int ibuflen, *rbuflen;
2117 struct dir *dir, *parentdir;
2125 memset(&uidgid, 0, sizeof(uidgid));
2126 #endif /* FORCE_UIDGID */
2131 memcpy(&vid, ibuf, sizeof(vid));
2132 ibuf += sizeof( vid );
2134 if (( vol = getvolbyvid( vid )) == NULL ) {
2135 return( AFPERR_PARAM );
2138 memcpy(&did, ibuf, sizeof(did));
2139 ibuf += sizeof(did);
2141 if (( parentdir = dirsearch( vol, did )) == NULL ) {
2142 return( AFPERR_NOOBJ );
2145 if (( path = cname( vol, parentdir, &ibuf )) == NULL ) {
2148 return( AFPERR_ACCESS );
2150 return( AFPERR_NOOBJ );
2154 /* see if we already have the directory. */
2155 upath = mtoupath(vol, path);
2156 if ( stat( upath, &st ) < 0 ) {
2157 return( AFPERR_NOOBJ );
2160 dir = parentdir->d_child;
2162 if (strdiacasecmp(dir->d_name, path) == 0) {
2163 memcpy(rbuf, &dir->d_did, sizeof(dir->d_did));
2164 *rbuflen = sizeof(dir->d_did);
2167 dir = (dir == parentdir->d_child->d_prev) ? NULL : dir->d_next;
2171 save_uidgid ( &uidgid );
2173 #endif /* FORCE_UIDGID */
2175 /* we don't already have a did. add one in. */
2176 if ((dir = adddir(vol, parentdir, path, strlen(path),
2177 upath, strlen(upath), &st)) == NULL) {
2179 restore_uidgid ( &uidgid );
2180 #endif /* FORCE_UIDGID */
2184 memcpy(rbuf, &dir->d_did, sizeof(dir->d_did));
2185 *rbuflen = sizeof(dir->d_did);
2187 restore_uidgid ( &uidgid );
2188 #endif /* FORCE_UIDGID */