关于main.c中的错误可以参考scullp中的处理方法:
这里主要处理mmap的错误处理:
包含头文件
,否则会提示struct semaphore sem没有定义之类的错误。
关键的改变在mmap.c中,由于vm_operations_struct的变化,需要对mmap.c做如下变化:
1. 包含头文件,否则在函数scull_mmap中,会提示
vma->vm_private_data = filp->private_data;
dereferencing pointer to incomplete type.这是因为其找不到struct file的定义。
2. 以前的函数
struct page *scullv_vma_nopage(struct vm_area_struct *vma, unsigned long address, int *type)
现在其后面的参数address, type都可以通过结构struct vm_fault来获得。该函数需要改变为:
static int scullv_vma_fault (struct vm_area_struct *vma, struct vm_fault *vmf)
其函数体也需要作出相应改变:
-
-
static int scullv_vma_fault(struct vm_area_struct *vma,
-
struct vm_fault *vmf)
-
{
-
unsigned long offset;
-
struct scullv_dev *ptr, *dev = vma->vm_private_data;
-
struct page *page;
-
void *pageptr = NULL; /* default to "missing" */
-
pgoff_t pgoff = vmf->pgoff;
-
-
down(&dev->sem);
-
offset = (pgoff << PAGE_SHIFT) + (vma->vm_pgoff << PAGE_SHIFT);
-
if (offset >= dev->size) goto out; /* out of range */
-
-
/*
-
* Now retrieve the scullv device from the list,then the page.
-
* If the device has holes, the process receives a SIGBUS when
-
* accessing the hole.
-
*/
-
offset >>= PAGE_SHIFT; /* offset is a number of pages */
-
for (ptr = dev; ptr && offset >= dev->qset;) {
-
ptr = ptr->next;
-
offset -= dev->qset;
-
}
-
if (ptr && ptr->data) pageptr = ptr->data[offset];
-
if (!pageptr) goto out; /* hole or end-of-file */
-
-
/*
-
* After scullv lookup, "page" is now the address of the page
-
* needed by the current process. Since it's a vmalloc address,
-
* turn it into a struct page.
-
*/
-
page = vmalloc_to_page(pageptr);
-
if (!page)
-
return VM_FAULT_SIGBUS;
-
-
/* got it, now increment the count */
-
vmf->page = page;
-
-
out:
-
up(&dev->sem);
-
return 0;
-
}
3. 在结构scull_vm_ops初始化时:
去掉.nopage = scullv_vma_nopage,
修改为.fault = scullv_vma_fault,
阅读(797) | 评论(0) | 转发(0) |