code/cow_brd.c
static void copy_from_brd(void *dst, struct brd_device *brd, sector_t sector,
    size_t n)
{
  struct page *page;
  void *src;
  unsigned int offset = (sector & (PAGE_SECTORS-1)) << SECTOR_SHIFT;
  size_t copy;

  copy = min_t(size_t, n, PAGE_SIZE - offset);
  page = brd_lookup_page(brd, sector);
  if (page) {
    // Present in the new radix tree so this page has been modified.
    src = kmap_atomic(page);
    memcpy(dst, src + offset, copy);
    kunmap_atomic(src);
  } else if (brd->parent_brd &&
      (page = brd_lookup_page(brd->parent_brd, sector))) {
    // Present in the old radix tree so this page has not been modified.
    src = kmap_atomic(page);
    memcpy(dst, src + offset, copy);
    kunmap_atomic(src);
  } else {
    // Page doesn't exist in either radix tree so it must never have been
    // written.
    memset(dst, 0, copy);
  }

  if (copy < n) {
    dst += copy;
    sector += copy >> SECTOR_SHIFT;
    copy = n - copy;
    page = brd_lookup_page(brd, sector);
    if (page) {
      // Present in the new radix tree so this page has been modified.
      src = kmap_atomic(page);
      memcpy(dst, src, copy);
      kunmap_atomic(src);
    } else if (brd->parent_brd &&
        (page = brd_lookup_page(brd->parent_brd, sector))) {
      // Present in the old radix tree so this page has not been modified.
      src = kmap_atomic(page);
      memcpy(dst, src, copy);
      kunmap_atomic(src);
    } else {
      // Page doesn't exist in either radix tree so it must never have been
      // written.
      memset(dst, 0, copy);
    }
  }
}
/*
 * Copy n bytes to dst from the brd starting at sector. Does not sleep.
 */
Copy n bytes to dst from the brd starting at sector. Does not sleep.
Copy n bytes to dst from the brd starting at sector . Does not sleep .
static void copy_from_brd(void *dst, struct brd_device *brd, sector_t sector,
    size_t n)
{
  struct page *page;
  void *src;
  unsigned int offset = (sector & (PAGE_SECTORS-1)) << SECTOR_SHIFT;
  size_t copy;
  copy = min_t(size_t, n, PAGE_SIZE - offset);
  page = brd_lookup_page(brd, sector);
  if (page) {
    src = kmap_atomic(page);
    memcpy(dst, src + offset, copy);
    kunmap_atomic(src);
  } else if (brd->parent_brd &&
      (page = brd_lookup_page(brd->parent_brd, sector))) {
    src = kmap_atomic(page);
    memcpy(dst, src + offset, copy);
    kunmap_atomic(src);
  } else {
    memset(dst, 0, copy);
  }
  if (copy < n) {
    dst += copy;
    sector += copy >> SECTOR_SHIFT;
    copy = n - copy;
    page = brd_lookup_page(brd, sector);
    if (page) {
      src = kmap_atomic(page);
      memcpy(dst, src, copy);
      kunmap_atomic(src);
    } else if (brd->parent_brd &&
        (page = brd_lookup_page(brd->parent_brd, sector))) {
      src = kmap_atomic(page);
      memcpy(dst, src, copy);
      kunmap_atomic(src);
    } else {
      memset(dst, 0, copy);
    }
  }
}
static void copy_from_brd ( void * dst , struct brd_device * brd , sector_t sector , size_t n ) { struct page * page ; void * src ; unsigned int offset = ( sector & ( PAGE_SECTORS - 1 ) ) << SECTOR_SHIFT ; size_t copy ; copy = min_t ( size_t , n , PAGE_SIZE - offset ) ; page = brd_lookup_page ( brd , sector ) ; if ( page ) { src = kmap_atomic ( page ) ; memcpy ( dst , src + offset , copy ) ; kunmap_atomic ( src ) ; } else if ( brd -> parent_brd && ( page = brd_lookup_page ( brd -> parent_brd , sector ) ) ) { src = kmap_atomic ( page ) ; memcpy ( dst , src + offset , copy ) ; kunmap_atomic ( src ) ; } else { memset ( dst , 0 , copy ) ; } if ( copy < n ) { dst += copy ; sector += copy >> SECTOR_SHIFT ; copy = n - copy ; page = brd_lookup_page ( brd , sector ) ; if ( page ) { src = kmap_atomic ( page ) ; memcpy ( dst , src , copy ) ; kunmap_atomic ( src ) ; } else if ( brd -> parent_brd && ( page = brd_lookup_page ( brd -> parent_brd , sector ) ) ) { src = kmap_atomic ( page ) ; memcpy ( dst , src , copy ) ; kunmap_atomic ( src ) ; } else { memset ( dst , 0 , copy ) ; } } }
Copy n bytes to dst from the brd starting at sector.
Copy n bytes to dst from the brd starting at sector .
// Present in the new radix tree so this page has been modified. // Present in the old radix tree so this page has not been modified. // Page doesn't exist in either radix tree so it must never have been // written. // Present in the new radix tree so this page has been modified. // Present in the old radix tree so this page has not been modified. // Page doesn't exist in either radix tree so it must never have been // written.