proc.c
来自「Linux Kernel 2.6.9 for OMAP1710」· C语言 代码 · 共 618 行 · 第 1/2 页
C
618 行
/* proc.c: /proc interface for RxRPC * * Copyright (C) 2002 Red Hat, Inc. All Rights Reserved. * Written by David Howells (dhowells@redhat.com) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version * 2 of the License, or (at your option) any later version. */#include <linux/sched.h>#include <linux/slab.h>#include <linux/module.h>#include <linux/proc_fs.h>#include <linux/seq_file.h>#include <rxrpc/rxrpc.h>#include <rxrpc/transport.h>#include <rxrpc/peer.h>#include <rxrpc/connection.h>#include <rxrpc/call.h>#include <rxrpc/message.h>#include "internal.h"static struct proc_dir_entry *proc_rxrpc;static int rxrpc_proc_transports_open(struct inode *inode, struct file *file);static void *rxrpc_proc_transports_start(struct seq_file *p, loff_t *pos);static void *rxrpc_proc_transports_next(struct seq_file *p, void *v, loff_t *pos);static void rxrpc_proc_transports_stop(struct seq_file *p, void *v);static int rxrpc_proc_transports_show(struct seq_file *m, void *v);static struct seq_operations rxrpc_proc_transports_ops = { .start = rxrpc_proc_transports_start, .next = rxrpc_proc_transports_next, .stop = rxrpc_proc_transports_stop, .show = rxrpc_proc_transports_show,};static struct file_operations rxrpc_proc_transports_fops = { .open = rxrpc_proc_transports_open, .read = seq_read, .llseek = seq_lseek, .release = seq_release,};static int rxrpc_proc_peers_open(struct inode *inode, struct file *file);static void *rxrpc_proc_peers_start(struct seq_file *p, loff_t *pos);static void *rxrpc_proc_peers_next(struct seq_file *p, void *v, loff_t *pos);static void rxrpc_proc_peers_stop(struct seq_file *p, void *v);static int rxrpc_proc_peers_show(struct seq_file *m, void *v);static struct seq_operations rxrpc_proc_peers_ops = { .start = rxrpc_proc_peers_start, .next = rxrpc_proc_peers_next, .stop = rxrpc_proc_peers_stop, .show = rxrpc_proc_peers_show,};static struct file_operations rxrpc_proc_peers_fops = { .open = rxrpc_proc_peers_open, .read = seq_read, .llseek = seq_lseek, .release = seq_release,};static int rxrpc_proc_conns_open(struct inode *inode, struct file *file);static void *rxrpc_proc_conns_start(struct seq_file *p, loff_t *pos);static void *rxrpc_proc_conns_next(struct seq_file *p, void *v, loff_t *pos);static void rxrpc_proc_conns_stop(struct seq_file *p, void *v);static int rxrpc_proc_conns_show(struct seq_file *m, void *v);static struct seq_operations rxrpc_proc_conns_ops = { .start = rxrpc_proc_conns_start, .next = rxrpc_proc_conns_next, .stop = rxrpc_proc_conns_stop, .show = rxrpc_proc_conns_show,};static struct file_operations rxrpc_proc_conns_fops = { .open = rxrpc_proc_conns_open, .read = seq_read, .llseek = seq_lseek, .release = seq_release,};static int rxrpc_proc_calls_open(struct inode *inode, struct file *file);static void *rxrpc_proc_calls_start(struct seq_file *p, loff_t *pos);static void *rxrpc_proc_calls_next(struct seq_file *p, void *v, loff_t *pos);static void rxrpc_proc_calls_stop(struct seq_file *p, void *v);static int rxrpc_proc_calls_show(struct seq_file *m, void *v);static struct seq_operations rxrpc_proc_calls_ops = { .start = rxrpc_proc_calls_start, .next = rxrpc_proc_calls_next, .stop = rxrpc_proc_calls_stop, .show = rxrpc_proc_calls_show,};static struct file_operations rxrpc_proc_calls_fops = { .open = rxrpc_proc_calls_open, .read = seq_read, .llseek = seq_lseek, .release = seq_release,};static const char *rxrpc_call_states7[] = { "complet", "error ", "rcv_op ", "rcv_arg", "got_arg", "snd_rpl", "fin_ack", "snd_arg", "rcv_rpl", "got_rpl"};static const char *rxrpc_call_error_states7[] = { "no_err ", "loc_abt", "rmt_abt", "loc_err", "rmt_err"};/*****************************************************************************//* * initialise the /proc/net/rxrpc/ directory */int rxrpc_proc_init(void){ struct proc_dir_entry *p; proc_rxrpc = proc_mkdir("rxrpc", proc_net); if (!proc_rxrpc) goto error; proc_rxrpc->owner = THIS_MODULE; p = create_proc_entry("calls", 0, proc_rxrpc); if (!p) goto error_proc; p->proc_fops = &rxrpc_proc_calls_fops; p->owner = THIS_MODULE; p = create_proc_entry("connections", 0, proc_rxrpc); if (!p) goto error_calls; p->proc_fops = &rxrpc_proc_conns_fops; p->owner = THIS_MODULE; p = create_proc_entry("peers", 0, proc_rxrpc); if (!p) goto error_calls; p->proc_fops = &rxrpc_proc_peers_fops; p->owner = THIS_MODULE; p = create_proc_entry("transports", 0, proc_rxrpc); if (!p) goto error_conns; p->proc_fops = &rxrpc_proc_transports_fops; p->owner = THIS_MODULE; return 0; error_conns: remove_proc_entry("connections", proc_rxrpc); error_calls: remove_proc_entry("calls", proc_rxrpc); error_proc: remove_proc_entry("rxrpc", proc_net); error: return -ENOMEM;} /* end rxrpc_proc_init() *//*****************************************************************************//* * clean up the /proc/net/rxrpc/ directory */void rxrpc_proc_cleanup(void){ remove_proc_entry("transports", proc_rxrpc); remove_proc_entry("peers", proc_rxrpc); remove_proc_entry("connections", proc_rxrpc); remove_proc_entry("calls", proc_rxrpc); remove_proc_entry("rxrpc", proc_net);} /* end rxrpc_proc_cleanup() *//*****************************************************************************//* * open "/proc/net/rxrpc/transports" which provides a summary of extant transports */static int rxrpc_proc_transports_open(struct inode *inode, struct file *file){ struct seq_file *m; int ret; ret = seq_open(file, &rxrpc_proc_transports_ops); if (ret < 0) return ret; m = file->private_data; m->private = PDE(inode)->data; return 0;} /* end rxrpc_proc_transports_open() *//*****************************************************************************//* * set up the iterator to start reading from the transports list and return the first item */static void *rxrpc_proc_transports_start(struct seq_file *m, loff_t *_pos){ struct list_head *_p; loff_t pos = *_pos; /* lock the list against modification */ down_read(&rxrpc_proc_transports_sem); /* allow for the header line */ if (!pos) return SEQ_START_TOKEN; pos--; /* find the n'th element in the list */ list_for_each(_p, &rxrpc_proc_transports) if (!pos--) break; return _p != &rxrpc_proc_transports ? _p : NULL;} /* end rxrpc_proc_transports_start() *//*****************************************************************************//* * move to next call in transports list */static void *rxrpc_proc_transports_next(struct seq_file *p, void *v, loff_t *pos){ struct list_head *_p; (*pos)++; _p = v; _p = (v == SEQ_START_TOKEN) ? rxrpc_proc_transports.next : _p->next; return _p != &rxrpc_proc_transports ? _p : NULL;} /* end rxrpc_proc_transports_next() *//*****************************************************************************//* * clean up after reading from the transports list */static void rxrpc_proc_transports_stop(struct seq_file *p, void *v){ up_read(&rxrpc_proc_transports_sem);} /* end rxrpc_proc_transports_stop() *//*****************************************************************************//* * display a header line followed by a load of call lines */static int rxrpc_proc_transports_show(struct seq_file *m, void *v){ struct rxrpc_transport *trans = list_entry(v, struct rxrpc_transport, proc_link); /* display header on line 1 */ if (v == SEQ_START_TOKEN) { seq_puts(m, "LOCAL USE\n"); return 0; } /* display one transport per line on subsequent lines */ seq_printf(m, "%5hu %3d\n", trans->port, atomic_read(&trans->usage) ); return 0;} /* end rxrpc_proc_transports_show() *//*****************************************************************************//* * open "/proc/net/rxrpc/peers" which provides a summary of extant peers */static int rxrpc_proc_peers_open(struct inode *inode, struct file *file){ struct seq_file *m; int ret; ret = seq_open(file, &rxrpc_proc_peers_ops); if (ret < 0) return ret; m = file->private_data; m->private = PDE(inode)->data; return 0;} /* end rxrpc_proc_peers_open() *//*****************************************************************************//* * set up the iterator to start reading from the peers list and return the * first item */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?