Calculation of JFFS2 free space

Sohn Chung-MCG31424 ChungSohn at motorola.com
Thu Feb 8 16:08:03 EST 2007


 

> -----Original Message-----
> From: Josh Boyer [mailto:jwboyer at gmail.com] 
> Sent: Thursday, February 08, 2007 12:44 PM
> To: Sohn Chung-MCG31424
> Cc: linux-mtd at lists.infradead.org
> Subject: Re: Calculation of JFFS2 free space
> 
> On 2/8/07, Sohn Chung-MCG31424 <ChungSohn at motorola.com> wrote:
> >
> > Hello,
> > I am using JFFS2 (Linux 2.6.10) on the Large Page NAND flash.
> > The size of JFFS2 partition is 7M. While applications were holding 
> > some files, I copied over an 8M file to this partition to make the 
> > filesystem full.
> > After I got the out of space message, I issued the 'df' command.
> >
> > The output of df was:
> > # df /jffs2
> > /dev/mtdblock/3    7168   7023   136   98% /jffs2
> >
> > # cd /jffs2
> > # touch foo
> > touch: foo: No space left on device
> >
> > The jffs2_statfs returned 136K as the available space.
> > After the filesystem is full, how the application program 
> can figure 
> > out the real available space on JFFS2 before write?
> 
> You currently can't from userspace.  The df output is a 
> best-estimate returned by JFFS2 given that it has to reserve 
> some blocks for normal operation.
> 
> What would be nice is some sysfs entries to export some of 
> this information, without requiring JFFS2_DEBUG to be set.
> 
> josh
> 

If I change the jffs2_statfs function like this, do I give more
accurate free space info to the user?
Do I have any side affect If I change like this?

Instead of this:
    avail = c->dirty_size + c->free_size;
    if (avail > c->sector_size * c->resv_blocks_write)
        avail -= c->sector_size * c->resv_blocks_write;
    else
        avail = 0;

Change to:
    free = c->free_size + c->nr_erasing_blocks * c->sector_size;
    dirty = c->dirty_size + c->erasing_size + c->unchecked_size -
            (c->nr_erasing_blocks * c->sector_size);

    if((free + dirty) > (c->resv_blocks_write * c->sector_size +
c->nospc_dirty_size))
        avail = free + dirty - 
                (c->resv_blocks_write * c->sector_size) - 
                c->nospc_dirty_size;
    else
        avail = 0;

Thanks,
Chung




More information about the linux-mtd mailing list