diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-05-31 17:41:33 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-05-31 17:41:33 +0200 |
commit | 9ac95d1867534f3347bda6dbb2ad021812a0a99a (patch) | |
tree | af3ef488e711cc6dae8ed27090df705fe8bdf206 | |
parent | fdf3608c8a0c940c27c4528480db7e0ef77cb83d (diff) | |
download | serenity-9ac95d1867534f3347bda6dbb2ad021812a0a99a.zip |
FileSystem: Pass mode_t to Inode::add_child().
This way the Ext2FS code can update its directory entry "file type" fields
correctly based on the file mode. This fixes some e2fsck whining.
-rw-r--r-- | Kernel/FileSystem/Ext2FileSystem.cpp | 41 | ||||
-rw-r--r-- | Kernel/FileSystem/Ext2FileSystem.h | 2 | ||||
-rw-r--r-- | Kernel/FileSystem/Inode.h | 2 | ||||
-rw-r--r-- | Kernel/FileSystem/ProcFS.cpp | 3 | ||||
-rw-r--r-- | Kernel/FileSystem/ProcFS.h | 2 | ||||
-rw-r--r-- | Kernel/FileSystem/SyntheticFileSystem.cpp | 3 | ||||
-rw-r--r-- | Kernel/FileSystem/SyntheticFileSystem.h | 2 | ||||
-rw-r--r-- | Kernel/FileSystem/VirtualFileSystem.cpp | 4 |
8 files changed, 30 insertions, 29 deletions
diff --git a/Kernel/FileSystem/Ext2FileSystem.cpp b/Kernel/FileSystem/Ext2FileSystem.cpp index 13e3b93fd1..b0e8925dde 100644 --- a/Kernel/FileSystem/Ext2FileSystem.cpp +++ b/Kernel/FileSystem/Ext2FileSystem.cpp @@ -12,6 +12,25 @@ static const ssize_t max_inline_symlink_length = 60; +static byte to_ext2_file_type(mode_t mode) +{ + if (is_regular_file(mode)) + return EXT2_FT_REG_FILE; + if (is_directory(mode)) + return EXT2_FT_DIR; + if (is_character_device(mode)) + return EXT2_FT_CHRDEV; + if (is_block_device(mode)) + return EXT2_FT_BLKDEV; + if (is_fifo(mode)) + return EXT2_FT_FIFO; + if (is_socket(mode)) + return EXT2_FT_SOCK; + if (is_symlink(mode)) + return EXT2_FT_SYMLINK; + return EXT2_FT_UNKNOWN; +} + Retained<Ext2FS> Ext2FS::create(Retained<DiskDevice>&& device) { return adopt(*new Ext2FS(move(device))); @@ -685,7 +704,7 @@ bool Ext2FSInode::traverse_as_directory(Function<bool(const FS::DirectoryEntry&) return true; } -KResult Ext2FSInode::add_child(InodeIdentifier child_id, const String& name, byte file_type) +KResult Ext2FSInode::add_child(InodeIdentifier child_id, const String& name, mode_t mode) { LOCKER(m_lock); ASSERT(is_directory()); @@ -713,7 +732,7 @@ KResult Ext2FSInode::add_child(InodeIdentifier child_id, const String& name, byt if (child_inode) child_inode->increment_link_count(); - entries.append({ name.characters(), name.length(), child_id, file_type }); + entries.append({ name.characters(), name.length(), child_id, to_ext2_file_type(mode) }); bool success = fs().write_directory_inode(index(), move(entries)); if (success) m_lookup_cache.set(name, child_id.index()); @@ -1130,24 +1149,8 @@ RetainPtr<Inode> Ext2FS::create_inode(InodeIdentifier parent_id, const String& n return { }; } - byte file_type = 0; - if (is_regular_file(mode)) - file_type = EXT2_FT_REG_FILE; - else if (is_directory(mode)) - file_type = EXT2_FT_DIR; - else if (is_character_device(mode)) - file_type = EXT2_FT_CHRDEV; - else if (is_block_device(mode)) - file_type = EXT2_FT_BLKDEV; - else if (is_fifo(mode)) - file_type = EXT2_FT_FIFO; - else if (is_socket(mode)) - file_type = EXT2_FT_SOCK; - else if (is_symlink(mode)) - file_type = EXT2_FT_SYMLINK; - // Try adding it to the directory first, in case the name is already in use. - auto result = parent_inode->add_child({ fsid(), inode_id }, name, file_type); + auto result = parent_inode->add_child({ fsid(), inode_id }, name, to_ext2_file_type(mode)); if (result.is_error()) { error = result; return { }; diff --git a/Kernel/FileSystem/Ext2FileSystem.h b/Kernel/FileSystem/Ext2FileSystem.h index 21e4e856b3..e53d6b2724 100644 --- a/Kernel/FileSystem/Ext2FileSystem.h +++ b/Kernel/FileSystem/Ext2FileSystem.h @@ -32,7 +32,7 @@ private: virtual String reverse_lookup(InodeIdentifier) override; virtual void flush_metadata() override; virtual ssize_t write_bytes(off_t, ssize_t, const byte* data, FileDescriptor*) override; - virtual KResult add_child(InodeIdentifier child_id, const String& name, byte file_type) override; + virtual KResult add_child(InodeIdentifier child_id, const String& name, mode_t) override; virtual KResult remove_child(const String& name) override; virtual RetainPtr<Inode> parent() const override; virtual int set_atime(time_t) override; diff --git a/Kernel/FileSystem/Inode.h b/Kernel/FileSystem/Inode.h index f7f560ce37..6aa6d5a5eb 100644 --- a/Kernel/FileSystem/Inode.h +++ b/Kernel/FileSystem/Inode.h @@ -44,7 +44,7 @@ public: virtual InodeIdentifier lookup(const String& name) = 0; virtual String reverse_lookup(InodeIdentifier) = 0; virtual ssize_t write_bytes(off_t, ssize_t, const byte* data, FileDescriptor*) = 0; - virtual KResult add_child(InodeIdentifier child_id, const String& name, byte file_type) = 0; + virtual KResult add_child(InodeIdentifier child_id, const String& name, mode_t) = 0; virtual KResult remove_child(const String& name) = 0; virtual RetainPtr<Inode> parent() const = 0; virtual size_t directory_entry_count() const = 0; diff --git a/Kernel/FileSystem/ProcFS.cpp b/Kernel/FileSystem/ProcFS.cpp index 3f71e7b206..517b96d689 100644 --- a/Kernel/FileSystem/ProcFS.cpp +++ b/Kernel/FileSystem/ProcFS.cpp @@ -1079,11 +1079,10 @@ ssize_t ProcFSInode::write_bytes(off_t offset, ssize_t size, const byte* buffer, return 0; } -KResult ProcFSInode::add_child(InodeIdentifier child_id, const String& name, byte file_type) +KResult ProcFSInode::add_child(InodeIdentifier child_id, const String& name, mode_t) { (void)child_id; (void)name; - (void)file_type; return KResult(-EPERM); } diff --git a/Kernel/FileSystem/ProcFS.h b/Kernel/FileSystem/ProcFS.h index a8e27a35ac..eff50cd225 100644 --- a/Kernel/FileSystem/ProcFS.h +++ b/Kernel/FileSystem/ProcFS.h @@ -87,7 +87,7 @@ private: virtual String reverse_lookup(InodeIdentifier) override; virtual void flush_metadata() override; virtual ssize_t write_bytes(off_t, ssize_t, const byte* buffer, FileDescriptor*) override; - virtual KResult add_child(InodeIdentifier child_id, const String& name, byte file_type) override; + virtual KResult add_child(InodeIdentifier child_id, const String& name, mode_t) override; virtual KResult remove_child(const String& name) override; virtual RetainPtr<Inode> parent() const override; virtual size_t directory_entry_count() const override; diff --git a/Kernel/FileSystem/SyntheticFileSystem.cpp b/Kernel/FileSystem/SyntheticFileSystem.cpp index b7d96c7b7b..79ec6c9968 100644 --- a/Kernel/FileSystem/SyntheticFileSystem.cpp +++ b/Kernel/FileSystem/SyntheticFileSystem.cpp @@ -279,11 +279,10 @@ ssize_t SynthFSInode::write_bytes(off_t offset, ssize_t size, const byte* buffer return 0; } -KResult SynthFSInode::add_child(InodeIdentifier child_id, const String& name, byte file_type) +KResult SynthFSInode::add_child(InodeIdentifier child_id, const String& name, mode_t) { (void)child_id; (void)name; - (void)file_type; ASSERT_NOT_REACHED(); } diff --git a/Kernel/FileSystem/SyntheticFileSystem.h b/Kernel/FileSystem/SyntheticFileSystem.h index 291d8918dc..825844732f 100644 --- a/Kernel/FileSystem/SyntheticFileSystem.h +++ b/Kernel/FileSystem/SyntheticFileSystem.h @@ -64,7 +64,7 @@ private: virtual String reverse_lookup(InodeIdentifier) override; virtual void flush_metadata() override; virtual ssize_t write_bytes(off_t, ssize_t, const byte* buffer, FileDescriptor*) override; - virtual KResult add_child(InodeIdentifier child_id, const String& name, byte file_type) override; + virtual KResult add_child(InodeIdentifier child_id, const String& name, mode_t) override; virtual KResult remove_child(const String& name) override; virtual RetainPtr<Inode> parent() const override; virtual size_t directory_entry_count() const override; diff --git a/Kernel/FileSystem/VirtualFileSystem.cpp b/Kernel/FileSystem/VirtualFileSystem.cpp index e5d2dce86d..d03af1d6ac 100644 --- a/Kernel/FileSystem/VirtualFileSystem.cpp +++ b/Kernel/FileSystem/VirtualFileSystem.cpp @@ -390,7 +390,7 @@ KResult VFS::rename(StringView old_path, StringView new_path, Custody& base) new_custody.did_delete({}); } - auto result = new_parent_inode.add_child(old_inode.identifier(), new_basename, 0 /* FIXME: file type? */); + auto result = new_parent_inode.add_child(old_inode.identifier(), new_basename, old_inode.mode()); if (result.is_error()) return result; @@ -461,7 +461,7 @@ KResult VFS::link(StringView old_path, StringView new_path, Custody& base) if (!parent_inode.metadata().may_write(current->process())) return KResult(-EACCES); - return parent_inode.add_child(old_inode.identifier(), FileSystemPath(new_path).basename(), 0); + return parent_inode.add_child(old_inode.identifier(), FileSystemPath(new_path).basename(), old_inode.mode()); } KResult VFS::unlink(StringView path, Custody& base) |