The Pedigree Project 0.1
Classes | Public Types | Public Member Functions | Static Public Attributes | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Private Member Functions | Friends | List of all members
File Class Reference

#include <File.h>

+ Inheritance diagram for File:
+ Collaboration diagram for File:

Classes

struct  Attributes
 
struct  CacheState
 
class  DataCacheKey
 
struct  MonitorTarget
 
class  ParentLease
 
class  PreparedShrink
 
struct  ReadPage
 
struct  ShrinkContext
 
class  WriteGuard
 

Public Types

enum  AttributeMask : uint32_t {
  AccessTime = 1U << 0 , ModifyTime = 1U << 1 , ChangeTime = 1U << 2 , Owner = 1U << 3 ,
  Group = 1U << 4 , Permissions = 1U << 5
}
 

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
 
size_t readCached (uint64_t location, size_t size, uintptr_t buffer, bool(*prepare)(uintptr_t, size_t)=nullptr)
 
virtual uint64_t write (uint64_t location, uint64_t size, uintptr_t buffer, bool bCanBlock=true) final
 
uint64_t append (uint64_t size, uintptr_t buffer, uint64_t &location, bool bCanBlock=true)
 
WriteGuard lockWrites ()
 
virtual physical_uintptr_t getPhysicalPage (size_t offset)
 
virtual bool isDirectPhysicalMapping () const
 
size_t physicalMappingFlags () const
 
virtual void returnPhysicalPage (size_t offset)
 
virtual bool tryBeginMappingRelease ()
 
void endMappingRelease ()
 
bool syncAndReturnPhysicalPage (size_t offset, bool async)
 
virtual bool sync ()
 
bool syncRange (size_t offset, size_t length)
 
virtual bool sync (size_t offset, bool async)
 
virtual bool syncPages (const uint64_t *offsets, size_t count)
 
Time::Timestamp getCreationTime ()
 
void setCreationTime (Time::Timestamp t)
 
Time::Timestamp getAccessedTime ()
 
void setAccessedTime (Time::Timestamp t)
 
Time::Timestamp getModifiedTime ()
 
void setModifiedTime (Time::Timestamp t)
 
void setTimes (Time::Timestamp accessed, Time::Timestamp modified, bool changeAccessed, bool changeModified)
 
virtual Attributes getAttributes () const
 
virtual XattrStatus getExtendedAttribute (const StringView &name, void *buffer, size_t capacity, size_t &required)
 
virtual XattrStatus listExtendedAttributes (void *buffer, size_t capacity, size_t &required)
 
virtual XattrStatus setExtendedAttribute (const StringView &name, const void *value, size_t length, unsigned flags)
 
virtual XattrStatus removeExtendedAttribute (const StringView &name)
 
virtual bool prepareSharedMapping (size_t offset, size_t length)
 
String getName () const
 
void getName (String &s) const
 
virtual void getFullPath (String &result, bool bWithMount=true)
 
virtual String getFullPath (bool bWithMount=true)
 
virtual void truncate ()
 
bool resize (size_t size)
 
virtual size_t getSize ()
 
void setSize (size_t sz)
 
virtual bool isSymlink ()
 
virtual bool isDirectory ()
 
virtual bool isBlockDevice () const
 
virtual uint64_t deviceNumber () const
 
virtual bool isPipe () const
 
virtual bool isFifo () const
 
virtual bool isSocket () const
 
virtual bool isSeekable () const
 
bool supportsRegularFileOperations ()
 
virtual bool isCharacterDevice () const
 
virtual bool isConsole () const
 
virtual uint64_t maximumFileSize () const
 
virtual bool allowMapping (bool shared, bool writeRequested, bool &mayWrite)
 
bool acquireMappingUse (bool executable, bool sharedWrite)
 
void releaseMappingUse (bool executable, bool sharedWrite)
 
uintptr_t getInode () const
 
virtual void setInode (uintptr_t inode)
 
virtual uintptr_t futexIdentity ()
 
Filesystem * getFilesystem () const
 
void setFilesystem (Filesystem *pFs)
 
virtual void fileAttributeChanged ()
 
void publishEvent (FileEventMask mask, const StringView &name=StringView(), bool targetIsDirectory=false)
 
virtual FileHandleStatus subscribeInodeEvents (FileEventMask mask, const SharedPointer< FileEventObserver > &observer, FileEventSubscription &subscription)
 
virtual void finishInodeRetirement ()
 
virtual void increaseRefCount (bool bIsWriter)
 
virtual void decreaseRefCount (bool bIsWriter)
 
virtual bool retainVfsReference ()
 
virtual void releaseVfsReference ()
 
virtual bool isStableVfsRoot () const
 
void setPermissions (uint32_t perms)
 
uint32_t getPermissions () const
 
bool setOwnership (size_t uid, size_t gid, bool changeUid, bool changeGid)
 
void setUid (size_t uid)
 
size_t getUid () const
 
void setGid (size_t gid)
 
size_t getGid () const
 
File * getParent () const
 
void getNamespace (ParentLease &parent, String &name) const
 
virtual int select (bool bWriting=false, int timeout=0)
 
virtual ReadyMask queryReady (bool reading, bool writing)
 
virtual bool supportsReadinessNotifications () const
 
void monitor (Thread *pThread, Event *pEvent)
 
void cullMonitorTargets (Thread *pThread)
 
void cullMonitorTargets (Event *pEvent)
 
virtual bool supports (const size_t command) const
 
virtual int command (const size_t command, void *buffer)
 
virtual size_t getBlockSize () const
 
void markPageExternallyWritable (size_t offset)
 
size_t populateRange (size_t offset, size_t length)
 
void enableDirect ()
 
void disableDirect ()
 
virtual void preallocate (size_t expectedSize, bool zero=true)
 
bool allocateRange (size_t offset, size_t length, bool keepSize=false)
 
virtual File * open ()
 
virtual File * openForDescriptor (RetainedFile &owner)
 
- Public Member Functions inherited from ReadinessSource
MUST_USE_RESULT bool subscribeReadiness (ReadyMask interest, const SharedPointer< ReadinessObserver > &observer, ReadinessSubscription &subscription)
 
virtual ReadinessGenerations readinessGenerations ()
 
- Public Member Functions inherited from FileEventSource
MUST_USE_RESULT bool subscribeFileEvents (FileEventMask interest, const SharedPointer< FileEventObserver > &observer, FileEventSubscription &subscription)
 

Static Public Attributes

static constexpr size_t MaxReadPages = 32
 

Protected Member Functions

bool tryAcquireFilesystemOperation (OperationBarrier::Lease &operation) const
 
virtual void updateAttributes (const Attributes &attributes, uint32_t mask)
 
virtual bool changeOwnership (size_t uid, size_t gid, bool changeUid, bool changeGid)
 
virtual bool allowPhysicalPage () const
 
virtual bool prepareWrite (uint64_t location, uint64_t size)
 
virtual bool allowResize (size_t oldSize, size_t newSize)
 
virtual bool prepareShrink (const ShrinkContext &context, UniquePointer< PreparedShrink > &prepared)
 
virtual bool resizeFile (size_t size)
 
virtual bool allocateFileRange (size_t offset, size_t length)
 
virtual Mutex & writeSerializationLock ()
 
virtual Mutex & dataMutationLock ()
 
virtual size_t & physicalPageLoans ()
 
bool clearDataCache ()
 
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 bool readPage (uint64_t location, uintptr_t destination)
 
virtual bool readPages (ReadPage *pages, size_t count)
 
virtual void writeBlock (uint64_t location, uintptr_t addr)
 
virtual void writeBlocks (uint64_t location, uintptr_t addr, size_t length)
 
virtual void extend (size_t newSize)
 
virtual void extend (size_t newSize, uint64_t location, uint64_t size)
 
virtual void publishInodeEvent (const FileEvent &event)
 
void dataChanged ()
 
void getFilesystemLabel (HugeStaticString &s)
 
void enableFillCacheWriteback ()
 
void shutdownFillCacheWriteback ()
 
bool syncFillCache (size_t offset, bool async, bool &present)
 
virtual bool useFillCache () const
 
virtual MUST_USE_RESULT bool pinBlock (uint64_t location)
 
virtual MUST_USE_RESULT uintptr_t acquireCachedBlock (uint64_t location, bool retryChanged)
 
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)
 
void retainDetachedParent ()
 
void moveNamespace (const String &name, File *parent)
 
bool snapshotNamespace (ParentLease &parent, String &name, FileEventMask interest) const
 
virtual CacheState & cacheState ()
 
void setPhysicalMappingFlags (size_t flags)
 
- Protected Member Functions inherited from ReadinessSource
void notifyReadiness (ReadyMask mask)
 
void closeReadiness (ReadyMask mask=ReadyInvalid|ReadyHangup)
 
- Protected Member Functions inherited from FileEventSource
bool hasFileEventObservers (FileEventMask mask) const
 
void notifyFileEvent (const FileEvent &event)
 
void notifyFinalFileEvent (const FileEvent &event)
 
void beginFinalFileEvent (const FileEvent &event)
 
void drainFileEvents ()
 
void closeFileEvents ()
 

Static Protected Member Functions

static bool writeCallback (CacheConstants::CallbackCause cause, uintptr_t loc, uintptr_t page, void *meta)
 
static bool fillCacheCallback (CacheConstants::CallbackCause cause, uintptr_t loc, uintptr_t page, void *meta)
 
- Static Protected Member Functions inherited from FileEventSource
static bool anyFileEventObservers ()
 

Protected Attributes

String m_Name
 
Time::Timestamp m_AccessedTime
 
Time::Timestamp m_ModifiedTime
 
Time::Timestamp m_CreationTime
 
uintptr_t m_Inode
 
uintptr_t m_FutexIdentity = 0
 
class Filesystem * m_pFilesystem
 
size_t m_Size
 
File * m_pParent
 
Mutex m_MetadataLock
 
File * m_pDetachedParent
 
bool m_bDetachedParentHandled
 
size_t m_nWriters
 
size_t m_nReaders
 
size_t m_Uid
 
size_t m_Gid
 
uint32_t m_Permissions
 
CacheState m_CacheState
 
bool m_bDirect
 
Mutex m_WriteLock
 
Mutex m_DataMutationLock
 
size_t m_PhysicalPageLoans = 0
 
size_t m_PhysicalMappingFlags = 0
 
Mutex m_Lock
 
List< MonitorTarget * > m_MonitorTargets
 

Private Member Functions

 File (const File &file)
 
File & operator= (const File &)
 
void publishWriteMetadata ()
 
uint64_t writeUnlocked (uint64_t location, uint64_t size, uintptr_t buffer, bool bCanBlock)
 
uintptr_t getCachedPage (size_t block, bool locked=true)
 
void setCachedPage (size_t block, uintptr_t value, bool locked=true)
 
uintptr_t readIntoCache (uintptr_t block, bool overwriteWholePage=false, size_t readAheadBytes=0)
 
size_t populateRangeLocked (size_t offset, size_t length)
 
void releaseReadReference (uintptr_t block)
 

Friends

class Filesystem
 
class Directory
 

Detailed Description

A File is a regular file - it is also the superclass of Directory, Symlink and Pipe.

Definition at line 75 of file File.h.

Member Enumeration Documentation

◆ AttributeMask

enum File::AttributeMask : uint32_t

Definition at line 241 of file File.h.

Constructor & Destructor Documentation

◆ File() [1/3]

File::File ( )

Constructor, creates an invalid file.

Definition at line 165 of file File.cc.

◆ File() [2/3]

File::File ( const File &  file)
private

Copy constructors are hidden - unused!

◆ File() [3/3]

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 188 of file File.cc.

References getBlockSize(), and setCachedPage().

◆ ~File()

File::~File ( )
virtual

Destructor - doesn't do anything.

Definition at line 221 of file File.cc.

References ReadinessSource::closeReadiness(), VFS::instance(), m_pDetachedParent, and VFS::untrackFile().

Member Function Documentation

◆ acquireCachedBlock()

uintptr_t File::acquireCachedBlock ( uint64_t  location,
bool  retryChanged 
)
protectedvirtual

Returns an existing block's exact address with one caller-owned reference, or zero without a reference. The aligned byte location must be released with one unpinBlock(). No backend population occurs on a miss. retryChanged retries when the File index changes while acquiring the pin.

Reimplemented in RamFile.

Definition at line 1419 of file File.cc.

References getBlockSize(), getCachedPage(), pinBlock(), and unpinBlock().

Referenced by getPhysicalPage(), and readIntoCache().

+ Here is the caller graph for this function:

◆ acquireMappingUse()

bool File::acquireMappingUse ( bool  executable,
bool  sharedWrite 
)

Exclude backing mutations while executable bytes can still be faulted in.

Definition at line 1181 of file File.cc.

Referenced by PosixSubsystem::prepareExecutable(), and MemoryMappedFile::setPermissions().

+ Here is the caller graph for this function:

◆ allocateFileRange()

bool File::allocateFileRange ( size_t  offset,
size_t  length 
)
protectedvirtual

Called with write/data locks held; must reserve and zero newly allocated storage.

Reimplemented in Ext2File, and RamFile.

Definition at line 72 of file File-allocation.cc.

Referenced by allocateRange().

+ Here is the caller graph for this function:

◆ allocateRange()

bool File::allocateRange ( size_t  offset,
size_t  length,
bool  keepSize = false 
)

◆ allowMapping()

bool File::allowMapping ( bool  shared,
bool  writeRequested,
bool &  mayWrite 
)
virtual

Admit a new mapping and restrict its later write upgrades if needed.

Reimplemented in MemFdFile.

Definition at line 1177 of file File.cc.

◆ allowPhysicalPage()

virtual bool File::allowPhysicalPage ( ) const
inlineprotectedvirtual

Definition at line 464 of file File.h.

◆ allowResize()

bool File::allowResize ( size_t  oldSize,
size_t  newSize 
)
protectedvirtual

Definition at line 1209 of file File.cc.

◆ append()

uint64_t File::append ( uint64_t  size,
uintptr_t  buffer,
uint64_t &  location,
bool  bCanBlock = true 
)

Atomically selects EOF and performs one append write.

Definition at line 415 of file File.cc.

References lockWrites().

Referenced by FileDescriptor::write().

+ Here is the caller graph for this function:

◆ cacheState()

File::CacheState & File::cacheState ( )
protectedvirtual

Definition at line 161 of file File.cc.

◆ changeOwnership()

bool File::changeOwnership ( size_t  uid,
size_t  gid,
bool  changeUid,
bool  changeGid 
)
protectedvirtual

Definition at line 950 of file File.cc.

◆ clearDataCache()

bool File::clearDataCache ( )
protected

Caller owns the data mutation lock and has excluded physical-page loans.

Definition at line 1167 of file File.cc.

◆ command()

int File::command ( const size_t  command,
void *  buffer 
)
virtual

Handle a command.

Reimplemented in RtcFile, FramebufferFile, RandomFile, and EvdevFile.

Definition at line 1073 of file File.cc.

◆ cullMonitorTargets() [1/2]

void File::cullMonitorTargets ( Event *  pEvent)

Walks the monitor-target queue, removing all for pEvent.

Definition at line 1514 of file File.cc.

References EMIT_IF.

◆ cullMonitorTargets() [2/2]

void File::cullMonitorTargets ( Thread *  pThread)

Walks the monitor-target queue, removing all for pThread .

Definition at line 1496 of file File.cc.

References EMIT_IF.

◆ dataChanged()

void File::dataChanged ( )
protected

Internal function to notify all registered MonitorTargets.

Definition at line 1452 of file File.cc.

References EMIT_IF, Scheduler::instance(), ReadinessSource::notifyReadiness(), Thread::sendEvent(), and Scheduler::yield().

Referenced by Pipe::decreaseRefCount(), UnixSocket::sendDatagram(), and TextIO::writeStr().

+ Here is the caller graph for this function:

◆ dataMutationLock()

Mutex & File::dataMutationLock ( )
protectedvirtual

Definition at line 1159 of file File.cc.

◆ decreaseRefCount()

void File::decreaseRefCount ( bool  bIsWriter)
virtual

Reimplemented in Pipe.

Definition at line 903 of file File.cc.

◆ deviceNumber()

virtual uint64_t File::deviceNumber ( ) const
inlinevirtual

Definition at line 305 of file File.h.

◆ disableDirect()

void File::disableDirect ( )

Disables direct mode (use File-level cache).

Definition at line 1085 of file File.cc.

◆ enableDirect()

void File::enableDirect ( )

Enables direct mode (no File-level cache).

Definition at line 1081 of file File.cc.

◆ enableFillCacheWriteback()

void File::enableFillCacheWriteback ( )
protected

Installs and drains the native-page fill-cache callback.

Definition at line 1763 of file File.cc.

References Cache::setCallback().

Referenced by Iso9660File::Iso9660File().

+ Here is the caller graph for this function:

◆ endMappingRelease()

void File::endMappingRelease ( )

Definition at line 591 of file File.cc.

◆ evict()

void File::evict ( uint64_t  location)
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 1436 of file File.cc.

References getBlockSize(), and setCachedPage().

◆ extend() [1/2]

void File::extend ( size_t  newSize)
protectedvirtual

Internal function to extend a file to be at least the given size.

Reimplemented in Ext2File, and FatFile.

Definition at line 1406 of file File.cc.

Referenced by extend().

+ Here is the caller graph for this function:

◆ extend() [2/2]

void File::extend ( size_t  newSize,
uint64_t  location,
uint64_t  size 
)
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 Ext2File, and FatFile.

Definition at line 1411 of file File.cc.

References extend().

◆ fileAttributeChanged()

void File::fileAttributeChanged ( )
virtual

Reimplemented in Ext2Symlink, Ext2Directory, Ext2File, and FatDirectory.

Definition at line 849 of file File.cc.

◆ fillCacheCallback()

bool File::fillCacheCallback ( CacheConstants::CallbackCause  cause,
uintptr_t  loc,
uintptr_t  page,
void *  meta 
)
staticprotected

Definition at line 142 of file File.cc.

◆ finishInodeRetirement()

void File::finishInodeRetirement ( )
virtual

Definition at line 859 of file File.cc.

◆ futexIdentity()

uintptr_t File::futexIdentity ( )
virtual

Stable backing token; aliases of one backing object must share it.

Reimplemented in Ext2File, and FatFile.

Definition at line 75 of file File.cc.

Referenced by Ext2File::Ext2File(), MemoryMapManager::hasSharedWriteCapability(), and MemoryMapManager::prepareFileResize().

+ Here is the caller graph for this function:

◆ getAccessedTime()

Time::Timestamp File::getAccessedTime ( )

Returns the time the file was last accessed.

Definition at line 736 of file File.cc.

◆ getAttributes()

File::Attributes File::getAttributes ( ) const
virtual

Definition at line 1091 of file File.cc.

◆ getBlockSize()

size_t File::getBlockSize ( ) const
virtual

◆ getCachedPage()

uintptr_t File::getCachedPage ( size_t  block,
bool  locked = true 
)
private

Retrieve a page from our cache.

Definition at line 1586 of file File.cc.

Referenced by acquireCachedBlock(), and syncRange().

+ Here is the caller graph for this function:

◆ getCreationTime()

Time::Timestamp File::getCreationTime ( )

Returns the time the file was created.

Definition at line 721 of file File.cc.

◆ getExtendedAttribute()

XattrStatus File::getExtendedAttribute ( const StringView &  name,
void *  buffer,
size_t  capacity,
size_t &  required 
)
virtual

Kernel buffers only. Capacity zero queries size without touching output; successful mutations update ctime and publish one Attributes event.

Reimplemented in Ext2Symlink, Ext2Directory, Ext2File, RamFile, and RamDir.

Definition at line 1107 of file File.cc.

◆ getFilesystem()

Filesystem * File::getFilesystem ( ) const

Definition at line 841 of file File.cc.

◆ getFilesystemLabel()

void File::getFilesystemLabel ( HugeStaticString &  s)
protected

Internal function to get the filesystem label for this file.

Definition at line 1531 of file File.cc.

References Filesystem::getVolumeLabel().

◆ getFullPath() [1/2]

String File::getFullPath ( bool  bWithMount = true)
virtual

Obtains the full path of the File and returns it.

Definition at line 1580 of file File.cc.

References getFullPath().

◆ getFullPath() [2/2]

void File::getFullPath ( String &  result,
bool  bWithMount = true 
)
virtual

Obtains the full path of the File in the root namespace.

Definition at line 1535 of file File.cc.

References getNamespace(), and VFS::instance().

Referenced by Filesystem::findNode(), getFullPath(), PosixSubsystem::parseShebang(), and readBlock().

+ Here is the caller graph for this function:

◆ getGid()

size_t File::getGid ( ) const

Definition at line 984 of file File.cc.

◆ getInode()

uintptr_t File::getInode ( ) const

Definition at line 833 of file File.cc.

◆ getModifiedTime()

Time::Timestamp File::getModifiedTime ( )

Returns the time the file was last modified.

Definition at line 767 of file File.cc.

◆ getName() [1/2]

String File::getName ( ) const

◆ getName() [2/2]

void File::getName ( String &  s) const

Definition at line 787 of file File.cc.

◆ getNamespace()

void File::getNamespace ( ParentLease &  parent,
String &  name 
) const

Snapshot a name and retain its parent across concurrent namespace moves.

Definition at line 992 of file File.cc.

Referenced by Filesystem::findNode(), Symlink::followLinkRetained(), getFullPath(), and Directory::lookupChildAt().

+ Here is the caller graph for this function:

◆ getParent()

File * File::getParent ( ) const

Definition at line 988 of file File.cc.

◆ getPermissions()

uint32_t File::getPermissions ( ) const

Definition at line 933 of file File.cc.

◆ getPhysicalPage()

physical_uintptr_t File::getPhysicalPage ( size_t  offset)
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 FramebufferFile, and MemFile.

Definition at line 486 of file File.cc.

References acquireCachedBlock(), EMIT_IF, getBlockSize(), VirtualAddressSpace::getMapping(), PhysicalMemoryManager::getPageSize(), ProcessorBase::information(), VirtualAddressSpace::isMapped(), LIKELY, Cache::lookup(), Cache::release(), UNLIKELY, unpinBlock(), and useFillCache().

Referenced by MemoryMappedFile::clone().

+ Here is the caller graph for this function:

◆ getSize()

size_t File::getSize ( )
virtual

Definition at line 792 of file File.cc.

◆ getUid()

size_t File::getUid ( ) const

Definition at line 969 of file File.cc.

◆ increaseRefCount()

void File::increaseRefCount ( bool  bIsWriter)
virtual

Definition at line 896 of file File.cc.

◆ isBlockDevice()

virtual bool File::isBlockDevice ( ) const
inlinevirtual

Definition at line 302 of file File.h.

◆ isBytewise()

bool File::isBytewise ( ) const
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 RandomFile, NullFile, ZeroFile, SerialFile, PtmxFile, RtcFile, Tty0File, MeminfoFile, PciDevicesFile, MountFile, UptimeFile, ConstantFile, PsAuxFile, UnixSocket, ConsoleFile, TextIO, Directory, Pipe, Symlink, InputFile, and EvdevFile.

Definition at line 1365 of file File.cc.

Referenced by populateRange(), read(), readBytewise(), readCached(), supportsRegularFileOperations(), writeBytewise(), and writeUnlocked().

+ Here is the caller graph for this function:

◆ isCharacterDevice()

virtual bool File::isCharacterDevice ( ) const
inlinevirtual

Definition at line 323 of file File.h.

◆ isConsole()

virtual bool File::isConsole ( ) const
inlinevirtual

Definition at line 326 of file File.h.

◆ isDirectory()

bool File::isDirectory ( )
virtual

◆ isDirectPhysicalMapping()

virtual bool File::isDirectPhysicalMapping ( ) const
inlinevirtual

Definition at line 167 of file File.h.

◆ isFifo()

bool File::isFifo ( ) const
virtual

Returns true if the File is actually a fifo.

Reimplemented in Pipe.

Definition at line 812 of file File.cc.

Referenced by Pipe::fromFile(), and supportsRegularFileOperations().

+ Here is the caller graph for this function:

◆ isPipe()

bool File::isPipe ( ) const
virtual

Returns true if the File is actually a pipe.

Reimplemented in Pipe.

Definition at line 808 of file File.cc.

Referenced by Pipe::fromFile(), and supportsRegularFileOperations().

+ Here is the caller graph for this function:

◆ isSeekable()

bool File::isSeekable ( ) const
virtual

Whether ordinary reads and writes consume a persistent byte offset.

Reimplemented in UnixSocket, ConsoleFile, TextIO, Pipe, InputFile, and EvdevFile.

Definition at line 820 of file File.cc.

Referenced by supportsRegularFileOperations().

+ Here is the caller graph for this function:

◆ isSocket()

bool File::isSocket ( ) const
virtual

Returns true if the File is actually a socket.

Reimplemented in UnixSocket.

Definition at line 816 of file File.cc.

Referenced by supportsRegularFileOperations().

+ Here is the caller graph for this function:

◆ isStableVfsRoot()

bool File::isStableVfsRoot ( ) const
virtual

Whether this untracked File is the externally owned filesystem root.

Definition at line 918 of file File.cc.

References Filesystem::getRoot().

◆ isSymlink()

bool File::isSymlink ( )
virtual

◆ listExtendedAttributes()

XattrStatus File::listExtendedAttributes ( void *  buffer,
size_t  capacity,
size_t &  required 
)
virtual

Definition at line 1112 of file File.cc.

◆ lockWrites()

File::WriteGuard File::lockWrites ( )

Begin a multi-fragment write which must not interleave with another writer.

Definition at line 420 of file File.cc.

Referenced by append(), and write().

+ Here is the caller graph for this function:

◆ markPageExternallyWritable()

void File::markPageExternallyWritable ( size_t  offset)

Mark an already borrowed page before exposing a writable shared mapping.

Definition at line 1611 of file File.cc.

References PhysicalMemoryManager::getPageSize(), Cache::markExternallyWritable(), and useFillCache().

Referenced by MemoryMappedFile::setPermissions(), and MemoryMappedFile::trap().

+ Here is the caller graph for this function:

◆ maximumFileSize()

uint64_t File::maximumFileSize ( ) const
virtual

Maximum byte length supported by the backing, independent of free space.

Reimplemented in Ext2File, and FatFile.

Definition at line 829 of file File.cc.

Referenced by allocateRange().

+ Here is the caller graph for this function:

◆ monitor()

void File::monitor ( Thread *  pThread,
Event *  pEvent 
)

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 1482 of file File.cc.

References EMIT_IF, and Event::tryAcquireRegistration().

◆ moveNamespace()

void File::moveNamespace ( const String &  name,
File *  parent 
)
protected

Definition at line 1019 of file File.cc.

◆ open()

File * File::open ( )
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 PtmxFile, Tty0File, InputFile, and EvdevFile.

Definition at line 1357 of file File.cc.

Referenced by openForDescriptor().

+ Here is the caller graph for this function:

◆ openForDescriptor()

File * File::openForDescriptor ( RetainedFile &  owner)
virtual

A per-open endpoint may place its initial VFS reference in owner. The caller retains this owner until the open file description takes over.

Definition at line 1361 of file File.cc.

References open().

◆ physicalMappingFlags()

size_t File::physicalMappingFlags ( ) const
inline

Definition at line 170 of file File.h.

◆ physicalPageLoans()

size_t & File::physicalPageLoans ( )
protectedvirtual

Definition at line 1163 of file File.cc.

◆ pinBlock()

bool File::pinBlock ( uint64_t  location)
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.

Returns true only when the page currently published for location is held until the matching unpinBlock(). The base implementation returns false so a cache-backed subclass cannot silently claim unsafe pages.

Reimplemented in RawFsFile, Ext2File, FatFile, Iso9660File, and RamFile.

Definition at line 1415 of file File.cc.

Referenced by acquireCachedBlock(), and syncRange().

+ Here is the caller graph for this function:

◆ populateRange()

size_t File::populateRange ( size_t  offset,
size_t  length 
)

Populate at most MaxReadPages and return the ready prefix from offset. Existing demand pages return immediately; later fill failures leave successfully populated pages available for subsequent demands.

Definition at line 1618 of file File.cc.

References PhysicalMemoryManager::getPageSize(), isBytewise(), read(), and useFillCache().

◆ populateRangeLocked()

size_t File::populateRangeLocked ( size_t  offset,
size_t  length 
)
private

Definition at line 1634 of file File.cc.

◆ preallocate()

void File::preallocate ( size_t  expectedSize,
bool  zero = true 
)
virtual

Optionally preallocates blocks to fit the given size.

Reimplemented in Ext2File.

Definition at line 1089 of file File.cc.

◆ prepareSharedMapping()

bool File::prepareSharedMapping ( size_t  offset,
size_t  length 
)
virtual

Prepare backing storage before a writable shared mapping is published.

Reimplemented in Ext2File, and Iso9660File.

Definition at line 1143 of file File.cc.

Referenced by MemoryMappedFile::trap().

+ Here is the caller graph for this function:

◆ prepareShrink()

bool File::prepareShrink ( const ShrinkContext &  context,
UniquePointer< PreparedShrink > &  prepared 
)
protectedvirtual

Definition at line 1347 of file File.cc.

◆ prepareWrite()

bool File::prepareWrite ( uint64_t  location,
uint64_t  size 
)
protectedvirtual

Definition at line 1147 of file File.cc.

◆ publishEvent()

void File::publishEvent ( FileEventMask  mask,
const StringView &  name = StringView(),
bool  targetIsDirectory = false 
)

◆ publishInodeEvent()

void File::publishInodeEvent ( const FileEvent &  event)
protectedvirtual

Definition at line 857 of file File.cc.

◆ publishWriteMetadata()

void File::publishWriteMetadata ( )
private

Definition at line 432 of file File.cc.

◆ queryReady()

ReadyMask File::queryReady ( bool  reading,
bool  writing 
)
virtual

Return the current readiness state for this open endpoint.

Reimplemented in ConsoleFile, ConsolePhysicalFile, and Pipe.

Definition at line 1054 of file File.cc.

References select().

Referenced by ConsolePhysicalFile::queryReady().

+ Here is the caller graph for this function:

◆ read()

uint64_t File::read ( uint64_t  location,
uint64_t  size,
uintptr_t  buffer,
bool  bCanBlock = true 
)
finalvirtual

Reads from the file.

Parameters
[in]bufferBuffer to write the read data into. Can be null, in which case the data can be found by calling getPhysicalPage.
[in]bCanBlockWhether or not the File can block when reading
Todo:
consider caching this still

Definition at line 239 of file File.cc.

References getBlockSize(), PhysicalMemoryManager::getPageSize(), isBytewise(), read(), Cache::read(), readBytewise(), readIntoCache(), releaseReadReference(), and useFillCache().

Referenced by Symlink::initialise(), PosixSubsystem::invoke(), PosixSubsystem::parseShebang(), populateRange(), PosixSubsystem::prepareExecutable(), FileDisk::read(), read(), FileDescriptor::read(), readCached(), and MemoryMappedFile::trap().

+ Here is the caller graph for this function:

◆ readBlock()

uintptr_t File::readBlock ( uint64_t  location)
protectedvirtual

Retrieves an aligned block with one caller-owned lifetime reference.

Every successful call must be balanced by exactly one unpinBlock() at the same location. Cache-backed implementations must acquire a reference in addition to the cache entry's publication reference on both hit and miss paths.

Reimplemented in FramebufferFile, RawFsFile, Ext2File, FatFile, Iso9660File, and RamFile.

Definition at line 1383 of file File.cc.

References getFullPath().

Referenced by readIntoCache(), and readPage().

+ Here is the caller graph for this function:

◆ readBytewise()

uint64_t File::readBytewise ( uint64_t  location,
uint64_t  size,
uintptr_t  buffer,
bool  bCanBlock = true 
)
protectedvirtual

Reads bytes from the file, if isBytewise() == true.

Reimplemented in RandomFile, NullFile, ZeroFile, SerialFile, PtmxFile, RtcFile, Tty0File, MeminfoFile, PciDevicesFile, MountFile, UptimeFile, ConstantFile, PsAuxFile, UnixSocket, ConsoleMasterFile, ConsoleSlaveFile, ConsolePhysicalFile, TextIO, Pipe, InputFile, EvdevFile, FatSymlink, and Ext2Symlink.

Definition at line 1369 of file File.cc.

References isBytewise().

Referenced by read().

+ Here is the caller graph for this function:

◆ readCached()

size_t File::readCached ( uint64_t  location,
size_t  size,
uintptr_t  buffer,
bool(*)(uintptr_t, size_t)  prepare = nullptr 
)

Copies a bounded resident prefix without backend I/O. The destination must remain writable throughout the call. prepare runs under dataMutationLock; callers must acquire any outer mapping guard before entering.

Definition at line 319 of file File.cc.

References isBytewise(), read(), Cache::read(), and useFillCache().

Referenced by PosixSubsystem::readCachedFile().

+ Here is the caller graph for this function:

◆ readIntoCache()

uintptr_t File::readIntoCache ( uintptr_t  block,
bool  overwriteWholePage = false,
size_t  readAheadBytes = 0 
)
private

Reads the given cache block and returns one per-use reference.

The block index does not own this reference.

Definition at line 1790 of file File.cc.

References acquireCachedBlock(), LockGuard< T >::disown(), getBlockSize(), PhysicalMemoryManager::getPageSize(), Cache::insert(), Cache::lookup(), Cache::markNoLongerEditing(), readBlock(), readIntoCache(), readPage(), Semaphore::release(), Cache::release(), setCachedPage(), and useFillCache().

Referenced by read(), readIntoCache(), and writeUnlocked().

+ Here is the caller graph for this function:

◆ readPage()

bool File::readPage ( uint64_t  location,
uintptr_t  destination 
)
protectedvirtual

Fill a caller-owned native page, including zeroes for holes and the EOF tail.

Reimplemented in Ext2File, FatFile, and Iso9660File.

Definition at line 1727 of file File.cc.

References getBlockSize(), PhysicalMemoryManager::getPageSize(), readBlock(), and unpinBlock().

Referenced by readIntoCache(), and readPages().

+ Here is the caller graph for this function:

◆ readPages()

bool File::readPages ( ReadPage *  pages,
size_t  count 
)
protectedvirtual

All destination accesses finish before return; complete identifies each fully initialised page even when another page in the batch failed.

Reimplemented in Ext2File.

Definition at line 1716 of file File.cc.

References readPage().

◆ releaseMappingUse()

void File::releaseMappingUse ( bool  executable,
bool  sharedWrite 
)

Definition at line 1196 of file File.cc.

◆ releaseReadReference()

void File::releaseReadReference ( uintptr_t  block)
private

Releases the per-use reference returned by readIntoCache().

Definition at line 1892 of file File.cc.

References getBlockSize(), PhysicalMemoryManager::getPageSize(), Cache::release(), unpinBlock(), and useFillCache().

Referenced by read(), and writeUnlocked().

+ Here is the caller graph for this function:

◆ releaseVfsReference()

void File::releaseVfsReference ( )
virtual

Releases a reference acquired by retainVfsReference().

Reimplemented in InputFile, EvdevFile, and Pipe.

Definition at line 914 of file File.cc.

References VFS::instance(), and VFS::untrackFile().

Referenced by UnixSocketSyscalls::bind(), InputFile::releaseVfsReference(), EvdevFile::releaseVfsReference(), Pipe::releaseVfsReference(), and Process::setCtty().

+ Here is the caller graph for this function:

◆ removeExtendedAttribute()

XattrStatus File::removeExtendedAttribute ( const StringView &  name)
virtual

Definition at line 1121 of file File.cc.

◆ resize()

bool File::resize ( size_t  size)

◆ resizeFile()

bool File::resizeFile ( size_t  size)
protectedvirtual

Definition at line 1352 of file File.cc.

◆ retainDetachedParent()

void File::retainDetachedParent ( )
protected

Keep the former parent alive after this node leaves its namespace.

Definition at line 1025 of file File.cc.

References Filesystem::getRoot(), VFS::instance(), and m_pDetachedParent.

◆ retainVfsReference()

bool File::retainVfsReference ( )
virtual

Attempts to retain this File through its existing VFS ownership record. Untracked filesystem roots remain borrowed and return false. Virtual dispatch lets kernel-owned contexts use the loadable VFS lifetime model without creating a kernel-to-module link dependency.

Reimplemented in InputFile, EvdevFile, and Pipe.

Definition at line 910 of file File.cc.

References VFS::instance(), and VFS::retainTrackedFile().

Referenced by InputFile::retainVfsReference(), EvdevFile::retainVfsReference(), Pipe::retainVfsReference(), and Process::setCtty().

+ Here is the caller graph for this function:

◆ returnPhysicalPage()

void File::returnPhysicalPage ( size_t  offset)
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, and FramebufferFile.

Definition at line 557 of file File.cc.

References getBlockSize(), PhysicalMemoryManager::getPageSize(), Cache::release(), UNLIKELY, unpinBlock(), and useFillCache().

Referenced by MemoryMappedFile::compact(), MemoryMappedFile::remove(), syncAndReturnPhysicalPage(), and MemoryMappedFile::trap().

+ Here is the caller graph for this function:

◆ select()

int File::select ( bool  bWriting = false,
int  timeout = 0 
)
virtual

Similar to POSIX's select() function

Returns
1 if ready for reading/writing, 0 otherwise
Note
Default implementation says always ready to read/write so be sure to override if that's not right

Reimplemented in ConsoleFile, ConsolePhysicalFile, SerialFile, PsAuxFile, UnixSocket, TextIO, Pipe, InputFile, and EvdevFile.

Definition at line 1050 of file File.cc.

Referenced by queryReady(), and ConsolePhysicalFile::select().

+ Here is the caller graph for this function:

◆ setAccessedTime()

void File::setAccessedTime ( Time::Timestamp  t)

Sets the time the file was last accessed.

Definition at line 740 of file File.cc.

References publishEvent().

Referenced by Ext2Filesystem::createNode().

+ Here is the caller graph for this function:

◆ setCachedPage()

void File::setCachedPage ( size_t  block,
uintptr_t  value,
bool  locked = true 
)
private

Set a page in our cache.

Definition at line 1598 of file File.cc.

Referenced by evict(), File(), readIntoCache(), and writeCallback().

+ Here is the caller graph for this function:

◆ setCreationTime()

void File::setCreationTime ( Time::Timestamp  t)

Sets the time the file was created.

Definition at line 725 of file File.cc.

References publishEvent().

Referenced by RamFs::createLink(), and RamFs::removeNode().

+ Here is the caller graph for this function:

◆ setExtendedAttribute()

XattrStatus File::setExtendedAttribute ( const StringView &  name,
const void *  value,
size_t  length,
unsigned  flags 
)
virtual

Definition at line 1117 of file File.cc.

◆ setFilesystem()

void File::setFilesystem ( Filesystem *  pFs)

Definition at line 845 of file File.cc.

◆ setGid()

void File::setGid ( size_t  gid)

Definition at line 973 of file File.cc.

◆ setGidOnly()

void File::setGidOnly ( size_t  gid)
protected

Set GID without raising fileAttributeChanged.

Definition at line 1448 of file File.cc.

Referenced by Ext2Directory::Ext2Directory(), Ext2File::Ext2File(), Ext2Symlink::Ext2Symlink(), and FatDirectory::FatDirectory().

+ Here is the caller graph for this function:

◆ setInode()

void File::setInode ( uintptr_t  inode)
virtual

Reimplemented in FatDirectory.

Definition at line 837 of file File.cc.

◆ setModifiedTime()

void File::setModifiedTime ( Time::Timestamp  t)

Sets the time the file was last modified.

Definition at line 771 of file File.cc.

References publishEvent().

Referenced by Ext2Filesystem::createNode().

+ Here is the caller graph for this function:

◆ setOwnership()

bool File::setOwnership ( size_t  uid,
size_t  gid,
bool  changeUid,
bool  changeGid 
)

Definition at line 937 of file File.cc.

◆ setPermissions()

void File::setPermissions ( uint32_t  perms)

Definition at line 922 of file File.cc.

◆ setPermissionsOnly()

void File::setPermissionsOnly ( uint32_t  perms)
protected

Set permissions without raising fileAttributeChanged.

Definition at line 1440 of file File.cc.

Referenced by Ext2Directory::Ext2Directory(), Ext2File::Ext2File(), Ext2Symlink::Ext2Symlink(), FatDirectory::FatDirectory(), and FatFile::FatFile().

+ Here is the caller graph for this function:

◆ setPhysicalMappingFlags()

void File::setPhysicalMappingFlags ( size_t  flags)
inlineprotected

Definition at line 685 of file File.h.

◆ setSize()

void File::setSize ( size_t  sz)

Definition at line 796 of file File.cc.

◆ setTimes()

void File::setTimes ( Time::Timestamp  accessed,
Time::Timestamp  modified,
bool  changeAccessed,
bool  changeModified 
)

Definition at line 751 of file File.cc.

◆ setUid()

void File::setUid ( size_t  uid)

Definition at line 958 of file File.cc.

◆ setUidOnly()

void File::setUidOnly ( size_t  uid)
protected

Set UID without raising fileAttributeChanged.

Definition at line 1444 of file File.cc.

Referenced by Ext2Directory::Ext2Directory(), Ext2File::Ext2File(), Ext2Symlink::Ext2Symlink(), and FatDirectory::FatDirectory().

+ Here is the caller graph for this function:

◆ shutdownFillCacheWriteback()

void File::shutdownFillCacheWriteback ( )
protected

Definition at line 1767 of file File.cc.

◆ snapshotNamespace()

bool File::snapshotNamespace ( ParentLease &  parent,
String &  name,
FileEventMask  interest 
) const
protected

Definition at line 996 of file File.cc.

◆ subscribeInodeEvents()

FileHandleStatus File::subscribeInodeEvents ( FileEventMask  mask,
const SharedPointer< FileEventObserver > &  observer,
FileEventSubscription &  subscription 
)
virtual

Definition at line 851 of file File.cc.

◆ supports()

bool File::supports ( const size_t  command) const
virtual

Does this File object support the given integer-based command?

Reimplemented in RtcFile, FramebufferFile, RandomFile, and EvdevFile.

Definition at line 1069 of file File.cc.

◆ supportsReadinessNotifications()

bool File::supportsReadinessNotifications ( ) const
virtual

Whether readiness transitions are reported through ReadinessSource.

Reimplemented in InputFile, EvdevFile, ConsoleFile, ConsolePhysicalFile, and Pipe.

Definition at line 1065 of file File.cc.

Referenced by EpollInstance::control().

+ Here is the caller graph for this function:

◆ supportsRegularFileOperations()

bool File::supportsRegularFileOperations ( )

Whether the backing supports ordinary file range operations.

Definition at line 824 of file File.cc.

References isBytewise(), isDirectory(), isFifo(), isPipe(), isSeekable(), isSocket(), and isSymlink().

Referenced by allocateRange(), Ext2Filesystem::encodeFileHandle(), PosixSubsystem::readCachedFile(), and resize().

+ Here is the caller graph for this function:

◆ sync() [1/2]

bool File::sync ( )
virtual

Sync all cached pages for the file back to disk.

Returns false if any cached page cannot be synchronised. Successful pages remain written when another page fails.

Reimplemented in RawFsFile, Ext2Directory, Ext2File, FatDirectory, FatFile, and FatSymlink.

Definition at line 595 of file File.cc.

References syncRange().

Referenced by MemoryMappedFile::compact(), Ext2File::sync(), MemoryMappedFile::sync(), syncAndReturnPhysicalPage(), syncPages(), and MemoryMappedFile::syncRange().

+ Here is the caller graph for this function:

◆ sync() [2/2]

bool File::sync ( size_t  offset,
bool  async 
)
virtual

Trigger a sync of an inner cache back to disk and report completion (or queue admission for an asynchronous request).

Reimplemented in RawFsFile, Ext2File, FatFile, FatDirectory, and FatSymlink.

Definition at line 705 of file File.cc.

◆ syncAndReturnPhysicalPage()

bool File::syncAndReturnPhysicalPage ( size_t  offset,
bool  async 
)

Syncs a mapped page before releasing its backing-cache reference.

Definition at line 581 of file File.cc.

References returnPhysicalPage(), and sync().

Referenced by MemoryMappedFile::remove().

+ Here is the caller graph for this function:

◆ syncFillCache()

bool File::syncFillCache ( size_t  offset,
bool  async,
bool &  present 
)
protected

Reports writeback success separately from an absent fill page.

Definition at line 1771 of file File.cc.

References PhysicalMemoryManager::getPageSize(), Cache::lookup(), Cache::release(), and Cache::sync().

Referenced by Ext2File::sync().

+ Here is the caller graph for this function:

◆ syncPages()

bool File::syncPages ( const uint64_t *  offsets,
size_t  count 
)
virtual

Persists a bounded group of offsets whose producer pages remain pinned.

Reimplemented in Ext2File, and FatFile.

Definition at line 688 of file File.cc.

References sync().

Referenced by syncRange(), and MemoryMappedFile::syncRange().

+ Here is the caller graph for this function:

◆ syncRange()

bool File::syncRange ( size_t  offset,
size_t  length 
)

Sync cached pages overlapping a byte range; zero length extends to EOF.

Definition at line 599 of file File.cc.

References Vector< T >::count(), getBlockSize(), getCachedPage(), PhysicalMemoryManager::getPageSize(), Cache::lookup(), pinBlock(), Vector< T >::pushBack(), Cache::release(), syncPages(), unpinBlock(), useFillCache(), and writeBlock().

Referenced by sync().

+ Here is the caller graph for this function:

◆ truncate()

void File::truncate ( )
virtual

Delete all data from the file.

Reimplemented in Ext2Symlink, Ext2Directory, Ext2File, FatDirectory, FatFile, and RamFile.

Definition at line 1153 of file File.cc.

◆ tryAcquireFilesystemOperation()

bool File::tryAcquireFilesystemOperation ( OperationBarrier::Lease &  operation) const
protected

Definition at line 713 of file File.cc.

◆ tryBeginMappingRelease()

bool File::tryBeginMappingRelease ( )
virtual

Memory-pressure compaction must never wait on a backing mutation.

Reimplemented in Ext2File.

Definition at line 587 of file File.cc.

References Semaphore::tryAcquire().

Referenced by MemoryMappedFile::compact().

+ Here is the caller graph for this function:

◆ unpinBlock()

void File::unpinBlock ( uint64_t  location)
protectedvirtual

Unpins the given page.

Reimplemented in RawFsFile, Ext2File, FatFile, Iso9660File, and RamFile.

Definition at line 1434 of file File.cc.

Referenced by acquireCachedBlock(), getPhysicalPage(), readPage(), releaseReadReference(), returnPhysicalPage(), and syncRange().

+ Here is the caller graph for this function:

◆ updateAttributes()

void File::updateAttributes ( const Attributes &  attributes,
uint32_t  mask 
)
protectedvirtual

Definition at line 1125 of file File.cc.

◆ useFillCache()

bool File::useFillCache ( ) const
protectedvirtual

Whether this file currently uses native-page fill caching.

Reimplemented in Ext2File, and FatFile.

Definition at line 1746 of file File.cc.

References EMIT_IF, getBlockSize(), and PhysicalMemoryManager::getPageSize().

Referenced by allocateRange(), getPhysicalPage(), markPageExternallyWritable(), populateRange(), read(), readCached(), readIntoCache(), releaseReadReference(), resize(), returnPhysicalPage(), syncRange(), Ext2File::useFillCache(), and writeUnlocked().

+ Here is the caller graph for this function:

◆ write()

uint64_t File::write ( uint64_t  location,
uint64_t  size,
uintptr_t  buffer,
bool  bCanBlock = true 
)
finalvirtual

Writes to the file.

Parameters
[in]bCanBlockWhether or not the File can block when reading

Definition at line 342 of file File.cc.

References lockWrites().

Referenced by Ext2Filesystem::createNode(), and FileDescriptor::write().

+ Here is the caller graph for this function:

◆ writeBlock()

void File::writeBlock ( uint64_t  location,
uintptr_t  addr 
)
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 Ext2File, FatFile, and RawFsFile.

Definition at line 1393 of file File.cc.

Referenced by syncRange(), writeBlocks(), and writeUnlocked().

+ Here is the caller graph for this function:

◆ writeBlocks()

void File::writeBlocks ( uint64_t  location,
uintptr_t  addr,
size_t  length 
)
protectedvirtual

Writes a range of whole filesystem blocks back to the file.

Reimplemented in Ext2File.

Definition at line 1395 of file File.cc.

References getBlockSize(), and writeBlock().

Referenced by Ext2File::writeBlocks(), writeCallback(), and writeUnlocked().

+ Here is the caller graph for this function:

◆ writeBytewise()

uint64_t File::writeBytewise ( uint64_t  location,
uint64_t  size,
uintptr_t  buffer,
bool  bCanBlock = true 
)
protectedvirtual

Writes bytes to the file, if isBytewise() == true.

Reimplemented in RandomFile, NullFile, ZeroFile, SerialFile, PtmxFile, RtcFile, Tty0File, MeminfoFile, PciDevicesFile, MountFile, UptimeFile, ConstantFile, PsAuxFile, UnixSocket, ConsoleMasterFile, ConsoleSlaveFile, ConsolePhysicalFile, TextIO, Pipe, InputFile, EvdevFile, FatSymlink, and Ext2Symlink.

Definition at line 1376 of file File.cc.

References isBytewise().

Referenced by writeUnlocked().

+ Here is the caller graph for this function:

◆ writeCallback()

bool File::writeCallback ( CacheConstants::CallbackCause  cause,
uintptr_t  loc,
uintptr_t  page,
void *  meta 
)
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.

Todo:
handle block size < 4K??

Definition at line 116 of file File.cc.

References getBlockSize(), PhysicalMemoryManager::getPageSize(), setCachedPage(), and writeBlocks().

◆ writeSerializationLock()

Mutex & File::writeSerializationLock ( )
protectedvirtual

Definition at line 1155 of file File.cc.

◆ writeUnlocked()

uint64_t File::writeUnlocked ( uint64_t  location,
uint64_t  size,
uintptr_t  buffer,
bool  bCanBlock 
)
private

Performs a write while m_WriteLock is already held.

Todo:
consider caching this still

Definition at line 347 of file File.cc.

References getBlockSize(), PhysicalMemoryManager::getPageSize(), isBytewise(), readIntoCache(), releaseReadReference(), useFillCache(), writeBlock(), writeBlocks(), and writeBytewise().

Friends And Related Symbol Documentation

◆ Directory

friend class Directory
friend

Definition at line 77 of file File.h.

◆ Filesystem

friend class Filesystem
friend

Definition at line 76 of file File.h.

Member Data Documentation

◆ m_AccessedTime

Time::Timestamp File::m_AccessedTime
protected

Definition at line 618 of file File.h.

◆ m_bDetachedParentHandled

bool File::m_bDetachedParentHandled
protected

Definition at line 632 of file File.h.

◆ m_bDirect

bool File::m_bDirect
protected

Definition at line 674 of file File.h.

◆ m_CacheState

CacheState File::m_CacheState
protected

Definition at line 672 of file File.h.

◆ m_CreationTime

Time::Timestamp File::m_CreationTime
protected

Definition at line 620 of file File.h.

◆ m_DataMutationLock

Mutex File::m_DataMutationLock
protected

Definition at line 681 of file File.h.

◆ m_FutexIdentity

uintptr_t File::m_FutexIdentity = 0
protected

Definition at line 622 of file File.h.

◆ m_Gid

size_t File::m_Gid
protected

Definition at line 637 of file File.h.

◆ m_Inode

uintptr_t File::m_Inode
protected

Definition at line 621 of file File.h.

◆ m_Lock

Mutex File::m_Lock
protected

Definition at line 689 of file File.h.

◆ m_MetadataLock

Mutex File::m_MetadataLock
mutableprotected

Definition at line 628 of file File.h.

◆ m_ModifiedTime

Time::Timestamp File::m_ModifiedTime
protected

Definition at line 619 of file File.h.

◆ m_MonitorTargets

List<MonitorTarget*> File::m_MonitorTargets
protected

Definition at line 699 of file File.h.

◆ m_Name

String File::m_Name
protected

Definition at line 617 of file File.h.

◆ m_nReaders

size_t File::m_nReaders
protected

Definition at line 634 of file File.h.

◆ m_nWriters

size_t File::m_nWriters
protected

Definition at line 634 of file File.h.

◆ m_pDetachedParent

File* File::m_pDetachedParent
protected

Pins a former tracked parent for this detached node's remaining life.

Definition at line 631 of file File.h.

Referenced by retainDetachedParent(), and ~File().

◆ m_Permissions

uint32_t File::m_Permissions
protected

Definition at line 638 of file File.h.

◆ m_pFilesystem

class Filesystem* File::m_pFilesystem
protected

Definition at line 624 of file File.h.

◆ m_PhysicalMappingFlags

size_t File::m_PhysicalMappingFlags = 0
protected

Definition at line 683 of file File.h.

◆ m_PhysicalPageLoans

size_t File::m_PhysicalPageLoans = 0
protected

Definition at line 682 of file File.h.

◆ m_pParent

File* File::m_pParent
protected

Definition at line 627 of file File.h.

◆ m_Size

size_t File::m_Size
protected

Definition at line 625 of file File.h.

◆ m_Uid

size_t File::m_Uid
protected

Definition at line 636 of file File.h.

◆ m_WriteLock

Mutex File::m_WriteLock
protected

Serializes file mutation, including append EOF selection, across open descriptions.

Definition at line 680 of file File.h.

Referenced by Ext2Filesystem::renameNode().

◆ MaxReadPages

constexpr size_t File::MaxReadPages = 32
staticconstexpr

Definition at line 430 of file File.h.


The documentation for this class was generated from the following files: