static void _verify(struct fixture *f, uint64_t byte_b, uint64_t byte_e, uint8_t pat) { struct block *b; block_address bb = byte_b / T_BLOCK_SIZE; block_address be = (byte_e + T_BLOCK_SIZE - 1) / T_BLOCK_SIZE; uint64_t offset = byte_b % T_BLOCK_SIZE; uint64_t blen, len = byte_e - byte_b; // Verify via bcache_read_bytes { unsigned i; size_t len2 = byte_e - byte_b; uint8_t *buffer = malloc(len2); T_ASSERT(bcache_read_bytes(f->cache, f->fd, byte_b, len2, buffer)); for (i = 0; i < len; i++) T_ASSERT_EQUAL(buffer[i], _pattern_at(pat, byte_b + i)); free(buffer); } // Verify again, driving bcache directly for (; bb != be; bb++) { T_ASSERT(bcache_get(f->cache, f->fd, bb, 0, &b)); blen = _min(T_BLOCK_SIZE - offset, len); _verify_bytes(b, bb * T_BLOCK_SIZE, offset, blen, pat); offset = 0; len -= blen; bcache_put(b); } }
/** * bce_type - get type of binding cache entry * @our_addr: our IPv6 address * @peer_addr: peer's IPv6 address * * Looks up entry from binding cache and returns its type. If not * found, returns -%ENOENT. **/ int bce_type(const struct in6_addr *our_addr, const struct in6_addr *peer_addr) { struct bcentry *bce; int type; bce = bcache_get(our_addr, peer_addr); if (bce == NULL) return -ENOENT; type = bce->type; bcache_release_entry(bce); return type; }
static void _verify_set(struct fixture *f, uint64_t byte_b, uint64_t byte_e, uint8_t val) { unsigned i; struct block *b; block_address bb = byte_b / T_BLOCK_SIZE; block_address be = (byte_e + T_BLOCK_SIZE - 1) / T_BLOCK_SIZE; uint64_t offset = byte_b % T_BLOCK_SIZE; uint64_t blen, len = byte_e - byte_b; for (; bb != be; bb++) { T_ASSERT(bcache_get(f->cache, f->fd, bb, 0, &b)); blen = _min(T_BLOCK_SIZE - offset, len); for (i = 0; i < blen; i++) T_ASSERT(((uint8_t *) b->data)[offset + i] == val); offset = 0; len -= blen; bcache_put(b); } }