源代码如下:
#include <linux/config.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/slab.h>
#include <linux/fs.h>
#include <linux/cdev.h>
#include <asm/uaccess.h>
//#include "scull.h"
#define SCULL_MAJOR 0 /* dynamic major by default */
#define SCULL_NR_DEVS 4 /* scull0 through scull3 */
#define SCULL_P_NR_DEVS 4 /* scullpipe0 through scullpipe3 */
#define SCULL_QUANTUM 4000
#define SCULL_QSET 1000
struct scull_qset {
void **data;
struct scull_qset *next;
};
struct scull_dev {
struct scull_qset *data; /* Pointer to first quantum set */
int quantum; /* the current quantum size */
int qset; /* the current array size */
unsigned long size; /* amount of data stored here */
unsigned int access_key; /* used by sculluid and scullpriv */
struct semaphore sem; /* mutual exclusion semaphore */
struct cdev cdev; /* Char device structure */
};
int scull_major = SCULL_MAJOR;
int scull_minor = 0;
int scull_nr_devs = SCULL_NR_DEVS;
int scull_quantum = SCULL_QUANTUM;
int scull_qset = SCULL_QSET;
module_param(scull_major, int, S_IRUGO);
module_param(scull_minor, int, S_IRUGO);
module_param(scull_nr_devs,int, S_IRUGO);
module_param(scull_quantum, int, S_IRUGO);
module_param(scull_qset,int,S_IRUGO);
MODULE_AUTHOR("BG2BKK");
MODULE_LICENSE("Dual BSD/GPL");
struct scull_dev *scull_devices;
int scull_trim(struct scull_dev *dev)
{
struct scull_qset *next,*dptr;
int qset = dev->qset;
int i;
for(dptr = dev->data; dptr;dptr = next)
{
if(dptr->data){
for (i=0;i<qset;i++)
kfree(dptr->data[i]);
kfree(dptr->data);
dptr->data = NULL;
}
next = dptr->next;
kfree(dptr);