void vnclear(struct vn_softc *vn, vfs_context_t ctx) { if (vn->sc_vp != NULL) { /* release long-term reference */ (void)vn_close(vn->sc_vp, vn->sc_open_flags, ctx); vn->sc_vp = NULL; } if (vn->sc_shadow_vp != NULL) { /* release long-term reference */ (void)vn_close(vn->sc_shadow_vp, FREAD | FWRITE, ctx); vn->sc_shadow_vp = NULL; } if (vn->sc_shadow_map != NULL) { shadow_map_free(vn->sc_shadow_map); vn->sc_shadow_map = NULL; } vn->sc_flags &= ~(VNF_INITED | VNF_READONLY); if (vn->sc_cred) { kauth_cred_unref(&vn->sc_cred); } vn->sc_size = 0; vn->sc_fsize = 0; if (vn->sc_cdev) { devfs_remove(vn->sc_cdev); vn->sc_cdev = NULL; } }
int main() { shadow_map_t * map; int i; block_request_t requests[] = { { WriteRequest, BAND_SIZE_BLOCKS * 2, 1 }, { ReadRequest, BAND_SIZE_BLOCKS / 2, BAND_SIZE_BLOCKS * 2 - 2 }, { WriteRequest, BAND_SIZE_BLOCKS * 1, 5 * BAND_SIZE_BLOCKS + 3}, { ReadRequest, 0, BAND_SIZE_BLOCKS * 10 }, { WriteRequest, BAND_SIZE_BLOCKS * (BAND_MAX - 1), BAND_SIZE_BLOCKS * 2}, { 0, 0 }, }; map = shadow_map_create(1024 * 1024 * 1024 * 8ULL, 0, 0, 512); if (map == NULL) { printf("shadow_map_create failed\n"); exit(1); } for (i = 0; TRUE; i++) { u_long offset; u_long resid; boolean_t shadow_grew; boolean_t read_shadow; if (requests[i].count == 0) { break; } offset = requests[i].offset; resid = requests[i].count; printf("\n%s REQUEST (%ld, %ld)\n", requests[i].type == WriteRequest ? "WRITE" : "READ", offset, resid); switch (requests[i].type) { case WriteRequest: while (resid > 0) { u_long this_offset; u_long this_count; shadow_grew = shadow_map_write(map, offset, resid, &this_offset, &this_count); printf("\t(%ld, %ld) => (%ld, %ld)", offset, resid, this_offset, this_count); resid -= this_count; offset += this_count; if (shadow_grew) { printf(" shadow grew to %ld", shadow_map_shadow_size(map)); } printf("\n"); } break; case ReadRequest: while (resid > 0) { u_long this_offset; u_long this_count; read_shadow = shadow_map_read(map, offset, resid, &this_offset, &this_count); printf("\t(%ld, %ld) => (%ld, %ld)%s\n", offset, resid, this_offset, this_count, read_shadow ? " from shadow" : ""); if (this_count == 0) { printf("this_count is 0, aborting\n"); break; } resid -= this_count; offset += this_count; } break; default: break; } } if (map) { shadow_map_free(map); } exit(0); return (0); }