dir.c (6b16f5d12202a23d875915349cc031c07fe1b3ec) dir.c (488dee96bb62f0b3d9e678cf42574034d5b033a5)
1/*
2 * fs/kernfs/dir.c - kernfs directory implementation
3 *
4 * Copyright (c) 2001-3 Patrick Mochel
5 * Copyright (c) 2007 SUSE Linux Products GmbH
6 * Copyright (c) 2007, 2013 Tejun Heo <tj@kernel.org>
7 *
8 * This file is released under the GPLv2.

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

614 if (dentry->d_sb->s_op == &kernfs_sops &&
615 !d_really_is_negative(dentry))
616 return kernfs_dentry_node(dentry);
617 return NULL;
618}
619
620static struct kernfs_node *__kernfs_new_node(struct kernfs_root *root,
621 const char *name, umode_t mode,
1/*
2 * fs/kernfs/dir.c - kernfs directory implementation
3 *
4 * Copyright (c) 2001-3 Patrick Mochel
5 * Copyright (c) 2007 SUSE Linux Products GmbH
6 * Copyright (c) 2007, 2013 Tejun Heo <tj@kernel.org>
7 *
8 * This file is released under the GPLv2.

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

614 if (dentry->d_sb->s_op == &kernfs_sops &&
615 !d_really_is_negative(dentry))
616 return kernfs_dentry_node(dentry);
617 return NULL;
618}
619
620static struct kernfs_node *__kernfs_new_node(struct kernfs_root *root,
621 const char *name, umode_t mode,
622 kuid_t uid, kgid_t gid,
622 unsigned flags)
623{
624 struct kernfs_node *kn;
625 u32 gen;
626 int cursor;
627 int ret;
628
629 name = kstrdup_const(name, GFP_KERNEL);

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

656 atomic_set(&kn->count, 1);
657 atomic_set(&kn->active, KN_DEACTIVATED_BIAS);
658 RB_CLEAR_NODE(&kn->rb);
659
660 kn->name = name;
661 kn->mode = mode;
662 kn->flags = flags;
663
623 unsigned flags)
624{
625 struct kernfs_node *kn;
626 u32 gen;
627 int cursor;
628 int ret;
629
630 name = kstrdup_const(name, GFP_KERNEL);

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

657 atomic_set(&kn->count, 1);
658 atomic_set(&kn->active, KN_DEACTIVATED_BIAS);
659 RB_CLEAR_NODE(&kn->rb);
660
661 kn->name = name;
662 kn->mode = mode;
663 kn->flags = flags;
664
665 if (!uid_eq(uid, GLOBAL_ROOT_UID) || !gid_eq(gid, GLOBAL_ROOT_GID)) {
666 struct iattr iattr = {
667 .ia_valid = ATTR_UID | ATTR_GID,
668 .ia_uid = uid,
669 .ia_gid = gid,
670 };
671
672 ret = __kernfs_setattr(kn, &iattr);
673 if (ret < 0)
674 goto err_out3;
675 }
676
664 return kn;
665
677 return kn;
678
679 err_out3:
680 idr_remove(&root->ino_idr, kn->id.ino);
666 err_out2:
667 kmem_cache_free(kernfs_node_cache, kn);
668 err_out1:
669 kfree_const(name);
670 return NULL;
671}
672
673struct kernfs_node *kernfs_new_node(struct kernfs_node *parent,
674 const char *name, umode_t mode,
681 err_out2:
682 kmem_cache_free(kernfs_node_cache, kn);
683 err_out1:
684 kfree_const(name);
685 return NULL;
686}
687
688struct kernfs_node *kernfs_new_node(struct kernfs_node *parent,
689 const char *name, umode_t mode,
690 kuid_t uid, kgid_t gid,
675 unsigned flags)
676{
677 struct kernfs_node *kn;
678
691 unsigned flags)
692{
693 struct kernfs_node *kn;
694
679 kn = __kernfs_new_node(kernfs_root(parent), name, mode, flags);
695 kn = __kernfs_new_node(kernfs_root(parent),
696 name, mode, uid, gid, flags);
680 if (kn) {
681 kernfs_get(parent);
682 kn->parent = parent;
683 }
684 return kn;
685}
686
687/*

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

941 if (!root)
942 return ERR_PTR(-ENOMEM);
943
944 idr_init(&root->ino_idr);
945 INIT_LIST_HEAD(&root->supers);
946 root->next_generation = 1;
947
948 kn = __kernfs_new_node(root, "", S_IFDIR | S_IRUGO | S_IXUGO,
697 if (kn) {
698 kernfs_get(parent);
699 kn->parent = parent;
700 }
701 return kn;
702}
703
704/*

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

958 if (!root)
959 return ERR_PTR(-ENOMEM);
960
961 idr_init(&root->ino_idr);
962 INIT_LIST_HEAD(&root->supers);
963 root->next_generation = 1;
964
965 kn = __kernfs_new_node(root, "", S_IFDIR | S_IRUGO | S_IXUGO,
966 GLOBAL_ROOT_UID, GLOBAL_ROOT_GID,
949 KERNFS_DIR);
950 if (!kn) {
951 idr_destroy(&root->ino_idr);
952 kfree(root);
953 return ERR_PTR(-ENOMEM);
954 }
955
956 kn->priv = priv;

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

979 kernfs_remove(root->kn); /* will also free @root */
980}
981
982/**
983 * kernfs_create_dir_ns - create a directory
984 * @parent: parent in which to create a new directory
985 * @name: name of the new directory
986 * @mode: mode of the new directory
967 KERNFS_DIR);
968 if (!kn) {
969 idr_destroy(&root->ino_idr);
970 kfree(root);
971 return ERR_PTR(-ENOMEM);
972 }
973
974 kn->priv = priv;

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

997 kernfs_remove(root->kn); /* will also free @root */
998}
999
1000/**
1001 * kernfs_create_dir_ns - create a directory
1002 * @parent: parent in which to create a new directory
1003 * @name: name of the new directory
1004 * @mode: mode of the new directory
1005 * @uid: uid of the new directory
1006 * @gid: gid of the new directory
987 * @priv: opaque data associated with the new directory
988 * @ns: optional namespace tag of the directory
989 *
990 * Returns the created node on success, ERR_PTR() value on failure.
991 */
992struct kernfs_node *kernfs_create_dir_ns(struct kernfs_node *parent,
993 const char *name, umode_t mode,
1007 * @priv: opaque data associated with the new directory
1008 * @ns: optional namespace tag of the directory
1009 *
1010 * Returns the created node on success, ERR_PTR() value on failure.
1011 */
1012struct kernfs_node *kernfs_create_dir_ns(struct kernfs_node *parent,
1013 const char *name, umode_t mode,
1014 kuid_t uid, kgid_t gid,
994 void *priv, const void *ns)
995{
996 struct kernfs_node *kn;
997 int rc;
998
999 /* allocate */
1015 void *priv, const void *ns)
1016{
1017 struct kernfs_node *kn;
1018 int rc;
1019
1020 /* allocate */
1000 kn = kernfs_new_node(parent, name, mode | S_IFDIR, KERNFS_DIR);
1021 kn = kernfs_new_node(parent, name, mode | S_IFDIR,
1022 uid, gid, KERNFS_DIR);
1001 if (!kn)
1002 return ERR_PTR(-ENOMEM);
1003
1004 kn->dir.root = parent->dir.root;
1005 kn->ns = ns;
1006 kn->priv = priv;
1007
1008 /* link in */

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

1023 */
1024struct kernfs_node *kernfs_create_empty_dir(struct kernfs_node *parent,
1025 const char *name)
1026{
1027 struct kernfs_node *kn;
1028 int rc;
1029
1030 /* allocate */
1023 if (!kn)
1024 return ERR_PTR(-ENOMEM);
1025
1026 kn->dir.root = parent->dir.root;
1027 kn->ns = ns;
1028 kn->priv = priv;
1029
1030 /* link in */

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

1045 */
1046struct kernfs_node *kernfs_create_empty_dir(struct kernfs_node *parent,
1047 const char *name)
1048{
1049 struct kernfs_node *kn;
1050 int rc;
1051
1052 /* allocate */
1031 kn = kernfs_new_node(parent, name, S_IRUGO|S_IXUGO|S_IFDIR, KERNFS_DIR);
1053 kn = kernfs_new_node(parent, name, S_IRUGO|S_IXUGO|S_IFDIR,
1054 GLOBAL_ROOT_UID, GLOBAL_ROOT_GID, KERNFS_DIR);
1032 if (!kn)
1033 return ERR_PTR(-ENOMEM);
1034
1035 kn->flags |= KERNFS_EMPTY_DIR;
1036 kn->dir.root = parent->dir.root;
1037 kn->ns = NULL;
1038 kn->priv = NULL;
1039

--- 640 unchanged lines hidden ---
1055 if (!kn)
1056 return ERR_PTR(-ENOMEM);
1057
1058 kn->flags |= KERNFS_EMPTY_DIR;
1059 kn->dir.root = parent->dir.root;
1060 kn->ns = NULL;
1061 kn->priv = NULL;
1062

--- 640 unchanged lines hidden ---