[Libsysio-commit] unification: libsysio/src unlink.c rmdir.c rename.c
Brought to you by:
lward
From: Lee W. <lw...@us...> - 2007-04-11 20:48:38
|
Update of /cvsroot/libsysio/libsysio/src In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv26755 Modified Files: Tag: unification unlink.c rmdir.c rename.c Log Message: New internal function supoprting this operation motivated significant change. Now, we just call namei to get path nodes and pass the buck. Index: unlink.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/unlink.c,v retrieving revision 1.18.2.2 retrieving revision 1.18.2.3 diff -u -w -b -B -p -r1.18.2.2 -r1.18.2.3 --- unlink.c 10 Apr 2007 21:25:31 -0000 1.18.2.2 +++ unlink.c 11 Apr 2007 20:48:35 -0000 1.18.2.3 @@ -63,26 +63,23 @@ SYSIO_INTERFACE_NAME(unlink)(const char SYSIO_INTERFACE_DISPLAY_BLOCK; SYSIO_INTERFACE_ENTER(unlink, path); + do { INTENT_INIT(&intent, INT_UPDPARENT, NULL, NULL); - err = _sysio_namei(_sysio_cwd, path, ND_NOFOLLOW, &intent, &pno); - if (err) - goto out; - + err = + _sysio_namei(_sysio_cwd, path, ND_NOFOLLOW, &intent, &pno); + if (err) { + pno = NULL; + break; + } err = _sysio_permitted(pno->p_parent, W_OK); if (err) - goto error; - - err = PNOP_UNLINK(pno); + break; + err = _sysio_p_unlink(pno); if (err) - goto error; - /* - * Disconnect the newly removed node from the graph. - */ - _sysio_pb_disconnect(pno->p_base); - -error: + break; + } while (0); + if (pno) P_RELE(pno); -out: SYSIO_INTERFACE_RETURN(err ? -1 : 0, err, unlink, 0); } Index: rmdir.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/rmdir.c,v retrieving revision 1.20.2.2 retrieving revision 1.20.2.3 diff -u -w -b -B -p -r1.20.2.2 -r1.20.2.3 --- rmdir.c 10 Apr 2007 21:25:31 -0000 1.20.2.2 +++ rmdir.c 11 Apr 2007 20:48:35 -0000 1.20.2.3 @@ -63,31 +63,22 @@ SYSIO_INTERFACE_NAME(rmdir)(const char * SYSIO_INTERFACE_DISPLAY_BLOCK; SYSIO_INTERFACE_ENTER(rmdir, path); + do { INTENT_INIT(&intent, INT_UPDPARENT, NULL, NULL); err = _sysio_namei(_sysio_cwd, path, 0, &intent, &pno); - if (err) - goto out; - if (!S_ISDIR(pno->p_base->pb_ino->i_stbuf.st_mode)) { - err = -ENOTDIR; - goto error; + if (err) { + pno = NULL; + break; } err = _sysio_permitted(pno->p_parent, W_OK); if (err) - goto error; - if (pno->p_ref > 1) { - err = -EBUSY; - goto error; - } - err = PNOP_RMDIR(pno); + break; + err = _sysio_p_rmdir(pno); if (err) - goto error; - /* - * Disconnect the path node from the existing graph. - */ - _sysio_pb_disconnect(pno->p_base); -error: + break; + } while (0); + if (pno) P_RELE(pno); -out: SYSIO_INTERFACE_RETURN(err ? -1 : 0, err, rmdir, 0); } Index: rename.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/rename.c,v retrieving revision 1.11.4.2 retrieving revision 1.11.4.3 diff -u -w -b -B -p -r1.11.4.2 -r1.11.4.3 --- rename.c 10 Apr 2007 21:25:31 -0000 1.11.4.2 +++ rename.c 11 Apr 2007 20:48:35 -0000 1.11.4.3 @@ -36,7 +36,7 @@ * Lee Ward * Sandia National Laboratories, New Mexico * P.O. Box 5800 - * Albuquerque, NM 87185-1110 + * Albuquerque, NM 87185-1319 * * le...@sa... */ @@ -60,7 +60,6 @@ SYSIO_INTERFACE_NAME(rename)(const char struct intent intent; int err; struct pnode *old, *new; - struct pnode_base *nxtpb, *pb; SYSIO_INTERFACE_DISPLAY_BLOCK; SYSIO_INTERFACE_ENTER(rename, oldpath, newpath); @@ -71,13 +70,17 @@ SYSIO_INTERFACE_NAME(rename)(const char if (*oldpath == '\0' || *newpath == '\0') SYSIO_INTERFACE_RETURN(-1, -ENOENT, rename, 0); + old = new = NULL; + do { /* * Resolve oldpath to a path node. */ INTENT_INIT(&intent, INT_UPDPARENT, NULL, NULL); err = _sysio_namei(_sysio_cwd, oldpath, ND_NOFOLLOW, &intent, &old); - if (err) - goto error3; + if (err) { + old = NULL; + break; + } /* * Resolve newpath to a path node. */ @@ -88,97 +91,17 @@ SYSIO_INTERFACE_NAME(rename)(const char ND_NOFOLLOW | ND_NEGOK, &intent, &new); - if (err) - goto error2; - - /* - * Don't allow mount points to move. - */ - if (old->p_mount->mnt_root == old || old->p_cover || - new->p_mount->mnt_root == new) { - err = -EBUSY; - goto error1; + if (err) { + new = NULL; + break; } - /* - * No xdev renames either. - */ - if (old->p_mount->mnt_fs != new->p_mount->mnt_fs) { - err = -EXDEV; - goto error1; - } - - /* - * Make sure the old pnode can't be found in the ancestor chain - * for the new. If it can, they are trying to move into a subdirectory - * of the old. - */ - nxtpb = new->p_base; - do { - pb = nxtpb; - nxtpb = pb->pb_parent; - if (pb == old->p_base) { - err = -EINVAL; - goto error1; - } - } while (nxtpb); - - /* - * If old == new, we're done. - */ - if (old->p_base->pb_ino == new->p_base->pb_ino) - goto out; - - if (new->p_base->pb_ino) { - /* - * Existing entry. We're replacing the new. Make sure that's - * ok. - */ - if (S_ISDIR(new->p_base->pb_ino->i_stbuf.st_mode)) { - if (!S_ISDIR(old->p_base->pb_ino->i_stbuf.st_mode)) { - err = -EISDIR; - goto error1; - } - if (new->p_base->pb_ino->i_stbuf.st_nlink > 2) { - err = -ENOTEMPTY; - goto error1; - } - } else if (S_ISDIR(old->p_base->pb_ino->i_stbuf.st_mode)) { - err = -ENOTDIR; - goto error1; - } - } - - /* - * It's not impossible to clean up the altered name space after - * a rename. However, it is onerous and I don't want to do it right - * 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 - * thing to do to the caller. - */ - if (_sysio_p_prune(new) != 1) { - err = -EBUSY; - goto error1; - } - err = PNOP_RENAME(old, new); - if (err) - goto error1; - /* - * Reflect the successful rename in the active name space graph by - * "losing" the existing, relevant, parts of the graph. A subsequent - * lookup will reestablish the proper graph. - */ - _sysio_pb_disconnect(old->p_base); + err = _sysio_p_rename(old, new); + } while (0); -error1: + if (new) P_RELE(new); -error2: + if (old) P_RELE(old); -error3: - if (err) - goto out; - _sysio_p_gone(old); /* kill it! */ -out: SYSIO_INTERFACE_RETURN(err ? -1 : 0, err, rename, 0); } |