1
0
Fork 0
mirror of https://gitlab.com/sortix/sortix.git synced 2023-02-13 20:55:38 -05:00

Add extfs support for d_type.

This commit is contained in:
Jonas 'Sortie' Termansen 2015-12-23 17:08:19 +01:00
parent 624ceff900
commit e89dc04674
4 changed files with 27 additions and 3 deletions

View file

@ -24,6 +24,7 @@
#include <sys/types.h>
#include <assert.h>
#include <dirent.h>
#include <errno.h>
#include <error.h>
#include <fcntl.h>
@ -92,6 +93,22 @@ uint32_t ExtModeFromHostMode(mode_t hostmode)
return extmode;
}
uint8_t HostDTFromExtDT(uint8_t extdt)
{
switch ( extdt )
{
case EXT2_FT_UNKNOWN: return DT_UNKNOWN;
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 DT_SOCK;
case EXT2_FT_SYMLINK: return DT_LNK;
}
return DT_UNKNOWN;
}
void StatInode(Inode* inode, struct stat* st)
{
memset(st, 0, sizeof(*st));

View file

@ -30,6 +30,7 @@ class Inode;
mode_t HostModeFromExtMode(uint32_t extmode);
uint32_t ExtModeFromHostMode(mode_t hostmode);
uint8_t HostDTFromExtDT(uint8_t extdt);
void StatInode(Inode* inode, struct stat* st);
#endif

View file

@ -29,6 +29,7 @@
#include <errno.h>
#include <error.h>
#include <dirent.h>
#include <fcntl.h>
#include <ioleast.h>
#include <signal.h>
@ -397,10 +398,13 @@ void HandleReadDir(int chl, struct fsm_req_readdirents* msg, Filesystem* fs)
const struct ext_dirent* entry = (const struct ext_dirent*) block_data;
if ( entry->inode && entry->name_len && !(msg->rec_num--) )
{
uint8_t file_type = EXT2_FT_UNKNOWN;
if ( fs->sb->s_feature_incompat & EXT2_FEATURE_INCOMPAT_FILETYPE )
file_type = entry->file_type;
kernel_entry.d_reclen = sizeof(kernel_entry) + entry->name_len;
kernel_entry.d_ino = entry->inode;
kernel_entry.d_dev = 0;
kernel_entry.d_type = 0; // TODO: Support this!
kernel_entry.d_type = HostDTFromExtDT(file_type);
kernel_entry.d_namlen = entry->name_len;
memcpy(kernel_entry.d_name, entry->name, entry->name_len);
size_t dname_offset = offsetof(struct dirent, d_name);

View file

@ -428,7 +428,9 @@ Inode* Inode::Open(const char* elem, int flags, mode_t mode)
entry->name_len == elem_length &&
memcmp(elem, entry->name, elem_length) == 0 )
{
uint8_t file_type = entry->file_type;
uint8_t file_type = EXT2_FT_UNKNOWN;
if ( filesystem->sb->s_feature_incompat & EXT2_FEATURE_INCOMPAT_FILETYPE )
file_type = entry->file_type;
uint32_t inode_id = entry->inode;
block->Unref();
if ( (flags & O_CREAT) && (flags & O_EXCL) )
@ -602,7 +604,7 @@ bool Inode::Link(const char* elem, Inode* dest, bool directories)
if ( filesystem->sb->s_feature_incompat & EXT2_FEATURE_INCOMPAT_FILETYPE )
entry->file_type = EXT2_FT_OF_MODE(dest->Mode());
else
entry->file_type = 0;
entry->file_type = EXT2_FT_UNKNOWN;
strncpy(entry->name, elem, new_entry_size - sizeof(struct ext_dirent));
block->FinishWrite();