Deleted Added
full compact
tmpfs_vnops.c (171070) tmpfs_vnops.c (171087)
1/* $NetBSD: tmpfs_vnops.c,v 1.35 2007/01/04 15:42:37 elad Exp $ */
2
3/*
4 * Copyright (c) 2005 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Julio M. Merino Vidal, developed as part of Google's Summer of Code

--- 27 unchanged lines hidden (view full) ---

36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGE.
38 */
39
40/*
41 * tmpfs vnode interface.
42 */
43#include <sys/cdefs.h>
1/* $NetBSD: tmpfs_vnops.c,v 1.35 2007/01/04 15:42:37 elad Exp $ */
2
3/*
4 * Copyright (c) 2005 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Julio M. Merino Vidal, developed as part of Google's Summer of Code

--- 27 unchanged lines hidden (view full) ---

36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGE.
38 */
39
40/*
41 * tmpfs vnode interface.
42 */
43#include <sys/cdefs.h>
44__FBSDID("$FreeBSD: head/sys/fs/tmpfs/tmpfs_vnops.c 171070 2007-06-28 02:39:31Z delphij $");
44__FBSDID("$FreeBSD: head/sys/fs/tmpfs/tmpfs_vnops.c 171087 2007-06-29 05:23:15Z delphij $");
45
46#include <sys/param.h>
47#include <sys/fcntl.h>
48#include <sys/lockf.h>
49#include <sys/namei.h>
50#include <sys/priv.h>
51#include <sys/proc.h>
52#include <sys/resourcevar.h>

--- 772 unchanged lines hidden (view full) ---

825 error = EPERM;
826 goto out_locked;
827 }
828
829 /* Ensure that we have enough memory to hold the new name, if it
830 * has to be changed. */
831 if (fcnp->cn_namelen != tcnp->cn_namelen ||
832 memcmp(fcnp->cn_nameptr, tcnp->cn_nameptr, fcnp->cn_namelen) != 0) {
45
46#include <sys/param.h>
47#include <sys/fcntl.h>
48#include <sys/lockf.h>
49#include <sys/namei.h>
50#include <sys/priv.h>
51#include <sys/proc.h>
52#include <sys/resourcevar.h>

--- 772 unchanged lines hidden (view full) ---

825 error = EPERM;
826 goto out_locked;
827 }
828
829 /* Ensure that we have enough memory to hold the new name, if it
830 * has to be changed. */
831 if (fcnp->cn_namelen != tcnp->cn_namelen ||
832 memcmp(fcnp->cn_nameptr, tcnp->cn_nameptr, fcnp->cn_namelen) != 0) {
833 newname = tmpfs_str_zone_alloc(&tmp->tm_str_pool, M_WAITOK,
834 tcnp->cn_namelen);
835 if (newname == NULL) {
836 error = ENOSPC;
837 goto out_locked;
838 }
833 newname = malloc(tcnp->cn_namelen, M_TMPFSNAME, M_WAITOK);
839 } else
840 newname = NULL;
841
842 /* If the node is being moved to another directory, we have to do
843 * the move. */
844 if (fdnode != tdnode) {
845 /* In case we are moving a directory, we have to adjust its
846 * parent to point to the new parent. */
847 if (de->td_node->tn_type == VDIR) {
848 struct tmpfs_node *n;
849
850 /* Ensure the target directory is not a child of the
851 * directory being moved. Otherwise, we'd end up
852 * with stale nodes. */
853 n = tdnode;
854 while (n != n->tn_dir.tn_parent) {
855 if (n == fnode) {
856 error = EINVAL;
857 if (newname != NULL)
834 } else
835 newname = NULL;
836
837 /* If the node is being moved to another directory, we have to do
838 * the move. */
839 if (fdnode != tdnode) {
840 /* In case we are moving a directory, we have to adjust its
841 * parent to point to the new parent. */
842 if (de->td_node->tn_type == VDIR) {
843 struct tmpfs_node *n;
844
845 /* Ensure the target directory is not a child of the
846 * directory being moved. Otherwise, we'd end up
847 * with stale nodes. */
848 n = tdnode;
849 while (n != n->tn_dir.tn_parent) {
850 if (n == fnode) {
851 error = EINVAL;
852 if (newname != NULL)
858 tmpfs_str_zone_free(&tmp->tm_str_pool,
859 newname, tcnp->cn_namelen);
853 free(newname, M_TMPFSNAME);
860 goto out_locked;
861 }
862 n = n->tn_dir.tn_parent;
863 }
864
865 /* Adjust the parent pointer. */
866 TMPFS_VALIDATE_DIR(fnode);
867 de->td_node->tn_dir.tn_parent = tdnode;

--- 11 unchanged lines hidden (view full) ---

879 tmpfs_dir_attach(tdvp, de);
880 }
881
882 /* If the name has changed, we need to make it effective by changing
883 * it in the directory entry. */
884 if (newname != NULL) {
885 MPASS(tcnp->cn_namelen <= MAXNAMLEN);
886
854 goto out_locked;
855 }
856 n = n->tn_dir.tn_parent;
857 }
858
859 /* Adjust the parent pointer. */
860 TMPFS_VALIDATE_DIR(fnode);
861 de->td_node->tn_dir.tn_parent = tdnode;

--- 11 unchanged lines hidden (view full) ---

873 tmpfs_dir_attach(tdvp, de);
874 }
875
876 /* If the name has changed, we need to make it effective by changing
877 * it in the directory entry. */
878 if (newname != NULL) {
879 MPASS(tcnp->cn_namelen <= MAXNAMLEN);
880
887 tmpfs_str_zone_free(&tmp->tm_str_pool, de->td_name,
888 de->td_namelen);
881 free(de->td_name, M_TMPFSNAME);
889 de->td_namelen = (uint16_t)tcnp->cn_namelen;
890 memcpy(newname, tcnp->cn_nameptr, tcnp->cn_namelen);
891 de->td_name = newname;
892
893 fnode->tn_status |= TMPFS_NODE_CHANGED;
894 tdnode->tn_status |= TMPFS_NODE_MODIFIED;
895 }
896

--- 471 unchanged lines hidden ---
882 de->td_namelen = (uint16_t)tcnp->cn_namelen;
883 memcpy(newname, tcnp->cn_nameptr, tcnp->cn_namelen);
884 de->td_name = newname;
885
886 fnode->tn_status |= TMPFS_NODE_CHANGED;
887 tdnode->tn_status |= TMPFS_NODE_MODIFIED;
888 }
889

--- 471 unchanged lines hidden ---