aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/base/devtmpfs.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2009-12-11 18:24:56 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2009-12-11 18:24:56 -0500
commitf58df54a54451c5feb2fdc4bc2f4fb12cf79be01 (patch)
tree930b5892717ce84de93508407ebc35757bbc5ea0 /drivers/base/devtmpfs.c
parent748e566b7e24541e05e3e70be311887a1262f2a1 (diff)
parent3589972e51fac1e02d0aaa576fa47f568cb94d40 (diff)
Merge git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core-2.6
* git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core-2.6: (27 commits) Driver core: fix race in dev_driver_string Driver Core: Early platform driver buffer sysfs: sysfs_setattr remove unnecessary permission check. sysfs: Factor out sysfs_rename from sysfs_rename_dir and sysfs_move_dir sysfs: Propagate renames to the vfs on demand sysfs: Gut sysfs_addrm_start and sysfs_addrm_finish sysfs: In sysfs_chmod_file lazily propagate the mode change. sysfs: Implement sysfs_getattr & sysfs_permission sysfs: Nicely indent sysfs_symlink_inode_operations sysfs: Update s_iattr on link and unlink. sysfs: Fix locking and factor out sysfs_sd_setattr sysfs: Simplify iattr time assignments sysfs: Simplify sysfs_chmod_file semantics sysfs: Use dentry_ops instead of directly playing with the dcache sysfs: Rename sysfs_d_iput to sysfs_dentry_iput sysfs: Update sysfs_setxattr so it updates secdata under the sysfs_mutex debugfs: fix create mutex racy fops and private data Driver core: Don't remove kobjects in device_shutdown. firmware_class: make request_firmware_nowait more useful Driver-Core: devtmpfs - set root directory mode to 0755 ...
Diffstat (limited to 'drivers/base/devtmpfs.c')
-rw-r--r--drivers/base/devtmpfs.c100
1 files changed, 50 insertions, 50 deletions
diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
index a1cb5afe6801..50375bb8e51d 100644
--- a/drivers/base/devtmpfs.c
+++ b/drivers/base/devtmpfs.c
@@ -32,6 +32,8 @@ static int dev_mount = 1;
32static int dev_mount; 32static int dev_mount;
33#endif 33#endif
34 34
35static rwlock_t dirlock;
36
35static int __init mount_param(char *str) 37static int __init mount_param(char *str)
36{ 38{
37 dev_mount = simple_strtoul(str, NULL, 0); 39 dev_mount = simple_strtoul(str, NULL, 0);
@@ -74,47 +76,35 @@ static int dev_mkdir(const char *name, mode_t mode)
74 dentry = lookup_create(&nd, 1); 76 dentry = lookup_create(&nd, 1);
75 if (!IS_ERR(dentry)) { 77 if (!IS_ERR(dentry)) {
76 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;
77 dput(dentry); 82 dput(dentry);
78 } else { 83 } else {
79 err = PTR_ERR(dentry); 84 err = PTR_ERR(dentry);
80 } 85 }
81 mutex_unlock(&nd.path.dentry->d_inode->i_mutex);
82 86
87 mutex_unlock(&nd.path.dentry->d_inode->i_mutex);
83 path_put(&nd.path); 88 path_put(&nd.path);
84 return err; 89 return err;
85} 90}
86 91
87static int create_path(const char *nodepath) 92static int create_path(const char *nodepath)
88{ 93{
89 char *path; 94 int err;
90 struct nameidata nd;
91 int err = 0;
92
93 path = kstrdup(nodepath, GFP_KERNEL);
94 if (!path)
95 return -ENOMEM;
96
97 err = vfs_path_lookup(dev_mnt->mnt_root, dev_mnt,
98 path, LOOKUP_PARENT, &nd);
99 if (err == 0) {
100 struct dentry *dentry;
101
102 /* create directory right away */
103 dentry = lookup_create(&nd, 1);
104 if (!IS_ERR(dentry)) {
105 err = vfs_mkdir(nd.path.dentry->d_inode,
106 dentry, 0755);
107 dput(dentry);
108 }
109 mutex_unlock(&nd.path.dentry->d_inode->i_mutex);
110 95
111 path_put(&nd.path); 96 read_lock(&dirlock);
112 } else if (err == -ENOENT) { 97 err = dev_mkdir(nodepath, 0755);
98 if (err == -ENOENT) {
99 char *path;
113 char *s; 100 char *s;
114 101
115 /* parent directories do not exist, create them */ 102 /* parent directories do not exist, create them */
103 path = kstrdup(nodepath, GFP_KERNEL);
104 if (!path)
105 return -ENOMEM;
116 s = path; 106 s = path;
117 while (1) { 107 for (;;) {
118 s = strchr(s, '/'); 108 s = strchr(s, '/');
119 if (!s) 109 if (!s)
120 break; 110 break;
@@ -125,9 +115,9 @@ static int create_path(const char *nodepath)
125 s[0] = '/'; 115 s[0] = '/';
126 s++; 116 s++;
127 } 117 }
118 kfree(path);
128 } 119 }
129 120 read_unlock(&dirlock);
130 kfree(path);
131 return err; 121 return err;
132} 122}
133 123
@@ -156,34 +146,40 @@ int devtmpfs_create_node(struct device *dev)
156 mode |= S_IFCHR; 146 mode |= S_IFCHR;
157 147
158 curr_cred = override_creds(&init_cred); 148 curr_cred = override_creds(&init_cred);
149
159 err = vfs_path_lookup(dev_mnt->mnt_root, dev_mnt, 150 err = vfs_path_lookup(dev_mnt->mnt_root, dev_mnt,
160 nodename, LOOKUP_PARENT, &nd); 151 nodename, LOOKUP_PARENT, &nd);
161 if (err == -ENOENT) { 152 if (err == -ENOENT) {
162 /* create missing parent directories */
163 create_path(nodename); 153 create_path(nodename);
164 err = vfs_path_lookup(dev_mnt->mnt_root, dev_mnt, 154 err = vfs_path_lookup(dev_mnt->mnt_root, dev_mnt,
165 nodename, LOOKUP_PARENT, &nd); 155 nodename, LOOKUP_PARENT, &nd);
166 if (err)
167 goto out;
168 } 156 }
157 if (err)
158 goto out;
169 159
170 dentry = lookup_create(&nd, 0); 160 dentry = lookup_create(&nd, 0);
171 if (!IS_ERR(dentry)) { 161 if (!IS_ERR(dentry)) {
172 int umask;
173
174 umask = sys_umask(0000);
175 err = vfs_mknod(nd.path.dentry->d_inode, 162 err = vfs_mknod(nd.path.dentry->d_inode,
176 dentry, mode, dev->devt); 163 dentry, mode, dev->devt);
177 sys_umask(umask); 164 if (!err) {
178 /* mark as kernel created inode */ 165 struct iattr newattrs;
179 if (!err) 166
167 /* fixup possibly umasked mode */
168 newattrs.ia_mode = mode;
169 newattrs.ia_valid = ATTR_MODE;
170 mutex_lock(&dentry->d_inode->i_mutex);
171 notify_change(dentry, &newattrs);
172 mutex_unlock(&dentry->d_inode->i_mutex);
173
174 /* mark as kernel-created inode */
180 dentry->d_inode->i_private = &dev_mnt; 175 dentry->d_inode->i_private = &dev_mnt;
176 }
181 dput(dentry); 177 dput(dentry);
182 } else { 178 } else {
183 err = PTR_ERR(dentry); 179 err = PTR_ERR(dentry);
184 } 180 }
185 mutex_unlock(&nd.path.dentry->d_inode->i_mutex);
186 181
182 mutex_unlock(&nd.path.dentry->d_inode->i_mutex);
187 path_put(&nd.path); 183 path_put(&nd.path);
188out: 184out:
189 kfree(tmp); 185 kfree(tmp);
@@ -205,16 +201,21 @@ static int dev_rmdir(const char *name)
205 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);
206 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);
207 if (!IS_ERR(dentry)) { 203 if (!IS_ERR(dentry)) {
208 if (dentry->d_inode) 204 if (dentry->d_inode) {
209 err = vfs_rmdir(nd.path.dentry->d_inode, dentry); 205 if (dentry->d_inode->i_private == &dev_mnt)
210 else 206 err = vfs_rmdir(nd.path.dentry->d_inode,
207 dentry);
208 else
209 err = -EPERM;
210 } else {
211 err = -ENOENT; 211 err = -ENOENT;
212 }
212 dput(dentry); 213 dput(dentry);
213 } else { 214 } else {
214 err = PTR_ERR(dentry); 215 err = PTR_ERR(dentry);
215 } 216 }
216 mutex_unlock(&nd.path.dentry->d_inode->i_mutex);
217 217
218 mutex_unlock(&nd.path.dentry->d_inode->i_mutex);
218 path_put(&nd.path); 219 path_put(&nd.path);
219 return err; 220 return err;
220} 221}
@@ -228,7 +229,8 @@ static int delete_path(const char *nodepath)
228 if (!path) 229 if (!path)
229 return -ENOMEM; 230 return -ENOMEM;
230 231
231 while (1) { 232 write_lock(&dirlock);
233 for (;;) {
232 char *base; 234 char *base;
233 235
234 base = strrchr(path, '/'); 236 base = strrchr(path, '/');
@@ -239,6 +241,7 @@ static int delete_path(const char *nodepath)
239 if (err) 241 if (err)
240 break; 242 break;
241 } 243 }
244 write_unlock(&dirlock);
242 245
243 kfree(path); 246 kfree(path);
244 return err; 247 return err;
@@ -322,9 +325,8 @@ out:
322 * If configured, or requested by the commandline, devtmpfs will be 325 * If configured, or requested by the commandline, devtmpfs will be
323 * auto-mounted after the kernel mounted the root filesystem. 326 * auto-mounted after the kernel mounted the root filesystem.
324 */ 327 */
325int devtmpfs_mount(const char *mountpoint) 328int devtmpfs_mount(const char *mntdir)
326{ 329{
327 struct path path;
328 int err; 330 int err;
329 331
330 if (!dev_mount) 332 if (!dev_mount)
@@ -333,15 +335,11 @@ int devtmpfs_mount(const char *mountpoint)
333 if (!dev_mnt) 335 if (!dev_mnt)
334 return 0; 336 return 0;
335 337
336 err = kern_path(mountpoint, LOOKUP_FOLLOW, &path); 338 err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
337 if (err)
338 return err;
339 err = do_add_mount(dev_mnt, &path, 0, NULL);
340 if (err) 339 if (err)
341 printk(KERN_INFO "devtmpfs: error mounting %i\n", err); 340 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
342 else 341 else
343 printk(KERN_INFO "devtmpfs: mounted\n"); 342 printk(KERN_INFO "devtmpfs: mounted\n");
344 path_put(&path);
345 return err; 343 return err;
346} 344}
347 345
@@ -354,6 +352,8 @@ int __init devtmpfs_init(void)
354 int err; 352 int err;
355 struct vfsmount *mnt; 353 struct vfsmount *mnt;
356 354
355 rwlock_init(&dirlock);
356
357 err = register_filesystem(&dev_fs_type); 357 err = register_filesystem(&dev_fs_type);
358 if (err) { 358 if (err) {
359 printk(KERN_ERR "devtmpfs: unable to register devtmpfs " 359 printk(KERN_ERR "devtmpfs: unable to register devtmpfs "
@@ -361,7 +361,7 @@ int __init devtmpfs_init(void)
361 return err; 361 return err;
362 } 362 }
363 363
364 mnt = kern_mount(&dev_fs_type); 364 mnt = kern_mount_data(&dev_fs_type, "mode=0755");
365 if (IS_ERR(mnt)) { 365 if (IS_ERR(mnt)) {
366 err = PTR_ERR(mnt); 366 err = PTR_ERR(mnt);
367 printk(KERN_ERR "devtmpfs: unable to create devtmpfs %i\n", err); 367 printk(KERN_ERR "devtmpfs: unable to create devtmpfs %i\n", err);