This source file includes following definitions.
- read_core
- read_profile
- write_profile
- get_loadavg
- get_kstat
- get_uptime
- get_meminfo
- get_version
- get_task
- get_phys_addr
- get_array
- get_env
- get_arg
- get_wchan
- get_stat
- statm_pte_range
- statm_pmd_range
- statm_pgd_range
- get_statm
- read_maps
- get_root_array
- get_process_array
- fill_array
- array_read
- arraylong_read
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 #include <linux/types.h>
31 #include <linux/errno.h>
32 #include <linux/sched.h>
33 #include <linux/kernel.h>
34 #include <linux/kernel_stat.h>
35 #include <linux/tty.h>
36 #include <linux/user.h>
37 #include <linux/a.out.h>
38 #include <linux/string.h>
39 #include <linux/mman.h>
40 #include <linux/proc_fs.h>
41 #include <linux/ioport.h>
42 #include <linux/config.h>
43 #include <linux/mm.h>
44
45 #include <asm/segment.h>
46 #include <asm/pgtable.h>
47 #include <asm/io.h>
48
49 #define LOAD_INT(x) ((x) >> FSHIFT)
50 #define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1-1)) * 100)
51
52 #ifdef CONFIG_DEBUG_MALLOC
53 int get_malloc(char * buffer);
54 #endif
55
56
57 static int read_core(struct inode * inode, struct file * file,char * buf, int count)
58 {
59 unsigned long p = file->f_pos, memsize;
60 int read;
61 int count1;
62 char * pnt;
63 struct user dump;
64 #ifdef __i386__
65 # define FIRST_MAPPED PAGE_SIZE
66 #else
67 # define FIRST_MAPPED 0
68 #endif
69
70 memset(&dump, 0, sizeof(struct user));
71 dump.magic = CMAGIC;
72 dump.u_dsize = MAP_NR(high_memory);
73 #ifdef __alpha__
74 dump.start_data = PAGE_OFFSET;
75 #endif
76
77 if (count < 0)
78 return -EINVAL;
79 memsize = MAP_NR(high_memory + PAGE_SIZE) << PAGE_SHIFT;
80 if (p >= memsize)
81 return 0;
82 if (count > memsize - p)
83 count = memsize - p;
84 read = 0;
85
86 if (p < sizeof(struct user) && count > 0) {
87 count1 = count;
88 if (p + count1 > sizeof(struct user))
89 count1 = sizeof(struct user)-p;
90 pnt = (char *) &dump + p;
91 memcpy_tofs(buf,(void *) pnt, count1);
92 buf += count1;
93 p += count1;
94 count -= count1;
95 read += count1;
96 }
97
98 while (count > 0 && p < PAGE_SIZE + FIRST_MAPPED) {
99 put_user(0,buf);
100 buf++;
101 p++;
102 count--;
103 read++;
104 }
105 memcpy_tofs(buf, (void *) (PAGE_OFFSET + p - PAGE_SIZE), count);
106 read += count;
107 file->f_pos += read;
108 return read;
109 }
110
111 static struct file_operations proc_kcore_operations = {
112 NULL,
113 read_core,
114 };
115
116 struct inode_operations proc_kcore_inode_operations = {
117 &proc_kcore_operations,
118 };
119
120
121 extern unsigned long prof_len;
122 extern unsigned long * prof_buffer;
123 extern unsigned long prof_shift;
124
125
126
127
128
129
130 static int read_profile(struct inode *inode, struct file *file, char *buf, int count)
131 {
132 unsigned long p = file->f_pos;
133 int read;
134 char * pnt;
135 unsigned long sample_step = 1 << prof_shift;
136
137 if (count < 0)
138 return -EINVAL;
139 if (p >= (prof_len+1)*sizeof(unsigned long))
140 return 0;
141 if (count > (prof_len+1)*sizeof(unsigned long) - p)
142 count = (prof_len+1)*sizeof(unsigned long) - p;
143 read = 0;
144
145 while (p < sizeof(unsigned long) && count > 0) {
146 put_user(*((char *)(&sample_step)+p),buf);
147 buf++; p++; count--; read++;
148 }
149 pnt = (char *)prof_buffer + p - sizeof(unsigned long);
150 memcpy_tofs(buf,(void *)pnt,count);
151 read += count;
152 file->f_pos += read;
153 return read;
154 }
155
156
157 static int write_profile(struct inode * inode, struct file * file, const char * buf, int count)
158 {
159 int i=prof_len;
160
161 while (i--)
162 prof_buffer[i]=0UL;
163 return count;
164 }
165
166 static struct file_operations proc_profile_operations = {
167 NULL,
168 read_profile,
169 write_profile,
170 };
171
172 struct inode_operations proc_profile_inode_operations = {
173 &proc_profile_operations,
174 };
175
176
177 static int get_loadavg(char * buffer)
178 {
179 int a, b, c;
180
181 a = avenrun[0] + (FIXED_1/200);
182 b = avenrun[1] + (FIXED_1/200);
183 c = avenrun[2] + (FIXED_1/200);
184 return sprintf(buffer,"%d.%02d %d.%02d %d.%02d %d/%d\n",
185 LOAD_INT(a), LOAD_FRAC(a),
186 LOAD_INT(b), LOAD_FRAC(b),
187 LOAD_INT(c), LOAD_FRAC(c),
188 nr_running, nr_tasks);
189 }
190
191 static int get_kstat(char * buffer)
192 {
193 int i, len;
194 unsigned sum = 0;
195
196 for (i = 0 ; i < NR_IRQS ; i++)
197 sum += kstat.interrupts[i];
198 len = sprintf(buffer,
199 "cpu %u %u %u %lu\n"
200 "disk %u %u %u %u\n"
201 "page %u %u\n"
202 "swap %u %u\n"
203 "intr %u",
204 kstat.cpu_user,
205 kstat.cpu_nice,
206 kstat.cpu_system,
207 jiffies - (kstat.cpu_user + kstat.cpu_nice + kstat.cpu_system),
208 kstat.dk_drive[0],
209 kstat.dk_drive[1],
210 kstat.dk_drive[2],
211 kstat.dk_drive[3],
212 kstat.pgpgin,
213 kstat.pgpgout,
214 kstat.pswpin,
215 kstat.pswpout,
216 sum);
217 for (i = 0 ; i < NR_IRQS ; i++)
218 len += sprintf(buffer + len, " %u", kstat.interrupts[i]);
219 len += sprintf(buffer + len,
220 "\nctxt %u\n"
221 "btime %lu\n",
222 kstat.context_swtch,
223 xtime.tv_sec - jiffies / HZ);
224 return len;
225 }
226
227
228 static int get_uptime(char * buffer)
229 {
230 unsigned long uptime;
231 unsigned long idle;
232
233 uptime = jiffies;
234 idle = task[0]->utime + task[0]->stime;
235
236
237
238
239
240
241
242
243
244
245 #if HZ!=100
246 return sprintf(buffer,"%lu.%02lu %lu.%02lu\n",
247 uptime / HZ,
248 (((uptime % HZ) * 100) / HZ) % 100,
249 idle / HZ,
250 (((idle % HZ) * 100) / HZ) % 100);
251 #else
252 return sprintf(buffer,"%lu.%02lu %lu.%02lu\n",
253 uptime / HZ,
254 uptime % HZ,
255 idle / HZ,
256 idle % HZ);
257 #endif
258 }
259
260 static int get_meminfo(char * buffer)
261 {
262 struct sysinfo i;
263
264 si_meminfo(&i);
265 si_swapinfo(&i);
266 return sprintf(buffer, " total: used: free: shared: buffers:\n"
267 "Mem: %8lu %8lu %8lu %8lu %8lu\n"
268 "Swap: %8lu %8lu %8lu\n",
269 i.totalram, i.totalram-i.freeram, i.freeram, i.sharedram, i.bufferram,
270 i.totalswap, i.totalswap-i.freeswap, i.freeswap);
271 }
272
273 static int get_version(char * buffer)
274 {
275 extern char *linux_banner;
276
277 strcpy(buffer, linux_banner);
278 return strlen(buffer);
279 }
280
281 static struct task_struct ** get_task(pid_t pid)
282 {
283 struct task_struct ** p;
284
285 p = task;
286 while (++p < task+NR_TASKS) {
287 if (*p && (*p)->pid == pid)
288 return p;
289 }
290 return NULL;
291 }
292
293 static unsigned long get_phys_addr(struct task_struct * p, unsigned long ptr)
294 {
295 pgd_t *page_dir;
296 pmd_t *page_middle;
297 pte_t pte;
298
299 if (!p || !p->mm || ptr >= TASK_SIZE)
300 return 0;
301 page_dir = pgd_offset(p->mm,ptr);
302 if (pgd_none(*page_dir))
303 return 0;
304 if (pgd_bad(*page_dir)) {
305 printk("bad page directory entry %08lx\n", pgd_val(*page_dir));
306 pgd_clear(page_dir);
307 return 0;
308 }
309 page_middle = pmd_offset(page_dir,ptr);
310 if (pmd_none(*page_middle))
311 return 0;
312 if (pmd_bad(*page_middle)) {
313 printk("bad page middle entry %08lx\n", pmd_val(*page_middle));
314 pmd_clear(page_middle);
315 return 0;
316 }
317 pte = *pte_offset(page_middle,ptr);
318 if (!pte_present(pte))
319 return 0;
320 return pte_page(pte) + (ptr & ~PAGE_MASK);
321 }
322
323 static int get_array(struct task_struct ** p, unsigned long start, unsigned long end, char * buffer)
324 {
325 unsigned long addr;
326 int size = 0, result = 0;
327 char c;
328
329 if (start >= end)
330 return result;
331 for (;;) {
332 addr = get_phys_addr(*p, start);
333 if (!addr)
334 goto ready;
335 do {
336 c = *(char *) addr;
337 if (!c)
338 result = size;
339 if (size < PAGE_SIZE)
340 buffer[size++] = c;
341 else
342 goto ready;
343 addr++;
344 start++;
345 if (!c && start >= end)
346 goto ready;
347 } while (addr & ~PAGE_MASK);
348 }
349 ready:
350
351 while (result>0 && buffer[result-1]==' ')
352 result--;
353 return result;
354 }
355
356 static int get_env(int pid, char * buffer)
357 {
358 struct task_struct ** p = get_task(pid);
359
360 if (!p || !*p || !(*p)->mm)
361 return 0;
362 return get_array(p, (*p)->mm->env_start, (*p)->mm->env_end, buffer);
363 }
364
365 static int get_arg(int pid, char * buffer)
366 {
367 struct task_struct ** p = get_task(pid);
368
369 if (!p || !*p || !(*p)->mm)
370 return 0;
371 return get_array(p, (*p)->mm->arg_start, (*p)->mm->arg_end, buffer);
372 }
373
374 static unsigned long get_wchan(struct task_struct *p)
375 {
376 if (!p || p == current || p->state == TASK_RUNNING)
377 return 0;
378 #if defined(__i386__)
379 {
380 unsigned long ebp, eip;
381 unsigned long stack_page;
382 int count = 0;
383
384 stack_page = p->kernel_stack_page;
385 if (!stack_page)
386 return 0;
387 ebp = p->tss.ebp;
388 do {
389 if (ebp < stack_page || ebp >= 4092+stack_page)
390 return 0;
391 eip = *(unsigned long *) (ebp+4);
392 if ((void *)eip != sleep_on &&
393 (void *)eip != interruptible_sleep_on)
394 return eip;
395 ebp = *(unsigned long *) ebp;
396 } while (count++ < 16);
397 }
398 #elif defined(__alpha__)
399
400
401
402
403
404
405
406
407
408 {
409 unsigned long schedule_frame;
410 unsigned long pc;
411
412 pc = thread_saved_pc(&p->tss);
413 if (pc >= (unsigned long) interruptible_sleep_on && pc < (unsigned long) add_timer) {
414 schedule_frame = ((unsigned long *)p->tss.ksp)[6];
415 return ((unsigned long *)schedule_frame)[12];
416 }
417 return pc;
418 }
419 #endif
420 return 0;
421 }
422
423 #if defined(__i386__)
424 # define KSTK_EIP(tsk) (((unsigned long *)tsk->kernel_stack_page)[1019])
425 # define KSTK_ESP(tsk) (((unsigned long *)tsk->kernel_stack_page)[1022])
426 #elif defined(__alpha__)
427
428
429
430 # define PT_REG(reg) (PAGE_SIZE - sizeof(struct pt_regs) \
431 + (long)&((struct pt_regs *)0)->reg)
432 # define KSTK_EIP(tsk) (*(unsigned long *)(tsk->kernel_stack_page + PT_REG(pc)))
433 # define KSTK_ESP(tsk) ((tsk) == current ? rdusp() : (tsk)->tss.usp)
434 #endif
435
436 static int get_stat(int pid, char * buffer)
437 {
438 struct task_struct ** p = get_task(pid), *tsk;
439 unsigned long sigignore=0, sigcatch=0, wchan;
440 unsigned long vsize, eip, esp;
441 long priority, nice;
442 int i,tty_pgrp;
443 char state;
444
445 if (!p || (tsk = *p) == NULL)
446 return 0;
447 if (tsk->state < 0 || tsk->state > 5)
448 state = '.';
449 else
450 state = "RSDZTD"[tsk->state];
451 vsize = eip = esp = 0;
452 if (tsk->mm) {
453 struct vm_area_struct *vma = tsk->mm->mmap;
454 while (vma) {
455 vsize += vma->vm_end - vma->vm_start;
456 vma = vma->vm_next;
457 }
458 if (tsk->kernel_stack_page) {
459 eip = KSTK_EIP(tsk);
460 esp = KSTK_ESP(tsk);
461 }
462 }
463 wchan = get_wchan(tsk);
464 if (tsk->sig) {
465 unsigned long bit = 1;
466 for(i=0; i<32; ++i) {
467 switch((unsigned long) tsk->sig->action[i].sa_handler) {
468 case 0:
469 break;
470 case 1:
471 sigignore |= bit;
472 break;
473 default:
474 sigcatch |= bit;
475 }
476 bit <<= 1;
477 }
478 }
479 if (tsk->tty)
480 tty_pgrp = tsk->tty->pgrp;
481 else
482 tty_pgrp = -1;
483
484
485 priority = tsk->counter;
486 priority = (priority * 10 + DEF_PRIORITY / 2) / DEF_PRIORITY - 20;
487 nice = tsk->priority;
488 nice = (nice * 20 + DEF_PRIORITY / 2) / DEF_PRIORITY - 20;
489
490 return sprintf(buffer,"%d (%s) %c %d %d %d %d %d %lu %lu \
491 %lu %lu %lu %ld %ld %ld %ld %ld %ld %lu %lu %ld %lu %lu %lu %lu %lu %lu %lu %lu %lu \
492 %lu %lu %lu %lu\n",
493 pid,
494 tsk->comm,
495 state,
496 tsk->p_pptr->pid,
497 tsk->pgrp,
498 tsk->session,
499 tsk->tty ? kdev_t_to_nr(tsk->tty->device) : 0,
500 tty_pgrp,
501 tsk->flags,
502 tsk->min_flt,
503 tsk->cmin_flt,
504 tsk->maj_flt,
505 tsk->cmaj_flt,
506 tsk->utime,
507 tsk->stime,
508 tsk->cutime,
509 tsk->cstime,
510 priority,
511
512 nice,
513
514 tsk->timeout,
515 tsk->it_real_value,
516 tsk->start_time,
517 vsize,
518 tsk->mm ? tsk->mm->rss : 0,
519 tsk->rlim ? tsk->rlim[RLIMIT_RSS].rlim_cur : 0,
520 tsk->mm ? tsk->mm->start_code : 0,
521 tsk->mm ? tsk->mm->end_code : 0,
522 tsk->mm ? tsk->mm->start_stack : 0,
523 esp,
524 eip,
525 tsk->signal,
526 tsk->blocked,
527 sigignore,
528 sigcatch,
529 wchan);
530 }
531
532 static inline void statm_pte_range(pmd_t * pmd, unsigned long address, unsigned long size,
533 int * pages, int * shared, int * dirty, int * total)
534 {
535 pte_t * pte;
536 unsigned long end;
537
538 if (pmd_none(*pmd))
539 return;
540 if (pmd_bad(*pmd)) {
541 printk("statm_pte_range: bad pmd (%08lx)\n", pmd_val(*pmd));
542 pmd_clear(pmd);
543 return;
544 }
545 pte = pte_offset(pmd, address);
546 address &= ~PMD_MASK;
547 end = address + size;
548 if (end > PMD_SIZE)
549 end = PMD_SIZE;
550 do {
551 pte_t page = *pte;
552
553 address += PAGE_SIZE;
554 pte++;
555 if (pte_none(page))
556 continue;
557 ++*total;
558 if (!pte_present(page))
559 continue;
560 ++*pages;
561 if (pte_dirty(page))
562 ++*dirty;
563 if (pte_page(page) >= high_memory)
564 continue;
565 if (mem_map[MAP_NR(pte_page(page))].count > 1)
566 ++*shared;
567 } while (address < end);
568 }
569
570 static inline void statm_pmd_range(pgd_t * pgd, unsigned long address, unsigned long size,
571 int * pages, int * shared, int * dirty, int * total)
572 {
573 pmd_t * pmd;
574 unsigned long end;
575
576 if (pgd_none(*pgd))
577 return;
578 if (pgd_bad(*pgd)) {
579 printk("statm_pmd_range: bad pgd (%08lx)\n", pgd_val(*pgd));
580 pgd_clear(pgd);
581 return;
582 }
583 pmd = pmd_offset(pgd, address);
584 address &= ~PGDIR_MASK;
585 end = address + size;
586 if (end > PGDIR_SIZE)
587 end = PGDIR_SIZE;
588 do {
589 statm_pte_range(pmd, address, end - address, pages, shared, dirty, total);
590 address = (address + PMD_SIZE) & PMD_MASK;
591 pmd++;
592 } while (address < end);
593 }
594
595 static void statm_pgd_range(pgd_t * pgd, unsigned long address, unsigned long end,
596 int * pages, int * shared, int * dirty, int * total)
597 {
598 while (address < end) {
599 statm_pmd_range(pgd, address, end - address, pages, shared, dirty, total);
600 address = (address + PGDIR_SIZE) & PGDIR_MASK;
601 pgd++;
602 }
603 }
604
605 static int get_statm(int pid, char * buffer)
606 {
607 struct task_struct ** p = get_task(pid), *tsk;
608 int size=0, resident=0, share=0, trs=0, lrs=0, drs=0, dt=0;
609
610 if (!p || (tsk = *p) == NULL)
611 return 0;
612 if (tsk->mm) {
613 struct vm_area_struct * vma = tsk->mm->mmap;
614
615 while (vma) {
616 pgd_t *pgd = pgd_offset(tsk->mm, vma->vm_start);
617 int pages = 0, shared = 0, dirty = 0, total = 0;
618
619 statm_pgd_range(pgd, vma->vm_start, vma->vm_end, &pages, &shared, &dirty, &total);
620 resident += pages;
621 share += shared;
622 dt += dirty;
623 size += total;
624 if (vma->vm_flags & VM_EXECUTABLE)
625 trs += pages;
626 else if (vma->vm_flags & VM_GROWSDOWN)
627 drs += pages;
628 else if (vma->vm_end > 0x60000000)
629 lrs += pages;
630 else
631 drs += pages;
632 vma = vma->vm_next;
633 }
634 }
635 return sprintf(buffer,"%d %d %d %d %d %d %d\n",
636 size, resident, share, trs, lrs, drs, dt);
637 }
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655 #define MAPS_LINE_LENGTH 1024
656 #define MAPS_LINE_SHIFT 10
657
658
659
660
661 #define MAPS_LINE_FORMAT "%08lx-%08lx %s %08lx %02x:%02x %lu\n"
662 #define MAPS_LINE_MAX 49
663
664 static int read_maps (int pid, struct file * file, char * buf, int count)
665 {
666 struct task_struct ** p = get_task(pid);
667 char * destptr;
668 loff_t lineno;
669 int column;
670 struct vm_area_struct * map;
671 int i;
672
673 if (!p || !*p)
674 return -EINVAL;
675
676 if (!(*p)->mm || count == 0)
677 return 0;
678
679
680 lineno = file->f_pos >> MAPS_LINE_SHIFT;
681 column = file->f_pos & (MAPS_LINE_LENGTH-1);
682
683
684 for (map = (*p)->mm->mmap, i = 0; map && (i < lineno); map = map->vm_next, i++)
685 continue;
686
687 destptr = buf;
688
689 for ( ; map ; ) {
690
691 char line[MAPS_LINE_MAX+1];
692 char str[5], *cp = str;
693 int flags;
694 kdev_t dev;
695 unsigned long ino;
696 int len;
697
698 flags = map->vm_flags;
699
700 *cp++ = flags & VM_READ ? 'r' : '-';
701 *cp++ = flags & VM_WRITE ? 'w' : '-';
702 *cp++ = flags & VM_EXEC ? 'x' : '-';
703 *cp++ = flags & VM_MAYSHARE ? 's' : 'p';
704 *cp++ = 0;
705
706 if (map->vm_inode != NULL) {
707 dev = map->vm_inode->i_dev;
708 ino = map->vm_inode->i_ino;
709 } else {
710 dev = 0;
711 ino = 0;
712 }
713
714 len = sprintf(line, MAPS_LINE_FORMAT,
715 map->vm_start, map->vm_end, str, map->vm_offset,
716 MAJOR(dev),MINOR(dev), ino);
717
718 if (column >= len) {
719 column = 0;
720 lineno++;
721 map = map->vm_next;
722 continue;
723 }
724
725 i = len-column;
726 if (i > count)
727 i = count;
728 memcpy_tofs(destptr, line+column, i);
729 destptr += i; count -= i;
730 column += i;
731 if (column >= len) {
732 column = 0;
733 lineno++;
734 map = map->vm_next;
735 }
736
737
738 if (count == 0)
739 break;
740
741
742
743
744 if (*p != current)
745 break;
746 }
747
748
749 file->f_pos = (lineno << MAPS_LINE_SHIFT) + column;
750
751 return destptr-buf;
752 }
753
754 extern int get_module_list(char *);
755 extern int get_device_list(char *);
756 extern int get_filesystem_list(char *);
757 extern int get_ksyms_list(char *, char **, off_t, int);
758 extern int get_irq_list(char *);
759 extern int get_dma_list(char *);
760 extern int get_cpuinfo(char *);
761 extern int get_pci_list(char*);
762
763 static int get_root_array(char * page, int type, char **start, off_t offset, int length)
764 {
765 switch (type) {
766 case PROC_LOADAVG:
767 return get_loadavg(page);
768
769 case PROC_UPTIME:
770 return get_uptime(page);
771
772 case PROC_MEMINFO:
773 return get_meminfo(page);
774
775 #ifdef CONFIG_PCI
776 case PROC_PCI:
777 return get_pci_list(page);
778 #endif
779
780 case PROC_CPUINFO:
781 return get_cpuinfo(page);
782
783 case PROC_VERSION:
784 return get_version(page);
785
786 #ifdef CONFIG_DEBUG_MALLOC
787 case PROC_MALLOC:
788 return get_malloc(page);
789 #endif
790
791 case PROC_MODULES:
792 return get_module_list(page);
793
794 case PROC_STAT:
795 return get_kstat(page);
796
797 case PROC_DEVICES:
798 return get_device_list(page);
799
800 case PROC_INTERRUPTS:
801 return get_irq_list(page);
802
803 case PROC_FILESYSTEMS:
804 return get_filesystem_list(page);
805
806 case PROC_KSYMS:
807 return get_ksyms_list(page, start, offset, length);
808
809 case PROC_DMA:
810 return get_dma_list(page);
811
812 case PROC_IOPORTS:
813 return get_ioport_list(page);
814 }
815 return -EBADF;
816 }
817
818 static int get_process_array(char * page, int pid, int type)
819 {
820 switch (type) {
821 case PROC_PID_ENVIRON:
822 return get_env(pid, page);
823 case PROC_PID_CMDLINE:
824 return get_arg(pid, page);
825 case PROC_PID_STAT:
826 return get_stat(pid, page);
827 case PROC_PID_STATM:
828 return get_statm(pid, page);
829 }
830 return -EBADF;
831 }
832
833
834 static inline int fill_array(char * page, int pid, int type, char **start, off_t offset, int length)
835 {
836 if (pid)
837 return get_process_array(page, pid, type);
838 return get_root_array(page, type, start, offset, length);
839 }
840
841 #define PROC_BLOCK_SIZE (3*1024)
842
843 static int array_read(struct inode * inode, struct file * file,char * buf, int count)
844 {
845 unsigned long page;
846 char *start;
847 int length;
848 int end;
849 unsigned int type, pid;
850
851 if (count < 0)
852 return -EINVAL;
853 if (count > PROC_BLOCK_SIZE)
854 count = PROC_BLOCK_SIZE;
855 if (!(page = __get_free_page(GFP_KERNEL)))
856 return -ENOMEM;
857 type = inode->i_ino;
858 pid = type >> 16;
859 type &= 0x0000ffff;
860 start = NULL;
861 length = fill_array((char *) page, pid, type,
862 &start, file->f_pos, count);
863 if (length < 0) {
864 free_page(page);
865 return length;
866 }
867 if (start != NULL) {
868
869 memcpy_tofs(buf, start, length);
870 file->f_pos += length;
871 count = length;
872 } else {
873
874 if (file->f_pos >= length) {
875 free_page(page);
876 return 0;
877 }
878 if (count + file->f_pos > length)
879 count = length - file->f_pos;
880 end = count + file->f_pos;
881 memcpy_tofs(buf, (char *) page + file->f_pos, count);
882 file->f_pos = end;
883 }
884 free_page(page);
885 return count;
886 }
887
888 static struct file_operations proc_array_operations = {
889 NULL,
890 array_read,
891 NULL,
892 NULL,
893 NULL,
894 NULL,
895 NULL,
896 NULL,
897 NULL,
898 NULL
899 };
900
901 struct inode_operations proc_array_inode_operations = {
902 &proc_array_operations,
903 NULL,
904 NULL,
905 NULL,
906 NULL,
907 NULL,
908 NULL,
909 NULL,
910 NULL,
911 NULL,
912 NULL,
913 NULL,
914 NULL,
915 NULL,
916 NULL
917 };
918
919 static int arraylong_read (struct inode * inode, struct file * file, char * buf, int count)
920 {
921 unsigned int pid = inode->i_ino >> 16;
922 unsigned int type = inode->i_ino & 0x0000ffff;
923
924 if (count < 0)
925 return -EINVAL;
926
927 switch (type) {
928 case PROC_PID_MAPS:
929 return read_maps(pid, file, buf, count);
930 }
931 return -EINVAL;
932 }
933
934 static struct file_operations proc_arraylong_operations = {
935 NULL,
936 arraylong_read,
937 NULL,
938 NULL,
939 NULL,
940 NULL,
941 NULL,
942 NULL,
943 NULL,
944 NULL
945 };
946
947 struct inode_operations proc_arraylong_inode_operations = {
948 &proc_arraylong_operations,
949 NULL,
950 NULL,
951 NULL,
952 NULL,
953 NULL,
954 NULL,
955 NULL,
956 NULL,
957 NULL,
958 NULL,
959 NULL,
960 NULL,
961 NULL,
962 NULL
963 };