+ if (NULL == (upath = mtoupath(vol, newname, curdir->d_did, utf8_encoding()))){
+ return AFPERR_PARAM;
+ }
+ path.u_name = upath;
+ st = &path.st;
+ if (0 != (rc = check_name(vol, upath))) {
+ return rc;
+ }
+
+ /* source == destination. we just silently accept this. */
+ if ((!isdir && curdir == sdir) || (isdir && curdir == sdir->d_parent)) {
+ if (strcmp(oldname, newname) == 0)
+ return AFP_OK;
+
+ if (stat(upath, st) == 0 || caseenumerate(vol, &path, curdir) == 0) {
+ if (!stat(p, &nst) && !(nst.st_dev == st->st_dev && nst.st_ino == st->st_ino) ) {
+ /* not the same file */
+ return AFPERR_EXIST;
+ }
+ errno = 0;
+ }
+ } else if (stat(upath, st ) == 0 || caseenumerate(vol, &path, curdir) == 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(vol, p, upath, newname, adp );
+ if (rc == AFP_OK)
+ of_rename(vol, opened, sdir, oldname, curdir, newname);
+ }
+ } else {
+ rc = renamedir(vol, p, upath, sdir, curdir, newname);
+ }
+ if ( rc == AFP_OK && id ) {
+ /* renaming may have moved the file/dir across a filesystem */
+ if (stat(upath, st) < 0)
+ return AFPERR_MISC;
+
+ /* fix up the catalog entry */
+ cnid_update(vol->v_cdb, id, st, curdir->d_did, upath, strlen(upath));
+ }
+
+ return rc;
+}
+
+/* -------------------------------------------- */
+int afp_rename(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf _U_, size_t *rbuflen)
+{
+ struct vol *vol;
+ struct dir *sdir;
+ char *oldname, *newname;
+ struct path *path;
+ u_int32_t did;
+ int plen;
+ u_int16_t vid;
+ int isdir = 0;
+ int rc;