1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 15:48:12 +00:00

Ext2FS: Make reported file_type values match up with those in dirent

This fixes an issue we had in the git port where git would not
recognize untracked files (for example in 'git status').
When git used readdir, the 'd_type' field in the dirent struct contained
bad values (Specifically, it contained the values defiend in
Kernel/FileSystem/ext2_fs.h instead of the ones in LibC/dirent.h).

After this fix, we can create a new git repository with 'git init', and
then stage and commit files as usual.
This commit is contained in:
Itamar 2020-08-28 16:15:51 +03:00 committed by Andreas Kling
parent 6cf064e4c6
commit b6c34c0521
3 changed files with 47 additions and 1 deletions

View file

@ -855,6 +855,28 @@ ssize_t Ext2FSInode::write_bytes(off_t offset, ssize_t count, const u8* data, Fi
return nwritten;
}
u8 Ext2FSInode::file_type_for_directory_entry(const ext2_dir_entry_2& entry)
{
switch (entry.file_type) {
case EXT2_FT_REG_FILE:
return DT_REG;
case EXT2_FT_DIR:
return DT_DIR;
case EXT2_FT_CHRDEV:
return DT_CHR;
case EXT2_FT_BLKDEV:
return DT_BLK;
case EXT2_FT_FIFO:
return DT_FIFO;
case EXT2_FT_SOCK:
return EXT2_FT_SOCK;
case EXT2_FT_SYMLINK:
return DT_LNK;
default:
return DT_UNKNOWN;
}
}
KResult Ext2FSInode::traverse_as_directory(Function<bool(const FS::DirectoryEntryView&)> callback) const
{
LOCKER(m_lock);
@ -877,7 +899,7 @@ KResult Ext2FSInode::traverse_as_directory(Function<bool(const FS::DirectoryEntr
#ifdef EXT2_DEBUG
dbg() << "Ext2Inode::traverse_as_directory: " << entry->inode << ", name_len: " << entry->name_len << ", rec_len: " << entry->rec_len << ", file_type: " << entry->file_type << ", name: " << String(entry->name, entry->name_len);
#endif
if (!callback({ { entry->name, entry->name_len }, { fsid(), entry->inode }, entry->file_type }))
if (!callback({ { entry->name, entry->name_len }, { fsid(), entry->inode }, file_type_for_directory_entry(*entry) }))
break;
}
entry = (ext2_dir_entry_2*)((char*)entry + entry->rec_len);

View file

@ -81,6 +81,8 @@ private:
void populate_lookup_cache() const;
KResult resize(u64);
static u8 file_type_for_directory_entry(const ext2_dir_entry_2&);
Ext2FS& fs();
const Ext2FS& fs() const;
Ext2FSInode(Ext2FS&, unsigned index);

View file

@ -614,3 +614,25 @@ struct rtentry {
#define PT_PEEK 7
#define PT_POKE 8
#define PT_SETREGS 9
// Used in struct dirent
enum {
DT_UNKNOWN = 0,
#define DT_UNKNOWN DT_UNKNOWN
DT_FIFO = 1,
#define DT_FIFO DT_FIFO
DT_CHR = 2,
#define DT_CHR DT_CHR
DT_DIR = 4,
#define DT_DIR DT_DIR
DT_BLK = 6,
#define DT_BLK DT_BLK
DT_REG = 8,
#define DT_REG DT_REG
DT_LNK = 10,
#define DT_LNK DT_LNK
DT_SOCK = 12,
#define DT_SOCK DT_SOCK
DT_WHT = 14
#define DT_WHT DT_WHT
};