[Libsysio-commit] RedStorm: libsysio/src link.c rename.c utime.c Makefile.am chdir.c chmod.c chown.c
Brought to you by:
lward
From: Lee W. <lw...@us...> - 2003-09-27 20:20:55
|
Update of /cvsroot/libsysio/libsysio/src In directory sc8-pr-cvs1:/tmp/cvs-serv15049/src Modified Files: Tag: RedStorm Makefile.am chdir.c chmod.c chown.c dev.c rmdir.c unlink.c Added Files: Tag: RedStorm link.c rename.c utime.c Log Message: Updated with recent changes in HEAD branch. --- NEW FILE --- /* * This Cplant(TM) source code is the property of Sandia National * Laboratories. * * This Cplant(TM) source code is copyrighted by Sandia National * Laboratories. * * The redistribution of this Cplant(TM) source code is subject to the * terms of the GNU Lesser General Public License * (see cit/LGPL or http://www.gnu.org/licenses/lgpl.html) * * Cplant(TM) Copyright 1998-2003 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 * Government. */ /* * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Questions or comments about this library should be sent to: * * Lee Ward * Sandia National Laboratories, New Mexico * P.O. Box 5800 * Albuquerque, NM 87185-1110 * * le...@sa... */ #include <string.h> #include <errno.h> #include <assert.h> #include <sys/types.h> #include <sys/stat.h> #include <unistd.h> #include <sys/queue.h> #include "sysio.h" #include "mount.h" #include "inode.h" int link(const char *oldpath, const char *newpath) { struct intent intent; int err; struct pnode *old, *new; INTENT_INIT(&intent, 0, NULL, NULL); err = _sysio_namei(_sysio_cwd, oldpath, 0, &intent, &old); if (err) goto out; if (S_ISDIR(old->p_base->pb_ino->i_mode)) { err = -EPERM; goto error2; } INTENT_INIT(&intent, INT_UPDPARENT, NULL, NULL); err = _sysio_namei(_sysio_cwd, newpath, ND_NEGOK, &intent, &new); if (err && !new) goto error2; if (!err || (err && err != -ENOENT)) { err = -EEXIST; goto error1; } if (old->p_mount->mnt_root != new->p_mount->mnt_root) { err = -EXDEV; goto error1; } err = old->p_base->pb_ino->i_ops.inop_link(old, new); if (err) goto error1; /* * The new path-base node must point to the inode referenced by * the old. As well, we need to record the new reference of the inode. */ new->p_base->pb_ino = old->p_base->pb_ino; I_REF(new->p_base->pb_ino); error1: P_RELE(new); error2: P_RELE(old); if (err) { errno = -err; err = -1; } out: return err; } --- NEW FILE --- /* * This Cplant(TM) source code is the property of Sandia National * Laboratories. * * This Cplant(TM) source code is copyrighted by Sandia National * Laboratories. * * The redistribution of this Cplant(TM) source code is subject to the * terms of the GNU Lesser General Public License * (see cit/LGPL or http://www.gnu.org/licenses/lgpl.html) * * Cplant(TM) Copyright 1998-2003 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 * Government. */ /* * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Questions or comments about this library should be sent to: * * Lee Ward * Sandia National Laboratories, New Mexico * P.O. Box 5800 * Albuquerque, NM 87185-1110 * * le...@sa... */ #include <stdlib.h> #include <string.h> #include <errno.h> #include <assert.h> #include <sys/types.h> #include <sys/stat.h> #include <unistd.h> #include <sys/queue.h> #include "sysio.h" #include "mount.h" #include "inode.h" int rename(const char *oldpath, const char *newpath) { struct intent intent; int err; struct pnode *old, *new; struct pnode_base *nxtpb, *pb; struct intnl_stat ostbuf, nstbuf; /* * Resolve oldpath to a path node. */ INTENT_INIT(&intent, INT_UPDPARENT, NULL, NULL); err = _sysio_namei(_sysio_cwd, oldpath, 0, &intent, &old); if (err) goto out; /* * Resolve newpath to a path node. */ INTENT_INIT(&intent, INT_UPDPARENT, NULL, NULL); err = _sysio_namei(_sysio_cwd, newpath, ND_NEGOK, &intent, &new); if (err && !new) goto error2; if (old->p_mount->mnt_root != new->p_mount->mnt_root) { /* * Oops. They're trying to move it across mounts. */ 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 (pb != nxtpb); while (new->p_base->pb_ino) { /* * Existing entry. We're replacing the new. Make sure that's * ok. */ err = old->p_base->pb_ino->i_ops.inop_getattr(old, NULL, &ostbuf); if (err) goto error1; err = new->p_base->pb_ino->i_ops.inop_getattr(new, NULL, &nstbuf); if (err) { if (err != ENOENT) goto error1; /* * Rats! It disappeared beneath us. */ (void )_sysio_p_validate(new, NULL, NULL); continue; } if (S_ISDIR(ostbuf.st_mode)) { if (!S_ISDIR(nstbuf.st_mode)) { err = -ENOTDIR; goto error1; } if (nstbuf.st_nlink > 2) { err = -ENOTEMPTY; goto error1; } } else if (S_ISDIR(nstbuf.st_mode)) { err = -EEXIST; 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. */ if (_sysio_p_prune(new) != 1) { err = -EBUSY; goto error1; } err = old->p_base->pb_ino->i_ops.inop_rename(old, new); if (err) goto error1; error1: P_RELE(new); error2: P_RELE(old); if (err) { errno = -err; err = -1; goto out; } _sysio_p_gone(old); /* kill it! */ out: return err; } --- NEW FILE --- /* * This Cplant(TM) source code is the property of Sandia National * Laboratories. * * This Cplant(TM) source code is copyrighted by Sandia National * Laboratories. * * The redistribution of this Cplant(TM) source code is subject to the * terms of the GNU Lesser General Public License * (see cit/LGPL or http://www.gnu.org/licenses/lgpl.html) * * Cplant(TM) Copyright 1998-2003 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 * Government. */ /* * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Questions or comments about this library should be sent to: * * Lee Ward * Sandia National Laboratories, New Mexico * P.O. Box 5800 * Albuquerque, NM 87185-1110 * * le...@sa... */ #include <string.h> #include <errno.h> #include <time.h> #include <assert.h> #include <sys/types.h> #include <utime.h> #include <sys/stat.h> #include <unistd.h> #include <sys/queue.h> #include "sysio.h" #include "inode.h" #include "file.h" int utime(const char *path, const struct utimbuf *buf) { struct intent intent; int err; struct pnode *pno; struct utimbuf _utbuffer; struct intnl_stat stbuf; INTENT_INIT(&intent, INT_SETATTR, NULL, NULL); err = _sysio_namei(_sysio_cwd, path, 0, &intent, &pno); if (err) goto out; if (!buf) { _utbuffer.actime = _utbuffer.modtime = time(NULL); buf = &_utbuffer; } (void )memset(&stbuf, 0, sizeof(struct intnl_stat)); stbuf.st_atime = buf->actime; stbuf.st_mtime = buf->modtime; err = _sysio_setattr(pno, pno->p_base->pb_ino, SETATTR_ATIME | SETATTR_MTIME, &stbuf); P_RELE(pno); out: if (err) { errno = -err; err = -1; } return err; } Index: Makefile.am =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/Makefile.am,v retrieving revision 1.5.6.4 retrieving revision 1.5.6.5 diff -u -w -b -B -p -r1.5.6.4 -r1.5.6.5 --- Makefile.am 26 Sep 2003 21:28:34 -0000 1.5.6.4 +++ Makefile.am 27 Sep 2003 20:20:40 -0000 1.5.6.5 @@ -2,8 +2,9 @@ lib_LIBRARIES = libsysio.a libsysio_a_SOURCES = chdir.c chmod.c chown.c dev.c dup.c fcntl.c file.c fs.c \ fsync.c getdirentries.c init.c inode.c ioctl.c ioctx.c iowait.c \ - lseek.c mkdir.c mknod.c mount.c namei.c open.c read.c rmdir.c stat.c \ - stat64.c statvfs.c symlink.c truncate.c unlink.c write.c access.c + link.c lseek.c mkdir.c mknod.c mount.c namei.c open.c read.c rename.c \ + rmdir.c stat.c stat64.c statvfs.c symlink.c truncate.c unlink.c \ + utime.c write.c access.c include $(top_srcdir)/Rules.make Index: chdir.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/chdir.c,v retrieving revision 1.3.10.1 retrieving revision 1.3.10.2 diff -u -w -b -B -p -r1.3.10.1 -r1.3.10.2 --- chdir.c 26 Sep 2003 21:28:34 -0000 1.3.10.1 +++ chdir.c 27 Sep 2003 20:20:40 -0000 1.3.10.2 @@ -64,12 +64,13 @@ */ #include <stdlib.h> +#include <sys/types.h> +#include <sys/stat.h> #include <unistd.h> #include <string.h> #include <limits.h> #include <errno.h> #include <assert.h> -#include <sys/types.h> #include <sys/queue.h> #include "sysio.h" @@ -79,6 +80,49 @@ struct pnode *_sysio_cwd = NULL; +/* + * Change to directory specified by the given pnode. + */ +int +_sysio_p_chdir(struct pnode *pno) +{ + int err; + struct intnl_stat stbuf; + + /* + * Revalidate + */ + err = _sysio_p_validate(pno, NULL, NULL); + if (err) + return err; + if (!pno->p_base->pb_ino) + return -ENOTDIR; + /* + * Stat the node and ensure it's a directory. + */ + err = + pno->p_base->pb_ino->i_ops.inop_getattr(pno, + NULL, + &stbuf); + if (err) + return err; + if (!S_ISDIR(stbuf.st_mode)) + return -ENOTDIR; + + /* + * Release old if set. + */ + if (_sysio_cwd) + P_RELE(_sysio_cwd); + + /* + * Finally, change to the new. + */ + _sysio_cwd = pno; + + return 0; +} + int chdir(const char *path) { @@ -91,11 +135,7 @@ chdir(const char *path) return -1; } - if (_sysio_cwd) - P_RELE(_sysio_cwd); - - _sysio_cwd = pno; - return 0; + return _sysio_p_chdir(pno); } /* Index: chmod.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/chmod.c,v retrieving revision 1.3 retrieving revision 1.3.6.1 diff -u -w -b -B -p -r1.3 -r1.3.6.1 --- chmod.c 24 Mar 2003 22:09:06 -0000 1.3 +++ chmod.c 27 Sep 2003 20:20:40 -0000 1.3.6.1 @@ -51,6 +51,21 @@ #include "sysio.h" #include "inode.h" +#include "file.h" + +static int +do_chmod(struct pnode *pno, struct inode *ino, mode_t mode) +{ + int err; + struct intnl_stat stbuf; + unsigned mask; + + (void )memset(&stbuf, 0, sizeof(struct intnl_stat)); + stbuf.st_mode = mode & 0777; + mask = SETATTR_MODE; + err = _sysio_setattr(pno, ino, mask, &stbuf); + return err; +} int chmod(const char *path, mode_t mode) @@ -58,18 +73,35 @@ chmod(const char *path, mode_t mode) struct intent intent; int err; struct pnode *pno; - struct intnl_stat stbuf; - unsigned mask; INTENT_INIT(&intent, INT_SETATTR, NULL, NULL); err = _sysio_namei(_sysio_cwd, path, 0, &intent, &pno); if (err) goto out; - (void )memset(&stbuf, 0, sizeof(struct intnl_stat)); - stbuf.st_mode = mode & 0777; - mask = SETATTR_MODE; - err = _sysio_setattr(pno, pno->p_base->pb_ino, mask, &stbuf); + err = do_chmod(pno, pno->p_base->pb_ino, mode); P_RELE(pno); +out: + if (err) { + errno = -err; + err = -1; + } + return err; +} + +int +fchmod(int fd, mode_t mode) +{ + int err; + struct file *fil; + + err = 0; + fil = _sysio_fd_find(fd); + if (!fil) { + err = -EBADF; + goto out; + } + + err = do_chmod(NULL, fil->f_ino, mode); out: if (err) { errno = -err; Index: chown.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/chown.c,v retrieving revision 1.3 retrieving revision 1.3.6.1 diff -u -w -b -B -p -r1.3 -r1.3.6.1 --- chown.c 24 Mar 2003 22:09:06 -0000 1.3 +++ chown.c 27 Sep 2003 20:20:40 -0000 1.3.6.1 @@ -51,18 +51,15 @@ #include "sysio.h" #include "inode.h" +#include "file.h" -int -chown(const char *path, uid_t owner, gid_t group) +static int +_do_chown(struct pnode *pno, struct inode *ino, uid_t owner, gid_t group) { int err; - struct pnode *pno; struct intnl_stat stbuf; unsigned mask; - err = _sysio_namei(_sysio_cwd, path, 0, NULL, &pno); - if (err) - goto out; (void )memset(&stbuf, 0, sizeof(struct intnl_stat)); mask = 0; if (owner != (uid_t )-1) { @@ -73,11 +70,44 @@ chown(const char *path, uid_t owner, gid stbuf.st_gid = group; mask |= SETATTR_GID; } - if (!mask) - goto done; - err = _sysio_setattr(pno, pno->p_base->pb_ino, mask, &stbuf); -done: + err = _sysio_setattr(pno, ino, mask, &stbuf); + return err; +} + +int +chown(const char *path, uid_t owner, gid_t group) +{ + int err; + struct pnode *pno; + + err = _sysio_namei(_sysio_cwd, path, 0, NULL, &pno); + if (err) + goto out; + + err = _do_chown(pno, pno->p_base->pb_ino, owner, group); P_RELE(pno); +out: + if (err) { + errno = -err; + err = -1; + } + return err; +} + +int +fchown(int fd, uid_t owner, gid_t group) +{ + int err; + struct file *fil; + + err = 0; + fil = _sysio_fd_find(fd); + if (!fil) { + err = -EBADF; + goto out; + } + + err = _do_chown(NULL, fil->f_ino, owner, group); out: if (err) { errno = -err; Index: dev.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/dev.c,v retrieving revision 1.2.6.1 retrieving revision 1.2.6.2 diff -u -w -b -B -p -r1.2.6.1 -r1.2.6.2 --- dev.c 12 May 2003 11:48:45 -0000 1.2.6.1 +++ dev.c 27 Sep 2003 20:20:40 -0000 1.2.6.2 @@ -63,7 +63,9 @@ const struct inode_ops _sysio_nodev_ops _sysio_nodev_inop_readlink, _sysio_nodev_inop_open, _sysio_nodev_inop_close, + _sysio_nodev_inop_link, _sysio_nodev_inop_unlink, + _sysio_nodev_inop_rename, _sysio_nodev_inop_ipreadv, _sysio_nodev_inop_ipwritev, _sysio_nodev_inop_iodone, @@ -169,45 +171,10 @@ _sysio_dev_lookup(mode_t mode, dev_t dev } int -_sysio_dev_e_notdir() -{ - - return -ENOTDIR; -} - -int -_sysio_dev_e_badf() -{ - - return -EBADF; -} - -int -_sysio_dev_e_inval() -{ - - return -EINVAL; -} - -int -_sysio_dev_e_nxio() -{ - - return -ENXIO; -} - -int -_sysio_dev_e_illop() +_sysio_dev_illop() { abort(); -} - -int -_sysio_dev_e_notty() -{ - - return -ENOTTY; } void Index: rmdir.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/rmdir.c,v retrieving revision 1.3 retrieving revision 1.3.6.1 diff -u -w -b -B -p -r1.3 -r1.3.6.1 --- rmdir.c 24 Mar 2003 22:09:06 -0000 1.3 +++ rmdir.c 27 Sep 2003 20:20:41 -0000 1.3.6.1 @@ -68,6 +68,13 @@ rmdir(const char *path) goto error; } err = pno->p_base->pb_ino->i_ops.inop_rmdir(pno); + if (err) + goto error; + /* + * Invalide the path-base node. The inode reference was dropped + * by the driver. + */ + pno->p_base->pb_ino = NULL; error: P_RELE(pno); out: Index: unlink.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/unlink.c,v retrieving revision 1.3 retrieving revision 1.3.6.1 diff -u -w -b -B -p -r1.3 -r1.3.6.1 --- unlink.c 24 Mar 2003 22:09:07 -0000 1.3 +++ unlink.c 27 Sep 2003 20:20:41 -0000 1.3.6.1 @@ -68,6 +68,13 @@ unlink(const char *path) goto error; } err = (*pno->p_base->pb_ino->i_ops.inop_unlink)(pno); + if (err) + goto error; + /* + * Invalidate the path-base node. The inode reference was + * dropped by the driver. + */ + pno->p_base->pb_ino = NULL; error: P_RELE(pno); out: |