blob: 8be352ab4ddbfdcfdda4885dde97c39b5477cf32 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Kay Sievers2b2af542009-04-30 15:23:42 +02002/*
3 * devtmpfs - kernel-maintained tmpfs-based /dev
4 *
5 * Copyright (C) 2009, Kay Sievers <kay.sievers@vrfy.org>
6 *
7 * During bootup, before any driver core device is registered,
8 * devtmpfs, a tmpfs-based filesystem is created. Every driver-core
9 * device which requests a device node, will add a node in this
Kay Sieverse454cea2009-09-18 23:01:12 +020010 * filesystem.
Peter Korsgaard02fbe5e2012-04-17 12:13:18 +020011 * By default, all devices are named after the name of the device,
12 * owned by root and have a default mode of 0600. Subsystems can
13 * overwrite the default setting if needed.
Kay Sievers2b2af542009-04-30 15:23:42 +020014 */
15
16#include <linux/kernel.h>
17#include <linux/syscalls.h>
18#include <linux/mount.h>
19#include <linux/device.h>
20#include <linux/genhd.h>
21#include <linux/namei.h>
22#include <linux/fs.h>
23#include <linux/shmem_fs.h>
Peter Korsgaardda5e4ef2010-03-16 21:55:21 +010024#include <linux/ramfs.h>
Kay Sieverse454cea2009-09-18 23:01:12 +020025#include <linux/sched.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090026#include <linux/slab.h>
Al Viro2780f1f2011-06-27 16:25:29 -040027#include <linux/kthread.h>
Christoph Hellwigc60166f2020-07-21 11:12:08 +020028#include <linux/init_syscalls.h>
David Howellse262e32d2018-11-01 23:07:23 +000029#include <uapi/linux/mount.h>
Greg Kroah-Hartmanc3a30422013-04-10 09:00:15 -070030#include "base.h"
Kay Sievers2b2af542009-04-30 15:23:42 +020031
Al Viro2780f1f2011-06-27 16:25:29 -040032static struct task_struct *thread;
Kay Sievers2b2af542009-04-30 15:23:42 +020033
Rasmus Villemoesfad1db82020-01-15 19:41:52 +010034static int __initdata mount_dev = IS_ENABLED(CONFIG_DEVTMPFS_MOUNT);
Kay Sievers2b2af542009-04-30 15:23:42 +020035
Al Viro2780f1f2011-06-27 16:25:29 -040036static DEFINE_SPINLOCK(req_lock);
37
38static struct req {
39 struct req *next;
40 struct completion done;
41 int err;
42 const char *name;
Al Viro2c9ede52011-07-23 20:24:48 -040043 umode_t mode; /* 0 => delete */
Greg Kroah-Hartman4e4098a2013-04-11 11:43:29 -070044 kuid_t uid;
45 kgid_t gid;
Al Viro2780f1f2011-06-27 16:25:29 -040046 struct device *dev;
47} *requests;
Kay Sieversed413ae2009-10-28 19:51:06 +010048
Kay Sievers2b2af542009-04-30 15:23:42 +020049static int __init mount_param(char *str)
50{
Al Virofc14f2f2010-07-25 01:48:30 +040051 mount_dev = simple_strtoul(str, NULL, 0);
Kay Sievers2b2af542009-04-30 15:23:42 +020052 return 1;
53}
54__setup("devtmpfs.mount=", mount_param);
55
Al Virod4017272019-06-01 18:43:09 -040056static struct vfsmount *mnt;
57
58static struct dentry *public_dev_mount(struct file_system_type *fs_type, int flags,
59 const char *dev_name, void *data)
60{
61 struct super_block *s = mnt->mnt_sb;
62 atomic_inc(&s->s_active);
63 down_write(&s->s_umount);
64 return dget(s->s_root);
65}
66
Al Virod4017272019-06-01 18:43:09 -040067static struct file_system_type internal_fs_type = {
Kay Sievers2b2af542009-04-30 15:23:42 +020068 .name = "devtmpfs",
David Howellsf3235622019-03-25 16:38:31 +000069#ifdef CONFIG_TMPFS
70 .init_fs_context = shmem_init_fs_context,
Al Virod7167b12019-09-07 07:23:15 -040071 .parameters = shmem_fs_parameters,
David Howellsf3235622019-03-25 16:38:31 +000072#else
73 .init_fs_context = ramfs_init_fs_context,
Al Virod7167b12019-09-07 07:23:15 -040074 .parameters = ramfs_fs_parameters,
David Howellsf3235622019-03-25 16:38:31 +000075#endif
Kay Sievers2b2af542009-04-30 15:23:42 +020076 .kill_sb = kill_litter_super,
77};
78
Al Virod4017272019-06-01 18:43:09 -040079static struct file_system_type dev_fs_type = {
80 .name = "devtmpfs",
81 .mount = public_dev_mount,
82};
83
Kay Sievers2b2af542009-04-30 15:23:42 +020084#ifdef CONFIG_BLOCK
85static inline int is_blockdev(struct device *dev)
86{
87 return dev->class == &block_class;
88}
89#else
90static inline int is_blockdev(struct device *dev) { return 0; }
91#endif
92
Rasmus Villemoes72a9cc92020-01-15 19:41:53 +010093static int devtmpfs_submit_req(struct req *req, const char *tmp)
94{
95 init_completion(&req->done);
96
97 spin_lock(&req_lock);
98 req->next = requests;
99 requests = req;
100 spin_unlock(&req_lock);
101
102 wake_up_process(thread);
103 wait_for_completion(&req->done);
104
105 kfree(tmp);
106
107 return req->err;
108}
109
Al Viro2780f1f2011-06-27 16:25:29 -0400110int devtmpfs_create_node(struct device *dev)
111{
112 const char *tmp = NULL;
113 struct req req;
114
115 if (!thread)
116 return 0;
117
118 req.mode = 0;
Greg Kroah-Hartman4e4098a2013-04-11 11:43:29 -0700119 req.uid = GLOBAL_ROOT_UID;
120 req.gid = GLOBAL_ROOT_GID;
Kay Sievers3c2670e2013-04-06 09:56:00 -0700121 req.name = device_get_devnode(dev, &req.mode, &req.uid, &req.gid, &tmp);
Al Viro2780f1f2011-06-27 16:25:29 -0400122 if (!req.name)
123 return -ENOMEM;
124
125 if (req.mode == 0)
126 req.mode = 0600;
127 if (is_blockdev(dev))
128 req.mode |= S_IFBLK;
129 else
130 req.mode |= S_IFCHR;
131
132 req.dev = dev;
133
Rasmus Villemoes72a9cc92020-01-15 19:41:53 +0100134 return devtmpfs_submit_req(&req, tmp);
Al Viro2780f1f2011-06-27 16:25:29 -0400135}
136
137int devtmpfs_delete_node(struct device *dev)
138{
139 const char *tmp = NULL;
140 struct req req;
141
142 if (!thread)
143 return 0;
144
Kay Sievers3c2670e2013-04-06 09:56:00 -0700145 req.name = device_get_devnode(dev, NULL, NULL, NULL, &tmp);
Al Viro2780f1f2011-06-27 16:25:29 -0400146 if (!req.name)
147 return -ENOMEM;
148
149 req.mode = 0;
150 req.dev = dev;
151
Rasmus Villemoes72a9cc92020-01-15 19:41:53 +0100152 return devtmpfs_submit_req(&req, tmp);
Al Viro2780f1f2011-06-27 16:25:29 -0400153}
154
Al Virofbd48a62011-07-24 10:47:56 -0400155static int dev_mkdir(const char *name, umode_t mode)
Kay Sievers2b2af542009-04-30 15:23:42 +0200156{
Kay Sievers2b2af542009-04-30 15:23:42 +0200157 struct dentry *dentry;
Al Viro69753a02011-06-27 16:35:45 -0400158 struct path path;
Kay Sievers2b2af542009-04-30 15:23:42 +0200159 int err;
160
Jeff Layton1ac12b42012-12-11 12:10:06 -0500161 dentry = kern_path_create(AT_FDCWD, name, &path, LOOKUP_DIRECTORY);
Al Viro69753a02011-06-27 16:35:45 -0400162 if (IS_ERR(dentry))
163 return PTR_ERR(dentry);
Kay Sievers2b2af542009-04-30 15:23:42 +0200164
Christian Brauner6521f892021-01-21 14:19:33 +0100165 err = vfs_mkdir(&init_user_ns, d_inode(path.dentry), dentry, mode);
Al Viro69753a02011-06-27 16:35:45 -0400166 if (!err)
167 /* mark as kernel-created inode */
David Howells75c3cfa2015-03-17 22:26:12 +0000168 d_inode(dentry)->i_private = &thread;
Al Viro921a1652012-07-20 01:15:31 +0400169 done_path_create(&path, dentry);
Kay Sievers2b2af542009-04-30 15:23:42 +0200170 return err;
171}
172
173static int create_path(const char *nodepath)
174{
Al Viro5da4e682011-06-27 16:37:12 -0400175 char *path;
176 char *s;
Al Viro9d108d22011-07-27 22:27:33 -0400177 int err = 0;
Kay Sievers2b2af542009-04-30 15:23:42 +0200178
Al Viro5da4e682011-06-27 16:37:12 -0400179 /* parent directories do not exist, create them */
180 path = kstrdup(nodepath, GFP_KERNEL);
181 if (!path)
182 return -ENOMEM;
Kay Sievers2b2af542009-04-30 15:23:42 +0200183
Al Viro5da4e682011-06-27 16:37:12 -0400184 s = path;
185 for (;;) {
186 s = strchr(s, '/');
187 if (!s)
188 break;
189 s[0] = '\0';
190 err = dev_mkdir(path, 0755);
191 if (err && err != -EEXIST)
192 break;
193 s[0] = '/';
194 s++;
Kay Sievers2b2af542009-04-30 15:23:42 +0200195 }
Al Viro5da4e682011-06-27 16:37:12 -0400196 kfree(path);
Kay Sievers2b2af542009-04-30 15:23:42 +0200197 return err;
198}
199
Greg Kroah-Hartman4e4098a2013-04-11 11:43:29 -0700200static int handle_create(const char *nodename, umode_t mode, kuid_t uid,
201 kgid_t gid, struct device *dev)
Kay Sievers2b2af542009-04-30 15:23:42 +0200202{
Kay Sievers2b2af542009-04-30 15:23:42 +0200203 struct dentry *dentry;
Al Viro69753a02011-06-27 16:35:45 -0400204 struct path path;
Kay Sievers2b2af542009-04-30 15:23:42 +0200205 int err;
206
Al Viro69753a02011-06-27 16:35:45 -0400207 dentry = kern_path_create(AT_FDCWD, nodename, &path, 0);
208 if (dentry == ERR_PTR(-ENOENT)) {
Kay Sievers2b2af542009-04-30 15:23:42 +0200209 create_path(nodename);
Al Viro69753a02011-06-27 16:35:45 -0400210 dentry = kern_path_create(AT_FDCWD, nodename, &path, 0);
Kay Sievers2b2af542009-04-30 15:23:42 +0200211 }
Al Viro69753a02011-06-27 16:35:45 -0400212 if (IS_ERR(dentry))
213 return PTR_ERR(dentry);
Kay Sievers2b2af542009-04-30 15:23:42 +0200214
Christian Brauner6521f892021-01-21 14:19:33 +0100215 err = vfs_mknod(&init_user_ns, d_inode(path.dentry), dentry, mode,
216 dev->devt);
Al Viro69753a02011-06-27 16:35:45 -0400217 if (!err) {
218 struct iattr newattrs;
Kay Sievers00926992009-10-28 19:50:57 +0100219
Al Viro69753a02011-06-27 16:35:45 -0400220 newattrs.ia_mode = mode;
Greg Kroah-Hartman4e4098a2013-04-11 11:43:29 -0700221 newattrs.ia_uid = uid;
222 newattrs.ia_gid = gid;
Kay Sievers3c2670e2013-04-06 09:56:00 -0700223 newattrs.ia_valid = ATTR_MODE|ATTR_UID|ATTR_GID;
Al Viro59551022016-01-22 15:40:57 -0500224 inode_lock(d_inode(dentry));
Christian Brauner2f221d62021-01-21 14:19:26 +0100225 notify_change(&init_user_ns, dentry, &newattrs, NULL);
Al Viro59551022016-01-22 15:40:57 -0500226 inode_unlock(d_inode(dentry));
Kay Sievers00926992009-10-28 19:50:57 +0100227
Al Viro69753a02011-06-27 16:35:45 -0400228 /* mark as kernel-created inode */
David Howells75c3cfa2015-03-17 22:26:12 +0000229 d_inode(dentry)->i_private = &thread;
Kay Sievers2b2af542009-04-30 15:23:42 +0200230 }
Al Viro921a1652012-07-20 01:15:31 +0400231 done_path_create(&path, dentry);
Kay Sievers2b2af542009-04-30 15:23:42 +0200232 return err;
233}
234
235static int dev_rmdir(const char *name)
236{
Al Viro79714f72012-06-15 03:01:42 +0400237 struct path parent;
Kay Sievers2b2af542009-04-30 15:23:42 +0200238 struct dentry *dentry;
239 int err;
240
Al Viro79714f72012-06-15 03:01:42 +0400241 dentry = kern_path_locked(name, &parent);
242 if (IS_ERR(dentry))
243 return PTR_ERR(dentry);
David Howells75c3cfa2015-03-17 22:26:12 +0000244 if (d_really_is_positive(dentry)) {
245 if (d_inode(dentry)->i_private == &thread)
Christian Brauner6521f892021-01-21 14:19:33 +0100246 err = vfs_rmdir(&init_user_ns, d_inode(parent.dentry),
247 dentry);
Al Viro79714f72012-06-15 03:01:42 +0400248 else
249 err = -EPERM;
Kay Sievers2b2af542009-04-30 15:23:42 +0200250 } else {
Al Viro79714f72012-06-15 03:01:42 +0400251 err = -ENOENT;
Kay Sievers2b2af542009-04-30 15:23:42 +0200252 }
Al Viro79714f72012-06-15 03:01:42 +0400253 dput(dentry);
Al Viro59551022016-01-22 15:40:57 -0500254 inode_unlock(d_inode(parent.dentry));
Al Viro79714f72012-06-15 03:01:42 +0400255 path_put(&parent);
Kay Sievers2b2af542009-04-30 15:23:42 +0200256 return err;
257}
258
259static int delete_path(const char *nodepath)
260{
Rasmus Villemoesbe6b1df2018-08-22 13:00:07 +0200261 char *path;
Kay Sievers2b2af542009-04-30 15:23:42 +0200262 int err = 0;
263
264 path = kstrdup(nodepath, GFP_KERNEL);
265 if (!path)
266 return -ENOMEM;
267
Kay Sieversed413ae2009-10-28 19:51:06 +0100268 for (;;) {
Kay Sievers2b2af542009-04-30 15:23:42 +0200269 char *base;
270
271 base = strrchr(path, '/');
272 if (!base)
273 break;
274 base[0] = '\0';
275 err = dev_rmdir(path);
276 if (err)
277 break;
278 }
279
280 kfree(path);
281 return err;
282}
283
284static int dev_mynode(struct device *dev, struct inode *inode, struct kstat *stat)
285{
286 /* did we create it */
Al Viro2780f1f2011-06-27 16:25:29 -0400287 if (inode->i_private != &thread)
Kay Sievers2b2af542009-04-30 15:23:42 +0200288 return 0;
289
290 /* does the dev_t match */
291 if (is_blockdev(dev)) {
292 if (!S_ISBLK(stat->mode))
293 return 0;
294 } else {
295 if (!S_ISCHR(stat->mode))
296 return 0;
297 }
298 if (stat->rdev != dev->devt)
299 return 0;
300
301 /* ours */
302 return 1;
303}
304
Al Viro2780f1f2011-06-27 16:25:29 -0400305static int handle_remove(const char *nodename, struct device *dev)
Kay Sievers2b2af542009-04-30 15:23:42 +0200306{
Al Viro79714f72012-06-15 03:01:42 +0400307 struct path parent;
Kay Sievers2b2af542009-04-30 15:23:42 +0200308 struct dentry *dentry;
Axel Linfbde7c62013-11-16 16:15:23 +0800309 int deleted = 0;
Kay Sievers2b2af542009-04-30 15:23:42 +0200310 int err;
311
Al Viro79714f72012-06-15 03:01:42 +0400312 dentry = kern_path_locked(nodename, &parent);
313 if (IS_ERR(dentry))
314 return PTR_ERR(dentry);
Kay Sievers2b2af542009-04-30 15:23:42 +0200315
David Howells75c3cfa2015-03-17 22:26:12 +0000316 if (d_really_is_positive(dentry)) {
Al Viro79714f72012-06-15 03:01:42 +0400317 struct kstat stat;
Al Viro3dadecc2013-01-24 02:18:08 -0500318 struct path p = {.mnt = parent.mnt, .dentry = dentry};
David Howellsa528d352017-01-31 16:46:22 +0000319 err = vfs_getattr(&p, &stat, STATX_TYPE | STATX_MODE,
320 AT_STATX_SYNC_AS_STAT);
David Howells75c3cfa2015-03-17 22:26:12 +0000321 if (!err && dev_mynode(dev, d_inode(dentry), &stat)) {
Al Viro79714f72012-06-15 03:01:42 +0400322 struct iattr newattrs;
323 /*
324 * before unlinking this node, reset permissions
325 * of possible references like hardlinks
326 */
Eric W. Biederman91fa2cc2012-04-25 04:25:35 -0700327 newattrs.ia_uid = GLOBAL_ROOT_UID;
328 newattrs.ia_gid = GLOBAL_ROOT_GID;
Al Viro79714f72012-06-15 03:01:42 +0400329 newattrs.ia_mode = stat.mode & ~0777;
330 newattrs.ia_valid =
331 ATTR_UID|ATTR_GID|ATTR_MODE;
Al Viro59551022016-01-22 15:40:57 -0500332 inode_lock(d_inode(dentry));
Christian Brauner2f221d62021-01-21 14:19:26 +0100333 notify_change(&init_user_ns, dentry, &newattrs, NULL);
Al Viro59551022016-01-22 15:40:57 -0500334 inode_unlock(d_inode(dentry));
Christian Brauner6521f892021-01-21 14:19:33 +0100335 err = vfs_unlink(&init_user_ns, d_inode(parent.dentry),
336 dentry, NULL);
Al Viro79714f72012-06-15 03:01:42 +0400337 if (!err || err == -ENOENT)
338 deleted = 1;
Kay Sievers2b2af542009-04-30 15:23:42 +0200339 }
Kay Sievers2b2af542009-04-30 15:23:42 +0200340 } else {
Al Viro79714f72012-06-15 03:01:42 +0400341 err = -ENOENT;
Kay Sievers2b2af542009-04-30 15:23:42 +0200342 }
Al Viro79714f72012-06-15 03:01:42 +0400343 dput(dentry);
Al Viro59551022016-01-22 15:40:57 -0500344 inode_unlock(d_inode(parent.dentry));
Kay Sievers2b2af542009-04-30 15:23:42 +0200345
Al Viro79714f72012-06-15 03:01:42 +0400346 path_put(&parent);
Kay Sievers2b2af542009-04-30 15:23:42 +0200347 if (deleted && strchr(nodename, '/'))
348 delete_path(nodename);
Kay Sievers2b2af542009-04-30 15:23:42 +0200349 return err;
350}
351
352/*
353 * If configured, or requested by the commandline, devtmpfs will be
354 * auto-mounted after the kernel mounted the root filesystem.
355 */
Rasmus Villemoesfad1db82020-01-15 19:41:52 +0100356int __init devtmpfs_mount(void)
Kay Sievers2b2af542009-04-30 15:23:42 +0200357{
Kay Sievers2b2af542009-04-30 15:23:42 +0200358 int err;
359
Al Virofc14f2f2010-07-25 01:48:30 +0400360 if (!mount_dev)
Kay Sievers2b2af542009-04-30 15:23:42 +0200361 return 0;
362
Al Viro2780f1f2011-06-27 16:25:29 -0400363 if (!thread)
Kay Sievers2b2af542009-04-30 15:23:42 +0200364 return 0;
365
Christoph Hellwigc60166f2020-07-21 11:12:08 +0200366 err = init_mount("devtmpfs", "dev", "devtmpfs", MS_SILENT, NULL);
Kay Sievers2b2af542009-04-30 15:23:42 +0200367 if (err)
368 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
369 else
370 printk(KERN_INFO "devtmpfs: mounted\n");
Kay Sievers2b2af542009-04-30 15:23:42 +0200371 return err;
372}
373
Rasmus Villemoes01085e22021-03-12 11:30:27 +0100374static __initdata DECLARE_COMPLETION(setup_done);
Al Viro2780f1f2011-06-27 16:25:29 -0400375
Greg Kroah-Hartman4e4098a2013-04-11 11:43:29 -0700376static int handle(const char *name, umode_t mode, kuid_t uid, kgid_t gid,
Kay Sievers3c2670e2013-04-06 09:56:00 -0700377 struct device *dev)
Al Viro2780f1f2011-06-27 16:25:29 -0400378{
379 if (mode)
Kay Sievers3c2670e2013-04-06 09:56:00 -0700380 return handle_create(name, mode, uid, gid, dev);
Al Viro2780f1f2011-06-27 16:25:29 -0400381 else
382 return handle_remove(name, dev);
383}
384
Christoph Hellwigbcbacc42020-07-22 10:48:25 +0200385static void __noreturn devtmpfs_work_loop(void)
Al Viro2780f1f2011-06-27 16:25:29 -0400386{
Al Viro2780f1f2011-06-27 16:25:29 -0400387 while (1) {
388 spin_lock(&req_lock);
389 while (requests) {
390 struct req *req = requests;
391 requests = NULL;
392 spin_unlock(&req_lock);
393 while (req) {
Al Viroe13889b2011-07-25 14:15:50 -0400394 struct req *next = req->next;
Kay Sievers3c2670e2013-04-06 09:56:00 -0700395 req->err = handle(req->name, req->mode,
396 req->uid, req->gid, req->dev);
Al Viro2780f1f2011-06-27 16:25:29 -0400397 complete(&req->done);
Al Viroe13889b2011-07-25 14:15:50 -0400398 req = next;
Al Viro2780f1f2011-06-27 16:25:29 -0400399 }
400 spin_lock(&req_lock);
401 }
Kautuk Consul65e67572011-11-15 14:52:34 -0800402 __set_current_state(TASK_INTERRUPTIBLE);
Al Viro2780f1f2011-06-27 16:25:29 -0400403 spin_unlock(&req_lock);
404 schedule();
Al Viro2780f1f2011-06-27 16:25:29 -0400405 }
Christoph Hellwigbcbacc42020-07-22 10:48:25 +0200406}
407
Rasmus Villemoes01085e22021-03-12 11:30:27 +0100408static noinline int __init devtmpfs_setup(void *p)
Christoph Hellwigbcbacc42020-07-22 10:48:25 +0200409{
410 int err;
411
412 err = ksys_unshare(CLONE_NEWNS);
413 if (err)
414 goto out;
Christoph Hellwigc60166f2020-07-21 11:12:08 +0200415 err = init_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, NULL);
Christoph Hellwigbcbacc42020-07-22 10:48:25 +0200416 if (err)
417 goto out;
Christoph Hellwigdb63f1e2020-07-22 11:25:21 +0200418 init_chdir("/.."); /* will traverse into overmounted root */
Christoph Hellwig4b7ca502020-07-22 11:26:13 +0200419 init_chroot(".");
Christoph Hellwigbcbacc42020-07-22 10:48:25 +0200420out:
421 *(int *)p = err;
Christoph Hellwigbcbacc42020-07-22 10:48:25 +0200422 return err;
423}
424
425/*
426 * The __ref is because devtmpfs_setup needs to be __init for the routines it
427 * calls. That call is done while devtmpfs_init, which is marked __init,
428 * synchronously waits for it to complete.
429 */
430static int __ref devtmpfsd(void *p)
431{
432 int err = devtmpfs_setup(p);
433
Rasmus Villemoes38f087de2021-03-12 11:30:26 +0100434 complete(&setup_done);
Christoph Hellwigbcbacc42020-07-22 10:48:25 +0200435 if (err)
436 return err;
437 devtmpfs_work_loop();
Al Viro2780f1f2011-06-27 16:25:29 -0400438 return 0;
Al Viro2780f1f2011-06-27 16:25:29 -0400439}
440
Kay Sievers2b2af542009-04-30 15:23:42 +0200441/*
442 * Create devtmpfs instance, driver-core devices will add their device
443 * nodes here.
444 */
445int __init devtmpfs_init(void)
446{
Al Virod4017272019-06-01 18:43:09 -0400447 char opts[] = "mode=0755";
448 int err;
449
450 mnt = vfs_kern_mount(&internal_fs_type, 0, "devtmpfs", opts);
451 if (IS_ERR(mnt)) {
452 printk(KERN_ERR "devtmpfs: unable to create devtmpfs %ld\n",
453 PTR_ERR(mnt));
454 return PTR_ERR(mnt);
455 }
456 err = register_filesystem(&dev_fs_type);
Kay Sievers2b2af542009-04-30 15:23:42 +0200457 if (err) {
458 printk(KERN_ERR "devtmpfs: unable to register devtmpfs "
459 "type %i\n", err);
460 return err;
461 }
462
Al Viro2780f1f2011-06-27 16:25:29 -0400463 thread = kthread_run(devtmpfsd, &err, "kdevtmpfs");
464 if (!IS_ERR(thread)) {
465 wait_for_completion(&setup_done);
466 } else {
467 err = PTR_ERR(thread);
468 thread = NULL;
469 }
470
471 if (err) {
Kay Sievers2b2af542009-04-30 15:23:42 +0200472 printk(KERN_ERR "devtmpfs: unable to create devtmpfs %i\n", err);
473 unregister_filesystem(&dev_fs_type);
474 return err;
475 }
Kay Sievers2b2af542009-04-30 15:23:42 +0200476
477 printk(KERN_INFO "devtmpfs: initialized\n");
478 return 0;
479}