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

📄 ioctl.c.bak

📁 一份精简的linux内核源代码
💻 BAK
字号:
/* *  linux/fs/ioctl.c * *  (C) 1991  Linus Torvalds */#include <string.h>#include <errno.h>#include <sys/stat.h>#include <linux/sched.h>extern int tty_ioctl(int dev, int cmd, int arg);typedef int (*ioctl_ptr)(int dev,int cmd,int arg);/*输入输出控制函数指针*/#define NRDEVS ((sizeof (ioctl_table))/(sizeof (ioctl_ptr)))/*取设备种数*/static ioctl_ptr ioctl_table[]={	NULL,		/* nodev */	NULL,		/* /dev/mem */	NULL,		/* /dev/fd */	NULL,		/* /dev/hd */	tty_ioctl,	/* /dev/ttyx */	tty_ioctl,	/* /dev/tty */	NULL,		/* /dev/lp */	NULL};		/* named pipes */	int sys_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)/*引用kernel/chr_drv/tty.c中的函数,实现字符设备的io控制功能*/{		struct file * filp;	int dev,mode;	if (fd >= NR_OPEN || !(filp = current->filp[fd]))		return -EBADF;	mode=filp->f_inode->i_mode;	if (!S_ISCHR(mode) && !S_ISBLK(mode))/*若不是字符设备或块设备文件,则出错退出,否则取设备号*/		return -EINVAL;	dev = filp->f_inode->i_zone[0];	if (MAJOR(dev) >= NRDEVS)		return -ENODEV;	if (!ioctl_table[MAJOR(dev)])		return -ENOTTY;	return ioctl_table[MAJOR(dev)](dev,cmd,arg);/*根据设备号调用指定设备io函数*/}

⌨️ 快捷键说明

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