The Pedigree Project
0.1
|
#include <File.h>
Classes | |
class | DataCacheKey |
struct | MonitorTarget |
Public Member Functions | |
File () | |
File (const String &name, Time::Timestamp accessedTime, Time::Timestamp modifiedTime, Time::Timestamp creationTime, uintptr_t inode, class Filesystem *pFs, size_t size, File *pParent) | |
virtual | ~File () |
virtual uint64_t | read (uint64_t location, uint64_t size, uintptr_t buffer, bool bCanBlock=true) final |
virtual uint64_t | write (uint64_t location, uint64_t size, uintptr_t buffer, bool bCanBlock=true) final |
virtual physical_uintptr_t | getPhysicalPage (size_t offset) |
virtual void | returnPhysicalPage (size_t offset) |
virtual void | sync () |
virtual void | sync (size_t offset, bool async) |
Time::Timestamp | getCreationTime () |
void | setCreationTime (Time::Timestamp t) |
Time::Timestamp | getAccessedTime () |
void | setAccessedTime (Time::Timestamp t) |
Time::Timestamp | getModifiedTime () |
void | setModifiedTime (Time::Timestamp t) |
String | getName () const |
void | getName (String &s) const |
virtual String | getFullPath (bool bWithLabel=true) |
virtual void | truncate () |
size_t | getSize () |
void | setSize (size_t sz) |
virtual bool | isSymlink () |
virtual bool | isDirectory () |
virtual bool | isPipe () const |
virtual bool | isFifo () const |
virtual bool | isSocket () const |
uintptr_t | getInode () const |
virtual void | setInode (uintptr_t inode) |
Filesystem * | getFilesystem () const |
void | setFilesystem (Filesystem *pFs) |
virtual void | fileAttributeChanged () |
virtual void | increaseRefCount (bool bIsWriter) |
virtual void | decreaseRefCount (bool bIsWriter) |
void | setPermissions (uint32_t perms) |
uint32_t | getPermissions () const |
void | setUid (size_t uid) |
size_t | getUid () const |
void | setGid (size_t gid) |
size_t | getGid () const |
File * | getParent () const |
virtual int | select (bool bWriting=false, int timeout=0) |
void | monitor (Thread *pThread, Event *pEvent) |
void | cullMonitorTargets (Thread *pThread) |
virtual bool | supports (const size_t command) const |
virtual int | command (const size_t command, void *buffer) |
virtual size_t | getBlockSize () const |
void | enableDirect () |
void | disableDirect () |
virtual void | preallocate (size_t expectedSize, bool zero=true) |
virtual File * | open () |
Protected Member Functions | |
virtual bool | isBytewise () const |
virtual uint64_t | readBytewise (uint64_t location, uint64_t size, uintptr_t buffer, bool bCanBlock=true) |
virtual uint64_t | writeBytewise (uint64_t location, uint64_t size, uintptr_t buffer, bool bCanBlock=true) |
virtual uintptr_t | readBlock (uint64_t location) |
virtual void | writeBlock (uint64_t location, uintptr_t addr) |
virtual void | extend (size_t newSize) |
virtual void | extend (size_t newSize, uint64_t location, uint64_t size) |
void | dataChanged () |
void | getFilesystemLabel (HugeStaticString &s) |
virtual void | pinBlock (uint64_t location) |
virtual void | unpinBlock (uint64_t location) |
void | evict (uint64_t location) |
void | setPermissionsOnly (uint32_t perms) |
void | setUidOnly (size_t uid) |
void | setGidOnly (size_t gid) |
Static Protected Member Functions | |
static void | writeCallback (CacheConstants::CallbackCause cause, uintptr_t loc, uintptr_t page, void *meta) |
Protected Attributes | |
String | m_Name |
Time::Timestamp | m_AccessedTime |
Time::Timestamp | m_ModifiedTime |
Time::Timestamp | m_CreationTime |
uintptr_t | m_Inode |
class Filesystem * | m_pFilesystem |
size_t | m_Size |
File * | m_pParent |
size_t | m_nWriters |
size_t | m_nReaders |
size_t | m_Uid |
size_t | m_Gid |
uint32_t | m_Permissions |
HashTable< DataCacheKey, uintptr_t > | m_DataCache |
bool | m_bDirect |
Cache | m_FillCache |
Mutex | m_Lock |
List< MonitorTarget * > | m_MonitorTargets |
Private Member Functions | |
File (const File &file) | |
File & | operator= (const File &) |
uintptr_t | getCachedPage (size_t block, bool locked=true) |
void | setCachedPage (size_t block, uintptr_t value, bool locked=true) |
bool | useFillCache () const |
uintptr_t | readIntoCache (uintptr_t block) |
Friends | |
class | Filesystem |
File::File | ( | ) |
Constructor, creates an invalid file.
Definition at line 68 of file File.cc.
Referenced by RtcFile::command(), FramebufferFile::command(), and NullFile::writeBytewise().
|
private |
Copy constructors are hidden - unused!
File::File | ( | const String & | name, |
Time::Timestamp | accessedTime, | ||
Time::Timestamp | modifiedTime, | ||
Time::Timestamp | creationTime, | ||
uintptr_t | inode, | ||
class Filesystem * | pFs, | ||
size_t | size, | ||
File * | pParent | ||
) |
Constructor, should be called only by a Filesystem.
Definition at line 84 of file File.cc.
References getBlockSize(), and setCachedPage().
|
virtual |
Handle a command.
Reimplemented in FramebufferFile, and RtcFile.
void File::cullMonitorTargets | ( | Thread * | pThread | ) |
|
protected |
Internal function to notify all registered MonitorTargets.
Definition at line 654 of file File.cc.
References Scheduler::instance(), Thread::sendEvent(), and Scheduler::yield().
Referenced by Pipe::decreaseRefCount(), ConsolePhysicalFile::performInject(), PsAuxFile::select(), and Pipe::writeBytewise().
void File::disableDirect | ( | ) |
void File::enableDirect | ( | ) |
|
protected |
Removes the given location from the VFS-level File cache.
Each File offers read() and write(), which in turn call readBlock. The result from readBlock is cached at the File object level in such a way that requires notification from the File subclass when the address returned from readBlock is no longer valid.
Definition at line 634 of file File.cc.
References getBlockSize(), and setCachedPage().
|
protectedvirtual |
|
protectedvirtual |
Does the same thing as extend() but with an optional hint indicating that the upcoming write will fill an entire block. This hint can be used to do things like avoid zeroing the block that would otherwise be written over anyway.
Reimplemented in FatFile, and Ext2File.
Definition at line 621 of file File.cc.
References extend().
Time::Timestamp File::getAccessedTime | ( | ) |
Returns the time the file was last accessed.
Definition at line 389 of file File.cc.
Referenced by Iso9660Directory::cacheDirectoryContents().
|
virtual |
Function to retrieve the block size returned by readBlock.
Reimplemented in ConsoleFile, Ext2File, Iso9660File, and RawFsFile.
Definition at line 549 of file File.cc.
References PhysicalMemoryManager::getPageSize().
Referenced by evict(), File(), getPhysicalPage(), read(), FatFile::readBlock(), readIntoCache(), returnPhysicalPage(), sync(), useFillCache(), write(), FatFile::writeBlock(), and writeCallback().
|
private |
Retrieve a page from our cache.
Definition at line 760 of file File.cc.
Referenced by getPhysicalPage(), and readIntoCache().
Time::Timestamp File::getCreationTime | ( | ) |
Returns the time the file was created.
Definition at line 378 of file File.cc.
Referenced by Iso9660Directory::cacheDirectoryContents().
|
protected |
Internal function to get the filesystem label for this file.
Definition at line 713 of file File.cc.
References Filesystem::getVolumeLabel().
Referenced by getFullPath().
|
virtual |
Obtains the full path of the File.
Definition at line 718 of file File.cc.
References ERROR, getFilesystemLabel(), and getName().
Referenced by UnixSocketSyscalls::bind(), FileDescriptor::FileDescriptor(), Filesystem::findNode(), FatFilesystem::getVolumeLabel(), FileDescriptor::operator=(), PosixSubsystem::parseShebang(), readBlock(), and FileDescriptor::~FileDescriptor().
Time::Timestamp File::getModifiedTime | ( | ) |
Returns the time the file was last modified.
Definition at line 400 of file File.cc.
Referenced by Iso9660Directory::cacheDirectoryContents().
String File::getName | ( | ) | const |
Returns the name of the file.
Definition at line 411 of file File.cc.
Referenced by RawFsDir::addEntry(), FatDirectory::addEntry(), Directory::addEphemeralFile(), UnixSocketSyscalls::bind(), FatFilesystem::findFreeCluster(), getFullPath(), ProcFs::initialise(), DevFs::initialise(), PosixSubsystem::invoke(), Pipe::isFifo(), Pipe::isPipe(), PosixSubsystem::loadElf(), DynamicLinker::loadObject(), DynamicLinker::loadProgram(), MemoryMapManager::mapFile(), VirtualTerminalManager::openInactive(), Ext2Filesystem::remove(), FatDirectory::removeEntry(), RawFsDir::removeRecursive(), MemoryMappedFile::setPermissions(), RamFile::unpinBlock(), and UnixSocket::writeBytewise().
|
virtual |
Get the physical address for the given offset into the file. Returns (physical_uintptr_t) ~0 if the offset isn't in the cache.
Reimplemented in MemFile.
Definition at line 242 of file File.cc.
References getBlockSize(), getCachedPage(), VirtualAddressSpace::getMapping(), PhysicalMemoryManager::getPageSize(), Processor::information(), VirtualAddressSpace::isMapped(), LIKELY, Cache::lookup(), m_FillCache, Cache::pin(), pinBlock(), UNLIKELY, useFillCache(), and WARNING.
Referenced by MemoryMappedFile::setPermissions().
|
protectedvirtual |
File subclasses can define this and return true if they require read() calls to perform actual data reads, and false if readBlock() is otherwise sufficient.
Reimplemented in Tty0File, UnixSocket, ConsoleFile, RtcFile, TextIO, ConstantFile, PtmxFile, Directory, UptimeFile, ZeroFile, Pipe, MountFile, NullFile, PciDevicesFile, Symlink, RandomFile, MeminfoFile, and PsAuxFile.
Definition at line 577 of file File.cc.
Referenced by Symlink::isSymlink(), read(), readBytewise(), write(), and writeBytewise().
|
virtual |
Returns true if the File is actually a directory.
Reimplemented in Directory.
Definition at line 436 of file File.cc.
Referenced by FatDirectory::addEntry(), UnixSocketSyscalls::bind(), RamFs::createDirectory(), RamFs::createFile(), FatFilesystem::createFile(), Ext2Filesystem::createLink(), Ext2Filesystem::createNode(), FatFilesystem::createSymlink(), Filesystem::findNode(), Filesystem::findParent(), Directory::fromFile(), Iso9660Filesystem::getVolumeLabel(), FatFilesystem::getVolumeLabel(), UnixFilesystem::getVolumeLabel(), PosixSubsystem::parseShebang(), Ext2Filesystem::remove(), Filesystem::remove(), RamFs::remove(), and FatDirectory::removeEntry().
|
virtual |
Returns true if the File is actually a fifo.
Reimplemented in Pipe.
Definition at line 446 of file File.cc.
Referenced by Pipe::fromFile().
|
virtual |
Returns true if the File is actually a pipe.
Reimplemented in Pipe.
Definition at line 441 of file File.cc.
Referenced by Pipe::fromFile().
|
virtual |
Returns true if the File is actually a socket.
Reimplemented in UnixSocket.
Definition at line 451 of file File.cc.
Referenced by UnixSocketSyscalls::connect(), and UnixSocketSyscalls::sendto_msg().
|
virtual |
Returns true if the File is actually a symlink.
Reimplemented in Symlink.
Definition at line 431 of file File.cc.
Referenced by FatDirectory::addEntry(), Ext2Filesystem::createLink(), Ext2Filesystem::createNode(), Filesystem::findNode(), Symlink::fromFile(), DynamicLinker::loadObject(), DynamicLinker::loadProgram(), PosixSubsystem::parseShebang(), Ext2Filesystem::remove(), and FatDirectory::removeEntry().
Causes the event pEvent to be dispatched to pThread when activity occurs on this File. Activity includes the file becoming available for reading, writing or erroring.
Definition at line 683 of file File.cc.
Referenced by IoEvent::IoEvent().
|
virtual |
Obtain the actual File object to use when opening this file.
This allows a File to exist and perform logic on an open() before returning either itself or some other File object. Some files require side effects as part of their opening, this facilitates that.
Reimplemented in Tty0File, and PtmxFile.
Definition at line 572 of file File.cc.
Referenced by Framebuffer::initialise().
|
protectedvirtual |
Pins the given page.
If your File subclass uses a Cache for readBlock, this method should be implemented to call Cache::pin. The VFS layer calls this method when it determines it is about to give a physical page to an upper layer, and therefore will be unable to guarantee the virtual page's dirty status is a correct reflection of the page's state.
Reimplemented in FatFile, Ext2File, and RamFile.
Definition at line 626 of file File.cc.
Referenced by getPhysicalPage().
|
virtual |
|
finalvirtual |
Reads from the file.
[in] | buffer | Buffer to write the read data into. Can be null, in which case the data can be found by calling getPhysicalPage. |
[in] | bCanBlock | Whether or not the File can block when reading |
Definition at line 116 of file File.cc.
References ERROR, getBlockSize(), PhysicalMemoryManager::getPageSize(), isBytewise(), readBytewise(), readIntoCache(), and useFillCache().
Referenced by Symlink::initialise(), PosixSubsystem::invoke(), PosixSubsystem::parseShebang(), and MemoryMappedFile::setPermissions().
|
protectedvirtual |
Internal function to retrieve an aligned 512byte section of the file.
Reimplemented in FramebufferFile, FatFile, Iso9660File, Ext2File, RamFile, and RawFsFile.
Definition at line 602 of file File.cc.
References assert, ERROR, and getFullPath().
Referenced by readIntoCache().
|
protectedvirtual |
Reads bytes from the file, if isBytewise() == true.
Reimplemented in ConsolePhysicalFile, ConsoleSlaveFile, Tty0File, ConsoleMasterFile, RtcFile, ConstantFile, PtmxFile, TextIO, UnixSocket, UptimeFile, ZeroFile, MountFile, NullFile, PciDevicesFile, Pipe, FatSymlink, RandomFile, Ext2Symlink, PsAuxFile, and MeminfoFile.
Definition at line 582 of file File.cc.
References FATAL, and isBytewise().
Referenced by Pipe::fromFile(), and read().
|
private |
Read the given block into the relevant cache.
Definition at line 816 of file File.cc.
References ERROR, getBlockSize(), getCachedPage(), PhysicalMemoryManager::getPageSize(), Cache::insert(), m_FillCache, Cache::markNoLongerEditing(), NOTICE, readBlock(), setCachedPage(), and useFillCache().
Referenced by read(), and write().
|
virtual |
Specifies that the system is done with the physical page retrieved from getPhysicalPage now. Allows the physical page to be evicted from the file cache again.
Reimplemented in MemFile.
Definition at line 315 of file File.cc.
References getBlockSize(), PhysicalMemoryManager::getPageSize(), m_FillCache, Cache::release(), UNLIKELY, unpinBlock(), and useFillCache().
|
virtual |
Similar to POSIX's select() function
Reimplemented in ConsolePhysicalFile, TextIO, UnixSocket, ConsoleFile, Pipe, and PsAuxFile.
Definition at line 534 of file File.cc.
Referenced by Pipe::fromFile().
void File::setAccessedTime | ( | Time::Timestamp | t | ) |
Sets the time the file was last accessed.
Definition at line 394 of file File.cc.
Referenced by Ext2Filesystem::createNode().
|
private |
Set a page in our cache.
Definition at line 778 of file File.cc.
References assert.
Referenced by evict(), File(), readIntoCache(), and writeCallback().
void File::setCreationTime | ( | Time::Timestamp | t | ) |
|
protected |
Set GID without raising fileAttributeChanged.
Definition at line 649 of file File.cc.
Referenced by RtcFile::command(), FramebufferFile::command(), Ext2Directory::Ext2Directory(), Ext2File::Ext2File(), Ext2Symlink::Ext2Symlink(), and NullFile::writeBytewise().
void File::setModifiedTime | ( | Time::Timestamp | t | ) |
Sets the time the file was last modified.
Definition at line 405 of file File.cc.
Referenced by Ext2Filesystem::createNode().
|
protected |
Set permissions without raising fileAttributeChanged.
Definition at line 639 of file File.cc.
Referenced by RtcFile::command(), FramebufferFile::command(), Ext2Directory::Ext2Directory(), Ext2File::Ext2File(), Ext2Symlink::Ext2Symlink(), and NullFile::writeBytewise().
|
protected |
Set UID without raising fileAttributeChanged.
Definition at line 644 of file File.cc.
Referenced by RtcFile::command(), FramebufferFile::command(), Ext2Directory::Ext2Directory(), Ext2File::Ext2File(), Ext2Symlink::Ext2Symlink(), and NullFile::writeBytewise().
|
virtual |
Does this File object support the given integer-based command?
Reimplemented in FramebufferFile, and RtcFile.
|
virtual |
Sync all cached pages for the file back to disk.
Default implementation calls writeBlock; only override if your File subclass does not actually expose readBlock/writeBlock, or if it already overrides read() or write().
Definition at line 351 of file File.cc.
References getBlockSize(), and writeBlock().
|
virtual |
|
virtual |
Delete all data from the file.
Reimplemented in Ext2Symlink, Ext2File, Ext2Directory, FatDirectory, and RamFile.
|
protectedvirtual |
|
private |
Indicate whether the 'fill cache' is needed to handle sub-page block sizes.
Definition at line 804 of file File.cc.
References getBlockSize(), and PhysicalMemoryManager::getPageSize().
Referenced by getPhysicalPage(), read(), readIntoCache(), and returnPhysicalPage().
|
finalvirtual |
Writes to the file.
[in] | bCanBlock | Whether or not the File can block when reading |
Definition at line 183 of file File.cc.
References ERROR, extend(), getBlockSize(), isBytewise(), readIntoCache(), writeBlock(), and writeBytewise().
Referenced by Ext2Filesystem::createNode(), FatFilesystem::createSymlink(), DevFs::initialise(), ConsolePhysicalFile::readBytewise(), and UnixSocketSyscalls::sendto_msg().
|
protectedvirtual |
Internal function to write a block retrieved with readBlock back to the file. The address of the block is provided for convenience.
Reimplemented in FatFile, and Ext2File.
Definition at line 611 of file File.cc.
Referenced by sync(), write(), and writeCallback().
|
protectedvirtual |
Writes bytes to the file, if isBytewise() == true.
Reimplemented in ConsolePhysicalFile, ConsoleSlaveFile, Tty0File, ConsoleMasterFile, RtcFile, ConstantFile, PtmxFile, TextIO, UnixSocket, UptimeFile, ZeroFile, MountFile, NullFile, PciDevicesFile, FatSymlink, Pipe, RandomFile, Ext2Symlink, PsAuxFile, and MeminfoFile.
Definition at line 592 of file File.cc.
References FATAL, and isBytewise().
Referenced by Pipe::fromFile(), and write().
|
staticprotected |
Called by a cache to write back changed data to disk.
File subclasses that use a Cache for readBlock can utilise this as the callback on their Cache instance to get a write-back notification.
Definition at line 37 of file File.cc.
References getBlockSize(), PhysicalMemoryManager::getPageSize(), setCachedPage(), WARNING, and writeBlock().
Referenced by FatFile::FatFile().
|
protected |
This cache is necessary to handle filesystems with block sizes that are smaller than the native page size. For these filesystems, to perform memory maps we read native page size blocks into this cache, and then return pages from it directly. This is expected to somewhat increase memory usage and reduce performance on non-natively-sized block sizes, but that's an acceptable compromise.
Definition at line 379 of file File.h.
Referenced by getPhysicalPage(), readIntoCache(), and returnPhysicalPage().