Lines Matching refs:part

93 static int build_block_map(struct partition *part, int block_no)  in build_block_map()  argument
95 struct block *block = &part->blocks[block_no]; in build_block_map()
98 block->offset = part->block_size * block_no; in build_block_map()
100 if (le16_to_cpu(part->header_cache[0]) != RFD_MAGIC) { in build_block_map()
107 for (i=0; i<part->data_sectors_per_block; i++) { in build_block_map()
110 entry = le16_to_cpu(part->header_cache[HEADER_MAP_OFFSET + i]); in build_block_map()
123 if (entry >= part->sector_count) { in build_block_map()
127 part->mbd.mtd->name, block_no, i, entry); in build_block_map()
131 if (part->sector_map[entry] != -1) { in build_block_map()
134 part->mbd.mtd->name, entry); in build_block_map()
135 part->errors = 1; in build_block_map()
139 part->sector_map[entry] = block->offset + in build_block_map()
140 (i + part->header_sectors_per_block) * SECTOR_SIZE; in build_block_map()
145 if (block->free_sectors == part->data_sectors_per_block) in build_block_map()
146 part->reserved_block = block_no; in build_block_map()
151 static int scan_header(struct partition *part) in scan_header() argument
158 sectors_per_block = part->block_size / SECTOR_SIZE; in scan_header()
159 part->total_blocks = (u32)part->mbd.mtd->size / part->block_size; in scan_header()
161 if (part->total_blocks < 2) in scan_header()
165 part->header_sectors_per_block = in scan_header()
169 part->data_sectors_per_block = sectors_per_block - in scan_header()
170 part->header_sectors_per_block; in scan_header()
172 part->header_size = (HEADER_MAP_OFFSET + in scan_header()
173 part->data_sectors_per_block) * sizeof(u16); in scan_header()
175 part->cylinders = (part->data_sectors_per_block * in scan_header()
176 (part->total_blocks - 1) - 1) / SECTORS_PER_TRACK; in scan_header()
178 part->sector_count = part->cylinders * SECTORS_PER_TRACK; in scan_header()
180 part->current_block = -1; in scan_header()
181 part->reserved_block = -1; in scan_header()
182 part->is_reclaiming = 0; in scan_header()
184 part->header_cache = kmalloc(part->header_size, GFP_KERNEL); in scan_header()
185 if (!part->header_cache) in scan_header()
188 part->blocks = kcalloc(part->total_blocks, sizeof(struct block), in scan_header()
190 if (!part->blocks) in scan_header()
193 part->sector_map = vmalloc(array_size(sizeof(u_long), in scan_header()
194 part->sector_count)); in scan_header()
195 if (!part->sector_map) in scan_header()
198 for (i=0; i<part->sector_count; i++) in scan_header()
199 part->sector_map[i] = -1; in scan_header()
201 for (i=0, blocks_found=0; i<part->total_blocks; i++) { in scan_header()
202 rc = mtd_read(part->mbd.mtd, i * part->block_size, in scan_header()
203 part->header_size, &retlen, in scan_header()
204 (u_char *)part->header_cache); in scan_header()
206 if (!rc && retlen != part->header_size) in scan_header()
212 if (!build_block_map(part, i)) in scan_header()
218 part->mbd.mtd->name); in scan_header()
223 if (part->reserved_block == -1) { in scan_header()
225 part->mbd.mtd->name); in scan_header()
227 part->errors = 1; in scan_header()
233 vfree(part->sector_map); in scan_header()
234 kfree(part->header_cache); in scan_header()
235 kfree(part->blocks); in scan_header()
242 struct partition *part = container_of(dev, struct partition, mbd); in rfd_ftl_readsect() local
247 if (sector >= part->sector_count) in rfd_ftl_readsect()
250 addr = part->sector_map[sector]; in rfd_ftl_readsect()
252 rc = mtd_read(part->mbd.mtd, addr, SECTOR_SIZE, &retlen, in rfd_ftl_readsect()
259 "0x%lx\n", part->mbd.mtd->name, addr); in rfd_ftl_readsect()
268 static int erase_block(struct partition *part, int block) in erase_block() argument
277 erase->addr = part->blocks[block].offset; in erase_block()
278 erase->len = part->block_size; in erase_block()
280 part->blocks[block].state = BLOCK_ERASING; in erase_block()
281 part->blocks[block].free_sectors = 0; in erase_block()
283 rc = mtd_erase(part->mbd.mtd, erase); in erase_block()
287 (unsigned long long)erase->len, part->mbd.mtd->name); in erase_block()
288 part->blocks[block].state = BLOCK_FAILED; in erase_block()
289 part->blocks[block].free_sectors = 0; in erase_block()
290 part->blocks[block].used_sectors = 0; in erase_block()
295 part->blocks[block].state = BLOCK_ERASED; in erase_block()
296 part->blocks[block].free_sectors = part->data_sectors_per_block; in erase_block()
297 part->blocks[block].used_sectors = 0; in erase_block()
298 part->blocks[block].erases++; in erase_block()
300 rc = mtd_write(part->mbd.mtd, part->blocks[block].offset, in erase_block()
307 part->mbd.mtd->name, part->blocks[block].offset); in erase_block()
308 part->blocks[block].state = BLOCK_FAILED; in erase_block()
310 part->blocks[block].state = BLOCK_OK; in erase_block()
319 static int move_block_contents(struct partition *part, int block_no, u_long *old_sector) in move_block_contents() argument
326 part->is_reclaiming = 1; in move_block_contents()
332 map = kmalloc(part->header_size, GFP_KERNEL); in move_block_contents()
336 rc = mtd_read(part->mbd.mtd, part->blocks[block_no].offset, in move_block_contents()
337 part->header_size, &retlen, (u_char *)map); in move_block_contents()
339 if (!rc && retlen != part->header_size) in move_block_contents()
344 "0x%lx\n", part->mbd.mtd->name, in move_block_contents()
345 part->blocks[block_no].offset); in move_block_contents()
350 for (i=0; i<part->data_sectors_per_block; i++) { in move_block_contents()
362 if (entry >= part->sector_count) in move_block_contents()
365 addr = part->blocks[block_no].offset + in move_block_contents()
366 (i + part->header_sectors_per_block) * SECTOR_SIZE; in move_block_contents()
370 if (!part->blocks[block_no].used_sectors--) { in move_block_contents()
371 rc = erase_block(part, block_no); in move_block_contents()
376 rc = mtd_read(part->mbd.mtd, addr, SECTOR_SIZE, &retlen, in move_block_contents()
385 part->mbd.mtd->name); in move_block_contents()
390 rc = rfd_ftl_writesect((struct mtd_blktrans_dev*)part, in move_block_contents()
402 part->is_reclaiming = 0; in move_block_contents()
407 static int reclaim_block(struct partition *part, u_long *old_sector) in reclaim_block() argument
413 mtd_sync(part->mbd.mtd); in reclaim_block()
418 old_sector_block = *old_sector / part->block_size; in reclaim_block()
422 for (block=0; block<part->total_blocks; block++) { in reclaim_block()
425 if (block == part->reserved_block) in reclaim_block()
433 if (part->blocks[block].free_sectors) in reclaim_block()
436 this_score = part->blocks[block].used_sectors; in reclaim_block()
442 if (part->blocks[block].used_sectors == in reclaim_block()
443 part->data_sectors_per_block) in reclaim_block()
447 this_score += part->blocks[block].erases; in reclaim_block()
458 part->current_block = -1; in reclaim_block()
459 part->reserved_block = best_block; in reclaim_block()
463 part->blocks[best_block].used_sectors, in reclaim_block()
464 part->blocks[best_block].free_sectors); in reclaim_block()
466 if (part->blocks[best_block].used_sectors) in reclaim_block()
467 rc = move_block_contents(part, best_block, old_sector); in reclaim_block()
469 rc = erase_block(part, best_block); in reclaim_block()
479 static int find_free_block(struct partition *part) in find_free_block() argument
483 block = part->current_block == -1 ? in find_free_block()
484 jiffies % part->total_blocks : part->current_block; in find_free_block()
488 if (part->blocks[block].free_sectors && in find_free_block()
489 block != part->reserved_block) in find_free_block()
492 if (part->blocks[block].state == BLOCK_UNUSED) in find_free_block()
493 erase_block(part, block); in find_free_block()
495 if (++block >= part->total_blocks) in find_free_block()
503 static int find_writable_block(struct partition *part, u_long *old_sector) in find_writable_block() argument
508 block = find_free_block(part); in find_writable_block()
511 if (!part->is_reclaiming) { in find_writable_block()
512 rc = reclaim_block(part, old_sector); in find_writable_block()
516 block = find_free_block(part); in find_writable_block()
525 rc = mtd_read(part->mbd.mtd, part->blocks[block].offset, in find_writable_block()
526 part->header_size, &retlen, in find_writable_block()
527 (u_char *)part->header_cache); in find_writable_block()
529 if (!rc && retlen != part->header_size) in find_writable_block()
534 "0x%lx\n", part->mbd.mtd->name, in find_writable_block()
535 part->blocks[block].offset); in find_writable_block()
539 part->current_block = block; in find_writable_block()
545 static int mark_sector_deleted(struct partition *part, u_long old_addr) in mark_sector_deleted() argument
552 block = old_addr / part->block_size; in mark_sector_deleted()
553 offset = (old_addr % part->block_size) / SECTOR_SIZE - in mark_sector_deleted()
554 part->header_sectors_per_block; in mark_sector_deleted()
556 addr = part->blocks[block].offset + in mark_sector_deleted()
558 rc = mtd_write(part->mbd.mtd, addr, sizeof(del), &retlen, in mark_sector_deleted()
566 "0x%lx\n", part->mbd.mtd->name, addr); in mark_sector_deleted()
569 if (block == part->current_block) in mark_sector_deleted()
570 part->header_cache[offset + HEADER_MAP_OFFSET] = del; in mark_sector_deleted()
572 part->blocks[block].used_sectors--; in mark_sector_deleted()
574 if (!part->blocks[block].used_sectors && in mark_sector_deleted()
575 !part->blocks[block].free_sectors) in mark_sector_deleted()
576 rc = erase_block(part, block); in mark_sector_deleted()
582 static int find_free_sector(const struct partition *part, const struct block *block) in find_free_sector() argument
586 i = stop = part->data_sectors_per_block - block->free_sectors; in find_free_sector()
589 if (le16_to_cpu(part->header_cache[HEADER_MAP_OFFSET + i]) in find_free_sector()
593 if (++i == part->data_sectors_per_block) in find_free_sector()
603 struct partition *part = container_of(dev, struct partition, mbd); in do_writesect() local
611 if (part->current_block == -1 || in do_writesect()
612 !part->blocks[part->current_block].free_sectors) { in do_writesect()
614 rc = find_writable_block(part, old_addr); in do_writesect()
619 block = &part->blocks[part->current_block]; in do_writesect()
621 i = find_free_sector(part, block); in do_writesect()
628 addr = (i + part->header_sectors_per_block) * SECTOR_SIZE + in do_writesect()
630 rc = mtd_write(part->mbd.mtd, addr, SECTOR_SIZE, &retlen, in do_writesect()
638 part->mbd.mtd->name, addr); in do_writesect()
642 part->sector_map[sector] = addr; in do_writesect()
646 part->header_cache[i + HEADER_MAP_OFFSET] = entry; in do_writesect()
649 rc = mtd_write(part->mbd.mtd, addr, sizeof(entry), &retlen, in do_writesect()
657 part->mbd.mtd->name, addr); in do_writesect()
669 struct partition *part = container_of(dev, struct partition, mbd); in rfd_ftl_writesect() local
676 if (part->reserved_block == -1) { in rfd_ftl_writesect()
681 if (sector >= part->sector_count) { in rfd_ftl_writesect()
686 old_addr = part->sector_map[sector]; in rfd_ftl_writesect()
699 part->sector_map[sector] = -1; in rfd_ftl_writesect()
702 rc = mark_sector_deleted(part, old_addr); in rfd_ftl_writesect()
711 struct partition *part = container_of(dev, struct partition, mbd); in rfd_ftl_discardsect() local
716 if (sector >= part->sector_count) in rfd_ftl_discardsect()
719 addr = part->sector_map[sector]; in rfd_ftl_discardsect()
722 rc = mark_sector_deleted(part, addr); in rfd_ftl_discardsect()
726 part->sector_map[sector] = -1; in rfd_ftl_discardsect()
738 struct partition *part = container_of(dev, struct partition, mbd); in rfd_ftl_getgeo() local
742 geo->cylinders = part->cylinders; in rfd_ftl_getgeo()
749 struct partition *part; in rfd_ftl_add_mtd() local
755 part = kzalloc(sizeof(struct partition), GFP_KERNEL); in rfd_ftl_add_mtd()
756 if (!part) in rfd_ftl_add_mtd()
759 part->mbd.mtd = mtd; in rfd_ftl_add_mtd()
762 part->block_size = block_size; in rfd_ftl_add_mtd()
768 part->block_size = mtd->erasesize; in rfd_ftl_add_mtd()
771 if (scan_header(part) == 0) { in rfd_ftl_add_mtd()
772 part->mbd.size = part->sector_count; in rfd_ftl_add_mtd()
773 part->mbd.tr = tr; in rfd_ftl_add_mtd()
774 part->mbd.devnum = -1; in rfd_ftl_add_mtd()
776 part->mbd.readonly = 1; in rfd_ftl_add_mtd()
777 else if (part->errors) { in rfd_ftl_add_mtd()
780 part->mbd.readonly = 1; in rfd_ftl_add_mtd()
786 if (!add_mtd_blktrans_dev(&part->mbd)) in rfd_ftl_add_mtd()
790 kfree(part); in rfd_ftl_add_mtd()
795 struct partition *part = container_of(dev, struct partition, mbd); in rfd_ftl_remove_dev() local
798 for (i=0; i<part->total_blocks; i++) { in rfd_ftl_remove_dev()
800 part->mbd.mtd->name, i, part->blocks[i].erases); in rfd_ftl_remove_dev()
803 vfree(part->sector_map); in rfd_ftl_remove_dev()
804 kfree(part->header_cache); in rfd_ftl_remove_dev()
805 kfree(part->blocks); in rfd_ftl_remove_dev()
806 del_mtd_blktrans_dev(&part->mbd); in rfd_ftl_remove_dev()