4 * Copyright (C) 1991, 1992 Linus Torvalds
6 * proc base directory handling functions
8 * 1999, Al Viro. Rewritten. Now it covers the whole per-process part.
9 * Instead of using magical inumbers to determine the kind of object
10 * we allocate and fill in-core inodes upon lookup. They don't even
11 * go into icache. We cache the reference to task_struct upon lookup too.
12 * Eventually it should become a filesystem in its own. We don't use the
13 * rest of procfs anymore.
19 * Bruna Moreira <bruna.moreira@indt.org.br>
20 * Edjard Mota <edjard.mota@indt.org.br>
21 * Ilias Biris <ilias.biris@indt.org.br>
22 * Mauricio Lin <mauricio.lin@indt.org.br>
24 * Embedded Linux Lab - 10LE Instituto Nokia de Tecnologia - INdT
26 * A new process specific entry (smaps) included in /proc. It shows the
27 * size of rss for each memory area. The maps entry lacks information
28 * about physical memory size (rss) for each mapped file, i.e.,
29 * rss information for executables and library files.
30 * This additional information is useful for any tools that need to know
31 * about physical memory consumption for a process specific library.
35 * Embedded Linux Lab - 10LE Instituto Nokia de Tecnologia - INdT
36 * Pud inclusion in the page table walking.
40 * 10LE Instituto Nokia de Tecnologia - INdT:
41 * A better way to walks through the page table as suggested by Hugh Dickins.
43 * Simo Piiroinen <simo.piiroinen@nokia.com>:
44 * Smaps information related to shared, private, clean and dirty pages.
46 * Paul Mundt <paul.mundt@nokia.com>:
47 * Overall revision about smaps.
50 #include <asm/uaccess.h>
52 #include <linux/errno.h>
53 #include <linux/time.h>
54 #include <linux/proc_fs.h>
55 #include <linux/stat.h>
56 #include <linux/init.h>
57 #include <linux/capability.h>
58 #include <linux/file.h>
59 #include <linux/string.h>
60 #include <linux/seq_file.h>
61 #include <linux/namei.h>
62 #include <linux/mnt_namespace.h>
64 #include <linux/rcupdate.h>
65 #include <linux/kallsyms.h>
66 #include <linux/resource.h>
67 #include <linux/module.h>
68 #include <linux/mount.h>
69 #include <linux/security.h>
70 #include <linux/ptrace.h>
71 #include <linux/cgroup.h>
72 #include <linux/cpuset.h>
73 #include <linux/audit.h>
74 #include <linux/poll.h>
75 #include <linux/nsproxy.h>
76 #include <linux/oom.h>
77 #include <linux/elf.h>
78 #include <linux/pid_namespace.h>
82 * Implementing inode permission operations in /proc is almost
83 * certainly an error. Permission checks need to happen during
84 * each system call not at open time. The reason is that most of
85 * what we wish to check for permissions in /proc varies at runtime.
87 * The classic example of a problem is opening file descriptors
88 * in /proc for a task before it execs a suid executable.
92 /* Worst case buffer size needed for holding an integer. */
93 #define PROC_NUMBUF 13
99 const struct inode_operations
*iop
;
100 const struct file_operations
*fop
;
104 #define NOD(NAME, MODE, IOP, FOP, OP) { \
106 .len = sizeof(NAME) - 1, \
113 #define DIR(NAME, MODE, OTYPE) \
114 NOD(NAME, (S_IFDIR|(MODE)), \
115 &proc_##OTYPE##_inode_operations, &proc_##OTYPE##_operations, \
117 #define LNK(NAME, OTYPE) \
118 NOD(NAME, (S_IFLNK|S_IRWXUGO), \
119 &proc_pid_link_inode_operations, NULL, \
120 { .proc_get_link = &proc_##OTYPE##_link } )
121 #define REG(NAME, MODE, OTYPE) \
122 NOD(NAME, (S_IFREG|(MODE)), NULL, \
123 &proc_##OTYPE##_operations, {})
124 #define INF(NAME, MODE, OTYPE) \
125 NOD(NAME, (S_IFREG|(MODE)), \
126 NULL, &proc_info_file_operations, \
127 { .proc_read = &proc_##OTYPE } )
130 EXPORT_SYMBOL(maps_protect
);
132 static struct fs_struct
*get_fs_struct(struct task_struct
*task
)
134 struct fs_struct
*fs
;
138 atomic_inc(&fs
->count
);
143 static int get_nr_threads(struct task_struct
*tsk
)
145 /* Must be called with the rcu_read_lock held */
149 if (lock_task_sighand(tsk
, &flags
)) {
150 count
= atomic_read(&tsk
->signal
->count
);
151 unlock_task_sighand(tsk
, &flags
);
156 static int proc_cwd_link(struct inode
*inode
, struct dentry
**dentry
, struct vfsmount
**mnt
)
158 struct task_struct
*task
= get_proc_task(inode
);
159 struct fs_struct
*fs
= NULL
;
160 int result
= -ENOENT
;
163 fs
= get_fs_struct(task
);
164 put_task_struct(task
);
167 read_lock(&fs
->lock
);
168 *mnt
= mntget(fs
->pwdmnt
);
169 *dentry
= dget(fs
->pwd
);
170 read_unlock(&fs
->lock
);
177 static int proc_root_link(struct inode
*inode
, struct dentry
**dentry
, struct vfsmount
**mnt
)
179 struct task_struct
*task
= get_proc_task(inode
);
180 struct fs_struct
*fs
= NULL
;
181 int result
= -ENOENT
;
184 fs
= get_fs_struct(task
);
185 put_task_struct(task
);
188 read_lock(&fs
->lock
);
189 *mnt
= mntget(fs
->rootmnt
);
190 *dentry
= dget(fs
->root
);
191 read_unlock(&fs
->lock
);
198 #define MAY_PTRACE(task) \
199 (task == current || \
200 (task->parent == current && \
201 (task->ptrace & PT_PTRACED) && \
202 (task->state == TASK_STOPPED || task->state == TASK_TRACED) && \
203 security_ptrace(current,task) == 0))
205 struct mm_struct
*mm_for_maps(struct task_struct
*task
)
207 struct mm_struct
*mm
= get_task_mm(task
);
210 down_read(&mm
->mmap_sem
);
214 if (task
->mm
!= current
->mm
&& __ptrace_may_attach(task
) < 0)
220 up_read(&mm
->mmap_sem
);
225 static int proc_pid_cmdline(struct task_struct
*task
, char * buffer
)
229 struct mm_struct
*mm
= get_task_mm(task
);
233 goto out_mm
; /* Shh! No looking before we're done */
235 len
= mm
->arg_end
- mm
->arg_start
;
240 res
= access_process_vm(task
, mm
->arg_start
, buffer
, len
, 0);
242 // If the nul at the end of args has been overwritten, then
243 // assume application is using setproctitle(3).
244 if (res
> 0 && buffer
[res
-1] != '\0' && len
< PAGE_SIZE
) {
245 len
= strnlen(buffer
, res
);
249 len
= mm
->env_end
- mm
->env_start
;
250 if (len
> PAGE_SIZE
- res
)
251 len
= PAGE_SIZE
- res
;
252 res
+= access_process_vm(task
, mm
->env_start
, buffer
+res
, len
, 0);
253 res
= strnlen(buffer
, res
);
262 static int proc_pid_auxv(struct task_struct
*task
, char *buffer
)
265 struct mm_struct
*mm
= get_task_mm(task
);
267 unsigned int nwords
= 0;
270 while (mm
->saved_auxv
[nwords
- 2] != 0); /* AT_NULL */
271 res
= nwords
* sizeof(mm
->saved_auxv
[0]);
274 memcpy(buffer
, mm
->saved_auxv
, res
);
281 #ifdef CONFIG_KALLSYMS
283 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
284 * Returns the resolved symbol. If that fails, simply return the address.
286 static int proc_pid_wchan(struct task_struct
*task
, char *buffer
)
289 char symname
[KSYM_NAME_LEN
];
291 wchan
= get_wchan(task
);
293 if (lookup_symbol_name(wchan
, symname
) < 0)
294 return sprintf(buffer
, "%lu", wchan
);
296 return sprintf(buffer
, "%s", symname
);
298 #endif /* CONFIG_KALLSYMS */
300 #ifdef CONFIG_SCHEDSTATS
302 * Provides /proc/PID/schedstat
304 static int proc_pid_schedstat(struct task_struct
*task
, char *buffer
)
306 return sprintf(buffer
, "%llu %llu %lu\n",
307 task
->sched_info
.cpu_time
,
308 task
->sched_info
.run_delay
,
309 task
->sched_info
.pcount
);
313 /* The badness from the OOM killer */
314 unsigned long badness(struct task_struct
*p
, unsigned long uptime
);
315 static int proc_oom_score(struct task_struct
*task
, char *buffer
)
317 unsigned long points
;
318 struct timespec uptime
;
320 do_posix_clock_monotonic_gettime(&uptime
);
321 read_lock(&tasklist_lock
);
322 points
= badness(task
, uptime
.tv_sec
);
323 read_unlock(&tasklist_lock
);
324 return sprintf(buffer
, "%lu\n", points
);
332 static const struct limit_names lnames
[RLIM_NLIMITS
] = {
333 [RLIMIT_CPU
] = {"Max cpu time", "ms"},
334 [RLIMIT_FSIZE
] = {"Max file size", "bytes"},
335 [RLIMIT_DATA
] = {"Max data size", "bytes"},
336 [RLIMIT_STACK
] = {"Max stack size", "bytes"},
337 [RLIMIT_CORE
] = {"Max core file size", "bytes"},
338 [RLIMIT_RSS
] = {"Max resident set", "bytes"},
339 [RLIMIT_NPROC
] = {"Max processes", "processes"},
340 [RLIMIT_NOFILE
] = {"Max open files", "files"},
341 [RLIMIT_MEMLOCK
] = {"Max locked memory", "bytes"},
342 [RLIMIT_AS
] = {"Max address space", "bytes"},
343 [RLIMIT_LOCKS
] = {"Max file locks", "locks"},
344 [RLIMIT_SIGPENDING
] = {"Max pending signals", "signals"},
345 [RLIMIT_MSGQUEUE
] = {"Max msgqueue size", "bytes"},
346 [RLIMIT_NICE
] = {"Max nice priority", NULL
},
347 [RLIMIT_RTPRIO
] = {"Max realtime priority", NULL
},
350 /* Display limits for a process */
351 static int proc_pid_limits(struct task_struct
*task
, char *buffer
)
356 char *bufptr
= buffer
;
358 struct rlimit rlim
[RLIM_NLIMITS
];
361 if (!lock_task_sighand(task
,&flags
)) {
365 memcpy(rlim
, task
->signal
->rlim
, sizeof(struct rlimit
) * RLIM_NLIMITS
);
366 unlock_task_sighand(task
, &flags
);
370 * print the file header
372 count
+= sprintf(&bufptr
[count
], "%-25s %-20s %-20s %-10s\n",
373 "Limit", "Soft Limit", "Hard Limit", "Units");
375 for (i
= 0; i
< RLIM_NLIMITS
; i
++) {
376 if (rlim
[i
].rlim_cur
== RLIM_INFINITY
)
377 count
+= sprintf(&bufptr
[count
], "%-25s %-20s ",
378 lnames
[i
].name
, "unlimited");
380 count
+= sprintf(&bufptr
[count
], "%-25s %-20lu ",
381 lnames
[i
].name
, rlim
[i
].rlim_cur
);
383 if (rlim
[i
].rlim_max
== RLIM_INFINITY
)
384 count
+= sprintf(&bufptr
[count
], "%-20s ", "unlimited");
386 count
+= sprintf(&bufptr
[count
], "%-20lu ",
390 count
+= sprintf(&bufptr
[count
], "%-10s\n",
393 count
+= sprintf(&bufptr
[count
], "\n");
399 /************************************************************************/
400 /* Here the fs part begins */
401 /************************************************************************/
403 /* permission checks */
404 static int proc_fd_access_allowed(struct inode
*inode
)
406 struct task_struct
*task
;
408 /* Allow access to a task's file descriptors if it is us or we
409 * may use ptrace attach to the process and find out that
412 task
= get_proc_task(inode
);
414 allowed
= ptrace_may_attach(task
);
415 put_task_struct(task
);
420 static int proc_setattr(struct dentry
*dentry
, struct iattr
*attr
)
423 struct inode
*inode
= dentry
->d_inode
;
425 if (attr
->ia_valid
& ATTR_MODE
)
428 error
= inode_change_ok(inode
, attr
);
430 error
= inode_setattr(inode
, attr
);
434 static const struct inode_operations proc_def_inode_operations
= {
435 .setattr
= proc_setattr
,
438 extern struct seq_operations mounts_op
;
444 static int mounts_open(struct inode
*inode
, struct file
*file
)
446 struct task_struct
*task
= get_proc_task(inode
);
448 struct mnt_namespace
*ns
= NULL
;
449 struct proc_mounts
*p
;
454 nsp
= task_nsproxy(task
);
462 put_task_struct(task
);
467 p
= kmalloc(sizeof(struct proc_mounts
), GFP_KERNEL
);
469 file
->private_data
= &p
->m
;
470 ret
= seq_open(file
, &mounts_op
);
473 p
->event
= ns
->event
;
483 static int mounts_release(struct inode
*inode
, struct file
*file
)
485 struct seq_file
*m
= file
->private_data
;
486 struct mnt_namespace
*ns
= m
->private;
488 return seq_release(inode
, file
);
491 static unsigned mounts_poll(struct file
*file
, poll_table
*wait
)
493 struct proc_mounts
*p
= file
->private_data
;
494 struct mnt_namespace
*ns
= p
->m
.private;
497 poll_wait(file
, &ns
->poll
, wait
);
499 spin_lock(&vfsmount_lock
);
500 if (p
->event
!= ns
->event
) {
501 p
->event
= ns
->event
;
504 spin_unlock(&vfsmount_lock
);
509 static const struct file_operations proc_mounts_operations
= {
513 .release
= mounts_release
,
517 extern struct seq_operations mountstats_op
;
518 static int mountstats_open(struct inode
*inode
, struct file
*file
)
520 int ret
= seq_open(file
, &mountstats_op
);
523 struct seq_file
*m
= file
->private_data
;
525 struct mnt_namespace
*mnt_ns
= NULL
;
526 struct task_struct
*task
= get_proc_task(inode
);
530 nsp
= task_nsproxy(task
);
532 mnt_ns
= nsp
->mnt_ns
;
538 put_task_struct(task
);
544 seq_release(inode
, file
);
551 static const struct file_operations proc_mountstats_operations
= {
552 .open
= mountstats_open
,
555 .release
= mounts_release
,
558 #define PROC_BLOCK_SIZE (3*1024) /* 4K page size but our output routines use some slack for overruns */
560 static ssize_t
proc_info_read(struct file
* file
, char __user
* buf
,
561 size_t count
, loff_t
*ppos
)
563 struct inode
* inode
= file
->f_path
.dentry
->d_inode
;
566 struct task_struct
*task
= get_proc_task(inode
);
572 if (count
> PROC_BLOCK_SIZE
)
573 count
= PROC_BLOCK_SIZE
;
576 if (!(page
= __get_free_page(GFP_TEMPORARY
)))
579 length
= PROC_I(inode
)->op
.proc_read(task
, (char*)page
);
582 length
= simple_read_from_buffer(buf
, count
, ppos
, (char *)page
, length
);
585 put_task_struct(task
);
590 static const struct file_operations proc_info_file_operations
= {
591 .read
= proc_info_read
,
594 static int mem_open(struct inode
* inode
, struct file
* file
)
596 file
->private_data
= (void*)((long)current
->self_exec_id
);
600 static ssize_t
mem_read(struct file
* file
, char __user
* buf
,
601 size_t count
, loff_t
*ppos
)
603 struct task_struct
*task
= get_proc_task(file
->f_path
.dentry
->d_inode
);
605 unsigned long src
= *ppos
;
607 struct mm_struct
*mm
;
612 if (!MAY_PTRACE(task
) || !ptrace_may_attach(task
))
616 page
= (char *)__get_free_page(GFP_TEMPORARY
);
622 mm
= get_task_mm(task
);
628 if (file
->private_data
!= (void*)((long)current
->self_exec_id
))
634 int this_len
, retval
;
636 this_len
= (count
> PAGE_SIZE
) ? PAGE_SIZE
: count
;
637 retval
= access_process_vm(task
, src
, page
, this_len
, 0);
638 if (!retval
|| !MAY_PTRACE(task
) || !ptrace_may_attach(task
)) {
644 if (copy_to_user(buf
, page
, retval
)) {
659 free_page((unsigned long) page
);
661 put_task_struct(task
);
666 #define mem_write NULL
669 /* This is a security hazard */
670 static ssize_t
mem_write(struct file
* file
, const char __user
*buf
,
671 size_t count
, loff_t
*ppos
)
675 struct task_struct
*task
= get_proc_task(file
->f_path
.dentry
->d_inode
);
676 unsigned long dst
= *ppos
;
682 if (!MAY_PTRACE(task
) || !ptrace_may_attach(task
))
686 page
= (char *)__get_free_page(GFP_TEMPORARY
);
692 int this_len
, retval
;
694 this_len
= (count
> PAGE_SIZE
) ? PAGE_SIZE
: count
;
695 if (copy_from_user(page
, buf
, this_len
)) {
699 retval
= access_process_vm(task
, dst
, page
, this_len
, 1);
711 free_page((unsigned long) page
);
713 put_task_struct(task
);
719 static loff_t
mem_lseek(struct file
* file
, loff_t offset
, int orig
)
723 file
->f_pos
= offset
;
726 file
->f_pos
+= offset
;
731 force_successful_syscall_return();
735 static const struct file_operations proc_mem_operations
= {
742 static ssize_t
environ_read(struct file
*file
, char __user
*buf
,
743 size_t count
, loff_t
*ppos
)
745 struct task_struct
*task
= get_proc_task(file
->f_dentry
->d_inode
);
747 unsigned long src
= *ppos
;
749 struct mm_struct
*mm
;
754 if (!ptrace_may_attach(task
))
758 page
= (char *)__get_free_page(GFP_TEMPORARY
);
764 mm
= get_task_mm(task
);
769 int this_len
, retval
, max_len
;
771 this_len
= mm
->env_end
- (mm
->env_start
+ src
);
776 max_len
= (count
> PAGE_SIZE
) ? PAGE_SIZE
: count
;
777 this_len
= (this_len
> max_len
) ? max_len
: this_len
;
779 retval
= access_process_vm(task
, (mm
->env_start
+ src
),
787 if (copy_to_user(buf
, page
, retval
)) {
801 free_page((unsigned long) page
);
803 put_task_struct(task
);
808 static const struct file_operations proc_environ_operations
= {
809 .read
= environ_read
,
812 static ssize_t
oom_adjust_read(struct file
*file
, char __user
*buf
,
813 size_t count
, loff_t
*ppos
)
815 struct task_struct
*task
= get_proc_task(file
->f_path
.dentry
->d_inode
);
816 char buffer
[PROC_NUMBUF
];
822 oom_adjust
= task
->oomkilladj
;
823 put_task_struct(task
);
825 len
= snprintf(buffer
, sizeof(buffer
), "%i\n", oom_adjust
);
827 return simple_read_from_buffer(buf
, count
, ppos
, buffer
, len
);
830 static ssize_t
oom_adjust_write(struct file
*file
, const char __user
*buf
,
831 size_t count
, loff_t
*ppos
)
833 struct task_struct
*task
;
834 char buffer
[PROC_NUMBUF
], *end
;
837 memset(buffer
, 0, sizeof(buffer
));
838 if (count
> sizeof(buffer
) - 1)
839 count
= sizeof(buffer
) - 1;
840 if (copy_from_user(buffer
, buf
, count
))
842 oom_adjust
= simple_strtol(buffer
, &end
, 0);
843 if ((oom_adjust
< OOM_ADJUST_MIN
|| oom_adjust
> OOM_ADJUST_MAX
) &&
844 oom_adjust
!= OOM_DISABLE
)
848 task
= get_proc_task(file
->f_path
.dentry
->d_inode
);
851 if (oom_adjust
< task
->oomkilladj
&& !capable(CAP_SYS_RESOURCE
)) {
852 put_task_struct(task
);
855 task
->oomkilladj
= oom_adjust
;
856 put_task_struct(task
);
857 if (end
- buffer
== 0)
862 static const struct file_operations proc_oom_adjust_operations
= {
863 .read
= oom_adjust_read
,
864 .write
= oom_adjust_write
,
868 static ssize_t
clear_refs_write(struct file
*file
, const char __user
*buf
,
869 size_t count
, loff_t
*ppos
)
871 struct task_struct
*task
;
872 char buffer
[PROC_NUMBUF
], *end
;
873 struct mm_struct
*mm
;
875 memset(buffer
, 0, sizeof(buffer
));
876 if (count
> sizeof(buffer
) - 1)
877 count
= sizeof(buffer
) - 1;
878 if (copy_from_user(buffer
, buf
, count
))
880 if (!simple_strtol(buffer
, &end
, 0))
884 task
= get_proc_task(file
->f_path
.dentry
->d_inode
);
887 mm
= get_task_mm(task
);
892 put_task_struct(task
);
893 if (end
- buffer
== 0)
898 static struct file_operations proc_clear_refs_operations
= {
899 .write
= clear_refs_write
,
903 #ifdef CONFIG_AUDITSYSCALL
905 static ssize_t
proc_loginuid_read(struct file
* file
, char __user
* buf
,
906 size_t count
, loff_t
*ppos
)
908 struct inode
* inode
= file
->f_path
.dentry
->d_inode
;
909 struct task_struct
*task
= get_proc_task(inode
);
911 char tmpbuf
[TMPBUFLEN
];
915 length
= scnprintf(tmpbuf
, TMPBUFLEN
, "%u",
916 audit_get_loginuid(task
->audit_context
));
917 put_task_struct(task
);
918 return simple_read_from_buffer(buf
, count
, ppos
, tmpbuf
, length
);
921 static ssize_t
proc_loginuid_write(struct file
* file
, const char __user
* buf
,
922 size_t count
, loff_t
*ppos
)
924 struct inode
* inode
= file
->f_path
.dentry
->d_inode
;
929 if (!capable(CAP_AUDIT_CONTROL
))
932 if (current
!= pid_task(proc_pid(inode
), PIDTYPE_PID
))
935 if (count
>= PAGE_SIZE
)
936 count
= PAGE_SIZE
- 1;
939 /* No partial writes. */
942 page
= (char*)__get_free_page(GFP_TEMPORARY
);
946 if (copy_from_user(page
, buf
, count
))
950 loginuid
= simple_strtoul(page
, &tmp
, 10);
956 length
= audit_set_loginuid(current
, loginuid
);
957 if (likely(length
== 0))
961 free_page((unsigned long) page
);
965 static const struct file_operations proc_loginuid_operations
= {
966 .read
= proc_loginuid_read
,
967 .write
= proc_loginuid_write
,
971 #ifdef CONFIG_FAULT_INJECTION
972 static ssize_t
proc_fault_inject_read(struct file
* file
, char __user
* buf
,
973 size_t count
, loff_t
*ppos
)
975 struct task_struct
*task
= get_proc_task(file
->f_dentry
->d_inode
);
976 char buffer
[PROC_NUMBUF
];
982 make_it_fail
= task
->make_it_fail
;
983 put_task_struct(task
);
985 len
= snprintf(buffer
, sizeof(buffer
), "%i\n", make_it_fail
);
987 return simple_read_from_buffer(buf
, count
, ppos
, buffer
, len
);
990 static ssize_t
proc_fault_inject_write(struct file
* file
,
991 const char __user
* buf
, size_t count
, loff_t
*ppos
)
993 struct task_struct
*task
;
994 char buffer
[PROC_NUMBUF
], *end
;
997 if (!capable(CAP_SYS_RESOURCE
))
999 memset(buffer
, 0, sizeof(buffer
));
1000 if (count
> sizeof(buffer
) - 1)
1001 count
= sizeof(buffer
) - 1;
1002 if (copy_from_user(buffer
, buf
, count
))
1004 make_it_fail
= simple_strtol(buffer
, &end
, 0);
1007 task
= get_proc_task(file
->f_dentry
->d_inode
);
1010 task
->make_it_fail
= make_it_fail
;
1011 put_task_struct(task
);
1012 if (end
- buffer
== 0)
1014 return end
- buffer
;
1017 static const struct file_operations proc_fault_inject_operations
= {
1018 .read
= proc_fault_inject_read
,
1019 .write
= proc_fault_inject_write
,
1023 #ifdef CONFIG_SCHED_DEBUG
1025 * Print out various scheduling related per-task fields:
1027 static int sched_show(struct seq_file
*m
, void *v
)
1029 struct inode
*inode
= m
->private;
1030 struct task_struct
*p
;
1034 p
= get_proc_task(inode
);
1037 proc_sched_show_task(p
, m
);
1045 sched_write(struct file
*file
, const char __user
*buf
,
1046 size_t count
, loff_t
*offset
)
1048 struct inode
*inode
= file
->f_path
.dentry
->d_inode
;
1049 struct task_struct
*p
;
1053 p
= get_proc_task(inode
);
1056 proc_sched_set_task(p
);
1063 static int sched_open(struct inode
*inode
, struct file
*filp
)
1067 ret
= single_open(filp
, sched_show
, NULL
);
1069 struct seq_file
*m
= filp
->private_data
;
1076 static const struct file_operations proc_pid_sched_operations
= {
1079 .write
= sched_write
,
1080 .llseek
= seq_lseek
,
1081 .release
= single_release
,
1086 static void *proc_pid_follow_link(struct dentry
*dentry
, struct nameidata
*nd
)
1088 struct inode
*inode
= dentry
->d_inode
;
1089 int error
= -EACCES
;
1091 /* We don't need a base pointer in the /proc filesystem */
1094 /* Are we allowed to snoop on the tasks file descriptors? */
1095 if (!proc_fd_access_allowed(inode
))
1098 error
= PROC_I(inode
)->op
.proc_get_link(inode
, &nd
->dentry
, &nd
->mnt
);
1099 nd
->last_type
= LAST_BIND
;
1101 return ERR_PTR(error
);
1104 static int do_proc_readlink(struct dentry
*dentry
, struct vfsmount
*mnt
,
1105 char __user
*buffer
, int buflen
)
1107 struct inode
* inode
;
1108 char *tmp
= (char*)__get_free_page(GFP_TEMPORARY
);
1115 inode
= dentry
->d_inode
;
1116 path
= d_path(dentry
, mnt
, tmp
, PAGE_SIZE
);
1117 len
= PTR_ERR(path
);
1120 len
= tmp
+ PAGE_SIZE
- 1 - path
;
1124 if (copy_to_user(buffer
, path
, len
))
1127 free_page((unsigned long)tmp
);
1131 static int proc_pid_readlink(struct dentry
* dentry
, char __user
* buffer
, int buflen
)
1133 int error
= -EACCES
;
1134 struct inode
*inode
= dentry
->d_inode
;
1136 struct vfsmount
*mnt
= NULL
;
1138 /* Are we allowed to snoop on the tasks file descriptors? */
1139 if (!proc_fd_access_allowed(inode
))
1142 error
= PROC_I(inode
)->op
.proc_get_link(inode
, &de
, &mnt
);
1146 error
= do_proc_readlink(de
, mnt
, buffer
, buflen
);
1153 static const struct inode_operations proc_pid_link_inode_operations
= {
1154 .readlink
= proc_pid_readlink
,
1155 .follow_link
= proc_pid_follow_link
,
1156 .setattr
= proc_setattr
,
1160 /* building an inode */
1162 static int task_dumpable(struct task_struct
*task
)
1165 struct mm_struct
*mm
;
1170 dumpable
= get_dumpable(mm
);
1178 static struct inode
*proc_pid_make_inode(struct super_block
* sb
, struct task_struct
*task
)
1180 struct inode
* inode
;
1181 struct proc_inode
*ei
;
1183 /* We need a new inode */
1185 inode
= new_inode(sb
);
1191 inode
->i_mtime
= inode
->i_atime
= inode
->i_ctime
= CURRENT_TIME
;
1192 inode
->i_op
= &proc_def_inode_operations
;
1195 * grab the reference to task.
1197 ei
->pid
= get_task_pid(task
, PIDTYPE_PID
);
1203 if (task_dumpable(task
)) {
1204 inode
->i_uid
= task
->euid
;
1205 inode
->i_gid
= task
->egid
;
1207 security_task_to_inode(task
, inode
);
1217 static int pid_getattr(struct vfsmount
*mnt
, struct dentry
*dentry
, struct kstat
*stat
)
1219 struct inode
*inode
= dentry
->d_inode
;
1220 struct task_struct
*task
;
1221 generic_fillattr(inode
, stat
);
1226 task
= pid_task(proc_pid(inode
), PIDTYPE_PID
);
1228 if ((inode
->i_mode
== (S_IFDIR
|S_IRUGO
|S_IXUGO
)) ||
1229 task_dumpable(task
)) {
1230 stat
->uid
= task
->euid
;
1231 stat
->gid
= task
->egid
;
1241 * Exceptional case: normally we are not allowed to unhash a busy
1242 * directory. In this case, however, we can do it - no aliasing problems
1243 * due to the way we treat inodes.
1245 * Rewrite the inode's ownerships here because the owning task may have
1246 * performed a setuid(), etc.
1248 * Before the /proc/pid/status file was created the only way to read
1249 * the effective uid of a /process was to stat /proc/pid. Reading
1250 * /proc/pid/status is slow enough that procps and other packages
1251 * kept stating /proc/pid. To keep the rules in /proc simple I have
1252 * made this apply to all per process world readable and executable
1255 static int pid_revalidate(struct dentry
*dentry
, struct nameidata
*nd
)
1257 struct inode
*inode
= dentry
->d_inode
;
1258 struct task_struct
*task
= get_proc_task(inode
);
1260 if ((inode
->i_mode
== (S_IFDIR
|S_IRUGO
|S_IXUGO
)) ||
1261 task_dumpable(task
)) {
1262 inode
->i_uid
= task
->euid
;
1263 inode
->i_gid
= task
->egid
;
1268 inode
->i_mode
&= ~(S_ISUID
| S_ISGID
);
1269 security_task_to_inode(task
, inode
);
1270 put_task_struct(task
);
1277 static int pid_delete_dentry(struct dentry
* dentry
)
1279 /* Is the task we represent dead?
1280 * If so, then don't put the dentry on the lru list,
1281 * kill it immediately.
1283 return !proc_pid(dentry
->d_inode
)->tasks
[PIDTYPE_PID
].first
;
1286 static struct dentry_operations pid_dentry_operations
=
1288 .d_revalidate
= pid_revalidate
,
1289 .d_delete
= pid_delete_dentry
,
1294 typedef struct dentry
*instantiate_t(struct inode
*, struct dentry
*,
1295 struct task_struct
*, const void *);
1298 * Fill a directory entry.
1300 * If possible create the dcache entry and derive our inode number and
1301 * file type from dcache entry.
1303 * Since all of the proc inode numbers are dynamically generated, the inode
1304 * numbers do not exist until the inode is cache. This means creating the
1305 * the dcache entry in readdir is necessary to keep the inode numbers
1306 * reported by readdir in sync with the inode numbers reported
1309 static int proc_fill_cache(struct file
*filp
, void *dirent
, filldir_t filldir
,
1310 char *name
, int len
,
1311 instantiate_t instantiate
, struct task_struct
*task
, const void *ptr
)
1313 struct dentry
*child
, *dir
= filp
->f_path
.dentry
;
1314 struct inode
*inode
;
1317 unsigned type
= DT_UNKNOWN
;
1321 qname
.hash
= full_name_hash(name
, len
);
1323 child
= d_lookup(dir
, &qname
);
1326 new = d_alloc(dir
, &qname
);
1328 child
= instantiate(dir
->d_inode
, new, task
, ptr
);
1335 if (!child
|| IS_ERR(child
) || !child
->d_inode
)
1336 goto end_instantiate
;
1337 inode
= child
->d_inode
;
1340 type
= inode
->i_mode
>> 12;
1345 ino
= find_inode_number(dir
, &qname
);
1348 return filldir(dirent
, name
, len
, filp
->f_pos
, ino
, type
);
1351 static unsigned name_to_int(struct dentry
*dentry
)
1353 const char *name
= dentry
->d_name
.name
;
1354 int len
= dentry
->d_name
.len
;
1357 if (len
> 1 && *name
== '0')
1360 unsigned c
= *name
++ - '0';
1363 if (n
>= (~0U-9)/10)
1373 #define PROC_FDINFO_MAX 64
1375 static int proc_fd_info(struct inode
*inode
, struct dentry
**dentry
,
1376 struct vfsmount
**mnt
, char *info
)
1378 struct task_struct
*task
= get_proc_task(inode
);
1379 struct files_struct
*files
= NULL
;
1381 int fd
= proc_fd(inode
);
1384 files
= get_files_struct(task
);
1385 put_task_struct(task
);
1389 * We are not taking a ref to the file structure, so we must
1392 spin_lock(&files
->file_lock
);
1393 file
= fcheck_files(files
, fd
);
1396 *mnt
= mntget(file
->f_path
.mnt
);
1398 *dentry
= dget(file
->f_path
.dentry
);
1400 snprintf(info
, PROC_FDINFO_MAX
,
1403 (long long) file
->f_pos
,
1405 spin_unlock(&files
->file_lock
);
1406 put_files_struct(files
);
1409 spin_unlock(&files
->file_lock
);
1410 put_files_struct(files
);
1415 static int proc_fd_link(struct inode
*inode
, struct dentry
**dentry
,
1416 struct vfsmount
**mnt
)
1418 return proc_fd_info(inode
, dentry
, mnt
, NULL
);
1421 static int tid_fd_revalidate(struct dentry
*dentry
, struct nameidata
*nd
)
1423 struct inode
*inode
= dentry
->d_inode
;
1424 struct task_struct
*task
= get_proc_task(inode
);
1425 int fd
= proc_fd(inode
);
1426 struct files_struct
*files
;
1429 files
= get_files_struct(task
);
1432 if (fcheck_files(files
, fd
)) {
1434 put_files_struct(files
);
1435 if (task_dumpable(task
)) {
1436 inode
->i_uid
= task
->euid
;
1437 inode
->i_gid
= task
->egid
;
1442 inode
->i_mode
&= ~(S_ISUID
| S_ISGID
);
1443 security_task_to_inode(task
, inode
);
1444 put_task_struct(task
);
1448 put_files_struct(files
);
1450 put_task_struct(task
);
1456 static struct dentry_operations tid_fd_dentry_operations
=
1458 .d_revalidate
= tid_fd_revalidate
,
1459 .d_delete
= pid_delete_dentry
,
1462 static struct dentry
*proc_fd_instantiate(struct inode
*dir
,
1463 struct dentry
*dentry
, struct task_struct
*task
, const void *ptr
)
1465 unsigned fd
= *(const unsigned *)ptr
;
1467 struct files_struct
*files
;
1468 struct inode
*inode
;
1469 struct proc_inode
*ei
;
1470 struct dentry
*error
= ERR_PTR(-ENOENT
);
1472 inode
= proc_pid_make_inode(dir
->i_sb
, task
);
1477 files
= get_files_struct(task
);
1480 inode
->i_mode
= S_IFLNK
;
1483 * We are not taking a ref to the file structure, so we must
1486 spin_lock(&files
->file_lock
);
1487 file
= fcheck_files(files
, fd
);
1490 if (file
->f_mode
& 1)
1491 inode
->i_mode
|= S_IRUSR
| S_IXUSR
;
1492 if (file
->f_mode
& 2)
1493 inode
->i_mode
|= S_IWUSR
| S_IXUSR
;
1494 spin_unlock(&files
->file_lock
);
1495 put_files_struct(files
);
1497 inode
->i_op
= &proc_pid_link_inode_operations
;
1499 ei
->op
.proc_get_link
= proc_fd_link
;
1500 dentry
->d_op
= &tid_fd_dentry_operations
;
1501 d_add(dentry
, inode
);
1502 /* Close the race of the process dying before we return the dentry */
1503 if (tid_fd_revalidate(dentry
, NULL
))
1509 spin_unlock(&files
->file_lock
);
1510 put_files_struct(files
);
1516 static struct dentry
*proc_lookupfd_common(struct inode
*dir
,
1517 struct dentry
*dentry
,
1518 instantiate_t instantiate
)
1520 struct task_struct
*task
= get_proc_task(dir
);
1521 unsigned fd
= name_to_int(dentry
);
1522 struct dentry
*result
= ERR_PTR(-ENOENT
);
1529 result
= instantiate(dir
, dentry
, task
, &fd
);
1531 put_task_struct(task
);
1536 static int proc_readfd_common(struct file
* filp
, void * dirent
,
1537 filldir_t filldir
, instantiate_t instantiate
)
1539 struct dentry
*dentry
= filp
->f_path
.dentry
;
1540 struct inode
*inode
= dentry
->d_inode
;
1541 struct task_struct
*p
= get_proc_task(inode
);
1542 unsigned int fd
, ino
;
1544 struct files_struct
* files
;
1545 struct fdtable
*fdt
;
1555 if (filldir(dirent
, ".", 1, 0, inode
->i_ino
, DT_DIR
) < 0)
1559 ino
= parent_ino(dentry
);
1560 if (filldir(dirent
, "..", 2, 1, ino
, DT_DIR
) < 0)
1564 files
= get_files_struct(p
);
1568 fdt
= files_fdtable(files
);
1569 for (fd
= filp
->f_pos
-2;
1571 fd
++, filp
->f_pos
++) {
1572 char name
[PROC_NUMBUF
];
1575 if (!fcheck_files(files
, fd
))
1579 len
= snprintf(name
, sizeof(name
), "%d", fd
);
1580 if (proc_fill_cache(filp
, dirent
, filldir
,
1581 name
, len
, instantiate
,
1589 put_files_struct(files
);
1597 static struct dentry
*proc_lookupfd(struct inode
*dir
, struct dentry
*dentry
,
1598 struct nameidata
*nd
)
1600 return proc_lookupfd_common(dir
, dentry
, proc_fd_instantiate
);
1603 static int proc_readfd(struct file
*filp
, void *dirent
, filldir_t filldir
)
1605 return proc_readfd_common(filp
, dirent
, filldir
, proc_fd_instantiate
);
1608 static ssize_t
proc_fdinfo_read(struct file
*file
, char __user
*buf
,
1609 size_t len
, loff_t
*ppos
)
1611 char tmp
[PROC_FDINFO_MAX
];
1612 int err
= proc_fd_info(file
->f_path
.dentry
->d_inode
, NULL
, NULL
, tmp
);
1614 err
= simple_read_from_buffer(buf
, len
, ppos
, tmp
, strlen(tmp
));
1618 static const struct file_operations proc_fdinfo_file_operations
= {
1619 .open
= nonseekable_open
,
1620 .read
= proc_fdinfo_read
,
1623 static const struct file_operations proc_fd_operations
= {
1624 .read
= generic_read_dir
,
1625 .readdir
= proc_readfd
,
1629 * /proc/pid/fd needs a special permission handler so that a process can still
1630 * access /proc/self/fd after it has executed a setuid().
1632 static int proc_fd_permission(struct inode
*inode
, int mask
,
1633 struct nameidata
*nd
)
1637 rv
= generic_permission(inode
, mask
, NULL
);
1640 if (task_pid(current
) == proc_pid(inode
))
1646 * proc directories can do almost nothing..
1648 static const struct inode_operations proc_fd_inode_operations
= {
1649 .lookup
= proc_lookupfd
,
1650 .permission
= proc_fd_permission
,
1651 .setattr
= proc_setattr
,
1654 static struct dentry
*proc_fdinfo_instantiate(struct inode
*dir
,
1655 struct dentry
*dentry
, struct task_struct
*task
, const void *ptr
)
1657 unsigned fd
= *(unsigned *)ptr
;
1658 struct inode
*inode
;
1659 struct proc_inode
*ei
;
1660 struct dentry
*error
= ERR_PTR(-ENOENT
);
1662 inode
= proc_pid_make_inode(dir
->i_sb
, task
);
1667 inode
->i_mode
= S_IFREG
| S_IRUSR
;
1668 inode
->i_fop
= &proc_fdinfo_file_operations
;
1669 dentry
->d_op
= &tid_fd_dentry_operations
;
1670 d_add(dentry
, inode
);
1671 /* Close the race of the process dying before we return the dentry */
1672 if (tid_fd_revalidate(dentry
, NULL
))
1679 static struct dentry
*proc_lookupfdinfo(struct inode
*dir
,
1680 struct dentry
*dentry
,
1681 struct nameidata
*nd
)
1683 return proc_lookupfd_common(dir
, dentry
, proc_fdinfo_instantiate
);
1686 static int proc_readfdinfo(struct file
*filp
, void *dirent
, filldir_t filldir
)
1688 return proc_readfd_common(filp
, dirent
, filldir
,
1689 proc_fdinfo_instantiate
);
1692 static const struct file_operations proc_fdinfo_operations
= {
1693 .read
= generic_read_dir
,
1694 .readdir
= proc_readfdinfo
,
1698 * proc directories can do almost nothing..
1700 static const struct inode_operations proc_fdinfo_inode_operations
= {
1701 .lookup
= proc_lookupfdinfo
,
1702 .setattr
= proc_setattr
,
1706 static struct dentry
*proc_pident_instantiate(struct inode
*dir
,
1707 struct dentry
*dentry
, struct task_struct
*task
, const void *ptr
)
1709 const struct pid_entry
*p
= ptr
;
1710 struct inode
*inode
;
1711 struct proc_inode
*ei
;
1712 struct dentry
*error
= ERR_PTR(-EINVAL
);
1714 inode
= proc_pid_make_inode(dir
->i_sb
, task
);
1719 inode
->i_mode
= p
->mode
;
1720 if (S_ISDIR(inode
->i_mode
))
1721 inode
->i_nlink
= 2; /* Use getattr to fix if necessary */
1723 inode
->i_op
= p
->iop
;
1725 inode
->i_fop
= p
->fop
;
1727 dentry
->d_op
= &pid_dentry_operations
;
1728 d_add(dentry
, inode
);
1729 /* Close the race of the process dying before we return the dentry */
1730 if (pid_revalidate(dentry
, NULL
))
1736 static struct dentry
*proc_pident_lookup(struct inode
*dir
,
1737 struct dentry
*dentry
,
1738 const struct pid_entry
*ents
,
1741 struct inode
*inode
;
1742 struct dentry
*error
;
1743 struct task_struct
*task
= get_proc_task(dir
);
1744 const struct pid_entry
*p
, *last
;
1746 error
= ERR_PTR(-ENOENT
);
1753 * Yes, it does not scale. And it should not. Don't add
1754 * new entries into /proc/<tgid>/ without very good reasons.
1756 last
= &ents
[nents
- 1];
1757 for (p
= ents
; p
<= last
; p
++) {
1758 if (p
->len
!= dentry
->d_name
.len
)
1760 if (!memcmp(dentry
->d_name
.name
, p
->name
, p
->len
))
1766 error
= proc_pident_instantiate(dir
, dentry
, task
, p
);
1768 put_task_struct(task
);
1773 static int proc_pident_fill_cache(struct file
*filp
, void *dirent
,
1774 filldir_t filldir
, struct task_struct
*task
, const struct pid_entry
*p
)
1776 return proc_fill_cache(filp
, dirent
, filldir
, p
->name
, p
->len
,
1777 proc_pident_instantiate
, task
, p
);
1780 static int proc_pident_readdir(struct file
*filp
,
1781 void *dirent
, filldir_t filldir
,
1782 const struct pid_entry
*ents
, unsigned int nents
)
1785 struct dentry
*dentry
= filp
->f_path
.dentry
;
1786 struct inode
*inode
= dentry
->d_inode
;
1787 struct task_struct
*task
= get_proc_task(inode
);
1788 const struct pid_entry
*p
, *last
;
1801 if (filldir(dirent
, ".", 1, i
, ino
, DT_DIR
) < 0)
1807 ino
= parent_ino(dentry
);
1808 if (filldir(dirent
, "..", 2, i
, ino
, DT_DIR
) < 0)
1820 last
= &ents
[nents
- 1];
1822 if (proc_pident_fill_cache(filp
, dirent
, filldir
, task
, p
) < 0)
1831 put_task_struct(task
);
1836 #ifdef CONFIG_SECURITY
1837 static ssize_t
proc_pid_attr_read(struct file
* file
, char __user
* buf
,
1838 size_t count
, loff_t
*ppos
)
1840 struct inode
* inode
= file
->f_path
.dentry
->d_inode
;
1843 struct task_struct
*task
= get_proc_task(inode
);
1848 length
= security_getprocattr(task
,
1849 (char*)file
->f_path
.dentry
->d_name
.name
,
1851 put_task_struct(task
);
1853 length
= simple_read_from_buffer(buf
, count
, ppos
, p
, length
);
1858 static ssize_t
proc_pid_attr_write(struct file
* file
, const char __user
* buf
,
1859 size_t count
, loff_t
*ppos
)
1861 struct inode
* inode
= file
->f_path
.dentry
->d_inode
;
1864 struct task_struct
*task
= get_proc_task(inode
);
1869 if (count
> PAGE_SIZE
)
1872 /* No partial writes. */
1878 page
= (char*)__get_free_page(GFP_TEMPORARY
);
1883 if (copy_from_user(page
, buf
, count
))
1886 length
= security_setprocattr(task
,
1887 (char*)file
->f_path
.dentry
->d_name
.name
,
1888 (void*)page
, count
);
1890 free_page((unsigned long) page
);
1892 put_task_struct(task
);
1897 static const struct file_operations proc_pid_attr_operations
= {
1898 .read
= proc_pid_attr_read
,
1899 .write
= proc_pid_attr_write
,
1902 static const struct pid_entry attr_dir_stuff
[] = {
1903 REG("current", S_IRUGO
|S_IWUGO
, pid_attr
),
1904 REG("prev", S_IRUGO
, pid_attr
),
1905 REG("exec", S_IRUGO
|S_IWUGO
, pid_attr
),
1906 REG("fscreate", S_IRUGO
|S_IWUGO
, pid_attr
),
1907 REG("keycreate", S_IRUGO
|S_IWUGO
, pid_attr
),
1908 REG("sockcreate", S_IRUGO
|S_IWUGO
, pid_attr
),
1911 static int proc_attr_dir_readdir(struct file
* filp
,
1912 void * dirent
, filldir_t filldir
)
1914 return proc_pident_readdir(filp
,dirent
,filldir
,
1915 attr_dir_stuff
,ARRAY_SIZE(attr_dir_stuff
));
1918 static const struct file_operations proc_attr_dir_operations
= {
1919 .read
= generic_read_dir
,
1920 .readdir
= proc_attr_dir_readdir
,
1923 static struct dentry
*proc_attr_dir_lookup(struct inode
*dir
,
1924 struct dentry
*dentry
, struct nameidata
*nd
)
1926 return proc_pident_lookup(dir
, dentry
,
1927 attr_dir_stuff
, ARRAY_SIZE(attr_dir_stuff
));
1930 static const struct inode_operations proc_attr_dir_inode_operations
= {
1931 .lookup
= proc_attr_dir_lookup
,
1932 .getattr
= pid_getattr
,
1933 .setattr
= proc_setattr
,
1938 #if defined(USE_ELF_CORE_DUMP) && defined(CONFIG_ELF_CORE)
1939 static ssize_t
proc_coredump_filter_read(struct file
*file
, char __user
*buf
,
1940 size_t count
, loff_t
*ppos
)
1942 struct task_struct
*task
= get_proc_task(file
->f_dentry
->d_inode
);
1943 struct mm_struct
*mm
;
1944 char buffer
[PROC_NUMBUF
];
1952 mm
= get_task_mm(task
);
1954 len
= snprintf(buffer
, sizeof(buffer
), "%08lx\n",
1955 ((mm
->flags
& MMF_DUMP_FILTER_MASK
) >>
1956 MMF_DUMP_FILTER_SHIFT
));
1958 ret
= simple_read_from_buffer(buf
, count
, ppos
, buffer
, len
);
1961 put_task_struct(task
);
1966 static ssize_t
proc_coredump_filter_write(struct file
*file
,
1967 const char __user
*buf
,
1971 struct task_struct
*task
;
1972 struct mm_struct
*mm
;
1973 char buffer
[PROC_NUMBUF
], *end
;
1980 memset(buffer
, 0, sizeof(buffer
));
1981 if (count
> sizeof(buffer
) - 1)
1982 count
= sizeof(buffer
) - 1;
1983 if (copy_from_user(buffer
, buf
, count
))
1987 val
= (unsigned int)simple_strtoul(buffer
, &end
, 0);
1990 if (end
- buffer
== 0)
1994 task
= get_proc_task(file
->f_dentry
->d_inode
);
1999 mm
= get_task_mm(task
);
2003 for (i
= 0, mask
= 1; i
< MMF_DUMP_FILTER_BITS
; i
++, mask
<<= 1) {
2005 set_bit(i
+ MMF_DUMP_FILTER_SHIFT
, &mm
->flags
);
2007 clear_bit(i
+ MMF_DUMP_FILTER_SHIFT
, &mm
->flags
);
2012 put_task_struct(task
);
2017 static const struct file_operations proc_coredump_filter_operations
= {
2018 .read
= proc_coredump_filter_read
,
2019 .write
= proc_coredump_filter_write
,
2026 static int proc_self_readlink(struct dentry
*dentry
, char __user
*buffer
,
2029 char tmp
[PROC_NUMBUF
];
2030 sprintf(tmp
, "%d", task_tgid_vnr(current
));
2031 return vfs_readlink(dentry
,buffer
,buflen
,tmp
);
2034 static void *proc_self_follow_link(struct dentry
*dentry
, struct nameidata
*nd
)
2036 char tmp
[PROC_NUMBUF
];
2037 sprintf(tmp
, "%d", task_tgid_vnr(current
));
2038 return ERR_PTR(vfs_follow_link(nd
,tmp
));
2041 static const struct inode_operations proc_self_inode_operations
= {
2042 .readlink
= proc_self_readlink
,
2043 .follow_link
= proc_self_follow_link
,
2049 * These are the directory entries in the root directory of /proc
2050 * that properly belong to the /proc filesystem, as they describe
2051 * describe something that is process related.
2053 static const struct pid_entry proc_base_stuff
[] = {
2054 NOD("self", S_IFLNK
|S_IRWXUGO
,
2055 &proc_self_inode_operations
, NULL
, {}),
2059 * Exceptional case: normally we are not allowed to unhash a busy
2060 * directory. In this case, however, we can do it - no aliasing problems
2061 * due to the way we treat inodes.
2063 static int proc_base_revalidate(struct dentry
*dentry
, struct nameidata
*nd
)
2065 struct inode
*inode
= dentry
->d_inode
;
2066 struct task_struct
*task
= get_proc_task(inode
);
2068 put_task_struct(task
);
2075 static struct dentry_operations proc_base_dentry_operations
=
2077 .d_revalidate
= proc_base_revalidate
,
2078 .d_delete
= pid_delete_dentry
,
2081 static struct dentry
*proc_base_instantiate(struct inode
*dir
,
2082 struct dentry
*dentry
, struct task_struct
*task
, const void *ptr
)
2084 const struct pid_entry
*p
= ptr
;
2085 struct inode
*inode
;
2086 struct proc_inode
*ei
;
2087 struct dentry
*error
= ERR_PTR(-EINVAL
);
2089 /* Allocate the inode */
2090 error
= ERR_PTR(-ENOMEM
);
2091 inode
= new_inode(dir
->i_sb
);
2095 /* Initialize the inode */
2097 inode
->i_mtime
= inode
->i_atime
= inode
->i_ctime
= CURRENT_TIME
;
2100 * grab the reference to the task.
2102 ei
->pid
= get_task_pid(task
, PIDTYPE_PID
);
2108 inode
->i_mode
= p
->mode
;
2109 if (S_ISDIR(inode
->i_mode
))
2111 if (S_ISLNK(inode
->i_mode
))
2114 inode
->i_op
= p
->iop
;
2116 inode
->i_fop
= p
->fop
;
2118 dentry
->d_op
= &proc_base_dentry_operations
;
2119 d_add(dentry
, inode
);
2128 static struct dentry
*proc_base_lookup(struct inode
*dir
, struct dentry
*dentry
)
2130 struct dentry
*error
;
2131 struct task_struct
*task
= get_proc_task(dir
);
2132 const struct pid_entry
*p
, *last
;
2134 error
= ERR_PTR(-ENOENT
);
2139 /* Lookup the directory entry */
2140 last
= &proc_base_stuff
[ARRAY_SIZE(proc_base_stuff
) - 1];
2141 for (p
= proc_base_stuff
; p
<= last
; p
++) {
2142 if (p
->len
!= dentry
->d_name
.len
)
2144 if (!memcmp(dentry
->d_name
.name
, p
->name
, p
->len
))
2150 error
= proc_base_instantiate(dir
, dentry
, task
, p
);
2153 put_task_struct(task
);
2158 static int proc_base_fill_cache(struct file
*filp
, void *dirent
,
2159 filldir_t filldir
, struct task_struct
*task
, const struct pid_entry
*p
)
2161 return proc_fill_cache(filp
, dirent
, filldir
, p
->name
, p
->len
,
2162 proc_base_instantiate
, task
, p
);
2165 #ifdef CONFIG_TASK_IO_ACCOUNTING
2166 static int proc_pid_io_accounting(struct task_struct
*task
, char *buffer
)
2168 return sprintf(buffer
,
2169 #ifdef CONFIG_TASK_XACCT
2175 "read_bytes: %llu\n"
2176 "write_bytes: %llu\n"
2177 "cancelled_write_bytes: %llu\n",
2178 #ifdef CONFIG_TASK_XACCT
2179 (unsigned long long)task
->rchar
,
2180 (unsigned long long)task
->wchar
,
2181 (unsigned long long)task
->syscr
,
2182 (unsigned long long)task
->syscw
,
2184 (unsigned long long)task
->ioac
.read_bytes
,
2185 (unsigned long long)task
->ioac
.write_bytes
,
2186 (unsigned long long)task
->ioac
.cancelled_write_bytes
);
2193 static const struct file_operations proc_task_operations
;
2194 static const struct inode_operations proc_task_inode_operations
;
2196 static const struct pid_entry tgid_base_stuff
[] = {
2197 DIR("task", S_IRUGO
|S_IXUGO
, task
),
2198 DIR("fd", S_IRUSR
|S_IXUSR
, fd
),
2199 DIR("fdinfo", S_IRUSR
|S_IXUSR
, fdinfo
),
2200 REG("environ", S_IRUSR
, environ
),
2201 INF("auxv", S_IRUSR
, pid_auxv
),
2202 INF("status", S_IRUGO
, pid_status
),
2203 INF("limits", S_IRUSR
, pid_limits
),
2204 #ifdef CONFIG_SCHED_DEBUG
2205 REG("sched", S_IRUGO
|S_IWUSR
, pid_sched
),
2207 INF("cmdline", S_IRUGO
, pid_cmdline
),
2208 INF("stat", S_IRUGO
, tgid_stat
),
2209 INF("statm", S_IRUGO
, pid_statm
),
2210 REG("maps", S_IRUGO
, maps
),
2212 REG("numa_maps", S_IRUGO
, numa_maps
),
2214 REG("mem", S_IRUSR
|S_IWUSR
, mem
),
2218 REG("mounts", S_IRUGO
, mounts
),
2219 REG("mountstats", S_IRUSR
, mountstats
),
2221 REG("clear_refs", S_IWUSR
, clear_refs
),
2222 REG("smaps", S_IRUGO
, smaps
),
2224 #ifdef CONFIG_SECURITY
2225 DIR("attr", S_IRUGO
|S_IXUGO
, attr_dir
),
2227 #ifdef CONFIG_KALLSYMS
2228 INF("wchan", S_IRUGO
, pid_wchan
),
2230 #ifdef CONFIG_SCHEDSTATS
2231 INF("schedstat", S_IRUGO
, pid_schedstat
),
2233 #ifdef CONFIG_PROC_PID_CPUSET
2234 REG("cpuset", S_IRUGO
, cpuset
),
2236 #ifdef CONFIG_CGROUPS
2237 REG("cgroup", S_IRUGO
, cgroup
),
2239 INF("oom_score", S_IRUGO
, oom_score
),
2240 REG("oom_adj", S_IRUGO
|S_IWUSR
, oom_adjust
),
2241 #ifdef CONFIG_AUDITSYSCALL
2242 REG("loginuid", S_IWUSR
|S_IRUGO
, loginuid
),
2244 #ifdef CONFIG_FAULT_INJECTION
2245 REG("make-it-fail", S_IRUGO
|S_IWUSR
, fault_inject
),
2247 #if defined(USE_ELF_CORE_DUMP) && defined(CONFIG_ELF_CORE)
2248 REG("coredump_filter", S_IRUGO
|S_IWUSR
, coredump_filter
),
2250 #ifdef CONFIG_TASK_IO_ACCOUNTING
2251 INF("io", S_IRUGO
, pid_io_accounting
),
2255 static int proc_tgid_base_readdir(struct file
* filp
,
2256 void * dirent
, filldir_t filldir
)
2258 return proc_pident_readdir(filp
,dirent
,filldir
,
2259 tgid_base_stuff
,ARRAY_SIZE(tgid_base_stuff
));
2262 static const struct file_operations proc_tgid_base_operations
= {
2263 .read
= generic_read_dir
,
2264 .readdir
= proc_tgid_base_readdir
,
2267 static struct dentry
*proc_tgid_base_lookup(struct inode
*dir
, struct dentry
*dentry
, struct nameidata
*nd
){
2268 return proc_pident_lookup(dir
, dentry
,
2269 tgid_base_stuff
, ARRAY_SIZE(tgid_base_stuff
));
2272 static const struct inode_operations proc_tgid_base_inode_operations
= {
2273 .lookup
= proc_tgid_base_lookup
,
2274 .getattr
= pid_getattr
,
2275 .setattr
= proc_setattr
,
2278 static void proc_flush_task_mnt(struct vfsmount
*mnt
, pid_t pid
, pid_t tgid
)
2280 struct dentry
*dentry
, *leader
, *dir
;
2281 char buf
[PROC_NUMBUF
];
2285 name
.len
= snprintf(buf
, sizeof(buf
), "%d", pid
);
2286 dentry
= d_hash_and_lookup(mnt
->mnt_root
, &name
);
2288 shrink_dcache_parent(dentry
);
2297 name
.len
= snprintf(buf
, sizeof(buf
), "%d", tgid
);
2298 leader
= d_hash_and_lookup(mnt
->mnt_root
, &name
);
2303 name
.len
= strlen(name
.name
);
2304 dir
= d_hash_and_lookup(leader
, &name
);
2306 goto out_put_leader
;
2309 name
.len
= snprintf(buf
, sizeof(buf
), "%d", pid
);
2310 dentry
= d_hash_and_lookup(dir
, &name
);
2312 shrink_dcache_parent(dentry
);
2325 * proc_flush_task - Remove dcache entries for @task from the /proc dcache.
2326 * @task: task that should be flushed.
2328 * When flushing dentries from proc, one needs to flush them from global
2329 * proc (proc_mnt) and from all the namespaces' procs this task was seen
2330 * in. This call is supposed to do all of this job.
2332 * Looks in the dcache for
2334 * /proc/@tgid/task/@pid
2335 * if either directory is present flushes it and all of it'ts children
2338 * It is safe and reasonable to cache /proc entries for a task until
2339 * that task exits. After that they just clog up the dcache with
2340 * useless entries, possibly causing useful dcache entries to be
2341 * flushed instead. This routine is proved to flush those useless
2342 * dcache entries at process exit time.
2344 * NOTE: This routine is just an optimization so it does not guarantee
2345 * that no dcache entries will exist at process exit time it
2346 * just makes it very unlikely that any will persist.
2349 void proc_flush_task(struct task_struct
*task
)
2352 struct pid
*pid
, *tgid
= NULL
;
2355 pid
= task_pid(task
);
2356 if (thread_group_leader(task
))
2357 tgid
= task_tgid(task
);
2359 for (i
= 0; i
<= pid
->level
; i
++) {
2360 upid
= &pid
->numbers
[i
];
2361 proc_flush_task_mnt(upid
->ns
->proc_mnt
, upid
->nr
,
2362 tgid
? tgid
->numbers
[i
].nr
: 0);
2365 upid
= &pid
->numbers
[pid
->level
];
2367 pid_ns_release_proc(upid
->ns
);
2370 static struct dentry
*proc_pid_instantiate(struct inode
*dir
,
2371 struct dentry
* dentry
,
2372 struct task_struct
*task
, const void *ptr
)
2374 struct dentry
*error
= ERR_PTR(-ENOENT
);
2375 struct inode
*inode
;
2377 inode
= proc_pid_make_inode(dir
->i_sb
, task
);
2381 inode
->i_mode
= S_IFDIR
|S_IRUGO
|S_IXUGO
;
2382 inode
->i_op
= &proc_tgid_base_inode_operations
;
2383 inode
->i_fop
= &proc_tgid_base_operations
;
2384 inode
->i_flags
|=S_IMMUTABLE
;
2386 #ifdef CONFIG_SECURITY
2387 inode
->i_nlink
+= 1;
2390 dentry
->d_op
= &pid_dentry_operations
;
2392 d_add(dentry
, inode
);
2393 /* Close the race of the process dying before we return the dentry */
2394 if (pid_revalidate(dentry
, NULL
))
2400 struct dentry
*proc_pid_lookup(struct inode
*dir
, struct dentry
* dentry
, struct nameidata
*nd
)
2402 struct dentry
*result
= ERR_PTR(-ENOENT
);
2403 struct task_struct
*task
;
2405 struct pid_namespace
*ns
;
2407 result
= proc_base_lookup(dir
, dentry
);
2408 if (!IS_ERR(result
) || PTR_ERR(result
) != -ENOENT
)
2411 tgid
= name_to_int(dentry
);
2415 ns
= dentry
->d_sb
->s_fs_info
;
2417 task
= find_task_by_pid_ns(tgid
, ns
);
2419 get_task_struct(task
);
2424 result
= proc_pid_instantiate(dir
, dentry
, task
, NULL
);
2425 put_task_struct(task
);
2431 * Find the first task with tgid >= tgid
2436 struct task_struct
*task
;
2438 static struct tgid_iter
next_tgid(struct pid_namespace
*ns
, struct tgid_iter iter
)
2443 put_task_struct(iter
.task
);
2447 pid
= find_ge_pid(iter
.tgid
, ns
);
2449 iter
.tgid
= pid_nr_ns(pid
, ns
);
2450 iter
.task
= pid_task(pid
, PIDTYPE_PID
);
2451 /* What we to know is if the pid we have find is the
2452 * pid of a thread_group_leader. Testing for task
2453 * being a thread_group_leader is the obvious thing
2454 * todo but there is a window when it fails, due to
2455 * the pid transfer logic in de_thread.
2457 * So we perform the straight forward test of seeing
2458 * if the pid we have found is the pid of a thread
2459 * group leader, and don't worry if the task we have
2460 * found doesn't happen to be a thread group leader.
2461 * As we don't care in the case of readdir.
2463 if (!iter
.task
|| !has_group_leader_pid(iter
.task
)) {
2467 get_task_struct(iter
.task
);
2473 #define TGID_OFFSET (FIRST_PROCESS_ENTRY + ARRAY_SIZE(proc_base_stuff))
2475 static int proc_pid_fill_cache(struct file
*filp
, void *dirent
, filldir_t filldir
,
2476 struct tgid_iter iter
)
2478 char name
[PROC_NUMBUF
];
2479 int len
= snprintf(name
, sizeof(name
), "%d", iter
.tgid
);
2480 return proc_fill_cache(filp
, dirent
, filldir
, name
, len
,
2481 proc_pid_instantiate
, iter
.task
, NULL
);
2484 /* for the /proc/ directory itself, after non-process stuff has been done */
2485 int proc_pid_readdir(struct file
* filp
, void * dirent
, filldir_t filldir
)
2487 unsigned int nr
= filp
->f_pos
- FIRST_PROCESS_ENTRY
;
2488 struct task_struct
*reaper
= get_proc_task(filp
->f_path
.dentry
->d_inode
);
2489 struct tgid_iter iter
;
2490 struct pid_namespace
*ns
;
2495 for (; nr
< ARRAY_SIZE(proc_base_stuff
); filp
->f_pos
++, nr
++) {
2496 const struct pid_entry
*p
= &proc_base_stuff
[nr
];
2497 if (proc_base_fill_cache(filp
, dirent
, filldir
, reaper
, p
) < 0)
2501 ns
= filp
->f_dentry
->d_sb
->s_fs_info
;
2503 iter
.tgid
= filp
->f_pos
- TGID_OFFSET
;
2504 for (iter
= next_tgid(ns
, iter
);
2506 iter
.tgid
+= 1, iter
= next_tgid(ns
, iter
)) {
2507 filp
->f_pos
= iter
.tgid
+ TGID_OFFSET
;
2508 if (proc_pid_fill_cache(filp
, dirent
, filldir
, iter
) < 0) {
2509 put_task_struct(iter
.task
);
2513 filp
->f_pos
= PID_MAX_LIMIT
+ TGID_OFFSET
;
2515 put_task_struct(reaper
);
2523 static const struct pid_entry tid_base_stuff
[] = {
2524 DIR("fd", S_IRUSR
|S_IXUSR
, fd
),
2525 DIR("fdinfo", S_IRUSR
|S_IXUSR
, fdinfo
),
2526 REG("environ", S_IRUSR
, environ
),
2527 INF("auxv", S_IRUSR
, pid_auxv
),
2528 INF("status", S_IRUGO
, pid_status
),
2529 INF("limits", S_IRUSR
, pid_limits
),
2530 #ifdef CONFIG_SCHED_DEBUG
2531 REG("sched", S_IRUGO
|S_IWUSR
, pid_sched
),
2533 INF("cmdline", S_IRUGO
, pid_cmdline
),
2534 INF("stat", S_IRUGO
, tid_stat
),
2535 INF("statm", S_IRUGO
, pid_statm
),
2536 REG("maps", S_IRUGO
, maps
),
2538 REG("numa_maps", S_IRUGO
, numa_maps
),
2540 REG("mem", S_IRUSR
|S_IWUSR
, mem
),
2544 REG("mounts", S_IRUGO
, mounts
),
2546 REG("clear_refs", S_IWUSR
, clear_refs
),
2547 REG("smaps", S_IRUGO
, smaps
),
2549 #ifdef CONFIG_SECURITY
2550 DIR("attr", S_IRUGO
|S_IXUGO
, attr_dir
),
2552 #ifdef CONFIG_KALLSYMS
2553 INF("wchan", S_IRUGO
, pid_wchan
),
2555 #ifdef CONFIG_SCHEDSTATS
2556 INF("schedstat", S_IRUGO
, pid_schedstat
),
2558 #ifdef CONFIG_PROC_PID_CPUSET
2559 REG("cpuset", S_IRUGO
, cpuset
),
2561 #ifdef CONFIG_CGROUPS
2562 REG("cgroup", S_IRUGO
, cgroup
),
2564 INF("oom_score", S_IRUGO
, oom_score
),
2565 REG("oom_adj", S_IRUGO
|S_IWUSR
, oom_adjust
),
2566 #ifdef CONFIG_AUDITSYSCALL
2567 REG("loginuid", S_IWUSR
|S_IRUGO
, loginuid
),
2569 #ifdef CONFIG_FAULT_INJECTION
2570 REG("make-it-fail", S_IRUGO
|S_IWUSR
, fault_inject
),
2574 static int proc_tid_base_readdir(struct file
* filp
,
2575 void * dirent
, filldir_t filldir
)
2577 return proc_pident_readdir(filp
,dirent
,filldir
,
2578 tid_base_stuff
,ARRAY_SIZE(tid_base_stuff
));
2581 static struct dentry
*proc_tid_base_lookup(struct inode
*dir
, struct dentry
*dentry
, struct nameidata
*nd
){
2582 return proc_pident_lookup(dir
, dentry
,
2583 tid_base_stuff
, ARRAY_SIZE(tid_base_stuff
));
2586 static const struct file_operations proc_tid_base_operations
= {
2587 .read
= generic_read_dir
,
2588 .readdir
= proc_tid_base_readdir
,
2591 static const struct inode_operations proc_tid_base_inode_operations
= {
2592 .lookup
= proc_tid_base_lookup
,
2593 .getattr
= pid_getattr
,
2594 .setattr
= proc_setattr
,
2597 static struct dentry
*proc_task_instantiate(struct inode
*dir
,
2598 struct dentry
*dentry
, struct task_struct
*task
, const void *ptr
)
2600 struct dentry
*error
= ERR_PTR(-ENOENT
);
2601 struct inode
*inode
;
2602 inode
= proc_pid_make_inode(dir
->i_sb
, task
);
2606 inode
->i_mode
= S_IFDIR
|S_IRUGO
|S_IXUGO
;
2607 inode
->i_op
= &proc_tid_base_inode_operations
;
2608 inode
->i_fop
= &proc_tid_base_operations
;
2609 inode
->i_flags
|=S_IMMUTABLE
;
2611 #ifdef CONFIG_SECURITY
2612 inode
->i_nlink
+= 1;
2615 dentry
->d_op
= &pid_dentry_operations
;
2617 d_add(dentry
, inode
);
2618 /* Close the race of the process dying before we return the dentry */
2619 if (pid_revalidate(dentry
, NULL
))
2625 static struct dentry
*proc_task_lookup(struct inode
*dir
, struct dentry
* dentry
, struct nameidata
*nd
)
2627 struct dentry
*result
= ERR_PTR(-ENOENT
);
2628 struct task_struct
*task
;
2629 struct task_struct
*leader
= get_proc_task(dir
);
2631 struct pid_namespace
*ns
;
2636 tid
= name_to_int(dentry
);
2640 ns
= dentry
->d_sb
->s_fs_info
;
2642 task
= find_task_by_pid_ns(tid
, ns
);
2644 get_task_struct(task
);
2648 if (!same_thread_group(leader
, task
))
2651 result
= proc_task_instantiate(dir
, dentry
, task
, NULL
);
2653 put_task_struct(task
);
2655 put_task_struct(leader
);
2661 * Find the first tid of a thread group to return to user space.
2663 * Usually this is just the thread group leader, but if the users
2664 * buffer was too small or there was a seek into the middle of the
2665 * directory we have more work todo.
2667 * In the case of a short read we start with find_task_by_pid.
2669 * In the case of a seek we start with the leader and walk nr
2672 static struct task_struct
*first_tid(struct task_struct
*leader
,
2673 int tid
, int nr
, struct pid_namespace
*ns
)
2675 struct task_struct
*pos
;
2678 /* Attempt to start with the pid of a thread */
2679 if (tid
&& (nr
> 0)) {
2680 pos
= find_task_by_pid_ns(tid
, ns
);
2681 if (pos
&& (pos
->group_leader
== leader
))
2685 /* If nr exceeds the number of threads there is nothing todo */
2687 if (nr
&& nr
>= get_nr_threads(leader
))
2690 /* If we haven't found our starting place yet start
2691 * with the leader and walk nr threads forward.
2693 for (pos
= leader
; nr
> 0; --nr
) {
2694 pos
= next_thread(pos
);
2695 if (pos
== leader
) {
2701 get_task_struct(pos
);
2708 * Find the next thread in the thread list.
2709 * Return NULL if there is an error or no next thread.
2711 * The reference to the input task_struct is released.
2713 static struct task_struct
*next_tid(struct task_struct
*start
)
2715 struct task_struct
*pos
= NULL
;
2717 if (pid_alive(start
)) {
2718 pos
= next_thread(start
);
2719 if (thread_group_leader(pos
))
2722 get_task_struct(pos
);
2725 put_task_struct(start
);
2729 static int proc_task_fill_cache(struct file
*filp
, void *dirent
, filldir_t filldir
,
2730 struct task_struct
*task
, int tid
)
2732 char name
[PROC_NUMBUF
];
2733 int len
= snprintf(name
, sizeof(name
), "%d", tid
);
2734 return proc_fill_cache(filp
, dirent
, filldir
, name
, len
,
2735 proc_task_instantiate
, task
, NULL
);
2738 /* for the /proc/TGID/task/ directories */
2739 static int proc_task_readdir(struct file
* filp
, void * dirent
, filldir_t filldir
)
2741 struct dentry
*dentry
= filp
->f_path
.dentry
;
2742 struct inode
*inode
= dentry
->d_inode
;
2743 struct task_struct
*leader
= NULL
;
2744 struct task_struct
*task
;
2745 int retval
= -ENOENT
;
2748 unsigned long pos
= filp
->f_pos
; /* avoiding "long long" filp->f_pos */
2749 struct pid_namespace
*ns
;
2751 task
= get_proc_task(inode
);
2755 if (pid_alive(task
)) {
2756 leader
= task
->group_leader
;
2757 get_task_struct(leader
);
2760 put_task_struct(task
);
2768 if (filldir(dirent
, ".", 1, pos
, ino
, DT_DIR
) < 0)
2773 ino
= parent_ino(dentry
);
2774 if (filldir(dirent
, "..", 2, pos
, ino
, DT_DIR
) < 0)
2780 /* f_version caches the tgid value that the last readdir call couldn't
2781 * return. lseek aka telldir automagically resets f_version to 0.
2783 ns
= filp
->f_dentry
->d_sb
->s_fs_info
;
2784 tid
= (int)filp
->f_version
;
2785 filp
->f_version
= 0;
2786 for (task
= first_tid(leader
, tid
, pos
- 2, ns
);
2788 task
= next_tid(task
), pos
++) {
2789 tid
= task_pid_nr_ns(task
, ns
);
2790 if (proc_task_fill_cache(filp
, dirent
, filldir
, task
, tid
) < 0) {
2791 /* returning this tgid failed, save it as the first
2792 * pid for the next readir call */
2793 filp
->f_version
= (u64
)tid
;
2794 put_task_struct(task
);
2800 put_task_struct(leader
);
2805 static int proc_task_getattr(struct vfsmount
*mnt
, struct dentry
*dentry
, struct kstat
*stat
)
2807 struct inode
*inode
= dentry
->d_inode
;
2808 struct task_struct
*p
= get_proc_task(inode
);
2809 generic_fillattr(inode
, stat
);
2813 stat
->nlink
+= get_nr_threads(p
);
2821 static const struct inode_operations proc_task_inode_operations
= {
2822 .lookup
= proc_task_lookup
,
2823 .getattr
= proc_task_getattr
,
2824 .setattr
= proc_setattr
,
2827 static const struct file_operations proc_task_operations
= {
2828 .read
= generic_read_dir
,
2829 .readdir
= proc_task_readdir
,