root/fs/proc/array.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. read_core
  2. read_profile
  3. write_profile
  4. get_loadavg
  5. get_kstat
  6. get_uptime
  7. get_meminfo
  8. get_version
  9. get_cpuinfo
  10. get_task
  11. get_phys_addr
  12. get_array
  13. get_env
  14. get_arg
  15. get_wchan
  16. get_stat
  17. get_statm
  18. get_maps
  19. get_root_array
  20. get_process_array
  21. fill_array
  22. array_read

   1 /*
   2  *  linux/fs/proc/array.c
   3  *
   4  *  Copyright (C) 1992  by Linus Torvalds
   5  *  based on ideas by Darren Senn
   6  *
   7  * Fixes:
   8  * Michael. K. Johnson: stat,statm extensions.
   9  *                      <johnsonm@stolaf.edu>
  10  *
  11  * Pauline Middelink :  Made cmdline,envline only break at '\0's, to
  12  *                      make sure SET_PROCTITLE works. Also removed
  13  *                      bad '!' which forced address recalculation for
  14  *                      EVERY character on the current page.
  15  *                      <middelin@polyware.iaf.nl>
  16  *
  17  * Danny ter Haar    :  Some minor additions for cpuinfo
  18  * <danny@ow.nl>
  19  *
  20  * Alessandro Rubini :  profile extension.
  21  *                      <rubini@ipvvis.unipv.it>
  22  */
  23 
  24 #include <linux/types.h>
  25 #include <linux/errno.h>
  26 #include <linux/sched.h>
  27 #include <linux/kernel.h>
  28 #include <linux/kernel_stat.h>
  29 #include <linux/tty.h>
  30 #include <linux/user.h>
  31 #include <linux/a.out.h>
  32 #include <linux/string.h>
  33 #include <linux/mman.h>
  34 #include <linux/proc_fs.h>
  35 #include <linux/ioport.h>
  36 
  37 #include <asm/segment.h>
  38 #include <asm/io.h>
  39 
  40 #define LOAD_INT(x) ((x) >> FSHIFT)
  41 #define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1-1)) * 100)
  42 
  43 #ifdef CONFIG_DEBUG_MALLOC
  44 int get_malloc(char * buffer);
  45 #endif
  46 
  47 static int read_core(struct inode * inode, struct file * file,char * buf, int count)
     /* [previous][next][first][last][top][bottom][index][help] */
  48 {
  49         unsigned long p = file->f_pos;
  50         int read;
  51         int count1;
  52         char * pnt;
  53         struct user dump;
  54 
  55         memset(&dump, 0, sizeof(struct user));
  56         dump.magic = CMAGIC;
  57         dump.u_dsize = high_memory >> 12;
  58 
  59         if (count < 0)
  60                 return -EINVAL;
  61         if (p >= high_memory + PAGE_SIZE)
  62                 return 0;
  63         if (count > high_memory + PAGE_SIZE - p)
  64                 count = high_memory + PAGE_SIZE - p;
  65         read = 0;
  66 
  67         if (p < sizeof(struct user) && count > 0) {
  68                 count1 = count;
  69                 if (p + count1 > sizeof(struct user))
  70                         count1 = sizeof(struct user)-p;
  71                 pnt = (char *) &dump + p;
  72                 memcpy_tofs(buf,(void *) pnt, count1);
  73                 buf += count1;
  74                 p += count1;
  75                 count -= count1;
  76                 read += count1;
  77         }
  78 
  79         while (p < 2*PAGE_SIZE && count > 0) {
  80                 put_fs_byte(0,buf);
  81                 buf++;
  82                 p++;
  83                 count--;
  84                 read++;
  85         }
  86         memcpy_tofs(buf,(void *) (p - PAGE_SIZE),count);
  87         read += count;
  88         file->f_pos += read;
  89         return read;
  90 }
  91 
  92 static struct file_operations proc_kcore_operations = {
  93         NULL,           /* lseek */
  94         read_core,
  95 };
  96 
  97 struct inode_operations proc_kcore_inode_operations = {
  98         &proc_kcore_operations, 
  99 };
 100 
 101 #ifdef CONFIG_PROFILE
 102 
 103 extern unsigned long prof_len;
 104 extern unsigned long * prof_buffer;
 105 /*
 106  * This function accesses profiling information. The returned data is
 107  * binary: the sampling step and the actual contents of the profile
 108  * buffer. Use of the program readprofile is recommended in order to
 109  * get meaningful info out of these data.
 110  */
 111 static int read_profile(struct inode *inode, struct file *file, char *buf, int count)
     /* [previous][next][first][last][top][bottom][index][help] */
 112 {
 113     unsigned long p = file->f_pos;
 114         int read;
 115         char * pnt;
 116         unsigned long sample_step = 1 << CONFIG_PROFILE_SHIFT;
 117 
 118         if (count < 0)
 119             return -EINVAL;
 120         if (p >= (prof_len+1)*sizeof(unsigned long))
 121             return 0;
 122         if (count > (prof_len+1)*sizeof(unsigned long) - p)
 123             count = (prof_len+1)*sizeof(unsigned long) - p;
 124     read = 0;
 125 
 126     while (p < sizeof(unsigned long) && count > 0) {
 127         put_fs_byte(*((char *)(&sample_step)+p),buf);
 128                 buf++; p++; count--; read++;
 129     }
 130     pnt = (char *)prof_buffer + p - sizeof(unsigned long);
 131         memcpy_tofs(buf,(void *)pnt,count);
 132         read += count;
 133         file->f_pos += read;
 134         return read;
 135 }
 136 
 137 /* Writing to /proc/profile resets the counters */
 138 static int write_profile(struct inode * inode, struct file * file, char * buf, int count)
     /* [previous][next][first][last][top][bottom][index][help] */
 139 {
 140     int i=prof_len;
 141 
 142     while (i--)
 143             prof_buffer[i]=0UL;
 144     return count;
 145 }
 146 
 147 static struct file_operations proc_profile_operations = {
 148         NULL,           /* lseek */
 149         read_profile,
 150         write_profile,
 151 };
 152 
 153 struct inode_operations proc_profile_inode_operations = {
 154         &proc_profile_operations, 
 155 };
 156 
 157 #endif /* CONFIG_PROFILE */
 158 
 159 static int get_loadavg(char * buffer)
     /* [previous][next][first][last][top][bottom][index][help] */
 160 {
 161         int a, b, c;
 162 
 163         a = avenrun[0] + (FIXED_1/200);
 164         b = avenrun[1] + (FIXED_1/200);
 165         c = avenrun[2] + (FIXED_1/200);
 166         return sprintf(buffer,"%d.%02d %d.%02d %d.%02d\n",
 167                 LOAD_INT(a), LOAD_FRAC(a),
 168                 LOAD_INT(b), LOAD_FRAC(b),
 169                 LOAD_INT(c), LOAD_FRAC(c));
 170 }
 171 
 172 static int get_kstat(char * buffer)
     /* [previous][next][first][last][top][bottom][index][help] */
 173 {
 174         int i, len;
 175         unsigned sum = 0;
 176 
 177         for (i = 0 ; i < 16 ; i++)
 178                 sum += kstat.interrupts[i];
 179         len = sprintf(buffer,
 180                 "cpu  %u %u %u %lu\n"
 181                 "disk %u %u %u %u\n"
 182                 "page %u %u\n"
 183                 "swap %u %u\n"
 184                 "intr %u",
 185                 kstat.cpu_user,
 186                 kstat.cpu_nice,
 187                 kstat.cpu_system,
 188                 jiffies - (kstat.cpu_user + kstat.cpu_nice + kstat.cpu_system),
 189                 kstat.dk_drive[0],
 190                 kstat.dk_drive[1],
 191                 kstat.dk_drive[2],
 192                 kstat.dk_drive[3],
 193                 kstat.pgpgin,
 194                 kstat.pgpgout,
 195                 kstat.pswpin,
 196                 kstat.pswpout,
 197                 sum);
 198         for (i = 0 ; i < 16 ; i++)
 199                 len += sprintf(buffer + len, " %u", kstat.interrupts[i]);
 200         len += sprintf(buffer + len,
 201                 "\nctxt %u\n"
 202                 "btime %lu\n",
 203                 kstat.context_swtch,
 204                 xtime.tv_sec - jiffies / HZ);
 205         return len;
 206 }
 207 
 208 
 209 static int get_uptime(char * buffer)
     /* [previous][next][first][last][top][bottom][index][help] */
 210 {
 211         unsigned long uptime;
 212         unsigned long idle;
 213 
 214         uptime = jiffies;
 215         idle = task[0]->utime + task[0]->stime;
 216         return sprintf(buffer,"%lu.%02lu %lu.%02lu\n",
 217                 uptime / HZ,
 218                 uptime % HZ,
 219                 idle / HZ,
 220                 idle % HZ);
 221 }
 222 
 223 static int get_meminfo(char * buffer)
     /* [previous][next][first][last][top][bottom][index][help] */
 224 {
 225         struct sysinfo i;
 226 
 227         si_meminfo(&i);
 228         si_swapinfo(&i);
 229         return sprintf(buffer, "        total:   used:    free:   shared:  buffers:\n"
 230                 "Mem:  %8lu %8lu %8lu %8lu %8lu\n"
 231                 "Swap: %8lu %8lu %8lu\n",
 232                 i.totalram, i.totalram-i.freeram, i.freeram, i.sharedram, i.bufferram,
 233                 i.totalswap, i.totalswap-i.freeswap, i.freeswap);
 234 }
 235 
 236 static int get_version(char * buffer)
     /* [previous][next][first][last][top][bottom][index][help] */
 237 {
 238         extern char *linux_banner;
 239 
 240         strcpy(buffer, linux_banner);
 241         return strlen(buffer);
 242 }
 243 
 244 static int get_cpuinfo(char * buffer)
     /* [previous][next][first][last][top][bottom][index][help] */
 245 {
 246         /* to conserve memory, we define the strins yes and no in
 247            advance */
 248         char *yes="yes";
 249         char *no="no";
 250         char *model[2][9]={{"DX","SX","DX/2","4","SX/2","6",
 251                                 "7","DX/4"},
 252                         {"Pentium 60/66","Pentium 90/100","3",
 253                                 "4","5","6","7","8"}};
 254         return sprintf(buffer,"cpu\t\t: %c86\n"
 255                               "model\t\t: %s\n"
 256                               "mask\t\t: %c\n"
 257                               "vid\t\t: %s\n"
 258                               "fdiv_bug\t: %s\n"
 259                               "math\t\t: %s\n"
 260                               "hlt\t\t: %s\n"
 261                               "wp\t\t: %s\n"
 262                               "Integrated NPU\t: %s\n"
 263                               "Enhanced VM86\t: %s\n"
 264                               "IO Breakpoints\t: %s\n"
 265                               "4MB Pages\t: %s\n"
 266                               "TS Counters\t: %s\n"
 267                               "Pentium MSR\t: %s\n"
 268                               "Mach. Ch. Exep.\t: %s\n"
 269                               "CMPXCHGB8B\t: %s\n",
 270                               x86+'0', 
 271                               x86_model ? model[x86-4][x86_model-1] : "Unknown",
 272                               x86_mask+'@',
 273                               x86_vendor_id,
 274                               fdiv_bug ? yes : no,
 275                               hard_math ? yes : no,
 276                               hlt_works_ok ? yes : no,
 277                               wp_works_ok ? yes : no,
 278                               x86_capability & 1 ? yes : no,
 279                               x86_capability & 2 ? yes : no,
 280                               x86_capability & 4 ? yes : no,
 281                               x86_capability & 8 ? yes : no,
 282                               x86_capability & 16 ? yes : no,
 283                               x86_capability & 32 ? yes : no,
 284                               x86_capability & 128 ? yes : no,
 285                               x86_capability & 256 ? yes : no
 286                               );
 287 }
 288 
 289 static struct task_struct ** get_task(pid_t pid)
     /* [previous][next][first][last][top][bottom][index][help] */
 290 {
 291         struct task_struct ** p;
 292 
 293         p = task;
 294         while (++p < task+NR_TASKS) {
 295                 if (*p && (*p)->pid == pid)
 296                         return p;
 297         }
 298         return NULL;
 299 }
 300 
 301 static unsigned long get_phys_addr(struct task_struct ** p, unsigned long ptr)
     /* [previous][next][first][last][top][bottom][index][help] */
 302 {
 303         unsigned long page;
 304 
 305         if (!p || !*p || ptr >= TASK_SIZE)
 306                 return 0;
 307         page = *PAGE_DIR_OFFSET((*p)->tss.cr3,ptr);
 308         if (!(page & PAGE_PRESENT))
 309                 return 0;
 310         page &= PAGE_MASK;
 311         page += PAGE_PTR(ptr);
 312         page = *(unsigned long *) page;
 313         if (!(page & PAGE_PRESENT))
 314                 return 0;
 315         page &= PAGE_MASK;
 316         page += ptr & ~PAGE_MASK;
 317         return page;
 318 }
 319 
 320 static int get_array(struct task_struct ** p, unsigned long start, unsigned long end, char * buffer)
     /* [previous][next][first][last][top][bottom][index][help] */
 321 {
 322         unsigned long addr;
 323         int size = 0, result = 0;
 324         char c;
 325 
 326         if (start >= end)
 327                 return result;
 328         for (;;) {
 329                 addr = get_phys_addr(p, start);
 330                 if (!addr)
 331                         goto ready;
 332                 do {
 333                         c = *(char *) addr;
 334                         if (!c)
 335                                 result = size;
 336                         if (size < PAGE_SIZE)
 337                                 buffer[size++] = c;
 338                         else
 339                                 goto ready;
 340                         addr++;
 341                         start++;
 342                         if (!c && start >= end)
 343                                 goto ready;
 344                 } while (addr & ~PAGE_MASK);
 345         }
 346 ready:
 347         /* remove the trailing blanks, used to fill out argv,envp space */
 348         while (result>0 && buffer[result-1]==' ')
 349                 result--;
 350         return result;
 351 }
 352 
 353 static int get_env(int pid, char * buffer)
     /* [previous][next][first][last][top][bottom][index][help] */
 354 {
 355         struct task_struct ** p = get_task(pid);
 356 
 357         if (!p || !*p)
 358                 return 0;
 359         return get_array(p, (*p)->mm->env_start, (*p)->mm->env_end, buffer);
 360 }
 361 
 362 static int get_arg(int pid, char * buffer)
     /* [previous][next][first][last][top][bottom][index][help] */
 363 {
 364         struct task_struct ** p = get_task(pid);
 365 
 366         if (!p || !*p)
 367                 return 0;
 368         return get_array(p, (*p)->mm->arg_start, (*p)->mm->arg_end, buffer);
 369 }
 370 
 371 static unsigned long get_wchan(struct task_struct *p)
     /* [previous][next][first][last][top][bottom][index][help] */
 372 {
 373         unsigned long ebp, eip;
 374         unsigned long stack_page;
 375         int count = 0;
 376 
 377         if (!p || p == current || p->state == TASK_RUNNING)
 378                 return 0;
 379         stack_page = p->kernel_stack_page;
 380         if (!stack_page)
 381                 return 0;
 382         ebp = p->tss.ebp;
 383         do {
 384                 if (ebp < stack_page || ebp >= 4092+stack_page)
 385                         return 0;
 386                 eip = *(unsigned long *) (ebp+4);
 387                 if ((void *)eip != sleep_on &&
 388                     (void *)eip != interruptible_sleep_on)
 389                         return eip;
 390                 ebp = *(unsigned long *) ebp;
 391         } while (count++ < 16);
 392         return 0;
 393 }
 394 
 395 #define KSTK_EIP(stack) (((unsigned long *)stack)[1019])
 396 #define KSTK_ESP(stack) (((unsigned long *)stack)[1022])
 397 
 398 static int get_stat(int pid, char * buffer)
     /* [previous][next][first][last][top][bottom][index][help] */
 399 {
 400         struct task_struct ** p = get_task(pid);
 401         unsigned long sigignore=0, sigcatch=0, bit=1, wchan;
 402         unsigned long vsize, eip, esp;
 403         int i,tty_pgrp;
 404         char state;
 405 
 406         if (!p || !*p)
 407                 return 0;
 408         if ((*p)->state < 0 || (*p)->state > 5)
 409                 state = '.';
 410         else
 411                 state = "RSDZTD"[(*p)->state];
 412         eip = esp = 0;
 413         vsize = (*p)->kernel_stack_page;
 414         if (vsize) {
 415                 eip = KSTK_EIP(vsize);
 416                 esp = KSTK_ESP(vsize);
 417                 vsize = (*p)->mm->brk - (*p)->mm->start_code + PAGE_SIZE-1;
 418                 if (esp)
 419                         vsize += TASK_SIZE - esp;
 420         }
 421         wchan = get_wchan(*p);
 422         for(i=0; i<32; ++i) {
 423                 switch((int) (*p)->sigaction[i].sa_handler) {
 424                 case 1: sigignore |= bit; break;
 425                 case 0: break;
 426                 default: sigcatch |= bit;
 427                 } bit <<= 1;
 428         }
 429         if ((*p)->tty)
 430                 tty_pgrp = (*p)->tty->pgrp;
 431         else
 432                 tty_pgrp = -1;
 433         return sprintf(buffer,"%d (%s) %c %d %d %d %d %d %lu %lu \
 434 %lu %lu %lu %ld %ld %ld %ld %ld %ld %lu %lu %ld %lu %lu %u %lu %lu %lu %lu %lu %lu \
 435 %lu %lu %lu %lu\n",
 436                 pid,
 437                 (*p)->comm,
 438                 state,
 439                 (*p)->p_pptr->pid,
 440                 (*p)->pgrp,
 441                 (*p)->session,
 442                 (*p)->tty ? (*p)->tty->device : 0,
 443                 tty_pgrp,
 444                 (*p)->flags,
 445                 (*p)->mm->min_flt,
 446                 (*p)->mm->cmin_flt,
 447                 (*p)->mm->maj_flt,
 448                 (*p)->mm->cmaj_flt,
 449                 (*p)->utime,
 450                 (*p)->stime,
 451                 (*p)->cutime,
 452                 (*p)->cstime,
 453                 (*p)->counter,  /* this is the kernel priority ---
 454                                    subtract 30 in your user-level program. */
 455                 (*p)->priority, /* this is the nice value ---
 456                                    subtract 15 in your user-level program. */
 457                 (*p)->timeout,
 458                 (*p)->it_real_value,
 459                 (*p)->start_time,
 460                 vsize,
 461                 (*p)->mm->rss, /* you might want to shift this left 3 */
 462                 (*p)->rlim[RLIMIT_RSS].rlim_cur,
 463                 (*p)->mm->start_code,
 464                 (*p)->mm->end_code,
 465                 (*p)->mm->start_stack,
 466                 esp,
 467                 eip,
 468                 (*p)->signal,
 469                 (*p)->blocked,
 470                 sigignore,
 471                 sigcatch,
 472                 wchan);
 473 }
 474 
 475 static int get_statm(int pid, char * buffer)
     /* [previous][next][first][last][top][bottom][index][help] */
 476 {
 477         struct task_struct ** p = get_task(pid);
 478         int i, tpag;
 479         int size=0, resident=0, share=0, trs=0, lrs=0, drs=0, dt=0;
 480         unsigned long ptbl, *buf, *pte, *pagedir, map_nr;
 481 
 482         if (!p || !*p)
 483                 return 0;
 484         tpag = (*p)->mm->end_code / PAGE_SIZE;
 485         if ((*p)->state != TASK_ZOMBIE) {
 486           pagedir = (unsigned long *) (*p)->tss.cr3;
 487           for (i = 0; i < 0x300; ++i) {
 488             if ((ptbl = pagedir[i]) == 0) {
 489               tpag -= PTRS_PER_PAGE;
 490               continue;
 491             }
 492             buf = (unsigned long *)(ptbl & PAGE_MASK);
 493             for (pte = buf; pte < (buf + PTRS_PER_PAGE); ++pte) {
 494               if (*pte != 0) {
 495                 ++size;
 496                 if (*pte & 1) {
 497                   ++resident;
 498                   if (tpag > 0)
 499                     ++trs;
 500                   else
 501                     ++drs;
 502                   if (i >= 15 && i < 0x2f0) {
 503                     ++lrs;
 504                     if (*pte & 0x40)
 505                       ++dt;
 506                     else
 507                       --drs;
 508                   }
 509                   map_nr = MAP_NR(*pte);
 510                   if (map_nr < (high_memory / PAGE_SIZE) && mem_map[map_nr] > 1)
 511                     ++share;
 512                 }
 513               }
 514               --tpag;
 515             }
 516           }
 517         }
 518         return sprintf(buffer,"%d %d %d %d %d %d %d\n",
 519                        size, resident, share, trs, lrs, drs, dt);
 520 }
 521 
 522 static int get_maps(int pid, char *buf)
     /* [previous][next][first][last][top][bottom][index][help] */
 523 {
 524         int sz = 0;
 525         struct task_struct **p = get_task(pid);
 526         struct vm_area_struct *map;
 527 
 528         if (!p || !*p)
 529                 return 0;
 530 
 531         for(map = (*p)->mm->mmap; map != NULL; map = map->vm_next) {
 532                 char str[7], *cp = str;
 533                 int flags;
 534                 int end = sz + 80;      /* Length of line */
 535                 dev_t dev;
 536                 unsigned long ino;
 537 
 538                 flags = map->vm_flags;
 539 
 540                 *cp++ = flags & VM_READ ? 'r' : '-';
 541                 *cp++ = flags & VM_WRITE ? 'w' : '-';
 542                 *cp++ = flags & VM_EXEC ? 'x' : '-';
 543                 *cp++ = flags & VM_SHARED ? 's' : 'p';
 544                 *cp++ = 0;
 545                 
 546                 if (end >= PAGE_SIZE) {
 547                         sprintf(buf+sz, "...\n");
 548                         break;
 549                 }
 550                 
 551                 if (map->vm_inode != NULL) {
 552                         dev = map->vm_inode->i_dev;
 553                         ino = map->vm_inode->i_ino;
 554                 } else {
 555                         dev = 0;
 556                         ino = 0;
 557                 }
 558 
 559                 sz += sprintf(buf+sz, "%08lx-%08lx %s %08lx %02x:%02x %lu\n",
 560                               map->vm_start, map->vm_end, str, map->vm_offset,
 561                               MAJOR(dev),MINOR(dev), ino);
 562                 if (sz > end) {
 563                         printk("get_maps: end(%d) < sz(%d)\n", end, sz);
 564                         break;
 565                 }
 566         }
 567         
 568         return sz;
 569 }
 570 
 571 extern int get_module_list(char *);
 572 extern int get_device_list(char *);
 573 extern int get_filesystem_list(char *);
 574 extern int get_ksyms_list(char *);
 575 extern int get_irq_list(char *);
 576 extern int get_dma_list(char *);
 577 extern int get_cpuinfo(char *);
 578 
 579 static int get_root_array(char * page, int type)
     /* [previous][next][first][last][top][bottom][index][help] */
 580 {
 581         switch (type) {
 582                 case PROC_LOADAVG:
 583                         return get_loadavg(page);
 584 
 585                 case PROC_UPTIME:
 586                         return get_uptime(page);
 587 
 588                 case PROC_MEMINFO:
 589                         return get_meminfo(page);
 590 
 591                 case PROC_CPUINFO:
 592                         return get_cpuinfo(page);
 593 
 594                 case PROC_VERSION:
 595                         return get_version(page);
 596 
 597 #ifdef CONFIG_DEBUG_MALLOC
 598                 case PROC_MALLOC:
 599                         return get_malloc(page);
 600 #endif
 601 
 602                 case PROC_MODULES:
 603                         return get_module_list(page);
 604 
 605                 case PROC_STAT:
 606                         return get_kstat(page);
 607 
 608                 case PROC_DEVICES:
 609                         return get_device_list(page);
 610 
 611                 case PROC_INTERRUPTS:
 612                         return get_irq_list(page);
 613 
 614                 case PROC_FILESYSTEMS:
 615                         return get_filesystem_list(page);
 616 
 617                 case PROC_KSYMS:
 618                         return get_ksyms_list(page);
 619 
 620                 case PROC_DMA:
 621                         return get_dma_list(page);
 622 
 623                 case PROC_IOPORTS:
 624                         return get_ioport_list(page);
 625         }
 626         return -EBADF;
 627 }
 628 
 629 static int get_process_array(char * page, int pid, int type)
     /* [previous][next][first][last][top][bottom][index][help] */
 630 {
 631         switch (type) {
 632                 case PROC_PID_ENVIRON:
 633                         return get_env(pid, page);
 634                 case PROC_PID_CMDLINE:
 635                         return get_arg(pid, page);
 636                 case PROC_PID_STAT:
 637                         return get_stat(pid, page);
 638                 case PROC_PID_STATM:
 639                         return get_statm(pid, page);
 640                 case PROC_PID_MAPS:
 641                         return get_maps(pid, page);
 642         }
 643         return -EBADF;
 644 }
 645 
 646 
 647 static inline int fill_array(char * page, int pid, int type)
     /* [previous][next][first][last][top][bottom][index][help] */
 648 {
 649         if (pid)
 650                 return get_process_array(page, pid, type);
 651         return get_root_array(page, type);
 652 }
 653 
 654 static int array_read(struct inode * inode, struct file * file,char * buf, int count)
     /* [previous][next][first][last][top][bottom][index][help] */
 655 {
 656         unsigned long page;
 657         int length;
 658         int end;
 659         unsigned int type, pid;
 660 
 661         if (count < 0)
 662                 return -EINVAL;
 663         if (!(page = __get_free_page(GFP_KERNEL)))
 664                 return -ENOMEM;
 665         type = inode->i_ino;
 666         pid = type >> 16;
 667         type &= 0x0000ffff;
 668         length = fill_array((char *) page, pid, type);
 669         if (length < 0) {
 670                 free_page(page);
 671                 return length;
 672         }
 673         if (file->f_pos >= length) {
 674                 free_page(page);
 675                 return 0;
 676         }
 677         if (count + file->f_pos > length)
 678                 count = length - file->f_pos;
 679         end = count + file->f_pos;
 680         memcpy_tofs(buf, (char *) page + file->f_pos, count);
 681         free_page(page);
 682         file->f_pos = end;
 683         return count;
 684 }
 685 
 686 static struct file_operations proc_array_operations = {
 687         NULL,           /* array_lseek */
 688         array_read,
 689         NULL,           /* array_write */
 690         NULL,           /* array_readdir */
 691         NULL,           /* array_select */
 692         NULL,           /* array_ioctl */
 693         NULL,           /* mmap */
 694         NULL,           /* no special open code */
 695         NULL,           /* no special release code */
 696         NULL            /* can't fsync */
 697 };
 698 
 699 struct inode_operations proc_array_inode_operations = {
 700         &proc_array_operations, /* default base directory file-ops */
 701         NULL,                   /* create */
 702         NULL,                   /* lookup */
 703         NULL,                   /* link */
 704         NULL,                   /* unlink */
 705         NULL,                   /* symlink */
 706         NULL,                   /* mkdir */
 707         NULL,                   /* rmdir */
 708         NULL,                   /* mknod */
 709         NULL,                   /* rename */
 710         NULL,                   /* readlink */
 711         NULL,                   /* follow_link */
 712         NULL,                   /* bmap */
 713         NULL,                   /* truncate */
 714         NULL                    /* permission */
 715 };

/* [previous][next][first][last][top][bottom][index][help] */