[Libsysio-commit] HEAD: libsysio/src init.c link.c mkdir.c mknod.c open.c rename.c rmdir.c symlink.
Brought to you by:
lward
From: Lee W. <lw...@us...> - 2009-08-04 15:01:34
|
Update of /cvsroot/libsysio/libsysio/src In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv450 Modified Files: init.c link.c mkdir.c mknod.c open.c rename.c rmdir.c symlink.c unlink.c Log Message: Use the new ND_WANTPARENT flag as appropriate. Index: init.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/init.c,v retrieving revision 1.44 retrieving revision 1.45 diff -u -w -b -B -p -r1.44 -r1.45 --- init.c 6 Dec 2008 21:56:25 -0000 1.44 +++ init.c 4 Aug 2009 15:01:24 -0000 1.45 @@ -9,7 +9,7 @@ * terms of the GNU Lesser General Public License * (see cit/LGPL or http://www.gnu.org/licenses/lgpl.html) * - * Cplant(TM) Copyright 1998-2007 Sandia Corporation. + * Cplant(TM) Copyright 1998-2009 Sandia Corporation. * Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive * license for use of this work by or on behalf of the US Government. * Export of this program may require a license from the United States @@ -469,27 +469,24 @@ do_creat(char *args) op = 0; if (strcmp(v[0].ovi_value, "dir") == 0) { op = CREATE_DIR; - INTENT_INIT(&intent, INT_CREAT, &mode, NULL); } else if (strcmp(v[0].ovi_value, "chr") == 0) { op = CREATE_CHR; mode |= S_IFCHR; - INTENT_INIT(&intent, INT_CREAT, &mode, NULL); if (!(v[5].ovi_value && parse_mm(v[5].ovi_value, &dev) == 0)) err = -EINVAL; } else if (strcmp(v[0].ovi_value, "blk") == 0) { op = CREATE_BLK; mode |= S_IFBLK; - INTENT_INIT(&intent, INT_CREAT, &mode, NULL); if (!(v[5].ovi_value && parse_mm(v[5].ovi_value, &dev) == 0)) err = -EINVAL; } else if (strcmp(v[0].ovi_value, "file") == 0) { op = CREATE_FILE; intent_mode = O_CREAT|O_EXCL; - INTENT_INIT(&intent, INT_CREAT, &mode, &intent_mode); } else err = -EINVAL; if (err) return err; + INTENT_INIT(&intent, INT_CREAT|INT_UPDPARENT, &mode, &intent_mode); /* * Lookup the given path. @@ -497,7 +494,7 @@ do_creat(char *args) err = _sysio_namei(dir, v[1].ovi_value, - ND_NEGOK|ND_NOPERMCHECK, + ND_NEGOK|ND_NOPERMCHECK|ND_WANTPARENT, &intent, &pno); if (err) @@ -550,6 +547,7 @@ do_creat(char *args) abort(); } + P_PUT(pno->p_parent); P_PUT(pno); return err; } Index: link.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/link.c,v retrieving revision 1.20 retrieving revision 1.21 diff -u -w -b -B -p -r1.20 -r1.21 --- link.c 4 Aug 2009 05:52:23 -0000 1.20 +++ link.c 4 Aug 2009 15:01:24 -0000 1.21 @@ -105,7 +105,11 @@ SYSIO_INTERFACE_NAME(link)(const char *o break; INTENT_INIT(&intent, INT_UPDPARENT, NULL, NULL); err = - _sysio_namei(_sysio_cwd, newpath, ND_NEGOK, &intent, &new); + _sysio_namei(_sysio_cwd, + newpath, + ND_NEGOK|ND_WANTPARENT, + &intent, + &new); if (err) break; if (new->p_base->pb_ino) { @@ -114,8 +118,10 @@ SYSIO_INTERFACE_NAME(link)(const char *o } err = _sysio_p_link(old, new); } while (0); - if (new) + if (new) { + P_PUT(new->p_parent); P_PUT(new); + } if (old) P_PUT(old); SYSIO_INTERFACE_RETURN(err ? -1 : 0, err, link, "%d", 0); Index: mkdir.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/mkdir.c,v retrieving revision 1.24 retrieving revision 1.25 diff -u -w -b -B -p -r1.24 -r1.25 --- mkdir.c 17 Jun 2008 17:18:57 -0000 1.24 +++ mkdir.c 4 Aug 2009 15:01:24 -0000 1.25 @@ -9,7 +9,7 @@ * terms of the GNU Lesser General Public License * (see cit/LGPL or http://www.gnu.org/licenses/lgpl.html) * - * Cplant(TM) Copyright 1998-2007 Sandia Corporation. + * Cplant(TM) Copyright 1998-2009 Sandia Corporation. * Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive * license for use of this work by or on behalf of the US Government. * Export of this program may require a license from the United States @@ -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... */ @@ -80,12 +80,18 @@ SYSIO_INTERFACE_NAME(mkdir)(const char * SYSIO_INTERFACE_ENTER(mkdir, "%s%mZ", path, mode); INTENT_INIT(&intent, INT_CREAT, &mode, NULL); - err = _sysio_namei(_sysio_cwd, path, ND_NEGOK, &intent, &pno); + err = + _sysio_namei(_sysio_cwd, + path, + ND_NEGOK|ND_WANTPARENT, + &intent, + &pno); if (err) goto out; mode &= ~(_sysio_umask & 0777); /* apply umask */ err = _sysio_mkdir(pno, mode); + P_PUT(pno->p_parent); P_PUT(pno); out: SYSIO_INTERFACE_RETURN(err ? -1 : 0, err, mkdir, "%d", 0); Index: mknod.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/mknod.c,v retrieving revision 1.23 retrieving revision 1.24 diff -u -w -b -B -p -r1.23 -r1.24 --- mknod.c 17 Jun 2008 17:18:57 -0000 1.23 +++ mknod.c 4 Aug 2009 15:01:24 -0000 1.24 @@ -9,7 +9,7 @@ * terms of the GNU Lesser General Public License * (see cit/LGPL or http://www.gnu.org/licenses/lgpl.html) * - * Cplant(TM) Copyright 1998-2007 Sandia Corporation. + * Cplant(TM) Copyright 1998-2009 Sandia Corporation. * Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive * license for use of this work by or on behalf of the US Government. * Export of this program may require a license from the United States @@ -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... */ @@ -64,6 +64,7 @@ int _sysio_mknod(struct pnode *pno, mode_t mode, dev_t dev) { + int err; if (pno->p_base->pb_ino) return -EEXIST; @@ -77,6 +78,11 @@ _sysio_mknod(struct pnode *pno, mode_t m if (IS_RDONLY(pno)) return -EROFS; + + err = _sysio_permitted(pno->p_parent, W_OK); + if (err) + return err; + return PNOP_MKNOD(pno, mode, dev); } @@ -100,15 +106,18 @@ PREPEND(__, SYSIO_INTERFACE_NAME(xmknod) mode &= ~(_sysio_umask & 0777); /* apply umask */ INTENT_INIT(&intent, INT_CREAT, &mode, NULL); - err = _sysio_namei(_sysio_cwd, path, ND_NEGOK, &intent, &pno); + err = + _sysio_namei(_sysio_cwd, + path, + ND_NEGOK|ND_WANTPARENT, + &intent, + &pno); if (err) goto out; - err = _sysio_permitted(pno->p_parent, W_OK); - if (err) - goto error; err = _sysio_mknod(pno, mode, *dev); error: + P_PUT(pno->p_parent); P_PUT(pno); out: SYSIO_INTERFACE_RETURN(err ? -1 : 0, err, xmknod, "%d", 0); Index: open.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/open.c,v retrieving revision 1.34 retrieving revision 1.35 diff -u -w -b -B -p -r1.34 -r1.35 --- open.c 6 Dec 2008 18:22:27 -0000 1.34 +++ open.c 4 Aug 2009 15:01:24 -0000 1.35 @@ -9,7 +9,7 @@ * terms of the GNU Lesser General Public License * (see cit/LGPL or http://www.gnu.org/licenses/lgpl.html) * - * Cplant(TM) Copyright 1998-2007 Sandia Corporation. + * Cplant(TM) Copyright 1998-2009 Sandia Corporation. * Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive * license for use of this work by or on behalf of the US Government. * Export of this program may require a license from the United States @@ -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... */ @@ -140,9 +140,11 @@ SYSIO_INTERFACE_NAME(open)(const char *p va_list ap; /* - * Set ndflags to indicate return of negative alias is OK. + * Set ndflags to indicate return of negative alias is OK and, + * since this is a create, we'll want a lock on the parent + * directory as well. */ - ndflags |= ND_NEGOK; + ndflags |= ND_NEGOK|ND_WANTPARENT; /* * Will need mode too. @@ -177,6 +179,7 @@ SYSIO_INTERFACE_NAME(open)(const char *p * Ask for the open/creat. */ rtn = _sysio_open(pno, flags, mode); + P_PUT(pno->p_parent); if (rtn) goto error; /* Index: rename.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/rename.c,v retrieving revision 1.16 retrieving revision 1.17 diff -u -w -b -B -p -r1.16 -r1.17 --- rename.c 28 Jan 2009 16:13:19 -0000 1.16 +++ rename.c 4 Aug 2009 15:01:24 -0000 1.17 @@ -9,7 +9,7 @@ * terms of the GNU Lesser General Public License * (see cit/LGPL or http://www.gnu.org/licenses/lgpl.html) * - * Cplant(TM) Copyright 1998-2007 Sandia Corporation. + * Cplant(TM) Copyright 1998-2009 Sandia Corporation. * Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive * license for use of this work by or on behalf of the US Government. * Export of this program may require a license from the United States @@ -160,15 +160,14 @@ SYSIO_INTERFACE_NAME(rename)(const char err = _sysio_namei(_sysio_cwd, oldpath, - ND_NOFOLLOW, + ND_NOFOLLOW|ND_WANTPARENT, &intent, &old); if (err) { old = NULL; break; } - P_REF(old); - P_PUT(old); + /* * Resolve newpath to a path node. */ @@ -176,25 +175,25 @@ SYSIO_INTERFACE_NAME(rename)(const char err = _sysio_namei(_sysio_cwd, newpath, - ND_NOFOLLOW | ND_NEGOK, + ND_NOFOLLOW|ND_NEGOK|ND_WANTPARENT, &intent, &new); if (err) { new = NULL; break; } - P_REF(new); - P_PUT(new); - _sysio_p_get2(old, new); err = _sysio_p_rename(old, new); - P_PUT(old); - P_PUT(new); } while (0); - if (new) - P_RELE(new); - if (old) - P_RELE(old); + if (new) { + P_PUT(new->p_parent); + P_PUT(new); + } + if (old) { + P_PUT(old->p_parent); + P_PUT(old); + } + SYSIO_INTERFACE_RETURN(err ? -1 : 0, err, rename, "%d", 0); } Index: rmdir.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/rmdir.c,v retrieving revision 1.24 retrieving revision 1.25 diff -u -w -b -B -p -r1.24 -r1.25 --- rmdir.c 28 Jan 2009 16:13:19 -0000 1.24 +++ rmdir.c 4 Aug 2009 15:01:24 -0000 1.25 @@ -9,7 +9,7 @@ * terms of the GNU Lesser General Public License * (see cit/LGPL or http://www.gnu.org/licenses/lgpl.html) * - * Cplant(TM) Copyright 1998-2007 Sandia Corporation. + * Cplant(TM) Copyright 1998-2009 Sandia Corporation. * Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive * license for use of this work by or on behalf of the US Government. * Export of this program may require a license from the United States @@ -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... */ @@ -68,6 +68,9 @@ _sysio_p_rmdir(struct pnode *pno) return -ENOENT; /* huh? */ if (!S_ISDIR(pno->p_base->pb_ino->i_stbuf.st_mode)) return -ENOTDIR; + err = _sysio_permitted(pno->p_parent, W_OK); + if (err) + return err; /* * Don't allow unlink of a root or a mount point. */ @@ -98,20 +101,24 @@ SYSIO_INTERFACE_NAME(rmdir)(const char * SYSIO_INTERFACE_ENTER(rmdir, "%s", path); do { INTENT_INIT(&intent, INT_UPDPARENT, NULL, NULL); - err = _sysio_namei(_sysio_cwd, path, 0, &intent, &pno); + err = + _sysio_namei(_sysio_cwd, + path, + ND_WANTPARENT, + &intent, + &pno); if (err) { pno = NULL; break; } - err = _sysio_permitted(pno->p_parent, W_OK); - if (err) - break; err = _sysio_p_rmdir(pno); if (err) break; } while (0); - if (pno) + if (pno) { + P_PUT(pno->p_parent); P_PUT(pno); + } SYSIO_INTERFACE_RETURN(err ? -1 : 0, err, rmdir, "%d", 0); } Index: symlink.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/symlink.c,v retrieving revision 1.21 retrieving revision 1.22 diff -u -w -b -B -p -r1.21 -r1.22 --- symlink.c 28 Jan 2009 16:13:19 -0000 1.21 +++ symlink.c 4 Aug 2009 15:01:24 -0000 1.22 @@ -9,7 +9,7 @@ * terms of the GNU Lesser General Public License * (see cit/LGPL or http://www.gnu.org/licenses/lgpl.html) * - * Cplant(TM) Copyright 1998-2007 Sandia Corporation. + * Cplant(TM) Copyright 1998-2009 Sandia Corporation. * Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive * license for use of this work by or on behalf of the US Government. * Export of this program may require a license from the United States @@ -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... */ @@ -63,6 +63,9 @@ _sysio_p_symlink(const char *oldpath, st if (new->p_base->pb_ino) return -EEXIST; + err = _sysio_permitted(new->p_parent, W_OK); + if (err) + return err; if (IS_RDONLY(new->p_parent)) return -EROFS; return PNOP_SYMLINK(new, oldpath); @@ -80,22 +83,21 @@ SYSIO_INTERFACE_NAME(symlink)(const char err = 0; pno = NULL; do { - INTENT_INIT(&intent, INT_CREAT, NULL, NULL); + INTENT_INIT(&intent, INT_CREAT|INT_UPDPARENT, NULL, NULL); err = _sysio_namei(_sysio_cwd, newpath, - ND_NOFOLLOW|ND_NEGOK, + ND_NOFOLLOW|ND_NEGOK|ND_WANTPARENT, &intent, &pno); if (err) break; - err = _sysio_permitted(pno->p_parent, W_OK); - if (err) - break; err = _sysio_p_symlink(oldpath, pno); } while (0); - if (pno) + if (pno) { + P_PUT(pno->p_parent); P_PUT(pno); + } SYSIO_INTERFACE_RETURN(err ? -1 : 0, err, symlink, "%d", 0); } Index: unlink.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/unlink.c,v retrieving revision 1.22 retrieving revision 1.23 diff -u -w -b -B -p -r1.22 -r1.23 --- unlink.c 28 Jan 2009 16:13:19 -0000 1.22 +++ unlink.c 4 Aug 2009 15:01:24 -0000 1.23 @@ -9,7 +9,7 @@ * terms of the GNU Lesser General Public License * (see cit/LGPL or http://www.gnu.org/licenses/lgpl.html) * - * Cplant(TM) Copyright 1998-2007 Sandia Corporation. + * Cplant(TM) Copyright 1998-2009 Sandia Corporation. * Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive * license for use of this work by or on behalf of the US Government. * Export of this program may require a license from the United States @@ -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... */ @@ -94,7 +94,11 @@ SYSIO_INTERFACE_NAME(unlink)(const char do { INTENT_INIT(&intent, INT_UPDPARENT, NULL, NULL); err = - _sysio_namei(_sysio_cwd, path, ND_NOFOLLOW, &intent, &pno); + _sysio_namei(_sysio_cwd, + path, + ND_NOFOLLOW|ND_WANTPARENT, + &intent, + &pno); if (err) { pno = NULL; break; @@ -106,8 +110,10 @@ SYSIO_INTERFACE_NAME(unlink)(const char if (err) break; } while (0); - if (pno) + if (pno) { + P_PUT(pno->p_parent); P_PUT(pno); + } SYSIO_INTERFACE_RETURN(err ? -1 : 0, err, unlink, "%d", 0); } |