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.
16 #include <asm/uaccess.h>
18 #include <linux/config.h>
19 #include <linux/errno.h>
20 #include <linux/sched.h>
21 #include <linux/proc_fs.h>
22 #include <linux/stat.h>
23 #include <linux/init.h>
24 #include <linux/file.h>
25 #include <linux/string.h>
28 * For hysterical raisins we keep the same inumbers as in the old procfs.
29 * Feel free to change the macro below - just keep the range distinct from
30 * inumbers of the rest of procfs (currently those are in 0x0000--0xffff).
31 * As soon as we'll get a separate superblock we will be able to forget
32 * about magical ranges too.
35 #define fake_ino(pid,ino) (((pid)<<16)|(ino))
37 ssize_t
proc_pid_read_maps(struct task_struct
*,struct file
*,char*,size_t,loff_t
*);
38 int proc_pid_stat(struct task_struct
*,char*);
39 int proc_pid_status(struct task_struct
*,char*);
40 int proc_pid_statm(struct task_struct
*,char*);
41 int proc_pid_cpu(struct task_struct
*,char*);
43 static int proc_fd_link(struct inode
*inode
, struct dentry
**dentry
, struct vfsmount
**mnt
)
45 if (inode
->u
.proc_i
.file
) {
46 *mnt
= mntget(inode
->u
.proc_i
.file
->f_vfsmnt
);
47 *dentry
= dget(inode
->u
.proc_i
.file
->f_dentry
);
53 static int proc_exe_link(struct inode
*inode
, struct dentry
**dentry
, struct vfsmount
**mnt
)
55 struct mm_struct
* mm
;
56 struct vm_area_struct
* vma
;
58 struct task_struct
*task
= inode
->u
.proc_i
.task
;
63 atomic_inc(&mm
->mm_users
);
70 if ((vma
->vm_flags
& VM_EXECUTABLE
) &&
72 *mnt
= mntget(vma
->vm_file
->f_vfsmnt
);
73 *dentry
= dget(vma
->vm_file
->f_dentry
);
85 static int proc_cwd_link(struct inode
*inode
, struct dentry
**dentry
, struct vfsmount
**mnt
)
89 task_lock(inode
->u
.proc_i
.task
);
90 fs
= inode
->u
.proc_i
.task
->fs
;
92 atomic_inc(&fs
->count
);
93 task_unlock(inode
->u
.proc_i
.task
);
96 *mnt
= mntget(fs
->pwdmnt
);
97 *dentry
= dget(fs
->pwd
);
98 read_unlock(&fs
->lock
);
105 static int proc_root_link(struct inode
*inode
, struct dentry
**dentry
, struct vfsmount
**mnt
)
107 struct fs_struct
*fs
;
108 int result
= -ENOENT
;
109 task_lock(inode
->u
.proc_i
.task
);
110 fs
= inode
->u
.proc_i
.task
->fs
;
112 atomic_inc(&fs
->count
);
113 task_unlock(inode
->u
.proc_i
.task
);
115 read_lock(&fs
->lock
);
116 *mnt
= mntget(fs
->rootmnt
);
117 *dentry
= dget(fs
->root
);
118 read_unlock(&fs
->lock
);
125 static int proc_pid_environ(struct task_struct
*task
, char * buffer
)
127 struct mm_struct
*mm
;
132 atomic_inc(&mm
->mm_users
);
135 int len
= mm
->env_end
- mm
->env_start
;
138 res
= access_process_vm(task
, mm
->env_start
, buffer
, len
, 0);
144 static int proc_pid_cmdline(struct task_struct
*task
, char * buffer
)
146 struct mm_struct
*mm
;
151 atomic_inc(&mm
->mm_users
);
154 int len
= mm
->arg_end
- mm
->arg_start
;
157 res
= access_process_vm(task
, mm
->arg_start
, buffer
, len
, 0);
158 // If the nul at the end of args has been overwritten, then
159 // assume application is using setproctitle(3).
160 if ( res
> 0 && buffer
[res
-1] != '\0' )
162 len
= strnlen( buffer
, res
);
169 len
= mm
->env_end
- mm
->env_start
;
170 if (len
> PAGE_SIZE
- res
)
171 len
= PAGE_SIZE
- res
;
172 res
+= access_process_vm(task
, mm
->env_start
, buffer
+res
, len
, 0);
173 res
= strnlen( buffer
, res
);
181 /************************************************************************/
182 /* Here the fs part begins */
183 /************************************************************************/
185 /* permission checks */
187 static int standard_permission(struct inode
*inode
, int mask
)
189 int mode
= inode
->i_mode
;
191 if ((mask
& S_IWOTH
) && IS_RDONLY(inode
) &&
192 (S_ISREG(mode
) || S_ISDIR(mode
) || S_ISLNK(mode
)))
193 return -EROFS
; /* Nobody gets write access to a read-only fs */
194 else if ((mask
& S_IWOTH
) && IS_IMMUTABLE(inode
))
195 return -EACCES
; /* Nobody gets write access to an immutable file */
196 else if (current
->fsuid
== inode
->i_uid
)
198 else if (in_group_p(inode
->i_gid
))
200 if (((mode
& mask
& S_IRWXO
) == mask
) || capable(CAP_DAC_OVERRIDE
))
202 /* read and search access */
203 if ((mask
== S_IROTH
) ||
204 (S_ISDIR(mode
) && !(mask
& ~(S_IROTH
| S_IXOTH
))))
205 if (capable(CAP_DAC_READ_SEARCH
))
210 static int proc_check_root(struct inode
*inode
)
212 struct dentry
*de
, *base
, *root
;
213 struct vfsmount
*our_vfsmnt
, *vfsmnt
, *mnt
;
216 if (proc_root_link(inode
, &root
, &vfsmnt
)) /* Ewww... */
218 read_lock(¤t
->fs
->lock
);
219 our_vfsmnt
= mntget(current
->fs
->rootmnt
);
220 base
= dget(current
->fs
->root
);
221 read_unlock(¤t
->fs
->lock
);
223 spin_lock(&dcache_lock
);
227 while (vfsmnt
!= our_vfsmnt
) {
228 if (vfsmnt
== vfsmnt
->mnt_parent
)
230 de
= vfsmnt
->mnt_mountpoint
;
231 vfsmnt
= vfsmnt
->mnt_parent
;
234 if (!is_subdir(de
, base
))
236 spin_unlock(&dcache_lock
);
245 spin_unlock(&dcache_lock
);
250 static int proc_permission(struct inode
*inode
, int mask
)
252 if (standard_permission(inode
, mask
) != 0)
254 return proc_check_root(inode
);
257 static ssize_t
pid_maps_read(struct file
* file
, char * buf
,
258 size_t count
, loff_t
*ppos
)
260 struct inode
* inode
= file
->f_dentry
->d_inode
;
261 struct task_struct
*task
= inode
->u
.proc_i
.task
;
264 res
= proc_pid_read_maps(task
, file
, buf
, count
, ppos
);
268 static struct file_operations proc_maps_operations
= {
272 #define PROC_BLOCK_SIZE (3*1024) /* 4K page size but our output routines use some slack for overruns */
274 static ssize_t
proc_info_read(struct file
* file
, char * buf
,
275 size_t count
, loff_t
*ppos
)
277 struct inode
* inode
= file
->f_dentry
->d_inode
;
281 struct task_struct
*task
= inode
->u
.proc_i
.task
;
283 if (count
> PROC_BLOCK_SIZE
)
284 count
= PROC_BLOCK_SIZE
;
285 if (!(page
= __get_free_page(GFP_KERNEL
)))
288 length
= inode
->u
.proc_i
.op
.proc_read(task
, (char*)page
);
294 /* Static 4kB (or whatever) block capacity */
295 if (*ppos
>= length
) {
299 if (count
+ *ppos
> length
)
300 count
= length
- *ppos
;
302 copy_to_user(buf
, (char *) page
+ *ppos
, count
);
308 static struct file_operations proc_info_file_operations
= {
309 read
: proc_info_read
,
312 #define MAY_PTRACE(p) \
313 (p==current||(p->p_pptr==current&&(p->ptrace & PT_PTRACED)&&p->state==TASK_STOPPED))
315 static ssize_t
mem_read(struct file
* file
, char * buf
,
316 size_t count
, loff_t
*ppos
)
318 struct task_struct
*task
= file
->f_dentry
->d_inode
->u
.proc_i
.task
;
320 unsigned long src
= *ppos
;
323 if (!MAY_PTRACE(task
))
326 page
= (char *)__get_free_page(GFP_USER
);
331 int this_len
, retval
;
333 this_len
= (count
> PAGE_SIZE
) ? PAGE_SIZE
: count
;
334 retval
= access_process_vm(task
, src
, page
, this_len
, 0);
340 if (copy_to_user(buf
, page
, retval
)) {
350 free_page((unsigned long) page
);
354 #define mem_write NULL
357 /* This is a security hazard */
358 static ssize_t
mem_write(struct file
* file
, const char * buf
,
359 size_t count
, loff_t
*ppos
)
363 struct task_struct
*task
= file
->f_dentry
->d_inode
->u
.proc_i
.task
;
364 unsigned long dst
= *ppos
;
366 if (!MAY_PTRACE(task
))
369 page
= (char *)__get_free_page(GFP_USER
);
374 int this_len
, retval
;
376 this_len
= (count
> PAGE_SIZE
) ? PAGE_SIZE
: count
;
377 if (copy_from_user(page
, buf
, this_len
)) {
381 retval
= access_process_vm(task
, dst
, page
, this_len
, 1);
393 free_page((unsigned long) page
);
398 static struct file_operations proc_mem_operations
= {
403 static struct inode_operations proc_mem_inode_operations
= {
404 permission
: proc_permission
,
407 static int proc_pid_follow_link(struct dentry
*dentry
, struct nameidata
*nd
)
409 struct inode
*inode
= dentry
->d_inode
;
412 /* We don't need a base pointer in the /proc filesystem */
415 if (current
->fsuid
!= inode
->i_uid
&& !capable(CAP_DAC_OVERRIDE
))
417 error
= proc_check_root(inode
);
421 error
= inode
->u
.proc_i
.op
.proc_get_link(inode
, &nd
->dentry
, &nd
->mnt
);
422 nd
->last_type
= LAST_BIND
;
427 static int do_proc_readlink(struct dentry
*dentry
, struct vfsmount
*mnt
,
428 char * buffer
, int buflen
)
430 struct inode
* inode
;
431 char * tmp
= (char*)__get_free_page(GFP_KERNEL
), *path
;
437 inode
= dentry
->d_inode
;
438 path
= d_path(dentry
, mnt
, tmp
, PAGE_SIZE
);
439 len
= tmp
+ PAGE_SIZE
- 1 - path
;
443 copy_to_user(buffer
, path
, buflen
);
444 free_page((unsigned long)tmp
);
448 static int proc_pid_readlink(struct dentry
* dentry
, char * buffer
, int buflen
)
451 struct inode
*inode
= dentry
->d_inode
;
453 struct vfsmount
*mnt
= NULL
;
455 if (current
->fsuid
!= inode
->i_uid
&& !capable(CAP_DAC_OVERRIDE
))
457 error
= proc_check_root(inode
);
461 error
= inode
->u
.proc_i
.op
.proc_get_link(inode
, &de
, &mnt
);
465 error
= do_proc_readlink(de
, mnt
, buffer
, buflen
);
472 static struct inode_operations proc_pid_link_inode_operations
= {
473 readlink
: proc_pid_readlink
,
474 follow_link
: proc_pid_follow_link
484 enum pid_directory_inos
{
498 PROC_PID_FD_DIR
= 0x8000, /* 0x8000-0xffff */
501 #define E(type,name,mode) {(type),sizeof(name)-1,(name),(mode)}
502 static struct pid_entry base_stuff
[] = {
503 E(PROC_PID_FD
, "fd", S_IFDIR
|S_IRUSR
|S_IXUSR
),
504 E(PROC_PID_ENVIRON
, "environ", S_IFREG
|S_IRUSR
),
505 E(PROC_PID_STATUS
, "status", S_IFREG
|S_IRUGO
),
506 E(PROC_PID_CMDLINE
, "cmdline", S_IFREG
|S_IRUGO
),
507 E(PROC_PID_STAT
, "stat", S_IFREG
|S_IRUGO
),
508 E(PROC_PID_STATM
, "statm", S_IFREG
|S_IRUGO
),
510 E(PROC_PID_CPU
, "cpu", S_IFREG
|S_IRUGO
),
512 E(PROC_PID_MAPS
, "maps", S_IFREG
|S_IRUGO
),
513 E(PROC_PID_MEM
, "mem", S_IFREG
|S_IRUSR
|S_IWUSR
),
514 E(PROC_PID_CWD
, "cwd", S_IFLNK
|S_IRWXUGO
),
515 E(PROC_PID_ROOT
, "root", S_IFLNK
|S_IRWXUGO
),
516 E(PROC_PID_EXE
, "exe", S_IFLNK
|S_IRWXUGO
),
523 static int proc_readfd(struct file
* filp
, void * dirent
, filldir_t filldir
)
525 struct inode
*inode
= filp
->f_dentry
->d_inode
;
526 struct task_struct
*p
= inode
->u
.proc_i
.task
;
527 unsigned int fd
, pid
, ino
;
530 struct files_struct
* files
;
538 if (filldir(dirent
, ".", 1, 0, inode
->i_ino
, DT_DIR
) < 0)
542 ino
= fake_ino(pid
, PROC_PID_INO
);
543 if (filldir(dirent
, "..", 2, 1, ino
, DT_DIR
) < 0)
550 atomic_inc(&files
->count
);
554 for (fd
= filp
->f_pos
-2;
556 fd
++, filp
->f_pos
++) {
559 if (!fcheck_files(files
, fd
))
566 buf
[j
] = '0' + (i
% 10);
570 ino
= fake_ino(pid
, PROC_PID_FD_DIR
+ fd
);
571 if (filldir(dirent
, buf
+j
, NUMBUF
-j
, fd
+2, ino
, DT_LNK
) < 0)
574 put_files_struct(files
);
580 static int proc_base_readdir(struct file
* filp
,
581 void * dirent
, filldir_t filldir
)
585 struct inode
*inode
= filp
->f_dentry
->d_inode
;
588 pid
= inode
->u
.proc_i
.task
->pid
;
589 if (!inode
->u
.proc_i
.task
->p_pptr
)
594 if (filldir(dirent
, ".", 1, i
, inode
->i_ino
, DT_DIR
) < 0)
600 if (filldir(dirent
, "..", 2, i
, PROC_ROOT_INO
, DT_DIR
) < 0)
607 if (i
>=sizeof(base_stuff
)/sizeof(base_stuff
[0]))
611 if (filldir(dirent
, p
->name
, p
->len
, filp
->f_pos
,
612 fake_ino(pid
, p
->type
), p
->mode
>> 12) < 0)
621 /* building an inode */
623 static struct inode
*proc_pid_make_inode(struct super_block
* sb
, struct task_struct
*task
, int ino
)
625 struct inode
* inode
;
627 /* We need a new inode */
629 inode
= new_inode(sb
);
635 inode
->i_mtime
= inode
->i_atime
= inode
->i_ctime
= CURRENT_TIME
;
636 inode
->i_ino
= fake_ino(task
->pid
, ino
);
638 inode
->u
.proc_i
.file
= NULL
;
640 * grab the reference to task.
642 inode
->u
.proc_i
.task
= task
;
643 get_task_struct(task
);
649 if (ino
== PROC_PID_INO
|| task
->dumpable
) {
650 inode
->i_uid
= task
->euid
;
651 inode
->i_gid
= task
->egid
;
664 static int pid_fd_revalidate(struct dentry
* dentry
, int flags
)
670 * Exceptional case: normally we are not allowed to unhash a busy
671 * directory. In this case, however, we can do it - no aliasing problems
672 * due to the way we treat inodes.
674 static int pid_base_revalidate(struct dentry
* dentry
, int flags
)
676 if (dentry
->d_inode
->u
.proc_i
.task
->p_pptr
)
682 static int pid_delete_dentry(struct dentry
* dentry
)
687 static struct dentry_operations pid_fd_dentry_operations
=
689 d_revalidate
: pid_fd_revalidate
,
690 d_delete
: pid_delete_dentry
,
693 static struct dentry_operations pid_dentry_operations
=
695 d_delete
: pid_delete_dentry
,
698 static struct dentry_operations pid_base_dentry_operations
=
700 d_revalidate
: pid_base_revalidate
,
701 d_delete
: pid_delete_dentry
,
705 #define MAX_MULBY10 ((~0U-9)/10)
707 static struct dentry
*proc_lookupfd(struct inode
* dir
, struct dentry
* dentry
)
710 struct task_struct
*task
= dir
->u
.proc_i
.task
;
712 struct files_struct
* files
;
718 len
= dentry
->d_name
.len
;
719 name
= dentry
->d_name
.name
;
720 if (len
> 1 && *name
== '0') goto out
;
726 if (fd
>= MAX_MULBY10
)
732 inode
= proc_pid_make_inode(dir
->i_sb
, task
, PROC_PID_FD_DIR
+fd
);
738 atomic_inc(&files
->count
);
742 read_lock(&files
->file_lock
);
743 file
= inode
->u
.proc_i
.file
= fcheck_files(files
, fd
);
747 read_unlock(&files
->file_lock
);
748 put_files_struct(files
);
749 inode
->i_op
= &proc_pid_link_inode_operations
;
751 inode
->i_mode
= S_IFLNK
;
752 inode
->u
.proc_i
.op
.proc_get_link
= proc_fd_link
;
753 if (file
->f_mode
& 1)
754 inode
->i_mode
|= S_IRUSR
| S_IXUSR
;
755 if (file
->f_mode
& 2)
756 inode
->i_mode
|= S_IWUSR
| S_IXUSR
;
757 dentry
->d_op
= &pid_fd_dentry_operations
;
758 d_add(dentry
, inode
);
762 put_files_struct(files
);
763 read_unlock(&files
->file_lock
);
767 return ERR_PTR(-ENOENT
);
770 static struct file_operations proc_fd_operations
= {
771 read
: generic_read_dir
,
772 readdir
: proc_readfd
,
776 * proc directories can do almost nothing..
778 static struct inode_operations proc_fd_inode_operations
= {
779 lookup
: proc_lookupfd
,
780 permission
: proc_permission
,
783 static struct dentry
*proc_base_lookup(struct inode
*dir
, struct dentry
*dentry
)
787 struct task_struct
*task
= dir
->u
.proc_i
.task
;
793 for (p
= base_stuff
; p
->name
; p
++) {
794 if (p
->len
!= dentry
->d_name
.len
)
796 if (!memcmp(dentry
->d_name
.name
, p
->name
, p
->len
))
803 inode
= proc_pid_make_inode(dir
->i_sb
, task
, p
->type
);
807 inode
->i_mode
= p
->mode
;
809 * Yes, it does not scale. And it should not. Don't add
810 * new entries into /proc/<pid>/ without very good reasons.
815 inode
->i_op
= &proc_fd_inode_operations
;
816 inode
->i_fop
= &proc_fd_operations
;
819 inode
->i_op
= &proc_pid_link_inode_operations
;
820 inode
->u
.proc_i
.op
.proc_get_link
= proc_exe_link
;
823 inode
->i_op
= &proc_pid_link_inode_operations
;
824 inode
->u
.proc_i
.op
.proc_get_link
= proc_cwd_link
;
827 inode
->i_op
= &proc_pid_link_inode_operations
;
828 inode
->u
.proc_i
.op
.proc_get_link
= proc_root_link
;
830 case PROC_PID_ENVIRON
:
831 inode
->i_fop
= &proc_info_file_operations
;
832 inode
->u
.proc_i
.op
.proc_read
= proc_pid_environ
;
834 case PROC_PID_STATUS
:
835 inode
->i_fop
= &proc_info_file_operations
;
836 inode
->u
.proc_i
.op
.proc_read
= proc_pid_status
;
839 inode
->i_fop
= &proc_info_file_operations
;
840 inode
->u
.proc_i
.op
.proc_read
= proc_pid_stat
;
842 case PROC_PID_CMDLINE
:
843 inode
->i_fop
= &proc_info_file_operations
;
844 inode
->u
.proc_i
.op
.proc_read
= proc_pid_cmdline
;
847 inode
->i_fop
= &proc_info_file_operations
;
848 inode
->u
.proc_i
.op
.proc_read
= proc_pid_statm
;
851 inode
->i_fop
= &proc_maps_operations
;
855 inode
->i_fop
= &proc_info_file_operations
;
856 inode
->u
.proc_i
.op
.proc_read
= proc_pid_cpu
;
860 inode
->i_op
= &proc_mem_inode_operations
;
861 inode
->i_fop
= &proc_mem_operations
;
864 printk("procfs: impossible type (%d)",p
->type
);
866 return ERR_PTR(-EINVAL
);
868 dentry
->d_op
= &pid_dentry_operations
;
869 d_add(dentry
, inode
);
873 return ERR_PTR(error
);
876 static struct file_operations proc_base_operations
= {
877 read
: generic_read_dir
,
878 readdir
: proc_base_readdir
,
881 static struct inode_operations proc_base_inode_operations
= {
882 lookup
: proc_base_lookup
,
888 static int proc_self_readlink(struct dentry
*dentry
, char *buffer
, int buflen
)
891 sprintf(tmp
, "%d", current
->pid
);
892 return vfs_readlink(dentry
,buffer
,buflen
,tmp
);
895 static int proc_self_follow_link(struct dentry
*dentry
, struct nameidata
*nd
)
898 sprintf(tmp
, "%d", current
->pid
);
899 return vfs_follow_link(nd
,tmp
);
902 static struct inode_operations proc_self_inode_operations
= {
903 readlink
: proc_self_readlink
,
904 follow_link
: proc_self_follow_link
,
907 struct dentry
*proc_pid_lookup(struct inode
*dir
, struct dentry
* dentry
)
910 struct task_struct
*task
;
916 name
= dentry
->d_name
.name
;
917 len
= dentry
->d_name
.len
;
918 if (len
== 4 && !memcmp(name
, "self", 4)) {
919 inode
= new_inode(dir
->i_sb
);
921 return ERR_PTR(-ENOMEM
);
922 inode
->i_mtime
= inode
->i_atime
= inode
->i_ctime
= CURRENT_TIME
;
923 inode
->i_ino
= fake_ino(0, PROC_PID_INO
);
924 inode
->u
.proc_i
.file
= NULL
;
925 inode
->u
.proc_i
.task
= NULL
;
926 inode
->i_mode
= S_IFLNK
|S_IRWXUGO
;
927 inode
->i_uid
= inode
->i_gid
= 0;
929 inode
->i_op
= &proc_self_inode_operations
;
930 d_add(dentry
, inode
);
938 if (pid
>= MAX_MULBY10
)
946 read_lock(&tasklist_lock
);
947 task
= find_task_by_pid(pid
);
949 get_task_struct(task
);
950 read_unlock(&tasklist_lock
);
954 inode
= proc_pid_make_inode(dir
->i_sb
, task
, PROC_PID_INO
);
956 free_task_struct(task
);
960 inode
->i_mode
= S_IFDIR
|S_IRUGO
|S_IXUGO
;
961 inode
->i_op
= &proc_base_inode_operations
;
962 inode
->i_fop
= &proc_base_operations
;
964 inode
->i_flags
|=S_IMMUTABLE
;
966 dentry
->d_op
= &pid_base_dentry_operations
;
967 d_add(dentry
, inode
);
970 return ERR_PTR(-ENOENT
);
973 void proc_pid_delete_inode(struct inode
*inode
)
975 if (inode
->u
.proc_i
.file
)
976 fput(inode
->u
.proc_i
.file
);
977 if (inode
->u
.proc_i
.task
)
978 free_task_struct(inode
->u
.proc_i
.task
);
981 #define PROC_NUMBUF 10
982 #define PROC_MAXPIDS 20
985 * Get a few pid's to return for filldir - we need to hold the
986 * tasklist lock while doing this, and we must release it before
987 * we actually do the filldir itself, so we use a temp buffer..
989 static int get_pid_list(int index
, unsigned int *pids
)
991 struct task_struct
*p
;
995 read_lock(&tasklist_lock
);
1002 pids
[nr_pids
] = pid
;
1004 if (nr_pids
>= PROC_MAXPIDS
)
1007 read_unlock(&tasklist_lock
);
1011 int proc_pid_readdir(struct file
* filp
, void * dirent
, filldir_t filldir
)
1013 unsigned int pid_array
[PROC_MAXPIDS
];
1014 char buf
[PROC_NUMBUF
];
1015 unsigned int nr
= filp
->f_pos
- FIRST_PROCESS_ENTRY
;
1016 unsigned int nr_pids
, i
;
1019 ino_t ino
= fake_ino(0,PROC_PID_INO
);
1020 if (filldir(dirent
, "self", 4, filp
->f_pos
, ino
, DT_LNK
) < 0)
1026 nr_pids
= get_pid_list(nr
, pid_array
);
1028 for (i
= 0; i
< nr_pids
; i
++) {
1029 int pid
= pid_array
[i
];
1030 ino_t ino
= fake_ino(pid
,PROC_PID_INO
);
1031 unsigned long j
= PROC_NUMBUF
;
1033 do buf
[--j
] = '0' + (pid
% 10); while (pid
/=10);
1035 if (filldir(dirent
, buf
+j
, PROC_NUMBUF
-j
, filp
->f_pos
, ino
, DT_DIR
) < 0)