mit-pdos / xv6-riscv

Xv6 for RISC-V
Other
6.58k stars 2.38k forks source link

Type inconsistent between struct dirent's inum(ushort) and its usage(uint). #164

Open zhouzilong2020 opened 1 year ago

zhouzilong2020 commented 1 year ago

inum defined inside struct dirent is a ushort, suggesting the dirent can only reference up to 4 inode on disk. https://github.com/mit-pdos/xv6-riscv/blob/f5b93ef12f7159f74f80f94729ee4faabe42c360/kernel/fs.h#L56-L59 However, in function dirlink(), it tries to set inum with a unit. https://github.com/mit-pdos/xv6-riscv/blob/f5b93ef12f7159f74f80f94729ee4faabe42c360/kernel/fs.c#L601

I further checked all the usage of the user space function link(), and it turns out none tried to open a file via its linked name. Is this a delicate design or a bug?

zhouzilong2020 commented 1 year ago

Since each dinode has 64 bytes right now, and there are 13 blocks for inode on disk, xv6 chould at most have 208 inode.

To make the data type of inum consistent, I suggest:

  1. Changing struct dirent as follows:

    #define DIRSIZ 12
    struct dirent {
    uint inum;
    char name[DIRSIZ];
    };
  2. Changing inum to ushort everywhere, which includes much more modifications to the code.