Lines Matching full:ch

135 	struct chunk *ch;  in image_chunk_find()  local
137 ch = (last != NULL && last->ch_block <= blk) in image_chunk_find()
139 while (ch != NULL) { in image_chunk_find()
140 if (ch->ch_block <= blk && in image_chunk_find()
141 (lba_t)(ch->ch_block + (ch->ch_size / secsz)) > blk) { in image_chunk_find()
142 last = ch; in image_chunk_find()
145 ch = TAILQ_NEXT(ch, ch_list); in image_chunk_find()
147 return (ch); in image_chunk_find()
151 image_chunk_grow(struct chunk *ch, size_t sz) in image_chunk_grow() argument
155 newsz = ch->ch_size + sz; in image_chunk_grow()
156 if (newsz > ch->ch_size) { in image_chunk_grow()
157 ch->ch_size = newsz; in image_chunk_grow()
161 dsz = SIZE_MAX - ch->ch_size; in image_chunk_grow()
163 ch->ch_size = SIZE_MAX; in image_chunk_grow()
168 image_chunk_memory(struct chunk *ch, lba_t blk) in image_chunk_memory() argument
177 if (ch->ch_block < blk) { in image_chunk_memory()
183 memcpy(new, ch, sizeof(*new)); in image_chunk_memory()
184 ch->ch_size = (blk - ch->ch_block) * secsz; in image_chunk_memory()
186 new->ch_size -= ch->ch_size; in image_chunk_memory()
187 TAILQ_INSERT_AFTER(&image_chunks, ch, new, ch_list); in image_chunk_memory()
189 ch = new; in image_chunk_memory()
192 if (ch->ch_size > secsz) { in image_chunk_memory()
198 memcpy(new, ch, sizeof(*new)); in image_chunk_memory()
199 ch->ch_size = secsz; in image_chunk_memory()
202 TAILQ_INSERT_AFTER(&image_chunks, ch, new, ch_list); in image_chunk_memory()
206 ch->ch_type = CH_TYPE_MEMORY; in image_chunk_memory()
207 ch->ch_u.mem.ptr = ptr; in image_chunk_memory()
208 return (ch); in image_chunk_memory()
214 struct chunk *ch; in image_chunk_skipto() local
218 ch = TAILQ_LAST(&image_chunks, chunk_head); in image_chunk_skipto()
219 from = (ch != NULL) ? ch->ch_block + (ch->ch_size / secsz) : 0LL; in image_chunk_skipto()
230 if (ch != NULL && ch->ch_type == CH_TYPE_ZEROES) { in image_chunk_skipto()
231 sz = image_chunk_grow(ch, sz); in image_chunk_skipto()
234 from = ch->ch_block + (ch->ch_size / secsz); in image_chunk_skipto()
236 ch = malloc(sizeof(*ch)); in image_chunk_skipto()
237 if (ch == NULL) in image_chunk_skipto()
239 memset(ch, 0, sizeof(*ch)); in image_chunk_skipto()
240 ch->ch_block = from; in image_chunk_skipto()
241 ch->ch_size = sz; in image_chunk_skipto()
242 ch->ch_type = CH_TYPE_ZEROES; in image_chunk_skipto()
243 TAILQ_INSERT_TAIL(&image_chunks, ch, ch_list); in image_chunk_skipto()
251 struct chunk *ch; in image_chunk_append() local
253 ch = TAILQ_LAST(&image_chunks, chunk_head); in image_chunk_append()
254 if (ch != NULL && ch->ch_type == CH_TYPE_FILE) { in image_chunk_append()
255 if (fd == ch->ch_u.file.fd && in image_chunk_append()
256 blk == (lba_t)(ch->ch_block + (ch->ch_size / secsz)) && in image_chunk_append()
257 ofs == (off_t)(ch->ch_u.file.ofs + ch->ch_size)) { in image_chunk_append()
258 sz = image_chunk_grow(ch, sz); in image_chunk_append()
261 blk = ch->ch_block + (ch->ch_size / secsz); in image_chunk_append()
262 ofs = ch->ch_u.file.ofs + ch->ch_size; in image_chunk_append()
265 ch = malloc(sizeof(*ch)); in image_chunk_append()
266 if (ch == NULL) in image_chunk_append()
268 memset(ch, 0, sizeof(*ch)); in image_chunk_append()
269 ch->ch_block = blk; in image_chunk_append()
270 ch->ch_size = sz; in image_chunk_append()
271 ch->ch_type = CH_TYPE_FILE; in image_chunk_append()
272 ch->ch_u.file.ofs = ofs; in image_chunk_append()
273 ch->ch_u.file.fd = fd; in image_chunk_append()
274 TAILQ_INSERT_TAIL(&image_chunks, ch, ch_list); in image_chunk_append()
603 struct chunk *ch; in image_copyout_region() local
611 ch = image_chunk_find(blk); in image_copyout_region()
612 if (ch == NULL) { in image_copyout_region()
616 ofs = (blk - ch->ch_block) * secsz; in image_copyout_region()
617 sz = ch->ch_size - ofs; in image_copyout_region()
619 switch (ch->ch_type) { in image_copyout_region()
624 error = image_copyout_file(fd, sz, ch->ch_u.file.fd, in image_copyout_region()
625 ch->ch_u.file.ofs + ofs); in image_copyout_region()
628 error = image_copyout_memory(fd, sz, ch->ch_u.mem.ptr); in image_copyout_region()
642 struct chunk *ch; in image_data() local
646 ch = image_chunk_find(blk); in image_data()
647 if (ch == NULL) in image_data()
649 if (ch->ch_type != CH_TYPE_ZEROES) in image_data()
651 lim = ch->ch_block + (ch->ch_size / secsz); in image_data()
681 struct chunk *ch; in image_write() local
685 ch = image_chunk_find(blk); in image_write()
686 if (ch == NULL) in image_write()
689 if (ch->ch_type == CH_TYPE_FILE) in image_write()
691 if (ch->ch_type == CH_TYPE_ZEROES) { in image_write()
692 ch = image_chunk_memory(ch, blk); in image_write()
693 if (ch == NULL) in image_write()
696 assert(ch->ch_type == CH_TYPE_MEMORY); in image_write()
697 memcpy(ch->ch_u.mem.ptr, buf, secsz); in image_write()
709 struct chunk *ch; in image_cleanup() local
711 while ((ch = TAILQ_FIRST(&image_chunks)) != NULL) { in image_cleanup()
712 switch (ch->ch_type) { in image_cleanup()
715 if (ch->ch_u.file.fd != -1) in image_cleanup()
716 close(ch->ch_u.file.fd); in image_cleanup()
719 free(ch->ch_u.mem.ptr); in image_cleanup()
724 TAILQ_REMOVE(&image_chunks, ch, ch_list); in image_cleanup()
725 free(ch); in image_cleanup()