Changeset 20707 in vbox for trunk/src/VBox/Additions/linux/sharedfolders/regops.c
- Timestamp:
- Jun 19, 2009 10:00:00 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/linux/sharedfolders/regops.c
r20342 r20707 38 38 pos, nread, buf, false /* already locked? */); 39 39 if (RT_FAILURE (rc)) { 40 LogFunc(("vboxCallRead failed. caller=%s, rc=%Rrc\n", 41 caller, rc)); 40 LogFunc(("vboxCallRead(%s) failed. caller=%s, rc=%Rrc\n", 41 sf_i->path->String.utf8, caller, rc)); 42 return -EPROTO; 43 } 44 return 0; 45 } 46 47 static int 48 sf_reg_write_aux (const char *caller, struct sf_glob_info *sf_g, 49 struct sf_reg_info *sf_r, void *buf, uint32_t *nwritten, 50 uint64_t pos) 51 { 52 int rc = vboxCallWrite (&client_handle, &sf_g->map, sf_r->handle, 53 pos, nwritten, buf, false /* already locked? */); 54 if (RT_FAILURE (rc)) { 55 LogFunc(("vboxCallWrite(%s) failed rc=%Rrc\n", 56 sf_i->path->String.utf8, caller, rc)); 42 57 return -EPROTO; 43 58 } … … 85 100 86 101 err = sf_reg_read_aux (__func__, sf_g, sf_r, tmp, &nread, pos); 87 if (err) {102 if (err) 88 103 goto fail; 89 }90 104 91 105 if (copy_to_user (buf, tmp, nread)) { … … 151 165 152 166 while (left) { 153 int rc;154 167 uint32_t to_write, nwritten; 155 168 … … 165 178 } 166 179 167 rc = vboxCallWrite (&client_handle, &sf_g->map, sf_r->handle, 168 pos, &nwritten, tmp, false /* already locked? */); 169 if (RT_FAILURE (rc)) { 170 err = -EPROTO; 171 LogFunc(("vboxCallWrite(%s) failed rc=%Rrc\n", 172 sf_i->path->String.utf8, rc)); 180 err = sf_reg_write_aux (__func__, sf_g, sf_r, tmp, &nwritten, pos); 181 if (err) 173 182 goto fail; 174 }175 183 176 184 pos += nwritten; … … 178 186 buf += nwritten; 179 187 total_bytes_written += nwritten; 180 if (nwritten != to_write) { 181 break; 182 } 188 if (nwritten != to_write) 189 break; 183 190 } 184 191 … … 297 304 sf_i->force_restat = 1; 298 305 sf_r->handle = params.Handle; 306 sf_i->file = file; 299 307 file->private_data = sf_r; 300 308 return rc_linux; … … 307 315 struct sf_reg_info *sf_r; 308 316 struct sf_glob_info *sf_g; 317 struct sf_inode_info *sf_i = GET_INODE_INFO (inode); 309 318 310 319 TRACE (); … … 321 330 322 331 kfree (sf_r); 332 sf_i->file = NULL; 323 333 file->private_data = NULL; 324 334 return 0; … … 468 478 sf_readpage(struct file *file, struct page *page) 469 479 { 470 char *buf = kmap(page);471 480 struct inode *inode = file->f_dentry->d_inode; 472 481 struct sf_glob_info *sf_g = GET_GLOB_INFO (inode->i_sb); 473 482 struct sf_reg_info *sf_r = file->private_data; 474 483 uint32_t nread = PAGE_SIZE; 475 loff_t off = page->index << PAGE_SHIFT; 484 char *buf; 485 loff_t off = ((loff_t)page->index) << PAGE_SHIFT; 476 486 int ret; 477 487 478 488 TRACE (); 479 489 490 buf = kmap(page); 480 491 ret = sf_reg_read_aux (__func__, sf_g, sf_r, buf, &nread, off); 481 492 if (ret) { 482 493 kunmap (page); 494 if (PageLocked(page)) 495 unlock_page(page); 483 496 return ret; 484 497 } 498 BUG_ON (nread > PAGE_SIZE); 499 memset(&buf[nread], 0, PAGE_SIZE - nread); 485 500 flush_dcache_page (page); 486 501 kunmap (page); 487 502 SetPageUptodate(page); 488 if (PageLocked(page))489 503 unlock_page(page); 490 504 return 0; 491 505 } 492 506 507 static int 508 sf_writepage(struct page *page, struct writeback_control *wbc) 509 { 510 struct address_space *mapping = page->mapping; 511 struct inode *inode = mapping->host; 512 struct sf_glob_info *sf_g = GET_GLOB_INFO (inode->i_sb); 513 struct sf_inode_info *sf_i = GET_INODE_INFO (inode); 514 struct file *file = sf_i->file; 515 struct sf_reg_info *sf_r = file->private_data; 516 char *buf; 517 uint32_t nwritten = PAGE_SIZE; 518 int end_index = inode->i_size >> PAGE_SHIFT; 519 loff_t off = ((loff_t) page->index) << PAGE_SHIFT; 520 int err; 521 522 TRACE (); 523 524 if (page->index >= end_index) 525 nwritten = inode->i_size & (PAGE_SIZE-1); 526 527 buf = kmap(page); 528 529 err = sf_reg_write_aux (__func__, sf_g, sf_r, buf, &nwritten, off); 530 if (err < 0) { 531 ClearPageUptodate(page); 532 goto out; 533 } 534 535 if (off > inode->i_size) 536 inode->i_size = off; 537 538 if (PageError(page)) 539 ClearPageError(page); 540 err = 0; 541 out: 542 kunmap(page); 543 544 unlock_page(page); 545 return err; 546 } 547 548 # if LINUX_VERSION_CODE >= KERNEL_VERSION (2, 6, 24) 549 int 550 sf_write_begin(struct file *file, struct address_space *mapping, loff_t pos, 551 unsigned len, unsigned flags, struct page **pagep, void **fsdata) 552 { 553 pgoff_t index = pos >> PAGE_SHIFT; 554 555 TRACE (); 556 557 *pagep = grab_cache_page_write_begin(mapping, index, flags); 558 if (!*pagep) 559 return -ENOMEM; 560 return 0; 561 } 562 563 int 564 sf_write_end(struct file *file, struct address_space *mapping, loff_t pos, 565 unsigned len, unsigned copied, struct page *page, void *fsdata) 566 { 567 struct inode *inode = mapping->host; 568 struct sf_glob_info *sf_g = GET_GLOB_INFO (inode->i_sb); 569 struct sf_reg_info *sf_r = file->private_data; 570 void *buf; 571 unsigned from = pos & (PAGE_SIZE - 1); 572 uint32_t nwritten = len; 573 int err; 574 575 TRACE (); 576 577 buf = kmap(page); 578 err = sf_reg_write_aux (__func__, sf_g, sf_r, buf+from, &nwritten, pos); 579 kunmap(page); 580 581 if (!PageUptodate(page) && err == PAGE_SIZE) 582 SetPageUptodate(page); 583 584 if (err >= 0) { 585 pos += nwritten; 586 if (pos > inode->i_size) 587 inode->i_size = pos; 588 } 589 590 unlock_page(page); 591 page_cache_release(page); 592 593 return nwritten; 594 } 595 596 # endif /* KERNEL_VERSION >= 2.6.24 */ 597 493 598 struct address_space_operations sf_reg_aops = { 494 599 .readpage = sf_readpage, 600 .writepage = sf_writepage, 495 601 # if LINUX_VERSION_CODE >= KERNEL_VERSION (2, 6, 24) 496 .write_begin = s imple_write_begin,497 .write_end = s imple_write_end,602 .write_begin = sf_write_begin, 603 .write_end = sf_write_end, 498 604 # else 499 605 .prepare_write = simple_prepare_write,
Note:
See TracChangeset
for help on using the changeset viewer.