void wtseek (void) { char *name; int fd; s64 i; name = RndName(); fd = creat(name, 0666); for (i = 0; Segment[i].offset >= 0; i++) { if (Segment[i].sparse && !Local_option.test_sparse) continue; write_segment(fd, Segment[i]); } close(fd); fd = open(name, O_RDONLY, 0); for (i = 0; Segment[i].offset >= 0; i++) { if (Segment[i].sparse && !Local_option.test_sparse) continue; check_segment(fd, Segment[i]); } for (i = 0; Hole[i].offset >= 0; i++) { if (Hole[i].sparse && !Local_option.test_sparse) continue; check_hole(fd, Hole[i]); } close(fd); free(name); }
static int compare_fiemap_and_map(int fd, char *map, int blocks, int blocksize) { struct fiemap *fiemap; char *fiebuf; int blocks_to_map, ret, cur_extent = 0, last_data; __u64 map_start, map_length; int i, c; blocks_to_map = (random() % blocks) + 1; fiebuf = malloc(sizeof(struct fiemap) + (blocks_to_map * sizeof(struct fiemap_extent))); if (!fiebuf) { perror("Could not allocate fiemap buffers"); return -1; } fiemap = (struct fiemap *) fiebuf; map_start = 0; map_length = blocks_to_map * blocksize; for (i = 0; i < blocks; i++) { if (map[i] != 'H') last_data = i; } fiemap->fm_flags = FIEMAP_FLAG_SYNC; fiemap->fm_extent_count = blocks_to_map; fiemap->fm_mapped_extents = 0; do { fiemap->fm_start = map_start; fiemap->fm_length = map_length; ret = ioctl(fd, FS_IOC_FIEMAP, (unsigned long) fiemap); if (ret < 0) { perror("FIEMAP ioctl failed"); free(fiemap); return -1; } if (check_flags(fiemap, blocksize)) goto error; for (i = cur_extent, c = 1; i < blocks; i++, c++) { __u64 logical_offset = i * blocksize; if (c > blocks_to_map) break; switch (map[i]) { case 'D': if (check_data(fiemap, logical_offset, blocksize, last_data == i, 0)) goto error; break; case 'H': if (check_hole(fiemap, fd, logical_offset, blocksize)) goto error; break; case 'P': if (check_data(fiemap, logical_offset, blocksize, last_data == i, 1)) goto error; break; default: printf("ERROR: weird value in map: %c\n", map[i]); goto error; } } cur_extent = i; map_start = i * blocksize; } while (cur_extent < blocks); ret = 0; return ret; error: printf("map is '%s'\n", map); show_extents(fiemap, blocksize); return -1; }