long uffs_space_free(const char *mount_point)
{
	uffs_Device *dev = NULL;
	long ret = -1L;

	dev = uffs_GetDeviceFromMountPoint(mount_point);
	if (dev) {
		uffs_GlobalFsLockLock();
		ret = (long) uffs_GetDeviceFree(dev);
		uffs_GlobalFsLockUnlock();
	}

	return ret;
}
Exemple #2
0
static int dfs_uffs_statfs(struct dfs_filesystem* fs,
                    struct statfs *buf)
{
    rt_base_t index;
    struct rt_mtd_nand_device * mtd = RT_MTD_NAND_DEVICE(fs->dev_id);

    RT_ASSERT(mtd != RT_NULL);

    /* find the device index */
    for (index = 0; index < UFFS_DEVICE_MAX; index++)
    {
        if (nand_part[index].dev == (void *)mtd)
            break;
    }
    if (index == UFFS_DEVICE_MAX)
        return -ENOENT;
    
    buf->f_bsize = mtd->page_size*mtd->pages_per_block;
    buf->f_blocks = (mtd->block_end - mtd->block_start + 1);
    buf->f_bfree = uffs_GetDeviceFree(&nand_part[index].uffs_dev)/buf->f_bsize ;
    
    return 0;
}
/** st [<mount>] */
static int cmd_st(int argc, char *argv[])
{
	uffs_Device *dev;
	const char *mount = "/";
	uffs_FlashStat *s;
	TreeNode *node;

	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;
	}

	s = &(dev->st);

	MSG("----------- basic info -----------" TENDSTR);
	MSG("TreeNode size:         %d" TENDSTR, sizeof(TreeNode));
	MSG("TagStore size:         %d" TENDSTR, sizeof(struct uffs_TagStoreSt));
	MSG("MaxCachedBlockInfo:    %d" TENDSTR, dev->cfg.bc_caches);
	MSG("MaxPageBuffers:        %d" TENDSTR, dev->cfg.page_buffers);
	MSG("MaxDirtyPagesPerBlock: %d" TENDSTR, dev->cfg.dirty_pages);
	MSG("MaxPathLength:         %d" TENDSTR, MAX_PATH_LENGTH);
	MSG("MaxObjectHandles:      %d" TENDSTR, MAX_OBJECT_HANDLE);
	MSG("FreeObjectHandles:     %d" TENDSTR, uffs_GetFreeObjectHandlers());
	MSG("MaxDirHandles:         %d" TENDSTR, MAX_DIR_HANDLE);
	MSG("FreeDirHandles:        %d" TENDSTR, uffs_PoolGetFreeCount(uffs_DirEntryBufGetPool()));

	MSG("----------- statistics for '%s' -----------" TENDSTR, mount);
	MSG("Device Ref:            %d" TENDSTR, dev->ref_count);
	MSG("Block Erased:          %d" TENDSTR, s->block_erase_count);
	MSG("Write Page:            %d" TENDSTR, s->page_write_count);
	MSG("Write Spare:           %d" TENDSTR, s->spare_write_count);
	MSG("Read Page:             %d" TENDSTR, s->page_read_count - s->page_header_read_count);
	MSG("Read Header:           %d" TENDSTR, s->page_header_read_count);
	MSG("Read Spare:            %d" TENDSTR, s->spare_read_count);
	MSG("I/O Read:              %lu" TENDSTR, s->io_read);
	MSG("I/O Write:             %lu" TENDSTR, s->io_write);

	MSG("--------- partition info for '%s' ---------" TENDSTR, mount);
	MSG("Space total:           %d" TENDSTR, uffs_GetDeviceTotal(dev));
	MSG("Space used:            %d" TENDSTR, uffs_GetDeviceUsed(dev));
	MSG("Space free:            %d" TENDSTR, uffs_GetDeviceFree(dev));
	MSG("Page Size:             %d" TENDSTR, dev->attr->page_data_size);
	MSG("Spare Size:            %d" TENDSTR, dev->attr->spare_size);
	MSG("Pages Per Block:       %d" TENDSTR, dev->attr->pages_per_block);
	MSG("Block size:            %d" TENDSTR, dev->attr->page_data_size * dev->attr->pages_per_block);
	MSG("Total blocks:          %d of %d" TENDSTR, (dev->par.end - dev->par.start + 1), dev->attr->total_blocks);
	if (dev->tree.bad) {
		MSG("Bad blocks: ");
		node = dev->tree.bad;
		while(node) {
			MSG("%d, ", node->u.list.block);
			node = node->u.list.next;
		}
		MSG(TENDSTR);
	}

	uffs_PutDevice(dev);

	return 0;

}