Changeset 77420 in vbox for trunk/src/VBox/Additions
- Timestamp:
- Feb 22, 2019 2:14:17 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/linux/sharedfolders/regops.c
r77419 r77420 74 74 75 75 /* fops */ 76 static int sf_reg_read_aux(const char *caller, struct sf_glob_info *sf_g,77 struct sf_reg_info *sf_r, void *buf,78 uint32_t * nread, uint64_t pos)79 {80 /** @todo bird: yes, kmap() and kmalloc() input only. Since the buffer is81 * contiguous in physical memory (kmalloc or single page), we should82 * use a physical address here to speed things up. */83 int rc = VbglR0SfRead(&client_handle, &sf_g->map, sf_r->handle,84 pos, nread, buf, false /* already locked? */ );85 if (RT_FAILURE(rc)) {86 LogFunc(("VbglR0SfRead failed. caller=%s, rc=%Rrc\n", caller,87 rc));88 return -EPROTO;89 }90 return 0;91 }92 76 93 77 static int sf_reg_write_aux(const char *caller, struct sf_glob_info *sf_g, … … 160 144 .get = sf_pipe_buf_get, 161 145 }; 146 147 static int sf_reg_read_aux(const char *caller, struct sf_glob_info *sf_g, 148 struct sf_reg_info *sf_r, void *buf, 149 uint32_t * nread, uint64_t pos) 150 { 151 int rc = VbglR0SfRead(&client_handle, &sf_g->map, sf_r->handle, 152 pos, nread, buf, false /* already locked? */ ); 153 if (RT_FAILURE(rc)) { 154 LogFunc(("VbglR0SfRead failed. caller=%s, rc=%Rrc\n", caller, 155 rc)); 156 return -EPROTO; 157 } 158 return 0; 159 } 162 160 163 161 # define LOCK_PIPE(pipe) do { if (pipe->inode) mutex_lock(&pipe->inode->i_mutex); } while (0) … … 1093 1091 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0) 1094 1092 1093 /** 1094 * Used to read the content of a page into the page cache. 1095 * 1096 * Needed for mmap and reads+writes when the file is mmapped in a 1097 * shared+writeable fashion. 1098 */ 1095 1099 static int sf_readpage(struct file *file, struct page *page) 1096 1100 { 1097 1101 struct inode *inode = GET_F_DENTRY(file)->d_inode; 1098 struct sf_glob_info *sf_g = GET_GLOB_INFO(inode->i_sb); 1099 struct sf_reg_info *sf_r = file->private_data; 1100 uint32_t nread = PAGE_SIZE; 1101 char *buf; 1102 loff_t off = (loff_t)page->index << PAGE_SHIFT; 1103 int ret; 1102 int err; 1104 1103 1105 1104 TRACE(); 1106 1107 buf = kmap(page); 1108 ret = sf_reg_read_aux(__func__, sf_g, sf_r, buf, &nread, off); 1109 if (ret) { 1110 kunmap(page); 1111 if (PageLocked(page)) 1112 unlock_page(page); 1113 return ret; 1114 } 1115 BUG_ON(nread > PAGE_SIZE); 1116 memset(&buf[nread], 0, PAGE_SIZE - nread); 1117 flush_dcache_page(page); 1118 kunmap(page); 1119 SetPageUptodate(page); 1105 if (!is_bad_inode(inode)) { 1106 VBOXSFREADPGLSTREQ *pReq = (VBOXSFREADPGLSTREQ *)VbglR0PhysHeapAlloc(sizeof(*pReq)); 1107 if (pReq) { 1108 struct sf_glob_info *sf_g = GET_GLOB_INFO(inode->i_sb); 1109 struct sf_reg_info *sf_r = file->private_data; 1110 uint8_t *pbMapped = (g_fHostFeatures & VMMDEV_HVF_HGCM_CONTIGUOUS_PAGE_LIST) 1111 ? NULL : (uint8_t *)kmap(page); 1112 int vrc = VbglR0SfHostReqReadContig(sf_g->map.root, 1113 pReq, 1114 sf_r->handle, 1115 (uint64_t)page->index << PAGE_SHIFT, 1116 PAGE_SIZE, 1117 pbMapped, 1118 page_to_phys(page)); 1119 uint32_t cbRead = pReq->Parms.cb32Read.u.value32; 1120 AssertStmt(cbRead <= PAGE_SIZE, cbRead = PAGE_SIZE); 1121 VbglR0PhysHeapFree(pReq); 1122 1123 if (RT_SUCCESS(vrc)) { 1124 if (cbRead == PAGE_SIZE) { 1125 /* likely */ 1126 } else { 1127 if (!pbMapped) 1128 pbMapped = (uint8_t *)kmap(page); 1129 RT_BZERO(&pbMapped[cbRead], PAGE_SIZE - cbRead); 1130 /** @todo truncate the inode file size? */ 1131 } 1132 flush_dcache_page(page); 1133 SetPageUptodate(page); 1134 unlock_page(page); 1135 err = 0; 1136 } else 1137 err = -EPROTO; 1138 if (pbMapped) 1139 kunmap(page); 1140 } else 1141 err = -ENOMEM; 1142 } else 1143 err = -EIO; 1120 1144 unlock_page(page); 1121 return 0;1145 return err; 1122 1146 } 1123 1147
Note:
See TracChangeset
for help on using the changeset viewer.