2 * $Id: directory.c,v 1.59 2003-01-26 10:42:40 didg Exp $
4 * Copyright (c) 1990,1993 Regents of The University of Michigan.
5 * All Rights Reserved. See COPYRIGHT.
7 * 19 jan 2000 implemented red-black trees for directory lookups
13 #endif /* HAVE_CONFIG_H */
15 #include <atalk/logger.h>
16 #include <sys/types.h>
20 #include <sys/param.h>
21 #include <netatalk/endian.h>
22 #include <atalk/adouble.h>
23 #include <atalk/afp.h>
24 #include <atalk/util.h>
26 #include <atalk/cnid.h>
34 #endif /* HAVE_FCNTL_H */
41 #else /* STDC_HEADERS */
45 #endif /* HAVE_STRCHR */
46 char *strchr (), *strrchr ();
48 #define memcpy(d,s,n) bcopy ((s), (d), (n))
49 #define memmove(d,s,n) bcopy ((s), (d), (n))
50 #endif /* ! HAVE_MEMCPY */
51 #endif /* STDC_HEADERS */
53 #include "directory.h"
65 #define SENTINEL (&sentinel)
66 static struct dir sentinel = { SENTINEL, SENTINEL, NULL, DIRTREE_COLOR_BLACK,
67 NULL, NULL, NULL, NULL, NULL, 0, 0,
69 static struct dir rootpar = { SENTINEL, SENTINEL, NULL, 0,
70 NULL, NULL, NULL, NULL, NULL, 0, 0,
73 /* (from IM: Toolbox Essentials)
74 * dirFinderInfo (DInfo) fields:
76 * frRect 8 folder's window rectangle
78 * frLocation 4 folder's location in window
79 * frView 2 folder's view (default == closedView (256))
81 * extended dirFinderInfo (DXInfo) fields:
82 * frScroll 4 scroll position
83 * frOpenChain: 4 directory ID chain of open folders
84 * frScript: 1 script flag and code
85 * frXFlags: 1 reserved
86 * frComment: 2 comment ID
87 * frPutAway: 4 home directory ID
91 * redid did assignment for directories. now we use red-black trees.
96 const struct vol *vol;
102 /* check for 0 did */
104 afp_errno = AFPERR_PARAM;
107 if ( did == DIRDID_ROOT_PARENT ) {
109 rootpar.d_did = DIRDID_ROOT_PARENT;
110 rootpar.d_child = vol->v_dir;
115 afp_errno = AFPERR_NOOBJ;
116 while ( dir != SENTINEL ) {
117 if (dir->d_did == did)
118 return dir->d_m_name ? dir : NULL;
119 dir = (dir->d_did > did) ? dir->d_left : dir->d_right;
124 /* ------------------- */
126 int path_isadir(struct path *o_path)
128 return o_path->m_name == '\0' || /* we are in a it */
129 !o_path->st_valid || /* in cache but we can't chdir in it */
130 (!o_path->st_errno && S_ISDIR(o_path->st.st_mode)); /* not in cache an can't chdir */
134 /* ------------------- */
136 dirsearch_byname( cdir, name )
142 if (!strcmp(name, "."))
146 if ( strcmp( dir->d_u_name, name ) == 0 ) {
149 dir = (dir == curdir->d_child->d_prev) ? NULL : dir->d_next;
154 /* -----------------------------------------
155 * if did is not in the cache resolve it with cnid
159 dirlookup( vol, did )
160 const struct vol *vol;
167 static char path[MAXPATHLEN + 1];
171 static char buffer[12 + MAXPATHLEN + 1];
172 int buflen = 12 + MAXPATHLEN + 1;
175 ret = dirsearch(vol, did);
176 if (ret != NULL || afp_errno == AFPERR_PARAM)
180 if (NULL == (upath = cnid_resolve(vol->v_db, &id, buffer, buflen)) ) {
181 afp_errno = AFPERR_NOOBJ;
184 ptr = path + MAXPATHLEN;
185 mpath = utompath(vol, upath);
187 pathlen = len; /* no 0 in the last part */
189 strcpy(ptr - len, mpath);
192 ret = dirsearch(vol,id);
196 if ((upath = cnid_resolve(vol->v_db, &id, buffer, buflen)) == NULL) {
197 afp_errno = AFPERR_NOOBJ;
200 mpath = utompath(vol, upath);
201 len = strlen(mpath) + 1;
204 afp_errno = AFPERR_PARAM;
207 strcpy(ptr - len, mpath);
212 *ptr = (unsigned char)pathlen;
215 /* cname is not efficient */
216 if (cname( vol, ret, &ptr ) == NULL )
219 return dirsearch(vol, did);
222 /* --------------------------- */
223 /* rotate the tree to the left */
224 static void dir_leftrotate(vol, dir)
228 struct dir *right = dir->d_right;
230 /* whee. move the right's left tree into dir's right tree */
231 dir->d_right = right->d_left;
232 if (right->d_left != SENTINEL)
233 right->d_left->d_back = dir;
235 if (right != SENTINEL) {
236 right->d_back = dir->d_back;
240 if (!dir->d_back) /* no parent. move the right tree to the top. */
242 else if (dir == dir->d_back->d_left) /* we were on the left */
243 dir->d_back->d_left = right;
245 dir->d_back->d_right = right; /* we were on the right */
247 /* re-insert dir on the left tree */
254 /* rotate the tree to the right */
255 static void dir_rightrotate(vol, dir)
259 struct dir *left = dir->d_left;
261 /* whee. move the left's right tree into dir's left tree */
262 dir->d_left = left->d_right;
263 if (left->d_right != SENTINEL)
264 left->d_right->d_back = dir;
266 if (left != SENTINEL) {
267 left->d_back = dir->d_back;
271 if (!dir->d_back) /* no parent. move the left tree to the top. */
273 else if (dir == dir->d_back->d_right) /* we were on the right */
274 dir->d_back->d_right = left;
276 dir->d_back->d_left = left; /* we were on the left */
278 /* re-insert dir on the right tree */
284 /* recolor after a removal */
285 static struct dir *dir_rmrecolor(vol, dir)
291 while ((dir != vol->v_root) && (dir->d_color == DIRTREE_COLOR_BLACK)) {
292 /* are we on the left tree? */
293 if (dir == dir->d_back->d_left) {
294 leaf = dir->d_back->d_right; /* get right side */
295 if (leaf->d_color == DIRTREE_COLOR_RED) {
296 /* we're red. we need to change to black. */
297 leaf->d_color = DIRTREE_COLOR_BLACK;
298 dir->d_back->d_color = DIRTREE_COLOR_RED;
299 dir_leftrotate(vol, dir->d_back);
300 leaf = dir->d_back->d_right;
303 /* right leaf has black end nodes */
304 if ((leaf->d_left->d_color == DIRTREE_COLOR_BLACK) &&
305 (leaf->d_right->d_color = DIRTREE_COLOR_BLACK)) {
306 leaf->d_color = DIRTREE_COLOR_RED; /* recolor leaf as red */
307 dir = dir->d_back; /* ascend */
309 if (leaf->d_right->d_color == DIRTREE_COLOR_BLACK) {
310 leaf->d_left->d_color = DIRTREE_COLOR_BLACK;
311 leaf->d_color = DIRTREE_COLOR_RED;
312 dir_rightrotate(vol, leaf);
313 leaf = dir->d_back->d_right;
315 leaf->d_color = dir->d_back->d_color;
316 dir->d_back->d_color = DIRTREE_COLOR_BLACK;
317 leaf->d_right->d_color = DIRTREE_COLOR_BLACK;
318 dir_leftrotate(vol, dir->d_back);
321 } else { /* right tree */
322 leaf = dir->d_back->d_left; /* left tree */
323 if (leaf->d_color == DIRTREE_COLOR_RED) {
324 leaf->d_color = DIRTREE_COLOR_BLACK;
325 dir->d_back->d_color = DIRTREE_COLOR_RED;
326 dir_rightrotate(vol, dir->d_back);
327 leaf = dir->d_back->d_left;
330 /* left leaf has black end nodes */
331 if ((leaf->d_right->d_color == DIRTREE_COLOR_BLACK) &&
332 (leaf->d_left->d_color = DIRTREE_COLOR_BLACK)) {
333 leaf->d_color = DIRTREE_COLOR_RED; /* recolor leaf as red */
334 dir = dir->d_back; /* ascend */
336 if (leaf->d_left->d_color == DIRTREE_COLOR_BLACK) {
337 leaf->d_right->d_color = DIRTREE_COLOR_BLACK;
338 leaf->d_color = DIRTREE_COLOR_RED;
339 dir_leftrotate(vol, leaf);
340 leaf = dir->d_back->d_left;
342 leaf->d_color = dir->d_back->d_color;
343 dir->d_back->d_color = DIRTREE_COLOR_BLACK;
344 leaf->d_left->d_color = DIRTREE_COLOR_BLACK;
345 dir_rightrotate(vol, dir->d_back);
350 dir->d_color = DIRTREE_COLOR_BLACK;
357 /* remove the node from the tree. this is just like insertion, but
358 * different. actually, it has to worry about a bunch of things that
359 * insertion doesn't care about. */
360 static void dir_remove( vol, dir )
365 struct ofork *of, *last;
366 struct dir *node, *leaf;
367 #endif /* REMOVE_NODES */
369 if (!dir || (dir == SENTINEL))
372 /* i'm not sure if it really helps to delete stuff. */
374 if (dir->d_u_name != dir->d_m_name) {
378 dir->d_m_name = NULL;
379 dir->d_u_name = NULL;
380 #else /* ! REMOVE_NODES */
382 /* go searching for a node with at most one child */
383 if ((dir->d_left == SENTINEL) || (dir->d_right == SENTINEL)) {
387 while (node->d_left != SENTINEL)
392 leaf = (node->d_left != SENTINEL) ? node->d_left : node->d_right;
395 leaf->d_back = node->d_back;
398 } else if (node == node->d_back->d_left) { /* left tree */
399 node->d_back->d_left = leaf;
401 node->d_back->d_right = leaf;
404 /* we want to free node, but we also want to free the data in dir.
405 * currently, that's d_name and the directory traversal bits.
406 * we just copy the necessary bits and then fix up all the
407 * various pointers to the directory. needless to say, there are
408 * a bunch of places that store the directory struct. */
410 struct dir save, *tmp;
412 memcpy(&save, dir, sizeof(save));
413 memcpy(dir, node, sizeof(struct dir));
415 /* restore the red-black bits */
416 dir->d_left = save.d_left;
417 dir->d_right = save.d_right;
418 dir->d_back = save.d_back;
419 dir->d_color = save.d_color;
421 if (node == vol->v_dir) {/* we may need to fix up this pointer */
423 rootpar.d_child = vol->v_dir;
425 /* if we aren't the root directory, we have parents and
426 * siblings to worry about */
427 if (dir->d_parent->d_child == node)
428 dir->d_parent->d_child = dir;
429 dir->d_next->d_prev = dir;
430 dir->d_prev->d_next = dir;
433 /* fix up children. */
437 tmp = (tmp == dir->d_child->d_prev) ? NULL : tmp->d_next;
440 if (node == curdir) /* another pointer to fixup */
443 /* we also need to fix up oforks. bleah */
444 if ((of = dir->d_ofork)) {
445 last = of->of_d_prev;
448 of = (last == of) ? NULL : of->of_d_next;
452 /* set the node's d_name */
453 node->d_m_name = save.d_m_name;
454 node->d_u_name = save.d_u_name;
457 if (node->d_color == DIRTREE_COLOR_BLACK)
458 dir_rmrecolor(vol, leaf);
460 if (node->d_u_name != node->d_m_name) {
461 free(node->d_u_name);
463 free(node->d_m_name);
465 #endif /* ! REMOVE_NODES */
468 /* ---------------------------------------
469 * remove the node and its childs from the tree
471 * FIXME what about opened forks with refs to it?
472 * it's an afp specs violation because you can't delete
473 * an opened forks. Now afpd doesn't care about forks opened by other
474 * process. It's fixable within afpd if fnctl_lock, doable with smb and
475 * next to impossible for nfs and local filesystem access.
477 static void dir_invalidate( vol, dir )
478 const struct vol *vol;
482 /* v_root can't be deleted */
483 if (movecwd(vol, vol->v_root) < 0) {
484 LOG(log_error, logtype_afpd, "cname can't chdir to : %s", vol->v_root);
488 dirchildremove(dir->d_parent, dir);
489 dir_remove( vol, dir );
492 /* ------------------------------------ */
493 static struct dir *dir_insert(vol, dir)
494 const struct vol *vol;
500 while (pdir->d_did != dir->d_did ) {
501 if ( pdir->d_did > dir->d_did ) {
502 if ( pdir->d_left == SENTINEL ) {
509 if ( pdir->d_right == SENTINEL ) {
514 pdir = pdir->d_right;
522 * attempt to extend the current dir. tree to include path
523 * as a side-effect, movecwd to that point and return the new dir
526 extenddir( vol, dir, path )
533 path->u_name = p = mtoupath(vol, path->m_name );
534 if ( of_stat( path ) != 0 ) {
538 if (!S_ISDIR(path->st.st_mode)) {
542 if (( dir = adddir( vol, dir, path)) == NULL ) {
546 if ( movecwd( vol, dir ) < 0 ) {
553 /* -------------------
554 system rmdir with afp error code.
555 ENOENT is not an error.
557 static int netatalk_rmdir(const char *name)
559 if (rmdir(name) < 0) {
564 return AFPERR_DIRNEMPT;
567 return AFPERR_ACCESS;
577 /* -------------------------
578 appledouble mkdir afp error code.
580 static int netatalk_mkdir(const char *name)
582 if (ad_mkdir(name, DIRBITS | 0777) < 0) {
585 return( AFPERR_NOOBJ );
587 return( AFPERR_VLOCK );
590 return( AFPERR_ACCESS );
592 return( AFPERR_EXIST );
595 return( AFPERR_DFULL );
597 return( AFPERR_PARAM );
603 /* -------------------
604 system unlink with afp error code.
605 ENOENT is not an error.
607 int netatalk_unlink(const char *name)
609 if (unlink(name) < 0) {
617 return AFPERR_ACCESS;
625 /* ------------------- */
626 static int deletedir(char *dir)
628 char path[MAXPATHLEN + 1];
636 if ((len = strlen(dir)) +2 > sizeof(path))
640 if ((dp = opendir(dir)) == NULL)
646 remain = sizeof(path) -len -1;
647 while ((de = readdir(dp)) && err == AFP_OK) {
648 /* skip this and previous directory */
649 if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, ".."))
652 if (strlen(de->d_name) > remain) {
656 strcpy(path + len, de->d_name);
657 if (stat(path, &st)) {
660 if (S_ISDIR(st.st_mode)) {
661 err = deletedir(path);
663 err = netatalk_unlink(path);
668 /* okay. the directory is empty. delete it. note: we already got rid
671 err = netatalk_rmdir(dir);
676 /* do a recursive copy. */
677 static int copydir(char *src, char *dst, int noadouble)
679 char spath[MAXPATHLEN + 1], dpath[MAXPATHLEN + 1];
689 /* doesn't exist or the path is too long. */
690 if (((slen = strlen(src)) > sizeof(spath) - 2) ||
691 ((dlen = strlen(dst)) > sizeof(dpath) - 2) ||
692 ((dp = opendir(src)) == NULL))
695 /* try to create the destination directory */
696 if (AFP_OK != (err = netatalk_mkdir(dst)) ) {
701 /* set things up to copy */
705 srem = sizeof(spath) - slen -1;
710 drem = sizeof(dpath) - dlen -1;
713 while ((de = readdir(dp))) {
714 /* skip this and previous directory */
715 if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, ".."))
718 if (strlen(de->d_name) > srem) {
722 strcpy(spath + slen, de->d_name);
724 if (stat(spath, &st) == 0) {
725 if (strlen(de->d_name) > drem) {
729 strcpy(dpath + dlen, de->d_name);
731 if (S_ISDIR(st.st_mode)) {
732 if (AFP_OK != (err = copydir(spath, dpath, noadouble)))
734 } else if (AFP_OK != (err = copyfile(spath, dpath, NULL, noadouble))) {
738 /* keep the same time stamp. */
739 ut.actime = ut.modtime = st.st_mtime;
745 /* keep the same time stamp. */
746 if (stat(src, &st) == 0) {
747 ut.actime = ut.modtime = st.st_mtime;
757 /* --- public functions follow --- */
759 /* NOTE: we start off with at least one node (the root directory). */
760 struct dir *dirinsert( vol, dir )
766 if ((node = dir_insert(vol, dir)))
769 /* recolor the tree. the current node is red. */
770 dir->d_color = DIRTREE_COLOR_RED;
772 /* parent of this node has to be black. if the parent node
773 * is red, then we have a grandparent. */
774 while ((dir != vol->v_root) &&
775 (dir->d_back->d_color == DIRTREE_COLOR_RED)) {
776 /* are we on the left tree? */
777 if (dir->d_back == dir->d_back->d_back->d_left) {
778 node = dir->d_back->d_back->d_right; /* get the right node */
779 if (node->d_color == DIRTREE_COLOR_RED) {
780 /* we're red. we need to change to black. */
781 dir->d_back->d_color = DIRTREE_COLOR_BLACK;
782 node->d_color = DIRTREE_COLOR_BLACK;
783 dir->d_back->d_back->d_color = DIRTREE_COLOR_RED;
784 dir = dir->d_back->d_back; /* finished. go up. */
786 if (dir == dir->d_back->d_right) {
788 dir_leftrotate(vol, dir);
790 dir->d_back->d_color = DIRTREE_COLOR_BLACK;
791 dir->d_back->d_back->d_color = DIRTREE_COLOR_RED;
792 dir_rightrotate(vol, dir->d_back->d_back);
795 node = dir->d_back->d_back->d_left;
796 if (node->d_color == DIRTREE_COLOR_RED) {
797 /* we're red. we need to change to black. */
798 dir->d_back->d_color = DIRTREE_COLOR_BLACK;
799 node->d_color = DIRTREE_COLOR_BLACK;
800 dir->d_back->d_back->d_color = DIRTREE_COLOR_RED;
801 dir = dir->d_back->d_back; /* finished. ascend */
803 if (dir == dir->d_back->d_left) {
805 dir_rightrotate(vol, dir);
807 dir->d_back->d_color = DIRTREE_COLOR_BLACK;
808 dir->d_back->d_back->d_color = DIRTREE_COLOR_RED;
809 dir_leftrotate(vol, dir->d_back->d_back);
814 vol->v_root->d_color = DIRTREE_COLOR_BLACK;
818 /* free everything down. we don't bother to recolor as this is only
819 * called to free the entire tree */
823 if (!dir || (dir == SENTINEL))
826 if ( dir->d_left != SENTINEL ) {
827 dirfree( dir->d_left );
829 if ( dir->d_right != SENTINEL ) {
830 dirfree( dir->d_right );
833 if (dir != SENTINEL) {
834 if (dir->d_u_name != dir->d_m_name) {
842 /* --------------------------------------------
843 * most of the time mac name and unix name are the same
845 struct dir *dirnew(const char *m_name, const char *u_name)
849 dir = (struct dir *) calloc(1, sizeof( struct dir ));
853 if ((dir->d_m_name = strdup(m_name)) == NULL) {
858 if (m_name == u_name) {
859 dir->d_u_name = dir->d_m_name;
861 else if ((dir->d_u_name = strdup(u_name)) == NULL) {
867 dir->d_left = dir->d_right = SENTINEL;
868 dir->d_next = dir->d_prev = dir;
872 /* -------------------------------------------------- */
878 stat the file or errno
881 curdir: filename parent directory
887 stat the dir or errno
891 curdir: dir parent directory
899 curdir: dir parent directory
906 cname( vol, dir, cpath )
907 const struct vol *vol;
912 static char path[ MAXPATHLEN + 1];
913 static struct path ret;
924 afp_errno = AFPERR_NOOBJ;
925 switch (ret.m_type = *data) { /* path type */
928 len = (unsigned char) *data++;
933 if (afp_version >= 30) {
935 memcpy(&hint, data, sizeof(hint));
937 data += sizeof(hint);
939 memcpy(&len16, data, sizeof(len16));
946 /* else it's an error */
948 afp_errno = AFPERR_PARAM;
952 *cpath += len + size;
959 if (movecwd( vol, dir ) < 0 ) {
961 movecwd failed some of dir path are not there anymore.
962 FIXME Is it true with other errors?
963 so we remove dir from the cache
965 if (dir->d_did == DIRDID_ROOT_PARENT)
967 if (afp_errno == AFPERR_ACCESS) {
968 if ( movecwd( vol, dir->d_parent ) < 0 ) {
971 ret.m_name = dir->d_m_name;
972 ret.u_name = dir->d_u_name;
976 dir_invalidate(vol, dir);
989 while (*data == sep && len > 0 ) {
990 if ( dir->d_parent == NULL ) {
998 /* would this be faster with strlen + strncpy? */
1000 while ( *data != sep && len > 0 ) {
1005 /* short cut bits by chopping off a trailing \0. this also
1006 makes the traversal happy w/ filenames at the end of the
1013 if ( p != path ) { /* we got something */
1015 cdir = dir->d_child;
1017 if ( strcmp( cdir->d_m_name, path ) == 0 ) {
1020 cdir = (cdir == dir->d_child->d_prev) ? NULL :
1023 if ( cdir == NULL ) {
1025 /* if dir == curdir it always succeed,
1026 even if curdir is deleted.
1027 it's not a pb because it will fail in extenddir
1029 if ( movecwd( vol, dir ) < 0 ) {
1030 /* dir is not valid anymore
1031 we delete dir from the cache and abort.
1033 if ( dir->d_did == DIRDID_ROOT_PARENT)
1035 if (afp_errno == AFPERR_ACCESS)
1037 dir_invalidate(vol, dir);
1040 cdir = extenddir( vol, dir, &ret );
1044 cdir = extenddir( vol, dir, &ret );
1047 if ( cdir == NULL ) {
1062 * Move curdir to dir, with a possible chdir()
1064 int movecwd( vol, dir)
1065 const struct vol *vol;
1068 char path[MAXPATHLEN + 1];
1073 if ( dir == curdir ) {
1076 if ( dir->d_did == DIRDID_ROOT_PARENT) {
1077 afp_errno = AFPERR_PARAM;
1081 p = path + sizeof(path) - 1;
1084 for ( d = dir; d->d_parent != NULL && d != curdir; d = d->d_parent ) {
1087 if (p -n -1 < path) {
1088 afp_errno = AFPERR_PARAM;
1095 if ( d != curdir ) {
1096 n = strlen( vol->v_path );
1097 if (p -n -1 < path) {
1098 afp_errno = AFPERR_PARAM;
1103 strncpy( p, vol->v_path, n );
1105 if ( chdir( p ) < 0 ) {
1109 afp_errno = AFPERR_ACCESS;
1112 afp_errno = AFPERR_NOOBJ;
1122 * We can't use unix file's perm to support Apple's inherited protection modes.
1123 * If we aren't the file's owner we can't change its perms when moving it and smb
1124 * nfs,... don't even try.
1126 #define AFP_CHECK_ACCESS
1128 int check_access(char *path, int mode)
1130 #ifdef AFP_CHECK_ACCESS
1138 accessmode(p, &ma, curdir, NULL);
1139 if ((mode & OPENACC_WR) && !(ma.ma_user & AR_UWRITE))
1141 if ((mode & OPENACC_RD) && !(ma.ma_user & AR_UREAD))
1147 /* ------------------------------
1149 (name, dir) with curdir:name == dir, from afp_enumerate
1152 int getdirparams(const struct vol *vol,
1153 u_int16_t bitmap, struct path *s_path,
1155 char *buf, int *buflen )
1159 char *data, *l_nameoff = NULL, *utf_nameoff = NULL;
1160 int bit = 0, isad = 0;
1165 struct stat *st = &s_path->st;
1166 char *upath = s_path->u_name;
1168 if ((bitmap & ((1 << DIRPBIT_ATTR) |
1169 (1 << DIRPBIT_CDATE) |
1170 (1 << DIRPBIT_MDATE) |
1171 (1 << DIRPBIT_BDATE) |
1172 (1 << DIRPBIT_FINFO)))) {
1173 memset(&ad, 0, sizeof(ad));
1174 if ( !ad_open( upath, ADFLAGS_HF|ADFLAGS_DIR, O_RDONLY,
1175 DIRBITS | 0777, &ad)) {
1181 while ( bitmap != 0 ) {
1182 while (( bitmap & 1 ) == 0 ) {
1190 ad_getattr(&ad, &ashort);
1191 } else if (*upath == '.' && strcmp(upath, ".") &&
1192 strcmp(upath, "..")) {
1193 ashort = htons(ATTRBIT_INVISIBLE);
1196 ashort |= htons(ATTRBIT_SHARED);
1197 memcpy( data, &ashort, sizeof( ashort ));
1198 data += sizeof( ashort );
1202 if ( dir->d_did == DIRDID_ROOT) {
1203 aint = DIRDID_ROOT_PARENT;
1204 } else if (dir->d_did == DIRDID_ROOT_PARENT) {
1207 aint = dir->d_parent->d_did;
1209 memcpy( data, &aint, sizeof( aint ));
1210 data += sizeof( aint );
1213 case DIRPBIT_CDATE :
1214 if (!isad || (ad_getdate(&ad, AD_DATE_CREATE, &aint) < 0))
1215 aint = AD_DATE_FROM_UNIX(st->st_mtime);
1216 memcpy( data, &aint, sizeof( aint ));
1217 data += sizeof( aint );
1220 case DIRPBIT_MDATE :
1221 aint = AD_DATE_FROM_UNIX(st->st_mtime);
1222 memcpy( data, &aint, sizeof( aint ));
1223 data += sizeof( aint );
1226 case DIRPBIT_BDATE :
1227 if (!isad || (ad_getdate(&ad, AD_DATE_BACKUP, &aint) < 0))
1228 aint = AD_DATE_START;
1229 memcpy( data, &aint, sizeof( aint ));
1230 data += sizeof( aint );
1233 case DIRPBIT_FINFO :
1235 memcpy( data, ad_entry( &ad, ADEID_FINDERI ), 32 );
1236 } else { /* no appledouble */
1237 memset( data, 0, 32 );
1238 /* set default view -- this also gets done in ad_open() */
1239 ashort = htons(FINDERINFO_CLOSEDVIEW);
1240 memcpy(data + FINDERINFO_FRVIEWOFF, &ashort, sizeof(ashort));
1242 /* dot files are by default invisible */
1243 if (*upath == '.' && strcmp(upath, ".") &&
1244 strcmp(upath, "..")) {
1245 ashort = htons(FINDERINFO_INVISIBLE);
1246 memcpy(data + FINDERINFO_FRFLAGOFF,
1247 &ashort, sizeof(ashort));
1253 case DIRPBIT_LNAME :
1254 if (dir->d_m_name) /* root of parent can have a null name */
1257 memset(data, 0, sizeof(u_int16_t));
1258 data += sizeof( u_int16_t );
1261 case DIRPBIT_SNAME :
1262 memset(data, 0, sizeof(u_int16_t));
1263 data += sizeof( u_int16_t );
1267 memcpy( data, &dir->d_did, sizeof( aint ));
1268 data += sizeof( aint );
1271 case DIRPBIT_OFFCNT :
1273 /* this needs to handle current directory access rights */
1274 if (st->st_ctime == dir->ctime) {
1275 ashort = dir->offcnt;
1277 else if ((ret = for_each_dirent(vol, upath, NULL,NULL)) >= 0) {
1279 dir->offcnt = ashort;
1280 dir->ctime = st->st_ctime;
1282 ashort = htons( ashort );
1283 memcpy( data, &ashort, sizeof( ashort ));
1284 data += sizeof( ashort );
1288 aint = htonl(st->st_uid);
1289 memcpy( data, &aint, sizeof( aint ));
1290 data += sizeof( aint );
1294 aint = htonl(st->st_gid);
1295 memcpy( data, &aint, sizeof( aint ));
1296 data += sizeof( aint );
1299 case DIRPBIT_ACCESS :
1300 accessmode( upath, &ma, dir , st);
1302 *data++ = ma.ma_user;
1303 *data++ = ma.ma_world;
1304 *data++ = ma.ma_group;
1305 *data++ = ma.ma_owner;
1308 /* Client has requested the ProDOS information block.
1309 Just pass back the same basic block for all
1310 directories. <shirsch@ibm.net> */
1311 case DIRPBIT_PDINFO :
1312 if (afp_version >= 30) { /* UTF8 name */
1313 utf8 = kTextEncodingUTF8;
1314 if (dir->d_m_name) /* root of parent can have a null name */
1317 memset(data, 0, sizeof(u_int16_t));
1318 data += sizeof( u_int16_t );
1320 memcpy(data, &aint, sizeof( aint ));
1321 data += sizeof( aint );
1323 else { /* ProDOS Info Block */
1326 ashort = htons( 0x0200 );
1327 memcpy( data, &ashort, sizeof( ashort ));
1328 data += sizeof( ashort );
1329 memset( data, 0, sizeof( ashort ));
1330 data += sizeof( ashort );
1336 ad_close( &ad, ADFLAGS_HF );
1338 return( AFPERR_BITMAP );
1344 ashort = htons( data - buf );
1345 memcpy( l_nameoff, &ashort, sizeof( ashort ));
1346 data = set_name(data, dir->d_m_name, 0);
1348 if ( utf_nameoff ) {
1349 ashort = htons( data - buf );
1350 memcpy( utf_nameoff, &ashort, sizeof( ashort ));
1351 data = set_name(data, dir->d_m_name, utf8);
1354 ad_close( &ad, ADFLAGS_HF );
1356 *buflen = data - buf;
1360 /* ----------------------------- */
1361 int afp_setdirparams(obj, ibuf, ibuflen, rbuf, rbuflen )
1364 int ibuflen, *rbuflen;
1369 u_int16_t vid, bitmap;
1375 memcpy( &vid, ibuf, sizeof( vid ));
1376 ibuf += sizeof( vid );
1378 if (NULL == ( vol = getvolbyvid( vid )) ) {
1379 return( AFPERR_PARAM );
1382 if (vol->v_flags & AFPVOL_RO)
1383 return AFPERR_VLOCK;
1385 memcpy( &did, ibuf, sizeof( did ));
1386 ibuf += sizeof( int );
1388 if (NULL == ( dir = dirlookup( vol, did )) ) {
1392 memcpy( &bitmap, ibuf, sizeof( bitmap ));
1393 bitmap = ntohs( bitmap );
1394 ibuf += sizeof( bitmap );
1396 if (NULL == ( path = cname( vol, dir, &ibuf )) ) {
1400 /* FIXME access error or not a file */
1401 if ( *path->m_name != '\0' ) {
1402 return (path_isadir( path))? afp_errno:AFPERR_BADTYPE ;
1406 * If ibuf is odd, make it even.
1408 if ((u_long)ibuf & 1 ) {
1412 if (AFP_OK == ( rc = setdirparams(vol, path, bitmap, ibuf )) ) {
1413 setvoltime(obj, vol );
1419 * cf AFP3.0.pdf page 244 for change_mdate and change_parent_mdate logic
1421 * assume path == '\0' eg. it's a directory in canonical form
1424 struct path Cur_Path = {
1427 ".", /* unix name */
1428 0, /* stat is not set */
1432 int setdirparams(const struct vol *vol,
1433 struct path *path, u_int16_t bitmap, char *buf )
1441 int bit = 0, aint, isad = 1;
1442 u_int16_t ashort, bshort;
1444 int change_mdate = 0;
1445 int change_parent_mdate = 0;
1448 upath = path->u_name;
1449 memset(&ad, 0, sizeof(ad));
1451 if (ad_open( upath, vol_noadouble(vol)|ADFLAGS_HF|ADFLAGS_DIR,
1452 O_RDWR|O_CREAT, 0666, &ad) < 0) {
1454 * Check to see what we're trying to set. If it's anything
1455 * but ACCESS, UID, or GID, give an error. If it's any of those
1456 * three, we don't need the ad to be open, so just continue.
1458 * note: we also don't need to worry about mdate. also, be quiet
1459 * if we're using the noadouble option.
1461 if (!vol_noadouble(vol) && (bitmap &
1462 ~((1<<DIRPBIT_ACCESS)|(1<<DIRPBIT_UID)|(1<<DIRPBIT_GID)|
1463 (1<<DIRPBIT_MDATE)|(1<<DIRPBIT_PDINFO)))) {
1464 return AFPERR_ACCESS;
1470 * Check to see if a create was necessary. If it was, we'll want
1471 * to set our name, etc.
1473 if ( ad_getoflags( &ad, ADFLAGS_HF ) & O_CREAT ) {
1474 ad_setentrylen( &ad, ADEID_NAME, strlen( curdir->d_m_name ));
1475 memcpy( ad_entry( &ad, ADEID_NAME ), curdir->d_m_name,
1476 ad_getentrylen( &ad, ADEID_NAME ));
1480 while ( bitmap != 0 ) {
1481 while (( bitmap & 1 ) == 0 ) {
1490 memcpy( &ashort, buf, sizeof( ashort ));
1491 ad_getattr(&ad, &bshort);
1492 if ( ntohs( ashort ) & ATTRBIT_SETCLR ) {
1493 bshort |= htons( ntohs( ashort ) & ~ATTRBIT_SETCLR );
1497 ad_setattr(&ad, bshort);
1498 if ((ashort & htons(ATTRBIT_INVISIBLE)))
1499 change_parent_mdate = 1;
1501 buf += sizeof( ashort );
1504 case DIRPBIT_CDATE :
1507 memcpy(&aint, buf, sizeof(aint));
1508 ad_setdate(&ad, AD_DATE_CREATE, aint);
1510 buf += sizeof( aint );
1513 case DIRPBIT_MDATE :
1514 memcpy(&newdate, buf, sizeof(newdate));
1515 buf += sizeof( newdate );
1518 case DIRPBIT_BDATE :
1521 memcpy(&aint, buf, sizeof(aint));
1522 ad_setdate(&ad, AD_DATE_BACKUP, aint);
1524 buf += sizeof( aint );
1527 case DIRPBIT_FINFO :
1530 * Alright, we admit it, this is *really* sick!
1531 * The 4 bytes that we don't copy, when we're dealing
1532 * with the root of a volume, are the directory's
1533 * location information. This eliminates that annoying
1534 * behavior one sees when mounting above another mount
1538 if ( curdir->d_did == DIRDID_ROOT ) {
1539 memcpy( ad_entry( &ad, ADEID_FINDERI ), buf, 10 );
1540 memcpy( ad_entry( &ad, ADEID_FINDERI ) + 14, buf + 14, 18 );
1542 memcpy( ad_entry( &ad, ADEID_FINDERI ), buf, 32 );
1548 case DIRPBIT_UID : /* What kind of loser mounts as root? */
1549 change_parent_mdate = 1;
1550 memcpy( &aint, buf, sizeof(aint));
1551 buf += sizeof( aint );
1552 if ( (curdir->d_did == DIRDID_ROOT) &&
1553 (setdeskowner( ntohl(aint), -1 ) < 0)) {
1557 err = AFPERR_ACCESS;
1558 goto setdirparam_done;
1562 goto setdirparam_done;
1565 LOG(log_error, logtype_afpd, "setdirparam: setdeskowner: %s",
1569 goto setdirparam_done;
1574 if ( setdirowner( ntohl(aint), -1, vol_noadouble(vol) ) < 0 ) {
1578 err = AFPERR_ACCESS;
1579 goto setdirparam_done;
1583 goto setdirparam_done;
1586 LOG(log_error, logtype_afpd, "setdirparam: setdirowner: %s",
1593 change_parent_mdate = 1;
1594 memcpy( &aint, buf, sizeof( aint ));
1595 buf += sizeof( aint );
1596 if (curdir->d_did == DIRDID_ROOT)
1597 setdeskowner( -1, ntohl(aint) );
1599 #if 0 /* don't error if we can't set the desktop owner. */
1603 err = AFPERR_ACCESS;
1604 goto setdirparam_done;
1608 goto setdirparam_done;
1611 LOG(log_error, logtype_afpd, "setdirparam: setdeskowner: %m" );
1614 goto setdirparam_done;
1620 if ( setdirowner( -1, ntohl(aint), vol_noadouble(vol) ) < 0 ) {
1624 err = AFPERR_ACCESS;
1625 goto setdirparam_done;
1629 goto setdirparam_done;
1632 LOG(log_error, logtype_afpd, "setdirparam: setdirowner: %s",
1639 case DIRPBIT_ACCESS :
1641 change_parent_mdate = 1;
1642 ma.ma_user = *buf++;
1643 ma.ma_world = *buf++;
1644 ma.ma_group = *buf++;
1645 ma.ma_owner = *buf++;
1647 if (curdir->d_did == DIRDID_ROOT)
1648 setdeskmode(mtoumode( &ma ));
1649 #if 0 /* don't error if we can't set the desktop mode */
1653 err = AFPERR_ACCESS;
1654 goto setdirparam_done;
1657 goto setdirparam_done;
1659 LOG(log_error, logtype_afpd, "setdirparam: setdeskmode: %s",
1663 goto setdirparam_done;
1667 if ( setdirmode( mtoumode( &ma ), vol_noadouble(vol),
1668 (vol->v_flags & AFPVOL_DROPBOX)) < 0 ) {
1672 err = AFPERR_ACCESS;
1673 goto setdirparam_done;
1676 goto setdirparam_done;
1678 LOG(log_error, logtype_afpd, "setdirparam: setdirmode: %s",
1681 goto setdirparam_done;
1686 /* Ignore what the client thinks we should do to the
1687 ProDOS information block. Skip over the data and
1688 report nothing amiss. <shirsch@ibm.net> */
1689 case DIRPBIT_PDINFO :
1690 if (afp_version < 30) {
1695 err = AFPERR_BITMAP;
1696 goto setdirparam_done;
1705 if (change_mdate && newdate == 0 && gettimeofday(&tv, NULL) == 0) {
1706 newdate = AD_DATE_FROM_UNIX(tv.tv_sec);
1710 ad_setdate(&ad, AD_DATE_MODIFY, newdate);
1711 ut.actime = ut.modtime = AD_DATE_TO_UNIX(newdate);
1716 ad_flush( &ad, ADFLAGS_HF );
1717 ad_close( &ad, ADFLAGS_HF );
1720 if (change_parent_mdate && curdir->d_did != DIRDID_ROOT
1721 && gettimeofday(&tv, NULL) == 0) {
1722 if (!movecwd(vol, curdir->d_parent)) {
1723 newdate = AD_DATE_FROM_UNIX(tv.tv_sec);
1724 bitmap = 1<<DIRPBIT_MDATE;
1725 setdirparams(vol, &Cur_Path, bitmap, (char *)&newdate);
1726 /* should we reset curdir ?*/
1733 int afp_createdir(obj, ibuf, ibuflen, rbuf, rbuflen )
1736 int ibuflen, *rbuflen;
1742 struct path *s_path;
1750 memcpy( &vid, ibuf, sizeof( vid ));
1751 ibuf += sizeof( vid );
1752 if (NULL == ( vol = getvolbyvid( vid )) ) {
1753 return( AFPERR_PARAM );
1756 if (vol->v_flags & AFPVOL_RO)
1757 return AFPERR_VLOCK;
1759 memcpy( &did, ibuf, sizeof( did ));
1760 ibuf += sizeof( did );
1761 if (NULL == ( dir = dirlookup( vol, did )) ) {
1762 return afp_errno; /* was AFPERR_NOOBJ */
1765 if (NULL == ( s_path = cname( vol, dir, &ibuf )) ) {
1768 /* cname was able to move curdir to it! */
1769 if (*s_path->m_name == '\0')
1770 return AFPERR_EXIST;
1772 upath = s_path->u_name;
1773 if (0 != (err = check_name(vol, upath))) {
1777 if (AFP_OK != (err = netatalk_mkdir( upath))) {
1781 if (of_stat(s_path) < 0) {
1785 if ((dir = adddir( vol, curdir, s_path)) == NULL) {
1789 if ( movecwd( vol, dir ) < 0 ) {
1790 return( AFPERR_PARAM );
1793 memset(&ad, 0, sizeof(ad));
1794 if (ad_open( ".", vol_noadouble(vol)|ADFLAGS_HF|ADFLAGS_DIR,
1795 O_RDWR|O_CREAT, 0666, &ad ) < 0) {
1796 if (vol_noadouble(vol))
1797 goto createdir_done;
1798 return( AFPERR_ACCESS );
1801 ad_setentrylen( &ad, ADEID_NAME, strlen( s_path->m_name ));
1802 memcpy( ad_entry( &ad, ADEID_NAME ), s_path->m_name,
1803 ad_getentrylen( &ad, ADEID_NAME ));
1804 ad_flush( &ad, ADFLAGS_HF );
1805 ad_close( &ad, ADFLAGS_HF );
1808 memcpy( rbuf, &dir->d_did, sizeof( u_int32_t ));
1809 *rbuflen = sizeof( u_int32_t );
1810 setvoltime(obj, vol );
1815 * dst new unix filename (not a pathname)
1816 * newname new mac name
1820 int renamedir(src, dst, dir, newparent, newname, noadouble)
1821 char *src, *dst, *newname;
1822 struct dir *dir, *newparent;
1823 const int noadouble;
1830 /* existence check moved to afp_moveandrename */
1831 if ( unix_rename( src, dst ) < 0 ) {
1834 return( AFPERR_NOOBJ );
1836 return( AFPERR_ACCESS );
1838 return AFPERR_VLOCK;
1840 /* tried to move directory into a subdirectory of itself */
1841 return AFPERR_CANTMOVE;
1843 /* this needs to copy and delete. bleah. that means we have
1844 * to deal with entire directory hierarchies. */
1845 if ((err = copydir(src, dst, noadouble)) < 0) {
1849 if ((err = deletedir(src)) < 0)
1853 return( AFPERR_PARAM );
1857 memset(&ad, 0, sizeof(ad));
1858 len = strlen( newname );
1859 /* rename() succeeded so we need to update our tree even if we can't open
1862 if ( !ad_open( dst, ADFLAGS_HF|ADFLAGS_DIR, O_RDWR, 0, &ad)) {
1863 ad_setentrylen( &ad, ADEID_NAME, len );
1864 memcpy( ad_entry( &ad, ADEID_NAME ), newname, len );
1865 ad_flush( &ad, ADFLAGS_HF );
1866 ad_close( &ad, ADFLAGS_HF );
1869 if (dir->d_m_name == dir->d_u_name)
1870 dir->d_u_name = NULL;
1872 if ((buf = (char *) realloc( dir->d_m_name, len + 1 )) == NULL ) {
1873 LOG(log_error, logtype_afpd, "renamedir: realloc mac name: %s", strerror(errno) );
1874 /* FIXME : fatal ? */
1877 dir->d_m_name = buf;
1878 strcpy( dir->d_m_name, newname );
1880 if (newname == dst) {
1881 free(dir->d_u_name);
1882 dir->d_u_name = dir->d_m_name;
1885 if ((buf = (char *) realloc( dir->d_u_name, strlen(dst) + 1 )) == NULL ) {
1886 LOG(log_error, logtype_afpd, "renamedir: realloc unix name: %s", strerror(errno) );
1889 dir->d_u_name = buf;
1890 strcpy( dir->d_u_name, dst );
1893 if (( parent = dir->d_parent ) == NULL ) {
1896 if ( parent == newparent ) {
1900 /* detach from old parent and add to new one. */
1901 dirchildremove(parent, dir);
1902 dir->d_parent = newparent;
1903 dirchildadd(newparent, dir);
1907 #define DOT_APPLEDOUBLE_LEN 13
1908 /* delete an empty directory */
1909 int deletecurdir( vol, path, pathlen )
1910 const struct vol *vol;
1922 if ( curdir->d_parent == NULL ) {
1923 return( AFPERR_ACCESS );
1926 if ( curdir->d_child != NULL ) {
1927 return( AFPERR_DIRNEMPT );
1932 memset(&ad, 0, sizeof(ad));
1933 if ( ad_open( ".", ADFLAGS_HF|ADFLAGS_DIR, O_RDONLY,
1934 DIRBITS | 0777, &ad) == 0 ) {
1936 ad_getattr(&ad, &ashort);
1937 ad_close( &ad, ADFLAGS_HF );
1938 if ((ashort & htons(ATTRBIT_NODELETE))) {
1939 return AFPERR_OLOCK;
1943 /* delete stray .AppleDouble files. this happens to get .Parent files
1945 if ((dp = opendir(".AppleDouble"))) {
1946 strcpy(path, ".AppleDouble/");
1947 while ((de = readdir(dp))) {
1948 /* skip this and previous directory */
1949 if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, ".."))
1952 /* bail if the file exists in the current directory.
1953 * note: this will not fail with dangling symlinks */
1954 if (stat(de->d_name, &st) == 0) {
1956 return AFPERR_DIRNEMPT;
1959 strcpy(path + DOT_APPLEDOUBLE_LEN, de->d_name);
1960 if ((err = netatalk_unlink(path))) {
1968 if ( (err = netatalk_rmdir( ".AppleDouble" )) ) {
1972 /* now get rid of dangling symlinks */
1973 if ((dp = opendir("."))) {
1974 while ((de = readdir(dp))) {
1975 /* skip this and previous directory */
1976 if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, ".."))
1979 /* bail if it's not a symlink */
1980 if ((lstat(de->d_name, &st) == 0) && !S_ISLNK(st.st_mode)) {
1982 return AFPERR_DIRNEMPT;
1985 if ((err = netatalk_unlink(de->d_name))) {
1993 if ( movecwd( vol, curdir->d_parent ) < 0 ) {
1997 if ( (err = netatalk_rmdir(fdir->d_u_name))) {
2001 dirchildremove(curdir, fdir);
2003 cnid_delete(vol->v_db, fdir->d_did);
2004 #endif /* CNID_DB */
2005 dir_remove( vol, fdir );
2010 int afp_mapid(obj, ibuf, ibuflen, rbuf, rbuflen )
2013 int ibuflen, *rbuflen;
2023 sfunc = (unsigned char) *ibuf++;
2024 memcpy( &id, ibuf, sizeof( id ));
2032 case 3 :/* unicode */
2033 if (( pw = getpwuid( id )) == NULL ) {
2034 return( AFPERR_NOITEM );
2040 case 4 : /* unicode */
2041 if (( gr = (struct group *)getgrgid( id )) == NULL ) {
2042 return( AFPERR_NOITEM );
2048 return( AFPERR_PARAM );
2053 if (afp_version < 30) {
2054 return( AFPERR_PARAM );
2057 /* map to unicode */
2060 len = strlen( name );
2067 u_int16_t tp = htons(len);
2068 memcpy(rbuf, &tp, sizeof(tp));
2077 memcpy( rbuf, name, len );
2083 int afp_mapname(obj, ibuf, ibuflen, rbuf, rbuflen )
2086 int ibuflen, *rbuflen;
2095 sfunc = (unsigned char) *ibuf++;
2098 case 2 : /* unicode */
2099 memcpy(&ulen, ibuf, sizeof(ulen));
2105 len = (unsigned char) *ibuf++;
2109 return( AFPERR_PARAM );
2116 case 1 : /* unicode */
2118 if (( pw = (struct passwd *)getpwnam( ibuf )) == NULL ) {
2120 return( AFPERR_NOITEM );
2125 case 2 : /* unicode */
2127 if (( gr = (struct group *)getgrnam( ibuf )) == NULL ) {
2129 return( AFPERR_NOITEM );
2138 memcpy( rbuf, &id, sizeof( id ));
2139 *rbuflen = sizeof( id );
2143 /* ------------------------------------
2144 variable DID support
2146 int afp_closedir(obj, ibuf, ibuflen, rbuf, rbuflen )
2149 int ibuflen, *rbuflen;
2160 /* do nothing as dids are static for the life of the process. */
2164 memcpy(&vid, ibuf, sizeof( vid ));
2165 ibuf += sizeof( vid );
2166 if (( vol = getvolbyvid( vid )) == NULL ) {
2167 return( AFPERR_PARAM );
2170 memcpy( &did, ibuf, sizeof( did ));
2171 ibuf += sizeof( did );
2172 if (( dir = dirlookup( vol, did )) == NULL ) {
2173 return( AFPERR_PARAM );
2176 /* dir_remove -- deletedid */
2182 /* did creation gets done automatically
2183 * there's a pb again with case but move it to cname
2185 int afp_opendir(obj, ibuf, ibuflen, rbuf, rbuflen )
2188 int ibuflen, *rbuflen;
2191 struct dir *parentdir;
2199 memcpy(&vid, ibuf, sizeof(vid));
2200 ibuf += sizeof( vid );
2202 if (NULL == ( vol = getvolbyvid( vid )) ) {
2203 return( AFPERR_PARAM );
2206 memcpy(&did, ibuf, sizeof(did));
2207 ibuf += sizeof(did);
2209 if (NULL == ( parentdir = dirlookup( vol, did )) ) {
2213 if (NULL == ( path = cname( vol, parentdir, &ibuf )) ) {
2217 if ( *path->m_name != '\0' ) {
2218 return (path_isadir(path))? afp_errno:AFPERR_BADTYPE ;
2221 if ( !path->st_valid && of_stat(path ) < 0 ) {
2222 return( AFPERR_NOOBJ );
2224 if ( path->st_errno ) {
2225 return( AFPERR_NOOBJ );
2228 memcpy(rbuf, &curdir->d_did, sizeof(curdir->d_did));
2229 *rbuflen = sizeof(curdir->d_did);