- } else if(
- ((file_off < ((obj->paging_offset) + obj_off)) &&
- ((file_off + len) >
- ((obj->paging_offset) + obj_off))) ||
- ((file_off > ((obj->paging_offset) + obj_off)) &&
- (((((obj->paging_offset) + obj_off)) + len)
- > file_off))) {
- vm_map_unlock(map);
- return KERN_FAILURE;
+ } else {
+ vm_object_offset_t obj_off_aligned;
+ vm_object_offset_t file_off_aligned;
+
+ obj_off_aligned = obj_off & ~PAGE_MASK;
+ file_off_aligned = file_off & ~PAGE_MASK;
+
+ if (file_off_aligned == (obj->paging_offset + obj_off_aligned)) {
+ /*
+ * the target map and the file offset start in the same page
+ * but are not identical...
+ */
+ vm_map_unlock(map);
+ return KERN_FAILURE;
+ }
+ if ((file_off < (obj->paging_offset + obj_off_aligned)) &&
+ ((file_off + len) > (obj->paging_offset + obj_off_aligned))) {
+ /*
+ * some portion of the tail of the I/O will fall
+ * within the encompass of the target map
+ */
+ vm_map_unlock(map);
+ return KERN_FAILURE;
+ }
+ if ((file_off_aligned > (obj->paging_offset + obj_off)) &&
+ (file_off_aligned < (obj->paging_offset + obj_off) + len)) {
+ /*
+ * the beginning page of the file offset falls within
+ * the target map's encompass
+ */
+ vm_map_unlock(map);
+ return KERN_FAILURE;
+ }