📄 zlg_ffs_uclinx.c
字号:
/*********************************************************************************************************
** Function name: zlg_ffs_release
** Descriptions: release device
** Input:inode: information of device
** filp: pointer of file
** Output 0: OK
** other: not OK
** Created by: Chenmingji
** Created Date: 2005-3-23
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified Date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
static int zlg_ffs_release(struct inode *inode, struct file *filp) { int num; Disk_RW_Parameter dp; unsigned long flag; num = MINOR(inode->i_rdev); if (num >= MAX_DRIVES) { return -ENODEV; } local_irq_save(flag); ZLG_FFS_usage[num]--; if (ZLG_FFS_usage[num] == 0) { dp.RsvdForLow = FFSDiskInfo + num; ZLG_FFS(DISK_CLOSE, &dp); } local_irq_restore(flag); MOD_DEC_USE_COUNT; return(0); } /*********************************************************************************************************
** Function name: zlg_ffs_ioctl
** Descriptions: IO control function
** Input:inode: information of device
** filp: pointer of file
** cmd: command
** arg: additive parameter
** Output 0: OK
** other: not OK
** Created by: Chenmingji
** Created Date: 2005-3-23
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified Date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
static int zlg_ffs_ioctl(struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg){ long size; struct hd_geometry geo; switch(cmd) { case BLKGETSIZE: /* Return the device size, expressed in sectors */ if (arg == 0) { return -EINVAL; /* NULL pointer: not valid */ } if(access_ok(VERIFY_WRITE, arg, sizeof(long)) == 0) { return -EFAULT; } size = 1024 * ZLG_FFS_sizes[MINOR(inode->i_rdev)] / ZLG_FFS_blocksizes[MINOR(inode->i_rdev)]; if (copy_to_user((long *) arg, &size, sizeof (long))) { return -EFAULT; } return 0; case BLKRRPART: /* re-read partition table: can't do it */ return -ENOTTY; case HDIO_GETGEO: /* * Get geometry: since we are a virtual device, we have to make * up something plausible. So we claim 16 sectors, four heads, * and calculate the corresponding number of cylinders. We set the * start of data at sector four. */ if (access_ok(VERIFY_WRITE, arg, sizeof(geo)) == 0) { return -EFAULT; } size = 1024 * ZLG_FFS_sizes[MINOR(inode->i_rdev)] / ZLG_FFS_blocksizes[MINOR(inode->i_rdev)]; geo.cylinders = (size & ~0x3f) >> 6; geo.heads = 4; geo.sectors = 16; geo.start = 0; if (copy_to_user((void *) arg, &geo, sizeof(geo))) { return -EFAULT; } return 0; default: /* * For ioctls we don't understand, let the block layer handle them. */ return blk_ioctl(inode->i_rdev, cmd, arg); } return -ENOTTY; /* unknown command */}/*********************************************************************************************************
** Function name: check_zlg_ffs_change
** Descriptions:
** Input:dev:
** Output 0: OK
** other: not OK
** Created by: Chenmingji
** Created Date: 2005-3-23
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified Date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
static int check_zlg_ffs_change(kdev_t dev){ return 0;}/*********************************************************************************************************
** Function name: zlg_ffs_revalidate
** Descriptions: revalidate device
** Input:dev: nformation of device
** Output 0: OK
** 1: not OK
** Created by: Chenmingji
** Created Date: 2005-3-23
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified Date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
static int zlg_ffs_revalidate(kdev_t dev){ return 0;}/*********************************************************************************************************
** Function name: zlg_ffs_init
** Descriptions: init driver
** Input:none
** Output 0: OK
** other: not OK
** Created by: Chenmingji
** Created Date: 2005-3-23
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified Date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
int zlg_ffs_init(void){ int result; init_flash(); result = register_blkdev(MAJOR_NR, DEVICE_NAME, &zlg_ffs_fops); if (result < 0) { printk(KERN_ERR DEVICE_NAME ": Unable to get major %d\n", MAJOR_NR ); return(result); } if (MAJOR_NR == 0) { MAJOR_NR = result; /* dynamic */ } blk_queue_make_request(BLK_DEFAULT_QUEUE(MAJOR_NR), zlg_ffs_make_request); //blk_init_queue(BLK_DEFAULT_QUEUE(MAJOR_NR), zlg_ffs_release); blk_size[MAJOR_NR] = ZLG_FFS_sizes; blksize_size[MAJOR_NR] = ZLG_FFS_blocksizes; printk(KERN_INFO DEVICE_NAME ": zlg_ffs_init OK\n"); return(0); }/*********************************************************************************************************
** Function name: zlg_ffs_cleanup
** Descriptions: exit driver
** Input:none
** Output none
** Created by: Chenmingji
** Created Date: 2005-3-23
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified Date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
void zlg_ffs_cleanup(void){ unregister_blkdev(MAJOR_NR, DEVICE_NAME);}#undef IN_ZLG_FFS_UCLINUX/*********************************************************************************************************** End Of File********************************************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -