Freeing space on JFFS2 after removing file

Николай Исаев stvdedal at gmail.com
Tue Oct 13 22:35:20 PDT 2015


Hello!

We have JFFS2 partition with files: X1, X2, X3, ...., Xn. All those
files have the same size and content.
When we tried to create new file, the error ENOSPC has occurred, which
means that the file system is full and all space is used.
With this file system state, we delete a single file (X1, for example)
in order to free space that the file used.
After that, we try to recreate the same file (X1), but the error
ENOSPC occurs again.
So, even after deleting a file, the file system does not free space to
store the same file.
The same behaviour occurs when we remount file system in order to
garbage collector does his job.

Questions:
1. Is it a JFFS2 bug?
2. Is it possible to determine when removing and subsequent creation
of a file will be successful?
3. How can we determine that the free space, shown by JFFS2, fits with
real free space on the system?

The bash script shows that:

-------------------- cut here -------------------------------------
mkdir /tmp/jffstest
cd /tmp/jffstest

#
# create empty directory and
# mount point directory
#
mkdir mnt emptydir

#
# create jffs2 image
# eraseblock size = 128 Kb
# total size      = 20 Mb
#
mkfs.jffs2 -r emptydir -o image.jffs2 --pad=20971520 -e 128

#
# mount image file
#
modprobe mtdram total_size=20480 erase_size=128
modprobe mtdblock
dd if=image.jffs2 of=/dev/mtdblock0
mount -t jffs2 /dev/mtdblock0 mnt

#
# create 15Mb and 512Kb files
# with random data
#
head -c 15m /dev/urandom >big
head -c 512k /dev/urandom >small

#
# Fill the jffs2 partition
#  firstly add big file
#  then add small files until ENOSPC occurred
#
cp big mnt/.
N=1; while cp small mnt/small_$N; do N=$(( N + 1)); done

echo
echo 'The filesystem is filled completely'
echo

echo
echo Test:
echo

rm -f mnt/small_1     # Remove file
cp small mnt/small_1  # Try recreate the same.
                      # But result will be "No space left on device"

-------------------- cut here -------------------------------------

The last command will be finished with error: "No space left on device"
I ran this script on openSUSE 12.3 (Dartmouth) (i586) with kernel 3.7.10

Thanks



More information about the linux-mtd mailing list