hc
2024-05-10 cde9070d9970eef1f7ec2360586c802a16230ad8
kernel/fs/proc/inode.c
....@@ -24,7 +24,7 @@
2424 #include <linux/seq_file.h>
2525 #include <linux/slab.h>
2626 #include <linux/mount.h>
27
-#include <linux/magic.h>
27
+#include <linux/bug.h>
2828
2929 #include <linux/uaccess.h>
3030
....@@ -34,21 +34,27 @@
3434 {
3535 struct proc_dir_entry *de;
3636 struct ctl_table_header *head;
37
+ struct proc_inode *ei = PROC_I(inode);
3738
3839 truncate_inode_pages_final(&inode->i_data);
3940 clear_inode(inode);
4041
4142 /* Stop tracking associated processes */
42
- put_pid(PROC_I(inode)->pid);
43
+ if (ei->pid) {
44
+ proc_pid_evict_inode(ei);
45
+ ei->pid = NULL;
46
+ }
4347
4448 /* Let go of any associated proc directory entry */
45
- de = PDE(inode);
46
- if (de)
49
+ de = ei->pde;
50
+ if (de) {
4751 pde_put(de);
52
+ ei->pde = NULL;
53
+ }
4854
49
- head = PROC_I(inode)->sysctl;
55
+ head = ei->sysctl;
5056 if (head) {
51
- RCU_INIT_POINTER(PROC_I(inode)->sysctl, NULL);
57
+ RCU_INIT_POINTER(ei->sysctl, NULL);
5258 proc_sys_evict_inode(inode, head);
5359 }
5460 }
....@@ -59,7 +65,6 @@
5965 static struct inode *proc_alloc_inode(struct super_block *sb)
6066 {
6167 struct proc_inode *ei;
62
- struct inode *inode;
6368
6469 ei = kmem_cache_alloc(proc_inode_cachep, GFP_KERNEL);
6570 if (!ei)
....@@ -70,20 +75,14 @@
7075 ei->pde = NULL;
7176 ei->sysctl = NULL;
7277 ei->sysctl_entry = NULL;
78
+ INIT_HLIST_NODE(&ei->sibling_inodes);
7379 ei->ns_ops = NULL;
74
- inode = &ei->vfs_inode;
75
- return inode;
80
+ return &ei->vfs_inode;
7681 }
7782
78
-static void proc_i_callback(struct rcu_head *head)
83
+static void proc_free_inode(struct inode *inode)
7984 {
80
- struct inode *inode = container_of(head, struct inode, i_rcu);
8185 kmem_cache_free(proc_inode_cachep, PROC_I(inode));
82
-}
83
-
84
-static void proc_destroy_inode(struct inode *inode)
85
-{
86
- call_rcu(&inode->i_rcu, proc_i_callback);
8786 }
8887
8988 static void init_once(void *foo)
....@@ -111,26 +110,94 @@
111110 BUILD_BUG_ON(sizeof(struct proc_dir_entry) >= SIZEOF_PDE);
112111 }
113112
113
+void proc_invalidate_siblings_dcache(struct hlist_head *inodes, spinlock_t *lock)
114
+{
115
+ struct inode *inode;
116
+ struct proc_inode *ei;
117
+ struct hlist_node *node;
118
+ struct super_block *old_sb = NULL;
119
+
120
+ rcu_read_lock();
121
+ for (;;) {
122
+ struct super_block *sb;
123
+ node = hlist_first_rcu(inodes);
124
+ if (!node)
125
+ break;
126
+ ei = hlist_entry(node, struct proc_inode, sibling_inodes);
127
+ spin_lock(lock);
128
+ hlist_del_init_rcu(&ei->sibling_inodes);
129
+ spin_unlock(lock);
130
+
131
+ inode = &ei->vfs_inode;
132
+ sb = inode->i_sb;
133
+ if ((sb != old_sb) && !atomic_inc_not_zero(&sb->s_active))
134
+ continue;
135
+ inode = igrab(inode);
136
+ rcu_read_unlock();
137
+ if (sb != old_sb) {
138
+ if (old_sb)
139
+ deactivate_super(old_sb);
140
+ old_sb = sb;
141
+ }
142
+ if (unlikely(!inode)) {
143
+ rcu_read_lock();
144
+ continue;
145
+ }
146
+
147
+ if (S_ISDIR(inode->i_mode)) {
148
+ struct dentry *dir = d_find_any_alias(inode);
149
+ if (dir) {
150
+ d_invalidate(dir);
151
+ dput(dir);
152
+ }
153
+ } else {
154
+ struct dentry *dentry;
155
+ while ((dentry = d_find_alias(inode))) {
156
+ d_invalidate(dentry);
157
+ dput(dentry);
158
+ }
159
+ }
160
+ iput(inode);
161
+
162
+ rcu_read_lock();
163
+ }
164
+ rcu_read_unlock();
165
+ if (old_sb)
166
+ deactivate_super(old_sb);
167
+}
168
+
169
+static inline const char *hidepid2str(enum proc_hidepid v)
170
+{
171
+ switch (v) {
172
+ case HIDEPID_OFF: return "off";
173
+ case HIDEPID_NO_ACCESS: return "noaccess";
174
+ case HIDEPID_INVISIBLE: return "invisible";
175
+ case HIDEPID_NOT_PTRACEABLE: return "ptraceable";
176
+ }
177
+ WARN_ONCE(1, "bad hide_pid value: %d\n", v);
178
+ return "unknown";
179
+}
180
+
114181 static int proc_show_options(struct seq_file *seq, struct dentry *root)
115182 {
116
- struct super_block *sb = root->d_sb;
117
- struct pid_namespace *pid = sb->s_fs_info;
183
+ struct proc_fs_info *fs_info = proc_sb_info(root->d_sb);
118184
119
- if (!gid_eq(pid->pid_gid, GLOBAL_ROOT_GID))
120
- seq_printf(seq, ",gid=%u", from_kgid_munged(&init_user_ns, pid->pid_gid));
121
- if (pid->hide_pid != HIDEPID_OFF)
122
- seq_printf(seq, ",hidepid=%u", pid->hide_pid);
185
+ if (!gid_eq(fs_info->pid_gid, GLOBAL_ROOT_GID))
186
+ seq_printf(seq, ",gid=%u", from_kgid_munged(&init_user_ns, fs_info->pid_gid));
187
+ if (fs_info->hide_pid != HIDEPID_OFF)
188
+ seq_printf(seq, ",hidepid=%s", hidepid2str(fs_info->hide_pid));
189
+ if (fs_info->pidonly != PROC_PIDONLY_OFF)
190
+ seq_printf(seq, ",subset=pid");
123191
124192 return 0;
125193 }
126194
127
-static const struct super_operations proc_sops = {
195
+const struct super_operations proc_sops = {
128196 .alloc_inode = proc_alloc_inode,
129
- .destroy_inode = proc_destroy_inode,
197
+ .free_inode = proc_free_inode,
130198 .drop_inode = generic_delete_inode,
131199 .evict_inode = proc_evict_inode,
132200 .statfs = simple_statfs,
133
- .remount_fs = proc_remount,
134201 .show_options = proc_show_options,
135202 };
136203
....@@ -149,6 +216,7 @@
149216
150217 /* pde is locked on entry, unlocked on exit */
151218 static void close_pdeo(struct proc_dir_entry *pde, struct pde_opener *pdeo)
219
+ __releases(&pde->pde_unload_lock)
152220 {
153221 /*
154222 * close() (proc_reg_release()) can't delete an entry and proceed:
....@@ -173,7 +241,7 @@
173241 pdeo->closing = true;
174242 spin_unlock(&pde->pde_unload_lock);
175243 file = pdeo->file;
176
- pde->proc_fops->release(file_inode(file), file);
244
+ pde->proc_ops->proc_release(file_inode(file), file);
177245 spin_lock(&pde->pde_unload_lock);
178246 /* After ->release. */
179247 list_del(&pdeo->lh);
....@@ -205,105 +273,205 @@
205273 spin_unlock(&de->pde_unload_lock);
206274 }
207275
276
+static loff_t pde_lseek(struct proc_dir_entry *pde, struct file *file, loff_t offset, int whence)
277
+{
278
+ typeof_member(struct proc_ops, proc_lseek) lseek;
279
+
280
+ lseek = pde->proc_ops->proc_lseek;
281
+ if (!lseek)
282
+ lseek = default_llseek;
283
+ return lseek(file, offset, whence);
284
+}
285
+
208286 static loff_t proc_reg_llseek(struct file *file, loff_t offset, int whence)
209287 {
210288 struct proc_dir_entry *pde = PDE(file_inode(file));
211289 loff_t rv = -EINVAL;
212
- if (use_pde(pde)) {
213
- loff_t (*llseek)(struct file *, loff_t, int);
214
- llseek = pde->proc_fops->llseek;
215
- if (!llseek)
216
- llseek = default_llseek;
217
- rv = llseek(file, offset, whence);
290
+
291
+ if (pde_is_permanent(pde)) {
292
+ return pde_lseek(pde, file, offset, whence);
293
+ } else if (use_pde(pde)) {
294
+ rv = pde_lseek(pde, file, offset, whence);
218295 unuse_pde(pde);
219296 }
220297 return rv;
298
+}
299
+
300
+static ssize_t proc_reg_read_iter(struct kiocb *iocb, struct iov_iter *iter)
301
+{
302
+ struct proc_dir_entry *pde = PDE(file_inode(iocb->ki_filp));
303
+ ssize_t ret;
304
+
305
+ if (pde_is_permanent(pde))
306
+ return pde->proc_ops->proc_read_iter(iocb, iter);
307
+
308
+ if (!use_pde(pde))
309
+ return -EIO;
310
+ ret = pde->proc_ops->proc_read_iter(iocb, iter);
311
+ unuse_pde(pde);
312
+ return ret;
313
+}
314
+
315
+static ssize_t pde_read(struct proc_dir_entry *pde, struct file *file, char __user *buf, size_t count, loff_t *ppos)
316
+{
317
+ typeof_member(struct proc_ops, proc_read) read;
318
+
319
+ read = pde->proc_ops->proc_read;
320
+ if (read)
321
+ return read(file, buf, count, ppos);
322
+ return -EIO;
221323 }
222324
223325 static ssize_t proc_reg_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
224326 {
225
- ssize_t (*read)(struct file *, char __user *, size_t, loff_t *);
226327 struct proc_dir_entry *pde = PDE(file_inode(file));
227328 ssize_t rv = -EIO;
228
- if (use_pde(pde)) {
229
- read = pde->proc_fops->read;
230
- if (read)
231
- rv = read(file, buf, count, ppos);
329
+
330
+ if (pde_is_permanent(pde)) {
331
+ return pde_read(pde, file, buf, count, ppos);
332
+ } else if (use_pde(pde)) {
333
+ rv = pde_read(pde, file, buf, count, ppos);
232334 unuse_pde(pde);
233335 }
234336 return rv;
235337 }
236338
339
+static ssize_t pde_write(struct proc_dir_entry *pde, struct file *file, const char __user *buf, size_t count, loff_t *ppos)
340
+{
341
+ typeof_member(struct proc_ops, proc_write) write;
342
+
343
+ write = pde->proc_ops->proc_write;
344
+ if (write)
345
+ return write(file, buf, count, ppos);
346
+ return -EIO;
347
+}
348
+
237349 static ssize_t proc_reg_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
238350 {
239
- ssize_t (*write)(struct file *, const char __user *, size_t, loff_t *);
240351 struct proc_dir_entry *pde = PDE(file_inode(file));
241352 ssize_t rv = -EIO;
242
- if (use_pde(pde)) {
243
- write = pde->proc_fops->write;
244
- if (write)
245
- rv = write(file, buf, count, ppos);
353
+
354
+ if (pde_is_permanent(pde)) {
355
+ return pde_write(pde, file, buf, count, ppos);
356
+ } else if (use_pde(pde)) {
357
+ rv = pde_write(pde, file, buf, count, ppos);
246358 unuse_pde(pde);
247359 }
248360 return rv;
361
+}
362
+
363
+static __poll_t pde_poll(struct proc_dir_entry *pde, struct file *file, struct poll_table_struct *pts)
364
+{
365
+ typeof_member(struct proc_ops, proc_poll) poll;
366
+
367
+ poll = pde->proc_ops->proc_poll;
368
+ if (poll)
369
+ return poll(file, pts);
370
+ return DEFAULT_POLLMASK;
249371 }
250372
251373 static __poll_t proc_reg_poll(struct file *file, struct poll_table_struct *pts)
252374 {
253375 struct proc_dir_entry *pde = PDE(file_inode(file));
254376 __poll_t rv = DEFAULT_POLLMASK;
255
- __poll_t (*poll)(struct file *, struct poll_table_struct *);
256
- if (use_pde(pde)) {
257
- poll = pde->proc_fops->poll;
258
- if (poll)
259
- rv = poll(file, pts);
377
+
378
+ if (pde_is_permanent(pde)) {
379
+ return pde_poll(pde, file, pts);
380
+ } else if (use_pde(pde)) {
381
+ rv = pde_poll(pde, file, pts);
260382 unuse_pde(pde);
261383 }
262384 return rv;
385
+}
386
+
387
+static long pde_ioctl(struct proc_dir_entry *pde, struct file *file, unsigned int cmd, unsigned long arg)
388
+{
389
+ typeof_member(struct proc_ops, proc_ioctl) ioctl;
390
+
391
+ ioctl = pde->proc_ops->proc_ioctl;
392
+ if (ioctl)
393
+ return ioctl(file, cmd, arg);
394
+ return -ENOTTY;
263395 }
264396
265397 static long proc_reg_unlocked_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
266398 {
267399 struct proc_dir_entry *pde = PDE(file_inode(file));
268400 long rv = -ENOTTY;
269
- long (*ioctl)(struct file *, unsigned int, unsigned long);
270
- if (use_pde(pde)) {
271
- ioctl = pde->proc_fops->unlocked_ioctl;
272
- if (ioctl)
273
- rv = ioctl(file, cmd, arg);
401
+
402
+ if (pde_is_permanent(pde)) {
403
+ return pde_ioctl(pde, file, cmd, arg);
404
+ } else if (use_pde(pde)) {
405
+ rv = pde_ioctl(pde, file, cmd, arg);
274406 unuse_pde(pde);
275407 }
276408 return rv;
277409 }
278410
279411 #ifdef CONFIG_COMPAT
412
+static long pde_compat_ioctl(struct proc_dir_entry *pde, struct file *file, unsigned int cmd, unsigned long arg)
413
+{
414
+ typeof_member(struct proc_ops, proc_compat_ioctl) compat_ioctl;
415
+
416
+ compat_ioctl = pde->proc_ops->proc_compat_ioctl;
417
+ if (compat_ioctl)
418
+ return compat_ioctl(file, cmd, arg);
419
+ return -ENOTTY;
420
+}
421
+
280422 static long proc_reg_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
281423 {
282424 struct proc_dir_entry *pde = PDE(file_inode(file));
283425 long rv = -ENOTTY;
284
- long (*compat_ioctl)(struct file *, unsigned int, unsigned long);
285
- if (use_pde(pde)) {
286
- compat_ioctl = pde->proc_fops->compat_ioctl;
287
- if (compat_ioctl)
288
- rv = compat_ioctl(file, cmd, arg);
426
+ if (pde_is_permanent(pde)) {
427
+ return pde_compat_ioctl(pde, file, cmd, arg);
428
+ } else if (use_pde(pde)) {
429
+ rv = pde_compat_ioctl(pde, file, cmd, arg);
289430 unuse_pde(pde);
290431 }
291432 return rv;
292433 }
293434 #endif
294435
436
+static int pde_mmap(struct proc_dir_entry *pde, struct file *file, struct vm_area_struct *vma)
437
+{
438
+ typeof_member(struct proc_ops, proc_mmap) mmap;
439
+
440
+ mmap = pde->proc_ops->proc_mmap;
441
+ if (mmap)
442
+ return mmap(file, vma);
443
+ return -EIO;
444
+}
445
+
295446 static int proc_reg_mmap(struct file *file, struct vm_area_struct *vma)
296447 {
297448 struct proc_dir_entry *pde = PDE(file_inode(file));
298449 int rv = -EIO;
299
- int (*mmap)(struct file *, struct vm_area_struct *);
300
- if (use_pde(pde)) {
301
- mmap = pde->proc_fops->mmap;
302
- if (mmap)
303
- rv = mmap(file, vma);
450
+
451
+ if (pde_is_permanent(pde)) {
452
+ return pde_mmap(pde, file, vma);
453
+ } else if (use_pde(pde)) {
454
+ rv = pde_mmap(pde, file, vma);
304455 unuse_pde(pde);
305456 }
306457 return rv;
458
+}
459
+
460
+static unsigned long
461
+pde_get_unmapped_area(struct proc_dir_entry *pde, struct file *file, unsigned long orig_addr,
462
+ unsigned long len, unsigned long pgoff,
463
+ unsigned long flags)
464
+{
465
+ typeof_member(struct proc_ops, proc_get_unmapped_area) get_area;
466
+
467
+ get_area = pde->proc_ops->proc_get_unmapped_area;
468
+#ifdef CONFIG_MMU
469
+ if (!get_area)
470
+ get_area = current->mm->get_unmapped_area;
471
+#endif
472
+ if (get_area)
473
+ return get_area(file, orig_addr, len, pgoff, flags);
474
+ return orig_addr;
307475 }
308476
309477 static unsigned long
....@@ -314,19 +482,10 @@
314482 struct proc_dir_entry *pde = PDE(file_inode(file));
315483 unsigned long rv = -EIO;
316484
317
- if (use_pde(pde)) {
318
- typeof(proc_reg_get_unmapped_area) *get_area;
319
-
320
- get_area = pde->proc_fops->get_unmapped_area;
321
-#ifdef CONFIG_MMU
322
- if (!get_area)
323
- get_area = current->mm->get_unmapped_area;
324
-#endif
325
-
326
- if (get_area)
327
- rv = get_area(file, orig_addr, len, pgoff, flags);
328
- else
329
- rv = orig_addr;
485
+ if (pde_is_permanent(pde)) {
486
+ return pde_get_unmapped_area(pde, file, orig_addr, len, pgoff, flags);
487
+ } else if (use_pde(pde)) {
488
+ rv = pde_get_unmapped_area(pde, file, orig_addr, len, pgoff, flags);
330489 unuse_pde(pde);
331490 }
332491 return rv;
....@@ -334,11 +493,22 @@
334493
335494 static int proc_reg_open(struct inode *inode, struct file *file)
336495 {
496
+ struct proc_fs_info *fs_info = proc_sb_info(inode->i_sb);
337497 struct proc_dir_entry *pde = PDE(inode);
338498 int rv = 0;
339
- int (*open)(struct inode *, struct file *);
340
- int (*release)(struct inode *, struct file *);
499
+ typeof_member(struct proc_ops, proc_open) open;
500
+ typeof_member(struct proc_ops, proc_release) release;
341501 struct pde_opener *pdeo;
502
+
503
+ if (pde_is_permanent(pde)) {
504
+ open = pde->proc_ops->proc_open;
505
+ if (open)
506
+ rv = open(inode, file);
507
+ return rv;
508
+ }
509
+
510
+ if (fs_info->pidonly == PROC_PIDONLY_ON)
511
+ return -ENOENT;
342512
343513 /*
344514 * Ensure that
....@@ -354,7 +524,7 @@
354524 if (!use_pde(pde))
355525 return -ENOENT;
356526
357
- release = pde->proc_fops->release;
527
+ release = pde->proc_ops->proc_release;
358528 if (release) {
359529 pdeo = kmem_cache_alloc(pde_opener_cache, GFP_KERNEL);
360530 if (!pdeo) {
....@@ -363,7 +533,7 @@
363533 }
364534 }
365535
366
- open = pde->proc_fops->open;
536
+ open = pde->proc_ops->proc_open;
367537 if (open)
368538 rv = open(inode, file);
369539
....@@ -389,6 +559,17 @@
389559 {
390560 struct proc_dir_entry *pde = PDE(inode);
391561 struct pde_opener *pdeo;
562
+
563
+ if (pde_is_permanent(pde)) {
564
+ typeof_member(struct proc_ops, proc_release) release;
565
+
566
+ release = pde->proc_ops->proc_release;
567
+ if (release) {
568
+ return release(inode, file);
569
+ }
570
+ return 0;
571
+ }
572
+
392573 spin_lock(&pde->pde_unload_lock);
393574 list_for_each_entry(pdeo, &pde->pde_openers, lh) {
394575 if (pdeo->file == file) {
....@@ -406,9 +587,19 @@
406587 .write = proc_reg_write,
407588 .poll = proc_reg_poll,
408589 .unlocked_ioctl = proc_reg_unlocked_ioctl,
409
-#ifdef CONFIG_COMPAT
410
- .compat_ioctl = proc_reg_compat_ioctl,
411
-#endif
590
+ .mmap = proc_reg_mmap,
591
+ .get_unmapped_area = proc_reg_get_unmapped_area,
592
+ .open = proc_reg_open,
593
+ .release = proc_reg_release,
594
+};
595
+
596
+static const struct file_operations proc_iter_file_ops = {
597
+ .llseek = proc_reg_llseek,
598
+ .read_iter = proc_reg_read_iter,
599
+ .write = proc_reg_write,
600
+ .splice_read = generic_file_splice_read,
601
+ .poll = proc_reg_poll,
602
+ .unlocked_ioctl = proc_reg_unlocked_ioctl,
412603 .mmap = proc_reg_mmap,
413604 .get_unmapped_area = proc_reg_get_unmapped_area,
414605 .open = proc_reg_open,
....@@ -416,12 +607,27 @@
416607 };
417608
418609 #ifdef CONFIG_COMPAT
419
-static const struct file_operations proc_reg_file_ops_no_compat = {
610
+static const struct file_operations proc_reg_file_ops_compat = {
420611 .llseek = proc_reg_llseek,
421612 .read = proc_reg_read,
422613 .write = proc_reg_write,
423614 .poll = proc_reg_poll,
424615 .unlocked_ioctl = proc_reg_unlocked_ioctl,
616
+ .compat_ioctl = proc_reg_compat_ioctl,
617
+ .mmap = proc_reg_mmap,
618
+ .get_unmapped_area = proc_reg_get_unmapped_area,
619
+ .open = proc_reg_open,
620
+ .release = proc_reg_release,
621
+};
622
+
623
+static const struct file_operations proc_iter_file_ops_compat = {
624
+ .llseek = proc_reg_llseek,
625
+ .read_iter = proc_reg_read_iter,
626
+ .splice_read = generic_file_splice_read,
627
+ .write = proc_reg_write,
628
+ .poll = proc_reg_poll,
629
+ .unlocked_ioctl = proc_reg_unlocked_ioctl,
630
+ .compat_ioctl = proc_reg_compat_ioctl,
425631 .mmap = proc_reg_mmap,
426632 .get_unmapped_area = proc_reg_get_unmapped_area,
427633 .open = proc_reg_open,
....@@ -453,81 +659,51 @@
453659 {
454660 struct inode *inode = new_inode(sb);
455661
456
- if (inode) {
457
- inode->i_ino = de->low_ino;
458
- inode->i_mtime = inode->i_atime = inode->i_ctime = current_time(inode);
459
- PROC_I(inode)->pde = de;
662
+ if (!inode) {
663
+ pde_put(de);
664
+ return NULL;
665
+ }
460666
461
- if (is_empty_pde(de)) {
462
- make_empty_dir_inode(inode);
463
- return inode;
464
- }
465
- if (de->mode) {
466
- inode->i_mode = de->mode;
467
- inode->i_uid = de->uid;
468
- inode->i_gid = de->gid;
469
- }
470
- if (de->size)
471
- inode->i_size = de->size;
472
- if (de->nlink)
473
- set_nlink(inode, de->nlink);
474
- WARN_ON(!de->proc_iops);
667
+ inode->i_ino = de->low_ino;
668
+ inode->i_mtime = inode->i_atime = inode->i_ctime = current_time(inode);
669
+ PROC_I(inode)->pde = de;
670
+ if (is_empty_pde(de)) {
671
+ make_empty_dir_inode(inode);
672
+ return inode;
673
+ }
674
+
675
+ if (de->mode) {
676
+ inode->i_mode = de->mode;
677
+ inode->i_uid = de->uid;
678
+ inode->i_gid = de->gid;
679
+ }
680
+ if (de->size)
681
+ inode->i_size = de->size;
682
+ if (de->nlink)
683
+ set_nlink(inode, de->nlink);
684
+
685
+ if (S_ISREG(inode->i_mode)) {
475686 inode->i_op = de->proc_iops;
476
- if (de->proc_fops) {
477
- if (S_ISREG(inode->i_mode)) {
687
+ if (de->proc_ops->proc_read_iter)
688
+ inode->i_fop = &proc_iter_file_ops;
689
+ else
690
+ inode->i_fop = &proc_reg_file_ops;
478691 #ifdef CONFIG_COMPAT
479
- if (!de->proc_fops->compat_ioctl)
480
- inode->i_fop =
481
- &proc_reg_file_ops_no_compat;
482
- else
483
-#endif
484
- inode->i_fop = &proc_reg_file_ops;
485
- } else {
486
- inode->i_fop = de->proc_fops;
487
- }
692
+ if (de->proc_ops->proc_compat_ioctl) {
693
+ if (de->proc_ops->proc_read_iter)
694
+ inode->i_fop = &proc_iter_file_ops_compat;
695
+ else
696
+ inode->i_fop = &proc_reg_file_ops_compat;
488697 }
489
- } else
490
- pde_put(de);
698
+#endif
699
+ } else if (S_ISDIR(inode->i_mode)) {
700
+ inode->i_op = de->proc_iops;
701
+ inode->i_fop = de->proc_dir_ops;
702
+ } else if (S_ISLNK(inode->i_mode)) {
703
+ inode->i_op = de->proc_iops;
704
+ inode->i_fop = NULL;
705
+ } else {
706
+ BUG();
707
+ }
491708 return inode;
492
-}
493
-
494
-int proc_fill_super(struct super_block *s)
495
-{
496
- struct inode *root_inode;
497
- int ret;
498
-
499
- /* User space would break if executables or devices appear on proc */
500
- s->s_iflags |= SB_I_USERNS_VISIBLE | SB_I_NODEV;
501
- s->s_flags |= SB_NODIRATIME | SB_NOSUID | SB_NOEXEC;
502
- s->s_blocksize = 1024;
503
- s->s_blocksize_bits = 10;
504
- s->s_magic = PROC_SUPER_MAGIC;
505
- s->s_op = &proc_sops;
506
- s->s_time_gran = 1;
507
-
508
- /*
509
- * procfs isn't actually a stacking filesystem; however, there is
510
- * too much magic going on inside it to permit stacking things on
511
- * top of it
512
- */
513
- s->s_stack_depth = FILESYSTEM_MAX_STACK_DEPTH;
514
-
515
- pde_get(&proc_root);
516
- root_inode = proc_get_inode(s, &proc_root);
517
- if (!root_inode) {
518
- pr_err("proc_fill_super: get root inode failed\n");
519
- return -ENOMEM;
520
- }
521
-
522
- s->s_root = d_make_root(root_inode);
523
- if (!s->s_root) {
524
- pr_err("proc_fill_super: allocate dentry failed\n");
525
- return -ENOMEM;
526
- }
527
-
528
- ret = proc_setup_self(s);
529
- if (ret) {
530
- return ret;
531
- }
532
- return proc_setup_thread_self(s);
533709 }