⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 proc_misc.c

📁 嵌入式系统设计与实验教材二源码linux内核移植与编译
💻 C
📖 第 1 页 / 共 2 页
字号:
		for (disk = 0; disk < DK_MAX_DISK; disk++) {			int active = kstat.dk_drive[major][disk] +				kstat.dk_drive_rblk[major][disk] +				kstat.dk_drive_wblk[major][disk];			if (active)				len += sprintf(page + len,					"(%u,%u):(%u,%u,%u,%u,%u) ",					major, disk,					kstat.dk_drive[major][disk],					kstat.dk_drive_rio[major][disk],					kstat.dk_drive_rblk[major][disk],					kstat.dk_drive_wio[major][disk],					kstat.dk_drive_wblk[major][disk]			);		}	}	len += sprintf(page + len,		"\nctxt %u\n"		"btime %lu\n"		"processes %lu\n",		kstat.context_swtch,		xtime.tv_sec - jif / HZ,		total_forks);	return proc_calc_metrics(page, start, off, count, eof, len);}static int devices_read_proc(char *page, char **start, off_t off,				 int count, int *eof, void *data){	int len = get_device_list(page);	return proc_calc_metrics(page, start, off, count, eof, len);}static int partitions_read_proc(char *page, char **start, off_t off,				 int count, int *eof, void *data){	int len = get_partition_list(page, start, off, count);	if (len < count) *eof = 1;	return len;}#if !defined(CONFIG_ARCH_S390)static int interrupts_read_proc(char *page, char **start, off_t off,				 int count, int *eof, void *data){	int len = get_irq_list(page);	return proc_calc_metrics(page, start, off, count, eof, len);}#endifstatic int filesystems_read_proc(char *page, char **start, off_t off,				 int count, int *eof, void *data){	int len = get_filesystem_list(page);	return proc_calc_metrics(page, start, off, count, eof, len);}#ifdef CONFIG_GENERIC_ISA_DMAstatic int dma_read_proc(char *page, char **start, off_t off,				 int count, int *eof, void *data){	int len = get_dma_list(page);	return proc_calc_metrics(page, start, off, count, eof, len);}#endifstatic int ioports_read_proc(char *page, char **start, off_t off,				 int count, int *eof, void *data){	int len = get_ioport_list(page);	return proc_calc_metrics(page, start, off, count, eof, len);}static int cmdline_read_proc(char *page, char **start, off_t off,				 int count, int *eof, void *data){	extern char saved_command_line[];	int len;	len = sprintf(page, "%s\n", saved_command_line);	len = strlen(page);	return proc_calc_metrics(page, start, off, count, eof, len);}#ifdef CONFIG_SGI_DS1286static int ds1286_read_proc(char *page, char **start, off_t off,				 int count, int *eof, void *data){	int len = get_ds1286_status(page);	return proc_calc_metrics(page, start, off, count, eof, len);}#endifstatic int locks_read_proc(char *page, char **start, off_t off,				 int count, int *eof, void *data){	int len;	lock_kernel();	len = get_locks_status(page, start, off, count);	unlock_kernel();	if (len < count) *eof = 1;	return len;}static int execdomains_read_proc(char *page, char **start, off_t off,				 int count, int *eof, void *data){	int len = get_exec_domain_list(page);	return proc_calc_metrics(page, start, off, count, eof, len);}static int swaps_read_proc(char *page, char **start, off_t off,				 int count, int *eof, void *data){	int len = get_swaparea_info(page);	return proc_calc_metrics(page, start, off, count, eof, len);}static int memory_read_proc(char *page, char **start, off_t off,				 int count, int *eof, void *data){	int len = get_mem_list(page);	return proc_calc_metrics(page, start, off, count, eof, len);}/* * This function accesses profiling information. The returned data is * binary: the sampling step and the actual contents of the profile * buffer. Use of the program readprofile is recommended in order to * get meaningful info out of these data. */static ssize_t read_profile(struct file *file, char *buf,			    size_t count, loff_t *ppos){	unsigned long p = *ppos;	ssize_t read;	char * pnt;	unsigned int sample_step = 1 << prof_shift;	if (p >= (prof_len+1)*sizeof(unsigned int))		return 0;	if (count > (prof_len+1)*sizeof(unsigned int) - p)		count = (prof_len+1)*sizeof(unsigned int) - p;	read = 0;	while (p < sizeof(unsigned int) && count > 0) {		put_user(*((char *)(&sample_step)+p),buf);		buf++; p++; count--; read++;	}	pnt = (char *)prof_buffer + p - sizeof(unsigned int);	copy_to_user(buf,(void *)pnt,count);	read += count;	*ppos += read;	return read;}/* * Writing to /proc/profile resets the counters * * Writing a 'profiling multiplier' value into it also re-sets the profiling * interrupt frequency, on architectures that support this. */static ssize_t write_profile(struct file * file, const char * buf,			     size_t count, loff_t *ppos){#ifdef CONFIG_SMP	extern int setup_profiling_timer (unsigned int multiplier);	if (count==sizeof(int)) {		unsigned int multiplier;		if (copy_from_user(&multiplier, buf, sizeof(int)))			return -EFAULT;		if (setup_profiling_timer(multiplier))			return -EINVAL;	}#endif	memset(prof_buffer, 0, prof_len * sizeof(*prof_buffer));	return count;}static struct file_operations proc_profile_operations = {	read:		read_profile,	write:		write_profile,};extern struct seq_operations mounts_op;static int mounts_open(struct inode *inode, struct file *file){	return seq_open(file, &mounts_op);}static struct file_operations proc_mounts_operations = {	open:		mounts_open,	read:		seq_read,	llseek:		seq_lseek,	release:	seq_release,};struct proc_dir_entry *proc_root_kcore;static void create_seq_entry(char *name, mode_t mode, struct file_operations *f){	struct proc_dir_entry *entry;	entry = create_proc_entry(name, mode, NULL);	if (entry)		entry->proc_fops = f;}void __init proc_misc_init(void){	struct proc_dir_entry *entry;	static struct {		char *name;		int (*read_proc)(char*,char**,off_t,int,int*,void*);	} *p, simple_ones[] = {		{"loadavg",     loadavg_read_proc},		{"uptime",	uptime_read_proc},		{"meminfo",	meminfo_read_proc},		{"version",	version_read_proc},#ifdef CONFIG_MODULES		{"modules",	modules_read_proc},#endif		{"stat",	kstat_read_proc},		{"devices",	devices_read_proc},		{"partitions",	partitions_read_proc},#if !defined(CONFIG_ARCH_S390)		{"interrupts",	interrupts_read_proc},#endif		{"filesystems",	filesystems_read_proc},#ifdef CONFIG_GENERIC_ISA_DMA		{"dma",		dma_read_proc},#endif				{"ioports",	ioports_read_proc},		{"cmdline",	cmdline_read_proc},#ifdef CONFIG_SGI_DS1286		{"rtc",		ds1286_read_proc},#endif		{"locks",	locks_read_proc},		{"swaps",	swaps_read_proc},		{"iomem",	memory_read_proc},		{"execdomains",	execdomains_read_proc},		{NULL,}	};	for (p = simple_ones; p->name; p++)		create_proc_read_entry(p->name, 0, NULL, p->read_proc, NULL);	/* And now for trickier ones */	entry = create_proc_entry("kmsg", S_IRUSR, &proc_root);	if (entry)		entry->proc_fops = &proc_kmsg_operations;	create_seq_entry("mounts", 0, &proc_mounts_operations);	create_seq_entry("cpuinfo", 0, &proc_cpuinfo_operations);#ifdef CONFIG_MODULES	create_seq_entry("ksyms", 0, &proc_ksyms_operations);#endif	proc_root_kcore = create_proc_entry("kcore", S_IRUSR, NULL);	if (proc_root_kcore) {		proc_root_kcore->proc_fops = &proc_kcore_operations;		proc_root_kcore->size =				(size_t)high_memory - PAGE_OFFSET + PAGE_SIZE;	}	if (prof_shift) {		entry = create_proc_entry("profile", S_IWUSR | S_IRUGO, NULL);		if (entry) {			entry->proc_fops = &proc_profile_operations;			entry->size = (1+prof_len) * sizeof(unsigned int);		}	}#ifdef CONFIG_PPC32	{		extern struct file_operations ppc_htab_operations;		entry = create_proc_entry("ppc_htab", S_IRUGO|S_IWUSR, NULL);		if (entry)			entry->proc_fops = &ppc_htab_operations;	}#endif	entry = create_proc_read_entry("slabinfo", S_IWUSR | S_IRUGO, NULL,				       slabinfo_read_proc, NULL);	if (entry)		entry->write_proc = slabinfo_write_proc;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -