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

📄 proc_misc.c

📁 讲述linux的初始化过程
💻 C
📖 第 1 页 / 共 2 页
字号:
		"page %u %u\n"                "swap %u %u\n"		"intr %u",			kstat.pgpgin,			kstat.pgpgout,			kstat.pswpin,			kstat.pswpout,			sum	);	for (i = 0 ; i < NR_IRQS ; i++)		len += sprintf(page + len, " %u", kstat_irqs(i));	len += sprintf(page + len, "\ndisk_io: ");	for (major = 0; major < DK_MAX_MAJOR; major++) {		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);}static 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);}static 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 mounts_read_proc(char *page, char **start, off_t off,				 int count, int *eof, void *data){	int len = get_filesystem_info(page);	return proc_calc_metrics(page, start, off, count, eof, 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,};struct proc_dir_entry *proc_root_kcore;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},		{"cpuinfo",	cpuinfo_read_proc},#ifdef CONFIG_PROC_HARDWARE		{"hardware",	hardware_read_proc},#endif#ifdef CONFIG_STRAM_PROC		{"stram",	stram_read_proc},#endif#ifdef CONFIG_DEBUG_MALLOC		{"malloc",	malloc_read_proc},#endif#ifdef CONFIG_MODULES		{"modules",	modules_read_proc},		{"ksyms",	ksyms_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},		{"dma",		dma_read_proc},		{"ioports",	ioports_read_proc},		{"cmdline",	cmdline_read_proc},#ifdef CONFIG_SGI_DS1286		{"rtc",		ds1286_read_proc},#endif		{"locks",	locks_read_proc},		{"mounts",	mounts_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;	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 __powerpc__	{		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 + -