资源简介
根据linux下的usb-skeleton.c改写的U盘驱动程序,包括.c .o文件和Makefile文件,可以直接编译

代码片段和文件信息
/*
* My UDisk driver - 0.1
*
* TODO:
* - fix urb->status race condition in write sequence
* - move minor_table to a dynamic list.
*
* History:
*
* 2008_01_9 - 0.1 - zero out dev in probe function for devices that do
*
*/
#define __KERNEL__
#define MODULE
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define MAJOR_NR 42 // 定义主设备号
#define DEVICE_NAME “myudisk“ // 定义设备名
#define DEVICE_NR(device) (MINOR(device))
#define DEVICE_ON(device)
#define DEVICE_OFF(device)
#define DEVICE_NO_RANDOM
#include
#define MYUDISK_SECTOR_BITS 9 /* 2**9 byte hardware sector */
#define MYUDISK_BLOCK_SIZE 1024 /* block size */ //定义了一个块的大小,以字节为单位
#define MYUDISK_TOTAL_SIZE 2048 /* size in blocks */ //定义了这个虚拟盘的容量,以块为单位
/* the storage pool */
//static char *myudisk_storage; //这个指针是全局变量,指向用于虚拟盘的内存
static int myudisk_sectorsize = 1 << MYUDISK_SECTOR_BITS;
static int myudisk_blocksize = MYUDISK_BLOCK_SIZE;
static int myudisk_size ;
static int myudisk_readahead = 4;
#define CONFIG_USB_DEBUG
#ifdef CONFIG_USB_DEBUG
static int debug = 1;
#else
static int debug;
#endif
/* Use our own dbg macro */
#undef dbg
#define dbg(format arg...) do { if (debug) printk(KERN_DEBUG __FILE__ “(%s): “ format “\n“ __FUNCTION__ ## arg); } while (0)
/* Version Information */
#define DRIVER_VERSION “v0.1“
#define DRIVER_AUTHOR “Wen Yan Jun yjwen@nudt.edu.cn“
#define DRIVER_DESC “My UDisk Driver“
/* Module paramaters */
MODULE_PARM(debug “i“);
MODULE_PARM_DESC(debug “Debug enabled or not“);
/* Define these values to match your device */
#define MY_UDISK_VENDOR_ID 0x58f
#define MY_UDISK_PRODUCT_ID 0x9380
/* table of devices that work with this driver */
/*当usb设备插入时,为了使linux系统自动装载驱动程序,需要创建一个MODULE_DEVICE_TABLE,这个模块仅支持某一特定设备*/
static struct usb_device_id myudisk_table [] = {
{ USB_DEVICE(MY_UDISK_VENDOR_ID MY_UDISK_PRODUCT_ID) }
{ } /* Terminating entry */
};
MODULE_DEVICE_TABLE (usb myudisk_table);
/* Get a minor range for your devices from the usb maintainer */
#define MY_UDISK_MINOR_base 192
/* we can have up to this number of device plugged in at once */
#define MAX_DEVICES 16
/* Structure to hold all of our device specific stuff */
struct my_udisk {
struct usb_device * udev; /* 保存usb设备指针 */
struct usb_interface * interface; /* usb所插入接口指针 */
devfs_handle_t devfs; /* devfs device node */
unsigned char minor; /* the starting minor number for this device */
unsigned char num_ports; /* the number of ports this device has */
char num_interrupt_in; /* number of interrupt in endpoints we have */
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 288 2007-12-28 01:47 Udisk\Makefile
文件 45390 2009-07-17 09:59 Udisk\myudisk.c
文件 31413 2005-12-23 18:47 Udisk\myudisk.o
目录 0 2009-07-18 15:43 Udisk
----------- --------- ---------- ----- ----
77091 4
相关资源
- uboot到linux logo显示不间断 补丁
- UNIX/LINUX编程实践教程的源码
- Linux任务管理器
- linux应用层的华容道游戏源代码
- [免费]安全加密软件U盘加密,文件加
- ubuntu9.10 可加载内核模块和字符设备驱
- MP3文件ID3v2ID3v2APEv2标签读取
- U盘强力修复器SD_MMC等内存卡超强修复
- 操作系统实验——虚存管理实验
- linux下的发包工具sendip
- 尚观培训linux许巍关于c 的笔记和讲义
- 尚观培训linux董亮老师关于数据结构的
- windows下制作macOS安装U盘,绝对简单好
- linux 线程池源码 c 版
- linux C 电梯程序练习
- U盘大盗者轻取老师课件
- linux下用多进程同步方法解决生产者
- 自动复制U盘数据程序
- U盘量产工具 全世界最简单教程
- 金士顿u盘修复 金士顿量产工具 量产
- Linux 操作系统实验(全)
- Linux From Scratch 中文手册
- linux 网络实验 ftp程序
- Linux命令大全离线版&在线版
- 操作系统共享内存实验
- dos 下运行Linux 命令--gnu_utils
- linux 0.12内核源代码
- linux简易shell C实现
- linux实验报告及心得体会
- 基于GTK的Linux环境下的简易任务管理器
评论
共有 条评论