mentos-team / MentOS

An educational 32-bit linux-like Operating System, with public bachelor- and master-level course slides.
https://mentos-team.github.io/
MIT License
125 stars 49 forks source link

Directory entries are dropped when new ones are created #87

Closed fischerling closed 2 weeks ago

fischerling commented 1 month ago

Directories are still buggy.

I introduced two seperate user alice and bob in commit 225bcda. This is the first commit where I can reproduce the buggy behavior. This behavior is independent of #82, because I could reproduce it after merging my modifications into the current master 4bc52fb08dff6be04c704d2c0a7e238b0e89c793.

What happens?

When I create a new file in alice' home directory using touch foo all other directory entries are lost.

However, if I delete the secrets.txt file from alice' home before creating a new file all expected entries are found. But creating a second file results in the same behavior, of loosing all entries except the newly created one.

fsck.ext2 reports unatteched inodes after creating a file foo as described above.

$ fsck.ext2 -fn rootfs.img

e2fsck 1.47.1 (20-May-2024)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Unattached inode 105
Connect to /lost+found? no

Unattached inode 106
Connect to /lost+found? no

Unattached inode 107
Connect to /lost+found? no

Pass 5: Checking group summary information

rootfs: ********** WARNING: Filesystem still has errors **********

rootfs: 686/8192 files (0.0% non-contiguous), 3994/8192 blocks

I will attach a kernel and file system image if you want. Just let me know.

fischerling commented 1 month ago

I could reproduce the behavior on current develop 84d5a7ab0592983f27e2b4c4c3a62567681c2c7f.

  1. Create a second empty hidden file files/home/user/.shellrc
  2. Build the filesystem image
  3. Start qemu
    1. login as user
    2. ls -> root and README entries are listed
    3. touch foo
    4. ls -> only foo is listed
    5. ls -la -> lists the hidden files and foo
fischerling commented 1 month ago

Apparently, when the .shellrc file is there to read during the initialization of the shell, this bug happens.

Galfurian commented 1 month ago

I'll investigate this bug. Thank you for opening the Issue.

Galfurian commented 2 weeks ago

Solved by #100.

After the latest update on ext2_mkdir, ext2_rmdir, and ext2_get_rec_len_from_direntry in #100, this problem seems to be solved. Especially after removing that pesky +1 in ext2_get_rec_len_from_direntry.