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 
 217         /* The formula for the fraction parts really is ((t * 100) / HZ) % 100, but
 218            that would overflow about every five days at HZ == 100.
 219            Therefore the identity a = (a / b) * b + a % b is used so that it is
 220            calculated as (((t / HZ) * 100) + ((t % HZ) * 100) / HZ) % 100.
 221            The part in front of the '+' always evaluates as 0 (mod 100). All divisions
 222            in the above formulas are truncating. For HZ being a power of 10, the
 223            calculations simplify to the version in the #else part (if the printf
 224            format is adapted to the same number of digits as zeroes in HZ.
 225          */
 226 #if HZ!=100
 227         return sprintf(buffer,"%lu.%02lu %lu.%02lu\n",
 228                 uptime / HZ,
 229                 (((uptime % HZ) * 100) / HZ) % 100,
 230                 idle / HZ,
 231                 (((idle % HZ) * 100) / HZ) % 100);
 232 #else
 233         return sprintf(buffer,"%lu.%02lu %lu.%02lu\n",
 234                 uptime / HZ,
 235                 uptime % HZ,
 236                 idle / HZ,
 237                 idle % HZ);
 238 #endif
 239 }
 240 
 241 static int get_meminfo(char * buffer)
     /* [previous][next][first][last][top][bottom][index][help] */
 242 {
 243         struct sysinfo i;
 244 
 245         si_meminfo(&i);
 246         si_swapinfo(&i);
 247         return sprintf(buffer, "        total:   used:    free:   shared:  buffers:\n"
 248                 "Mem:  %8lu %8lu %8lu %8lu %8lu\n"
 249                 "Swap: %8lu %8lu %8lu\n",
 250                 i.totalram, i.totalram-i.freeram, i.freeram, i.sharedram, i.bufferram,
 251                 i.totalswap, i.totalswap-i.freeswap, i.freeswap);
 252 }
 253 
 254 static int get_version(char * buffer)
     /* [previous][next][first][last][top][bottom][index][help] */
 255 {
 256         extern char *linux_banner;
 257 
 258         strcpy(buffer, linux_banner);
 259         return strlen(buffer);
 260 }
 261 
 262 static int get_cpuinfo(char * buffer)
     /* [previous][next][first][last][top][bottom][index][help] */
 263 {
 264         char *model[2][9]={{"DX","SX","DX/2","4","SX/2","6",
 265                                 "7","DX/4"},
 266                         {"Pentium 60/66","Pentium 90/100","3",
 267                                 "4","5","6","7","8"}};
 268         char mask[2];
 269         mask[0] = x86_mask+'@';
 270         mask[1] = '\0';
 271         return sprintf(buffer,"cpu\t\t: %c86\n"
 272                               "model\t\t: %s\n"
 273                               "mask\t\t: %s\n"
 274                               "vid\t\t: %s\n"
 275                               "fdiv_bug\t: %s\n"
 276                               "math\t\t: %s\n"
 277                               "hlt\t\t: %s\n"
 278                               "wp\t\t: %s\n"
 279                               "Integrated NPU\t: %s\n"
 280                               "Enhanced VM86\t: %s\n"
 281                               "IO Breakpoints\t: %s\n"
 282                               "4MB Pages\t: %s\n"
 283                               "TS Counters\t: %s\n"
 284                               "Pentium MSR\t: %s\n"
 285                               "Mach. Ch. Exep.\t: %s\n"
 286                               "CMPXCHGB8B\t: %s\n",
 287                               x86+'0', 
 288                               x86_model ? model[x86-4][x86_model-1] : "Unknown",
 289                               x86_mask ? mask : "Unknown",
 290                               x86_vendor_id,
 291                               fdiv_bug ? "yes" : "no",
 292                               hard_math ? "yes" : "no",
 293                               hlt_works_ok ? "yes" : "no",
 294                               wp_works_ok ? "yes" : "no",
 295                               x86_capability & 1 ? "yes" : "no",
 296                               x86_capability & 2 ? "yes" : "no",
 297                               x86_capability & 4 ? "yes" : "no",
 298                               x86_capability & 8 ? "yes" : "no",
 299                               x86_capability & 16 ? "yes" : "no",
 300                               x86_capability & 32 ? "yes" : "no",
 301                               x86_capability & 128 ? "yes" : "no",
 302                               x86_capability & 256 ? "yes" : "no"
 303                               );
 304 }
 305 
 306 static struct task_struct ** get_task(pid_t pid)
     /* [previous][next][first][last][top][bottom][index][help] */
 307 {
 308         struct task_struct ** p;
 309 
 310         p = task;
 311         while (++p < task+NR_TASKS) {
 312                 if (*p && (*p)->pid == pid)
 313                         return p;
 314         }
 315         return NULL;
 316 }
 317 
 318 static unsigned long get_phys_addr(struct task_struct ** p, unsigned long ptr)
     /* [previous][next][first][last][top][bottom][index][help] */
 319 {
 320         unsigned long page;
 321 
 322         if (!p || !*p || ptr >= TASK_SIZE)
 323                 return 0;
 324         page = *PAGE_DIR_OFFSET((*p)->tss.cr3,ptr);
 325         if (!(page & PAGE_PRESENT))
 326                 return 0;
 327         page &= PAGE_MASK;
 328         page += PAGE_PTR(ptr);
 329         page = *(unsigned long *) page;
 330         if (!(page & PAGE_PRESENT))
 331                 return 0;
 332         page &= PAGE_MASK;
 333         page += ptr & ~PAGE_MASK;
 334         return page;
 335 }
 336 
 337 static int get_array(struct task_struct ** p, unsigned long start, unsigned long end, char * buffer)
     /* [previous][next][first][last][top][bottom][index][help] */
 338 {
 339         unsigned long addr;
 340         int size = 0, result = 0;
 341         char c;
 342 
 343         if (start >= end)
 344                 return result;
 345         for (;;) {
 346                 addr = get_phys_addr(p, start);
 347                 if (!addr)
 348                         goto ready;
 349                 do {
 350                         c = *(char *) addr;
 351                         if (!c)
 352                                 result = size;
 353                         if (size < PAGE_SIZE)
 354                                 buffer[size++] = c;
 355                         else
 356                                 goto ready;
 357                         addr++;
 358                         start++;
 359                         if (!c && start >= end)
 360                                 goto ready;
 361                 } while (addr & ~PAGE_MASK);
 362         }
 363 ready:
 364         /* remove the trailing blanks, used to fill out argv,envp space */
 365         while (result>0 && buffer[result-1]==' ')
 366                 result--;
 367         return result;
 368 }
 369 
 370 static int get_env(int pid, char * buffer)
     /* [previous][next][first][last][top][bottom][index][help] */
 371 {
 372         struct task_struct ** p = get_task(pid);
 373 
 374         if (!p || !*p)
 375                 return 0;
 376         return get_array(p, (*p)->mm->env_start, (*p)->mm->env_end, buffer);
 377 }
 378 
 379 static int get_arg(int pid, char * buffer)
     /* [previous][next][first][last][top][bottom][index][help] */
 380 {
 381         struct task_struct ** p = get_task(pid);
 382 
 383         if (!p || !*p)
 384                 return 0;
 385         return get_array(p, (*p)->mm->arg_start, (*p)->mm->arg_end, buffer);
 386 }
 387 
 388 static unsigned long get_wchan(struct task_struct *p)
     /* [previous][next][first][last][top][bottom][index][help] */
 389 {
 390         unsigned long ebp, eip;
 391         unsigned long stack_page;
 392         int count = 0;
 393 
 394         if (!p || p == current || p->state == TASK_RUNNING)
 395                 return 0;
 396         stack_page = p->kernel_stack_page;
 397         if (!stack_page)
 398                 return 0;
 399         ebp = p->tss.ebp;
 400         do {
 401                 if (ebp < stack_page || ebp >= 4092+stack_page)
 402                         return 0;
 403                 eip = *(unsigned long *) (ebp+4);
 404                 if ((void *)eip != sleep_on &&
 405                     (void *)eip != interruptible_sleep_on)
 406                         return eip;
 407                 ebp = *(unsigned long *) ebp;
 408         } while (count++ < 16);
 409         return 0;
 410 }
 411 
 412 #define KSTK_EIP(stack) (((unsigned long *)stack)[1019])
 413 #define KSTK_ESP(stack) (((unsigned long *)stack)[1022])
 414 
 415 static int get_stat(int pid, char * buffer)
     /* [previous][next][first][last][top][bottom][index][help] */
 416 {
 417         struct task_struct ** p = get_task(pid);
 418         unsigned long sigignore=0, sigcatch=0, bit=1, wchan;
 419         unsigned long vsize, eip, esp;
 420         int i,tty_pgrp;
 421         char state;
 422 
 423         if (!p || !*p)
 424                 return 0;
 425         if ((*p)->state < 0 || (*p)->state > 5)
 426                 state = '.';
 427         else
 428                 state = "RSDZTD"[(*p)->state];
 429         eip = esp = 0;
 430         vsize = (*p)->kernel_stack_page;
 431         if (vsize) {
 432                 eip = KSTK_EIP(vsize);
 433                 esp = KSTK_ESP(vsize);
 434                 vsize = (*p)->mm->brk - (*p)->mm->start_code + PAGE_SIZE-1;
 435                 if (esp)
 436                         vsize += TASK_SIZE - esp;
 437         }
 438         wchan = get_wchan(*p);
 439         for(i=0; i<32; ++i) {
 440                 switch((int) (*p)->sigaction[i].sa_handler) {
 441                 case 1: sigignore |= bit; break;
 442                 case 0: break;
 443                 default: sigcatch |= bit;
 444                 } bit <<= 1;
 445         }
 446         if ((*p)->tty)
 447                 tty_pgrp = (*p)->tty->pgrp;
 448         else
 449                 tty_pgrp = -1;
 450         return sprintf(buffer,"%d (%s) %c %d %d %d %d %d %lu %lu \
 451 %lu %lu %lu %ld %ld %ld %ld %ld %ld %lu %lu %ld %lu %lu %lu %lu %lu %lu %lu %lu %lu \
 452 %lu %lu %lu %lu\n",
 453                 pid,
 454                 (*p)->comm,
 455                 state,
 456                 (*p)->p_pptr->pid,
 457                 (*p)->pgrp,
 458                 (*p)->session,
 459                 (*p)->tty ? (*p)->tty->device : 0,
 460                 tty_pgrp,
 461                 (*p)->flags,
 462                 (*p)->mm->min_flt,
 463                 (*p)->mm->cmin_flt,
 464                 (*p)->mm->maj_flt,
 465                 (*p)->mm->cmaj_flt,
 466                 (*p)->utime,
 467                 (*p)->stime,
 468                 (*p)->cutime,
 469                 (*p)->cstime,
 470                 (*p)->counter,  /* this is the kernel priority ---
 471                                    subtract 30 in your user-level program. */
 472                 (*p)->priority, /* this is the nice value ---
 473                                    subtract 15 in your user-level program. */
 474                 (*p)->timeout,
 475                 (*p)->it_real_value,
 476                 (*p)->start_time,
 477                 vsize,
 478                 (*p)->mm->rss, /* you might want to shift this left 3 */
 479                 (*p)->rlim[RLIMIT_RSS].rlim_cur,
 480                 (*p)->mm->start_code,
 481                 (*p)->mm->end_code,
 482                 (*p)->mm->start_stack,
 483                 esp,
 484                 eip,
 485                 (*p)->signal,
 486                 (*p)->blocked,
 487                 sigignore,
 488                 sigcatch,
 489                 wchan);
 490 }
 491 
 492 static int get_statm(int pid, char * buffer)
     /* [previous][next][first][last][top][bottom][index][help] */
 493 {
 494         struct task_struct ** p = get_task(pid);
 495         int i, tpag;
 496         int size=0, resident=0, share=0, trs=0, lrs=0, drs=0, dt=0;
 497         unsigned long ptbl, *buf, *pte, *pagedir, map_nr;
 498 
 499         if (!p || !*p)
 500                 return 0;
 501         tpag = (*p)->mm->end_code / PAGE_SIZE;
 502         if ((*p)->state != TASK_ZOMBIE) {
 503           pagedir = (unsigned long *) (*p)->tss.cr3;
 504           for (i = 0; i < 0x300; ++i) {
 505             if ((ptbl = pagedir[i]) == 0) {
 506               tpag -= PTRS_PER_PAGE;
 507               continue;
 508             }
 509             buf = (unsigned long *)(ptbl & PAGE_MASK);
 510             for (pte = buf; pte < (buf + PTRS_PER_PAGE); ++pte) {
 511               if (*pte != 0) {
 512                 ++size;
 513                 if (*pte & 1) {
 514                   ++resident;
 515                   if (tpag > 0)
 516                     ++trs;
 517                   else
 518                     ++drs;
 519                   if (i >= 15 && i < 0x2f0) {
 520                     ++lrs;
 521                     if (*pte & 0x40)
 522                       ++dt;
 523                     else
 524                       --drs;
 525                   }
 526                   map_nr = MAP_NR(*pte);
 527                   if (map_nr < (high_memory / PAGE_SIZE) && mem_map[map_nr] > 1)
 528                     ++share;
 529                 }
 530               }
 531               --tpag;
 532             }
 533           }
 534         }
 535         return sprintf(buffer,"%d %d %d %d %d %d %d\n",
 536                        size, resident, share, trs, lrs, drs, dt);
 537 }
 538 
 539 static int get_maps(int pid, char *buf)
     /* [previous][next][first][last][top][bottom][index][help] */
 540 {
 541         int sz = 0;
 542         struct task_struct **p = get_task(pid);
 543         struct vm_area_struct *map;
 544 
 545         if (!p || !*p)
 546                 return 0;
 547 
 548         for(map = (*p)->mm->mmap; map != NULL; map = map->vm_next) {
 549                 char str[7], *cp = str;
 550                 int flags;
 551                 int end = sz + 80;      /* Length of line */
 552                 dev_t dev;
 553                 unsigned long ino;
 554 
 555                 flags = map->vm_flags;
 556 
 557                 *cp++ = flags & VM_READ ? 'r' : '-';
 558                 *cp++ = flags & VM_WRITE ? 'w' : '-';
 559                 *cp++ = flags & VM_EXEC ? 'x' : '-';
 560                 *cp++ = flags & VM_SHARED ? 's' : 'p';
 561                 *cp++ = 0;
 562                 
 563                 if (end >= PAGE_SIZE) {
 564                         sprintf(buf+sz, "...\n");
 565                         break;
 566                 }
 567                 
 568                 if (map->vm_inode != NULL) {
 569                         dev = map->vm_inode->i_dev;
 570                         ino = map->vm_inode->i_ino;
 571                 } else {
 572                         dev = 0;
 573                         ino = 0;
 574                 }
 575 
 576                 sz += sprintf(buf+sz, "%08lx-%08lx %s %08lx %02x:%02x %lu\n",
 577                               map->vm_start, map->vm_end, str, map->vm_offset,
 578                               MAJOR(dev),MINOR(dev), ino);
 579                 if (sz > end) {
 580                         printk("get_maps: end(%d) < sz(%d)\n", end, sz);
 581                         break;
 582                 }
 583         }
 584         
 585         return sz;
 586 }
 587 
 588 extern int get_module_list(char *);
 589 extern int get_device_list(char *);
 590 extern int get_filesystem_list(char *);
 591 extern int get_ksyms_list(char *);
 592 extern int get_irq_list(char *);
 593 extern int get_dma_list(char *);
 594 extern int get_cpuinfo(char *);
 595 
 596 static int get_root_array(char * page, int type)
     /* [previous][next][first][last][top][bottom][index][help] */
 597 {
 598         switch (type) {
 599                 case PROC_LOADAVG:
 600                         return get_loadavg(page);
 601 
 602                 case PROC_UPTIME:
 603                         return get_uptime(page);
 604 
 605                 case PROC_MEMINFO:
 606                         return get_meminfo(page);
 607 
 608                 case PROC_CPUINFO:
 609                         return get_cpuinfo(page);
 610 
 611                 case PROC_VERSION:
 612                         return get_version(page);
 613 
 614 #ifdef CONFIG_DEBUG_MALLOC
 615                 case PROC_MALLOC:
 616                         return get_malloc(page);
 617 #endif
 618 
 619                 case PROC_MODULES:
 620                         return get_module_list(page);
 621 
 622                 case PROC_STAT:
 623                         return get_kstat(page);
 624 
 625                 case PROC_DEVICES:
 626                         return get_device_list(page);
 627 
 628                 case PROC_INTERRUPTS:
 629                         return get_irq_list(page);
 630 
 631                 case PROC_FILESYSTEMS:
 632                         return get_filesystem_list(page);
 633 
 634                 case PROC_KSYMS:
 635                         return get_ksyms_list(page);
 636 
 637                 case PROC_DMA:
 638                         return get_dma_list(page);
 639 
 640                 case PROC_IOPORTS:
 641                         return get_ioport_list(page);
 642         }
 643         return -EBADF;
 644 }
 645 
 646 static int get_process_array(char * page, int pid, int type)
     /* [previous][next][first][last][top][bottom][index][help] */
 647 {
 648         switch (type) {
 649                 case PROC_PID_ENVIRON:
 650                         return get_env(pid, page);
 651                 case PROC_PID_CMDLINE:
 652                         return get_arg(pid, page);
 653                 case PROC_PID_STAT:
 654                         return get_stat(pid, page);
 655                 case PROC_PID_STATM:
 656                         return get_statm(pid, page);
 657                 case PROC_PID_MAPS:
 658                         return get_maps(pid, page);
 659         }
 660         return -EBADF;
 661 }
 662 
 663 
 664 static inline int fill_array(char * page, int pid, int type)
     /* [previous][next][first][last][top][bottom][index][help] */
 665 {
 666         if (pid)
 667                 return get_process_array(page, pid, type);
 668         return get_root_array(page, type);
 669 }
 670 
 671 static int array_read(struct inode * inode, struct file * file,char * buf, int count)
     /* [previous][next][first][last][top][bottom][index][help] */
 672 {
 673         unsigned long page;
 674         int length;
 675         int end;
 676         unsigned int type, pid;
 677 
 678         if (count < 0)
 679                 return -EINVAL;
 680         if (!(page = __get_free_page(GFP_KERNEL)))
 681                 return -ENOMEM;
 682         type = inode->i_ino;
 683         pid = type >> 16;
 684         type &= 0x0000ffff;
 685         length = fill_array((char *) page, pid, type);
 686         if (length < 0) {
 687                 free_page(page);
 688                 return length;
 689         }
 690         if (file->f_pos >= length) {
 691                 free_page(page);
 692                 return 0;
 693         }
 694         if (count + file->f_pos > length)
 695                 count = length - file->f_pos;
 696         end = count + file->f_pos;
 697         memcpy_tofs(buf, (char *) page + file->f_pos, count);
 698         free_page(page);
 699         file->f_pos = end;
 700         return count;
 701 }
 702 
 703 static struct file_operations proc_array_operations = {
 704         NULL,           /* array_lseek */
 705         array_read,
 706         NULL,           /* array_write */
 707         NULL,           /* array_readdir */
 708         NULL,           /* array_select */
 709         NULL,           /* array_ioctl */
 710         NULL,           /* mmap */
 711         NULL,           /* no special open code */
 712         NULL,           /* no special release code */
 713         NULL            /* can't fsync */
 714 };
 715 
 716 struct inode_operations proc_array_inode_operations = {
 717         &proc_array_operations, /* default base directory file-ops */
 718         NULL,                   /* create */
 719         NULL,                   /* lookup */
 720         NULL,                   /* link */
 721         NULL,                   /* unlink */
 722         NULL,                   /* symlink */
 723         NULL,                   /* mkdir */
 724         NULL,                   /* rmdir */
 725         NULL,                   /* mknod */
 726         NULL,                   /* rename */
 727         NULL,                   /* readlink */
 728         NULL,                   /* follow_link */
 729         NULL,                   /* bmap */
 730         NULL,                   /* truncate */
 731         NULL                    /* permission */
 732 };

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