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

📄 ioctl32.c

📁 linux-2.4.29操作系统的源码
💻 C
📖 第 1 页 / 共 5 页
字号:
	return err ? -EFAULT : 0;}struct loop_info32 {	int			lo_number;      /* ioctl r/o */	__kernel_dev_t32	lo_device;      /* ioctl r/o */	unsigned int		lo_inode;       /* ioctl r/o */	__kernel_dev_t32	lo_rdevice;     /* ioctl r/o */	int			lo_offset;	int			lo_encrypt_type;	int			lo_encrypt_key_size;    /* ioctl w/o */	int			lo_flags;       /* ioctl r/o */	char			lo_name[LO_NAME_SIZE];	unsigned char		lo_encrypt_key[LO_KEY_SIZE]; /* ioctl w/o */	unsigned int		lo_init[2];	char			reserved[4];};static int loop_status(unsigned int fd, unsigned int cmd, unsigned long arg){	mm_segment_t old_fs = get_fs();	struct loop_info l;	int err = -EINVAL;	switch(cmd) {	case LOOP_SET_STATUS:		err = get_user(l.lo_number, &((struct loop_info32 *)arg)->lo_number);		err |= __get_user(l.lo_device, &((struct loop_info32 *)arg)->lo_device);		err |= __get_user(l.lo_inode, &((struct loop_info32 *)arg)->lo_inode);		err |= __get_user(l.lo_rdevice, &((struct loop_info32 *)arg)->lo_rdevice);		err |= __copy_from_user((char *)&l.lo_offset, (char *)&((struct loop_info32 *)arg)->lo_offset,					   8 + (unsigned long)l.lo_init - (unsigned long)&l.lo_offset);		if (err) {			err = -EFAULT;		} else {			set_fs (KERNEL_DS);			err = sys_ioctl (fd, cmd, (unsigned long)&l);			set_fs (old_fs);		}		break;	case LOOP_GET_STATUS:		set_fs (KERNEL_DS);		err = sys_ioctl (fd, cmd, (unsigned long)&l);		set_fs (old_fs);		if (!err) {			err = put_user(l.lo_number, &((struct loop_info32 *)arg)->lo_number);			err |= __put_user(l.lo_device, &((struct loop_info32 *)arg)->lo_device);			err |= __put_user(l.lo_inode, &((struct loop_info32 *)arg)->lo_inode);			err |= __put_user(l.lo_rdevice, &((struct loop_info32 *)arg)->lo_rdevice);			err |= __copy_to_user((char *)&((struct loop_info32 *)arg)->lo_offset,					   (char *)&l.lo_offset, (unsigned long)l.lo_init - (unsigned long)&l.lo_offset);			if (err)				err = -EFAULT;		}		break;	default: {		static int count = 0;		if (++count <= 20)			printk(KERN_WARNING				"%s: Unknown loop ioctl cmd, fd(%d) "				"cmd(%08x) arg(%08lx)\n",				__FUNCTION__, fd, cmd, arg);	}	}	return err;}#ifdef CONFIG_VTextern int tty_ioctl(struct inode * inode, struct file * file, unsigned int cmd, unsigned long arg);static int vt_check(struct file *file){	struct tty_struct *tty;	struct inode *inode = file->f_dentry->d_inode;		if (file->f_op->ioctl != tty_ioctl)		return -EINVAL;	                	tty = (struct tty_struct *)file->private_data;	if (tty_paranoia_check(tty, inode->i_rdev, "tty_ioctl"))		return -EINVAL;	                                                	if (tty->driver.ioctl != vt_ioctl)		return -EINVAL;		/*	 * To have permissions to do most of the vt ioctls, we either have	 * to be the owner of the tty, or super-user.	 */	if (current->tty == tty || suser())		return 1;	return 0;                                                    }struct consolefontdesc32 {	unsigned short charcount;       /* characters in font (256 or 512) */	unsigned short charheight;      /* scan lines per character (1-32) */	u32 chardata;			/* font data in expanded form */};static int do_fontx_ioctl(unsigned int fd, int cmd, struct consolefontdesc32 *user_cfd, struct file *file){	struct consolefontdesc cfdarg;	struct console_font_op op;	int i, perm;	perm = vt_check(file);	if (perm < 0) return perm;		if (copy_from_user(&cfdarg, user_cfd, sizeof(struct consolefontdesc32)))		return -EFAULT;		cfdarg.chardata = (unsigned char *)A(((struct consolefontdesc32 *)&cfdarg)->chardata); 		switch (cmd) {	case PIO_FONTX:		if (!perm)			return -EPERM;		op.op = KD_FONT_OP_SET;		op.flags = 0;		op.width = 8;		op.height = cfdarg.charheight;		op.charcount = cfdarg.charcount;		op.data = cfdarg.chardata;		return con_font_op(fg_console, &op);	case GIO_FONTX:		if (!cfdarg.chardata)			return 0;		op.op = KD_FONT_OP_GET;		op.flags = 0;		op.width = 8;		op.height = cfdarg.charheight;		op.charcount = cfdarg.charcount;		op.data = cfdarg.chardata;		i = con_font_op(fg_console, &op);		if (i)			return i;		cfdarg.charheight = op.height;		cfdarg.charcount = op.charcount;		((struct consolefontdesc32 *)&cfdarg)->chardata	= (unsigned long)cfdarg.chardata;		if (copy_to_user(user_cfd, &cfdarg, sizeof(struct consolefontdesc32)))			return -EFAULT;		return 0;	}	return -EINVAL;}struct console_font_op32 {	unsigned int op;        /* operation code KD_FONT_OP_* */	unsigned int flags;     /* KD_FONT_FLAG_* */	unsigned int width, height;     /* font size */	unsigned int charcount;	u32 data;    /* font data with height fixed to 32 */};                                        static int do_kdfontop_ioctl(unsigned int fd, unsigned int cmd, struct console_font_op32 *fontop, struct file *file){	struct console_font_op op;	int perm = vt_check(file), i;	struct vt_struct *vt;		if (perm < 0) return perm;		if (copy_from_user(&op, (void *) fontop, sizeof(struct console_font_op32)))		return -EFAULT;	if (!perm && op.op != KD_FONT_OP_GET)		return -EPERM;	op.data = (unsigned char *)A(((struct console_font_op32 *)&op)->data);	op.flags |= KD_FONT_FLAG_OLD;	vt = (struct vt_struct *)((struct tty_struct *)file->private_data)->driver_data;	i = con_font_op(vt->vc_num, &op);	if (i) return i;	((struct console_font_op32 *)&op)->data = (unsigned long)op.data;	if (copy_to_user((void *) fontop, &op, sizeof(struct console_font_op32)))		return -EFAULT;	return 0;}struct unimapdesc32 {	unsigned short entry_ct;	u32 entries;};static int do_unimap_ioctl(unsigned int fd, unsigned int cmd, struct unimapdesc32 *user_ud, struct file *file){	struct unimapdesc32 tmp;	int perm = vt_check(file);		if (perm < 0) return perm;	if (copy_from_user(&tmp, user_ud, sizeof tmp))		return -EFAULT;	switch (cmd) {	case PIO_UNIMAP:		if (!perm) return -EPERM;		return con_set_unimap(fg_console, tmp.entry_ct, (struct unipair *)A(tmp.entries));	case GIO_UNIMAP:		return con_get_unimap(fg_console, tmp.entry_ct, &(user_ud->entry_ct), (struct unipair *)A(tmp.entries));	}	return 0;}#endif#if 0static int do_smb_getmountuid(unsigned int fd, unsigned int cmd, unsigned long arg){	mm_segment_t old_fs = get_fs();	__kernel_uid_t kuid;	int err;	cmd = SMB_IOC_GETMOUNTUID;	set_fs(KERNEL_DS);	err = sys_ioctl(fd, cmd, (unsigned long)&kuid);	set_fs(old_fs);	if (err >= 0)		err = put_user(kuid, (__kernel_uid_t32 *)arg);	return err;}#endifstruct atmif_sioc32 {        int                number;        int                length;        __kernel_caddr_t32 arg;};struct atm_iobuf32 {	int                length;	__kernel_caddr_t32 buffer;};#define ATM_GETLINKRATE32 _IOW('a', ATMIOC_ITF+1, struct atmif_sioc32)#define ATM_GETNAMES32    _IOW('a', ATMIOC_ITF+3, struct atm_iobuf32)#define ATM_GETTYPE32     _IOW('a', ATMIOC_ITF+4, struct atmif_sioc32)#define ATM_GETESI32	  _IOW('a', ATMIOC_ITF+5, struct atmif_sioc32)#define ATM_GETADDR32	  _IOW('a', ATMIOC_ITF+6, struct atmif_sioc32)#define ATM_RSTADDR32	  _IOW('a', ATMIOC_ITF+7, struct atmif_sioc32)#define ATM_ADDADDR32	  _IOW('a', ATMIOC_ITF+8, struct atmif_sioc32)#define ATM_DELADDR32	  _IOW('a', ATMIOC_ITF+9, struct atmif_sioc32)#define ATM_GETCIRANGE32  _IOW('a', ATMIOC_ITF+10, struct atmif_sioc32)#define ATM_SETCIRANGE32  _IOW('a', ATMIOC_ITF+11, struct atmif_sioc32)#define ATM_SETESI32      _IOW('a', ATMIOC_ITF+12, struct atmif_sioc32)#define ATM_SETESIF32     _IOW('a', ATMIOC_ITF+13, struct atmif_sioc32)#define ATM_GETSTAT32     _IOW('a', ATMIOC_SARCOM+0, struct atmif_sioc32)#define ATM_GETSTATZ32    _IOW('a', ATMIOC_SARCOM+1, struct atmif_sioc32)#define ATM_GETLOOP32	  _IOW('a', ATMIOC_SARCOM+2, struct atmif_sioc32)#define ATM_SETLOOP32	  _IOW('a', ATMIOC_SARCOM+3, struct atmif_sioc32)#define ATM_QUERYLOOP32	  _IOW('a', ATMIOC_SARCOM+4, struct atmif_sioc32)static struct {        unsigned int cmd32;        unsigned int cmd;} atm_ioctl_map[] = {        { ATM_GETLINKRATE32, ATM_GETLINKRATE },	{ ATM_GETNAMES32,    ATM_GETNAMES },        { ATM_GETTYPE32,     ATM_GETTYPE },        { ATM_GETESI32,      ATM_GETESI },        { ATM_GETADDR32,     ATM_GETADDR },        { ATM_RSTADDR32,     ATM_RSTADDR },        { ATM_ADDADDR32,     ATM_ADDADDR },        { ATM_DELADDR32,     ATM_DELADDR },        { ATM_GETCIRANGE32,  ATM_GETCIRANGE },	{ ATM_SETCIRANGE32,  ATM_SETCIRANGE },	{ ATM_SETESI32,      ATM_SETESI },	{ ATM_SETESIF32,     ATM_SETESIF },	{ ATM_GETSTAT32,     ATM_GETSTAT },	{ ATM_GETSTATZ32,    ATM_GETSTATZ },	{ ATM_GETLOOP32,     ATM_GETLOOP },	{ ATM_SETLOOP32,     ATM_SETLOOP },	{ ATM_QUERYLOOP32,   ATM_QUERYLOOP }};#define NR_ATM_IOCTL (sizeof(atm_ioctl_map)/sizeof(atm_ioctl_map[0]))static int do_atm_iobuf(unsigned int fd, unsigned int cmd, unsigned long arg){	struct atm_iobuf32 iobuf32;	struct atm_iobuf   iobuf = { 0, NULL };	mm_segment_t old_fs;	int err;	err = copy_from_user(&iobuf32, (struct atm_iobuf32*)arg,	    sizeof(struct atm_iobuf32));	if (err)		return -EFAULT;	iobuf.length = iobuf32.length;	if (iobuf32.buffer == (__kernel_caddr_t32) NULL || iobuf32.length == 0) {		iobuf.buffer = (void*)(unsigned long)iobuf32.buffer;	} else {		iobuf.buffer = kmalloc(iobuf.length, GFP_KERNEL);		if (iobuf.buffer == NULL) {			err = -ENOMEM;			goto out;		}		err = copy_from_user(iobuf.buffer, A(iobuf32.buffer), iobuf.length);		if (err) {			err = -EFAULT;			goto out;		}	}	old_fs = get_fs(); set_fs (KERNEL_DS);	err = sys_ioctl (fd, cmd, (unsigned long)&iobuf);      	set_fs (old_fs);        if(err)		goto out;        if(iobuf.buffer && iobuf.length > 0) {		err = copy_to_user(A(iobuf32.buffer), iobuf.buffer, iobuf.length);		if (err) {			err = -EFAULT;			goto out;		}	}	err = __put_user(iobuf.length, &(((struct atm_iobuf32*)arg)->length)); out:        if(iobuf32.buffer && iobuf32.length > 0)		kfree(iobuf.buffer);	return err;}static int do_atmif_sioc(unsigned int fd, unsigned int cmd, unsigned long arg){        struct atmif_sioc32 sioc32;        struct atmif_sioc   sioc = { 0, 0, NULL };        mm_segment_t old_fs;        int err;                err = copy_from_user(&sioc32, (struct atmif_sioc32*)arg,			     sizeof(struct atmif_sioc32));        if (err)                return -EFAULT;        sioc.number = sioc32.number;        sioc.length = sioc32.length;        	if (sioc32.arg == (__kernel_caddr_t32) NULL || sioc32.length == 0) {		sioc.arg = (void*)(unsigned long)sioc32.arg;        } else {                sioc.arg = kmalloc(sioc.length, GFP_KERNEL);                if (sioc.arg == NULL) {                        err = -ENOMEM;			goto out;		}                                err = copy_from_user(sioc.arg, A(sioc32.arg), sioc32.length);                if (err) {                        err = -EFAULT;                        goto out;                }        }                old_fs = get_fs(); set_fs (KERNEL_DS);        err = sys_ioctl (fd, cmd, (unsigned long)&sioc);	        set_fs (old_fs);        if(err) {                goto out;	}                if(sioc.arg && sioc.length > 0) {                err = copy_to_user(A(sioc32.arg), sioc.arg, sioc.length);                if (err) {                        err = -EFAULT;                        goto out;                }        }        err = __put_user(sioc.length, &(((struct atmif_sioc32*)arg)->length));         out:        if(sioc32.arg && sioc32.length > 0)		kfree(sioc.arg);        	return err;}static int do_atm_ioctl(unsigned int fd, unsigned int cmd32, unsigned long arg){        int i;        unsigned int cmd = 0;        	switch (cmd32) {	case SONET_GETSTAT:	case SONET_GETSTATZ:	case SONET_GETDIAG:	case SONET_SETDIAG:	case SONET_CLRDIAG:	case SONET_SETFRAMING:	case SONET_GETFRAMING:	case SONET_GETFRSENSE:		return do_atmif_sioc(fd, cmd32, arg);	}		for (i = 0; i < NR_ATM_IOCTL; i++) {			if (cmd32 == atm_ioctl_map[i].cmd32) {				cmd = atm_ioctl_map[i].cmd;				break;			}		}	        if (i == NR_ATM_IOCTL) {	        return -EINVAL;	        }                switch (cmd) {	case ATM_GETNAMES:		return do_atm_iobuf(fd, cmd, arg);	    	case ATM_GETLINKRATE:        case ATM_GETTYPE:        case ATM_GETESI:        case ATM_GETADDR:        case ATM_RSTADDR:        case ATM_ADDADDR:        case ATM_DELADDR:        case ATM_GETCIRANGE:	case ATM_SETCIRANGE:	case ATM_SETESI:	case ATM_SETESIF:	case ATM_GETSTAT:	case ATM_GETSTATZ:	case ATM_GETLOOP:	case ATM_SETLOOP:	case ATM_QUERYLOOP:                return do_atmif_sioc(fd, cmd, arg);        }        return -EINVAL;}#if defined(CONFIG_BLK_DEV_LVM) || defined(CONFIG_BLK_DEV_LVM_MODULE)/* Ugh, LVM. Pitty it was not cleaned up before accepted :((. */typedef struct {	uint8_t vg_name[NAME_LEN];	uint32_t vg_number;	uint32_t vg_access;	uint32_t vg_status;	uint32_t lv_max;	uint32_t lv_cur;	uint32_t lv_open;	uint32_t pv_max;

⌨️ 快捷键说明

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