mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
Support the ext2 directory entry file_type field.
This commit is contained in:
parent
e7901476d3
commit
47fc6344ac
Notes:
sideshowbarker
2024-07-19 18:47:55 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/47fc6344acf
2 changed files with 23 additions and 6 deletions
|
@ -390,8 +390,8 @@ bool Ext2FileSystem::enumerateDirectoryInode(InodeIdentifier inode, std::functio
|
|||
if (entry->inode != 0) {
|
||||
memcpy(namebuf, entry->name, entry->name_len);
|
||||
namebuf[entry->name_len] = 0;
|
||||
#ifdef EXT2_DEBUG
|
||||
printf("inode: %u, name_len: %u, rec_len: %u, name: %s\n", entry->inode, entry->name_len, entry->rec_len, namebuf);
|
||||
#ifndef EXT2_DEBUG
|
||||
printf("inode: %u, name_len: %u, rec_len: %u, file_type: %u, name: %s\n", entry->inode, entry->name_len, entry->rec_len, entry->file_type, namebuf);
|
||||
#endif
|
||||
if (!callback({ namebuf, { id(), entry->inode }, entry->file_type }))
|
||||
break;
|
||||
|
@ -401,7 +401,7 @@ bool Ext2FileSystem::enumerateDirectoryInode(InodeIdentifier inode, std::functio
|
|||
return true;
|
||||
}
|
||||
|
||||
bool Ext2FileSystem::addInodeToDirectory(unsigned directoryInode, unsigned inode, const String& name)
|
||||
bool Ext2FileSystem::addInodeToDirectory(unsigned directoryInode, unsigned inode, const String& name, byte fileType)
|
||||
{
|
||||
auto e2inodeForDirectory = lookupExt2Inode(directoryInode);
|
||||
ASSERT(e2inodeForDirectory);
|
||||
|
@ -426,7 +426,7 @@ bool Ext2FileSystem::addInodeToDirectory(unsigned directoryInode, unsigned inode
|
|||
return false;
|
||||
}
|
||||
|
||||
entries.append({ name, { id(), inode } });
|
||||
entries.append({ name, { id(), inode }, fileType });
|
||||
|
||||
return writeDirectoryInode(directoryInode, std::move(entries));
|
||||
}
|
||||
|
@ -502,6 +502,7 @@ bool Ext2FileSystem::writeDirectoryInode(unsigned directoryInode, Vector<Directo
|
|||
printf("* inode: %u", entry.inode.index());
|
||||
printf(", name_len: %u", word(entry.name.length()));
|
||||
printf(", rec_len: %u", word(recordLength));
|
||||
printf(", file_type: %u", byte(entry.fileType));
|
||||
printf(", name: %s\n", entry.name.characters());
|
||||
|
||||
stream << dword(entry.inode.index());
|
||||
|
@ -754,8 +755,24 @@ InodeIdentifier Ext2FileSystem::createInode(InodeIdentifier parentInode, const S
|
|||
// NOTE: This doesn't commit the inode allocation just yet!
|
||||
auto inode = allocateInode(0, 0);
|
||||
|
||||
byte fileType = 0;
|
||||
if (isRegularFile(mode))
|
||||
fileType = EXT2_FT_REG_FILE;
|
||||
else if (isDirectory(mode))
|
||||
fileType = EXT2_FT_DIR;
|
||||
else if (isCharacterDevice(mode))
|
||||
fileType = EXT2_FT_CHRDEV;
|
||||
else if (isBlockDevice(mode))
|
||||
fileType = EXT2_FT_BLKDEV;
|
||||
else if (isFIFO(mode))
|
||||
fileType = EXT2_FT_FIFO;
|
||||
else if (isSocket(mode))
|
||||
fileType = EXT2_FT_SOCK;
|
||||
else if (isSymbolicLink(mode))
|
||||
fileType = EXT2_FT_SYMLINK;
|
||||
|
||||
// Try adding it to the directory first, in case the name is already in use.
|
||||
bool success = addInodeToDirectory(parentInode.index(), inode, name);
|
||||
bool success = addInodeToDirectory(parentInode.index(), inode, name, fileType);
|
||||
if (!success) {
|
||||
printf("[ext2fs] failed to add inode to directory :(\n");
|
||||
return { };
|
||||
|
|
|
@ -54,7 +54,7 @@ private:
|
|||
template<typename F>
|
||||
void traverseInodeBitmap(unsigned groupIndex, F) const;
|
||||
|
||||
bool addInodeToDirectory(unsigned directoryInode, unsigned inode, const String& name);
|
||||
bool addInodeToDirectory(unsigned directoryInode, unsigned inode, const String& name, byte fileType);
|
||||
bool writeDirectoryInode(unsigned directoryInode, Vector<DirectoryEntry>&&);
|
||||
bool setInodeAllocationState(unsigned inode, bool);
|
||||
|
||||
|
|
Loading…
Reference in a new issue