/** print block wear-leveling information * wl [<mount>] */ static int cmd_wl(int argc, char *argv[]) { const char *mount = "/"; uffs_Device *dev; struct uffs_PartitionSt *par; uffs_FileEmu *emu; int i, max; u32 n; #define NUM_PER_LINE 10 CHK_ARGC(1, 2); if (argc > 1) { mount = argv[1]; } dev = uffs_GetDeviceFromMountPoint(mount); if (dev == NULL) { MSGLN("Can't get device from mount point %s", mount); return -1; } par = &dev->par; emu = (uffs_FileEmu *)(dev->attr->_private); max = -1; for (i = 0; i < par->end - par->start; i++) { if ((i % NUM_PER_LINE) == 0) { MSG("%04d:", i + par->start); } n = i + par->start; max = (max == -1 ? n : (emu->em_monitor_block[n] > emu->em_monitor_block[max] ? n : max) ); MSG(" %4d", emu->em_monitor_block[n]); if (uffs_TreeFindBadNodeByBlock(dev, n)) MSG("%c", 'x'); else if (uffs_TreeFindErasedNodeByBlock(dev, n)) MSG("%c", ' '); else MSG("%c", '.'); if (((i + 1) % NUM_PER_LINE) == 0) MSG("\n"); } MSG("\n"); MSG("Total blocks %d, peak erase count %d at block %d\n", par->end - par->start, max == -1 ? 0 : emu->em_monitor_block[max], max); uffs_PutDevice(dev); return 0; }
TreeNode * uffs_TreeFindNodeByBlock(uffs_Device *dev, u16 block, int *region) { TreeNode *node = NULL; if (*region & SEARCH_REGION_DATA) { node = uffs_TreeFindDataNodeByBlock(dev, block); if (node) { *region &= SEARCH_REGION_DATA; return node; } } if (*region & SEARCH_REGION_FILE) { node = uffs_TreeFindFileNodeByBlock(dev, block); if (node) { *region &= SEARCH_REGION_FILE; return node; } } if (*region & SEARCH_REGION_DIR) { node = uffs_TreeFindDirNodeByBlock(dev, block); if (node) { *region &= SEARCH_REGION_DIR; return node; } } if (*region & SEARCH_REGION_ERASED) { node = uffs_TreeFindErasedNodeByBlock(dev, block); if (node) { *region &= SEARCH_REGION_ERASED; return node; } } if (*region & SEARCH_REGION_BAD) { node = uffs_TreeFindBadNodeByBlock(dev, block); if (node) { *region &= SEARCH_REGION_BAD; return node; } } return node; }