Kay Sievers | 2b2af54 | 2009-04-30 15:23:42 +0200 | [diff] [blame] | 1 | /* |
| 2 | * devtmpfs - kernel-maintained tmpfs-based /dev |
| 3 | * |
| 4 | * Copyright (C) 2009, Kay Sievers <kay.sievers@vrfy.org> |
| 5 | * |
| 6 | * During bootup, before any driver core device is registered, |
| 7 | * devtmpfs, a tmpfs-based filesystem is created. Every driver-core |
| 8 | * device which requests a device node, will add a node in this |
Kay Sievers | e454cea | 2009-09-18 23:01:12 +0200 | [diff] [blame] | 9 | * filesystem. |
| 10 | * By default, all devices are named after the the name of the |
| 11 | * device, owned by root and have a default mode of 0600. Subsystems |
| 12 | * can overwrite the default setting if needed. |
Kay Sievers | 2b2af54 | 2009-04-30 15:23:42 +0200 | [diff] [blame] | 13 | */ |
| 14 | |
| 15 | #include <linux/kernel.h> |
| 16 | #include <linux/syscalls.h> |
| 17 | #include <linux/mount.h> |
| 18 | #include <linux/device.h> |
| 19 | #include <linux/genhd.h> |
| 20 | #include <linux/namei.h> |
| 21 | #include <linux/fs.h> |
| 22 | #include <linux/shmem_fs.h> |
Peter Korsgaard | da5e4ef | 2010-03-16 21:55:21 +0100 | [diff] [blame] | 23 | #include <linux/ramfs.h> |
Kay Sievers | 2b2af54 | 2009-04-30 15:23:42 +0200 | [diff] [blame] | 24 | #include <linux/cred.h> |
Kay Sievers | e454cea | 2009-09-18 23:01:12 +0200 | [diff] [blame] | 25 | #include <linux/sched.h> |
Kay Sievers | 2b2af54 | 2009-04-30 15:23:42 +0200 | [diff] [blame] | 26 | #include <linux/init_task.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 27 | #include <linux/slab.h> |
Kay Sievers | 2b2af54 | 2009-04-30 15:23:42 +0200 | [diff] [blame] | 28 | |
| 29 | static struct vfsmount *dev_mnt; |
| 30 | |
| 31 | #if defined CONFIG_DEVTMPFS_MOUNT |
Al Viro | fc14f2f | 2010-07-25 01:48:30 +0400 | [diff] [blame] | 32 | static int mount_dev = 1; |
Kay Sievers | 2b2af54 | 2009-04-30 15:23:42 +0200 | [diff] [blame] | 33 | #else |
Al Viro | fc14f2f | 2010-07-25 01:48:30 +0400 | [diff] [blame] | 34 | static int mount_dev; |
Kay Sievers | 2b2af54 | 2009-04-30 15:23:42 +0200 | [diff] [blame] | 35 | #endif |
| 36 | |
Thomas Gleixner | f1f76f8 | 2009-12-16 21:31:33 +0000 | [diff] [blame] | 37 | static DEFINE_MUTEX(dirlock); |
Kay Sievers | ed413ae | 2009-10-28 19:51:06 +0100 | [diff] [blame] | 38 | |
Kay Sievers | 2b2af54 | 2009-04-30 15:23:42 +0200 | [diff] [blame] | 39 | static int __init mount_param(char *str) |
| 40 | { |
Al Viro | fc14f2f | 2010-07-25 01:48:30 +0400 | [diff] [blame] | 41 | mount_dev = simple_strtoul(str, NULL, 0); |
Kay Sievers | 2b2af54 | 2009-04-30 15:23:42 +0200 | [diff] [blame] | 42 | return 1; |
| 43 | } |
| 44 | __setup("devtmpfs.mount=", mount_param); |
| 45 | |
Al Viro | fc14f2f | 2010-07-25 01:48:30 +0400 | [diff] [blame] | 46 | static struct dentry *dev_mount(struct file_system_type *fs_type, int flags, |
| 47 | const char *dev_name, void *data) |
Kay Sievers | 2b2af54 | 2009-04-30 15:23:42 +0200 | [diff] [blame] | 48 | { |
Peter Korsgaard | da5e4ef | 2010-03-16 21:55:21 +0100 | [diff] [blame] | 49 | #ifdef CONFIG_TMPFS |
Al Viro | fc14f2f | 2010-07-25 01:48:30 +0400 | [diff] [blame] | 50 | return mount_single(fs_type, flags, data, shmem_fill_super); |
Peter Korsgaard | da5e4ef | 2010-03-16 21:55:21 +0100 | [diff] [blame] | 51 | #else |
Al Viro | fc14f2f | 2010-07-25 01:48:30 +0400 | [diff] [blame] | 52 | return mount_single(fs_type, flags, data, ramfs_fill_super); |
Peter Korsgaard | da5e4ef | 2010-03-16 21:55:21 +0100 | [diff] [blame] | 53 | #endif |
Kay Sievers | 2b2af54 | 2009-04-30 15:23:42 +0200 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | static struct file_system_type dev_fs_type = { |
| 57 | .name = "devtmpfs", |
Al Viro | fc14f2f | 2010-07-25 01:48:30 +0400 | [diff] [blame] | 58 | .mount = dev_mount, |
Kay Sievers | 2b2af54 | 2009-04-30 15:23:42 +0200 | [diff] [blame] | 59 | .kill_sb = kill_litter_super, |
| 60 | }; |
| 61 | |
| 62 | #ifdef CONFIG_BLOCK |
| 63 | static inline int is_blockdev(struct device *dev) |
| 64 | { |
| 65 | return dev->class == &block_class; |
| 66 | } |
| 67 | #else |
| 68 | static inline int is_blockdev(struct device *dev) { return 0; } |
| 69 | #endif |
| 70 | |
| 71 | static int dev_mkdir(const char *name, mode_t mode) |
| 72 | { |
| 73 | struct nameidata nd; |
| 74 | struct dentry *dentry; |
| 75 | int err; |
| 76 | |
| 77 | err = vfs_path_lookup(dev_mnt->mnt_root, dev_mnt, |
| 78 | name, LOOKUP_PARENT, &nd); |
| 79 | if (err) |
| 80 | return err; |
| 81 | |
| 82 | dentry = lookup_create(&nd, 1); |
| 83 | if (!IS_ERR(dentry)) { |
| 84 | err = vfs_mkdir(nd.path.dentry->d_inode, dentry, mode); |
Kay Sievers | 015bf43 | 2009-10-28 19:51:26 +0100 | [diff] [blame] | 85 | if (!err) |
| 86 | /* mark as kernel-created inode */ |
| 87 | dentry->d_inode->i_private = &dev_mnt; |
Kay Sievers | 2b2af54 | 2009-04-30 15:23:42 +0200 | [diff] [blame] | 88 | dput(dentry); |
| 89 | } else { |
| 90 | err = PTR_ERR(dentry); |
| 91 | } |
Kay Sievers | 2b2af54 | 2009-04-30 15:23:42 +0200 | [diff] [blame] | 92 | |
Kay Sievers | 015bf43 | 2009-10-28 19:51:26 +0100 | [diff] [blame] | 93 | mutex_unlock(&nd.path.dentry->d_inode->i_mutex); |
Kay Sievers | 2b2af54 | 2009-04-30 15:23:42 +0200 | [diff] [blame] | 94 | path_put(&nd.path); |
| 95 | return err; |
| 96 | } |
| 97 | |
| 98 | static int create_path(const char *nodepath) |
| 99 | { |
Kay Sievers | 015bf43 | 2009-10-28 19:51:26 +0100 | [diff] [blame] | 100 | int err; |
Kay Sievers | 2b2af54 | 2009-04-30 15:23:42 +0200 | [diff] [blame] | 101 | |
Thomas Gleixner | f1f76f8 | 2009-12-16 21:31:33 +0000 | [diff] [blame] | 102 | mutex_lock(&dirlock); |
Kay Sievers | 015bf43 | 2009-10-28 19:51:26 +0100 | [diff] [blame] | 103 | err = dev_mkdir(nodepath, 0755); |
| 104 | if (err == -ENOENT) { |
Kay Sievers | ed413ae | 2009-10-28 19:51:06 +0100 | [diff] [blame] | 105 | char *path; |
Kay Sievers | 2b2af54 | 2009-04-30 15:23:42 +0200 | [diff] [blame] | 106 | char *s; |
| 107 | |
| 108 | /* parent directories do not exist, create them */ |
Kay Sievers | ed413ae | 2009-10-28 19:51:06 +0100 | [diff] [blame] | 109 | path = kstrdup(nodepath, GFP_KERNEL); |
Kay Sievers | 8042273 | 2009-12-22 22:25:16 +0100 | [diff] [blame] | 110 | if (!path) { |
| 111 | err = -ENOMEM; |
| 112 | goto out; |
| 113 | } |
Kay Sievers | 2b2af54 | 2009-04-30 15:23:42 +0200 | [diff] [blame] | 114 | s = path; |
Kay Sievers | ed413ae | 2009-10-28 19:51:06 +0100 | [diff] [blame] | 115 | for (;;) { |
Kay Sievers | 2b2af54 | 2009-04-30 15:23:42 +0200 | [diff] [blame] | 116 | s = strchr(s, '/'); |
| 117 | if (!s) |
| 118 | break; |
| 119 | s[0] = '\0'; |
| 120 | err = dev_mkdir(path, 0755); |
| 121 | if (err && err != -EEXIST) |
| 122 | break; |
| 123 | s[0] = '/'; |
| 124 | s++; |
| 125 | } |
Kay Sievers | ed413ae | 2009-10-28 19:51:06 +0100 | [diff] [blame] | 126 | kfree(path); |
Kay Sievers | 2b2af54 | 2009-04-30 15:23:42 +0200 | [diff] [blame] | 127 | } |
Kay Sievers | 8042273 | 2009-12-22 22:25:16 +0100 | [diff] [blame] | 128 | out: |
Thomas Gleixner | f1f76f8 | 2009-12-16 21:31:33 +0000 | [diff] [blame] | 129 | mutex_unlock(&dirlock); |
Kay Sievers | 2b2af54 | 2009-04-30 15:23:42 +0200 | [diff] [blame] | 130 | return err; |
| 131 | } |
| 132 | |
| 133 | int devtmpfs_create_node(struct device *dev) |
| 134 | { |
| 135 | const char *tmp = NULL; |
| 136 | const char *nodename; |
| 137 | const struct cred *curr_cred; |
Kay Sievers | e454cea | 2009-09-18 23:01:12 +0200 | [diff] [blame] | 138 | mode_t mode = 0; |
Kay Sievers | 2b2af54 | 2009-04-30 15:23:42 +0200 | [diff] [blame] | 139 | struct nameidata nd; |
| 140 | struct dentry *dentry; |
| 141 | int err; |
| 142 | |
| 143 | if (!dev_mnt) |
| 144 | return 0; |
| 145 | |
Kay Sievers | e454cea | 2009-09-18 23:01:12 +0200 | [diff] [blame] | 146 | nodename = device_get_devnode(dev, &mode, &tmp); |
Kay Sievers | 2b2af54 | 2009-04-30 15:23:42 +0200 | [diff] [blame] | 147 | if (!nodename) |
| 148 | return -ENOMEM; |
| 149 | |
Kay Sievers | e454cea | 2009-09-18 23:01:12 +0200 | [diff] [blame] | 150 | if (mode == 0) |
| 151 | mode = 0600; |
Kay Sievers | 2b2af54 | 2009-04-30 15:23:42 +0200 | [diff] [blame] | 152 | if (is_blockdev(dev)) |
Kay Sievers | e454cea | 2009-09-18 23:01:12 +0200 | [diff] [blame] | 153 | mode |= S_IFBLK; |
Kay Sievers | 2b2af54 | 2009-04-30 15:23:42 +0200 | [diff] [blame] | 154 | else |
Kay Sievers | e454cea | 2009-09-18 23:01:12 +0200 | [diff] [blame] | 155 | mode |= S_IFCHR; |
Kay Sievers | 2b2af54 | 2009-04-30 15:23:42 +0200 | [diff] [blame] | 156 | |
| 157 | curr_cred = override_creds(&init_cred); |
Kay Sievers | 0092699 | 2009-10-28 19:50:57 +0100 | [diff] [blame] | 158 | |
Kay Sievers | 2b2af54 | 2009-04-30 15:23:42 +0200 | [diff] [blame] | 159 | err = vfs_path_lookup(dev_mnt->mnt_root, dev_mnt, |
| 160 | nodename, LOOKUP_PARENT, &nd); |
| 161 | if (err == -ENOENT) { |
Kay Sievers | 2b2af54 | 2009-04-30 15:23:42 +0200 | [diff] [blame] | 162 | create_path(nodename); |
| 163 | err = vfs_path_lookup(dev_mnt->mnt_root, dev_mnt, |
| 164 | nodename, LOOKUP_PARENT, &nd); |
Kay Sievers | 2b2af54 | 2009-04-30 15:23:42 +0200 | [diff] [blame] | 165 | } |
Kay Sievers | 0092699 | 2009-10-28 19:50:57 +0100 | [diff] [blame] | 166 | if (err) |
| 167 | goto out; |
Kay Sievers | 2b2af54 | 2009-04-30 15:23:42 +0200 | [diff] [blame] | 168 | |
| 169 | dentry = lookup_create(&nd, 0); |
| 170 | if (!IS_ERR(dentry)) { |
| 171 | err = vfs_mknod(nd.path.dentry->d_inode, |
| 172 | dentry, mode, dev->devt); |
Kay Sievers | 0092699 | 2009-10-28 19:50:57 +0100 | [diff] [blame] | 173 | if (!err) { |
| 174 | struct iattr newattrs; |
| 175 | |
| 176 | /* fixup possibly umasked mode */ |
| 177 | newattrs.ia_mode = mode; |
| 178 | newattrs.ia_valid = ATTR_MODE; |
| 179 | mutex_lock(&dentry->d_inode->i_mutex); |
| 180 | notify_change(dentry, &newattrs); |
| 181 | mutex_unlock(&dentry->d_inode->i_mutex); |
| 182 | |
| 183 | /* mark as kernel-created inode */ |
Kay Sievers | 2b2af54 | 2009-04-30 15:23:42 +0200 | [diff] [blame] | 184 | dentry->d_inode->i_private = &dev_mnt; |
Kay Sievers | 0092699 | 2009-10-28 19:50:57 +0100 | [diff] [blame] | 185 | } |
Kay Sievers | 2b2af54 | 2009-04-30 15:23:42 +0200 | [diff] [blame] | 186 | dput(dentry); |
| 187 | } else { |
| 188 | err = PTR_ERR(dentry); |
| 189 | } |
Kay Sievers | 2b2af54 | 2009-04-30 15:23:42 +0200 | [diff] [blame] | 190 | |
Kay Sievers | 0092699 | 2009-10-28 19:50:57 +0100 | [diff] [blame] | 191 | mutex_unlock(&nd.path.dentry->d_inode->i_mutex); |
Kay Sievers | 2b2af54 | 2009-04-30 15:23:42 +0200 | [diff] [blame] | 192 | path_put(&nd.path); |
| 193 | out: |
| 194 | kfree(tmp); |
| 195 | revert_creds(curr_cred); |
| 196 | return err; |
| 197 | } |
| 198 | |
| 199 | static int dev_rmdir(const char *name) |
| 200 | { |
| 201 | struct nameidata nd; |
| 202 | struct dentry *dentry; |
| 203 | int err; |
| 204 | |
| 205 | err = vfs_path_lookup(dev_mnt->mnt_root, dev_mnt, |
| 206 | name, LOOKUP_PARENT, &nd); |
| 207 | if (err) |
| 208 | return err; |
| 209 | |
| 210 | mutex_lock_nested(&nd.path.dentry->d_inode->i_mutex, I_MUTEX_PARENT); |
| 211 | dentry = lookup_one_len(nd.last.name, nd.path.dentry, nd.last.len); |
| 212 | if (!IS_ERR(dentry)) { |
Kay Sievers | 015bf43 | 2009-10-28 19:51:26 +0100 | [diff] [blame] | 213 | if (dentry->d_inode) { |
| 214 | if (dentry->d_inode->i_private == &dev_mnt) |
| 215 | err = vfs_rmdir(nd.path.dentry->d_inode, |
| 216 | dentry); |
| 217 | else |
| 218 | err = -EPERM; |
| 219 | } else { |
Kay Sievers | 2b2af54 | 2009-04-30 15:23:42 +0200 | [diff] [blame] | 220 | err = -ENOENT; |
Kay Sievers | 015bf43 | 2009-10-28 19:51:26 +0100 | [diff] [blame] | 221 | } |
Kay Sievers | 2b2af54 | 2009-04-30 15:23:42 +0200 | [diff] [blame] | 222 | dput(dentry); |
| 223 | } else { |
| 224 | err = PTR_ERR(dentry); |
| 225 | } |
Kay Sievers | 2b2af54 | 2009-04-30 15:23:42 +0200 | [diff] [blame] | 226 | |
Kay Sievers | 015bf43 | 2009-10-28 19:51:26 +0100 | [diff] [blame] | 227 | mutex_unlock(&nd.path.dentry->d_inode->i_mutex); |
Kay Sievers | 2b2af54 | 2009-04-30 15:23:42 +0200 | [diff] [blame] | 228 | path_put(&nd.path); |
| 229 | return err; |
| 230 | } |
| 231 | |
| 232 | static int delete_path(const char *nodepath) |
| 233 | { |
| 234 | const char *path; |
| 235 | int err = 0; |
| 236 | |
| 237 | path = kstrdup(nodepath, GFP_KERNEL); |
| 238 | if (!path) |
| 239 | return -ENOMEM; |
| 240 | |
Thomas Gleixner | f1f76f8 | 2009-12-16 21:31:33 +0000 | [diff] [blame] | 241 | mutex_lock(&dirlock); |
Kay Sievers | ed413ae | 2009-10-28 19:51:06 +0100 | [diff] [blame] | 242 | for (;;) { |
Kay Sievers | 2b2af54 | 2009-04-30 15:23:42 +0200 | [diff] [blame] | 243 | char *base; |
| 244 | |
| 245 | base = strrchr(path, '/'); |
| 246 | if (!base) |
| 247 | break; |
| 248 | base[0] = '\0'; |
| 249 | err = dev_rmdir(path); |
| 250 | if (err) |
| 251 | break; |
| 252 | } |
Thomas Gleixner | f1f76f8 | 2009-12-16 21:31:33 +0000 | [diff] [blame] | 253 | mutex_unlock(&dirlock); |
Kay Sievers | 2b2af54 | 2009-04-30 15:23:42 +0200 | [diff] [blame] | 254 | |
| 255 | kfree(path); |
| 256 | return err; |
| 257 | } |
| 258 | |
| 259 | static int dev_mynode(struct device *dev, struct inode *inode, struct kstat *stat) |
| 260 | { |
| 261 | /* did we create it */ |
| 262 | if (inode->i_private != &dev_mnt) |
| 263 | return 0; |
| 264 | |
| 265 | /* does the dev_t match */ |
| 266 | if (is_blockdev(dev)) { |
| 267 | if (!S_ISBLK(stat->mode)) |
| 268 | return 0; |
| 269 | } else { |
| 270 | if (!S_ISCHR(stat->mode)) |
| 271 | return 0; |
| 272 | } |
| 273 | if (stat->rdev != dev->devt) |
| 274 | return 0; |
| 275 | |
| 276 | /* ours */ |
| 277 | return 1; |
| 278 | } |
| 279 | |
| 280 | int devtmpfs_delete_node(struct device *dev) |
| 281 | { |
| 282 | const char *tmp = NULL; |
| 283 | const char *nodename; |
| 284 | const struct cred *curr_cred; |
| 285 | struct nameidata nd; |
| 286 | struct dentry *dentry; |
| 287 | struct kstat stat; |
| 288 | int deleted = 1; |
| 289 | int err; |
| 290 | |
| 291 | if (!dev_mnt) |
| 292 | return 0; |
| 293 | |
Kay Sievers | e454cea | 2009-09-18 23:01:12 +0200 | [diff] [blame] | 294 | nodename = device_get_devnode(dev, NULL, &tmp); |
Kay Sievers | 2b2af54 | 2009-04-30 15:23:42 +0200 | [diff] [blame] | 295 | if (!nodename) |
| 296 | return -ENOMEM; |
| 297 | |
| 298 | curr_cred = override_creds(&init_cred); |
| 299 | err = vfs_path_lookup(dev_mnt->mnt_root, dev_mnt, |
| 300 | nodename, LOOKUP_PARENT, &nd); |
| 301 | if (err) |
| 302 | goto out; |
| 303 | |
| 304 | mutex_lock_nested(&nd.path.dentry->d_inode->i_mutex, I_MUTEX_PARENT); |
| 305 | dentry = lookup_one_len(nd.last.name, nd.path.dentry, nd.last.len); |
| 306 | if (!IS_ERR(dentry)) { |
| 307 | if (dentry->d_inode) { |
| 308 | err = vfs_getattr(nd.path.mnt, dentry, &stat); |
| 309 | if (!err && dev_mynode(dev, dentry->d_inode, &stat)) { |
Kay Sievers | 5e31d76 | 2010-01-13 14:16:36 +0100 | [diff] [blame] | 310 | struct iattr newattrs; |
| 311 | /* |
| 312 | * before unlinking this node, reset permissions |
| 313 | * of possible references like hardlinks |
| 314 | */ |
| 315 | newattrs.ia_uid = 0; |
| 316 | newattrs.ia_gid = 0; |
| 317 | newattrs.ia_mode = stat.mode & ~0777; |
| 318 | newattrs.ia_valid = |
| 319 | ATTR_UID|ATTR_GID|ATTR_MODE; |
| 320 | mutex_lock(&dentry->d_inode->i_mutex); |
| 321 | notify_change(dentry, &newattrs); |
| 322 | mutex_unlock(&dentry->d_inode->i_mutex); |
Kay Sievers | 2b2af54 | 2009-04-30 15:23:42 +0200 | [diff] [blame] | 323 | err = vfs_unlink(nd.path.dentry->d_inode, |
| 324 | dentry); |
| 325 | if (!err || err == -ENOENT) |
| 326 | deleted = 1; |
| 327 | } |
| 328 | } else { |
| 329 | err = -ENOENT; |
| 330 | } |
| 331 | dput(dentry); |
| 332 | } else { |
| 333 | err = PTR_ERR(dentry); |
| 334 | } |
| 335 | mutex_unlock(&nd.path.dentry->d_inode->i_mutex); |
| 336 | |
| 337 | path_put(&nd.path); |
| 338 | if (deleted && strchr(nodename, '/')) |
| 339 | delete_path(nodename); |
| 340 | out: |
| 341 | kfree(tmp); |
| 342 | revert_creds(curr_cred); |
| 343 | return err; |
| 344 | } |
| 345 | |
| 346 | /* |
| 347 | * If configured, or requested by the commandline, devtmpfs will be |
| 348 | * auto-mounted after the kernel mounted the root filesystem. |
| 349 | */ |
Kay Sievers | 073120c | 2009-10-28 19:51:17 +0100 | [diff] [blame] | 350 | int devtmpfs_mount(const char *mntdir) |
Kay Sievers | 2b2af54 | 2009-04-30 15:23:42 +0200 | [diff] [blame] | 351 | { |
Kay Sievers | 2b2af54 | 2009-04-30 15:23:42 +0200 | [diff] [blame] | 352 | int err; |
| 353 | |
Al Viro | fc14f2f | 2010-07-25 01:48:30 +0400 | [diff] [blame] | 354 | if (!mount_dev) |
Kay Sievers | 2b2af54 | 2009-04-30 15:23:42 +0200 | [diff] [blame] | 355 | return 0; |
| 356 | |
| 357 | if (!dev_mnt) |
| 358 | return 0; |
| 359 | |
Kay Sievers | 073120c | 2009-10-28 19:51:17 +0100 | [diff] [blame] | 360 | err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL); |
Kay Sievers | 2b2af54 | 2009-04-30 15:23:42 +0200 | [diff] [blame] | 361 | if (err) |
| 362 | printk(KERN_INFO "devtmpfs: error mounting %i\n", err); |
| 363 | else |
| 364 | printk(KERN_INFO "devtmpfs: mounted\n"); |
Kay Sievers | 2b2af54 | 2009-04-30 15:23:42 +0200 | [diff] [blame] | 365 | return err; |
| 366 | } |
| 367 | |
| 368 | /* |
| 369 | * Create devtmpfs instance, driver-core devices will add their device |
| 370 | * nodes here. |
| 371 | */ |
| 372 | int __init devtmpfs_init(void) |
| 373 | { |
| 374 | int err; |
| 375 | struct vfsmount *mnt; |
Heiko Carstens | f776c5e | 2010-01-18 14:36:12 +0100 | [diff] [blame] | 376 | char options[] = "mode=0755"; |
Kay Sievers | 2b2af54 | 2009-04-30 15:23:42 +0200 | [diff] [blame] | 377 | |
Kay Sievers | 2b2af54 | 2009-04-30 15:23:42 +0200 | [diff] [blame] | 378 | err = register_filesystem(&dev_fs_type); |
| 379 | if (err) { |
| 380 | printk(KERN_ERR "devtmpfs: unable to register devtmpfs " |
| 381 | "type %i\n", err); |
| 382 | return err; |
| 383 | } |
| 384 | |
Heiko Carstens | f776c5e | 2010-01-18 14:36:12 +0100 | [diff] [blame] | 385 | mnt = kern_mount_data(&dev_fs_type, options); |
Kay Sievers | 2b2af54 | 2009-04-30 15:23:42 +0200 | [diff] [blame] | 386 | if (IS_ERR(mnt)) { |
| 387 | err = PTR_ERR(mnt); |
| 388 | printk(KERN_ERR "devtmpfs: unable to create devtmpfs %i\n", err); |
| 389 | unregister_filesystem(&dev_fs_type); |
| 390 | return err; |
| 391 | } |
| 392 | dev_mnt = mnt; |
| 393 | |
| 394 | printk(KERN_INFO "devtmpfs: initialized\n"); |
| 395 | return 0; |
| 396 | } |