Lines Matching refs:part

87     do { (dev)->part[(drive)*(minors)].nr_sects = size; \
88 if (size == 0) (dev)->part[(drive)*(minors)].start_sect = -1; \
132 #define MINOR_NR(dev,reg,part) (((dev)<<5)+((reg)<<3)+(part)) argument
190 void ftl_freepart(partition_t *part);
219 part: ftl_hd,
261 static int scan_header(partition_t *part) in scan_header() argument
266 part->header.FormattedSize = 0; in scan_header()
267 max_offset = (0x100000<part->mtd->size)?0x100000:part->mtd->size; in scan_header()
271 offset += part->mtd->erasesize ? : 0x2000) { in scan_header()
273 ret = part->mtd->read(part->mtd, offset, sizeof(header), &ret, in scan_header()
292 if ((1 << header.EraseUnitSize) != part->mtd->erasesize) { in scan_header()
294 1 << header.EraseUnitSize,part->mtd->erasesize); in scan_header()
297 part->header = header; in scan_header()
301 static int build_maps(partition_t *part) in build_maps() argument
311 part->DataUnits = le16_to_cpu(part->header.NumEraseUnits) - in build_maps()
312 part->header.NumTransferUnits; in build_maps()
313 part->EUNInfo = kmalloc(part->DataUnits * sizeof(struct eun_info_t), in build_maps()
315 if (!part->EUNInfo) in build_maps()
317 for (i = 0; i < part->DataUnits; i++) in build_maps()
318 part->EUNInfo[i].Offset = 0xffffffff; in build_maps()
319 part->XferInfo = in build_maps()
320 kmalloc(part->header.NumTransferUnits * sizeof(struct xfer_info_t), in build_maps()
322 if (!part->XferInfo) in build_maps()
326 for (i = 0; i < le16_to_cpu(part->header.NumEraseUnits); i++) { in build_maps()
327 offset = ((i + le16_to_cpu(part->header.FirstPhysicalEUN)) in build_maps()
328 << part->header.EraseUnitSize); in build_maps()
329 ret = part->mtd->read(part->mtd, offset, sizeof(header), &retval, in build_maps()
338 if (hdr_ok && (le16_to_cpu(header.LogicalEUN) < part->DataUnits) && in build_maps()
339 (part->EUNInfo[le16_to_cpu(header.LogicalEUN)].Offset == 0xffffffff)) { in build_maps()
340 part->EUNInfo[le16_to_cpu(header.LogicalEUN)].Offset = offset; in build_maps()
341 part->EUNInfo[le16_to_cpu(header.LogicalEUN)].EraseCount = in build_maps()
345 if (xtrans == part->header.NumTransferUnits) { in build_maps()
351 part->XferInfo[xtrans].state = XFER_PREPARED; in build_maps()
352 part->XferInfo[xtrans].EraseCount = le32_to_cpu(header.EraseCount); in build_maps()
354 part->XferInfo[xtrans].state = XFER_UNKNOWN; in build_maps()
356 part->XferInfo[xtrans].EraseCount = in build_maps()
357 le32_to_cpu(part->header.EraseCount); in build_maps()
359 part->XferInfo[xtrans].Offset = offset; in build_maps()
364 header = part->header; in build_maps()
374 part->VirtualBlockMap = vmalloc(blocks * sizeof(u_int32_t)); in build_maps()
375 if (!part->VirtualBlockMap) in build_maps()
378 memset(part->VirtualBlockMap, 0xff, blocks * sizeof(u_int32_t)); in build_maps()
379 part->BlocksPerUnit = (1 << header.EraseUnitSize) >> header.BlockSize; in build_maps()
381 part->bam_cache = kmalloc(part->BlocksPerUnit * sizeof(u_int32_t), in build_maps()
383 if (!part->bam_cache) in build_maps()
386 part->bam_index = 0xffff; in build_maps()
387 part->FreeTotal = 0; in build_maps()
389 for (i = 0; i < part->DataUnits; i++) { in build_maps()
390 part->EUNInfo[i].Free = 0; in build_maps()
391 part->EUNInfo[i].Deleted = 0; in build_maps()
392 offset = part->EUNInfo[i].Offset + le32_to_cpu(header.BAMOffset); in build_maps()
394 ret = part->mtd->read(part->mtd, offset, in build_maps()
395 part->BlocksPerUnit * sizeof(u_int32_t), &retval, in build_maps()
396 (unsigned char *)part->bam_cache); in build_maps()
401 for (j = 0; j < part->BlocksPerUnit; j++) { in build_maps()
402 if (BLOCK_FREE(le32_to_cpu(part->bam_cache[j]))) { in build_maps()
403 part->EUNInfo[i].Free++; in build_maps()
404 part->FreeTotal++; in build_maps()
405 } else if ((BLOCK_TYPE(le32_to_cpu(part->bam_cache[j])) == BLOCK_DATA) && in build_maps()
406 (BLOCK_NUMBER(le32_to_cpu(part->bam_cache[j])) < blocks)) in build_maps()
407 part->VirtualBlockMap[BLOCK_NUMBER(le32_to_cpu(part->bam_cache[j]))] = in build_maps()
409 else if (BLOCK_DELETED(le32_to_cpu(part->bam_cache[j]))) in build_maps()
410 part->EUNInfo[i].Deleted++; in build_maps()
418 kfree(part->bam_cache); in build_maps()
420 vfree(part->VirtualBlockMap); in build_maps()
422 kfree(part->XferInfo); in build_maps()
424 kfree(part->EUNInfo); in build_maps()
436 static int erase_xfer(partition_t *part, in erase_xfer() argument
443 xfer = &part->XferInfo[xfernum]; in erase_xfer()
456 erase->len = 1 << part->header.EraseUnitSize; in erase_xfer()
457 erase->priv = (u_long)part; in erase_xfer()
459 ret = part->mtd->erase(part->mtd, erase); in erase_xfer()
478 partition_t *part; in ftl_erase_callback() local
483 part = (partition_t *)(erase->priv); in ftl_erase_callback()
485 for (i = 0; i < part->header.NumTransferUnits; i++) in ftl_erase_callback()
486 if (part->XferInfo[i].Offset == erase->addr) break; in ftl_erase_callback()
488 if (i == part->header.NumTransferUnits) { in ftl_erase_callback()
494 xfer = &part->XferInfo[i]; in ftl_erase_callback()
507 static int prepare_xfer(partition_t *part, int i) in prepare_xfer() argument
516 xfer = &part->XferInfo[i]; in prepare_xfer()
522 header = part->header; in prepare_xfer()
526 ret = part->mtd->write(part->mtd, xfer->Offset, sizeof(header), in prepare_xfer()
534 nbam = (part->BlocksPerUnit * sizeof(u_int32_t) + in prepare_xfer()
535 le32_to_cpu(part->header.BAMOffset) + SECTOR_SIZE - 1) / SECTOR_SIZE; in prepare_xfer()
537 offset = xfer->Offset + le32_to_cpu(part->header.BAMOffset); in prepare_xfer()
542 ret = part->mtd->write(part->mtd, offset, sizeof(u_int32_t), in prepare_xfer()
565 static int copy_erase_unit(partition_t *part, u_int16_t srcunit, in copy_erase_unit() argument
578 eun = &part->EUNInfo[srcunit]; in copy_erase_unit()
579 xfer = &part->XferInfo[xferunit]; in copy_erase_unit()
585 if (part->bam_index != srcunit) { in copy_erase_unit()
587 offset = eun->Offset + le32_to_cpu(part->header.BAMOffset); in copy_erase_unit()
589 ret = part->mtd->read(part->mtd, offset, in copy_erase_unit()
590 part->BlocksPerUnit * sizeof(u_int32_t), in copy_erase_unit()
591 &retlen, (u_char *) (part->bam_cache)); in copy_erase_unit()
594 part->bam_index = 0xffff; in copy_erase_unit()
607 ret = part->mtd->write(part->mtd, offset, sizeof(u_int16_t), in copy_erase_unit()
620 for (i = 0; i < part->BlocksPerUnit; i++) { in copy_erase_unit()
621 switch (BLOCK_TYPE(le32_to_cpu(part->bam_cache[i]))) { in copy_erase_unit()
627 ret = part->mtd->read(part->mtd, src, SECTOR_SIZE, in copy_erase_unit()
635 ret = part->mtd->write(part->mtd, dest, SECTOR_SIZE, in copy_erase_unit()
645 part->bam_cache[i] = cpu_to_le32(0xffffffff); in copy_erase_unit()
654 ret = part->mtd->write(part->mtd, xfer->Offset + le32_to_cpu(part->header.BAMOffset), in copy_erase_unit()
655 part->BlocksPerUnit * sizeof(int32_t), &retlen, in copy_erase_unit()
656 (u_char *)part->bam_cache); in copy_erase_unit()
664 ret = part->mtd->write(part->mtd, xfer->Offset + 20, sizeof(u_int16_t), in copy_erase_unit()
680 part->FreeTotal -= eun->Free; in copy_erase_unit()
681 part->FreeTotal += free; in copy_erase_unit()
686 part->bam_index = srcunit; in copy_erase_unit()
707 static int reclaim_block(partition_t *part) in reclaim_block() argument
714 DEBUG(3, "NumTransferUnits == %x\n", part->header.NumTransferUnits); in reclaim_block()
719 for (i = 0; i < part->header.NumTransferUnits; i++) { in reclaim_block()
721 if (part->XferInfo[i].state == XFER_UNKNOWN) { in reclaim_block()
724 erase_xfer(part, i); in reclaim_block()
726 if (part->XferInfo[i].state == XFER_ERASING) { in reclaim_block()
731 else if (part->XferInfo[i].state == XFER_ERASED) { in reclaim_block()
734 prepare_xfer(part, i); in reclaim_block()
736 if (part->XferInfo[i].state == XFER_PREPARED) { in reclaim_block()
739 if (part->XferInfo[i].EraseCount <= best) { in reclaim_block()
740 best = part->XferInfo[i].EraseCount; in reclaim_block()
745 DEBUG(3,"XferInfo[%d].state == %x\n",i, part->XferInfo[i].state); in reclaim_block()
752 if (part->mtd->sync) in reclaim_block()
753 part->mtd->sync(part->mtd); in reclaim_block()
772 for (i = 0; i < part->DataUnits; i++) in reclaim_block()
773 if (part->EUNInfo[i].EraseCount <= best) { in reclaim_block()
774 best = part->EUNInfo[i].EraseCount; in reclaim_block()
779 for (i = 0; i < part->DataUnits; i++) in reclaim_block()
780 if (part->EUNInfo[i].Deleted >= best) { in reclaim_block()
781 best = part->EUNInfo[i].Deleted; in reclaim_block()
796 ret = copy_erase_unit(part, eun, xfer); in reclaim_block()
798 erase_xfer(part, xfer); in reclaim_block()
815 static void dump_lists(partition_t *part) in dump_lists() argument
818 printk(KERN_DEBUG "ftl_cs: Free total = %d\n", part->FreeTotal); in dump_lists()
819 for (i = 0; i < part->DataUnits; i++) in dump_lists()
822 part->EUNInfo[i].Offset >> part->header.EraseUnitSize, in dump_lists()
823 part->EUNInfo[i].Free, part->EUNInfo[i].Deleted); in dump_lists()
827 static u_int32_t find_free(partition_t *part) in find_free() argument
835 stop = (part->bam_index == 0xffff) ? 0 : part->bam_index; in find_free()
838 if (part->EUNInfo[eun].Free != 0) break; in find_free()
840 if (++eun == part->DataUnits) eun = 0; in find_free()
843 if (part->EUNInfo[eun].Free == 0) in find_free()
847 if (eun != part->bam_index) { in find_free()
849 part->bam_index = 0xffff; in find_free()
851 ret = part->mtd->read(part->mtd, in find_free()
852 part->EUNInfo[eun].Offset + le32_to_cpu(part->header.BAMOffset), in find_free()
853 part->BlocksPerUnit * sizeof(u_int32_t), in find_free()
854 &retlen, (u_char *) (part->bam_cache)); in find_free()
860 part->bam_index = eun; in find_free()
864 for (blk = 0; blk < part->BlocksPerUnit; blk++) in find_free()
865 if (BLOCK_FREE(le32_to_cpu(part->bam_cache[blk]))) break; in find_free()
866 if (blk == part->BlocksPerUnit) { in find_free()
870 dump_lists(part); in find_free()
903 if (ftl_gendisk.part[minor].nr_sects == 0) in ftl_open()
931 partition_t *part = myparts[minor >> 4]; in ftl_close() local
937 if (part->mtd->sync) in ftl_close()
938 part->mtd->sync(part->mtd); in ftl_close()
940 for (i = 0; i < part->header.NumTransferUnits; i++) { in ftl_close()
941 if (part->XferInfo[i].state == XFER_ERASED) in ftl_close()
942 prepare_xfer(part, i); in ftl_close()
945 atomic_dec(&part->open); in ftl_close()
947 put_mtd_device(part->mtd); in ftl_close()
959 static int ftl_read(partition_t *part, caddr_t buffer, in ftl_read() argument
968 part, sector, nblocks); in ftl_read()
969 if (!(part->state & FTL_FORMATTED)) { in ftl_read()
973 bsize = 1 << part->header.EraseUnitSize; in ftl_read()
976 if (((sector+i) * SECTOR_SIZE) >= le32_to_cpu(part->header.FormattedSize)) { in ftl_read()
980 log_addr = part->VirtualBlockMap[sector+i]; in ftl_read()
984 offset = (part->EUNInfo[log_addr / bsize].Offset in ftl_read()
986 ret = part->mtd->read(part->mtd, offset, SECTOR_SIZE, in ftl_read()
1005 static int set_bam_entry(partition_t *part, u_int32_t log_addr, in set_bam_entry() argument
1017 part, log_addr, virt_addr); in set_bam_entry()
1018 bsize = 1 << part->header.EraseUnitSize; in set_bam_entry()
1021 offset = (part->EUNInfo[eun].Offset + blk * sizeof(u_int32_t) + in set_bam_entry()
1022 le32_to_cpu(part->header.BAMOffset)); in set_bam_entry()
1025 ret = part->mtd->read(part->mtd, offset, sizeof(u_int32_t), in set_bam_entry()
1046 if (part->bam_index == eun) { in set_bam_entry()
1048 if (le32_to_cpu(part->bam_cache[blk]) != old_addr) { in set_bam_entry()
1055 le32_to_cpu(part->bam_cache[blk]), old_addr); in set_bam_entry()
1060 part->bam_cache[blk] = le_virt_addr; in set_bam_entry()
1062 ret = part->mtd->write(part->mtd, offset, sizeof(u_int32_t), in set_bam_entry()
1073 static int ftl_write(partition_t *part, caddr_t buffer, in ftl_write() argument
1082 part, sector, nblocks); in ftl_write()
1083 if (!(part->state & FTL_FORMATTED)) { in ftl_write()
1088 while (part->FreeTotal < nblocks) { in ftl_write()
1089 ret = reclaim_block(part); in ftl_write()
1094 bsize = 1 << part->header.EraseUnitSize; in ftl_write()
1098 if (virt_addr >= le32_to_cpu(part->header.FormattedSize)) { in ftl_write()
1104 blk = find_free(part); in ftl_write()
1114 log_addr = part->bam_index * bsize + blk * SECTOR_SIZE; in ftl_write()
1115 part->EUNInfo[part->bam_index].Free--; in ftl_write()
1116 part->FreeTotal--; in ftl_write()
1117 if (set_bam_entry(part, log_addr, 0xfffffffe)) in ftl_write()
1119 part->EUNInfo[part->bam_index].Deleted++; in ftl_write()
1120 offset = (part->EUNInfo[part->bam_index].Offset + in ftl_write()
1122 ret = part->mtd->write(part->mtd, offset, SECTOR_SIZE, &retlen, in ftl_write()
1134 old_addr = part->VirtualBlockMap[sector+i]; in ftl_write()
1136 part->VirtualBlockMap[sector+i] = 0xffffffff; in ftl_write()
1137 part->EUNInfo[old_addr/bsize].Deleted++; in ftl_write()
1138 if (set_bam_entry(part, old_addr, 0)) in ftl_write()
1143 if (set_bam_entry(part, log_addr, virt_addr)) in ftl_write()
1145 part->VirtualBlockMap[sector+i] = log_addr; in ftl_write()
1146 part->EUNInfo[part->bam_index].Deleted--; in ftl_write()
1165 partition_t *part= myparts[minor >> 4]; in ftl_ioctl() local
1168 if (!part) in ftl_ioctl()
1176 sect = le32_to_cpu(part->header.FormattedSize)/SECTOR_SIZE; in ftl_ioctl()
1224 partition_t *part = myparts[minor >> 4]; in ftl_reread_partitions() local
1228 if ((atomic_read(&part->open) > 1)) { in ftl_reread_partitions()
1244 scan_header(part); in ftl_reread_partitions()
1247 &ftl_blk_fops, le32_to_cpu(part->header.FormattedSize)/SECTOR_SIZE); in ftl_reread_partitions()
1269 partition_t *part; in do_ftl_request() local
1277 part = myparts[minor >> 4]; in do_ftl_request()
1278 if (part) { in do_ftl_request()
1283 ret = ftl_read(part, CURRENT->buffer, in do_ftl_request()
1290 ret = ftl_write(part, CURRENT->buffer, in do_ftl_request()
1315 void ftl_freepart(partition_t *part) in ftl_freepart() argument
1317 if (part->VirtualBlockMap) { in ftl_freepart()
1318 vfree(part->VirtualBlockMap); in ftl_freepart()
1319 part->VirtualBlockMap = NULL; in ftl_freepart()
1321 if (part->VirtualPageMap) { in ftl_freepart()
1322 kfree(part->VirtualPageMap); in ftl_freepart()
1323 part->VirtualPageMap = NULL; in ftl_freepart()
1325 if (part->EUNInfo) { in ftl_freepart()
1326 kfree(part->EUNInfo); in ftl_freepart()
1327 part->EUNInfo = NULL; in ftl_freepart()
1329 if (part->XferInfo) { in ftl_freepart()
1330 kfree(part->XferInfo); in ftl_freepart()
1331 part->XferInfo = NULL; in ftl_freepart()
1333 if (part->bam_cache) { in ftl_freepart()
1334 kfree(part->bam_cache); in ftl_freepart()
1335 part->bam_cache = NULL; in ftl_freepart()
1403 ftl_gendisk.part[j].nr_sects=0; in ftl_notify_remove()
1404 ftl_gendisk.part[j].start_sect=0; in ftl_notify_remove()