mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 11:12:45 +00:00 
			
		
		
		
	Implement SyntheticFileSystem::readInodeBytes().
This commit is contained in:
		
							parent
							
								
									1f41a36c52
								
							
						
					
					
						commit
						c7c957966a
					
				
					 2 changed files with 21 additions and 9 deletions
				
			
		|  | @ -258,7 +258,7 @@ Vector<unsigned> Ext2FileSystem::blockListForInode(const ext2_inode& e2inode) co | |||
|     return list; | ||||
| } | ||||
| 
 | ||||
| ssize_t Ext2FileSystem::readInodeBytes(InodeIdentifier inode, Unix::off_t offset, size_t count, byte* buffer) const | ||||
| Unix::ssize_t Ext2FileSystem::readInodeBytes(InodeIdentifier inode, Unix::off_t offset, Unix::size_t count, byte* buffer) const | ||||
| { | ||||
|     ASSERT(offset >= 0); | ||||
|     ASSERT(inode.fileSystemID() == id()); | ||||
|  | @ -282,7 +282,7 @@ ssize_t Ext2FileSystem::readInodeBytes(InodeIdentifier inode, Unix::off_t offset | |||
|     // This avoids wasting an entire block on short links. (Most links are short.)
 | ||||
|     static const unsigned maxInlineSymlinkLength = 60; | ||||
|     if (isSymbolicLink(e2inode->i_mode) && e2inode->i_size < maxInlineSymlinkLength) { | ||||
|         ssize_t nread = min(e2inode->i_size - offset, static_cast<Unix::off_t>(count)); | ||||
|         Unix::ssize_t nread = min(e2inode->i_size - offset, static_cast<Unix::off_t>(count)); | ||||
|         memcpy(buffer, e2inode->i_block + offset, nread); | ||||
|         return nread; | ||||
|     } | ||||
|  | @ -302,8 +302,8 @@ ssize_t Ext2FileSystem::readInodeBytes(InodeIdentifier inode, Unix::off_t offset | |||
| 
 | ||||
|     dword offsetIntoFirstBlock = offset % blockSize(); | ||||
| 
 | ||||
|     ssize_t nread = 0; | ||||
|     size_t remainingCount = min((Unix::off_t)count, e2inode->i_size - offset); | ||||
|     Unix::ssize_t nread = 0; | ||||
|     Unix::size_t remainingCount = min((Unix::off_t)count, e2inode->i_size - offset); | ||||
|     byte* out = buffer; | ||||
| 
 | ||||
| #ifdef EXT2_DEBUG | ||||
|  | @ -346,7 +346,7 @@ ByteBuffer Ext2FileSystem::readInode(InodeIdentifier inode) const | |||
| 
 | ||||
|     auto contents = ByteBuffer::createUninitialized(e2inode->i_size); | ||||
| 
 | ||||
|     ssize_t nread; | ||||
|     Unix::ssize_t nread; | ||||
|     byte buffer[512]; | ||||
|     byte* out = contents.pointer(); | ||||
|     Unix::off_t offset = 0; | ||||
|  | @ -501,7 +501,7 @@ public: | |||
| 
 | ||||
| private: | ||||
|     ByteBuffer& m_buffer; | ||||
|     size_t m_offset { 0 }; | ||||
|     Unix::size_t m_offset { 0 }; | ||||
| }; | ||||
| 
 | ||||
| bool Ext2FileSystem::writeDirectoryInode(unsigned directoryInode, Vector<DirectoryEntry>&& entries) | ||||
|  |  | |||
|  | @ -1,4 +1,5 @@ | |||
| #include "SyntheticFileSystem.h" | ||||
| #include <AK/StdLib.h> | ||||
| 
 | ||||
| RetainPtr<SyntheticFileSystem> SyntheticFileSystem::create() | ||||
| { | ||||
|  | @ -122,8 +123,19 @@ bool SyntheticFileSystem::writeInode(InodeIdentifier, const ByteBuffer&) | |||
|     return false; | ||||
| } | ||||
| 
 | ||||
| ssize_t SyntheticFileSystem::readInodeBytes(InodeIdentifier, Unix::off_t offset, size_t count, byte* buffer) const | ||||
| ssize_t SyntheticFileSystem::readInodeBytes(InodeIdentifier inode, Unix::off_t offset, Unix::size_t count, byte* buffer) const | ||||
| { | ||||
|     printf("FIXME: Implement SyntheticFileSystem::readInodeBytes().\n"); | ||||
|     return 0; | ||||
|     ASSERT(inode.fileSystemID() == id()); | ||||
| #ifdef SYNTHFS_DEBUG | ||||
|     printf("[synthfs] readInode %u\n", inode.index()); | ||||
| #endif | ||||
|     ASSERT(inode.index() != 1); | ||||
|     ASSERT(inode.index() <= m_files.size()); | ||||
|     ASSERT(offset >= 0); | ||||
|     ASSERT(buffer); | ||||
| 
 | ||||
|     auto& file = *m_files[inode.index() - 1]; | ||||
|     Unix::ssize_t nread = min(file.data.size() - offset, static_cast<Unix::off_t>(count)); | ||||
|     memcpy(buffer, file.data.pointer() + offset, nread); | ||||
|     return nread; | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Andreas Kling
						Andreas Kling