Import 2.3.26pre2
[davej-history.git] / fs / proc / root.c
blob082b419fdc392d625c9924d195a8fc0a97643bb1
1 /*
2 * linux/fs/proc/root.c
4 * Copyright (C) 1991, 1992 Linus Torvalds
6 * proc root directory handling functions
7 */
9 #include <asm/uaccess.h>
11 #include <linux/errno.h>
12 #include <linux/sched.h>
13 #include <linux/proc_fs.h>
14 #include <linux/stat.h>
15 #include <linux/config.h>
16 #include <linux/init.h>
17 #include <asm/bitops.h>
18 #ifdef CONFIG_KMOD
19 #include <linux/kmod.h>
20 #endif
21 #ifdef CONFIG_ZORRO
22 #include <linux/zorro.h>
23 #endif
26 * Offset of the first process in the /proc root directory..
28 #define FIRST_PROCESS_ENTRY 256
30 static int proc_root_readdir(struct file *, void *, filldir_t);
31 static struct dentry *proc_root_lookup(struct inode *,struct dentry *);
32 static int proc_unlink(struct inode *, struct dentry *);
34 static unsigned char proc_alloc_map[PROC_NDYNAMIC / 8] = {0};
37 * These are the generic /proc directory operations. They
38 * use the in-memory "struct proc_dir_entry" tree to parse
39 * the /proc directory.
41 * NOTE! The /proc/scsi directory currently does not correctly
42 * build up the proc_dir_entry tree, and will show up empty.
44 static struct file_operations proc_dir_operations = {
45 NULL, /* lseek - default */
46 NULL, /* read - bad */
47 NULL, /* write - bad */
48 proc_readdir, /* readdir */
49 NULL, /* poll - default */
50 NULL, /* ioctl - default */
51 NULL, /* mmap */
52 NULL, /* no special open code */
53 NULL, /* flush */
54 NULL, /* no special release code */
55 NULL /* can't fsync */
59 * proc directories can do almost nothing..
61 struct inode_operations proc_dir_inode_operations = {
62 &proc_dir_operations, /* default net directory file-ops */
63 NULL, /* create */
64 proc_lookup, /* lookup */
65 NULL, /* link */
66 NULL, /* unlink */
67 NULL, /* symlink */
68 NULL, /* mkdir */
69 NULL, /* rmdir */
70 NULL, /* mknod */
71 NULL, /* rename */
72 NULL, /* readlink */
73 NULL, /* follow_link */
74 NULL, /* get_block */
75 NULL, /* readpage */
76 NULL, /* writepage */
77 NULL, /* flushpage */
78 NULL, /* truncate */
79 NULL, /* permission */
80 NULL, /* smap */
81 NULL /* revalidate */
85 * /proc dynamic directories now support unlinking
87 struct inode_operations proc_dyna_dir_inode_operations = {
88 &proc_dir_operations, /* default proc dir ops */
89 NULL, /* create */
90 proc_lookup, /* lookup */
91 NULL, /* link */
92 proc_unlink, /* unlink(struct inode *, struct dentry *) */
93 NULL, /* symlink */
94 NULL, /* mkdir */
95 NULL, /* rmdir */
96 NULL, /* mknod */
97 NULL, /* rename */
98 NULL, /* readlink */
99 NULL, /* follow_link */
100 NULL, /* get_block */
101 NULL, /* readpage */
102 NULL, /* writepage */
103 NULL, /* flushpage */
104 NULL, /* truncate */
105 NULL, /* permission */
106 NULL, /* smap */
107 NULL /* revalidate */
111 * The root /proc directory is special, as it has the
112 * <pid> directories. Thus we don't use the generic
113 * directory handling functions for that..
115 static struct file_operations proc_root_operations = {
116 NULL, /* lseek - default */
117 NULL, /* read - bad */
118 NULL, /* write - bad */
119 proc_root_readdir, /* readdir */
120 NULL, /* poll - default */
121 NULL, /* ioctl - default */
122 NULL, /* mmap */
123 NULL, /* no special open code */
124 NULL, /* flush */
125 NULL, /* no special release code */
126 NULL /* no fsync */
130 * proc root can do almost nothing..
132 static struct inode_operations proc_root_inode_operations = {
133 &proc_root_operations, /* default base directory file-ops */
134 NULL, /* create */
135 proc_root_lookup, /* lookup */
136 NULL, /* link */
137 NULL, /* unlink */
138 NULL, /* symlink */
139 NULL, /* mkdir */
140 NULL, /* rmdir */
141 NULL, /* mknod */
142 NULL, /* rename */
143 NULL, /* readlink */
144 NULL, /* follow_link */
145 NULL, /* get_block */
146 NULL, /* readpage */
147 NULL, /* writepage */
148 NULL, /* flushpage */
149 NULL, /* truncate */
150 NULL, /* permission */
151 NULL, /* smap */
152 NULL /* revalidate */
156 * This is the root "inode" in the /proc tree..
158 struct proc_dir_entry proc_root = {
159 PROC_ROOT_INO, 5, "/proc",
160 S_IFDIR | S_IRUGO | S_IXUGO, 2, 0, 0,
161 0, &proc_root_inode_operations,
162 NULL, NULL,
163 NULL,
164 &proc_root, NULL
167 struct proc_dir_entry *proc_net, *proc_scsi, *proc_bus, *proc_sysvipc,
168 *proc_root_fs, *proc_root_driver;
170 #ifdef CONFIG_MCA
171 struct proc_dir_entry *proc_mca;
172 #endif
174 #ifdef CONFIG_SYSCTL
175 struct proc_dir_entry *proc_sys_root;
176 #endif
178 #if defined(CONFIG_SUN_OPENPROMFS) || defined(CONFIG_SUN_OPENPROMFS_MODULE)
180 static int (*proc_openprom_defreaddir_ptr)(struct file *, void *, filldir_t);
181 static struct dentry * (*proc_openprom_deflookup_ptr)(struct inode *, struct dentry *);
182 void (*proc_openprom_use)(struct inode *, int) = 0;
183 static struct openpromfs_dev *proc_openprom_devices = NULL;
184 static ino_t proc_openpromdev_ino = PROC_OPENPROMD_FIRST;
186 struct inode_operations *
187 proc_openprom_register(int (*readdir)(struct file *, void *, filldir_t),
188 struct dentry * (*lookup)(struct inode *, struct dentry *),
189 void (*use)(struct inode *, int),
190 struct openpromfs_dev ***devices)
192 proc_openprom_defreaddir_ptr = (proc_openprom_inode_operations.default_file_ops)->readdir;
193 proc_openprom_deflookup_ptr = proc_openprom_inode_operations.lookup;
194 (proc_openprom_inode_operations.default_file_ops)->readdir = readdir;
195 proc_openprom_inode_operations.lookup = lookup;
196 proc_openprom_use = use;
197 *devices = &proc_openprom_devices;
198 return &proc_openprom_inode_operations;
201 int proc_openprom_regdev(struct openpromfs_dev *d)
203 if (proc_openpromdev_ino == PROC_OPENPROMD_FIRST + PROC_NOPENPROMD)
204 return -1;
205 d->next = proc_openprom_devices;
206 d->inode = proc_openpromdev_ino++;
207 proc_openprom_devices = d;
208 return 0;
211 int proc_openprom_unregdev(struct openpromfs_dev *d)
213 if (d == proc_openprom_devices) {
214 proc_openprom_devices = d->next;
215 } else if (!proc_openprom_devices)
216 return -1;
217 else {
218 struct openpromfs_dev *p;
220 for (p = proc_openprom_devices; p->next != d && p->next; p = p->next);
221 if (!p->next) return -1;
222 p->next = d->next;
224 return 0;
227 #ifdef CONFIG_SUN_OPENPROMFS_MODULE
228 void
229 proc_openprom_deregister(void)
231 (proc_openprom_inode_operations.default_file_ops)->readdir = proc_openprom_defreaddir_ptr;
232 proc_openprom_inode_operations.lookup = proc_openprom_deflookup_ptr;
233 proc_openprom_use = 0;
235 #endif
237 #if defined(CONFIG_SUN_OPENPROMFS_MODULE) && defined(CONFIG_KMOD)
238 static int
239 proc_openprom_defreaddir(struct file * filp, void * dirent, filldir_t filldir)
241 request_module("openpromfs");
242 if ((proc_openprom_inode_operations.default_file_ops)->readdir !=
243 proc_openprom_defreaddir)
244 return (proc_openprom_inode_operations.default_file_ops)->readdir
245 (filp, dirent, filldir);
246 return -EINVAL;
248 #define OPENPROM_DEFREADDIR proc_openprom_defreaddir
250 static struct dentry *
251 proc_openprom_deflookup(struct inode * dir, struct dentry *dentry)
253 request_module("openpromfs");
254 if (proc_openprom_inode_operations.lookup !=
255 proc_openprom_deflookup)
256 return proc_openprom_inode_operations.lookup
257 (dir, dentry);
258 return ERR_PTR(-ENOENT);
260 #define OPENPROM_DEFLOOKUP proc_openprom_deflookup
261 #else
262 #define OPENPROM_DEFREADDIR NULL
263 #define OPENPROM_DEFLOOKUP NULL
264 #endif
266 static struct file_operations proc_openprom_operations = {
267 NULL, /* lseek - default */
268 NULL, /* read - bad */
269 NULL, /* write - bad */
270 OPENPROM_DEFREADDIR, /* readdir */
271 NULL, /* poll - default */
272 NULL, /* ioctl - default */
273 NULL, /* mmap */
274 NULL, /* no special open code */
275 NULL, /* flush */
276 NULL, /* no special release code */
277 NULL /* can't fsync */
280 struct inode_operations proc_openprom_inode_operations = {
281 &proc_openprom_operations,/* default net directory file-ops */
282 NULL, /* create */
283 OPENPROM_DEFLOOKUP, /* lookup */
284 NULL, /* link */
285 NULL, /* unlink */
286 NULL, /* symlink */
287 NULL, /* mkdir */
288 NULL, /* rmdir */
289 NULL, /* mknod */
290 NULL, /* rename */
291 NULL, /* readlink */
292 NULL, /* follow_link */
293 NULL, /* get_block */
294 NULL, /* readpage */
295 NULL, /* writepage */
296 NULL, /* flushpage */
297 NULL, /* truncate */
298 NULL, /* permission */
299 NULL, /* smap */
300 NULL /* revalidate */
303 struct proc_dir_entry proc_openprom = {
304 PROC_OPENPROM, 8, "openprom",
305 S_IFDIR | S_IRUGO | S_IXUGO, 2, 0, 0,
306 0, &proc_openprom_inode_operations,
307 NULL, NULL,
308 NULL,
309 &proc_root, NULL
312 extern void openpromfs_init (void);
313 #endif /* CONFIG_SUN_OPENPROMFS */
315 static int make_inode_number(void)
317 int i = find_first_zero_bit((void *) proc_alloc_map, PROC_NDYNAMIC);
318 if (i<0 || i>=PROC_NDYNAMIC)
319 return -1;
320 set_bit(i, (void *) proc_alloc_map);
321 return PROC_DYNAMIC_FIRST + i;
324 int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp)
326 int i;
328 if (dp->low_ino == 0) {
329 i = make_inode_number();
330 if (i < 0)
331 return -EAGAIN;
332 dp->low_ino = i;
334 dp->next = dir->subdir;
335 dp->parent = dir;
336 dir->subdir = dp;
337 if (S_ISDIR(dp->mode)) {
338 if (dp->ops == NULL)
339 dp->ops = &proc_dir_inode_operations;
340 dir->nlink++;
341 } else if (S_ISLNK(dp->mode)) {
342 if (dp->ops == NULL)
343 dp->ops = &proc_link_inode_operations;
344 } else {
345 if (dp->ops == NULL)
346 dp->ops = &proc_file_inode_operations;
348 return 0;
352 * Kill an inode that got unregistered..
354 static void proc_kill_inodes(int ino)
356 struct list_head *p;
357 struct super_block *sb;
360 * Actually it's a partial revoke(). We have to go through all
361 * copies of procfs. proc_super_blocks is protected by the big
362 * lock for the time being.
364 for (sb = proc_super_blocks;
366 sb = (struct super_block*)sb->u.generic_sbp) {
367 file_list_lock();
368 for (p = sb->s_files.next; p != &sb->s_files; p = p->next) {
369 struct file * filp = list_entry(p, struct file, f_list);
370 struct dentry * dentry;
371 struct inode * inode;
373 dentry = filp->f_dentry;
374 if (!dentry)
375 continue;
376 if (dentry->d_op != &proc_dentry_operations)
377 continue;
378 inode = dentry->d_inode;
379 if (!inode)
380 continue;
381 if (inode->i_ino != ino)
382 continue;
383 filp->f_op = NULL;
385 file_list_unlock();
389 int proc_unregister(struct proc_dir_entry * dir, int ino)
391 struct proc_dir_entry **p = &dir->subdir, *dp;
393 while ((dp = *p) != NULL) {
394 if (dp->low_ino == ino) {
395 *p = dp->next;
396 dp->next = NULL;
397 if (S_ISDIR(dp->mode))
398 dir->nlink--;
399 if (ino >= PROC_DYNAMIC_FIRST &&
400 ino < PROC_DYNAMIC_FIRST+PROC_NDYNAMIC)
401 clear_bit(ino-PROC_DYNAMIC_FIRST,
402 (void *) proc_alloc_map);
403 proc_kill_inodes(ino);
404 return 0;
406 p = &dp->next;
408 return -EINVAL;
412 * /proc/self:
414 static int proc_self_readlink(struct dentry *dentry, char *buffer, int buflen)
416 int len;
417 char tmp[30];
419 len = sprintf(tmp, "%d", current->pid);
420 if (buflen < len)
421 len = buflen;
422 copy_to_user(buffer, tmp, len);
423 return len;
426 static struct dentry * proc_self_follow_link(struct dentry *dentry,
427 struct dentry *base,
428 unsigned int follow)
430 char tmp[30];
432 sprintf(tmp, "%d", current->pid);
433 return lookup_dentry(tmp, base, follow);
436 int proc_readlink(struct dentry * dentry, char * buffer, int buflen)
438 struct inode *inode = dentry->d_inode;
439 struct proc_dir_entry * de;
440 char *page;
441 int len = 0;
443 de = (struct proc_dir_entry *) inode->u.generic_ip;
444 if (!de)
445 return -ENOENT;
446 if (!(page = (char*) __get_free_page(GFP_KERNEL)))
447 return -ENOMEM;
449 if (de->readlink_proc)
450 len = de->readlink_proc(de, page);
452 if (len > buflen)
453 len = buflen;
455 copy_to_user(buffer, page, len);
456 free_page((unsigned long) page);
457 return len;
460 struct dentry * proc_follow_link(struct dentry * dentry, struct dentry *base, unsigned int follow)
462 struct inode *inode = dentry->d_inode;
463 struct proc_dir_entry * de;
464 char *page;
465 struct dentry *d;
466 int len = 0;
468 de = (struct proc_dir_entry *) inode->u.generic_ip;
469 if (!(page = (char*) __get_free_page(GFP_KERNEL)))
470 return NULL;
472 if (de->readlink_proc)
473 len = de->readlink_proc(de, page);
475 d = lookup_dentry(page, base, follow);
476 free_page((unsigned long) page);
477 return d;
480 static struct inode_operations proc_self_inode_operations = {
481 NULL, /* no file-ops */
482 NULL, /* create */
483 NULL, /* lookup */
484 NULL, /* link */
485 NULL, /* unlink */
486 NULL, /* symlink */
487 NULL, /* mkdir */
488 NULL, /* rmdir */
489 NULL, /* mknod */
490 NULL, /* rename */
491 proc_self_readlink, /* readlink */
492 proc_self_follow_link, /* follow_link */
493 NULL, /* get_block */
494 NULL, /* readpage */
495 NULL, /* writepage */
496 NULL, /* flushpage */
497 NULL, /* truncate */
498 NULL, /* permission */
499 NULL, /* smap */
500 NULL /* revalidate */
503 static struct inode_operations proc_link_inode_operations = {
504 NULL, /* no file-ops */
505 NULL, /* create */
506 NULL, /* lookup */
507 NULL, /* link */
508 NULL, /* unlink */
509 NULL, /* symlink */
510 NULL, /* mkdir */
511 NULL, /* rmdir */
512 NULL, /* mknod */
513 NULL, /* rename */
514 proc_readlink, /* readlink */
515 proc_follow_link, /* follow_link */
516 NULL, /* get_block */
517 NULL, /* readpage */
518 NULL, /* writepage */
519 NULL, /* flushpage */
520 NULL, /* truncate */
521 NULL, /* permission */
522 NULL, /* smap */
523 NULL /* revalidate */
526 static struct proc_dir_entry proc_root_self = {
527 0, 4, "self",
528 S_IFLNK | S_IRUGO | S_IWUGO | S_IXUGO, 1, 0, 0,
529 64, &proc_self_inode_operations,
531 #ifdef __powerpc__
532 static struct proc_dir_entry proc_root_ppc_htab = {
533 0, 8, "ppc_htab",
534 S_IFREG | S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH, 1, 0, 0,
535 0, &proc_ppc_htab_inode_operations,
536 NULL, NULL, /* get_info, fill_inode */
537 NULL, /* next */
538 NULL, NULL /* parent, subdir */
540 #endif
542 void __init proc_root_init(void)
544 proc_base_init();
545 proc_misc_init();
546 proc_register(&proc_root, &proc_root_self);
547 proc_net = create_proc_entry("net", S_IFDIR, 0);
548 proc_scsi = create_proc_entry("scsi", S_IFDIR, 0);
549 #ifdef CONFIG_SYSVIPC
550 proc_sysvipc = create_proc_entry("sysvipc", S_IFDIR, 0);
551 #endif
552 #ifdef CONFIG_SYSCTL
553 proc_sys_root = create_proc_entry("sys", S_IFDIR, 0);
554 #endif
555 #ifdef CONFIG_MCA
556 proc_mca = create_proc_entry("mca", S_IFDIR, 0);
557 #endif
558 proc_root_fs = create_proc_entry("fs", S_IFDIR, 0);
559 proc_root_driver = create_proc_entry("driver", S_IFDIR, 0);
560 #if defined(CONFIG_SUN_OPENPROMFS) || defined(CONFIG_SUN_OPENPROMFS_MODULE)
561 #ifdef CONFIG_SUN_OPENPROMFS
562 openpromfs_init ();
563 #endif
564 proc_register(&proc_root, &proc_openprom);
565 #endif
566 proc_tty_init();
567 #ifdef __powerpc__
568 proc_register(&proc_root, &proc_root_ppc_htab);
569 #endif
570 #ifdef CONFIG_PROC_DEVICETREE
571 proc_device_tree_init();
572 #endif
573 proc_bus = create_proc_entry("bus", S_IFDIR, 0);
577 * As some entries in /proc are volatile, we want to
578 * get rid of unused dentries. This could be made
579 * smarter: we could keep a "volatile" flag in the
580 * inode to indicate which ones to keep.
582 static void
583 proc_delete_dentry(struct dentry * dentry)
585 d_drop(dentry);
588 struct dentry_operations proc_dentry_operations =
590 NULL, /* revalidate */
591 NULL, /* d_hash */
592 NULL, /* d_compare */
593 proc_delete_dentry /* d_delete(struct dentry *) */
597 * Don't create negative dentries here, return -ENOENT by hand
598 * instead.
600 struct dentry *proc_lookup(struct inode * dir, struct dentry *dentry)
602 struct inode *inode;
603 struct proc_dir_entry * de;
604 int error;
606 error = -ENOENT;
607 inode = NULL;
608 de = (struct proc_dir_entry *) dir->u.generic_ip;
609 if (de) {
610 for (de = de->subdir; de ; de = de->next) {
611 if (!de || !de->low_ino)
612 continue;
613 if (de->namelen != dentry->d_name.len)
614 continue;
615 if (!memcmp(dentry->d_name.name, de->name, de->namelen)) {
616 int ino = de->low_ino | (dir->i_ino & ~(0xffff));
617 error = -EINVAL;
618 inode = proc_get_inode(dir->i_sb, ino, de);
619 break;
624 if (inode) {
625 dentry->d_op = &proc_dentry_operations;
626 d_add(dentry, inode);
627 return NULL;
629 return ERR_PTR(error);
632 static struct dentry *proc_root_lookup(struct inode * dir, struct dentry * dentry)
634 unsigned int pid, c;
635 struct task_struct *p;
636 const char *name;
637 struct inode *inode;
638 int len;
640 if (dir->i_ino == PROC_ROOT_INO) { /* check for safety... */
641 extern unsigned long total_forks;
642 static int last_timestamp = 0;
645 * this one can be a serious 'ps' performance problem if
646 * there are many threads running - thus we do 'lazy'
647 * link-recalculation - we change it only if the number
648 * of threads has increased.
650 if (total_forks != last_timestamp) {
651 int nlink = proc_root.nlink;
653 read_lock(&tasklist_lock);
654 last_timestamp = total_forks;
655 for_each_task(p)
656 nlink++;
657 read_unlock(&tasklist_lock);
659 * subtract the # of idle threads which
660 * do not show up in /proc:
662 dir->i_nlink = nlink - smp_num_cpus;
666 if (!proc_lookup(dir, dentry))
667 return NULL;
669 pid = 0;
670 name = dentry->d_name.name;
671 len = dentry->d_name.len;
672 while (len-- > 0) {
673 c = *name - '0';
674 name++;
675 if (c > 9) {
676 pid = 0;
677 break;
679 pid *= 10;
680 pid += c;
681 if (!pid)
682 break;
683 if (pid & 0xffff0000) {
684 pid = 0;
685 break;
688 read_lock(&tasklist_lock);
689 p = find_task_by_pid(pid);
690 read_unlock(&tasklist_lock);
691 inode = NULL;
692 if (pid && p) {
693 unsigned long ino = (pid << 16) + PROC_PID_INO;
694 inode = proc_get_inode(dir->i_sb, ino, &proc_pid);
695 if (!inode)
696 return ERR_PTR(-EINVAL);
697 inode->i_flags|=S_IMMUTABLE;
700 dentry->d_op = &proc_dentry_operations;
701 d_add(dentry, inode);
702 return NULL;
706 * This returns non-zero if at EOF, so that the /proc
707 * root directory can use this and check if it should
708 * continue with the <pid> entries..
710 * Note that the VFS-layer doesn't care about the return
711 * value of the readdir() call, as long as it's non-negative
712 * for success..
714 int proc_readdir(struct file * filp,
715 void * dirent, filldir_t filldir)
717 struct proc_dir_entry * de;
718 unsigned int ino;
719 int i;
720 struct inode *inode = filp->f_dentry->d_inode;
722 ino = inode->i_ino;
723 de = (struct proc_dir_entry *) inode->u.generic_ip;
724 if (!de)
725 return -EINVAL;
726 i = filp->f_pos;
727 switch (i) {
728 case 0:
729 if (filldir(dirent, ".", 1, i, ino) < 0)
730 return 0;
731 i++;
732 filp->f_pos++;
733 /* fall through */
734 case 1:
735 if (filldir(dirent, "..", 2, i, de->parent->low_ino) < 0)
736 return 0;
737 i++;
738 filp->f_pos++;
739 /* fall through */
740 default:
741 ino &= ~0xffff;
742 de = de->subdir;
743 i -= 2;
744 for (;;) {
745 if (!de)
746 return 1;
747 if (!i)
748 break;
749 de = de->next;
750 i--;
753 do {
754 if (filldir(dirent, de->name, de->namelen, filp->f_pos, ino | de->low_ino) < 0)
755 return 0;
756 filp->f_pos++;
757 de = de->next;
758 } while (de);
760 return 1;
763 #define PROC_NUMBUF 10
764 #define PROC_MAXPIDS 20
767 * Get a few pid's to return for filldir - we need to hold the
768 * tasklist lock while doing this, and we must release it before
769 * we actually do the filldir itself, so we use a temp buffer..
771 static int get_pid_list(int index, unsigned int *pids)
773 struct task_struct *p;
774 int nr_pids = 0;
776 index -= FIRST_PROCESS_ENTRY;
777 read_lock(&tasklist_lock);
778 for_each_task(p) {
779 int pid = p->pid;
780 if (!pid)
781 continue;
782 if (--index >= 0)
783 continue;
784 pids[nr_pids] = pid;
785 nr_pids++;
786 if (nr_pids >= PROC_MAXPIDS)
787 break;
789 read_unlock(&tasklist_lock);
790 return nr_pids;
793 static int proc_root_readdir(struct file * filp,
794 void * dirent, filldir_t filldir)
796 unsigned int pid_array[PROC_MAXPIDS];
797 char buf[PROC_NUMBUF];
798 unsigned int nr = filp->f_pos;
799 unsigned int nr_pids, i;
801 if (nr < FIRST_PROCESS_ENTRY) {
802 int error = proc_readdir(filp, dirent, filldir);
803 if (error <= 0)
804 return error;
805 filp->f_pos = nr = FIRST_PROCESS_ENTRY;
808 nr_pids = get_pid_list(nr, pid_array);
810 for (i = 0; i < nr_pids; i++) {
811 int pid = pid_array[i];
812 ino_t ino = (pid << 16) + PROC_PID_INO;
813 unsigned long j = PROC_NUMBUF;
815 do {
816 j--;
817 buf[j] = '0' + (pid % 10);
818 pid /= 10;
819 } while (pid);
821 if (filldir(dirent, buf+j, PROC_NUMBUF-j, filp->f_pos, ino) < 0)
822 break;
823 filp->f_pos++;
825 return 0;
828 static int proc_unlink(struct inode *dir, struct dentry *dentry)
830 struct proc_dir_entry * dp = dir->u.generic_ip;
832 printk("proc_file_unlink: deleting %s/%s\n", dp->name, dentry->d_name.name);
834 remove_proc_entry(dentry->d_name.name, dp);
835 dentry->d_inode->i_nlink = 0;
836 d_delete(dentry);
837 return 0;