Thread: [Libsysio-commit] HEAD: libsysio/src rename.c
Brought to you by:
lward
From: Lee W. <lw...@us...> - 2003-10-13 21:23:48
|
Update of /cvsroot/libsysio/libsysio/src In directory sc8-pr-cvs1:/tmp/cvs-serv10077/src Modified Files: rename.c Log Message: Crafted new test for rename call. Fixed a few bugs in rename: Path node parent at root is NULL, not a cycle. Check for cross device renames, not simple cross mount. Check to make sure that that the source is not covered and that neither the source nor the destination is a mountpoint. Index: rename.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/rename.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -w -b -B -p -r1.1 -r1.2 --- rename.c 27 Sep 2003 19:42:03 -0000 1.1 +++ rename.c 13 Oct 2003 21:23:44 -0000 1.2 @@ -78,9 +78,15 @@ rename(const char *oldpath, const char * if (err && !new) goto error2; - if (old->p_mount->mnt_root != new->p_mount->mnt_root) { + if (old->p_mount->mnt_root == old || old->p_cover || + new->p_mount->mnt_root == new) { + err = -EBUSY; + goto error1; + } + + if (old->p_mount->mnt_fs != new->p_mount->mnt_fs) { /* - * Oops. They're trying to move it across mounts. + * Oops. They're trying to move it across file systems. */ err = -EXDEV; goto error1; @@ -99,7 +105,7 @@ rename(const char *oldpath, const char * err = -EINVAL; goto error1; } - } while (pb != nxtpb); + } while (nxtpb); while (new->p_base->pb_ino) { /* @@ -134,6 +140,7 @@ rename(const char *oldpath, const char * err = -EEXIST; goto error1; } + break; } /* |
From: Lee W. <lw...@us...> - 2004-08-09 14:30:10
|
Update of /cvsroot/libsysio/libsysio/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9459 Modified Files: rename.c Log Message: From Cray SPR_729681, Sue Kelly, and Kevin Pedretti: A long file name given as target causes a seg fault. The error condition check included the returned "new" pnode. This was not being altered in the path lookup, so contained garbage. That would allow the routine to proceed, dereferencing the garbage pointer. Fixed. Index: rename.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/rename.c,v retrieving revision 1.7 retrieving revision 1.8 diff -u -w -b -B -p -r1.7 -r1.8 --- rename.c 27 Jul 2004 15:00:48 -0000 1.7 +++ rename.c 9 Aug 2004 14:30:00 -0000 1.8 @@ -77,7 +77,7 @@ SYSIO_INTERFACE_NAME(rename)(const char */ INTENT_INIT(&intent, INT_UPDPARENT, NULL, NULL); err = _sysio_namei(_sysio_cwd, newpath, ND_NEGOK, &intent, &new); - if (err && !new) + if (err) goto error2; if (old->p_mount->mnt_root == old || old->p_cover || |
From: Lee W. <lw...@us...> - 2004-08-26 09:03:11
|
Update of /cvsroot/libsysio/libsysio/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20651 Modified Files: rename.c Log Message: Fixed many bugs in rename. This is a complex function. Should be right now. I was carefuly this time. Really, I promise :-) Index: rename.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/rename.c,v retrieving revision 1.8 retrieving revision 1.9 diff -u -w -b -B -p -r1.8 -r1.9 --- rename.c 9 Aug 2004 14:30:00 -0000 1.8 +++ rename.c 26 Aug 2004 09:03:03 -0000 1.9 @@ -65,18 +65,30 @@ SYSIO_INTERFACE_NAME(rename)(const char SYSIO_INTERFACE_DISPLAY_BLOCK; SYSIO_INTERFACE_ENTER; + + /* + * Neither old nor new may be the empty string. + */ + if (*oldpath == '\0' || *newpath == '\0') + SYSIO_INTERFACE_RETURN(-1, -ENOENT); + /* * Resolve oldpath to a path node. */ INTENT_INIT(&intent, INT_UPDPARENT, NULL, NULL); - err = _sysio_namei(_sysio_cwd, oldpath, 0, &intent, &old); + err = _sysio_namei(_sysio_cwd, oldpath, ND_NOFOLLOW, &intent, &old); if (err) goto error3; /* * Resolve newpath to a path node. */ INTENT_INIT(&intent, INT_UPDPARENT, NULL, NULL); - err = _sysio_namei(_sysio_cwd, newpath, ND_NEGOK, &intent, &new); + err = + _sysio_namei(_sysio_cwd, + newpath, + ND_NOFOLLOW | ND_NEGOK, + &intent, + &new); if (err) goto error2; @@ -109,6 +121,12 @@ SYSIO_INTERFACE_NAME(rename)(const char } } while (nxtpb); + /* + * If old == new, we're done. + */ + if (old->p_base->pb_ino == new->p_base->pb_ino) + goto out; + while (new->p_base->pb_ino) { /* * Existing entry. We're replacing the new. Make sure that's @@ -129,17 +147,17 @@ SYSIO_INTERFACE_NAME(rename)(const char (void )_sysio_p_validate(new, NULL, NULL); continue; } - if (S_ISDIR(ostbuf.st_mode)) { - if (!S_ISDIR(nstbuf.st_mode)) { - err = -ENOTDIR; + if (S_ISDIR(nstbuf.st_mode)) { + if (!S_ISDIR(ostbuf.st_mode)) { + err = -EISDIR; goto error1; } if (nstbuf.st_nlink > 2) { err = -ENOTEMPTY; goto error1; } - } else if (S_ISDIR(nstbuf.st_mode)) { - err = -EEXIST; + } else if (S_ISDIR(ostbuf.st_mode)) { + err = -ENOTDIR; goto error1; } break; @@ -151,7 +169,7 @@ SYSIO_INTERFACE_NAME(rename)(const char * now. If it becomes an issue, we can do it later. For now, I've * elected to use the semantic that says, basically, the entire * sub-tree must be unreferenced. That's per POSIX, but it's a nasty - * this to do to the caller. + * thing to do to the caller. */ if (_sysio_p_prune(new) != 1) { err = -EBUSY; |
From: Lee W. <lw...@us...> - 2007-03-15 02:53:38
|
Update of /cvsroot/libsysio/libsysio/src In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv19858/src Modified Files: rename.c Log Message: Fixed a bug in rename, reported by Cray (SPR 737687), when a file is renamed to a hard link of itself. I.e.: link old, new rename old, new The rename function was not releasing the pnodes when it detected the source and target were the same. Index: rename.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/rename.c,v retrieving revision 1.11 retrieving revision 1.12 diff -u -w -b -B -p -r1.11 -r1.12 --- rename.c 25 Jan 2005 18:56:15 -0000 1.11 +++ rename.c 15 Mar 2007 02:53:34 -0000 1.12 @@ -127,7 +127,7 @@ SYSIO_INTERFACE_NAME(rename)(const char * If old == new, we're done. */ if (old->p_base->pb_ino == new->p_base->pb_ino) - goto out; + goto short_out; if (new->p_base->pb_ino) { /* @@ -175,8 +175,10 @@ SYSIO_INTERFACE_NAME(rename)(const char if (new->p_base->pb_ino) I_GONE(new->p_base->pb_ino); new->p_base->pb_ino = old->p_base->pb_ino; + old->p_base->pb_ino = NULL; I_REF(new->p_base->pb_ino); +short_out: error1: P_RELE(new); error2: @@ -184,7 +186,6 @@ error2: error3: if (err) goto out; - _sysio_p_gone(old); /* kill it! */ out: SYSIO_INTERFACE_RETURN(err ? -1 : 0, err); } |