Determining if writing to a jffs2 partition will fail

Jonas Holmberg jonas.holmberg at
Sat Dec 20 09:34:04 EST 2003

Is there any reliable way to determine if a regular file can be 
written to a jffs2 partition without getting ENOSPC? I don't want to 
write the file to jffs2 and then find out that the fs was full, 
because other processes might fail to write to the fs during that 
test (if the fs gets full).

The best I have come up with is:

1. gzip the file (on tmpfs)
2. do statfs on jffs2 the get available space
3. test if the gzipped file would fit in jffs2 without making 
   available space go below one eraseblock (64KiB on my NOR flash).

If it succeeds I would be almost shure the gunzipped file could be 
written to jffs2 without getting ENOSPC, but gzip will of course not 
compress the file to exacly the same size as jffs2 will. And 
statfs won't always tell the truth. I could of course send SIGHUP 
to the gc-thread, wait some and try again.

This doesn't feel like a good solution though, does anyone know of any 
better way?


More information about the linux-mtd mailing list