+ struct adouble *adp;
+ struct ofork *opened = NULL;
+ struct path path;
+#ifdef CNID_DB
+ cnid_t id;
+#endif /* CNID_DB */
+
+ memset(&ad, 0, sizeof(ad));
+ adp = &ad;
+ adflags = 0;
+
+ if (!isdir) {
+#ifdef CNID_DB
+ p = mtoupath(vol, oldname);
+ id = cnid_get(vol->v_db, sdir->d_did, p, strlen(p));
+#endif /* CNID_DB */
+ p = ctoupath( vol, sdir, oldname );
+ path.st_valid = 0;
+ path.u_name = p;
+ if ((opened = of_findname(&path))) {
+ /* reuse struct adouble so it won't break locks */
+ adp = opened->of_ad;
+ }
+ }
+ else {
+#ifdef CNID_DB
+ id = sdir->d_did; /* we already have the CNID */
+#endif /* CNID_DB */
+ p = ctoupath( vol, sdir->d_parent, oldname );
+ adflags = ADFLAGS_DIR;
+ }
+ /*
+ * p now points to the full pathname of the source fs object.
+ *
+ * we are in the dest folder so we need to use p for ad_open
+ */
+
+ if (!ad_open(p, ADFLAGS_HF |adflags, O_RDONLY, 0666, adp)) {
+ u_int16_t bshort;
+
+ ad_getattr(adp, &bshort);
+ ad_close( adp, ADFLAGS_HF );
+ if ((bshort & htons(ATTRBIT_NORENAME)))
+ return(AFPERR_OLOCK);
+ }
+
+ upath = mtoupath(vol, newname);
+ path.u_name = upath;
+ st = &path.st;
+ if (0 != (rc = check_name(vol, upath))) {
+ return rc;
+ }
+
+ /* source == destination. we just silently accept this. */
+ if (curdir == sdir) {
+ if (strcmp(oldname, newname) == 0)
+ return AFP_OK;
+
+ /* deal with case insensitive, case-preserving filesystems. */
+ if ((stat(upath, st) == 0) && strdiacasecmp(oldname, newname))
+ return AFPERR_EXIST;
+
+ } else if (stat(upath, st ) == 0)
+ return AFPERR_EXIST;
+
+ if ( !isdir ) {
+ path.st_valid = 1;
+ path.st_errno = errno;
+ if (of_findname(&path)) {
+ rc = AFPERR_EXIST; /* was AFPERR_BUSY; */
+ } else {
+ rc = renamefile( p, upath, newname,vol_noadouble(vol), adp );
+ if (rc == AFP_OK)
+ of_rename(vol, opened, sdir, oldname, curdir, newname);
+ }
+ } else {
+ rc = renamedir(p, upath, sdir, curdir, newname, vol_noadouble(vol));
+ }
+ if ( rc == AFP_OK ) {