sysprog21 / simplefs

A simple native file system for Linux kernel
Other
362 stars 91 forks source link

File Content Disappears After Remount #54

Closed antoniprzybylik closed 3 months ago

antoniprzybylik commented 3 months ago

When mounting newly created filesystem, creating a file with content "I have a cat.", unmounting, and then remounting the filesystem again, the file remains but its content disappears.

How to reproduce the bug:

dd if=/dev/zero of=./IMAGE bs=1M count=50
./mkfs.simplefs IMAGE
mount -o loop -t simplefs IMAGE mnt/
echo "I have a cat." > mnt/file.txt
umount mnt/
mount -o loop -t simplefs IMAGE mnt/

Now try to print the contents of the file "mnt/file.txt", it will be empty.

HotMercury commented 3 months ago

You can use sync before umount

antoniprzybylik commented 3 months ago

You can use sync before umount

This does not solve my problem.

HotMercury commented 3 months ago

The reason for being empty is that the file couldn't be written to the disk in time. The solution is to use multiple sync commands or wait for a period of time. Like this, and it will work.

dd if=/dev/zero of=./IMAGE bs=1M count=50
./mkfs.simplefs IMAGE
mount -o loop -t simplefs IMAGE mnt/
echo "I have a cat." > mnt/file.txt
sync
sync
sync
...
umount mnt/
mount -o loop -t simplefs IMAGE mnt/

If it still doesn't work, please provide me with more information.

antoniprzybylik commented 3 months ago

The solution is to use multiple sync commands or wait for a period of time.

Well... It worked.

I always thought that the sync command blocks until my data is written to all connected drives. However, it turns out that's not the case. So this is possible that I could execute sync, wait for it to finish, disconnect a disk, and lose my data? What a disappointment.