aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/base/devtmpfs.c
diff options
context:
space:
mode:
authorKay Sievers <kay.sievers@vrfy.org>2009-10-28 14:51:26 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2009-12-11 14:24:52 -0500
commit015bf43b07158668c2f38af463939afcc6d19403 (patch)
treeeb0b7fd69fbbe304e8fcf1490f1ba9d745d1019c /drivers/base/devtmpfs.c
parent073120cc28ad9f6003452c8bb9d15a87b1820201 (diff)
Driver Core: devtmpfs: do not remove non-kernel-created directories
Signed-off-by: Kay Sievers <kay.sievers@vrfy.org> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/base/devtmpfs.c')
-rw-r--r--drivers/base/devtmpfs.c39
1 files changed, 16 insertions, 23 deletions
diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
index 880a203b6688..c7f5c08f8790 100644
--- a/drivers/base/devtmpfs.c
+++ b/drivers/base/devtmpfs.c
@@ -76,37 +76,26 @@ static int dev_mkdir(const char *name, mode_t mode)
76 dentry = lookup_create(&nd, 1); 76 dentry = lookup_create(&nd, 1);
77 if (!IS_ERR(dentry)) { 77 if (!IS_ERR(dentry)) {
78 err = vfs_mkdir(nd.path.dentry->d_inode, dentry, mode); 78 err = vfs_mkdir(nd.path.dentry->d_inode, dentry, mode);
79 if (!err)
80 /* mark as kernel-created inode */
81 dentry->d_inode->i_private = &dev_mnt;
79 dput(dentry); 82 dput(dentry);
80 } else { 83 } else {
81 err = PTR_ERR(dentry); 84 err = PTR_ERR(dentry);
82 } 85 }
83 mutex_unlock(&nd.path.dentry->d_inode->i_mutex);
84 86
87 mutex_unlock(&nd.path.dentry->d_inode->i_mutex);
85 path_put(&nd.path); 88 path_put(&nd.path);
86 return err; 89 return err;
87} 90}
88 91
89static int create_path(const char *nodepath) 92static int create_path(const char *nodepath)
90{ 93{
91 struct nameidata nd; 94 int err;
92 int err = 0;
93 95
94 read_lock(&dirlock); 96 read_lock(&dirlock);
95 err = vfs_path_lookup(dev_mnt->mnt_root, dev_mnt, 97 err = dev_mkdir(nodepath, 0755);
96 nodepath, LOOKUP_PARENT, &nd); 98 if (err == -ENOENT) {
97 if (err == 0) {
98 struct dentry *dentry;
99
100 /* create directory right away */
101 dentry = lookup_create(&nd, 1);
102 if (!IS_ERR(dentry)) {
103 err = vfs_mkdir(nd.path.dentry->d_inode,
104 dentry, 0755);
105 dput(dentry);
106 }
107 mutex_unlock(&nd.path.dentry->d_inode->i_mutex);
108 path_put(&nd.path);
109 } else if (err == -ENOENT) {
110 char *path; 99 char *path;
111 char *s; 100 char *s;
112 101
@@ -129,7 +118,6 @@ static int create_path(const char *nodepath)
129 kfree(path); 118 kfree(path);
130 } 119 }
131 read_unlock(&dirlock); 120 read_unlock(&dirlock);
132
133 return err; 121 return err;
134} 122}
135 123
@@ -213,16 +201,21 @@ static int dev_rmdir(const char *name)
213 mutex_lock_nested(&nd.path.dentry->d_inode->i_mutex, I_MUTEX_PARENT); 201 mutex_lock_nested(&nd.path.dentry->d_inode->i_mutex, I_MUTEX_PARENT);
214 dentry = lookup_one_len(nd.last.name, nd.path.dentry, nd.last.len); 202 dentry = lookup_one_len(nd.last.name, nd.path.dentry, nd.last.len);
215 if (!IS_ERR(dentry)) { 203 if (!IS_ERR(dentry)) {
216 if (dentry->d_inode) 204 if (dentry->d_inode) {
217 err = vfs_rmdir(nd.path.dentry->d_inode, dentry); 205 if (dentry->d_inode->i_private == &dev_mnt)
218 else 206 err = vfs_rmdir(nd.path.dentry->d_inode,
207 dentry);
208 else
209 err = -EPERM;
210 } else {
219 err = -ENOENT; 211 err = -ENOENT;
212 }
220 dput(dentry); 213 dput(dentry);
221 } else { 214 } else {
222 err = PTR_ERR(dentry); 215 err = PTR_ERR(dentry);
223 } 216 }
224 mutex_unlock(&nd.path.dentry->d_inode->i_mutex);
225 217
218 mutex_unlock(&nd.path.dentry->d_inode->i_mutex);
226 path_put(&nd.path); 219 path_put(&nd.path);
227 return err; 220 return err;
228} 221}