~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/fs/proc/proc_misc.c

Version: ~ [ linux-5.8 ] ~ [ linux-5.7.14 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.57 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.138 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.193 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.232 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.232 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.85 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  *  linux/fs/proc/proc_misc.c
  3  *
  4  *  linux/fs/proc/array.c
  5  *  Copyright (C) 1992  by Linus Torvalds
  6  *  based on ideas by Darren Senn
  7  *
  8  *  This used to be the part of array.c. See the rest of history and credits
  9  *  there. I took this into a separate file and switched the thing to generic
 10  *  proc_file_inode_operations, leaving in array.c only per-process stuff.
 11  *  Inumbers allocation made dynamic (via create_proc_entry()).  AV, May 1999.
 12  *
 13  * Changes:
 14  * Fulton Green      :  Encapsulated position metric calculations.
 15  *                      <kernel@FultonGreen.com>
 16  */
 17 
 18 #include <linux/types.h>
 19 #include <linux/errno.h>
 20 #include <linux/time.h>
 21 #include <linux/kernel.h>
 22 #include <linux/kernel_stat.h>
 23 #include <linux/tty.h>
 24 #include <linux/string.h>
 25 #include <linux/mman.h>
 26 #include <linux/proc_fs.h>
 27 #include <linux/ioport.h>
 28 #include <linux/config.h>
 29 #include <linux/mm.h>
 30 #include <linux/mmzone.h>
 31 #include <linux/pagemap.h>
 32 #include <linux/swap.h>
 33 #include <linux/slab.h>
 34 #include <linux/smp.h>
 35 #include <linux/signal.h>
 36 #include <linux/module.h>
 37 #include <linux/init.h>
 38 #include <linux/smp_lock.h>
 39 #include <linux/seq_file.h>
 40 #include <linux/times.h>
 41 #include <linux/profile.h>
 42 #include <linux/blkdev.h>
 43 #include <linux/hugetlb.h>
 44 #include <linux/jiffies.h>
 45 #include <linux/sysrq.h>
 46 #include <linux/vmalloc.h>
 47 #include <asm/uaccess.h>
 48 #include <asm/pgtable.h>
 49 #include <asm/io.h>
 50 #include <asm/pgalloc.h>
 51 #include <asm/tlb.h>
 52 #include <asm/div64.h>
 53 
 54 #define LOAD_INT(x) ((x) >> FSHIFT)
 55 #define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1-1)) * 100)
 56 /*
 57  * Warning: stuff below (imported functions) assumes that its output will fit
 58  * into one page. For some of those functions it may be wrong. Moreover, we
 59  * have a way to deal with that gracefully. Right now I used straightforward
 60  * wrappers, but this needs further analysis wrt potential overflows.
 61  */
 62 extern int get_hardware_list(char *);
 63 extern int get_stram_list(char *);
 64 extern int get_chrdev_list(char *);
 65 extern int get_blkdev_list(char *);
 66 extern int get_filesystem_list(char *);
 67 extern int get_exec_domain_list(char *);
 68 extern int get_dma_list(char *);
 69 extern int get_locks_status (char *, char **, off_t, int);
 70 #ifdef CONFIG_SGI_DS1286
 71 extern int get_ds1286_status(char *);
 72 #endif
 73 
 74 static int proc_calc_metrics(char *page, char **start, off_t off,
 75                                  int count, int *eof, int len)
 76 {
 77         if (len <= off+count) *eof = 1;
 78         *start = page + off;
 79         len -= off;
 80         if (len>count) len = count;
 81         if (len<0) len = 0;
 82         return len;
 83 }
 84 
 85 static int loadavg_read_proc(char *page, char **start, off_t off,
 86                                  int count, int *eof, void *data)
 87 {
 88         int a, b, c;
 89         int len;
 90 
 91         a = avenrun[0] + (FIXED_1/200);
 92         b = avenrun[1] + (FIXED_1/200);
 93         c = avenrun[2] + (FIXED_1/200);
 94         len = sprintf(page,"%d.%02d %d.%02d %d.%02d %ld/%d %d\n",
 95                 LOAD_INT(a), LOAD_FRAC(a),
 96                 LOAD_INT(b), LOAD_FRAC(b),
 97                 LOAD_INT(c), LOAD_FRAC(c),
 98                 nr_running(), nr_threads, last_pid);
 99         return proc_calc_metrics(page, start, off, count, eof, len);
100 }
101 
102 struct vmalloc_info {
103         unsigned long used;
104         unsigned long largest_chunk;
105 };
106 
107 static struct vmalloc_info get_vmalloc_info(void)
108 {
109         unsigned long prev_end = VMALLOC_START;
110         struct vm_struct* vma;
111         struct vmalloc_info vmi;
112         vmi.used = 0;
113 
114         read_lock(&vmlist_lock);
115 
116         if(!vmlist)
117                 vmi.largest_chunk = (VMALLOC_END-VMALLOC_START);
118         else
119                 vmi.largest_chunk = 0;
120 
121         for (vma = vmlist; vma; vma = vma->next) {
122                 unsigned long free_area_size =
123                         (unsigned long)vma->addr - prev_end;
124                 vmi.used += vma->size;
125                 if (vmi.largest_chunk < free_area_size )
126 
127                         vmi.largest_chunk = free_area_size;
128                 prev_end = vma->size + (unsigned long)vma->addr;
129         }
130         if(VMALLOC_END-prev_end > vmi.largest_chunk)
131                 vmi.largest_chunk = VMALLOC_END-prev_end;
132 
133         read_unlock(&vmlist_lock);
134         return vmi;
135 }
136 
137 static int uptime_read_proc(char *page, char **start, off_t off,
138                                  int count, int *eof, void *data)
139 {
140         struct timespec uptime;
141         struct timespec idle;
142         int len;
143         u64 idle_jiffies = init_task.utime + init_task.stime;
144 
145         do_posix_clock_monotonic_gettime(&uptime);
146         jiffies_to_timespec(idle_jiffies, &idle);
147         len = sprintf(page,"%lu.%02lu %lu.%02lu\n",
148                         (unsigned long) uptime.tv_sec,
149                         (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
150                         (unsigned long) idle.tv_sec,
151                         (idle.tv_nsec / (NSEC_PER_SEC / 100)));
152 
153         return proc_calc_metrics(page, start, off, count, eof, len);
154 }
155 
156 static int meminfo_read_proc(char *page, char **start, off_t off,
157                                  int count, int *eof, void *data)
158 {
159         struct sysinfo i;
160         int len, committed;
161         struct page_state ps;
162         unsigned long inactive;
163         unsigned long active;
164         unsigned long free;
165         unsigned long vmtot;
166         struct vmalloc_info vmi;
167 
168         get_page_state(&ps);
169         get_zone_counts(&active, &inactive, &free);
170 
171 /*
172  * display in kilobytes.
173  */
174 #define K(x) ((x) << (PAGE_SHIFT - 10))
175         si_meminfo(&i);
176         si_swapinfo(&i);
177         committed = atomic_read(&vm_committed_space);
178 
179         vmtot = (VMALLOC_END-VMALLOC_START)>>10;
180         vmi = get_vmalloc_info();
181         vmi.used >>= 10;
182         vmi.largest_chunk >>= 10;
183 
184         /*
185          * Tagged format, for easy grepping and expansion.
186          */
187         len = sprintf(page,
188                 "MemTotal:     %8lu kB\n"
189                 "MemFree:      %8lu kB\n"
190                 "Buffers:      %8lu kB\n"
191                 "Cached:       %8lu kB\n"
192                 "SwapCached:   %8lu kB\n"
193                 "Active:       %8lu kB\n"
194                 "Inactive:     %8lu kB\n"
195                 "HighTotal:    %8lu kB\n"
196                 "HighFree:     %8lu kB\n"
197                 "LowTotal:     %8lu kB\n"
198                 "LowFree:      %8lu kB\n"
199                 "SwapTotal:    %8lu kB\n"
200                 "SwapFree:     %8lu kB\n"
201                 "Dirty:        %8lu kB\n"
202                 "Writeback:    %8lu kB\n"
203                 "Mapped:       %8lu kB\n"
204                 "Slab:         %8lu kB\n"
205                 "Committed_AS: %8u kB\n"
206                 "PageTables:   %8lu kB\n"
207                 "VmallocTotal: %8lu kB\n"
208                 "VmallocUsed:  %8lu kB\n"
209                 "VmallocChunk: %8lu kB\n",
210                 K(i.totalram),
211                 K(i.freeram),
212                 K(i.bufferram),
213                 K(get_page_cache_size()-total_swapcache_pages-i.bufferram),
214                 K(total_swapcache_pages),
215                 K(active),
216                 K(inactive),
217                 K(i.totalhigh),
218                 K(i.freehigh),
219                 K(i.totalram-i.totalhigh),
220                 K(i.freeram-i.freehigh),
221                 K(i.totalswap),
222                 K(i.freeswap),
223                 K(ps.nr_dirty),
224                 K(ps.nr_writeback),
225                 K(ps.nr_mapped),
226                 K(ps.nr_slab),
227                 K(committed),
228                 K(ps.nr_page_table_pages),
229                 vmtot,
230                 vmi.used,
231                 vmi.largest_chunk
232                 );
233 
234                 len += hugetlb_report_meminfo(page + len);
235 
236         return proc_calc_metrics(page, start, off, count, eof, len);
237 #undef K
238 }
239 
240 extern struct seq_operations fragmentation_op;
241 static int fragmentation_open(struct inode *inode, struct file *file)
242 {
243         (void)inode;
244         return seq_open(file, &fragmentation_op);
245 }
246 
247 static struct file_operations fragmentation_file_operations = {
248         .open           = fragmentation_open,
249         .read           = seq_read,
250         .llseek         = seq_lseek,
251         .release        = seq_release,
252 };
253 
254 static int version_read_proc(char *page, char **start, off_t off,
255                                  int count, int *eof, void *data)
256 {
257         extern char *linux_banner;
258         int len;
259 
260         strcpy(page, linux_banner);
261         len = strlen(page);
262         return proc_calc_metrics(page, start, off, count, eof, len);
263 }
264 
265 extern struct seq_operations cpuinfo_op;
266 static int cpuinfo_open(struct inode *inode, struct file *file)
267 {
268         return seq_open(file, &cpuinfo_op);
269 }
270 static struct file_operations proc_cpuinfo_operations = {
271         .open           = cpuinfo_open,
272         .read           = seq_read,
273         .llseek         = seq_lseek,
274         .release        = seq_release,
275 };
276 
277 extern struct seq_operations vmstat_op;
278 static int vmstat_open(struct inode *inode, struct file *file)
279 {
280         return seq_open(file, &vmstat_op);
281 }
282 static struct file_operations proc_vmstat_file_operations = {
283         .open           = vmstat_open,
284         .read           = seq_read,
285         .llseek         = seq_lseek,
286         .release        = seq_release,
287 };
288 
289 #ifdef CONFIG_PROC_HARDWARE
290 static int hardware_read_proc(char *page, char **start, off_t off,
291                                  int count, int *eof, void *data)
292 {
293         int len = get_hardware_list(page);
294         return proc_calc_metrics(page, start, off, count, eof, len);
295 }
296 #endif
297 
298 #ifdef CONFIG_STRAM_PROC
299 static int stram_read_proc(char *page, char **start, off_t off,
300                                  int count, int *eof, void *data)
301 {
302         int len = get_stram_list(page);
303         return proc_calc_metrics(page, start, off, count, eof, len);
304 }
305 #endif
306 
307 extern struct seq_operations partitions_op;
308 static int partitions_open(struct inode *inode, struct file *file)
309 {
310         return seq_open(file, &partitions_op);
311 }
312 static struct file_operations proc_partitions_operations = {
313         .open           = partitions_open,
314         .read           = seq_read,
315         .llseek         = seq_lseek,
316         .release        = seq_release,
317 };
318 
319 extern struct seq_operations diskstats_op;
320 static int diskstats_open(struct inode *inode, struct file *file)
321 {
322         return seq_open(file, &diskstats_op);
323 }
324 static struct file_operations proc_diskstats_operations = {
325         .open           = diskstats_open,
326         .read           = seq_read,
327         .llseek         = seq_lseek,
328         .release        = seq_release,
329 };
330 
331 #ifdef CONFIG_MODULES
332 extern struct seq_operations modules_op;
333 static int modules_open(struct inode *inode, struct file *file)
334 {
335         return seq_open(file, &modules_op);
336 }
337 static struct file_operations proc_modules_operations = {
338         .open           = modules_open,
339         .read           = seq_read,
340         .llseek         = seq_lseek,
341         .release        = seq_release,
342 };
343 #endif
344 
345 extern struct seq_operations slabinfo_op;
346 extern ssize_t slabinfo_write(struct file *, const char __user *, size_t, loff_t *);
347 static int slabinfo_open(struct inode *inode, struct file *file)
348 {
349         return seq_open(file, &slabinfo_op);
350 }
351 static struct file_operations proc_slabinfo_operations = {
352         .open           = slabinfo_open,
353         .read           = seq_read,
354         .write          = slabinfo_write,
355         .llseek         = seq_lseek,
356         .release        = seq_release,
357 };
358 
359 int show_stat(struct seq_file *p, void *v)
360 {
361         int i;
362         extern unsigned long total_forks;
363         u64 jif;
364         unsigned int sum = 0, user = 0, nice = 0, system = 0, idle = 0, iowait = 0, irq = 0, softirq = 0;
365         struct timeval now; 
366         unsigned long seq;
367 
368         /* Atomically read jiffies and time of day */ 
369         do {
370                 seq = read_seqbegin(&xtime_lock);
371 
372                 jif = get_jiffies_64();
373                 do_gettimeofday(&now);
374         } while (read_seqretry(&xtime_lock, seq));
375 
376         /* calc # of seconds since boot time */
377         jif -= INITIAL_JIFFIES;
378         jif = ((u64)now.tv_sec * HZ) + (now.tv_usec/(1000000/HZ)) - jif;
379         do_div(jif, HZ);
380 
381         for (i = 0; i < NR_CPUS; i++) {
382                 int j;
383 
384                 if (!cpu_online(i)) continue;
385                 user += kstat_cpu(i).cpustat.user;
386                 nice += kstat_cpu(i).cpustat.nice;
387                 system += kstat_cpu(i).cpustat.system;
388                 idle += kstat_cpu(i).cpustat.idle;
389                 iowait += kstat_cpu(i).cpustat.iowait;
390                 irq += kstat_cpu(i).cpustat.irq;
391                 softirq += kstat_cpu(i).cpustat.softirq;
392                 for (j = 0 ; j < NR_IRQS ; j++)
393                         sum += kstat_cpu(i).irqs[j];
394         }
395 
396         seq_printf(p, "cpu  %u %u %u %u %u %u %u\n",
397                 jiffies_to_clock_t(user),
398                 jiffies_to_clock_t(nice),
399                 jiffies_to_clock_t(system),
400                 jiffies_to_clock_t(idle),
401                 jiffies_to_clock_t(iowait),
402                 jiffies_to_clock_t(irq),
403                 jiffies_to_clock_t(softirq));
404         for (i = 0; i < NR_CPUS; i++){
405                 if (!cpu_online(i)) continue;
406                 seq_printf(p, "cpu%d %u %u %u %u %u %u %u\n",
407                         i,
408                         jiffies_to_clock_t(kstat_cpu(i).cpustat.user),
409                         jiffies_to_clock_t(kstat_cpu(i).cpustat.nice),
410                         jiffies_to_clock_t(kstat_cpu(i).cpustat.system),
411                         jiffies_to_clock_t(kstat_cpu(i).cpustat.idle),
412                         jiffies_to_clock_t(kstat_cpu(i).cpustat.iowait),
413                         jiffies_to_clock_t(kstat_cpu(i).cpustat.irq),
414                         jiffies_to_clock_t(kstat_cpu(i).cpustat.softirq));
415         }
416         seq_printf(p, "intr %u", sum);
417 
418 #if !defined(CONFIG_PPC64) && !defined(CONFIG_ALPHA)
419         for (i = 0; i < NR_IRQS; i++)
420                 seq_printf(p, " %u", kstat_irqs(i));
421 #endif
422 
423         seq_printf(p,
424                 "\nctxt %lu\n"
425                 "btime %lu\n"
426                 "processes %lu\n"
427                 "procs_running %lu\n"
428                 "procs_blocked %lu\n",
429                 nr_context_switches(),
430                 (unsigned long)jif,
431                 total_forks,
432                 nr_running(),
433                 nr_iowait());
434 
435         return 0;
436 }
437 
438 static int stat_open(struct inode *inode, struct file *file)
439 {
440         unsigned size = 4096 * (1 + num_online_cpus() / 32);
441         char *buf;
442         struct seq_file *m;
443         int res;
444 
445         /* don't ask for more than the kmalloc() max size, currently 128 KB */
446         if (size > 128 * 1024)
447                 size = 128 * 1024;
448         buf = kmalloc(size, GFP_KERNEL);
449         if (!buf)
450                 return -ENOMEM;
451 
452         res = single_open(file, show_stat, NULL);
453         if (!res) {
454                 m = file->private_data;
455                 m->buf = buf;
456                 m->size = size;
457         } else
458                 kfree(buf);
459         return res;
460 }
461 static struct file_operations proc_stat_operations = {
462         .open           = stat_open,
463         .read           = seq_read,
464         .llseek         = seq_lseek,
465         .release        = single_release,
466 };
467 
468 static int devices_read_proc(char *page, char **start, off_t off,
469                                  int count, int *eof, void *data)
470 {
471         int len = get_chrdev_list(page);
472         len += get_blkdev_list(page+len);
473         return proc_calc_metrics(page, start, off, count, eof, len);
474 }
475 
476 extern int show_interrupts(struct seq_file *p, void *v);
477 static int interrupts_open(struct inode *inode, struct file *file)
478 {
479         unsigned size = 4096 * (1 + num_online_cpus() / 8);
480         char *buf = kmalloc(size, GFP_KERNEL);
481         struct seq_file *m;
482         int res;
483 
484         if (!buf)
485                 return -ENOMEM;
486         res = single_open(file, show_interrupts, NULL);
487         if (!res) {
488                 m = file->private_data;
489                 m->buf = buf;
490                 m->size = size;
491         } else
492                 kfree(buf);
493         return res;
494 }
495 static struct file_operations proc_interrupts_operations = {
496         .open           = interrupts_open,
497         .read           = seq_read,
498         .llseek         = seq_lseek,
499         .release        = single_release,
500 };
501 
502 static int filesystems_read_proc(char *page, char **start, off_t off,
503                                  int count, int *eof, void *data)
504 {
505         int len = get_filesystem_list(page);
506         return proc_calc_metrics(page, start, off, count, eof, len);
507 }
508 
509 static int cmdline_read_proc(char *page, char **start, off_t off,
510                                  int count, int *eof, void *data)
511 {
512         extern char saved_command_line[];
513         int len;
514 
515         len = sprintf(page, "%s\n", saved_command_line);
516         return proc_calc_metrics(page, start, off, count, eof, len);
517 }
518 
519 #ifdef CONFIG_SGI_DS1286
520 static int ds1286_read_proc(char *page, char **start, off_t off,
521                                  int count, int *eof, void *data)
522 {
523         int len = get_ds1286_status(page);
524         return proc_calc_metrics(page, start, off, count, eof, len);
525 }
526 #endif
527 
528 static int locks_read_proc(char *page, char **start, off_t off,
529                                  int count, int *eof, void *data)
530 {
531         int len = get_locks_status(page, start, off, count);
532 
533         if (len < count)
534                 *eof = 1;
535         return len;
536 }
537 
538 static int execdomains_read_proc(char *page, char **start, off_t off,
539                                  int count, int *eof, void *data)
540 {
541         int len = get_exec_domain_list(page);
542         return proc_calc_metrics(page, start, off, count, eof, len);
543 }
544 
545 /*
546  * This function accesses profiling information. The returned data is
547  * binary: the sampling step and the actual contents of the profile
548  * buffer. Use of the program readprofile is recommended in order to
549  * get meaningful info out of these data.
550  */
551 static ssize_t
552 read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
553 {
554         unsigned long p = *ppos;
555         ssize_t read;
556         char * pnt;
557         unsigned int sample_step = 1 << prof_shift;
558 
559         if (p >= (prof_len+1)*sizeof(unsigned int))
560                 return 0;
561         if (count > (prof_len+1)*sizeof(unsigned int) - p)
562                 count = (prof_len+1)*sizeof(unsigned int) - p;
563         read = 0;
564 
565         while (p < sizeof(unsigned int) && count > 0) {
566                 put_user(*((char *)(&sample_step)+p),buf);
567                 buf++; p++; count--; read++;
568         }
569         pnt = (char *)prof_buffer + p - sizeof(unsigned int);
570         if (copy_to_user(buf,(void *)pnt,count))
571                 return -EFAULT;
572         read += count;
573         *ppos += read;
574         return read;
575 }
576 
577 /*
578  * Writing to /proc/profile resets the counters
579  *
580  * Writing a 'profiling multiplier' value into it also re-sets the profiling
581  * interrupt frequency, on architectures that support this.
582  */
583 static ssize_t write_profile(struct file *file, const char __user *buf,
584                              size_t count, loff_t *ppos)
585 {
586 #ifdef CONFIG_SMP
587         extern int setup_profiling_timer (unsigned int multiplier);
588 
589         if (count == sizeof(int)) {
590                 unsigned int multiplier;
591 
592                 if (copy_from_user(&multiplier, buf, sizeof(int)))
593                         return -EFAULT;
594 
595                 if (setup_profiling_timer(multiplier))
596                         return -EINVAL;
597         }
598 #endif
599 
600         memset(prof_buffer, 0, prof_len * sizeof(*prof_buffer));
601         return count;
602 }
603 
604 static struct file_operations proc_profile_operations = {
605         .read           = read_profile,
606         .write          = write_profile,
607 };
608 
609 #ifdef CONFIG_MAGIC_SYSRQ
610 /*
611  * writing 'C' to /proc/sysrq-trigger is like sysrq-C
612  */
613 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
614                                    size_t count, loff_t *ppos)
615 {
616         if (count) {
617                 char c;
618 
619                 if (get_user(c, buf))
620                         return -EFAULT;
621                 handle_sysrq(c, NULL, NULL);
622         }
623         return count;
624 }
625 
626 static struct file_operations proc_sysrq_trigger_operations = {
627         .write          = write_sysrq_trigger,
628 };
629 #endif
630 
631 struct proc_dir_entry *proc_root_kcore;
632 
633 static void create_seq_entry(char *name, mode_t mode, struct file_operations *f)
634 {
635         struct proc_dir_entry *entry;
636         entry = create_proc_entry(name, mode, NULL);
637         if (entry)
638                 entry->proc_fops = f;
639 }
640 
641 void __init proc_misc_init(void)
642 {
643         struct proc_dir_entry *entry;
644         static struct {
645                 char *name;
646                 int (*read_proc)(char*,char**,off_t,int,int*,void*);
647         } *p, simple_ones[] = {
648                 {"loadavg",     loadavg_read_proc},
649                 {"uptime",      uptime_read_proc},
650                 {"meminfo",     meminfo_read_proc},
651                 {"version",     version_read_proc},
652 #ifdef CONFIG_PROC_HARDWARE
653                 {"hardware",    hardware_read_proc},
654 #endif
655 #ifdef CONFIG_STRAM_PROC
656                 {"stram",       stram_read_proc},
657 #endif
658                 {"devices",     devices_read_proc},
659                 {"filesystems", filesystems_read_proc},
660                 {"cmdline",     cmdline_read_proc},
661 #ifdef CONFIG_SGI_DS1286
662                 {"rtc",         ds1286_read_proc},
663 #endif
664                 {"locks",       locks_read_proc},
665                 {"execdomains", execdomains_read_proc},
666                 {NULL,}
667         };
668         for (p = simple_ones; p->name; p++)
669                 create_proc_read_entry(p->name, 0, NULL, p->read_proc, NULL);
670 
671         proc_symlink("mounts", NULL, "self/mounts");
672 
673         /* And now for trickier ones */
674         entry = create_proc_entry("kmsg", S_IRUSR, &proc_root);
675         if (entry)
676                 entry->proc_fops = &proc_kmsg_operations;
677         create_seq_entry("cpuinfo", 0, &proc_cpuinfo_operations);
678         create_seq_entry("partitions", 0, &proc_partitions_operations);
679         create_seq_entry("stat", 0, &proc_stat_operations);
680         create_seq_entry("interrupts", 0, &proc_interrupts_operations);
681         create_seq_entry("slabinfo",S_IWUSR|S_IRUGO,&proc_slabinfo_operations);
682         create_seq_entry("buddyinfo",S_IRUGO, &fragmentation_file_operations);
683         create_seq_entry("vmstat",S_IRUGO, &proc_vmstat_file_operations);
684         create_seq_entry("diskstats", 0, &proc_diskstats_operations);
685 #ifdef CONFIG_MODULES
686         create_seq_entry("modules", 0, &proc_modules_operations);
687 #endif
688 #ifdef CONFIG_PROC_KCORE
689         proc_root_kcore = create_proc_entry("kcore", S_IRUSR, NULL);
690         if (proc_root_kcore) {
691                 proc_root_kcore->proc_fops = &proc_kcore_operations;
692                 proc_root_kcore->size =
693                                 (size_t)high_memory - PAGE_OFFSET + PAGE_SIZE;
694         }
695 #endif
696         if (prof_on) {
697                 entry = create_proc_entry("profile", S_IWUSR | S_IRUGO, NULL);
698                 if (entry) {
699                         entry->proc_fops = &proc_profile_operations;
700                         entry->size = (1+prof_len) * sizeof(unsigned int);
701                 }
702         }
703 #ifdef CONFIG_MAGIC_SYSRQ
704         entry = create_proc_entry("sysrq-trigger", S_IWUSR, NULL);
705         if (entry)
706                 entry->proc_fops = &proc_sysrq_trigger_operations;
707 #endif
708 #ifdef CONFIG_PPC32
709         {
710                 extern struct file_operations ppc_htab_operations;
711                 entry = create_proc_entry("ppc_htab", S_IRUGO|S_IWUSR, NULL);
712                 if (entry)
713                         entry->proc_fops = &ppc_htab_operations;
714         }
715 #endif
716 }
717 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp